当前位置: 首页>>代码示例>>C++>>正文


C++ NetworkAdapter类代码示例

本文整理汇总了C++中NetworkAdapter的典型用法代码示例。如果您正苦于以下问题:C++ NetworkAdapter类的具体用法?C++ NetworkAdapter怎么用?C++ NetworkAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NetworkAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TraceAdapter

void NetworkAdapterList::TraceAdapter(const TChar* aPrefix, NetworkAdapter& aAdapter)
{ // static
    Endpoint ep(0, aAdapter.Address());
    Bws<Endpoint::kMaxAddressBytes> addr;
    ep.AppendAddress(addr);
    LOG(kTrace, "%s: %s(%s)\n", aPrefix, aAdapter.Name(), (const TChar*)addr.Ptr());
}
开发者ID:MatthewMiddleweek,项目名称:ohNet,代码行数:7,代码来源:NetworkAdapterList.cpp

示例2: mDNS_DeregisterInterface

void MdnsPlatform::SubnetListChanged()
{
    iInterfacesLock.Wait();
    NetworkAdapter* current = iEnv.NetworkAdapterList().CurrentAdapter(kNifCookie);
    NetworkAdapterList& nifList = iEnv.NetworkAdapterList();
    std::vector<NetworkAdapter*>* subnetList = nifList.CreateSubnetList();
    for (TInt i=(TInt)iInterfaces.size()-1; i>=0; i--) {
        // Remove adapters with subnets no longer available and which don't
        // match the currently selected adapter (if there is one).
        if (InterfaceIndex(iInterfaces[i]->Adapter(), *subnetList) == -1
                || (current != NULL && current->Address() != iInterfaces[i]->Adapter().Address())) {
            mDNS_DeregisterInterface(iMdns, &iInterfaces[i]->Info(), false);
            delete iInterfaces[i];
            iInterfaces.erase(iInterfaces.begin()+i);
        }
    }
    if (current == NULL) { // no adapter selected; add new subnets
        for (TUint i=0; i<(TUint)subnetList->size(); i++) {
            NetworkAdapter* nif = (*subnetList)[i];
            if (InterfaceIndex(*nif) == -1) {
                AddInterface(nif);
            }
        }
    }
    if (current != NULL) {
        if (iInterfaces.size() == 0) { // current adapter is on a newly added subnet
            AddInterface(current);
            iClient.SetMulticastIf(current->Address());
        }
        current->RemoveRef(kNifCookie);
    }
    iInterfacesLock.Signal();
    nifList.DestroySubnetList(subnetList);
}
开发者ID:sewood,项目名称:ohNet,代码行数:34,代码来源:MdnsPlatform.cpp

示例3: single

TBool CpiDeviceListUpnp::IsLocationReachable(const Brx& aLocation) const
{
    /* linux's filtering of multicast messages appears to be buggy and messages
       received by all interfaces are sometimes delivered to sockets which are
       bound to / members of a group on a single (different) interface.  It'd be
       more correct to filter these out in SsdpListenerMulticast but that would
       require API changes which would be more inconvenient than just moving the
       filtering here.
       This should be reconsidered if we ever add more clients of SsdpListenerMulticast */
    TBool reachable = false;
    Uri uri;
    try {
        uri.Replace(aLocation);
    }
    catch (UriError&) {
        return false;
    }
    iLock.Wait();
    Endpoint endpt(0, uri.Host());
    NetworkAdapter* nif = iCpStack.Env().NetworkAdapterList().CurrentAdapter("CpiDeviceListUpnp::IsLocationReachable");
    if (nif != NULL) {
        if (nif->Address() == iInterface && nif->ContainsAddress(endpt.Address())) {
            reachable = true;
        }
        nif->RemoveRef("CpiDeviceListUpnp::IsLocationReachable");
    }
    iLock.Signal();
    return reachable;
}
开发者ID:DoomHammer,项目名称:ohNet,代码行数:29,代码来源:CpiDeviceUpnp.cpp

示例4: GetResourceManagerUri

