bool DBusObjectManagerStub::emitInterfacesAddedSignal(std::shared_ptr<DBusStubAdapter> dbusStubAdapter,
                                                      const std::shared_ptr<DBusProxyConnection>& dbusConnection) const {
    assert(dbusConnection);
    assert(dbusConnection->isConnected());

    const auto& dbusStubObjectPath = dbusStubAdapter->getObjectPath();
    const auto& dbusStubInterfaceName = dbusStubAdapter->getInterfaceName();
    DBusMessage dbusSignal = DBusMessage::createSignal(dbusObjectPath_, getInterfaceName(), "InterfacesAdded", "oa{sa{sv}}");
    DBusOutputStream dbusOutputStream(dbusSignal);
    DBusInterfacesAndPropertiesDict dbusInterfacesAndPropertiesDict({
        { dbusStubInterfaceName, DBusPropertiesChangedDict() }
    });

    if (dbusStubAdapter->isManagingInterface()) {
        dbusInterfacesAndPropertiesDict.insert({ getInterfaceName(), DBusPropertiesChangedDict() });
    }

    if (dbusStubAdapter->hasFreedesktopProperties()) {
        dbusInterfacesAndPropertiesDict.insert({ "org.freedesktop.DBus.Properties", DBusPropertiesChangedDict() });
    }

    dbusOutputStream << dbusStubObjectPath;
    dbusOutputStream << dbusInterfacesAndPropertiesDict;
    dbusOutputStream.flush();

    const bool dbusSignalEmitted = dbusConnection->sendDBusMessage(dbusSignal);
    return dbusSignalEmitted;
}
Beispiel #2
0
 void serialize(
     Archive &                           ar, 
     RcfClientT &                        rcfClient)
 {
     if (ar.isWrite())
     {
         rcfClient.mClientStubPtr ?
             ar & true & rcfClient.getClientStub() :
             ar & false;
     }
     else //if (ar.isRead())
     {
         bool hasClientStub = false;
         ar & hasClientStub;
         if (hasClientStub)
         {
             if (!rcfClient.mClientStubPtr)
             {
                 typedef typename RcfClientT::Interface Interface;
                 std::string interfaceName = getInterfaceName( (Interface*) 0);
                 ClientStubPtr clientStubPtr(new ClientStub(interfaceName));
                 rcfClient.setClientStubPtr(clientStubPtr);
             }
             ar & rcfClient.getClientStub();
         }
         else
         {
             rcfClient.setClientStubPtr( ClientStubPtr());
         }
     }
 }
Beispiel #3
0
void
Ethernet_getInterfaceMACAddress(const char* interfaceId, uint8_t* addr)
{
#ifdef __GNUC__
#ifndef __MINGW64_VERSION_MAJOR
    if (!dllLoaded) {
    	loadDLLs();
    	dllLoaded = true;
    }
#endif
#endif

    char* endPtr;

    long interfaceIndex = strtol(interfaceId, &endPtr, 10);

    if (endPtr != NULL) {
    	printf("Ethernet_getInterfaceMACAddress: invalid interface number %s\n", interfaceId);
    	return;
    }

    char* interfaceName = getInterfaceName((int) interfaceIndex);

	getAdapterMacAddress(interfaceName, addr);
}
shared_ptr<Interface> ThriftConfigApplier::updateInterface(
    const shared_ptr<Interface>& orig,
    const cfg::Interface* config,
    const Interface::Addresses& addrs) {
    CHECK_EQ(orig->getID(), config->intfID);

    cfg::NdpConfig ndp;
    if (config->__isset.ndp) {
        ndp = config->ndp;
    }
    auto name = getInterfaceName(config);
    auto mac = getInterfaceMac(config);
    auto mtu = config->__isset.mtu ? config->mtu : Interface::kDefaultMtu;
    if (orig->getRouterID() == RouterID(config->routerID) &&
            orig->getVlanID() == VlanID(config->vlanID) &&
            orig->getName() == name &&
            orig->getMac() == mac &&
            orig->getAddresses() == addrs &&
            orig->getNdpConfig() == ndp &&
            orig->getMtu() == mtu) {
        // No change
        return nullptr;
    }

    auto newIntf = orig->clone();
    newIntf->setRouterID(RouterID(config->routerID));
    newIntf->setVlanID(VlanID(config->vlanID));
    newIntf->setName(name);
    newIntf->setMac(mac);
    newIntf->setAddresses(addrs);
    newIntf->setNdpConfig(ndp);
    newIntf->setMtu(mtu);
    return newIntf;
}
        bool endPublish(Interface *, const std::string &publisherName_ = "")
        {
            const std::string &publisherName = (publisherName_ == "") ?
                getInterfaceName((Interface *) NULL) :
                publisherName_;

            return endPublishNamed(publisherName);
        }
        bool beginPublish(Interface *, const std::string &publisherName_ = "")
        {
            const std::string &publisherName = (publisherName_ == "") ?
                getInterfaceName((Interface *) NULL) :
                publisherName_;

            typedef typename Interface::RcfClientT RcfClientT;
            RcfClientPtr rcfClientPtr( new RcfClientT( ClientStub(publisherName)));
            return beginPublishNamed(publisherName, rcfClientPtr);
        }
        typename Interface::RcfClientT &publish(
            Interface *,
            const std::string &publisherName_ = "")
        {
            const std::string &publisherName = (publisherName_ == "") ?
                getInterfaceName( (Interface *) NULL) :
                publisherName_;

            return dynamic_cast<typename Interface::RcfClientT &>(
                publishNamed(publisherName) );
        }
        bool bind(I1 *, I2 *, ImplementationT **, const std::string &name_ = "")
        {
            const std::string &name = (name_ == "") ?
                getInterfaceName((I1 *) NULL) :
                name_;

            StubFactoryPtr stubFactoryPtr(
                new RCF::StubFactory_2<ImplementationT, I1, I2>());

            std::string desc;
            return insertStubFactory(name, desc, stubFactoryPtr);
        }
