本文整理汇总了C++中NetworkAdapter::RemoveRef方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkAdapter::RemoveRef方法的具体用法?C++ NetworkAdapter::RemoveRef怎么用?C++ NetworkAdapter::RemoveRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkAdapter
的用法示例。
在下文中一共展示了NetworkAdapter::RemoveRef方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Init
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;
}
示例2: IsLocationReachable
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;
}
示例3: SubnetListChanged
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);
}
示例4: Test
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;
}
示例5: HandleInterfaceChange
void CpiDeviceListUpnp::HandleInterfaceChange(TBool aNewSubnet)
{
NetworkAdapter* current = iCpStack.Env().NetworkAdapterList().CurrentAdapter("CpiDeviceListUpnp::HandleInterfaceChange");
if (aNewSubnet && current != NULL && current->Address() == iInterface) {
// list of subnets has changed but our interface is still available so there's nothing for us to do here
current->RemoveRef("CpiDeviceListUpnp::HandleInterfaceChange");
return;
}
iNextRefreshTimer->Cancel();
iCpStack.Env().Mutex().Wait();
iPendingRefreshCount = 0;
iCpStack.Env().Mutex().Signal();
StopListeners();
if (current == NULL) {
iLock.Wait();
iInterface = 0;
iLock.Signal();
RemoveAll();
return;
}
// we used to only remove devices for subnet changes
// its not clear why this was correct - any interface change will result in control/event urls changing
RemoveAll();
iLock.Wait();
iInterface = current->Address();
iLock.Signal();
TUint msearchTime = iCpStack.Env().InitParams().MsearchTimeSecs();
Mutex& lock = iCpStack.Env().Mutex();
lock.Wait();
iPendingRefreshCount = (kMaxMsearchRetryForNewAdapterSecs + msearchTime - 1) / (2 * msearchTime);
lock.Signal();
current->RemoveRef("CpiDeviceListUpnp::HandleInterfaceChange");
iSsdpLock.Wait();
iUnicastListener = new SsdpListenerUnicast(iCpStack.Env(), *this, iInterface);
iUnicastListener->Start();
iMulticastListener = &(iCpStack.Env().MulticastListenerClaim(iInterface));
iNotifyHandlerId = iMulticastListener->AddNotifyHandler(this);
iSsdpLock.Signal();
Refresh();
}
示例6: 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);
}
示例7: 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();
}
示例8: 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();
}
示例9: HandleInterfaceChange
void CpiDeviceListUpnp::HandleInterfaceChange()
{
NetworkAdapter* current = iCpStack.Env().NetworkAdapterList().CurrentAdapter("CpiDeviceListUpnp::HandleInterfaceChange");
if (current != NULL && current->Address() == iInterface) {
// list of subnets has changed but our interface is still available so there's nothing for us to do here
current->RemoveRef("CpiDeviceListUpnp::HandleInterfaceChange");
return;
}
StopListeners();
if (current == NULL) {
iLock.Wait();
iInterface = 0;
iLock.Signal();
RemoveAll();
return;
}
// we used to only remove devices for subnet changes
// its not clear why this was correct - any interface change will result in control/event urls changing
RemoveAll();
iLock.Wait();
iInterface = current->Address();
iLock.Signal();
current->RemoveRef("CpiDeviceListUpnp::HandleInterfaceChange");
{
AutoMutex a(iSsdpLock);
iUnicastListener = new SsdpListenerUnicast(iCpStack.Env(), *this, iInterface);
iUnicastListener->Start();
iMulticastListener = &(iCpStack.Env().MulticastListenerClaim(iInterface));
iNotifyHandlerId = iMulticastListener->AddNotifyHandler(this);
}
Refresh();
}
示例10: CurrentAdapterChanged
void MdnsPlatform::CurrentAdapterChanged()
{
iInterfacesLock.Wait();
NetworkAdapter* current = iEnv.NetworkAdapterList().CurrentAdapter(kNifCookie);
NetworkAdapterList& nifList = iEnv.NetworkAdapterList();
std::vector<NetworkAdapter*>* subnetList = nifList.CreateSubnetList();
if (current != NULL) {
// Remove existing interface(s) if not belonging to current adapter,
// then add current adapter if it didn't exist before.
for (TInt i=(TInt)iInterfaces.size()-1; i>=0; i--) {
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 (iInterfaces.size() == 0) { // current adapter is on a newly added subnet
AddInterface(current);
}
// Set multicast iface in case current adapter was previously in a list
// subnets so no multicast iface was set.
iClient.SetMulticastIf(current->Address());
current->RemoveRef(kNifCookie);
}
else {
// No adapter selected.
// First, check if selected interface should be removed.
for (TInt i=(TInt)iInterfaces.size()-1; i>=0; i--) {
if (InterfaceIndex(iInterfaces[i]->Adapter(), *subnetList) == -1) {
mDNS_DeregisterInterface(iMdns, &iInterfaces[i]->Info(), false);
delete iInterfaces[i];
iInterfaces.erase(iInterfaces.begin()+i);
}
}
// Then, re-add all subnets that aren't already added.
for (TUint i=0; i<(TUint)subnetList->size(); i++) {
NetworkAdapter* nif = (*subnetList)[i];
if (InterfaceIndex(*nif) == -1) {
AddInterface(nif);
}
}
}
iInterfacesLock.Signal();
nifList.DestroySubnetList(subnetList);
}
示例11: LogUdn
TBool CpListenerMsearch::LogUdn(const Brx& aUuid, const Brx& aLocation)
{
Uri uri(aLocation);
Endpoint endpt(0, uri.Host());
NetworkAdapter* nif = iEnv.NetworkAdapterList().CurrentAdapter(kAdapterCookie);
TBool correctSubnet = nif->ContainsAddress(endpt.Address());
nif->RemoveRef(kAdapterCookie);
if (!correctSubnet) {
#if 0
Print("Discarding advertisement from ");
Print(aUuid);
Endpoint::EndpointBuf buf;
endpt.AppendEndpoint(buf);
Print(" at %s\n", buf.Ptr());
#endif
return false;
}
if (aUuid == SuiteMsearch::gNameDevice1){
iUdnsReceived |= 1;
}
else if (aUuid == SuiteMsearch::gNameDevice2){
iUdnsReceived |= 2;
}
else if (aUuid == SuiteMsearch::gNameDevice2Embedded1) {
iUdnsReceived |= 4;
}
else {
#if 0
Print("Didn't match advertisement from ");
Print(aUuid);
Endpoint::EndpointBuf buf;
endpt.AppendEndpoint(buf);
Print(" at %s\n", buf.Ptr());
#endif
return false;
}
iTotal++;
return true;
}
示例12: Suite
SuiteMsearch::SuiteMsearch(DvStack& aDvStack)
: Suite("Msearches")
, iDvStack(aDvStack)
{
RandomiseUdn(iDvStack.Env(), gNameDevice1);
RandomiseUdn(iDvStack.Env(), gNameDevice2);
RandomiseUdn(iDvStack.Env(), gNameDevice2Embedded1);
Print("UDNs: \n ");
Print(gNameDevice1);
Print("\n ");
Print(gNameDevice2);
Print("\n ");
Print(gNameDevice2Embedded1);
Print("\n\n");
Environment& env = iDvStack.Env();
iBlocker = new Blocker(env);
iListener = new CpListenerMsearch(env);
NetworkAdapter* nif = env.NetworkAdapterList().CurrentAdapter(kAdapterCookie);
iListenerUnicast = new SsdpListenerUnicast(env, *iListener, nif->Address());
nif->RemoveRef(kAdapterCookie);
iListenerUnicast->Start();
}
示例13: OhNetNetworkAdapterRemoveRef
void STDCALL OhNetNetworkAdapterRemoveRef(OhNetHandleNetworkAdapter aNif, const char* aCookie)
{
NetworkAdapter* nif = reinterpret_cast<NetworkAdapter*>(aNif);
ASSERT(nif != NULL);
return nif->RemoveRef(aCookie);
}
示例14: HandleInterfaceListChanged
//.........这里部分代码省略.........
std::vector<NetworkAdapter*> oldSubnetsObj(iSubnets->begin(), iSubnets->end());
std::vector<NetworkAdapter*> newSubnetsObj(subnets->begin(), subnets->end());
std::vector<NetworkAdapter*>* oldSubnets = &oldSubnetsObj;
std::vector<NetworkAdapter*>* newSubnets = &newSubnetsObj;
std::vector<NetworkAdapter*> added;
std::vector<NetworkAdapter*> removed;
std::vector<NetworkAdapter*> adapterChanged;
std::sort(oldSubnets->begin(), oldSubnets->end(), CompareSubnets);
std::sort(newSubnets->begin(), newSubnets->end(), CompareSubnets);
if (oldSubnets->size() == 0 && newSubnets->size() > 0) {
for (TUint i=0; i < newSubnets->size(); i++) {
added.push_back((*newSubnets)[i]);
}
}
else if (oldSubnets->size() > 0 && newSubnets->size() == 0) {
for (TUint i=0; i < oldSubnets->size(); i++) {
NetworkAdapter* removedAdapter = (*oldSubnets)[i];
removed.push_back(removedAdapter);
removedAdapter->AddRef(kRemovedAdapterCookie); // DestroySubnetList(iSubnets) may destroy the last ref to this before QueueAdapterRemoved later claims a new ref
}
}
else {
TUint j = 0;
for (TUint i=0; i < newSubnets->size(); i++) {
while (j < oldSubnets->size() && (*oldSubnets)[j]->Subnet() < (*newSubnets)[i]->Subnet()) {
NetworkAdapter* removedAdapter = (*oldSubnets)[j];
removed.push_back(removedAdapter);
removedAdapter->AddRef(kRemovedAdapterCookie);
j++;
}
if (j < oldSubnets->size() && (*oldSubnets)[j]->Subnet() == (*newSubnets)[i]->Subnet()) {
if ((*oldSubnets)[j]->Address() != (*newSubnets)[i]->Address()) {
adapterChanged.push_back((*newSubnets)[i]);
}
j++;
}
}
if (j < oldSubnets->size()) {
while (j < oldSubnets->size()) {
NetworkAdapter* removedAdapter = (*oldSubnets)[j];
removed.push_back(removedAdapter);
removedAdapter->AddRef(kRemovedAdapterCookie);
j++;
}
}
j = 0;
for (TUint i=0; i < oldSubnets->size(); i++) {
while (j < newSubnets->size() && (*newSubnets)[j]->Subnet() < (*oldSubnets)[i]->Subnet()) {
added.push_back((*newSubnets)[j]);
j++;
}
if (j < newSubnets->size() && (*newSubnets)[j]->Subnet() == (*oldSubnets)[i]->Subnet()) {
j++;
}
}
if (j < newSubnets->size()) {
while (j < newSubnets->size()) {
added.push_back((*newSubnets)[j]);
j++;
}
}
}
DestroySubnetList(iSubnets);
iSubnets = subnets;
iListLock.Signal();
if (subnetsChanged) {
iNotifierThread->QueueSubnetsChanged();
}
else if (newAddress != oldAddress) {
iNotifierThread->QueueCurrentChanged();
}
// Notify added/removed callbacks.
if (removed.size() > 0) {
for (TUint i=0; i < removed.size(); i++) {
NetworkAdapter* removedAdapter = removed[i];
TraceAdapter("NetworkAdapter removed", *removedAdapter);
iNotifierThread->QueueAdapterRemoved(*removedAdapter);
removedAdapter->RemoveRef(kRemovedAdapterCookie);
}
}
if (added.size() > 0) {
for (TUint i=0; i < added.size(); i++) {
TraceAdapter("NetworkAdapter added", *added[i]);
iNotifierThread->QueueAdapterAdded(*added[i]);
}
}
// Notify network adapter changed callbacks.
if (adapterChanged.size() > 0) {
for (TUint i=0; i < adapterChanged.size(); i++) {
TraceAdapter("NetworkAdapter changed", *adapterChanged[i]);
iNotifierThread->QueueAdapterChanged(*adapterChanged[i]);
}
}
}