void DviProtocolUpnp::GetResourceManagerUri(const NetworkAdapter& aAdapter, Brh& aUri)
{
    if (iDevice.ResourceManager() == NULL) {
        return;
    }
    for (TUint i=0; i<(TUint)iAdapters.size(); i++) {
        if (iAdapters[i]->Interface() == aAdapter.Address()) {
            WriterBwh writer(1024);
            writer.Write("http://");
            Bws<Endpoint::kMaxEndpointBytes> buf;
            Endpoint ep(iAdapters[i]->ServerPort(), aAdapter.Address());
            ep.AppendEndpoint(buf);
            writer.Write(buf);
            writer.Write('/');
            Uri::Escape(writer, iDevice.Udn());
            writer.Write('/');
            writer.Write(kProtocolName);
            writer.Write('/');
            writer.Write(iDevice.kResourceDir);
            writer.Write('/');
            writer.TransferTo(aUri);
            return;
        }
    }
}
开发者ID:Jacik,项目名称:ohNet,代码行数:25,代码来源:DviProtocolUpnp.cpp

示例5: LOG

MdnsPlatform::Status MdnsPlatform::Init()
{
    LOG(kBonjour, "Bonjour             Init\n");
    LOG(kBonjour, "Bonjour             Init - Set FQDN\n");
    DoSetHostName();
    LOG(kBonjour, "Bonjour             Init - Register Interface\n");

    iInterfacesLock.Wait();
    Status status = mStatus_NoError;
    NetworkAdapterList& nifList = iEnv.NetworkAdapterList();
    Functor functorSubnet = MakeFunctor(*this, &MdnsPlatform::SubnetListChanged);
    iSubnetListChangeListenerId = nifList.AddSubnetListChangeListener(functorSubnet, "MdnsPlatform-subnet");
    Functor functorAdapter = MakeFunctor(*this, &MdnsPlatform::CurrentAdapterChanged);
    iCurrentAdapterChangeListenerId = nifList.AddCurrentChangeListener(functorAdapter, "MdnsPlatform-current");

    NetworkAdapter* current = iEnv.NetworkAdapterList().CurrentAdapter(kNifCookie);
    if (current == NULL) { // Listening on all adapters.
        std::vector<NetworkAdapter*>* subnetList = nifList.CreateSubnetList();
        for (TUint i=0; i<(TUint)subnetList->size() && status==mStatus_NoError; i++) {
            status = AddInterface((*subnetList)[i]);
        }
        nifList.DestroySubnetList(subnetList);
    }
    else { // Using a single adapter.
        status = AddInterface(current);
        iClient.SetMulticastIf(current->Address());
        current->RemoveRef(kNifCookie);
    }

    iInterfacesLock.Signal();
    if (status == mStatus_NoError) {
        mDNSCoreInitComplete(iMdns, status);
    }
    return status;
}
开发者ID:openhome,项目名称:ohNet,代码行数:35,代码来源:MdnsPlatform.cpp

示例6: NifsMatch

TBool MdnsPlatform::NifsMatch(const NetworkAdapter& aNif1, const NetworkAdapter& aNif2)
{
    if (aNif1.Address() == aNif2.Address() && aNif1.Subnet() == aNif2.Subnet() && strcmp(aNif1.Name(), aNif2.Name()) == 0) {
        return true;
    }
    return false;
}
开发者ID:ACDN,项目名称:ohNet,代码行数:7,代码来源:MdnsPlatform.cpp

示例7: Blocker

