📄 provisioninterface.cxx
字号:
parser.findNode(NULL, "key", listOfKeys); for (list < xmlNodePtr > ::iterator itr = listOfKeys.begin(); itr != listOfKeys.end(); itr++) { xmlNodePtr keyNode = (*itr); string regKey = parser.getAttribute(keyNode, "value"); list < xmlNodePtr > listOfContacts; parser.findNode(keyNode, "contact", listOfContacts); VPlanElement vElem(regKey); for (list < xmlNodePtr > ::iterator itr2 = listOfContacts.begin(); itr2 != listOfContacts.end(); itr2++) { xmlNodePtr contactNode = (*itr2); string contactStr = parser.getAttribute(contactNode, "value"); vElem.insertContact(contactStr); } retData.push_back(vElem); }}voidProvisionInterface::registerForUpdateImpl(CallBackFunc func, const string& name){ if (_callBackMap.count(name)) { CallBackList& aList = _callBackMap[name]; if(find(aList.begin(), aList.end(), func) == aList.end()) { cpLog(LOG_INFO, "Adding Callback function for item (%s)", name.c_str()); _callBackMap[name].push_back(func); } else { cpLog(LOG_INFO, "Callback function is already in the list for item (%s)", name.c_str()); } } else { CallBackList aList; aList.push_back(func); _callBackMap[name] = aList; }}voidProvisionInterface::registerForUpdate(CallBackFunc func, const string& name, PContext context){ string group = dirContext(context); char hashkey[512]; sprintf(hashkey, "ITEM_%s_%s", group.c_str(), name.c_str()); registerForUpdateImpl(func, hashkey); // register with the ProvisionServer string hName(_hostName); // Put the listener port where the notification updates would // be received, set the listener port that the PSListener is bound to hName += ":"; char portBuf[56]; sprintf(portBuf, "%d", _listener->getListenerPort()); hName += portBuf; _interface.registerForItem(group, name, hName);}voidProvisionInterface::registerForUpdate(const string& host, int port, CallBackFunc func, PContext context){ // this is actually a group registration that is called for registering // by asking for context (which gets mapped to group) string hName(_hostName); // Put the listener port where the notification updates would // be received, set the listener port that the PSListener is bound to hName += ":"; char portBuf[56]; sprintf(portBuf, "%d", _listener->getListenerPort()); hName += portBuf; char buf[256]; string cntxt = dirContext(context); char hashkey[512]; string group; // If feature is mapped, there are actually two if (context == VFEATURE) { sprintf(buf, "%s_%s_%d_Called", cntxt.c_str(), host.c_str(), port); group = buf; sprintf(hashkey, "GROUP_%s", group.c_str()); registerForUpdateImpl(func, hashkey); _interface.registerForGroup(group, hName); sprintf(buf, "%s_%s_%d_Calling", cntxt.c_str(), host.c_str(), port); group = buf; sprintf(hashkey, "GROUP_%s", group.c_str()); registerForUpdateImpl(func, hashkey); _interface.registerForGroup(group, hName); } else { sprintf(buf, "%s_%s_%d", cntxt.c_str(), host.c_str(), port); group = buf; sprintf(hashkey, "GROUP_%s", group.c_str()); registerForUpdateImpl(func, hashkey); _interface.registerForGroup(group, hName); }}voidProvisionInterface::registerDirForUpdate(CallBackFunc func, const string &group){ // Put the listener port where the notification updates would // be received, set the listener port that the PSListener is bound to string hName(_hostName); hName += ":"; char portBuf[56]; sprintf(portBuf, "%d", _listener->getListenerPort()); hName += portBuf; char hashkey[512]; sprintf(hashkey, "GROUP_%s", group.c_str()); registerForUpdateImpl(func, hashkey); _interface.registerForGroup(group, hName);}voidProvisionInterface::unregisterForUpdateImpl(CallBackFunc func, const string& name){ if (_callBackMap.count(name)) { CallBackList& aList = _callBackMap[name]; for (CallBackList::iterator i = aList.begin(); i != aList.end(); i++) { if ((*i) == func) aList.erase(i); break; } }}voidProvisionInterface::unregisterForUpdate(CallBackFunc func, const string& name, PContext context){ string group = dirContext(context); char hashkey[512]; sprintf(hashkey, "ITEM_%s_%s", group.c_str(), name.c_str()); unregisterForUpdateImpl(func, hashkey); // unregister with the ProvisionServer string hName(_hostName); // Put the listener port where the notification updates would // be received, set the listener port that the PSListener is bound to hName += ":"; char portBuf[56]; sprintf(portBuf, "%d", _listener->getListenerPort()); hName += portBuf; _interface.unregisterForItem(group, name, hName);}voidProvisionInterface::unregisterForUpdate(const string& host, int port, CallBackFunc func, PContext context){ // this is actually a group unregistration that is called for unregistering // by asking for context (which gets mapped to group) string hName(_hostName); // Put the listener port where the notification updates would // be received, set the listener port that the PSListener is bound to hName += ":"; char portBuf[56]; sprintf(portBuf, "%d", _listener->getListenerPort()); hName += portBuf; char buf[256]; string cntxt = dirContext(context); char hashkey[512]; string group; // If feature is mapped, there are actually two if (context == VFEATURE) { sprintf(buf, "%s_%s_%d_Called", cntxt.c_str(), host.c_str(), port); group = buf; sprintf(hashkey, "GROUP_%s", group.c_str()); unregisterForUpdateImpl(func, hashkey); _interface.unregisterForGroup(group, hName); sprintf(buf, "%s_%s_%d_Calling", cntxt.c_str(), host.c_str(), port); group = buf; sprintf(hashkey, "GROUP_%s", group.c_str()); unregisterForUpdateImpl(func, hashkey); _interface.unregisterForGroup(group, hName); } else { sprintf(buf, "%s_%s_%d", cntxt.c_str(), host.c_str(), port); group = buf; sprintf(hashkey, "GROUP_%s", group.c_str()); unregisterForUpdateImpl(func, hashkey); _interface.unregisterForGroup(group, hName); }}voidProvisionInterface::unregisterGroupForUpdate(CallBackFunc func, const string &group){ // Put the listener port where the notification updates would // be received, set the listener port that the PSListener is bound to string hName(_hostName); hName += ":"; char portBuf[56]; sprintf(portBuf, "%d", _listener->getListenerPort()); hName += portBuf; char hashkey[512]; sprintf(hashkey, "GROUP_%s", group.c_str()); unregisterForUpdateImpl(func, hashkey); _interface.unregisterForGroup(group, hName);}voidProvisionInterface::sendUpdateNotification(const string &item, const string &name){ char hashkey[512]; sprintf(hashkey, "ITEM_%s_%s", item.c_str(), name.c_str()); if (_callBackMap.count(hashkey)) { // Update the config update flag if the name is a list of servers updateConfigCallback(name); try { string dRead; if(name != "REGISTERITEM") { dRead = _interface.readItem(item, name); } CallBackList& aList = _callBackMap[hashkey]; cpLog(LOG_DEBUG, "Sending update notice to %d registrant for item (%s,%s)", aList.size(), item.c_str(), name.c_str()); for (CallBackList::iterator i = aList.begin(); i != aList.end(); i++) { (*i)(dRead, name, false); } } catch (VException& e) { cpLog(LOG_ALERT, "sendUpdateNotification failed, reason:%s", e.getDescription().c_str()); } }}voidProvisionInterface::sendUpdateNotification(const string& group, const string& name, bool delflag){ // this function gets called by listener when data is updated // on the server. We check if the data is a list of servers and // if it is, we invalidate the "cache" entry for that data. cpLog(LOG_DEBUG, "Send update dir notification for group (%s)", group.c_str()); char hashkey[512]; sprintf(hashkey, "GROUP_%s", group.c_str()); if (_callBackMap.count(hashkey)) { // Set the config update flag if this is a list of servers updateConfigCallback(name); try { CallBackList& aList = _callBackMap[hashkey]; cpLog(LOG_DEBUG, "Sending update notice to %d registrant for group (%s)", aList.size(), group.c_str()); for (CallBackList::iterator i = aList.begin(); i != aList.end(); i++) { (*i)(name, group, delflag); } } catch (VNetworkException& e) { cpLog(LOG_ALERT, "sendUpdateNotification failed, reason:%s", e.getDescription().c_str()); } }}voidProvisionInterface::sendDeleteNotification(const string &item, const string &name){ char hashkey[512]; sprintf(hashkey, "ITEM_%s_%s", item.c_str(), name.c_str()); if (_callBackMap.count(hashkey)) { //Update the flag if we get a list of servers updateConfigCallback(name); try { CallBackList& aList = _callBackMap[hashkey]; cpLog(LOG_DEBUG, "Sending delete notice to %d registrant for item (%s,%s)", aList.size(), item.c_str(), name.c_str()); for (CallBackList::iterator i = aList.begin(); i != aList.end(); i++) { (*i)("", name, true); } } catch (VNetworkException& e) { cpLog(LOG_ALERT, "sendUpdateNotification failed, reason:%s", e.getDescription().c_str()); } }}voidProvisionInterface::initializeJtapiServerList() throw(VException&){ if (!_jtapiServerGrpCont.needsUpdate()) return ; /// Read the jtapi server list string dRead = _interface.readItem(VSYS_CONF, JTAPI_CONFIG_ITEM); assert(dRead.size()); _jtapiServerGrpCont.initializeMap(dRead);}voidProvisionInterface::initializeFeatureServerList() throw(VException&){ if (!_featureServerGrpCont.needsUpdate()) return ; /// Read the feature server list string dRead = _interface.readItem(VSYS_CONF, FEATURE_CONFIG_ITEM); assert(dRead.size()); _featureServerGrpCont.initializeMap(dRead);}voidProvisionInterface::initializeMarshalServerList() throw(VException&){ if (!_marshalServerGrpCont.needsUpdate()) return ; /// Read the feature server list string dRead = _interface.readItem(VSYS_CONF, MARSHAL_CONFIG_ITEM); assert(dRead.size()); _marshalServerGrpCont.initializeMap(dRead);}voidProvisionInterface::initializeCdrServerList() throw(VException&){ if (!_cdrServerGrpCont.needsUpdate()) return ; /// Read the cdr server list string dRead = _interface.readItem(VSYS_CONF, CDR_CONFIG_ITEM); assert(dRead.size()); _cdrServerGrpCont.initializeMap(dRead);}voidProvisionInterface::initializeHeartbeatServerList() throw(VException&){ if (!_heartbeatServerGrpCont.needsUpdate()) return ; /// Read the heartbeat server list string dRead = _interface.readItem(VSYS_CONF, HEARTBEAT_CONFIG_ITEM); assert(dRead.size()); _heartbeatServerGrpCont.initializeMap(dRead);}voidProvisionInterface::initializeRedirectServerList() throw(VException&){ if (!_redirectServerGrpCont.needsUpdate()) return ; /// Read the redirect server list string dRead = _interface.readItem(VSYS_CONF, REDIRECT_CONFIG_ITEM); assert(dRead.size()); _redirectServerGrpCont.initializeMap(dRead);}voidProvisionInterface::initializePolicyServerList() throw(VException&){ if (!_policyServerGrpCont.needsUpdate()) return ; /// Read the policy server list string dRead = _interface.readItem(VSYS_CONF, POLICY_CONFIG_ITEM); assert(dRead.size()); _policyServerGrpCont.initializeMap(dRead);}stringProvisionInterface::dirContext(PContext context){ string cntxt; switch (context) { case ProvisionInterface::VFEATURE: cntxt = VFEATURES; break; case ProvisionInterface::VREDIRECT: cntxt = VRSERVERS; break; case ProvisionInterface::VJTAPI: cntxt = VJTAPIS; break; case ProvisionInterface::VLOCATION: cntxt = VLOCATIONS; break; case ProvisionInterface::VMARSHAL: cntxt = VMARSHALS; break; case ProvisionInterface::VCDR: cntxt = VCDRS; break; case ProvisionInterface::VCONFIG: cntxt = VSYS_CONF; break; case ProvisionInterface::VPOLICY: cntxt = VPOLICIES; break; case ProvisionInterface::VNONE: cntxt = ""; break; default: assert(0); break; } return cntxt;}/// Function call to invalidate the local cached copies of the lists.voidProvisionInterface::updateConfigCallback(const string& name){ // This is called when an update is received to invalidate the local // cached copies of each of the list of servers. if (name.find(FEATURE_CONFIG_ITEM) != string::npos) { _featureServerGrpCont.markForUpdate(); } else if (name.find(MARSHAL_CONFIG_ITEM) != string::npos) { _marshalServerGrpCont.markForUpdate(); } else if (name.find(REDIRECT_CONFIG_ITEM) != string::npos) { _redirectServerGrpCont.markForUpdate(); } else if (name.find(CDR_CONFIG_ITEM) != string::npos) { _cdrServerGrpCont.markForUpdate(); } else if (name.find(JTAPI_CONFIG_ITEM) != string::npos) { _jtapiServerGrpCont.markForUpdate(); } else if (name.find(POLICY_CONFIG_ITEM) != string::npos) { _policyServerGrpCont.markForUpdate(); }}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -