Notifier Engine::notify() const { return Notifier(*this); }
listener::listener(const std::function<void(const payload&)>& function, const string& id): m_notification(Notifier().at(id)), m_ex_function(function) { m_notification.subscribe(this); }
bool Subject::notifyObservers(ObserverMessage * message) { for_each(m_ObserverVec.begin(), m_ObserverVec.end(), Notifier(this, message)); //Return false if there are no observers in the vector return (m_ObserverVec.size() > 0); }
bool Observee::NotifyObservers() { for_each(m_ObserverVec.begin(), m_ObserverVec.end(), Notifier(this)); return (m_ObserverVec.size() > 0); }
NMErr EndpointHander::GetDatagramEP(void) { DEBUG_ENTRY_EXIT("EndpointHander::GetDatagramEP"); CachedEP *datagramEP = NULL; OTLink *acceptorLink = NULL; NMErr status = kNMNoError; // if we're not in uber mode, there should be no datagram ep // just jump to the notifier if (mNewEP->mMode != kNMNormalMode) { Notifier(this, T_BINDCOMPLETE, kNMNoError, NULL); return kNMNoError; } //Try_ { // Get a datagram endpoint from the cache acceptorLink = OTLIFODequeue(&OTEndpoint::sDatagramEPCache.Q); if (acceptorLink) { OTAtomicAdd32(-1, &OTEndpoint::sDatagramEPCache.readyCount); OTAtomicAdd32(-1, &OTEndpoint::sDatagramEPCache.totalCount); //jacked up and good to go mState |= kGotDatagramEP; //get the cache reloading itself OTEndpoint::ServiceEPCaches(); } //if we couldn't get one off the cache, we'll make one after we have a stream endpoint // (one at a time for simplicity) else { if (mState & kGotStreamEP) { return OTAsyncOpenEndpoint(OTCreateConfiguration(mListenerEP->GetDatagramProtocolName()), 0, NULL, mNotifier.fUPP, this); } return kNMNoError; //we just wait for the stream endpoint to get done } // Get the pointer to the cached ep object datagramEP = OTGetLinkObject(acceptorLink, CachedEP, link); op_assert(datagramEP != NULL); // Remove the notifier that was being used for cacheing and install the "normal" one OTRemoveNotifier(datagramEP->ep); OTInstallNotifier(datagramEP->ep, mNotifier.fUPP, this); mNewEP->mDatagramEndpoint->mEP = datagramEP->ep; delete datagramEP; //if we got both endpoints, go ahead and bind here if (mState & kGotStreamEP) { // Bind the endpoint. Execution continues in the notifier for T_BINDCOMPLETE mBindReq.addr.len = 0; mBindReq.addr.buf = NULL; mBindRet.addr = mNewEP->mDatagramEndpoint->mLocalAddress; status = OTBind(mNewEP->mDatagramEndpoint->mEP,NULL, &mBindRet); //status = OTBind(mNewEP->mDatagramEndpoint->mEP,&mBindReq, &mBindRet); DEBUG_NETWORK_API(mNewEP->mDatagramEndpoint->mEP, "OTBind", status); //ThrowIfOSErr_(status); if (status) goto error; } } //Catch_(code) error: if (status) { NMErr code = status; return code; } return kNMNoError; }
static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch(Msg) { case WM_CLOSE: DestroyWindow(Hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_DEVICECHANGE: { //bool Arrival=false; switch(wParam) { case DBT_DEVICEARRIVAL: //Arrival=true; case DBT_DEVICEREMOVECOMPLETE: { auto Pbh = reinterpret_cast<PDEV_BROADCAST_HDR>(lParam); if(Pbh->dbch_devicetype==DBT_DEVTYP_VOLUME) { // currently we don't care what actually happened, "just a notification" is OK //auto Pdv=reinterpret_cast<PDEV_BROADCAST_VOLUME>(Pbh); //bool Media = Pdv->dbcv_flags & DBTF_MEDIA != 0; Notifier().at(devices_notify).notify(std::make_unique<payload>()); } } break; } } break; case WM_SETTINGCHANGE: if(lParam) { if (!StrCmp(reinterpret_cast<LPCWSTR>(lParam),L"Environment")) { if (Global->Opt->UpdateEnvironment) { Notifier().at(environment_notify).notify(std::make_unique<payload>()); } } else if (!StrCmp(reinterpret_cast<LPCWSTR>(lParam),L"intl")) { Notifier().at(intl_notify).notify(std::make_unique<payload>()); } } break; case WM_POWERBROADCAST: switch(wParam) { case PBT_APMPOWERSTATUSCHANGE: // change status case PBT_POWERSETTINGCHANGE: // change percent Notifier().at(power_notify).notify(std::make_unique<payload>()); break; // TODO: // PBT_APMSUSPEND & PBT_APMRESUMEAUTOMATIC handlers } break; } return DefWindowProc(Hwnd, Msg, wParam, lParam); }