void SuiteAlive::Test()
{
    Environment& env = iDvStack.Env();
    Blocker* blocker = new Blocker(env);
    CpListenerBasic* listener = new CpListenerBasic;
    NetworkAdapter* nif = env.NetworkAdapterList().CurrentAdapter(kAdapterCookie);
    SsdpListenerMulticast* listenerMulticast = new SsdpListenerMulticast(env, nif->Address());
    nif->RemoveRef(kAdapterCookie);
    TInt listenerId = listenerMulticast->AddNotifyHandler(listener);
    listenerMulticast->Start();
    DviDevice* device = new DviDeviceStandard(iDvStack, gNameDevice1);
    device->SetAttribute("Upnp.Domain", "a.b.c");
    device->SetAttribute("Upnp.Type", "type1");
    device->SetAttribute("Upnp.Version", "1");
    AddService(device, new DviService(iDvStack, "a.b.c", "service1", 1));
    AddService(device, new DviService(iDvStack, "a.b.c", "service2", 1));
    device->SetEnabled();
    blocker->Wait(1);
    /* we expect 5 messages but linux sometimes reports multicast messages from
      all subnets to listeners on any single subnet so just check that we've
      received a multiple of 5 messages */

    TEST(listener->TotalAlives() > 0);
    TEST(listener->TotalAlives() == listener->TotalByeByes());
    TEST(listener->TotalAlives() % 5 == 0);

    TUint byebyes = listener->TotalByeByes();
    Functor disabled = MakeFunctor(*this, &SuiteAlive::Disabled);
    device->SetDisabled(disabled);
    iSem.Wait();
    blocker->Wait(1); /* semaphore being signalled implies that the device has been
                         disabled.  We may require some extra time to receive the
                         multicast byebye confirming this */
    TEST(listener->TotalByeByes() > byebyes);
    TEST(listener->TotalByeByes() % 5 == 0);

    TUint alives = listener->TotalAlives();
    byebyes = listener->TotalByeByes();
    device->SetEnabled();
    blocker->Wait(1);
    TEST(listener->TotalAlives() > alives);
    TEST(listener->TotalAlives() - alives == listener->TotalByeByes() - byebyes);
    TEST(listener->TotalAlives() % 5 == 0);

    // Control point doesn't process ssdp:update notifications
    // check that updates are basically working by counting the extra alive messages instead
    alives = listener->TotalAlives();
    device->SetAttribute("Upnp.TestUpdate", "1");
    blocker->Wait(1);
    TEST(listener->TotalAlives() > alives);
    TEST(listener->TotalAlives() % 5 == 0);

    device->Destroy();
    listenerMulticast->RemoveNotifyHandler(listenerId);
    delete listenerMulticast;
    delete listener;
    delete blocker;
}
开发者ID:Jacik,项目名称:ohNet,代码行数:58,代码来源:TestDviDiscovery.cpp

示例8: DoSubscribe

void CpiSubscription::DoSubscribe()
{
    CpStack& cpStack = iDevice.GetCpStack();
    Bws<Uri::kMaxUriBytes> uri;
    uri.Append(Http::kSchemeHttp);
    NetworkAdapter* nif = cpStack.Env().NetworkAdapterList().CurrentAdapter("CpiSubscription::DoSubscribe");
    if (nif == NULL) {
        THROW(NetworkError);
    }
    TIpAddress nifAddr = nif->Address();
    nif->RemoveRef("CpiSubscription::DoSubscribe");
    Endpoint endpt(cpStack.SubscriptionManager().EventServerPort(), nifAddr);
    Endpoint::EndpointBuf buf;
    endpt.AppendEndpoint(buf);
    uri.Append(buf);
    uri.Append('/');
    Uri subscriber(uri);

    LOG(kEvent, "Subscribing - service = ");
    LOG(kEvent, iServiceType.FullName());
    LOG(kEvent, "\n    subscriber = ");
    LOG(kEvent, subscriber.AbsoluteUri());
    LOG(kEvent, "\n");

    iNextSequenceNumber = 0;
    TUint renewSecs;
    try {
        renewSecs = iDevice.Subscribe(*this, subscriber);
    }
    catch (XmlError&) {
        // we don't expect to ever get here.  Its worth capturing some debug info if we do.
        Brh deviceXml;
        if (!iDevice.GetAttribute("Upnp.DeviceXml", deviceXml)) {
            deviceXml.Set("[missing]");
        }
        const Brx& udn = iDevice.Udn();
        cpStack.Env().Mutex().Wait();
        Log::Print("XmlError attempting to subscribe to device ");
        Log::Print(udn);
        Log::Print(", with xml\n\n");
        Log::Print(deviceXml);
        Log::Print("\n\n");
        cpStack.Env().Mutex().Signal();
        THROW(XmlError);
    }

    cpStack.SubscriptionManager().Add(*this);

    LOG(kEvent, "Subscription for ");
    LOG(kEvent, iServiceType.FullName());
    LOG(kEvent, " completed\n    Sid is ");
    LOG(kEvent, iSid);
    LOG(kEvent, "\n    Renew in %u secs\n", renewSecs);

    SetRenewTimer(renewSecs);
}
开发者ID:broonie,项目名称:ohNet,代码行数:56,代码来源:CpiSubscription.cpp

示例9: MakeIpAddress