bool DBusObjectManagerStub::emitInterfacesRemovedSignal(std::shared_ptr<DBusStubAdapter> dbusStubAdapter,
                                                        const std::shared_ptr<DBusProxyConnection>& dbusConnection) const {
    assert(dbusConnection);
    assert(dbusConnection->isConnected());

    const auto& dbusStubObjectPath = dbusStubAdapter->getObjectPath();
    const auto& dbusStubInterfaceName = dbusStubAdapter->getInterfaceName();
    DBusMessage dbusSignal = DBusMessage::createSignal(dbusObjectPath_, getInterfaceName(), "InterfacesRemoved", "oas");
    DBusOutputStream dbusOutputStream(dbusSignal);
    std::vector<std::string> removedInterfaces({ { dbusStubInterfaceName } });

    if (dbusStubAdapter->isManagingInterface()) {
        removedInterfaces.push_back(getInterfaceName());
    }

    dbusOutputStream << dbusStubObjectPath;
    dbusOutputStream << removedInterfaces;
    dbusOutputStream.flush();

    const bool dbusSignalEmitted = dbusConnection->sendDBusMessage(dbusSignal);
    return dbusSignalEmitted;
}
Beispiel #10
0
NwIface::NwIface()
{
    int s, lerrno;
    struct ifreq ifr;
    struct sockaddr_in *sin(0);
    if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    {
        OW_THROW(SocketException, "socket");
    }
    getInterfaceName(s);
    bzero(&ifr, sizeof(ifr));
    strncpy(ifr.ifr_name, m_name.c_str(), sizeof(ifr.ifr_name));
    ////////////////////
    // Get IP address
    if (ioctl(s, SIOCGIFADDR, &ifr) < 0)
    {
        lerrno = errno;
        close(s);
        OW_THROW(SocketException, "ioctl:SIOCGIFADDR");
    }
    sin = reinterpret_cast<struct sockaddr_in *>(&ifr.ifr_addr);
    m_addr = sin->sin_addr.s_addr;
    ////////////////////
    // Get the broadcast address
    // Testing
    if (ioctl(s, SIOCGIFBRDADDR, &ifr) < 0)
    {
        lerrno = errno;
        close(s);
        OW_THROW(SocketException, "ioctl:SIOCGIFBRDADDR");
    }
    sin = reinterpret_cast<struct sockaddr_in*>(&ifr.ifr_broadaddr);
    m_bcastAddr = sin->sin_addr.s_addr;
    ////////////////////
    // Get net mask
    if (ioctl(s, SIOCGIFNETMASK, &ifr) < 0)
    {
        lerrno = errno;
        close(s);
        OW_THROW(SocketException, "ioctl:SIOCGIFNETMASK");
    }
#ifdef OW_GNU_LINUX
    sin = reinterpret_cast<struct sockaddr_in *>(&ifr.ifr_netmask);
#else
    sin = reinterpret_cast<struct sockaddr_in *>(&ifr.ifr_broadaddr);
#endif
    m_netmask = sin->sin_addr.s_addr;
    close(s);
}
bool DBusObjectManagerStub::onInterfaceDBusMessage(const DBusMessage& dbusMessage) {
    auto dbusConnection = dbusConnection_.lock();

    if (!dbusConnection || !dbusConnection->isConnected()) {
        return false;
    }

    if (!dbusMessage.isMethodCallType() || !dbusMessage.hasMemberName("GetManagedObjects")) {
        return false;
    }

    std::lock_guard<std::mutex> dbusObjectManagerStubLock(dbusObjectManagerStubLock_);
    DBusObjectPathAndInterfacesDict dbusObjectPathAndInterfacesDict;

    for (const auto& registeredDBusObjectPathIterator : registeredDBusObjectPathsMap_) {
        const std::string& registeredDBusObjectPath = registeredDBusObjectPathIterator.first;
        const auto& registeredDBusInterfacesMap = registeredDBusObjectPathIterator.second;
        DBusInterfacesAndPropertiesDict dbusInterfacesAndPropertiesDict;

        assert(registeredDBusObjectPath.length() > 0);
        assert(registeredDBusInterfacesMap.size() > 0);

        for (const auto& registeredDBusInterfaceIterator : registeredDBusInterfacesMap) {
            const std::string& registeredDBusInterfaceName = registeredDBusInterfaceIterator.first;
            const auto& registeredDBusStubAdapter = registeredDBusInterfaceIterator.second;

            assert(registeredDBusInterfaceName.length() > 0);

            dbusInterfacesAndPropertiesDict.insert({ registeredDBusInterfaceName, DBusPropertiesChangedDict() });

            if (registeredDBusStubAdapter->isManagingInterface()) {
                dbusInterfacesAndPropertiesDict.insert({ getInterfaceName(), DBusPropertiesChangedDict() });
            }
        }

        dbusObjectPathAndInterfacesDict.insert({ registeredDBusObjectPath, std::move(dbusInterfacesAndPropertiesDict) });
    }

    DBusMessage dbusMessageReply = dbusMessage.createMethodReturn("a{oa{sa{sv}}}");
    DBusOutputStream dbusOutputStream(dbusMessageReply);

    dbusOutputStream << dbusObjectPathAndInterfacesDict;
    dbusOutputStream.flush();

    const bool dbusMessageReplySent = dbusConnection->sendDBusMessage(dbusMessageReply);
    return dbusMessageReplySent;
}
shared_ptr<Interface> ThriftConfigApplier::createInterface(
    const cfg::Interface* config,
    const Interface::Addresses& addrs) {
    auto name = getInterfaceName(config);
    auto mac = getInterfaceMac(config);
    auto mtu = config->__isset.mtu ? config->mtu : Interface::kDefaultMtu;
    auto intf = make_shared<Interface>(InterfaceID(config->intfID),
                                       RouterID(config->routerID),
                                       VlanID(config->vlanID),
                                       name,
                                       mac,
                                       mtu);
    intf->setAddresses(addrs);
    if (config->__isset.ndp) {
        intf->setNdpConfig(config->ndp);
    }
    return intf;
}
Beispiel #13
0
EthernetSocket
Ethernet_createSocket(const char* interfaceId, uint8_t* destAddress)
{
    pcap_t *pcapSocket;
    char errbuf[PCAP_ERRBUF_SIZE];

    int interfaceIndex = atoi(interfaceId);

    char* interfaceName = getInterfaceName(interfaceIndex);

    if ((pcapSocket = pcap_open_live(interfaceName, 65536, PCAP_OPENFLAG_PROMISCUOUS, 10, errbuf)) == NULL)
    {
        printf("Open ethernet socket failed for device %s\n", interfaceName);
        return NULL;
    }

    EthernetSocket ethernetSocket = (EthernetSocket) calloc(1, sizeof(struct sEthernetSocket));

    ethernetSocket->rawSocket = pcapSocket;

    return ethernetSocket;
}
Beispiel #14
0
        void serialize(
            Archive &                           ar, 
            RcfClientT &                        rcfClient,
            const unsigned int)
        {
            typedef typename Archive::is_saving IsSaving;
            const bool isSaving = IsSaving::value;

            if (isSaving)
            {
                bool hasClientStub = rcfClient.mClientStubPtr;
                ar & hasClientStub;
                if (hasClientStub)
                {
                    ar & rcfClient.getClientStub();
                }
            }
            else //if (ar.isRead())
            {
                bool hasClientStub = false;
                ar & hasClientStub;
                
                if (hasClientStub)
                {
                    if (!rcfClient.mClientStubPtr)
                    {
                        typedef typename RcfClientT::Interface Interface;
                        std::string interfaceName = getInterfaceName( (Interface*) 0);
                        ClientStubPtr clientStubPtr(new ClientStub(interfaceName));
                        rcfClient.setClientStubPtr(clientStubPtr);
                    }
                    ar & rcfClient.getClientStub();
                }
                else
                {
                    rcfClient.setClientStubPtr( ClientStubPtr());
                }
            }
        }
Beispiel #15
0
    FutureImpl<Void> ClientStub::ping(const CallOptions & callOptions)
    {
        typedef Void V;

        CurrentClientStubSentry sentry(*this);

        setAsync(false);

        return RCF::FutureImpl<V>(
            ::RCF::AllocateClientParameters<
                V
                    ,
                V,V,V,V,V,V,V,V,V,V,V,V,V,V,V >()(
                    *this
                        ,
                    V(),V(),V(),V(),V(),V(),V(),V(),V(),V(),V(),V(),V(),V(),V()).r.get(),
            *this,
            getInterfaceName(),
            -1,
            callOptions.apply(*this),
            "ping",
            "V0");

    }   
Beispiel #16
0
Properties::Properties(const QString &objectPath,
                       const QString &interface,
                       QObject *parent)
    : SystemBusInterface(parent),
      mObjectPath(objectPath),
      mInterface(interface)
{
   qDebug() << "Connected" <<
               QDBusConnection::systemBus().connect(getServiceName(), getObjectPath(), getInterfaceName(), "PropertiesChanged", this, SLOT(PropertiesChanged(QString,QMap<QString,QVariant>,QList<QString>)));

}