void CEsperEngine::DeleteListener (const SArchonMessage &Msg) // DeleteListener // // Deletes the listener { CSmartLock Lock(m_cs); // Get the name CString sName = Msg.dPayload.GetElement(0); // Find the listener int iIndex; if (!FindListener(sName, &iIndex)) { // If we're in shutdown, then it is OK that we can't find // a listener. Otherwise we return an error if (!m_bShutdown) SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(ERR_LISTENER_NOT_FOUND, sName), Msg); return; } // Ask the listener to stop m_Listeners[iIndex]->SignalShutdown(); // Done (we will reply when the thread shuts down) }
void TMessageSystem::Unsubscribe(const ComponentHandle& source, const ComponentHandle& listener, const MessageID& messageId) { auto listenersIt = routingTable.find(source); if (listenersIt == routingTable.end()) { return; } auto listenerIt = FindListener(listenersIt->second, listener); if (listenerIt == listenersIt->second.end()) { return; } auto& subscriptions = listenerIt->second; const auto subscritpionIt = FindSubscription(subscriptions, messageId); if (subscritpionIt != subscriptions.end()) { subscriptions.erase(subscritpionIt); } if (subscriptions.empty() == true) { listenersIt->second.erase(listenerIt); } if (listenersIt->second.empty() == true) { routingTable.erase(listenersIt); } }
bool EventTarget::RemoveTemporaryListener(int32 token) { int32 index; event_listener* listener = FindListener(token, &index); if (listener == NULL) return false; return _RemoveTemporaryListener(listener, index); }
void CEsperEngine::MsgEsperStartListener (const SArchonMessage &Msg) // MsgEsperStartListener // // Esper.startListener {name} {port} [{protocol}] { CSmartLock Lock(m_cs); // If we're in shutdown, then ignore this message if (m_bShutdown) return; // Get some parameters CString sName = Msg.dPayload.GetElement(0); CString sProtocol = Msg.dPayload.GetElement(2); // Get the type from the protocol CEsperConnection::ETypes iType; if (sProtocol.IsEmpty() || strEquals(sProtocol, PROTOCOL_RAW)) iType = CEsperConnection::typeRawIn; else if (strEquals(sProtocol, PROTOCOL_AMP1)) iType = CEsperConnection::typeAMP1In; else if (strEquals(sProtocol, PROTOCOL_TLS)) iType = CEsperConnection::typeTLSIn; else { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(ERR_UNKNOWN_PROTOCOL, sProtocol), Msg); return; } // Make sure that we don't already have a listener with this name if (sName.IsEmpty() || FindListener(sName)) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, (sName.IsEmpty() ? ERR_INVALID_LISTENER_NAME : ERR_DUPLICATE_LISTENER_NAME), Msg); return; } // Add a new thread (array takes ownership of the context) CEsperListenerThread *pThread = new CEsperListenerThread(this, iType, Msg); m_Listeners.Insert(pThread); pThread->Start(); }
void TMessageSystem::Unsubscribe(const ComponentHandle& listener) { for (auto it = routingTable.begin(); it != routingTable.end();) { const auto listenerIt = FindListener(it->second, listener); if (listenerIt != it->second.end()) { it->second.erase(listenerIt); } if (it->second.empty() == true) { it = routingTable.erase(it); } else { ++it; } } }
void TMessageSystem::Subscribe(const ComponentHandle& source, const ComponentHandle& listener, const MessageID& messageId, const MessageCallback& callback) { ASSERT(static_cast<bool>(callback) != false, "Wrong callback function."); ASSERT(source != listener, "Can not subscribe component to himself."); auto& listeners = routingTable[source]; const auto it = FindListener(listeners, listener); if (it != listeners.end()) { it->second.emplace_back(messageId, callback); } else { listeners.emplace_back(listener, Subscriptions{ Subscription(messageId, callback) }); } }
void TMessageSystem::Unsubscribe(const ComponentHandle& source, const ComponentHandle& listener) { auto listenersIt = routingTable.find(source); if (listenersIt == routingTable.end()) { return; } const auto listenerIt = FindListener(listenersIt->second, listener); if (listenerIt != listenersIt->second.end()) { listenersIt->second.erase(listenerIt); } if (listenersIt->second.empty() == true) { routingTable.erase(listenersIt); } }
bool EventTarget::RemoveListener(int32 token) { int32 index; event_listener* listener = FindListener(token, &index); if (listener == NULL) return false; if (listener->temporary_event_mask != 0) { // we still need this event listener->event_mask = 0; listener->options = 0; return false; } fListeners.RemoveItemAt(index); delete listener; return true; }