void DviProtocolUpnp::HandleInterfaceChange()
{
    TBool update = false;
    std::vector<DviProtocolUpnpAdapterSpecificData*> pendingDelete;
    {
        const TIpAddress kLoopbackAddr = MakeIpAddress(127, 0, 0, 1);
        AutoMutex a(iLock);
        NetworkAdapterList& adapterList = iDvStack.Env().NetworkAdapterList();
        AutoNetworkAdapterRef ref(iDvStack.Env(), "DviProtocolUpnp::HandleInterfaceChange");
        const NetworkAdapter* current = ref.Adapter();
        TUint i = 0;
        std::vector<NetworkAdapter*>* subnetList = adapterList.CreateSubnetList();
        std::vector<NetworkAdapter*>* adapters = adapterList.CreateNetworkAdapterList();
        // remove listeners whose interface is no longer available
        while (i<iAdapters.size()) {
            if (FindAdapter(iAdapters[i]->Interface(), *adapters) != -1
                && (!adapterList.SingleSubnetModeEnabled() ||
                (current != NULL && iAdapters[i]->Interface() == current->Address()) ||
                iAdapters[i]->Interface() == kLoopbackAddr)) {
                i++;
            }
            else {
                iAdapters[i]->SetPendingDelete();
                pendingDelete.push_back(iAdapters[i]);
                iAdapters.erase(iAdapters.begin() + i);
            }
        }

        // add listeners for new subnets
        for (i=0; i<subnetList->size(); i++) {
            NetworkAdapter* subnet = (*subnetList)[i];
            if (FindListenerForSubnet(subnet->Subnet()) == -1) {
                AddInterface(*subnet);
                update = iDevice.Enabled();
            }
        }
        NetworkAdapterList::DestroyNetworkAdapterList(adapters);
        NetworkAdapterList::DestroySubnetList(subnetList);
        if (update) {
            // halt any ssdp broadcasts/responses that are currently in progress
            // (in case they're for a subnet that's no longer valid)
            // they'll be advertised again by the SendUpdateNotifications() call below
            iDvStack.SsdpNotifierManager().Stop(iDevice.Udn());
        }
    }

    for (TUint i=0; i<pendingDelete.size(); i++) {
        pendingDelete[i]->Destroy();
    }

    if (update) {
        SendUpdateNotifications();
    }
}
开发者ID:Montellese,项目名称:ohNet,代码行数:54,代码来源:DviProtocolUpnp.cpp

示例10: aCallback

/*
void NetworkAdapterList::TempFailureRetry(Functor& aCallback)
{ // static
    static const TUint kDelaysMs[] = { 100, 200, 400, 800, 1600, 3200, 5000, 10000, 20000, 20000, 30000 }; // roughly 90s worth of retries
    for (TUint i=0; i<sizeof(kDelaysMs)/sizeof(kDelaysMs[0]); i++) {
        try {
            aCallback();
            return;
        }
        catch (NetworkError&) {
            LOG2(kNetwork, kError, "TempFailureRetry: error handling adapter change, try again in %ums\n", kDelaysMs[i]);
            Thread::Sleep(kDelaysMs[i]);
        }
    }
    THROW(NetworkError);
}
*/
std::vector<NetworkAdapter*>* NetworkAdapterList::CreateSubnetListLocked() const
{
    std::vector<NetworkAdapter*>* list = new std::vector<NetworkAdapter*>;
    for (TUint i=0; i<iNetworkAdapters->size(); i++) {
        NetworkAdapter* nif = (*iNetworkAdapters)[i];
        TIpAddress subnet = nif->Subnet();
        if (-1 == NetworkAdapterList::FindSubnet(subnet, *list)) {
            nif->AddRef("NetworkAdapterList");
            list->push_back(nif);
        }
    }
    return list;
}
开发者ID:MatthewMiddleweek,项目名称:ohNet,代码行数:30,代码来源:NetworkAdapterList.cpp

示例11: Suite

SuiteMsearch::SuiteMsearch()
    : Suite("Msearches")
{
    RandomiseUdn(gNameDevice1);
    RandomiseUdn(gNameDevice2);
    RandomiseUdn(gNameDevice2Embedded1);
    iBlocker = new Blocker;
    iListener = new CpListenerMsearch;
    NetworkAdapter* nif = Stack::NetworkAdapterList().CurrentAdapter(kAdapterCookie);
    iListenerUnicast = new SsdpListenerUnicast(*iListener, nif->Address());
    nif->RemoveRef(kAdapterCookie);
    iListenerUnicast->Start();
}
开发者ID:astaykov,项目名称:ohNet,代码行数:13,代码来源:TestDviDiscovery.cpp

示例12: a

