📄 sippresencemonitor.cpp
字号:
{ bool requiredPublish = false; if (mPresenceEventList.find(&contact) == NULL) { requiredPublish = true; OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipPresenceMonitor::addPresenceEvent adding the presenceEvent %p for contact %s", presenceEvent, contact.data()); } else { OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipPresenceMonitor::addPresenceEvent presenceEvent %p for contact %s already exists, just update the content.", presenceEvent, contact.data()); // Get the object from the presence event list UtlContainable* oldKey; UtlContainable* foundValue; foundValue = mPresenceEventList.findValue(&contact); SipPresenceEvent* oldPresenceEvent = dynamic_cast <SipPresenceEvent *> (foundValue); UtlString oldStatus, status; UtlString id; NetMd5Codec::encode(contact, id); oldPresenceEvent->getTuple(id)->getStatus(oldStatus); presenceEvent->getTuple(id)->getStatus(status); if (status.compareTo(oldStatus) != 0) { requiredPublish = true; oldKey = mPresenceEventList.removeKeyAndValue(&contact, foundValue); delete oldKey; OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipPresenceMonitor::addPresenceEvent remove the presenceEvent %p for contact %s", oldPresenceEvent, contact.data()); int numOldContents; HttpBody* oldContent[1]; // Unpublish the content to the subscribe server if (!mSipPublishContentMgr.unpublish(contact.data(), PRESENCE_EVENT_TYPE, PRESENCE_EVENT_TYPE, 1, numOldContents, oldContent)) { UtlString presenceContent; int length; oldPresenceEvent->getBytes(&presenceContent, &length); OsSysLog::add(FAC_SIP, PRI_ERR, "SipPresenceMonitor::publishContent PresenceEvent %s\n was not successfully unpublished from the subscribe server", presenceContent.data()); } if (oldPresenceEvent) { delete oldPresenceEvent; } } else { delete presenceEvent; } } if (requiredPublish) { // Insert it into the presence event list presenceEvent->buildBody(); mPresenceEventList.insertKeyAndValue(new UtlString(contact), presenceEvent); if (mToBePublished) { // Publish the content to the resource list publishContent(contact, presenceEvent); } // Notify the state change notifyStateChange(contact, presenceEvent); } return requiredPublish;}void SipPresenceMonitor::publishContent(UtlString& contact, SipPresenceEvent* presenceEvent){#ifdef SUPPORT_RESOURCE_LIST bool contentChanged; // Loop through all the resource lists UtlHashMapIterator iterator(mMonitoredLists); UtlString* listUri; SipResourceList* list; Resource* resource; UtlString id, state; while (listUri = dynamic_cast <UtlString *> (iterator())) { contentChanged = false; list = dynamic_cast <SipResourceList *> (mMonitoredLists.findValue(listUri)); OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipPresenceMonitor::publishContent listUri %s list %p", listUri->data(), list); // Search for the contact in this list resource = list->getResource(contact); if (resource) { resource->getInstance(id, state); if (presenceEvent->isEmpty()) { resource->setInstance(id, STATE_TERMINATED); } else { UtlString id; NetMd5Codec::encode(contact, id); Tuple* tuple = presenceEvent->getTuple(id); UtlString status; tuple->getStatus(status); if (status.compareTo(STATUS_CLOSE) == 0) { resource->setInstance(id, STATE_TERMINATED); } else { resource->setInstance(id, STATE_ACTIVE); } } list->buildBody(); contentChanged = true; } if (contentChanged) { int numOldContents; HttpBody* oldContent[1]; // Publish the content to the subscribe server if (!mSipPublishContentMgr.publish(listUri->data(), PRESENCE_EVENT_TYPE, PRESENCE_EVENT_TYPE, 1, (HttpBody**)&list, 1, numOldContents, oldContent)) { UtlString presenceContent; int length; list->getBytes(&presenceContent, &length); OsSysLog::add(FAC_SIP, PRI_ERR, "SipPresenceMonitor::publishContent PresenceEvent %s\n was not successfully published to the subscribe server", presenceContent.data()); } } }#endif int numOldContents; HttpBody* oldContent[1]; // Publish the content to the subscribe server if (!mSipPublishContentMgr.publish(contact.data(), PRESENCE_EVENT_TYPE, PRESENCE_EVENT_TYPE, 1, (HttpBody**)&presenceEvent, 1, numOldContents, oldContent)) { UtlString presenceContent; int length; presenceEvent->getBytes(&presenceContent, &length); OsSysLog::add(FAC_SIP, PRI_ERR, "SipPresenceMonitor::publishContent PresenceEvent %s\n was not successfully published to the subscribe server", presenceContent.data()); }}void SipPresenceMonitor::addStateChangeNotifier(const char* fileUrl, StateChangeNotifier* notifier){ mLock.acquire(); UtlString* name = new UtlString(fileUrl); UtlVoidPtr* value = new UtlVoidPtr(notifier); mStateChangeNotifiers.insertKeyAndValue(name, value); mLock.release();}void SipPresenceMonitor::removeStateChangeNotifier(const char* fileUrl){ mLock.acquire(); UtlString name(fileUrl); mStateChangeNotifiers.destroy(&name); mLock.release();}void SipPresenceMonitor::notifyStateChange(UtlString& contact, SipPresenceEvent* presenceEvent){ // Loop through the notifier list UtlHashMapIterator iterator(mStateChangeNotifiers); UtlString* listUri; StateChangeNotifier* notifier; Url contactUrl(contact); mLock.acquire(); while (listUri = dynamic_cast <UtlString *> (iterator())) { notifier = dynamic_cast <StateChangeNotifier *> (mStateChangeNotifiers.findValue(listUri)); if (presenceEvent->isEmpty()) { notifier->setStatus(contactUrl, StateChangeNotifier::AWAY); } else { UtlString id; NetMd5Codec::encode(contact, id); Tuple* tuple = presenceEvent->getTuple(id); UtlString status; tuple->getStatus(status); if (status.compareTo(STATUS_CLOSE) == 0) { notifier->setStatus(contactUrl, StateChangeNotifier::AWAY); } else { notifier->setStatus(contactUrl, StateChangeNotifier::PRESENT); } } } mLock.release();}bool SipPresenceMonitor::setStatus(const Url& aor, const Status value){ bool result = false; UtlString contact; aor.getUserId(contact); contact += mHostAndPort; // Create a presence event package and store it in the publisher SipPresenceEvent* sipPresenceEvent = new SipPresenceEvent(contact); UtlString id; NetMd5Codec::encode(contact, id); Tuple* tuple = new Tuple(id.data()); if (value == StateChangeNotifier::PRESENT) { tuple->setStatus(STATUS_OPEN); tuple->setContact(contact, 1.0); } else { if (value == StateChangeNotifier::AWAY) { tuple->setStatus(STATUS_CLOSE); tuple->setContact(contact, 1.0); } } sipPresenceEvent->insertTuple(tuple); // Add the SipPresenceEvent object to the subscribe list result = addPresenceEvent(contact, sipPresenceEvent); return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -