PushObjectManager.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "PushObjectManager.h"
  2. #include "AllObjectManagerUtil.h"
  3. #include "ErrorCode.h"
  4. #include "Poco/Exception.h"
  5. #include "Util.h"
  6. #include "PhmsLogger.h"
  7. #include "MsgListPush.h"
  8. using Poco::FileNotFoundException;
  9. map<string, CPushBase*> CPushObjectManager::m_map;
  10. int CPushObjectManager::InsertPushMsgListObject(string stringUuid, string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgType, string stringMsgDirection, string stringVersion,
  11. pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback)
  12. {
  13. Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
  14. CPushBase* pNetInterface = NULL;
  15. try
  16. {
  17. pNetInterface = new CMsgListPush(stringUuid, stringSenderId, stringCaseId, stringCaseType, stringMsgType, stringMsgDirection, stringVersion, pCallback, pFailCallback);
  18. }
  19. catch(FileNotFoundException& e)
  20. {
  21. CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
  22. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_NET_CONFIG_FILE), __FUNCTION__, __FILE__, __LINE__);
  23. return COMMON_NO_NET_CONFIG_FILE;
  24. }
  25. catch(Exception& e)
  26. {
  27. CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
  28. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NET_CONFIG_READ_ERROR), __FUNCTION__, __FILE__, __LINE__);
  29. return COMMON_NET_CONFIG_READ_ERROR;
  30. }
  31. m_map.insert(map<string, CPushBase*>::value_type(stringUuid, pNetInterface));
  32. string stringSessionId;
  33. if(CNetThreadManager::m_map.size() != 0)
  34. {
  35. map<string, CExternalNetInterface*>::const_iterator iter;
  36. for(iter=CNetThreadManager::m_map.begin(); iter!=CNetThreadManager::m_map.end(); iter++)
  37. {
  38. if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
  39. {
  40. stringSessionId = iter->second->GetSessionId();
  41. pNetInterface->SetSessionId(stringSessionId);
  42. break;
  43. }
  44. }
  45. }
  46. else
  47. {
  48. map<string, CPushBase*>::const_iterator iter;
  49. for(iter=CPushObjectManager::m_map.begin(); iter!=CPushObjectManager::m_map.end(); iter++)
  50. {
  51. if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
  52. {
  53. stringSessionId = iter->second->GetSessionId();
  54. pNetInterface->SetSessionId(stringSessionId);
  55. break;
  56. }
  57. }
  58. }
  59. if(stringSessionId.size() == 0)
  60. {
  61. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_VALID_SESSIONID), __FUNCTION__, __FILE__, __LINE__);
  62. return COMMON_NO_VALID_SESSIONID;
  63. }
  64. return PHMS_SUCCESSFUL_RESULT;
  65. }
  66. int CPushObjectManager::DeletePushObject(string stringUuid)
  67. {
  68. Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
  69. CPushBase* pNetInterface = NULL;
  70. if(m_map.find(stringUuid) != m_map.end())
  71. {
  72. pNetInterface = m_map[stringUuid];
  73. }
  74. if(pNetInterface != NULL)
  75. {
  76. pNetInterface->EndPush();
  77. m_map.erase(stringUuid);
  78. delete pNetInterface;
  79. return PHMS_SUCCESSFUL_RESULT;
  80. }
  81. else
  82. {
  83. return COMMON_INVALID_HANDLE;
  84. }
  85. }
  86. int CPushObjectManager::GetSessionId(string& stringSessionId)
  87. {
  88. Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
  89. map<string, CPushBase*>::const_iterator iter;
  90. for(iter=m_map.begin(); iter!=m_map.end(); iter++)
  91. {
  92. if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
  93. {
  94. stringSessionId = iter->second->GetSessionId();
  95. break;
  96. }
  97. }
  98. if(iter == m_map.end())
  99. {
  100. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_VALID_SESSIONID), __FUNCTION__, __FILE__, __LINE__);
  101. return COMMON_NO_VALID_SESSIONID;
  102. }
  103. return PHMS_SUCCESSFUL_RESULT;
  104. }
  105. int CPushObjectManager::SetSessionId(string stringSessionId)
  106. {
  107. HandleSessionSync(stringSessionId);
  108. return PHMS_SUCCESSFUL_RESULT;
  109. }
  110. void CPushObjectManager::HandleSessionSync(string stringSessionId)
  111. {
  112. Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
  113. map<string, CPushBase*>::iterator iter;
  114. for(iter=m_map.begin(); iter!=m_map.end(); iter++)
  115. {
  116. iter->second->SetSessionId(stringSessionId);
  117. }
  118. return;
  119. }
  120. bool CPushObjectManager::SomeTypePushIsRun(int nPushType)
  121. {
  122. Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
  123. map<string, CPushBase*>::iterator iter;
  124. for(iter=m_map.begin(); iter!=m_map.end(); iter++)
  125. {
  126. if(iter->second->GetPushType() == nPushType)
  127. {
  128. return true;
  129. }
  130. }
  131. return false;
  132. }