void DviServer::SubnetListChanged()
{
    /* DviProtocolUpnp relies on servers being available on all appropriate interfaces.
       We assume this happens through DviServer being created before any devices
       so registering for subnet change notification earlier.  Assuming NetworkAdapterList
       always runs its listeners in the order they registered, we'll have updated before
       any device listeners are run. */

    AutoMutex a(iLock);
    NetworkAdapterList& adapterList = iDvStack.Env().NetworkAdapterList();
    AutoNetworkAdapterRef ref(iDvStack.Env(), "DviServer::SubnetListChanged");
    NetworkAdapter* current = ref.Adapter();
    if (adapterList.SingleSubnetModeEnabled()) {
        TInt i;
        // remove servers whose interface is no longer available
        for (i = (TInt)iServers.size() - 1; i >= 0; i--) {
            DviServer::Server* server = iServers[i];
            if (current == NULL || server->Interface() != current->Address()) {
                delete server;
                iServers.erase(iServers.begin() + i);
            }
        }
        // add server if 'current' is a new subnet
        if (current != NULL && iServers.size() == 0) {
            AddServer(*current);
        }
    }
    else {
        std::vector<NetworkAdapter*>* subnetList = adapterList.CreateSubnetList();
        std::vector<NetworkAdapter*>* nifList = adapterList.CreateNetworkAdapterList();
        TInt i;
        // remove servers whose interface is no longer available
        for (i = (TInt)iServers.size() - 1; i >= 0; i--) {
            DviServer::Server* server = iServers[i];
            if (FindInterface(server->Interface(), *nifList) == -1) {
                delete server;
                iServers.erase(iServers.begin() + i);
            }
        }
        // add servers for new subnets
        for (i = 0; i < (TInt)subnetList->size(); i++) {
            NetworkAdapter* subnet = (*subnetList)[i];
            if (FindServer(subnet->Subnet()) == -1) {
                AddServer(*subnet);
            }
        }
        NetworkAdapterList::DestroyNetworkAdapterList(nifList);
        NetworkAdapterList::DestroySubnetList(subnetList);
    }
}
开发者ID:DoomHammer,项目名称:ohNet,代码行数:50,代码来源:DviServer.cpp

示例13: RandomiseUdn

static void RandomiseUdn(Bwh& aUdn)
{
    aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1);
    aUdn.Append('-');
    Bws<Ascii::kMaxUintStringBytes> buf;
    NetworkAdapter* nif = Stack::NetworkAdapterList().CurrentAdapter(kAdapterCookie);
    TUint max = nif->Address();
    TUint seed = DviStack::ServerUpnp().Port(nif->Address());
    SetRandomSeed(seed);
    nif->RemoveRef(kAdapterCookie);
    (void)Ascii::AppendDec(buf, Random(max));
    aUdn.Append(buf);
    aUdn.PtrZ();
}
开发者ID:astaykov,项目名称:ohNet,代码行数:14,代码来源:TestDviDiscovery.cpp

示例14:

std::vector<NetworkAdapter*>* NetworkAdapterList::CreateNetworkAdapterList() const
{
    iListLock.Wait();

    std::vector<NetworkAdapter*>* list = new std::vector<NetworkAdapter*>;
    for (TUint i=0; i<iNetworkAdapters->size(); i++) {
        NetworkAdapter* nif = (*iNetworkAdapters)[i];
        nif->AddRef("NetworkAdapterList");
        list->push_back(nif);
    }

    iListLock.Signal();
    return list;
}
开发者ID:MatthewMiddleweek,项目名称:ohNet,代码行数:14,代码来源:NetworkAdapterList.cpp

示例15: iRefCount

DviProtocolUpnpAdapterSpecificData::DviProtocolUpnpAdapterSpecificData(DvStack& aDvStack, IUpnpMsearchHandler& aMsearchHandler, const NetworkAdapter& aAdapter, Bwx& aUriBase, TUint aServerPort)
    : iRefCount(1)
    , iDvStack(aDvStack)
    , iMsearchHandler(&aMsearchHandler)
    , iId(0x7fffffff)
    , iSubnet(aAdapter.Subnet())
    , iAdapter(aAdapter.Address())
    , iUriBase(aUriBase)
    , iServerPort(aServerPort)
    , iBonjourWebPage(0)
    , iDevice(NULL)
{
    iListener = &(iDvStack.Env().MulticastListenerClaim(aAdapter.Address()));
    iId = iListener->AddMsearchHandler(this);
}
开发者ID:Jacik,项目名称:ohNet,代码行数:15,代码来源:DviProtocolUpnp.cpp


注:本文中的NetworkAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。