WH 6 vuotta sitten
commit
3d581b32c6
83 muutettua tiedostoa jossa 43837 lisäystä ja 0 poistoa
  1. 62 0
      AllObjectManagerUtil.cpp
  2. 23 0
      AllObjectManagerUtil.h
  3. 826 0
      CommonNetInterface.cpp
  4. 663 0
      CommonNetInterface.h
  5. 1 0
      DeviceNetInterface.cpp
  6. 1 0
      DeviceNetInterface.h
  7. 1170 0
      DoctorNetInterface.cpp
  8. 1113 0
      DoctorNetInterface.h
  9. 59 0
      DownloadThreadCallback.cpp
  10. 32 0
      DownloadThreadCallback.h
  11. 109 0
      DownloadTimerCallback.cpp
  12. 28 0
      DownloadTimerCallback.h
  13. 88 0
      ErrorCode.h
  14. 3184 0
      ExternalNetInterface.cpp
  15. 278 0
      ExternalNetInterface.h
  16. 9 0
      GlobalTerminalLogoString.h
  17. 47 0
      HandleMutexManager.cpp
  18. 21 0
      HandleMutexManager.h
  19. 402 0
      HttpPushSession.cpp
  20. 45 0
      HttpPushSession.h
  21. 1228 0
      HttpSession.cpp
  22. 67 0
      HttpSession.h
  23. 4947 0
      InternalNetIntetface.cpp
  24. 435 0
      InternalNetIntetface.h
  25. 41 0
      MsgListPush.cpp
  26. 22 0
      MsgListPush.h
  27. 178 0
      NetConfig.cpp
  28. 65 0
      NetConfig.h
  29. 213 0
      NetThreadManager.cpp
  30. 34 0
      NetThreadManager.h
  31. 299 0
      PhmsDataType.h
  32. 474 0
      PhmsHttp.vcproj
  33. 65 0
      PhmsHttp.vcproj.wh-PC.wh.user
  34. 147 0
      PhmsLogger.cpp
  35. 23 0
      PhmsLogger.h
  36. 326 0
      PhmsPushSession.cpp
  37. 46 0
      PhmsPushSession.h
  38. 147 0
      PhmsRequest.cpp
  39. 40 0
      PhmsRequest.h
  40. 49 0
      PhmsRequestBody.cpp
  41. 20 0
      PhmsRequestBody.h
  42. 125 0
      PhmsRequestHead.cpp
  43. 57 0
      PhmsRequestHead.h
  44. 402 0
      PhmsResponse.cpp
  45. 33 0
      PhmsResponse.h
  46. 175 0
      PhmsResponseBody.cpp
  47. 27 0
      PhmsResponseBody.h
  48. 120 0
      PhmsResponseHead.cpp
  49. 63 0
      PhmsResponseHead.h
  50. 13844 0
      PhmsSession.cpp
  51. 446 0
      PhmsSession.h
  52. 43 0
      PushBase.cpp
  53. 31 0
      PushBase.h
  54. 144 0
      PushObjectManager.cpp
  55. 17 0
      PushObjectManager.h
  56. 51 0
      SessionIdManager.cpp
  57. 16 0
      SessionIdManager.h
  58. 151 0
      TelecomHealthInterface.cpp
  59. 213 0
      TelecomHealthInterface.h
  60. 59 0
      UploadTimerCallback.cpp
  61. 24 0
      UploadTimerCallback.h
  62. 1348 0
      UserNetInterface.cpp
  63. 1175 0
      UserNetInterface.h
  64. 1100 0
      Util.cpp
  65. 48 0
      Util.h
  66. 309 0
      WithinHospitalNetInterface.cpp
  67. 285 0
      WithinHospitalNetInterface.h
  68. 19 0
      jsoncpp-src-0.5.0/include/json/autolink.h
  69. 43 0
      jsoncpp-src-0.5.0/include/json/config.h
  70. 42 0
      jsoncpp-src-0.5.0/include/json/features.h
  71. 39 0
      jsoncpp-src-0.5.0/include/json/forwards.h
  72. 10 0
      jsoncpp-src-0.5.0/include/json/json.h
  73. 196 0
      jsoncpp-src-0.5.0/include/json/reader.h
  74. 1069 0
      jsoncpp-src-0.5.0/include/json/value.h
  75. 174 0
      jsoncpp-src-0.5.0/include/json/writer.h
  76. 125 0
      jsoncpp-src-0.5.0/src/lib_json/json_batchallocator.h
  77. 448 0
      jsoncpp-src-0.5.0/src/lib_json/json_internalarray.inl
  78. 607 0
      jsoncpp-src-0.5.0/src/lib_json/json_internalmap.inl
  79. 885 0
      jsoncpp-src-0.5.0/src/lib_json/json_reader.cpp
  80. 1718 0
      jsoncpp-src-0.5.0/src/lib_json/json_value.cpp
  81. 292 0
      jsoncpp-src-0.5.0/src/lib_json/json_valueiterator.inl
  82. 829 0
      jsoncpp-src-0.5.0/src/lib_json/json_writer.cpp
  83. 8 0
      jsoncpp-src-0.5.0/src/lib_json/sconscript

+ 62 - 0
AllObjectManagerUtil.cpp

@@ -0,0 +1,62 @@
+#include "AllObjectManagerUtil.h"
+#include "PhmsLogger.h"
+
+Mutex CAllObjectManagerUtil::m_mutex;
+string CAllObjectManagerUtil::m_stringPriorIp;
+
+void CAllObjectManagerUtil::InitializeSSL()
+{
+	Mutex::ScopedLock lock(m_mutex);
+	if(CNetThreadManager::m_map.size() == 0 && CPushObjectManager::m_map.size()==0)
+	{
+		Poco::Net::initializeSSL();
+	}
+}
+
+void CAllObjectManagerUtil::UnInitializeSSL()
+{
+	Mutex::ScopedLock lock(m_mutex);
+	if(CNetThreadManager::m_map.size() == 0 && CPushObjectManager::m_map.size()==0)
+	{
+		Poco::Net::uninitializeSSL();
+	}
+}
+
+void CAllObjectManagerUtil::InitializeLocale()
+{
+	Mutex::ScopedLock lock(m_mutex);
+	if(CNetThreadManager::m_map.size() == 0 && CPushObjectManager::m_map.size()==0)
+	{
+		std::locale::global(locale(locale("C"), "", locale::ctype));
+	}
+}
+
+void CAllObjectManagerUtil::UnInitializeLocale()
+{
+	Mutex::ScopedLock lock(m_mutex);
+	if(CNetThreadManager::m_map.size() == 0 && CPushObjectManager::m_map.size()==0)
+	{
+		std::locale::global(locale("C"));
+	}
+}
+
+void CAllObjectManagerUtil::ReleasePhmsLogger()
+{
+	Mutex::ScopedLock lock(m_mutex);
+	if(CNetThreadManager::m_map.size()==0 && CPushObjectManager::m_map.size()==0)
+	{
+		//ÊÍ·ÅÈÕÖ¾¶ÔÏó
+		CPhmsLogger::ReleasePhmsLogger();
+	}
+}
+
+void CAllObjectManagerUtil::SetPriorIp(string stringIp)
+{
+	Mutex::ScopedLock lock(m_mutex);
+	m_stringPriorIp = stringIp;
+}
+
+string CAllObjectManagerUtil::GetPriorIp()
+{
+	return m_stringPriorIp;
+}

+ 23 - 0
AllObjectManagerUtil.h

@@ -0,0 +1,23 @@
+#pragma once
+#include <string>
+#include "Poco/Mutex.h"
+#include "NetThreadManager.h"
+#include "PushObjectManager.h"
+
+using namespace std;
+using Poco::Mutex;
+
+class CAllObjectManagerUtil
+{
+public:
+	static void InitializeSSL();
+	static void UnInitializeSSL();
+	static void InitializeLocale();
+	static void UnInitializeLocale();
+	static void ReleasePhmsLogger();
+	static void SetPriorIp(string stringIp);
+	static string GetPriorIp();
+public:
+	static Mutex m_mutex;
+	static string m_stringPriorIp;
+};

+ 826 - 0
CommonNetInterface.cpp

@@ -0,0 +1,826 @@
+#define PHMS_DLL_EXPORTS
+#include "CommonNetInterface.h"
+#include "Poco/UUIDGenerator.h"
+#include "Poco/UUID.h"
+#include "Poco/Exception.h"
+#include "Poco/Thread.h"
+#include "Util.h"
+#include "PhmsLogger.h"
+#include "ExternalNetInterface.h"
+#include "ErrorCode.h"
+#include <map>
+#include "NetThreadManager.h"
+#include "SessionIdManager.h"
+#include "HandleMutexManager.h"
+#include "PushObjectManager.h"
+#include "AllObjectManagerUtil.h"
+#include "GlobalTerminalLogoString.h"
+
+
+using Poco::UUID;
+using Poco::UUIDGenerator;
+using Poco::Thread;
+using namespace std;
+
+
+string g_stringTerminalType;
+string g_stringContecServerAddr;
+string g_stringContecServerPort;
+string g_stringUsername;
+string g_stringPassword;
+
+void SetContecServerInfo(const char* stringContecServerAddr, const char* stringContecServerPort)
+{
+	g_stringContecServerAddr = stringContecServerAddr;
+	g_stringContecServerPort = stringContecServerPort;
+}
+
+void SetAppDir(const char* stringWorkDir)
+{
+	return CUtil::SetAppDir(stringWorkDir);
+}
+
+int SetTerminalType(const char* stringTerminalType)
+{
+	if(stringTerminalType == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	g_stringTerminalType = stringTerminalType;
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+NET_HANDLE InitializeNetLibObject()
+{
+	CAllObjectManagerUtil::InitializeSSL();
+	CAllObjectManagerUtil::InitializeLocale();
+	//初始化日志对象Logger
+	NET_HANDLE handle = new char[128];
+	memset(handle, 0, 128);
+	string stringUuid;
+	stringUuid = CNetThreadManager::GetHandleByThreadId(Thread::currentTid());
+	if(stringUuid.size() != 0)
+	{
+		strcpy(handle, stringUuid.c_str());
+		return handle;
+	}
+	try
+	{
+		CPhmsLogger::GetPhmsLogger();
+	}
+	catch(Exception& error)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_GENERATE_LOG_FILE_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		delete handle;
+		return NULL;
+	}
+	if(g_stringTerminalType.size() == 0)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_SET_TERMINAL_TYPE), __FUNCTION__, __FILE__, __LINE__);
+		delete handle;
+		return NULL;
+	}
+	stringUuid = UUIDGenerator::defaultGenerator().createOne().toString();
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = CNetThreadManager::InsertNetThread(stringUuid);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		delete handle;
+		return NULL;
+	}
+	nRet = CHandleMutexManager::InsertHandleMutex(stringUuid);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		delete handle;
+		return NULL;
+	}
+	strcpy(handle, stringUuid.c_str());
+	return handle;
+}
+int DeleteNetLibObject(NET_HANDLE handle)
+{
+	if(handle == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	//DeleteNetLibObject接口也不允许handle跨线程
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	Thread::yield();
+	Mutex* pMutex = CHandleMutexManager::GetHandleMutex(handle);
+	if(pMutex == NULL)
+	{
+		return COMMON_INVALID_HANDLE;
+	}
+	Thread::yield();
+	pMutex->lock();
+	nRet = CNetThreadManager::DeleteNetThread(stringUuid);
+	if(nRet == PHMS_SUCCESSFUL_RESULT)
+	{
+		CAllObjectManagerUtil::UnInitializeSSL();
+		CAllObjectManagerUtil::UnInitializeLocale();
+		delete handle;
+	}
+	pMutex->unlock();
+	nRet = CHandleMutexManager::DeleteHandleMutex(stringUuid);
+	CAllObjectManagerUtil::ReleasePhmsLogger();
+	return nRet;
+}
+int SetSessionId(const char* stringSessionId)
+{
+	if(stringSessionId == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringTempSessionId = stringSessionId;
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = CSessionIdManager::SetSessionId(stringTempSessionId);
+	return nRet;
+}
+
+int GetSessionId(char* bufSessionId, unsigned int nBufMaxLen)
+{
+	if(bufSessionId == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringSessionId;
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = CSessionIdManager::GetSessionId(stringSessionId);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		return nRet;
+	}
+	if(stringSessionId.size() <= nBufMaxLen)
+	{
+		strcpy(bufSessionId, stringSessionId.c_str());
+	}
+	else
+	{
+		return COMMON_BUF_SMALL;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int SetUsernameAndPassword(const char* stringUsername, const char* stringPassword)
+{
+	if(stringUsername==NULL || stringPassword==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	g_stringUsername = stringUsername;
+	g_stringPassword = stringPassword;
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int KeepSession(NET_HANDLE handle)
+{
+	if(handle == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->KeepSession();
+}
+
+int Logout(NET_HANDLE handle)
+{
+	if(handle == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->Logout();
+}
+int UploadIm(NET_HANDLE handle, const char* stringSenderId, const char* stringSenderName, const char* stringReceiverId, const char* stringMsgDirection, const char* stringMsgType, 
+			 const char* stringMsgContent, const char* stringAudioFilePath, const char* stringCaseId, const char* stringCaseType)
+{
+	if(handle==NULL || stringSenderId==NULL || stringSenderName==NULL || stringReceiverId==NULL || stringMsgDirection==NULL || stringMsgType==NULL || 
+		stringMsgContent==NULL || stringAudioFilePath==NULL || stringCaseId==NULL || stringCaseType==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->UploadIm(stringSenderId, stringSenderName, stringReceiverId, stringMsgDirection, stringMsgType, stringMsgContent, stringAudioFilePath, stringCaseId, stringCaseType);
+}
+int GetImList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringSenderId, const char* stringCaseId, const char* stringCaseType, const char* stringMsgDirection, const char* stringMsgType)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringSenderId==NULL || stringCaseId==NULL || stringCaseType==NULL || stringMsgDirection==NULL || stringMsgType==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetImList(stringLocalFilePath, stringSenderId, stringCaseId, stringCaseType, stringMsgDirection, stringMsgType);
+}
+
+
+int GetImList2(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringNextId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringNextId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetImList2(stringLocalFilePath, stringNextId);
+}
+
+int DownloadIm(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringMsgId, const char* stringUri, unsigned long nFileSize)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringMsgId==NULL || stringUri==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->DownloadIm(stringLocalFilePath, stringMsgId, stringUri, nFileSize);
+}
+int DownloadImComplete(NET_HANDLE handle, const char* stringMsgId)
+{
+	if(handle==NULL || stringMsgId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->DownloadImComplete(stringMsgId);
+}
+int ChangePwd(NET_HANDLE handle, const char* stringOldPwd, const char* stringNewPwd)
+{
+	if(handle==NULL || stringOldPwd==NULL || stringNewPwd==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->ChangePwd(stringOldPwd, stringNewPwd);
+}
+int Feedback(NET_HANDLE handle, const char* stringTitle, const char* stringNotes, const char* stringPhone, const char* stringPicPath)
+{
+	if(handle==NULL || stringTitle==NULL || stringNotes==NULL || stringPhone==NULL || stringPicPath==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->Feedback(stringTitle, stringNotes, stringPhone, stringPicPath);
+}
+int GetReportListOfCase(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCaseId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringCaseId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetReportListOfCase(stringLocalFilePath, stringCaseId);
+}
+int GetHospitalListOfGroup(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringGroupId, const char* stringType, const char* stringCaseType, unsigned int nPageTo, unsigned int nPageSize)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringGroupId==NULL || stringType==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetHospitalListOfGroup(stringLocalFilePath, stringGroupId, stringType, stringCaseType, nPageTo, nPageSize);
+}
+int GetDoctorListOfHospital(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringDoctorId, const char* stringCaseType, const char* stringDoctorType, unsigned int nPageTo, unsigned int nPageSize)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringHospitalId==NULL || stringDoctorId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetDoctorListOfHospital(stringLocalFilePath, stringHospitalId, stringDoctorId, stringCaseType, stringDoctorType, nPageTo, nPageSize);
+}
+
+int AbortSession(NET_HANDLE handle)
+{
+	if(handle==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	Mutex* pMutex = CHandleMutexManager::GetHandleMutex(handle);
+	if(pMutex == NULL)
+	{
+		return COMMON_INVALID_HANDLE;
+	}
+	Mutex::ScopedLock lock(*pMutex);
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid, true);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->AbortSession();
+}
+
+int GetEventStream(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCaseId, const char* stringOriginalHospital)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringCaseId==NULL || stringOriginalHospital==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetEventStream(stringLocalFilePath, stringCaseId, stringOriginalHospital);
+}
+
+int GetCaseTypeList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLanguage)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringLanguage==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetCaseTypeList(stringLocalFilePath, stringLanguage);
+}
+
+int DownloadPhoto(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUri, unsigned long nFileSize, pProgressAndSpeedCallback pCallback)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringUri==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->DownloadPhoto(stringLocalFilePath, stringUri, nFileSize, pCallback);
+}
+
+int GetServerFileSize(NET_HANDLE handle, const char* stringUri, int& nFileSize)
+{
+	if(handle==NULL || stringUri==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetAlreadyUploadFileSize(stringUri, nFileSize);
+}
+
+int SendPhoneMsg(NET_HANDLE handle, const char* stringCardId, const char* stringPhone, const char* stringMsg)
+{
+	if(handle==NULL || stringCardId==NULL || stringPhone==NULL || stringMsg==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->SendPhoneMsg(stringCardId, stringPhone, stringMsg);
+}
+
+int GetFileWithHttp(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUrl, int bContinue)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringUrl==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetFileWithHttp(stringLocalFilePath, stringUrl, bContinue);
+}
+
+
+int PostForm(NET_HANDLE handle, char* stringResponse, unsigned int nResponseSize, const char* stringHost, const char* stringUrl, const char* stringKey[], const char* stringValue[], int nSize)
+{
+	if(handle==NULL || stringResponse==NULL || stringHost==NULL || stringUrl==NULL || stringKey==NULL || stringValue==NULL || nSize==0 || nResponseSize==0)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	map<string, string> mapParams;
+	for(int i=0; i<nSize; i++)
+	{
+		mapParams[stringKey[i]] = stringValue[i];
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	string stringTempResponse;
+	nRet = pNetInterface->PostForm(stringTempResponse, stringHost, stringUrl, mapParams);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		return nRet;
+	}
+	if(stringTempResponse.size() != 0)
+	{
+		if(stringTempResponse.size() > nResponseSize)
+		{
+			strncpy(stringResponse, stringTempResponse.c_str(), nResponseSize);
+		}
+		else
+		{
+			strcpy(stringResponse, stringTempResponse.c_str());
+		}
+	}
+	return nRet;
+}
+
+int GetVerificationCode(NET_HANDLE handle, const char* stringType, const char* stringPhone)
+{
+	if(handle==NULL || stringType==NULL || stringPhone==NULL)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(handle, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(stringType, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(stringPhone, __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetVerificationCode(stringType, stringPhone);
+}
+
+int ApplyQRCode(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringScene)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringType==NULL || stringScene==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->ApplyQRCode(stringLocalFilePath, stringType, stringScene);
+}
+
+
+int ValidateUserAccount(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLoginId, const char* stringPassword, const char* stringRole)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringLoginId==NULL || stringPassword==NULL || stringRole==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->ValidateUserAccount(stringLocalFilePath, stringLoginId, stringPassword, stringRole);
+}
+
+int UploadCommonFile(NET_HANDLE handle, char* stringUri, const char* stringType, const char* stringExtra, const char* stringLocalFilePath, const char* stringFileType, pProgressAndSpeedCallback pCallbcak)
+{
+	if(handle==NULL || stringType==NULL || stringExtra==NULL || stringLocalFilePath==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	string stringTempUri;
+	int nRet = pNetInterface->UploadCommonFile(stringTempUri, stringType, stringExtra, stringLocalFilePath, stringFileType, pCallbcak);
+	if(stringTempUri.size() != 0)
+	{
+		strcpy(stringUri, stringTempUri.c_str());
+	}
+	return nRet;
+}
+
+int GetListOfHealthyKnowledge(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringSenderId, const char* stringNextId, const char* stringIds, const char* stringPageSize, const char* stringOrderBy)
+{
+	if(handle==NULL || stringSenderId==NULL || stringNextId==NULL || stringIds==NULL || stringLocalFilePath==NULL || stringPageSize==NULL || stringOrderBy==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetListOfHealthyKnowledge(stringLocalFilePath, stringSenderId, stringNextId, stringIds, stringPageSize, stringOrderBy);
+}
+
+int GetCardUserReportList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringReportId, const char* stringReportStartDate, const char* stringReportEndDate, const char* stringCaseType, const char* stringState, const char* stringOrderBy, 
+		const char* stringThirdIdType, const char* stringThirdId, const char* stringNextId, const char* stringPageSize)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringReportId==NULL || stringReportStartDate==NULL || stringReportEndDate==NULL || stringCaseType==NULL || stringState==NULL || stringOrderBy==NULL ||
+		stringThirdIdType==NULL || stringThirdId==NULL || stringNextId==NULL || stringPageSize==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetCardUserReportList(stringLocalFilePath, stringReportId, stringReportStartDate, stringReportEndDate, stringCaseType, stringState, stringOrderBy, stringThirdIdType, stringThirdId, stringNextId, stringPageSize);
+}
+
+int MyFans(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUserId, const char* stringNextId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringUserId==NULL || stringNextId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->MyFans(stringLocalFilePath, stringUserId, stringNextId);
+}
+
+int GetPayCode(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringCaseId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringType==NULL || stringCaseId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetPayCode(stringLocalFilePath, stringType, stringCaseId);
+}
+
+int GetOrderInfo(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringCaseId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringType==NULL || stringCaseId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetOrderInfo(stringLocalFilePath, stringType, stringCaseId);
+}
+
+int AbortSessionByThreadId(THREAD_ID threadId)
+{
+#if(POCO_OS == POCO_OS_MAC_OS_X)
+	return PHMS_SUCCESSFUL_RESULT;
+#else
+	string handle = CNetThreadManager::GetHandleByThreadId(threadId);
+	if(handle.size() == 0)
+	{
+		return COMMON_INVALID_THREAD_ID;
+	}
+	return AbortSession((char*)handle.c_str());
+#endif
+}
+
+NET_HANDLE NET_API BeginMsgListPush(const char* stringSenderId, const char* stringCaseId, const char* stringCaseType, const char* stringMsgType, const char* stringMsgDirection, const char* stringVersion, 
+									pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback)
+{
+	CAllObjectManagerUtil::InitializeSSL();
+	CAllObjectManagerUtil::InitializeLocale();
+	//初始化日志对象Logger
+	string stringUuid;
+	try
+	{
+		CPhmsLogger::GetPhmsLogger();
+	}
+	catch(Exception& error)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_GENERATE_LOG_FILE_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return NULL;
+	}
+	if(stringSenderId==NULL || stringCaseId==NULL || stringCaseType==NULL || stringMsgType==NULL ||stringMsgDirection==NULL || 
+		pCallback==NULL || pFailCallback==NULL)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PARAMETER_NULL), __FUNCTION__, __FILE__, __LINE__);
+		return NULL;
+	}
+	if(g_stringTerminalType.size() == 0)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_SET_TERMINAL_TYPE), __FUNCTION__, __FILE__, __LINE__);
+		return NULL;
+	}
+	if(CPushObjectManager::SomeTypePushIsRun(MSG_LIST_PUSH))
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SAME_PUSH_IS_RUN), __FUNCTION__, __FILE__, __LINE__);
+		return NULL;
+	}
+	stringUuid = UUIDGenerator::defaultGenerator().createOne().toString();
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = CPushObjectManager::InsertPushMsgListObject(stringUuid, stringSenderId, stringCaseId, stringCaseType, stringMsgType, stringMsgDirection, stringVersion, pCallback, pFailCallback);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		return NULL;
+	}
+	NET_HANDLE handle = new char[128];
+	memset(handle, 0, 128);
+	strcpy(handle, stringUuid.c_str());
+	return handle;
+}
+
+int NET_API EndPush(NET_HANDLE handle)
+{
+	if(handle == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = CPushObjectManager::DeletePushObject(stringUuid);
+	if(nRet == PHMS_SUCCESSFUL_RESULT)
+	{
+		CAllObjectManagerUtil::UnInitializeSSL();
+		CAllObjectManagerUtil::UnInitializeLocale();
+		delete handle;
+	}
+	CAllObjectManagerUtil::ReleasePhmsLogger();
+	return nRet;
+}
+
+int ExecuteGWService(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLastPath, const char* stringJson, const char* stringUploadFilePath)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringLastPath==NULL || stringJson==NULL || stringUploadFilePath==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->ExecuteGWService(stringLocalFilePath, stringLastPath, stringJson, stringUploadFilePath);
+}
+
+int ExecuteCommonRESTful(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringIp, const char* stringPort, const char* stringUrl, const char* stringContentType, const char* stringPayload)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringIp==NULL || stringPort==NULL || stringUrl==NULL || stringContentType==NULL || stringPayload==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->ExecuteCommonRESTful(stringLocalFilePath, stringIp, stringPort, stringUrl, stringContentType, stringPayload);
+}
+

+ 663 - 0
CommonNetInterface.h

@@ -0,0 +1,663 @@
+#ifndef PHMS_COMMOM_INTERFACE
+#define PHMS_COMMON_INTERFACE
+#include "PhmsDataType.h"
+
+
+#if defined(_WIN32) || defined(_WIN32_WCE)
+#if defined(PHMS_DLL_EXPORTS)
+#define NET_API __declspec(dllexport)
+#else
+#define NET_API __declspec(dllimport)	
+#endif
+#endif
+
+
+#if !defined(NET_API)
+#define NET_API
+#endif
+
+
+
+#ifdef __cplusplus 
+extern "C" { 
+#endif 
+
+//==================================================================
+//参数要求:
+//①所有目标文件所在目录必须存在,否则返回文件打开失败
+//②目录中暂时不支持汉字(有需要可以改)(已改支持汉字2013-4-18)
+//③字符指针参数不能为NULL
+//④要求字符串参数编码为GBK,将来有可能改成UTF8
+//==================================================================
+
+
+//==================================================================
+//函数名:SetContecServerInfo
+//作者:YangJiannan
+//日期:2016.11.16
+//功能:用户会诊小程序设置目标服务器ip和端口
+//输入参数:stringContecServerAddr	服务器ip或域名
+//			stringContecServerPort	服务器端口
+//返回值: 无
+//备注:优先于PhmsConfig.ini
+//==================================================================
+void NET_API SetContecServerInfo(const char* stringContecServerAddr, const char* stringContecServerPort);
+
+//==================================================================
+//函数名:SetAppDir
+//作者:YangJiannan
+//日期:2015.11.4
+//功能:用于Android程序调用,设置工作目录,因为无法从底层获得运行的Android APP的工作目录,需要外部设置
+//输入参数:stringWorkDir	工作目录
+//返回值: 无
+//修改记录:
+//==================================================================
+void NET_API SetAppDir(const char* stringWorkDir);
+
+
+//==================================================================
+//函数名:设置终端类型标识
+//作者:YangJiannan
+//日期:2013.4.18
+//功能:设置每一个终端类型标识
+//输入参数:终端标识号,参见P还没收DataType.h
+//返回值: 正确或错误码
+//修改记录:
+//==================================================================
+int NET_API SetTerminalType(const char* stringTerminalType);
+
+
+//==================================================================
+//函数名:InitializeNetLibObject
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:初始化网络对象,获得网络对象句柄,每个线程中如果要使用网络接口,必须先调用该函数,获得网络对象句柄,以后每个接口都要传入该句柄
+//输入参数:无
+//返回值: 网络对象句柄
+//修改记录:
+//==================================================================
+NET_HANDLE NET_API InitializeNetLibObject();
+
+//==================================================================
+//函数名:DeleteNetLibObject
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:删除网络对象,线程结束之前必须调用该函数,否则内存泄露
+//输入参数:handle					网络对象句柄
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API DeleteNetLibObject(NET_HANDLE handle);
+
+//==================================================================
+//函数名:SetSessionId(此函数只在跨进程使用同一sessionid的时候才需要用,同一进程的SessionId实现用户透明管理)
+//作者:YangJiannan
+//日期:2013.1.18
+//功能:设置当前进程的Session Id,这是已知SessionId的情况,直接设置,不需要再次登录,服务器也不允许同一账号同时登录
+//输入参数:stringSessionId			SessionId
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API SetSessionId(const char* stringSessionId);
+
+//==================================================================
+//函数名:GetSessionId(此函数只在跨进程使用同一sessionid的时候才需要用,同一进程的SessionId实现用户透明管理)
+//作者:YangJiannan
+//日期:2013.1.18
+//功能:获得当前进程的Session Id
+//输入参数:bufSessionId			buf,输出函数,用于保存SessionId
+//			nBufMaxLen				buf的最大长度(不得小于128)
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetSessionId(char* bufSessionId, unsigned int nBufMaxLen);
+
+//==================================================================
+//函数名:SetUsernameAndPassword(此函数只在跨进程使用同一sessionid的时候才需要用,同一进程的SessionId实现用户透明管理)
+//作者:YangJiannan
+//日期:2017.5.24
+//功能:设置登录账号密码,用于计算签名
+//输入参数:stringUsername			用户名
+//			stringPassword			密码
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API SetUsernameAndPassword(const char* stringUsername, const char* stringPassword);
+
+
+//==================================================================
+//函数名:HandleSessionSync
+//作者:YangJiannan
+//日期:2012.12.24
+//功能:用于旧session id失效后重新获得新session id,然后调用本接口,使其他网络线程session id同步
+//输入参数:stringSessionId			有效的session id
+//返回值: 无
+//修改记录:
+//==================================================================
+//void HandleSessionSync(const char* stringSessionId);
+
+
+
+//==================================================================
+//函数名:KeepSession
+//作者:YangJiannan
+//日期:2013.3.11
+//功能:保持会话
+//输入参数:handle					网络对象句柄
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API KeepSession(NET_HANDLE handle);
+
+
+//==================================================================
+//函数名:Logout
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:注销登录
+//输入参数:handle					网络对象句柄
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API Logout(NET_HANDLE handle);
+
+//==================================================================
+//函数名:UploadIm
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:上传即时消息
+//输入参数:handle					网络对象句柄
+//			stringSenderId			发送者Id
+//			stringSenderName		发送者姓名
+//			stringReceiverId		接收者Id
+//			stringMsgDirection		消息方向
+//			stringMsgType			消息类型
+//			stringAudioFilePath		音视频文件本地路径
+//			stringCaseId			病例号
+//			stringCaseType			病例类型
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API UploadIm(NET_HANDLE handle, const char* stringSenderId, const char* stringSenderName, const char* stringReceiverId, const char* stringMsgDirection, const char* stringMsgType, 
+			 const char* stringMsgContent, const char* stringAudioFilePath, const char* stringCaseId, const char* stringCaseType);
+
+//==================================================================
+//函数名:GetImList
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:获得即时消息列表
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		即时消息列表本地保存路径
+//			stringSenderId			发送者Id
+//			stringCaseId			病例Id
+//			stringCaseType			病例类型
+//			stringMsgDirection		消息方向
+//			stringMsgType			消息类型
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetImList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringSenderId, const char* stringCaseId, const char* stringCaseType, const char* stringMsgDirection, const char* stringMsgType);
+
+//==================================================================
+//函数名:GetImList2
+//作者:YangJiannan
+//日期:2015.7.24
+//功能:获得即时消息列表2
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		即时消息列表本地保存路径
+//			stringNextId			拉去消息位置,首次传0
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetImList2(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringNextId);
+
+//==================================================================
+//函数名:DownloadIm
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:下载音视频消息
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		音视频消息文件本地保存路径
+//			stringMsgId				消息Id
+//			stringUri				音视频消息文件服务器路径
+//			nFileSize				文件大小
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API DownloadIm(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringMsgId, const char* stringUri, unsigned long nFileSize);
+
+//==================================================================
+//函数名:DownloadImComplete
+//作者:YangJiannan
+//日期:2014.3.21
+//功能:下载音视频消息
+//输入参数:handle					网络对象句柄
+//			stringMsgId				消息Id
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API DownloadImComplete(NET_HANDLE handle, const char* stringMsgId);
+
+//==================================================================
+//函数名:ChangePwd
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:修改密码
+//输入参数:handle					网络对象句柄
+//			stringOldPwd			旧密码
+//			stringNewPwd			新密码
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API ChangePwd(NET_HANDLE handle, const char* stringOldPwd, const char* stringNewPwd);
+
+//==================================================================
+//函数名:Feedbcak
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:上传意见反馈
+//输入参数:handle					网络对象句柄
+//			stringTitle				标题
+//			stringNotes				详细描述
+//			stringPhone				电话号码
+//			stringPicPath			要上传的本地文件路径
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API Feedback(NET_HANDLE handle, const char* stringTitle, const char* stringNotes, const char* stringPhone, const char* stringPicPath);
+
+//==================================================================
+//函数名:GetReportListOfCase
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:获得病例的报告列表
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		报告列表文件本地保存路径
+//			stringCaseId			病例Id
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetReportListOfCase(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCaseId);
+
+//==================================================================
+//函数名:GetHospitalListOfGroup
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:获得组织内医院列表
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		医院列表文件本地保存路径
+//			stringGroupId			组织Id
+//			stringType				医院类型(0:转发医院,1:可选医院)
+//			nPageTo					第几页
+//			nPageSize				每页几条数据
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetHospitalListOfGroup(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringGroupId, const char* stringType, const char* stringCaseType, unsigned int nPageTo, unsigned int nPageSize);
+
+//==================================================================
+//函数名:GetDoctorListOfHospital
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:获得医院内医生列表
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		医生列表文件本地保存路径
+//			stringHospitalId		医院Id
+//			stringDoctorId			医生Id
+//			stringCaseType			病例类型
+//			stringDoctorType		医生类型
+//			nPageTo					第几页
+//			nPageSize				每页几条数据
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetDoctorListOfHospital(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringDoctorId, const char* stringCaseType, const char* stringDoctorType, unsigned int nPageTo, unsigned int nPageSize);
+
+
+//==================================================================
+//函数名:AbortSession
+//作者:YangJiannan
+//日期:2012.12.13
+//功能:即时退出Http Session
+//输入参数:handle					网络对象句柄
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API AbortSession(NET_HANDLE handle);
+
+//==================================================================
+//函数名:GetEventStream
+//作者:YangJiannan
+//日期:2013.01.30
+//功能:获得病例事件流
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		文件本地保存路径
+//			stringCaseId			病例号
+//			stringOriginalHospital	病例原始医院
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetEventStream(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCaseId, const char* stringOriginalHospital);
+
+//==================================================================
+//函数名:GetCaseTypeList
+//作者:YangJiannan
+//日期:2013.01.30
+//功能:获得病例类型权限
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		文件本地保存路径
+//			stringLanguage			指定类型名语言
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetCaseTypeList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLanguage);
+
+//==================================================================
+//函数名:DownloadPhoto
+//作者:YangJiannan
+//日期:2013.4.8
+//功能:下载医生照片(通用文件下载接口)
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringUri				照片服务器路径
+//			nFileSize				照片大小
+//			pCallback				回调函数
+//修改记录:
+//==================================================================
+int NET_API DownloadPhoto(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUri, unsigned long nFileSize, pProgressAndSpeedCallback pCallback);
+
+//==================================================================
+//函数名:GetServerFileSize
+//作者:YangJiannan
+//日期:2018.7.24
+//功能:获得服务器文件大小
+//输入参数:handle					网络对象句柄
+//			stringUri				文件服务器路径
+//输出参数:nFileSize				文件大小
+//修改记录:
+//==================================================================
+int NET_API GetServerFileSize(NET_HANDLE handle, const char* stringUri, int& nFileSize);
+//==================================================================
+//函数名:SendPhoneMsg
+//作者:YangJiannan
+//日期:2013.4.23
+//功能:发送短信接口
+//输入参数:handle					网络对象句柄
+//			stringCardId			用户卡号,卡用户列表中的senderid值
+//			stringPhone				手机号码
+//			stringMsg				短信内容
+//附加说明:stringCardId和stringPhone都为可选参数,但必须至少有一个不为空字符串。当stringCardId为空,stringPhone不为空时,
+//			任何角色都可以调用该接口发送短信;当stringPhone为空,stringCardId不为空是,医生调用该接口给卡用户发送健康建议;
+//			当都不为空时,已stringCard为准。
+//参数和返回值的详细信息参见Net_Interface_V1.doc的4.5.18
+//修改记录:
+//==================================================================
+int NET_API SendPhoneMsg(NET_HANDLE handle, const char* stringCardId, const char* stringPhone, const char* stringMsg);
+
+//==================================================================
+//函数名:GetFileWithHttp
+//作者:YangJiannan
+//日期:2013.5.13
+//功能:通过http请求文件,不通过php
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		文件本地保存路径
+//			stringUrl				文件web url
+//			bContinue				是否断点续传(0 否,1 是)
+//附加说明:本接口不同于其他任何接口,因为本接口没有对应的Phms协议,只是通过http请求文件,不通过php页面;在内部接口中走了
+//一条NoPhms分支,所有内部函数都有NoPhms标识,可查询该分支;该接口也需要一个handle,防止多个线程公用一个handle,导致http请求和响应混乱;
+//但是该handle所有对应的CExternalNetInterface对象不需要sessionid,为了统一,也同步了sessionid,不过实际上没有用到sessionid。
+//修改记录:
+//==================================================================
+int NET_API GetFileWithHttp(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUrl, int bContinue);
+
+
+//==================================================================
+//函数名:PostForm
+//作者:YangJiannan
+//日期:2013.4.22
+//功能:提交Form表单并获得响应内容
+//输入参数:handle					网络对象句柄
+//			stringResponse			响应保存buf
+//			stringHost				服务器地址
+//			stringUrl				页面url
+//			stringKey				Post参数名数组
+//			stringValue				Post参数值数组
+//			nSize					数组大小
+//附加说明:本接口不同于其他任何接口,因为本接口没有对应的Phms协议,只是Post一个Form表单;在内部接口中走了
+//一条Form分支,所有内部函数都有Form标识,可查询该分支;该接口也需要一个handle,防止多个线程公用一个handle,导致http请求和响应混乱;
+//但是该handle所有对应的CExternalNetInterface对象不需要sessionid,为了统一,也同步了sessionid,不过实际上没有用到sessionid。
+//参数和返回值的详细信息参见Net_Interface_V1.doc的4.5.18
+//修改记录:
+//==================================================================
+int NET_API PostForm(NET_HANDLE handle, char* stringResponse, unsigned int nResponseSize, const char* stringHost, const char* stringUrl, const char* stringKey[], const char* stringValue[], int nSize);
+
+//==================================================================
+//函数名:GetVerificationCode
+//作者:YangJiannan
+//日期:2013.10.17
+//功能:身份证号注册
+//输入参数:handle					网络对象句柄
+//			stringType				请求短信类型
+//			stringPhone				电话号码
+//返回值: 正常或错误返回码
+//弃用该接口:2013.12.11
+//接口另作他用:2014.1.4
+//==================================================================
+int NET_API GetVerificationCode(NET_HANDLE handle, const char* stringType, const char* stringPhone);
+
+//==================================================================
+//函数名:ApplyQRCode
+//作者:YangJiannan
+//日期:2014.12.10
+//功能:申请二维码
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringType				二维码类型
+//			stringScene				二维码使用场景
+//返回值: 正常或错误返回码
+//==================================================================
+int NET_API ApplyQRCode(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringScene);
+
+//==================================================================
+//函数名:ValidateUserAccount
+//作者:YangJiannan
+//日期:2014.12.10
+//功能:申请二维码
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringLoginId			用户名
+//			stringPassword			密码
+//			stringRole				用户角色
+//返回值: 正常或错误返回码
+//备注:强制加密传输;不验证签名与sessionid
+//==================================================================
+int NET_API ValidateUserAccount(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLoginId, const char* stringPassword, const char* stringRole);
+
+//==================================================================
+//函数名:UploadCommonFile
+//作者:YangJiannan
+//日期:2015.6.29
+//功能:通用上传文件
+//输入参数:handle					网络对象句柄
+//			stringType				文件类型
+//			stringExtra				额外信息
+//			stringLocalFilePath		本地文件路径
+//			stringFileType			文件类型(0:pdf+bin   1:心电图机报告+bin    空:不处理)
+//			pCallbcak				回调函数
+//输出参数:stringUri				服务器文件保存路径
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API UploadCommonFile(NET_HANDLE handle, char* stringUri, const char* stringType, const char* stringExtra, const char* stringLocalFilePath, const char* stringFileType, pProgressAndSpeedCallback pCallbcak);
+
+
+//==================================================================
+//函数名:GetListOfHealthyKnowledge
+//作者:YangJiannan
+//日期:2015.7.23
+//功能:获得健康知识列表
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringSenderId			医生SenderId
+//			stringNextId			拉取位置
+//			stringIds				健康知识ID
+//			stringPageSize			每次拉取条数
+//			stringOrderBy			0:倒序  1:正序
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetListOfHealthyKnowledge(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringSenderId, const char* stringNextId, const char* stringIds, const char* stringPageSize, const char* stringOrderBy);
+
+
+//==================================================================
+//函数名:GetCardUserReportList
+//作者:YangJiannan
+//日期:2015.9.22
+//功能:获得卡用户报告列表
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringReportId			报告Id
+//			stringReportStartDate	报告开始时间
+//			stringReportEndDate		报告结束时间
+//			stringCaseType			病例类型
+//			stringState				报告状态
+//			stringOrderBy			排序方式
+//			stringThirdIdType		第三方号类型
+//			stringThirdId			第三方号
+//			stringNextId			获取列表拉取的位置
+//			stringPageSize			每次返回数据条数
+//返回值: 正常或错误返回码
+//修改记录:
+//==================================================================
+int NET_API GetCardUserReportList(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringReportId, const char* stringReportStartDate, const char* stringReportEndDate, const char* stringCaseType, const char* stringState, const char* stringOrderBy, 
+		const char* stringThirdIdType, const char* stringThirdId, const char* stringNextId, const char* stringPageSize);
+
+//==================================================================
+//函数名:MyFans
+//作者:YangJiannan
+//日期:2015.6.29
+//功能:我的粉丝
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringUserId			用户ID
+//			stringNextId			拉取列表的位置
+//返回值: 正常或错误返回码
+//
+//==================================================================
+int NET_API MyFans(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringUserId, const char* stringNextId);
+
+//==================================================================
+//函数名:GetPayCode
+//作者:YangJiannan
+//日期:2018.1.17
+//功能:获得第三方支付码
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringUserId			用户ID
+//			stringNextId			拉取列表的位置
+//返回值: 正常或错误返回码
+//
+//==================================================================
+int NET_API GetPayCode(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringCaseId);
+
+//==================================================================
+//函数名:GetOrderInfo
+//作者:YangJiannan
+//日期:2018.1.17
+//功能:获得订单信息
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringUserId			用户ID
+//			stringNextId			拉取列表的位置
+//返回值: 正常或错误返回码
+//
+//==================================================================
+int NET_API GetOrderInfo(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringType, const char* stringCaseId);
+
+//==================================================================
+//函数名:AbortSessionByThreadId
+//作者:YangJiannan
+//日期:2014.12.11
+//功能:即时退出Http Session
+//输入参数:threadId				网络线程id
+//返回值: 正常或错误返回码
+//==================================================================
+#if defined(_WIN32) || defined(_WIN64)
+#define THREAD_ID unsigned long
+#else
+#define THREAD_ID unsigned long int
+#endif
+int NET_API AbortSessionByThreadId(THREAD_ID threadId);
+
+//==================================================================
+//函数名:BeginMsgListPush
+//作者:YangJiannan
+//日期:2013.6.19
+//功能:开始即时消息列表推送
+//输入参数:stringSenderId			发送者Id
+//			stringCaseId			病例Id
+//			stringCaseType			病例类型
+//			stringMsgDirection		消息方向
+//			stringMsgType			消息类型
+//			stringVersion			除此参数外,其他参数全部忽略
+//			pCallback				推送成功回调函数
+//			pFailCallback			推送失败回调函数
+//返回值: 网络对象句柄
+//参数和返回值的详细信息参见Net_Interface_V1.doc的4.5.20
+//备注:pCallback调用时机:①服务器成功推送消息 ②成功建立推送连接(两个参数分别为NULL, 0)
+//		pFailCallback调用时机:①错误码COMMON_SESSION_INVALID、COMMON_LOGIN_ANOTHER_PLACE、COMMON_SERVER_NO_SUPPORT、COMMON_INVALID_CHARSET、COMMON_NET_CONFIG_ERROR、
+//								COMMON_URL_NOT_FOUND或COMMON_NO_NET_CONFIG_FILE调用并结束推送线程②其他错误码只调用后重试,不结束推送线程
+//==================================================================
+NET_HANDLE NET_API BeginMsgListPush(const char* stringSenderId, const char* stringCaseId, const char* stringCaseType, const char* stringMsgType, const char* stringMsgDirection, const char* stringVersion, 
+									pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback);
+
+//==================================================================
+//函数名:EndPush
+//作者:YangJiannan
+//日期:2012.12.3
+//功能:结束推送,可以是任何推送,只要句柄有对应
+//输入参数:handle					网络对象句柄
+//返回值: 正常或错误返回码
+//参数和返回值的详细信息参见Net_Interface_V1.doc的4.5.21
+//修改记录:
+//备注:不能在BeginMsgListPush中传入的正确回调和错误回调中调用此函数,会引发死锁
+//==================================================================
+int NET_API EndPush(NET_HANDLE handle);
+
+
+//==================================================================
+//函数名:ExecuteGWService
+//作者:YangJiannan
+//日期:2018.3.5
+//功能:请求公卫服务
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		文件本地保存路径
+//			stringLastPath			网络url的path部分的最后一部分,比如https://<server ip or domain>/healthApi/v1/login中的login
+//			stringJson				json
+//			stringUploadFilePath	要上传文件的本地路径
+//返回值: 正常或错误返回码
+//==================================================================
+int NET_API ExecuteGWService(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringLastPath, const char* stringJson, const char* stringUploadFilePath);
+
+
+//==================================================================
+//函数名:ExecuteCommonRESTful
+//作者:YangJiannan
+//日期:2018.3.5
+//功能:请求公卫服务
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		文件本地保存路径
+//			stringIp				目标服务器地址
+//			stringPort				目标服务器端口
+//			stringUrl				目标服务器url,端口后的部分,比如"http://ip:port/Collect/InitDevice"中的/Collect/InitDevice 
+//			stringContentType		http请求头中的Content-Type,比如text/json
+//			stringPayload			有效负载
+//返回值: 正常或错误返回码
+//==================================================================
+int NET_API ExecuteCommonRESTful(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringIp, const char* stringPort, const char* stringUrl, const char* stringContentType, const char* stringPayload);
+
+#ifdef __cplusplus 
+	} 
+#endif 
+
+#endif

+ 1 - 0
DeviceNetInterface.cpp

@@ -0,0 +1 @@
+#include "DeviceNetInterface.h"

+ 1 - 0
DeviceNetInterface.h

@@ -0,0 +1 @@
+#pragma once

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1170 - 0
DoctorNetInterface.cpp


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1113 - 0
DoctorNetInterface.h


+ 59 - 0
DownloadThreadCallback.cpp

@@ -0,0 +1,59 @@
+#include "DownloadThreadCallback.h"
+//#include "Poco/Thread.h"
+
+CDownloadThreadCallback::CDownloadThreadCallback(void)
+	:m_nStart(0), m_nEnd(0)
+{
+}
+
+CDownloadThreadCallback::CDownloadThreadCallback(string stringUri, string stringLocalFile, unsigned long nStart, unsigned long nEnd, CInternalNetIntetface* pNet)
+:m_stringUri(stringUri), m_stringLocalFile(stringLocalFile), m_nStart(nStart), m_nEnd(nEnd), m_pNet(pNet)
+{
+}
+
+CDownloadThreadCallback::~CDownloadThreadCallback(void)
+{
+}
+
+void CDownloadThreadCallback::SetUri(string stringUri)
+{
+	m_stringUri = stringUri;
+}
+
+void CDownloadThreadCallback::SetLocalFile(string stringLocalFile)
+{
+	m_stringLocalFile = stringLocalFile;
+}
+
+void CDownloadThreadCallback::SetStart(unsigned long nStart)
+{
+	m_nStart = nStart;
+}
+
+void CDownloadThreadCallback::SetEnd(unsigned long nEnd)
+{
+	m_nEnd = nEnd;
+}
+
+void CDownloadThreadCallback::SetNet(CInternalNetIntetface* pNet)
+{
+	m_pNet = pNet;
+}
+
+unsigned long CDownloadThreadCallback::GetStart()
+{
+	return m_nStart;
+}
+
+unsigned long CDownloadThreadCallback::GetEnd()
+{
+	return m_nEnd;
+}
+
+void CDownloadThreadCallback::run()
+{
+	//Poco::Thread::sleep(1000*2);
+ 	m_pNet->SetSaveType(2);
+ 	m_pNet->SetFilePath(m_stringLocalFile);
+ 	m_pNet->DownloadFileSegment(m_stringUri, m_nStart, m_nEnd);
+}

+ 32 - 0
DownloadThreadCallback.h

@@ -0,0 +1,32 @@
+#pragma once
+#include "Poco/Runnable.h"
+#include "InternalNetIntetface.h"
+
+using Poco::Runnable;
+
+
+class CDownloadThreadCallback :
+	public Runnable
+{
+public:
+	CDownloadThreadCallback(void);
+	CDownloadThreadCallback(string, string, unsigned long, unsigned long, CInternalNetIntetface*);
+	~CDownloadThreadCallback(void);
+public:
+	void SetUri(string);
+	void SetLocalFile(string);
+	void SetStart(unsigned long);
+	void SetEnd(unsigned long);
+	void SetNet(CInternalNetIntetface*);
+
+	unsigned long GetStart();
+	unsigned long GetEnd();
+protected:
+	void run();
+private:
+	string m_stringUri;
+	string m_stringLocalFile;
+	unsigned long m_nStart;
+	unsigned long m_nEnd;
+	CInternalNetIntetface* m_pNet;
+};

+ 109 - 0
DownloadTimerCallback.cpp

@@ -0,0 +1,109 @@
+#include "DownloadTimerCallback.h"
+#include "Poco/File.h"
+#include "Poco/Exception.h"
+#include <vector>
+#include "Util.h"
+#include "PhmsLogger.h"
+#include "ErrorCode.h"
+
+using namespace std;
+using Poco::File;
+using Poco::Exception;
+
+CDownloadTimerCallback::CDownloadTimerCallback(pProgressAndSpeedCallback pCallback, unsigned long nFileSize, string stringLocalFilePath, 
+					   string stringTempDirectory, unsigned long nAlreadyDownloadFileSize, int nThreadCount, string stringServerFilePath)
+					   :m_pCallback(pCallback), m_nFileSize(nFileSize), m_stringLocalFilePath(stringLocalFilePath), 
+						m_stringTempDirectory(stringTempDirectory), m_nCurrentDownloadFileSize(nAlreadyDownloadFileSize), 
+						m_nPreDownloadFileSize(nAlreadyDownloadFileSize),m_nThreadCount(nThreadCount), m_stringServerFilePath(stringServerFilePath), m_nSeconds(0)
+{
+}
+
+CDownloadTimerCallback::~CDownloadTimerCallback(void)
+{
+}
+void CDownloadTimerCallback::onTimer(Timer& timer)
+{
+	m_nSeconds++;
+	File fileLocalFile(m_stringLocalFilePath, "gbk");
+	try
+	{
+		fileLocalFile.createFile();
+		m_nCurrentDownloadFileSize = (unsigned long)fileLocalFile.getSize();
+	}
+	catch(const Exception& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_FILE_OPEN_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		m_nCurrentDownloadFileSize = 0;
+	}
+	
+	File fileTempDirectory(m_stringTempDirectory, "gbk");
+	vector<File> vTempFile;
+	vector<File>::const_iterator iter;
+	try
+	{
+		fileTempDirectory.list(vTempFile);
+	}
+	catch(const Exception&)
+	{
+		vTempFile.clear();
+	}
+	for(int nThreadNum=0; nThreadNum<m_nThreadCount; nThreadNum++)
+	{
+		for(iter=vTempFile.begin(); iter!=vTempFile.end(); iter++)
+		{
+			if(iter->path().find("PHMS_TEMP_"+CUtil::UIntToString(nThreadNum)) != string::npos)
+			{
+				try
+				{
+					m_nCurrentDownloadFileSize += (unsigned long)iter->getSize();
+				}
+				catch(const Exception&)
+				{
+					m_nCurrentDownloadFileSize += 0;
+				}
+				break;
+			}
+		}
+	}
+	//¼ÆËã½ø¶È
+	double dProgress = 0.0;
+	if(m_nCurrentDownloadFileSize <= m_nFileSize)
+	{
+		dProgress = ((double)(m_nCurrentDownloadFileSize))/m_nFileSize*100;
+	}
+	else
+	{
+		dProgress = 100.0;
+	}
+	//¼ÆËãËÙ¶È
+	long nInterval = 1000;
+// 	if(timer.getPeriodicInterval() == 0)
+// 	{
+// 		nInterval = 1000;
+// 	}
+// 	else
+// 	{
+// 		nInterval = timer.getPeriodicInterval();
+// 	}
+	unsigned long nTimeCount = m_nSeconds*nInterval/1000;
+	double dSpeed = 0.0;
+	if(nTimeCount != 0)
+	{
+		if(m_nCurrentDownloadFileSize<m_nPreDownloadFileSize)
+		{
+			dSpeed = 0.0;
+		}
+		else
+		{
+			dSpeed = (m_nCurrentDownloadFileSize-m_nPreDownloadFileSize)/nTimeCount;
+		}
+		m_nPreDownloadFileSize = m_nCurrentDownloadFileSize;
+	}
+	if(m_pCallback != NULL)
+	{
+		(*m_pCallback)(dProgress, dSpeed, m_stringServerFilePath.c_str(), m_stringLocalFilePath.c_str());
+	}
+	m_nSeconds = 0;
+	return;
+}

+ 28 - 0
DownloadTimerCallback.h

@@ -0,0 +1,28 @@
+#pragma once
+#include "Poco/Timer.h"
+#include "PhmsDataType.h"
+#include <string>
+
+using Poco::Timer;
+using namespace std;
+
+class CDownloadTimerCallback
+{
+public:
+	CDownloadTimerCallback(pProgressAndSpeedCallback pCallback, unsigned long nFileSize, string stringLocalFilePath, 
+		string stringTempDirectory, unsigned long nAlreadyDownloadFileSize, int nThreadCount, string stringServerFilePath);
+	~CDownloadTimerCallback(void);
+private:
+	pProgressAndSpeedCallback m_pCallback;
+	unsigned long m_nFileSize;
+	string m_stringLocalFilePath;
+	string m_stringTempDirectory;
+	unsigned long m_nCurrentDownloadFileSize;
+	unsigned long m_nPreDownloadFileSize;
+	int m_nThreadCount;
+	string m_stringServerFilePath;
+	int m_nSeconds;
+
+public:
+	void onTimer(Timer& timer); 
+};

+ 88 - 0
ErrorCode.h

@@ -0,0 +1,88 @@
+#pragma once
+//成功
+#define PHMS_SUCCESSFUL_RESULT	100000
+
+
+//客户端公共错误
+#define COMMON_PARAM_VALIDATE_FAIL	900001
+#define COMMON_NO_IP	900002
+#define COMMON_NO_PORT	900003
+#define COMMON_DNS_FAIL	900004
+#define COMMON_CONNECT_FAIL	900005
+#define COMMON_SEND_FAIL	900006
+#define COMMON_SEND_TIMEOUT	900007
+#define COMMON_RECV_FAIL	900008
+#define COMMON_RECV_TIMEOUT	900009
+#define COMMON_OFF_NETWORK	900010
+#define COMMON_FILE_OPEN_FAIL	900011
+#define COMMON_FILE_WRITE_FAIL	900012
+#define COMMON_FILE_READ_FAIL	900013
+#define COMMON_CREATE_DIR_FAIL	900014
+#define COMMON_MEMORY_FAIL	900015
+#define COMMON_BUF_SMALL	900016
+#define COMMON_DISK_FULL	900017
+#define COMMON_CALCULATE_MD5_FAIL	900018
+#define COMMON_VALIDATE_MD5_FAIL	900019
+#define COMMON_BINARY_TO_STRING		900020
+#define COMMON_RECV_CONTENT_FAIL	900021
+#define COMMON_SSL_CONFLICT_ERROR	900022
+#define COMMON_OUTPUT_STREAM_FAIL	900023
+#define COMMON_INPUT_STREAM_FAIL	900024
+#define COMMON_NET_CONFIG_ERROR		900025
+#define COMMON_RESPONSE_SIGN_VALIDATE_FAIL	900026
+#define COMMON_NO_SAVE_SESSIONID	900027
+#define COMMON_PARSE_XML_FAIL		900028
+#define COMMON_NO_SID				900029
+#define COMMON_WRITE_XML_ERROR		900030
+#define COMMON_UPLOAD_INI_SIZE_ERROR	900031
+#define COMMON_DOWNLOAD_THREAD_COUNT_TOO_LARGE	900032
+#define COMMON_LOCAL_FILE_MORE_THAN_SERVER_FILE	900033
+#define COMMON_LOCAL_TEMP_TOO_LARGE		900034
+#define COMMON_DOWNLOAD_SEGMENT_FAIL_FOR_FILESIEZE_CHANGE	900035
+#define COMMON_COMBILE_FILE_FAIL		900036
+#define COMMON_INVALID_HANDLE			900037
+#define COMMON_SESSION_BUF_TOO_SMALL	900038
+#define COMMON_PHMS_REQUEST_VALIDATE_FAIL	900039
+#define COMMON_NO_URL						900040
+#define COMMON_PROXY_INFO_ERROR				900041
+#define COMMON_RESPONSE_FORMAT_ERROR		900042
+#define COMMON_CONVERT_ENCODE_ERROR				900043
+#define COMMON_UPLOAD_LESS_3_BYTES				900044
+#define COMMON_NO_NET_CONFIG_FILE				900045
+#define	COMMON_NET_CONFIG_READ_ERROR			900046
+#define COMMON_PARAMETER_NULL					900047
+#define COMMON_NO_VALID_SESSIONID				900048
+#define COMMON_HANDLE_THREAD_MISMATCH			900049
+#define COMMON_GET_CASE_STATE_ERROR				900050
+#define COMMON_GENERATE_LOG_FILE_ERROR			900051
+#define COMMON_TERMINAL_LOGO_LEN_ERROR			900052
+#define COMMON_DOWNLOAD_FILE_SIZE_0				900053
+#define COMMON_SAME_PUSH_IS_RUN					900054
+#define COMMON_NO_SET_TERMINAL_TYPE				900055
+#define COMMON_URL_NOT_FOUND					900056
+#define COMMON_GET_CASE_SIZE_ERROR				900057
+#define COMMON_MULT_THREAD_SSL_SWITCH			900060
+#define COMMON_COMBILE_FILE_FAIL_BUT_CAN_RETRY	900061
+#define COMMON_INVALID_THREAD_ID				900062
+#define COMMON_ILLEGAL_GBK_ENCODING				900063
+#define COMMON_PARAM_SIZE_0						900064
+#define COMMON_PICTURE_CONSULTATION_ERROR		900065
+#define COMMON_INVALID_URL						900066
+
+
+//服务器端公共错误
+#define COMMON_SESSION_INVALID					100002
+#define COMMON_LOGIN_ANOTHER_PLACE				100007
+#define COMMON_SERVER_NO_SUPPORT				100005
+#define COMMON_INVALID_CHARSET					100006
+
+
+//phms接口之间业务逻辑错误
+#define LOGIC_NO_DOCTOR_SIGN				200101
+#define NOT_HODL_BY_YOURSELF				200102
+#define LOGIC_NO_HOSPITAL_ID				200103
+#define LOGIC_NO_HOSPITAL_PHOTO				200104
+
+//东软熙康接口错误
+#define COMMON_XIKANG_URL_OPENID_NULL					300001
+#define COMMON_GET_TOKEN_FAIL					300002

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 3184 - 0
ExternalNetInterface.cpp


+ 278 - 0
ExternalNetInterface.h

@@ -0,0 +1,278 @@
+#pragma once
+#include "InternalNetIntetface.h"
+#include <string>
+#include <map>
+
+
+using namespace std;
+
+class CExternalNetInterface
+{
+public:
+	CExternalNetInterface(void);
+	~CExternalNetInterface(void);
+private:
+	CInternalNetIntetface* m_pInternalNetInterface;
+public:
+	void SetSessionId(string stringSessionId);
+	string GetSessionId();
+	void SetGWSessionId(string stringSessionId);
+	string GetGWSessionId();
+public:
+	//专家端接口
+	int DoctorLogin(string stringLocalFilePath, string stringUsername, string stringPassword, string stringLanguage, string stringSignPath, 
+		string stringHospitalInfoPath, string stringHospitalPhotoPath, string stringCliniqueListPath, string stringHospitalListPath, 
+		string stringDoctorListPath, string& stringIp);
+	int UploadSign(string stringSignPath);
+	int UploadPhoto(string stringPhotoPath);
+	int GetUnanalyzedCaseList(string stringLocalFilePath, string stringOwnerId, string stringOrderBy, unsigned int nPageTo, unsigned int nPageSize);
+	int SearchCaseFromServer(string stringLocalFilePath, string stringCaseId, string stringCaseType, string stringCaseSource, 
+		string stringCaseState, string stringPatientName, string stringSenderId, string stringReceiverId, string stringStartDate, string stringEndDate, 
+		string stringCheckStartDate, string stringCheckEndDate, string stringSenderName, string stringDiagnostic, string stringCaseOrigin, string stringYzlb, string stringAId, 
+		string stringSex, string stringOrderBy, string stringThirdId, string stringLang, string stringIsFullName, unsigned int nPageTo, unsigned int nPageSize);
+	int GetAutoCaseInfo(string stringLocalFilePath, string stringCaseType,string stringSenderId,string stringCaseOrigin);
+	int ManualDownloadCase(string stringLocalFilePath, string stringCaseId, string stringHospitalId, string stringReceiverId, string stringUri, unsigned long nFileSize, 
+		pProgressAndSpeedCallback pCallback, bool bDownloadNotSelfOwn);
+	int RollbackCase(string stringCaseId, string stringReceiverId, string stringBackTo);
+	int TransmitCase(string stringCaseId, string stringReceiverId, string stringForwardToH, string stringForwardToHospitalName, 
+		string stringForwardToD, string stringForwardToDoctorName);
+	int InvalidCase(string stringCaseId, string stringReceiverId, string stringReason);
+	int AnalyzeBegin(string stringCaseId, string stringReceiverId, string stringCaseType);
+	int AnalyzeComplete(string stringCaseId, string stringReceiverId, string stringCaseType);
+	int UploadReport(string& stringReportId, string stringCaseId, string stringReceiverId, string stringDiagnosis, string stringDigitalSign, string stringTimestampSign, string stringCaseType, string stringLocalReportPath, int nResultFlag, 
+		string stringFileType, pProgressAndSpeedCallback pCallbcak);
+	int DoctorDownloadReport(string stringLocalFilePath, string stringUri, unsigned long nFileSize, pProgressAndSpeedCallback pCallback);
+	int UploadAdvice(string stringUserId, string stringUsername, string stringMsg, string stringType, string stringIsSendMsg);	
+	int DoctorChangeInfo(string stringName, string stringSex, string stringTel, string stringBirthyead, string stringPosition, string stringNotes);
+	int DoctorGetSelfInfo(string stringLocalFilePath, string stringSenderId);//接口有变动,加了一个参数senderid,表示要查找信息的人,如为空表示自己
+	int GetReviewReportList(string stringLocalFilePath, string stringReportStartDate, string stringReportEndDate,string stringReviewStartDate,
+		string stringReviewEndDate, string stringReviewState, string stringCaseType, string stringPtName, string stringSenderId, string stringYzlb, string stringAId, 
+		string stringReviewerId, string stringReceiverId, string stringCaseId, unsigned int nPageTo, unsigned int nPageSize);
+	int ReviewReport(string stringReportKeyId, string stringReviewState, string stringPath, string stringDiagnostic, 
+		string stringDigitalSign, string stringTimeStampSign);
+	int GetCardUserList (string stringLocalFilePath, string stringCardId, string stringSenderId, string stringPersonId, string stringTel, string stringName,
+		string stringType, unsigned int nPageTo, unsigned int nPageSize);
+	int MarkCaseException(string stringCaseId, string stringReceiverId, int nResultFlag);
+	int GetAllTeamList(string stringLocalFilePath);
+	int GetDoctorListOfTeam(string stringLocalFilePath, string stringTeamId);
+	int DoctorHandledCaseStatistics(string stringLocalFilePath, string stringCaseType, string stringStartTime, string stringEndTime);
+	int DoctorDownloadCaseAndOneReportOfOldCm(string stringLocalCasePath, string stringLocalReportPath, string stringCaseId, string stringReportUri, unsigned long nReportSize, pProgressAndSpeedCallback pCallback);
+	int GetTrendData(string stringLocalFilePath, string stringUId, string stringInterUId, string stringTrendType, string stringStartDate, string stringEndDate, string stringNextId);
+	int GetHealthDegree(string stringLocalFilePath, string stringUId, string stringInterUId, string stringDate);
+	int GetUserOfNoAdviceAndMostData(string stringLocalFilePath, string stringDays);
+	int AdviceDelay(string stringUId, string stringMinutes);
+	int AdviceComplete(string stringUId, string stringOptionType, string stringAdvice);
+	int GetUserListOfNoAdvice(string stringLocalFilePath, string stringDays, unsigned int nPageTo, unsigned int nPageSize);
+	int AdviceBegin(string stringUId);
+	int GetUserListOfAdvicing(string stringLocalFilePath, unsigned int nPageTo, unsigned int nPageSize);
+	int GetAskList(string stringLocalFilePath, string stringAskType, string stringAskEnd, string stringDoctorId, string stringIsAsk, string stringUserId, string stringStartTime, string stringEndTime, unsigned int nPageTo, unsigned int nPageSize);
+	int GetAskDetail(string stringLocalFilePath, string stringAskId);
+	int SubmitQuestion(string stringUserId, string stringAdvise, string stringReportType, string stringAskId, string stringAskedId, string stringDoctorPhotoPath);
+	int GetCliniqueListOfHospital(string stringLocalFilePath, string stringHospitalId);
+	int GetStatisticsInfo(string stringLocalFilePath, string stringTypeId, string stringMonth, string stringMonthDay, unsigned int nPageTo, unsigned int nPageSize);
+	int GetUserHealthList(string stringLocalFilePath, string stringNextId, string stringTypeId, string stringSecondTypeId, string stringName, string stringSex, string stringThirdIdType, 
+		string stringThirdId, string stringHospitalId, string stringUnitSenderId, string stringIsData, string stringIntervalTime, string stringPopulations, string stringContractDoctor, string stringIsContract, string stringPageSize);
+	int GetAdviceImplemention(string& stringPercent, string stringThirdId, string stringHospitalId);
+	int ChangePersonType(string stringThirdId, string stringPeopleType, string stringHospitalId);
+	int SetNextVisitTime(string stringThirdId, string stringInterViewTime, string stringHospitalId);
+	int GetPersonTypeList(string stringLocalFilePath, string stringLanguage);
+	int PersonIdRegisterAndLogin(string stringRole, string stringPId, string stringName, string stringSex, string stringBirthday, string stringAddress, string stringDeviceId, string stringHospitalId, 
+		string stringLang, string stringRegFrom);
+	int GetTrendRangeValue(string stringLocalFilePath);
+	int OnlyDownloadCase(string stringLocalFilePath, string stringCaseId, string stringReceiverId, string stringUri, unsigned long nFileSize, pProgressAndSpeedCallback pCallback);
+	int HoldPlaceAndAnalyzeBegin(string stringCaseId, string stringHospitalId, string stringReceiverId, string stringCaseType);
+	int ReviewReportWithFile(string stringCaseId, string stringReceiverId, string stringReportKeyId, string stringReviewState, string stringLoaclFilePath, string stringDiagnostic, 
+		string stringDigitalSign, string stringTimeStampSign, string stringResultFlag, string stringFileType, pProgressAndSpeedCallback pCallback);
+	int AddTag(string& stringTagId, string stringTagName, string stringTagDescription);
+	int GetTagList(string stringLocalFilePath, string stringSenderId);
+	int AddCaseToTag(string stringTagId, string stringTagName, string stringCaseId, string stringCaseType, string stringCaseTypeName, string stringPatientName);
+	int GetCaseListOfTag(string stringLocalFilePath, string stringTagId, string stringSenderId, string stringCaseType);
+	
+	//公共接口
+	int KeepSession();
+	int Logout();
+	int UploadIm(string stringSenderId, string stringSenderName, string stringReceiverId, string stringMsgDirection, string stringMsgType, 
+		string stringMsgContent, string stringAudioFilePath, string stringCaseId, string stringCaseType);
+	int GetImList(string stringLocalFilePath, string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgDirection, string stringMsgType);
+	int GetImList2(string stringLocalFilePath, string stringNextId);
+	int DownloadIm(string stringLocalFilePath, string stringMsgId, string stringUri, unsigned long nFileSize);
+	int DownloadImComplete(string stringMsgId);
+	int ChangePwd(string stringOldPwd, string stringNewPwd);
+	int Feedback(string stringTitle, string stringNotes, string stringPhone, string stringPicPath);
+	int GetReportListOfCase(string stringLocalFilePath, string stringCaseId);
+	int GetHospitalListOfGroup(string stringLocalFilePath, string stringGroupId, string stringType, string stringCaseType, unsigned int nPageTo, unsigned int nPageSize);
+	int GetDoctorListOfHospital(string stringLocalFilePath, string stringHospitalId, string stringDoctorId, string stringCaseType, string stringDoctorType, unsigned int nPageTo, unsigned int nPageSize);
+	int AbortSession();
+	int GetEventStream(string stringLocalFilePath, string stringCaseId, string stringOriginalHospital);
+	int GetCaseTypeList(string stringLocalFilePath, string stringLanguage);
+	int DownloadPhoto(string stringLocalFilePath, string stringUri, unsigned long nFileSize, pProgressAndSpeedCallback pCallback);
+	int GetAlreadyUploadFileSize(string stringUri, int& nFileSize);
+	int SendPhoneMsg(string stringCardId, string stringPhone, string stringMsg);
+	int GetFileWithHttp(string stringLocalFilePath, string stringUrl, int bContinue);
+	int PostForm(string& stringResponse, string stringHost, string stringUrl, map<string, string> mapParams);
+	int GetCardUserReportList(string stringLocalFilePath, string stringReportId, string stringReportStartDate, string stringReportEndDate, string stringCaseType, string stringState, string stringOrderBy, 
+		string stringThirdIdType, string stringThirdId, string stringNextId, string stringPageSize);
+	int SearchCaseAdvanced(string stringLocalFilePath, string stringHospitalId, string stringDiagnostic, 
+		string stringName, string stringSex, QUERY_RANGE rangeAge, QUERY_RANGE rangeCreateTime, string stringMode, 
+		string stringCaseType, QUERY_ECG ecg, string stringFrom, string stringSize);
+	int SearchCaseAdvancedString(string stringLocalFilePath, string stringHospitalId, string stringDiagnostic, 
+		string stringName, string stringSex, string stringJsonAge, string stringJsonCreateTime, string stringMode, 
+		string stringCaseType, string stringJsonEcg, string stringFrom, string stringSize);
+	int GetPayCode(string stringLocalFilePath, string stringType, string stringCaseId);
+	int GetOrderInfo(string stringLocalFilePath, string stringType, string stringCaseId);
+
+	//客户端接口
+	int UserLogin(string stringLocalFilePath, string stringUsername, string stringPassword, string stringRole, string stringToken, string& stringIp);
+	int GetUserInfo(string stringLocalFilePath);
+	int GetHospitalInfo(string stringLocalFilePath, string stringHospitalId);
+	int GetDoctorInfo(string stringLocalFilePath, string stringDoctorId);
+	int UploadCase(string& stringCaseId, string stringName, string stringThirdId, string stringDataType, string stringDataTypeName, string stringNotes, string stringHospitalId, 
+		string stringHospitalName, string stringDoctorId, string stringDoctorName, string stringCheckTime, string stringOtherParam, string stringDeviceId, string stringDeviceName, string stringCaseOrigin, string stringYzlb, string stringSex, 
+		string stringApplicationNo, string stringAutoMatic, string stringLocalCasePath, pProgressAndSpeedCallback pCallback);
+	int UserDownloadReport(string stringLocalFilePath, string stringCaseId, string stringReportId, string stringUri, unsigned long nFileSize, pProgressAndSpeedCallback pCallback);
+	int GetCaseReportState(string& stringReportState, string stringCaseId);
+	int UserGetReportList(string stringLocalFilePath, string stringReportId, string stringReportStartDate, string stringReportEndDate, 
+		string stringCaseType, string stringReportState, string stringOrderBy, unsigned long nPageTo, unsigned long nPageSize);
+	int UserGetCaseList(string stringLocalFilePath, string stringCaseId, string stringCaseType, string stringCaseState, string stringThirdId, string stringName, 
+		string stringStartDate, string stringEndDate, string stringCheckStartDate, string stringCheckEndDate, string stringCaseOrigin, 
+		string stringYzlb, string stringSex, string stringIsRead, string stringOrderBy, unsigned int nPageTo, unsigned int nPageSize);
+	int GetAdvice(string stringLocalFilePath, string stringSgId, string stringUserId, string stringDoctorId, string stringDownloadState, string stringType, 
+		string stringStartDate, string stringEndDate, unsigned int nPageTo, unsigned int nPageSize);
+	int MarkReportRead(string stringReportId);
+	int CardUserChangeInfo(string stringPId, string stringName, string stringSex, string stringTel, string stringBirthday, string stringAddress, string stringLmp, string stringToken, string stringHeight, string stringWeight, string stringPhoto, string stringVCodeBeFollowed, string stringHospitalId, string stringOtherInfo);
+	int CliniqueChangeInfo(string stringPId, string stringName, string stringTel, string stringNotes);
+	int UploadTrendData(string stringCardId, string stringDeviceId, string stringDeviceName, string stringCaseId, vector<RECORD_DATA> vRecordData);
+	int UploadTrendDataString(string stringCardId, string stringDeviceId, string stringDeviceName, string stringCaseId, vector<RECORD_DATA_STRING> vRecordData);
+	int UploadTrendDataFile(string stringFilePath);
+	int VerifyThirdId(string& stringCardId, string stringUId, string stringType);
+	int PersonIdRegister(string stringLocalFilePath, string stringType, string stringRegFrom, string stringPersonId, string stringName, string stringSex, string stringBirthday, string stringAddress, 
+		string stringPhone, string stringHeigth, string stringUploadUnitId, string stringHospitalId, string stringHGroupId, string stringScode, string stringWxUId, string stringLmp, string stringWeight, string stringPassword, 
+		string stringThirdCode, string stringIsRegister);
+	int GetVerificationCode(string stringType, string stringPhone);
+	int GetDataDictionary(string stringLocalFilePath);
+	int LoggingHealthBaseInfo(string stringUserId, string stringWeblock, string stringNation, string stringProfression, string stringCrowd, string stringBloodType, 
+		string stringJwsJiBing, string stringJwsShouShu, string stringJwsWaiShang, string stringJwsShuXue, string stringJwsBaoLuShi, string stringJwsBaoLuShiBz, 
+		string stringJwsYiChuanJiBing, string stringGmsGuoMinShi, string stringGmsGuoMinShiBz, string stringJzsFuQin, string stringJzsFuQinBz, string stringJzsMuQin, 
+		string stringJzsMuQinBz, string stringJzsXdjm, string stringJzsXdjmBz, string stringJzsZiNv, string stringJzsZiNvBz, string stringJzsQiTa);
+	int LoggingHealthCurrentInfo(string stringUserId, string stringShfsYinShi, string stringShfsXlzk, string stringShfsXlzkBz, string stringShfsXltz, string stringShfsXiYan, 
+		string stringShfsYinJiu, string stringShfsSyqk, string stringShfsYunDong, string stringShfsYunDongShiJian, string stringSysjcDanGuChun, string stringSysjcXueChangGui, 
+		string stringSysjcXueChangGuiBz, string stringSysjcNiaoChangGui, string stringSysjcNiaoChangGuiBz, string stringSysjcQiTa, string stringYongYao, string stringZhuYuan, 
+		string stringJkwtNaoXueGuan, string stringJkwtNaoXueGuanBz, string stringJkwtShenZang, string stringJkwtShenZangBz, string stringJkwtXinZang, string stringJkwtXinZangBz, 
+		string stringJkwtXueGuan, string stringJkwtXueGuanBz, string stringJkwtYanBu, string stringJkwtYanBuBz, string stringJkwtShenJing, string stringJkwtQiTa, string stringDate);
+	int UpdateCaseInfo(string& stringDoctorId, string stringHospitalId, string stringCaseId, string stringOtherParam, string stringFlag, string stringNotes, string stringReceiverId);
+	int PersonIdRegisterAndLogin(string stringLocalFilePath, string stringRole, string stringPId, string stringName, string stringSex, string stringBirthday, string stringAddress, string stringDeviceId, string stringHospitalId, 
+		string stringLang, string stringRegFrom);
+	int UploadTrendData2(string stringTargetPath);
+	int CardBindPhone(string stringPhone, string stringScode);
+	int ResetPassword(string stringPhone, string stringScode, string stringNewPwd);
+	int UploadDaily(string stringType, string stringCreateTime, string stringFiles);
+	int GetDateListOfDaily(string stringLocalFilePath, string stringYear, string stringMonth);
+	int GetDailyOfDate(string stringLocalFilePath, string stringDate, string stringType);
+	int ShareDaily(string stringLocalFilePath, string stringType, string stringCreateTime);
+	int DeleteDaily(string stringType, string stringDate);
+	int PhoneScanQR(string& stringSence, string stringQRCode);
+	int PhoneScanQRVerify(string stringQRCode);
+	int ApplyQRCode(string stringLocalFilePath, string stringType, string stringScene);
+	int ValidateUserAccount(string stringLocalFilePath, string stringLoginId, string stringPassword, string stringRole);
+	int RegisterBluetoothDevice(string stringUniqueSN, string stringSerial, string stringBluetoothAddress, string stringBluetoothName, string stringDeviceType);
+	int GetBluetoothInfoOfDevice(string stringLocalFilePath, string stringUniqueSN);
+	int ChangeDeviceType(string stringUniqueSN, string stringDeviceType);
+	int UnregisterBluetoothDevice(string stringUniqueSN);
+	int GetHospitalListOfArea(string stringLocalFilePath, string stringAreaId, string stringRank, string stringBeta);
+	int UploadCommonFile(string& stringUri, string stringType, string stringExtra, string stringLocalFilePath, string stringFileType, pProgressAndSpeedCallback pCallbcak);
+	int SearchSomebody(string stringLocalFilePath, string stringUserId);
+	int FollowSomebody(string stringUserId, string stringUsername, string stringNickname, string stringVCode);
+	int MyFollowing(string stringLocalFilePath, string stringUserId, string stringNextId, string stringFType);
+	int MyFans(string stringLocalFilePath, string stringUserId, string stringNextId);
+	int ChangeNicknameOfFollowed(string stringUserId, string stringNickname);
+	int CancelFollowing(string stringUserId);
+	int PublishHealthyKnowledge(vector<HEALTHY_KNOWLEDGE> vHealthKnowledge);
+	int GetListOfHealthyKnowledge(string stringLocalFilePath, string stringSenderId, string stringNextId, string stringIds, string stringPageSize, string stringOrderBy);
+	int GenerateOrDeletePngZlibReport(string stringLocalFilePath, string stringServerPath, string stringFlag);
+	int GetDailyList(string stringLocalFilePath, string stringType, string stringStartDate, string stringEndDate, string stringOrderBy, string stringNextId, string stringPageSize);
+	int ChangeViewLikeCollectCount(string stringHealthTipId, string stringUri, string stringTitle, string stringLike, string stringRead, string stringCollect);
+	int ChangeAdviceExecutiveState(string stringSgId, string stringState);
+	int GetCliniqueReportList(string stringLocalFilePath, string stringCliniqueSenderId, string stringStartDate, 
+		string stringEndDate, string stringState, string stringName, string stringPatientSourceCode, string stringYzlb, string stringPIdType, string stringPId, string stringHb, string stringASectionId, string stringNextId, string stringPageSize);
+	int GetUserListBindingOrNot(string stringLocalFilePath, string stringNextId, string stringPageSize, string stringIsBind, string stringIsActive);
+	int BindUser(string stringUId, string stringUName);
+	int UnbindUser(string stringUId);
+	int GetCardUserListOfCustomer(string stringLocalFilePath, string stringThirdId, string stringName, string stringCaseType, string stringStartDate, string stringEndDate, string stringNextId, unsigned int nPageSize);
+	int SignDoctor(string stringUId);
+	int RefundFee(string stringType, string stringCaseId, string stringRefundFee);
+	int HoldPlaceReview(string stringReportId);
+	int RollBackReview(string stringReportId);
+	int ResetReviewHoldPlace(string stringReportId, string stringOccupantId, string stringOccupantName, string stringSuperKey);
+	int ResetCaseHoldPlace(string stringCaseId, string stringReceiverId, string stringOccupantId, string stringOccupantName, string stringSuperKey);
+
+	//冠新接口
+//	int CreateSession_GuanXin(string stringUsername, string stringPassword);
+	int GetAccessToken_GuanXin(string stringLocalFilePath, string stringUsername, string stringPassword);
+	int GetPersonInfo_GuanXin(string stringLocalFilePath, string stringAccessToken, string stringPersonName, string stringPersonGender, string stringPersonIdentity, string stringPersonBirthDate);
+	int UploadECGData_GuanXin(string stringLocalFilePath, string stringECGXmlPath, string stringECGDataPath);
+	int UploadOtherData_GuanXin(string stringLocalFilePath, string stringOtherXmlPath);
+	int UploadCheckData_GuanXin(string stringLocalFilePath, string stringCheckXmlPath);
+	int UploadPersonInfo_GuanXin(string stringLocalFilePath, string stringPersonInfoXmlPath);
+
+	
+
+	//院内使用接口
+	int SetCliniqueBusy(string stringCliniqueId);
+	int SetCliniqueFree(string stringCliniqueId);
+	int SetCliniqueChecking(string stringCliniqueId);
+	int SetCliniqueShoutComplete(string stringCliniqueId);
+	int GetPatientInfoByAppNum(string stringLocalFilePath, string stringHospitalId, string stringOrderType, string stringOrderId, string stringReqDepart, string stringOrderState, string stringCheckType, string stringStartDate, string stringEndDate, string stringClinicId);
+	int GetPatientInfoByAppNumToHis(string stringLocalFilePath, string stringHospitalId, string stringOrderType, string stringOrderId);
+	int GetPatientInfoByAppNumToPhmsAndHis(string stringLocalFilePath, string stringHospitalId, string stringOrderType, string stringOrderId);
+	int ApplyCheck(string stringCliniqueId, string stringOrderId, string stringOrderType);
+	int GetWaitingCheck(string stringLocalFilePath, string stringCliniqueId);
+	int GetCliniqueState(string stringLocalFilePath, string stringCliniqueId);
+	int NotifyCaseState(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int NotifyReportState(string stringReportId);
+	int SetDoctorAgentId(string stringDoctorAgentId);
+	int NotifyAppState(string stringUnitId, string stringOrderId, string stringOrderType, string stringState);
+	int VerifyAppState(string stringLocalFilePath, string stringOrderId, string stringOrderType);
+	int GetHisReportState(string stringLocalFilePath, string stringHospitalId, string stringOrderType, string stringOrderId);
+	int SetHisCriticalValue(string stringHospitalId, string stringCaseId, string stringCriticalValues);
+	//东亚医讯接口
+	int GetDoctorList_999120(string stringLocalFilePath, string stringKtCliniqueId, string stringCaseTypeId);
+	int ValidatePay_999120(string stringLocalFilePath, string stringConsumeId, string stringKtCliniqueId, string stringCardNumber, string stringKtDoctorId, string stringConsumeMoney, string stringCaseTypeId);
+	int UpdateCaseForConsumerRecord_999120(string stringLocalFilePath, string stringConsumeId, string stringKtCaseId, string stringCaseTypeId);
+	//北京心医接口
+	int ValidatePay_XinJie(string stringLocalFilePath, string stringRrn, string stringLocalDate);
+	int NotifyCheck_XinJie(string stringLocalFilePath, string stringRrn, string stringLocalDate);
+	//电信健康小屋接口
+	int UserAuthorize_Telecom(string stringLocalFilePath, string stringPersonId, string stringName, string stringNation, string stringAddress, string stringRoomId);
+	int BloodPressureUpload_Telecom(string stringLocalFilePath, string stringPersonType, string stringPersonId, string stringSBP, string stringDBP, string stringAverageValue, string stringPulseRate, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int BloodOxygenUpload_Telecom(string stringLocalFilePath, string stringPersonType, string stringPersonId, string stringBloodOxygen, string stringPulseRate, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int BloodSugarUpload_Telecom(string stringLocalFilePath, string stringPersonType, string stringPersonId, string stringBloodSugar, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int HeightWeightUpload_Telecom(string stringLocalFilePath, string stringPersonType, string stringPersonId, string stringHeight, string stringWeight, string stringBMI, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int LungUpload_Telecom(string stringLocalFilePath, string stringPersonType, string stringPersonId, string stringM_B1, string stringBSA, string stringBSA1, string stringMMF, string stringMefSeventyFive, string stringMefFifty, 
+		string stringMefTwentyFive, string stringMefFVST, string stringIC, string stringIRV, string stringERV, string stringFevOne, string stringFevTwo, string stringFevThree, 
+		string stringFevOnePer, string stringFevTwoPer, string stringFevThreePer, string stringRR, string stringFVC, string stringPEF, string stringTV, string stringVC, string stringMVV, 
+		string stringMV, string stringVSTHeight, string stringVSMvvBsa, string stringVSMvvOne, string stringSVC, string stringFevOneZeroFive, string stringFevOneZeroFivePer, string stringPefOne, 
+		string stringPefTwo, string stringPefThree, string stringFive, string stringFiveOne, string stringFiveTwo, string stringFiveThree, string stringPIF, string stringMifFifty, 
+		string stringDetectionTime, string stringEquCode, string stringRoomId);
+	int ECGUpload_Telecom(string stringLocalFilePath, string stringPersonType, string stringPersonId, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId, TELCOM_ECG ecgData);
+	//东软熙康接口
+	int Login_XiKang(string stringLocalFilePath, string stringUsername, string stringPassword);
+	int RegisterPatientId_XiKang(string stringLocalFilePath, string stringName, string stringSex, string stringPhoneNum, string stringProofNum);
+	int RegisterPatientInfo_XiKang(string stringLocalFilePath, string stringPatientOpenId, string stringName, string stringSex, string stringPhoneNum, string stringProofNum, string stringPassword);
+	int BindPatient_XiKang(string stringLocalFilePath, string stringDoctorOpenId, string stringPatientOpenId);
+	int GetPatientIdList_XiKang(string stringLocalFilePath, string stringDoctorOpenId);
+	int GetPatientInfo_XiKang(string stringLocalFilePath, string stringPatientOpenId);
+	int SearchPatientId_XiKang(string stringLocalFilePath, string stringKey, string stringValue);
+	int GetCaseList_XiKang(string stringLocalFilePath, vector<string> vPatientOpenId);
+	int SubmitCase_XiKang(string stringLocalFilePath, string stringPatientOpenId, string stringAdvice, string stringCaseType, string stringEcgXmlContent);
+	int GetReportFile_XiKang(string stringLocalFilePath, string stringCaseId);
+	int UploadFile_XiKang(string stringLocalFilePath, string stringCaseId, string stringCaseFilePath);
+	//公卫接口
+	int ExecuteGWService(string stringLocalFilePath, string stringLastPath, string stringJson, string stringFilePath);
+	//通用RESTful接口
+	int ExecuteCommonRESTful(string stringLocalFilePath, string stringIp, string stringPort, string stringUrl, string stringContentType, string stringPayload);
+};

+ 9 - 0
GlobalTerminalLogoString.h

@@ -0,0 +1,9 @@
+#include <string>
+
+using std::string;
+
+extern string g_stringTerminalType;
+extern string g_stringContecServerAddr;
+extern string g_stringContecServerPort;
+extern string g_stringUsername;
+extern string g_stringPassword;

+ 47 - 0
HandleMutexManager.cpp

@@ -0,0 +1,47 @@
+#include "HandleMutexManager.h"
+#include "ErrorCode.h"
+
+Mutex CHandleMutexManager::m_mutexHandleMutex;
+map<string, Mutex*> CHandleMutexManager::m_mapHandleAndMutex;
+
+int CHandleMutexManager::InsertHandleMutex(string stringUuid)
+{
+	Mutex::ScopedLock lock(m_mutexHandleMutex);
+	if(m_mapHandleAndMutex.find(stringUuid) != m_mapHandleAndMutex.end())
+	{
+		//˵Ã÷¸ÃhandleµÄmutexÒÑ´æÔÚ
+		return PHMS_SUCCESSFUL_RESULT;
+	}
+	m_mapHandleAndMutex.insert(map<string, Mutex*>::value_type(stringUuid, new Mutex));
+	return PHMS_SUCCESSFUL_RESULT;
+}
+int CHandleMutexManager::DeleteHandleMutex(string stringUuid)
+{
+	Mutex::ScopedLock lock(m_mutexHandleMutex);
+	Mutex* pMutex = NULL;
+	if(m_mapHandleAndMutex.find(stringUuid) != m_mapHandleAndMutex.end())
+	{
+		pMutex = m_mapHandleAndMutex[stringUuid];
+	}
+	if(pMutex != NULL)
+	{
+		m_mapHandleAndMutex.erase(stringUuid);
+		delete pMutex;
+	}
+	else
+	{
+		return COMMON_INVALID_HANDLE;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+Mutex* CHandleMutexManager::GetHandleMutex(string stringUuid)
+{
+	Mutex::ScopedLock lock(m_mutexHandleMutex);
+	Mutex* pMutex = NULL;
+	if(m_mapHandleAndMutex.find(stringUuid) != m_mapHandleAndMutex.end())
+	{
+		pMutex = m_mapHandleAndMutex[stringUuid];
+	}
+	return pMutex;
+}

+ 21 - 0
HandleMutexManager.h

@@ -0,0 +1,21 @@
+#pragma once
+#include "string"
+#include <map>
+#include "Poco/Mutex.h"
+#include "Poco/Thread.h"
+
+using namespace::std;
+using Poco::FastMutex;
+using Poco::Mutex;
+using Poco::Thread;
+
+class CHandleMutexManager
+{
+public:
+	static int InsertHandleMutex(string stringUuid);
+	static int DeleteHandleMutex(string stringUuid);
+	static Mutex* GetHandleMutex(string stringUuid);
+private:
+	static Mutex m_mutexHandleMutex;
+	static map<string, Mutex*> m_mapHandleAndMutex;
+};

+ 402 - 0
HttpPushSession.cpp

@@ -0,0 +1,402 @@
+#include "HttpPushSession.h"
+#include "Poco/Net/MediaType.h"
+#include "Poco/Exception.h"
+#include "Poco/Net/MultipartWriter.h"
+#include "Poco/Net/NameValueCollection.h"
+#include "ErrorCode.h"
+#include <fstream>
+#include "Poco/Buffer.h"
+#include "Poco/Timespan.h"
+#include "PhmsLogger.h"
+#include "Util.h"
+#include "GlobalTerminalLogoString.h"
+#include <sstream>
+#include "PhmsResponse.h"
+
+using Poco::Exception;
+using Poco::TimeoutException;
+using Poco::Net::MultipartWriter;
+using Poco::Net::MediaType;
+using Poco::Net::MessageHeader;
+using Poco::Buffer;
+using Poco::Timespan;
+using Poco::Net::NameValueCollection;
+using std::ifstream;
+
+CHttpPushSession::CHttpPushSession(void):m_bSsl(false)
+{
+	m_pSession = new HTTPClientSession();
+	m_pContext = NULL;
+}
+
+CHttpPushSession::CHttpPushSession(bool bSsl):m_bSsl(bSsl)
+{
+	if(!m_bSsl)
+	{
+		m_pSession = new HTTPClientSession();
+		m_pContext = NULL;
+	}
+	else
+	{
+		//不知道为什么调用Poco::Net::initializeSSL()不起作用,无参数的HTTPSClientSession构造函数报错,必须先创建一个Context
+		//然后调用传入Context::Ptr类型的HTTPSClientSession构造函数,以后有时间在研究
+		//不必考虑ssl初始化函数重入,Poco::Crypto::OpenSSLInitializer::initialize()函数做了互斥
+		m_pContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false);
+		m_pSession = new HTTPSClientSession(m_pContext);
+	}
+}
+
+CHttpPushSession::CHttpPushSession(CNetConfig netConfig):m_bSsl(netConfig.GetSsl())
+{
+	if(!m_bSsl)
+	{
+		m_pSession = new HTTPClientSession();
+		m_pContext = NULL;
+	}
+	else
+	{
+		m_pContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false);
+		m_pSession = new HTTPSClientSession(m_pContext);
+	}
+}
+
+CHttpPushSession::~CHttpPushSession(void)
+{
+	delete m_pSession;
+	m_pSession = NULL;
+}
+
+//Getter
+bool CHttpPushSession::GetSsl()
+{
+	return m_bSsl;
+}
+HTTPClientSession* CHttpPushSession::GetHttpClientSession()
+{
+	return m_pSession;
+}
+
+
+int CHttpPushSession::ExecuteHttpPushSession(CNetConfig& netConfig, CPhmsRequest& phmsRequest, pHttpPushCallback pCallback)
+{
+	//if(m_pSession->connected())
+	{
+		m_pSession->release();
+	}
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = this->SetNetWork(netConfig);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+		return nRet;
+	}
+	HTTPRequest httpRequest;
+	string stringBoundary = MultipartWriter::createBoundary();
+	this->GenerateHttpRequest(netConfig, phmsRequest, stringBoundary, httpRequest);
+	try
+	{
+		m_pSession->setHttpPush();//设置推送http
+		ostream &requestStream = m_pSession->sendRequest(httpRequest);
+		nRet = this->SendPhms(requestStream, stringBoundary, phmsRequest);
+		if(nRet != PHMS_SUCCESSFUL_RESULT)
+		{
+			//写日志
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+			return nRet;
+		}
+	}
+	catch(TimeoutException &e)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SEND_TIMEOUT), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_SEND_TIMEOUT;
+	}
+	catch(Exception& e)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SEND_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_SEND_FAIL;
+	}
+	HTTPResponse httpResponse;
+	try
+	{
+		m_pSession->receiveResponseHead(httpResponse);
+		nRet = HandleHttpResponse(httpResponse);
+		if(nRet != PHMS_SUCCESSFUL_RESULT)
+		{
+			//写日志
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(httpResponse.getReason(), __FUNCTION__, __FILE__, __LINE__);
+			return nRet;
+		}
+		else
+		{
+			pCallback(NULL, 0);
+		}
+		int nChunkedLen = 0;
+		do 
+		{
+			string stringChunkedContent;
+			nChunkedLen = m_pSession->receiveResponseBody_PUSH(stringChunkedContent);
+			//判断Phms响应头
+			if(nChunkedLen != 0)
+			{
+				CPhmsResponse phmsResponse;
+				istringstream iPhmsResponse(stringChunkedContent);
+				nRet = phmsResponse.SetPhmsResponse(&iPhmsResponse, this);
+				if(nRet != PHMS_SUCCESSFUL_RESULT)
+				{
+					CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+					return nRet;
+				}
+				string stringXmlContent;
+				string stringXmlPath;
+				nRet = phmsResponse.GetResult(1, stringXmlContent, stringXmlPath);
+				if(nRet != PHMS_SUCCESSFUL_RESULT)
+				{
+					CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+					return nRet;
+				}
+				if(pCallback != NULL)
+				{
+					pCallback(stringXmlContent.c_str(), (unsigned long)stringXmlContent.size());
+				}
+			}
+		} while (nChunkedLen != 0);
+	}
+	//无timeout超时,推送是recv无限等待
+	catch(Exception& e)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_FAIL;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+
+int CHttpPushSession::GetHttpExceptionInfo(int& nCode, string& stringMsgName, string& stringMsgText)
+{
+	const Exception* p = m_pSession->networkException();
+	if(p != NULL)
+		nCode = p->code();
+	stringMsgName = p->name();
+	stringMsgText = p->message();
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CHttpPushSession::abort()
+{
+	try
+	{
+		m_pSession->abort();
+	}
+	catch(Exception&)
+	{
+		//异常说明socket已经是无效的了,其效果等同于abort成功,所以异常捕获里无操作
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CHttpPushSession::SetNetWork(CNetConfig& netConfig)
+{
+	if(m_bSsl != netConfig.GetSsl())
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SSL_CONFLICT_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_SSL_CONFLICT_ERROR;
+	}
+	if(netConfig.ValidatePort()==false || netConfig.ValidAddrAndUrl()==false)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NET_CONFIG_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NET_CONFIG_ERROR;
+	}
+	if(netConfig.GetPrpxyType() != NO_PROXY)
+	{
+		if(netConfig.ValidateProxyInfo() == false)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PROXY_INFO_ERROR), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_PROXY_INFO_ERROR;
+		}
+	}
+	m_pSession->setHost(netConfig.GetHost());
+	m_pSession->setAddr(netConfig.GetAddr());
+	m_pSession->setPort(netConfig.GetPort());
+	if(netConfig.GetPrpxyType() == HTTP_PROXY)
+	{
+		m_pSession->setProxyType(HTTP_PROXY);
+		m_pSession->setProxy(netConfig.GetProxyAddr(), netConfig.GetProxyPort());
+		m_pSession->setProxyCredentials(netConfig.GetProxyUsername(), netConfig.GetProxyPassword());
+	}
+	if(netConfig.GetPrpxyType() == SOCK_PROXY)
+	{
+		m_pSession->setProxyType(SOCK_PROXY);
+		m_pSession->setProxy(netConfig.GetProxyAddr(), netConfig.GetProxyPort());
+		m_pSession->setProxyCredentials(netConfig.GetProxyUsername(), netConfig.GetProxyPassword());
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+int CHttpPushSession::GenerateHttpRequest(CNetConfig& netConfig, CPhmsRequest& phmsRequest, string stringBoundary, HTTPRequest& httpRequest)
+{
+	httpRequest.setVersion(HTTPMessage::HTTP_1_1);
+	httpRequest.setMethod(HTTPRequest::HTTP_POST);
+	httpRequest.setURI(netConfig.GetUrl());
+	httpRequest.setKeepAlive(false);
+	httpRequest.set("pragma", "no-cache");
+	httpRequest.set("User-Agent", g_stringTerminalType);
+	if(phmsRequest.GetPhmsRequestHead().GetOperationCode() != "1002")
+	{
+		NameValueCollection nameValueCollection;
+		nameValueCollection.add("PHPSESSID", phmsRequest.GetPhmsRequestHead().GetSessionId());
+		httpRequest.setCookies(nameValueCollection);
+	}
+	if(phmsRequest.GetFilePath().size() == 0)
+	{
+		//无附加文件
+		MediaType mediaType("application", "x-www-form-urlencoded");
+		mediaType.setParameter("charset", "GB2312");
+		httpRequest.setContentType(mediaType);
+		string stringParameterName = "msg=";
+		httpRequest.setContentLength(phmsRequest.ToString().size()+stringParameterName.size());
+	}
+	else
+	{
+		//有附件文件
+		MediaType mediaType("multipart", "form-data");
+		mediaType.setParameter("boundary", stringBoundary);
+		httpRequest.setContentType(mediaType);
+		//由于当前使用的Nginx版本,不支持客户端的chunked模式请求,所以暂时不使用chunked模式请求
+		//Nginx服务器到版本1.3.9才支持chunked模式的请求
+		//服务器添加了支持chunked请求的模块2012-12-25
+		httpRequest.setChunkedTransferEncoding(true);
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CHttpPushSession::SendPhms(ostream& outputStream, string stringBoundary, CPhmsRequest& phmsRequest)
+{
+	if(phmsRequest.GetFilePath().size() == 0)
+	{
+		//无附加文件
+		try
+		{
+			outputStream.exceptions(ios::failbit|ios::badbit);
+			outputStream<<"msg="<<phmsRequest.ToString();
+		}
+		catch(const ios::failure& error)
+		{
+			//写日志
+			int nCode = 0;
+			string stringMsgName;
+			string stringMsgText;
+			this->GetHttpExceptionInfo(nCode, stringMsgName, stringMsgText);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(stringMsgText, __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_OUTPUT_STREAM_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_OUTPUT_STREAM_FAIL;
+		}
+		catch(const TimeoutException& e)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SEND_TIMEOUT), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_SEND_TIMEOUT;
+		}
+		catch(const Exception& e)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SEND_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_SEND_FAIL;
+		}
+	}
+	else
+	{
+		//有附加文件
+		MediaType mediaType1("");
+		MediaType mediaType2("");
+		MessageHeader messageHeader1;
+		MessageHeader messageHeader2;
+		mediaType1.setType("form-data");
+		mediaType1.setParameter("name", "msg");
+		mediaType2.setType("form-data");
+		mediaType2.setParameter("name", "filename");
+		mediaType2.setParameter("filename", phmsRequest.GetFilePath());
+		messageHeader1.set("Content-Disposition", mediaType1.toString());
+		messageHeader2.set("Content-Disposition", mediaType2.toString());
+		try
+		{
+			MultipartWriter multipartWrite(outputStream, stringBoundary);
+			multipartWrite.nextPart(messageHeader1);
+			outputStream<<phmsRequest.ToString();
+			multipartWrite.nextPart(messageHeader2);
+			ifstream inputFileStream;
+			inputFileStream.exceptions(ios::badbit);
+			inputFileStream.open(phmsRequest.GetFilePath().c_str(), ios::in|ios::binary);
+			if(inputFileStream.fail())
+			{
+				CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_FILE_OPEN_FAIL), __FUNCTION__, __FILE__, __LINE__);
+				return COMMON_FILE_OPEN_FAIL;
+			}
+			outputStream.exceptions(ios::failbit|ios::badbit);
+			while(!inputFileStream.eof())
+			{
+				Buffer<char> bufFileContent(1024);
+				memset(bufFileContent.begin(), 0, 1024);
+				inputFileStream.read(bufFileContent.begin(), 1024);
+				outputStream.write(bufFileContent.begin(), inputFileStream.gcount());
+			}
+			multipartWrite.close();
+			inputFileStream.close();
+		}
+		catch(const ios::failure& error)
+		{
+			//写日志
+			if(outputStream.fail() || outputStream.bad())
+			{
+				int nCode = 0;
+				string stringMsgName;
+				string stringMsgText;
+				this->GetHttpExceptionInfo(nCode, stringMsgName, stringMsgText);
+				CPhmsLogger::GetPhmsLogger()->WriteLog(stringMsgText, __FUNCTION__, __FILE__, __LINE__);
+			}
+			CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_OUTPUT_STREAM_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_OUTPUT_STREAM_FAIL;
+		}
+		catch(const TimeoutException& e)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SEND_TIMEOUT), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_SEND_TIMEOUT;
+		}
+		catch(const Exception& e)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_SEND_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_SEND_FAIL;
+		}
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CHttpPushSession::HandleHttpResponse(HTTPResponse& httpResponse)
+{
+	switch(httpResponse.getStatus())
+	{
+	case HTTPResponse::HTTP_OK:
+		return PHMS_SUCCESSFUL_RESULT;
+	case HTTPResponse::HTTP_NOT_FOUND:
+	case HTTPResponse::HTTP_FORBIDDEN:
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_URL_NOT_FOUND), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_URL_NOT_FOUND;
+	default:
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_CONTENT_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_CONTENT_FAIL;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+

+ 45 - 0
HttpPushSession.h

@@ -0,0 +1,45 @@
+#pragma once
+#include "Poco/Net/HTTPClientSession.h"
+#include "Poco/Net/HTTPSClientSession.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/HTTPResponse.h"
+#include "Poco/Net/Context.h"
+#include <istream>
+#include <ostream>
+
+#include "PhmsRequest.h"
+#include "PhmsResponse.h"
+#include "NetConfig.h"
+#include "PhmsDataType.h"
+
+using Poco::Net::HTTPClientSession;
+using Poco::Net::HTTPSClientSession;
+using Poco::Net::HTTPRequest;
+using Poco::Net::HTTPResponse;
+using Poco::Net::HTTPMessage;
+using Poco::Net::Context;
+class CHttpPushSession
+{
+public:
+	CHttpPushSession(void);
+	CHttpPushSession(bool bSsl);
+	CHttpPushSession(CNetConfig netConfig);
+	~CHttpPushSession(void);
+private:
+	bool m_bSsl;
+	HTTPClientSession* m_pSession;
+	Context::Ptr m_pContext;
+public:
+	//Getter
+	bool GetSsl();
+	HTTPClientSession* GetHttpClientSession();
+
+	int ExecuteHttpPushSession(CNetConfig& netConfig, CPhmsRequest& phmsRequest, pHttpPushCallback pCallback);
+	int GetHttpExceptionInfo(int& nCode, string& msgName, string& msgText);
+	int abort();
+private:
+	int SetNetWork(CNetConfig& netConfig);
+	int GenerateHttpRequest(CNetConfig& netConfig, CPhmsRequest& phmsRequest, string stringBoundary, HTTPRequest& httpRequest);
+	int SendPhms(ostream& outputStream, string stringBoundary, CPhmsRequest& phmsRequest);
+	int HandleHttpResponse(HTTPResponse& httpResponse);
+};

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1228 - 0
HttpSession.cpp


+ 67 - 0
HttpSession.h

@@ -0,0 +1,67 @@
+#pragma once
+#include "Poco/Net/HTTPClientSession.h"
+#include "Poco/Net/HTTPSClientSession.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/HTTPResponse.h"
+#include "Poco/Net/Context.h"
+#include <istream>
+#include <ostream>
+
+#include "PhmsRequest.h"
+#include "PhmsResponse.h"
+#include "NetConfig.h"
+
+using Poco::Net::HTTPClientSession;
+using Poco::Net::HTTPSClientSession;
+using Poco::Net::HTTPRequest;
+using Poco::Net::HTTPResponse;
+using Poco::Net::HTTPMessage;
+using Poco::Net::Context;
+
+
+class CHttpSession
+{
+public:
+	CHttpSession(void);
+	CHttpSession(bool bSsl);
+	CHttpSession(CNetConfig netConfig);
+	~CHttpSession(void);
+private:
+	bool m_bSsl;
+	HTTPClientSession* m_pSession;
+	Context::Ptr m_pContext;
+public:
+	//Getter
+	bool GetSsl();
+	HTTPClientSession* GetHttpClientSession();
+
+	int ExecuteHttpSession(CNetConfig& netConfig, CPhmsRequest& phmsRequest, istream* & pInputStream);
+	//该接口用于非Phms协议的Http请求,用于直接请求某资源,比如http直接请求xml升级配置文件或其他文件,不通过php
+	int ExecuteNoPhmsHttpSession(CNetConfig& netConfig, istream* & pInputStream, int bContinue, string stringLocalFilePath="");
+	//该接口用于非Phms协议的Http请求,比如使用Post提交Form表单,通过php(暂时不支持附带文件的表单,以后有需求可以扩充)
+	int	ExecuteFormHttpSession(CNetConfig& netConfig, map<string, string> mapParam, istream* & pInputStream);
+	//该接口用于非Phms协议的Http请求,比如使用Post提交Form表单,可选附带或者不附带文件,通过php等脚本
+	int	ExecuteFormHttpSession(CNetConfig& netConfig, map<string, string> mapParam, string stringLocalFilePath, istream* & pInputStream);
+	//该接口用于非Phms协议的Http请求,比如提交xml,用于东亚医讯接口或用于心界的接口
+	int ExecuteXmlHttpSession(CNetConfig& netConfig, string stringXmlContent, istream* & pInputStream);
+	//该接口用于非Phms协议的Http请求,用于使用GET方式提交参数
+	int ExeceteGetHttpSession(CNetConfig& netConfig, map<string, string> mapParam, istream* & pInputStream);
+	//该接口用于通用POST请求,参数中决定Content-Type、HttpBody以及URL Param
+	int ExeceteCommonPostSession(CNetConfig& netConfig, map<string, string> mapParam, string stringContentType, string stringHttpBody, istream* & pInputStream);
+	
+	
+	int GetHttpExceptionInfo(int& nCode, string& msgName, string& msgText);
+	int AbortSession();
+private:
+	int SetNetWork(CNetConfig& netConfig);
+	int GenerateHttpRequest(CNetConfig& netConfig, CPhmsRequest& phmsRequest, string stringBoundary, HTTPRequest& httpRequest);
+	int GenerateNoPhmsHttpRequest(CNetConfig& netConfig, HTTPRequest& httpRequest, int bContinue, string stringLocalFilePath="");
+	int GenerateFormHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, string& stringParam, HTTPRequest& httpRequest);
+	int GenerateFormHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, string stringLocalFilePath, string stringBoundary, HTTPRequest& httpRequest);
+	int GeneratePostHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, string stringContentType, string stringHttpBody, HTTPRequest& httpRequest);
+	int GenerateXmlHttpRequest(CNetConfig& netConfig, string stringXmlContent, HTTPRequest& httpRequest);
+	int GenerateGetHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, HTTPRequest& httpRequest);
+	int SendPhms(ostream& outputStream, string stringBoundary, CPhmsRequest& phmsRequest);
+	int SendPostMapAndFile(ostream& outputStream, string stringBoundary, map<string, string> mapParam, string stringLocalFilePath);
+	int HandleHttpResponse(HTTPResponse& httpResponse);
+};

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 4947 - 0
InternalNetIntetface.cpp


+ 435 - 0
InternalNetIntetface.h

@@ -0,0 +1,435 @@
+#pragma once
+#include <string>
+#include <vector>
+#include <map>
+#include "PhmsDataType.h"
+#include "PhmsSession.h"
+#include "Poco/Event.h"
+
+using namespace std;
+using Poco::Event;
+class CInternalNetIntetface
+{
+public:
+	CInternalNetIntetface(void);
+	~CInternalNetIntetface(void);
+private:
+	CPhmsSession* m_pPhmsSession;
+	int m_nSaveType;
+	string m_stringContent;
+	string m_stringFilePath;
+	Event m_eventSocketAbort;
+	string m_stringIp;
+public:
+	//Setter
+	void SetSaveType(int nSaveType);
+	void SetFilePath(string stringFilePath);
+	void SetSessionId(string stringSessionId);
+	void SetCommandType(EnumPhmsCommandType enumCommandType);
+	void SetGWSessionId(string stringSessionId);
+	//Getter
+	int GetSaveType();
+	string GetContent();
+	string GetSessionId();
+	EnumPhmsCommandType GetCommandType();
+	string GetIp();
+	string GetGWSessionId();
+private:
+	typedef struct  tagSEGMENT_INFO
+	{
+		string m_stringStart;
+		string m_stringEnd;
+		string m_stringMd5;
+	}SEGMENT_INFO;
+	typedef vector< SEGMENT_INFO > vSegmentInfo;
+	int LoadServerPathAndAlreadyUploadSize(string stringLocalIniPath, string& stringServerPath, string& stringAlreadyUploadSize);
+	int StoreServerPathAndAlreadyUploadSize(string stringLocalIniPath, string stringServerPath, string stringAlreadyUploadSize);
+	int GetUploadSegmentInfo(int nSegmentCount,unsigned long nAlreadyUploadSize, unsigned long nThisTimeUploadSize, string stringLocalPath, vSegmentInfo& vSI);
+	int GenerateTempUploadFile(int nAlreadyUploadSize, int nThisTimeUploadSize, string stringLocalFilePath, string& stringTempUploadFilePath);
+	int GetOrder(unsigned long nTotalSize, unsigned long nAlreadyUploadSize, unsigned long nThisTimeUploadSize, string& stringOrder);
+	int GetDownloadTempFileSize(string stringTempDirectory, int nThreadCount, unsigned long* pTempFileSize);
+	int DivideSegment(unsigned long nRemainFileSize, unsigned long nSegmentMaxSize, int& nThreadCount, unsigned long* pSegmentFileSize);
+	int CombineSegmentFile(string stringLocalFile, string stringTempDirectory, int nThreadCount);
+public:
+	//内部接口--针对PHMS接口
+	int Login(string stringRole, string stringUsername, string stringPassword, string stringLanguage, string stringToken, bool bMustSsl);
+
+	int MechineRegister(string stringCountry, string stringAreaId, string stringArea, string stringDevice, string stringSignature, string stringSerialnum);
+
+	int Logout();
+	int SetDoctorSign(string stringFilePath);
+
+	int SetDoctorPhoto(string stringFilePath);
+
+	int ApplyNewCase(string stringName, string stringThirdId, string stringDataType, string stringDataTypeName, string stringNotes, string stringHospitalId, 
+		string stringHospitalName, string stringDoctorId, string stringDoctorName, string stringCheckTime, string stringOtherParam, string stringDeviceId, string stringDeviceName, 
+		string stringMd5, string stringCaseOrigin, string stringYzlb, string stringSex, string stringApplicationNo, string stringAutoMatic);
+
+	int UploadCaseSegment(string stringCaseId, unsigned long nTotalSize,  unsigned long nAlreadyUploadSize, 
+		unsigned long nThisTimeUploadSize, string stringServerPath, string stringLocalPath);
+
+	int CaseHoldPlace(string stringCaseId, string stringReceiverId);
+
+	int GetAutoDownloadCase(string stringCaseType,string stringSenderId,string stringCaseOrigin);
+
+	int DownloadCaseBegin(string stringCaseId, string stringReceiverId);
+
+	int DownloadFileSegment(string stringUri, unsigned long nBeginPos, unsigned long nEndPos);
+
+	int DownloadCaseComplete(string stringCaseId, string stringReceiverId);
+
+	int InvalidCase(string stringCaseId, string stringReceiverId, string stringReason);
+
+	int TransmitCase(string stringCaseId, string stringReceiverId, string stringForwardToH, string stringForwardToHospitalName, 
+		string stringForwardToD, string stringForwardToDoctorName);
+
+	int RollbackCase(string stringCaseId, string stringReceiverId, string stringBackTo);
+
+	int GetHospitalListOfGroup(string stringHGroupId, string stringType, string stringCaseType, unsigned int nPageTo, unsigned int nPageSize);
+
+	int GetDoctorListOfHospital(string stringHospitalId, string stringDoctorId, string stringCaseType, string stringDoctorType, unsigned int nPageTo, unsigned int nPageSize);
+
+	int AnalyzeBegin(string stringCaseId, string stringReceiverId, string stringCaseType);
+
+	int AnalyzeComplete(string stringCaseId, string stringReceiverId, string stringCaseType);
+
+	int ApplyNewReport(string stringCaseId, string stringReceiverId, string stringDiagnosis, string stringMd5, string stringDigitalSign, string stringTimestampSign, string stringCaseType);
+
+	int UploadReportSegment(string stringCaseId, string stringReceiverId, string stringCaseType, string stringReportId, unsigned long nTotalSize,
+		unsigned long nAlreadyUploadSize, unsigned long nThisTimeUploadSize, string stringServerPath, string stringLocalPath, string stringFileType);
+
+	int DownloadReportBegin(string stringCaseId, string stringReportId);
+
+	int DownloadReportComplete(string stringCaseId, string stringReportId);
+
+	int GetAlreadyUploadFileSize(string stringUri);
+
+	int GetReviewReportList(string stringReportStartDate, string stringReportEndDate,string stringReviewStartDate,
+		string stringReviewEndDate, string stringReviewState, string stringCaseType, string stringPtName, string stringSenderId, string stringYzlb, string stringAId, 
+		string stringReviewerId, string stringReceiverId, string stringCaseId, unsigned int nPageTo, unsigned int nPageSize);
+
+	int ReviewReport(string stringReportKeyId, string stringReviewState, string stringPath, string stringDiagnostic, 
+		string stringDigitalSign, string stringTimeStampSign);
+
+	int GetReportStateOfCase(string stringCaseId);
+
+	int GetCaseListOfDoctor(string stringCaseId, string stringCaseType, string stringCaseSource, string stringCaseState,
+		string stringPatientName, string stringSenderId, string stringReceiverId, string stringStartDate, string stringEndDate, string stringCheckStartDate,
+		string stringCheckEndDate, string stringSenderName, string stringDiagnostic, string stringCaseOrigin, string stringYzlb, string stringAId, string stringSex, string stringOrderBy, 
+		string stringThirdId, string stringLang, string stringIsFullName, unsigned int nPageTo, unsigned int nPageSize);
+
+	int GetHospitalInfo(string stringHospitalId);
+
+	int UploadIm(string stringSenderId, string stringSenderName, string stringReceiverId, string stringMsgDirection,
+		string stringMsgType, string stringMsgContent, string stringCaseId, string stringCaseType);
+
+	int GetImList(string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgDirection,
+		string stringMsgType);
+
+	int GetImList2(string stringNextId);
+
+	int DownloadImComplete(string stringMsgId);
+
+	int SendPhoneMsg (string stringCardId, string stringPhoneNum, string stringMsg);
+
+	int UploadTrendData(string stringCardId, string stringDeviceId, string stringDeviceName, string stringCaseId, vector<RECORD_DATA> vRecordData);
+
+	int UploadTrendDataString(string stringCardId, string stringDeviceId, string stringDeviceName, string stringCaseId, vector<RECORD_DATA_STRING> vRecordData);
+
+	int UploadTrendDataFile(string stringFilePath);
+	
+	int UploadAudioSegment (string stringMsgId, unsigned long nTotalSize, unsigned long nAlreadyUploadSize, 
+		unsigned long nThisTimeUploadSize, string stringServerPath, string stringLocalPath);
+
+	int UploadAdvice (string stringUserId, string stringUsername, string stringMsg, string stringType, string stringIsSendMsg);
+
+	int GetAdvice (string stringSgId, string stringUserId, string stringDoctorId, string stringDownloadState, string stringType, 
+		string stringStartDate, string stringEndDate, unsigned int nPageTo, unsigned int nPageSize);
+
+	int DownloadAdviceComplete (string stringAdviceId);
+
+	int GetReportListOfCase (string stringCaseId);
+
+	int GetSelfInfo (string stringSenderId);//接口有变动,加了一个参数senderid,表示要查找信息的人,如为空表示自己
+
+	int ChangePwd (string stringOldPwd, string stringNewPwd);
+
+	int DoctorChangeInfo (string stringName, string stringSex, string stringTel, string stringBirthdear,
+		string stringPosition, string stringNotes);
+
+	int CliniqueChangeInfo (string stringPid, string stringName, string stringTel, string stringNotes);
+
+	int UserChangeInfo (string stringPid, string stringName, string stringSex, string stringTel, string stringBirthday,
+		string stringAddress, string stringLmp, string stringToken, string stringHeight, string stringWeight, string stringPhoto, string stringVCodeBeFollowed, string stringHospitalId, string stringOtherInfo);
+
+	int GetCaseListOfUser (string stringCaseId, string stringCaseType, string stringCaseState, string stringThirdId, string stringName, 
+		string stringStartDate, string stringEndDate, string stringCheckStartDate, string stringCheckEndDate, string stringCaseOrigin, 
+		string stringYzlb, string stringSex, string stringIsRead, string stringOrderBy, unsigned int nPageTo, unsigned int nPageSize);
+
+	int GetReportListOfUser (string stringReportId, string stringReportStartDate, string stringReportEndDate,
+		string stringCaseType, string stringReportState, string stringOrderBy, unsigned int nPageTo, unsigned int nPageSize);
+
+	int GetCardUserList (string stringCardId, string stringSenderId, string stringPersonId, string stringTel, string stringName,
+		string stringType, unsigned int nPageTo, unsigned int nPageSize);
+
+	int KeepSession();
+
+	int MarkCaseException(string stringCaseId, string stringReceiverId, int nResultFlag);
+
+	int MarkReportRead(string stringReportId);
+
+	int Feedback(string stringTitle, string stringNotes, string stringPhone, string stringFilePath);
+
+	int UploadTrendData2(string stringTargetPath);
+
+	int GetAllTeamList();
+
+	int GetDoctorListOfTeam(string stringTeamId);
+
+	int GetEventStream(string stringCaseId, string stringOriginalHospital);
+
+	int GetCaseTypeList(string stringLanguage);
+
+	int DoctorHandledCaseStatistics(string stringCaseType, string stringStartTime, string stringEndTime);
+
+	int UserRegister(string stringPhone, string stringName, string stringHeigth);
+
+	int GetTrendData(string stringUId, string stringInterUId, string stringTrendType, string stringStartDate, string stringEndDate, string stringNextId);//该接口目前只支持保存到文件
+
+	int GetLastPhysiologicalData();
+
+	int GetHealthDegree(string stringUId, string stringInterUId, string stringDate);
+
+	int GetUserOfNoAdviceAndMostData(string stringDays);
+
+	int AdviceDelay(string stringUId, string stringMinutes);
+
+	int AdviceComplete(string stringUId, string stringOptionType, string stringAdvice);
+
+	int GetUserListOfNoAdvice(string stringDays, unsigned int nPageTo, unsigned int nPageSize);
+
+	int AdviceBegin(string stringUId);
+
+	int GetUserListOfAdvicing(unsigned int nPageTo, unsigned int nPageSize);
+
+	int VerifyThirdId(string stringUId, string stringType);
+
+	int PersonIdRegister(string stringType, string stringRegFrom, string stringPersonId, string stringName, string stringSex, string stringBirthday, string stringAddress, 
+		string stringPhone, string stringHeigth, string stringUploadUnitId, string stringHospitalId, string stringHGroupId, string stringScode, string stringWxUId, string stringLmp, string stringWeight, string stringPassword, 
+		string stringThirdCode, string stringIsRegister);
+
+	int GetVerificationCode(string stringType, string stringPhone);
+
+	int GetAskList(string stringAskType, string stringAskEnd, string stringDoctorId, string stringIsAsk, string stringUserId, string stringStartTime, string stringEndTime, unsigned int nPageTo, unsigned int nPageSize);
+
+	int GetAskDetail(string stringAskId);
+
+	int GetQuestionList(string stringDoctorId, string stringReportType, string stringAskId);
+
+	int SubmitQuestion(string stringUserId, string stringAdvise, string stringReportType, string stringAskId, string stringAskedId, string stringDoctorPhotoPath);
+
+	int GetDataDictionary();
+
+	int LoggingHealthBaseInfo(string stringUserId, string stringWeblock, string stringNation, string stringProfression, string stringCrowd, string stringBloodType, 
+		string stringJwsJiBing, string stringJwsShouShu, string stringJwsWaiShang, string stringJwsShuXue, string stringJwsBaoLuShi, string stringJwsBaoLuShiBz, 
+		string stringJwsYiChuanJiBing, string stringGmsGuoMinShi, string stringGmsGuoMinShiBz, string stringJzsFuQin, string stringJzsFuQinBz, string stringJzsMuQin, 
+		string stringJzsMuQinBz, string stringJzsXdjm, string stringJzsXdjmBz, string stringJzsZiNv, string stringJzsZiNvBz, string stringJzsQiTa);
+
+	int LoggingHealthCurrentInfo(string stringUserId, string stringShfsYinShi, string stringShfsXlzk, string stringShfsXlzkBz, string stringShfsXltz, string stringShfsXiYan, 
+		string stringShfsYinJiu, string stringShfsSyqk, string stringShfsYunDong, string stringShfsYunDongShiJian, string stringSysjcDanGuChun, string stringSysjcXueChangGui, 
+		string stringSysjcXueChangGuiBz, string stringSysjcNiaoChangGui, string stringSysjcNiaoChangGuiBz, string stringSysjcQiTa, string stringYongYao, string stringZhuYuan, 
+		string stringJkwtNaoXueGuan, string stringJkwtNaoXueGuanBz, string stringJkwtShenZang, string stringJkwtShenZangBz, string stringJkwtXinZang, string stringJkwtXinZangBz, 
+		string stringJkwtXueGuan, string stringJkwtXueGuanBz, string stringJkwtYanBu, string stringJkwtYanBuBz, string stringJkwtShenJing, string stringJkwtQiTa, string stringDate);
+
+	int GetCliniqueListOfHospital(string stringHospitalId);
+
+	int GetStatisticsInfo(string stringTypeId, string stringMonth, string stringMonthDay, unsigned int nPageTo, unsigned int nPageSize);
+
+	int UpdateCaseInfo(string stringHospitalId, string stringCaseId, string stringOtherParam, string stringFlag, string stringNotes, string stringReceiverId);
+
+	int GetUserHealthList(string stringNextId, string stringTypeId, string stringSecondTypeId, string stringName, string stringSex, string stringThirdIdType, 
+		string stringThirdId, string stringHospitalId, string stringUnitSenderId, string stringIsData, string stringIntervalTime, string stringPopulations, string stringContractDoctor, string stringIsContract, string stringPageSize);
+
+	int GetAdviceImplemention(string stringThirdId, string stringHospitalId);
+
+	int ChangePersonType(string stringThirdId, string stringPeopleType, string stringHospitalId);
+
+	int SetNextVisitTime(string stringThirdId, string stringInterViewTime, string stringHospitalId);
+
+	int GetPersonTypeList(string stringLanguage);
+
+	int PersonIdRegisterAndLogin(string stringRole, string stringPId, string stringName, string stringSex, string stringBirthday, string stringAddress, string stringDeviceId, string stringMd5, 
+		string stringLang, string stringRegFrom);
+
+	int CardBindPhone(string stringPhone, string stringScode);
+
+	int ResetPassword(string stringPhone, string stringScode, string stringNewPwd);
+
+	int UploadDaily(string stringType, string stringCreateTime, string stringFiles);
+
+	int GetDateListOfDaily(string stringYear, string stringMonth);
+
+	int GetDailyOfDate(string stringDate, string stringType);
+
+	int ShareDaily(string stringType, string stringCreateTime);
+
+	int DeleteDaily(string stringType, string stringDate);
+
+	int PhoneScanQR(string stringQRCode);
+
+	int PhoneScanQRVerify(string stringQRCode);
+
+	int ApplyQRCode(string stringType, string stringScene);
+
+	int ValidateUserAccount(string stringLoginId, string stringPassword, string stringRole);
+
+	int RegisterBluetoothDevice(string stringUniqueSN, string stringSerial, string stringBluetoothAddress, string stringBluetoothName, string stringDeviceType);
+	
+	int GetBluetoothInfoOfDevice(string stringUniqueSN);
+	
+	int ChangeDeviceType(string stringUniqueSN, string stringDeviceType);
+	
+	int UnregisterBluetoothDevice(string stringUniqueSN);
+
+	int GetHospitalListOfArea(string stringAreaId, string stringRank, string stringBeta);
+	int UploadCommonFileSegment (string stringType, string stringExtra, unsigned long nTotalSize, unsigned long nAlreadyUploadSize, 
+		unsigned long nThisTimeUploadSize, string stringServerPath, string stringLocalPath, string stringFileType);
+	int SearchSomebody(string stringUserId);
+	int FollowSomebody(string stringUserId, string stringUsername, string stringNickname, string stringVCode);
+	int MyFollowing(string stringUserId, string stringNextId, string stringFType);
+	int MyFans(string stringUserId, string stringNextId);
+	int ChangeNicknameOfFollowed(string stringUserId, string stringNickname);
+	int CancelFollowing(string stringUserId);
+	int PublishHealthyKnowledge(vector<HEALTHY_KNOWLEDGE> vHealthKnowledge);
+	int GetListOfHealthyKnowledge(string stringSenderId, string stringNextId, string stringIds, string stringPageSize, string stringOrderBy);
+	int GenerateOrDeletePngZlibReport(string stringServerPath, string stringFlag);
+	int GetDailyList(string stringType, string stringStartDate, string stringEndDate, string stringOrderBy, string stringNextId, string stringPageSize);
+
+	int GetCardUserReportList(string stringReportId, string stringReportStartDate, string stringReportEndDate, string stringCaseType, string stringState, string stringOrderBy, 
+		string stringThirdIdType, string stringThirdId, string stringNextId, string stringPageSize);
+	int ChangeViewLikeCollectCount(string stringHealthTipId, string stringUri, string stringTitle, string stringLike, string stringRead, string stringCollect);
+	int ChangeAdviceExecutiveState(string stringSgId, string stringState);
+	int GetTrendRangeValue();
+	int GetCliniqueReportList(string stringCliniqueSenderId, string stringStartDate, 
+		string stringEndDate, string stringState, string stringName, string stringPatientSourceCode, string stringYzlb, string stringPIdType, string stringPId, string stringHb, string stringASectionId, string stringNextId, string stringPageSize);
+	int GetUserListBindingOrNot(string stringNextId, string stringPageSize, string stringIsBind, string stringIsActive);
+	int BindUser(string stringUId, string stringUName);
+	int UnbindUser(string stringUId);
+	int GetCardUserListOfCustomer(string stringThirdId, string stringName, string stringCaseType, string stringStartDate, string stringEndDate, string stringNextId, unsigned int nPageSize);
+	int SearchCaseAdvanced(string stringHospitalId, string stringDiagnostic, 
+		string stringName, string stringSex, QUERY_RANGE rangeAge, QUERY_RANGE rangeCreateTime, string stringMode, 
+		string stringCaseType, QUERY_ECG ecg, string stringFrom, string stringSize);
+	int SearchCaseAdvancedString(string stringHospitalId, string stringDiagnostic, 
+		string stringName, string stringSex, string stringJsonAge, string stringJsonCreateTime, string stringMode, 
+		string stringCaseType, string stringJsonEcg, string stringFrom, string stringSize);
+	int GetPayCode(string stringType, string stringCaseId);
+	int GetOrderInfo(string stringType, string stringCaseId);
+	int SignDoctor(string stringUId);
+	int RefundFee(string stringType, string stringCaseId, string stringRefundFee);
+	int HoldPlaceReview(string stringReportId);
+	int RollBackReview(string stringReportId);
+	int ResetReviewHoldPlace(string stringReportId, string stringOccupantId, string stringOccupantName, string stringSuperKey);
+	int ResetCaseHoldPlace(string stringCaseId, string stringReceiverId, string stringOccupantId, string stringOccupantName, string stringSuperKey);
+	int AddTag(string stringTagName, string stringTagDescription);
+	int GetTagList(string stringSenderId);
+	int AddCaseToTag(string stringTagId, string stringTagName, string stringCaseId, string stringCaseType, string stringCaseTypeName, string stringPatientName);
+	int GetCaseListOfTag(string stringTagId, string stringSenderId, string stringCaseType);
+
+	//冠新接口
+//	int CreateSession_GuanXin(string stringUsername, string stringPassword);
+	int GetAccessToken_GuanXin(string stringUsername, string stringPassword);
+	int GetPersonInfo_GuanXin(string stringAccessToken, string stringPersonName, string stringPersonGender, string stringPersonIdentity, string stringPersonBirthDate);
+	int UploadECGData_GuanXin(string stringECGXmlPath, string stringECGDataPath);
+	int UploadOtherData_GuanXin(string stringOtherXmlPath);
+	int UploadCheckData_GuanXin(string stringCheckXmlPath);
+	int UploadPersonInfo_GuanXin(string stringPersonInfoXmlPath);
+
+
+
+
+
+	//自定义内部接口,间接针对一个或多个Phms接口
+	//下载文件这个接口比较特殊,规定服务器返回的内容只能保存文件,不走对象的nSaveType指定,保存的服务器路径通过stringLocalFilePath传进来
+	int DownloadFile (int nThreadCount, string stringUri, unsigned long nFileSize, string stringLocalFilePath, pProgressAndSpeedCallback pCallback);
+
+	int UploadCase (string stringCaseId, string stringLocalCasePath, pProgressAndSpeedCallback pCallback);
+
+	int UploadReport (string stringCaseId, string stringReceiverId, string stringCaseType, string stringReportId, string stringLocalReportPath, string stringFileType, pProgressAndSpeedCallback pCallback);
+
+	int UploadAudio(string stringMsgId, string stringLocalAudioPath, pProgressAndSpeedCallback pCallback);
+
+	int UploadCommonFile(string& stringUri, string stringType, string stringExtra, string stringLocalFilePath, string stringFileType, pProgressAndSpeedCallback pCallback);
+
+	//用于即时退出Http Session
+	int AbortSession();
+
+
+
+	//内部接口--针对NoPhms接口,直接用http协议请求文件,不通过php
+	int GetFileWithHttp(string stringUrl, int bContinue);
+
+	//内部接口--针对Form表单
+	int PostForm(string stringHost, string stringUrl, map<string, string> mapParam);
+
+	//院内使用接口
+	int SetCliniqueState(string stringCliniqueId, string stringState);
+	int GetPatientInfoByAppNum(string stringHospitalId, string stringOrderType, string stringOrderId, string stringReqDepart, string stringOrderState, string stringCheckType, string stringStartDate, string stringEndDate,string stringClinicId);
+	int GetPatientInfoByAppNumToHis(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int GetPatientInfoByAppNumToPhmsAndHis(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int ApplyCheck(string stringCliniqueId, string stringOrderId, string stringOrderType);
+	int GetWaitingCheck(string stringCliniqueId);
+	int GetCliniqueState(string stringCliniqueId);
+	int NotifyCaseState(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int NotifyReportState(string stringReportId);
+	int SetDoctorAgentId(string stringDoctorAgentId);
+	int NotifyAppState(string stringUnitId, string stringOrderId, string stringOrderType, string stringState);
+	int VerifyAppState(string stringOrderId, string stringOrderType);
+	int GetHisReportState(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int SetHisCriticalValue(string stringHospitalId, string stringCaseId, string stringCriticalValues);
+
+	//东亚医讯Xml接口
+	int GetDoctorList_999120(string stringKtCliniqueId, string stringCaseTypeId);
+
+	int ValidatePay_999120(string stringConsumeId, string stringKtCliniqueId, string stringCardNumber, string stringKtDoctorId, string stringConsumeMoney, string stringCaseTypeId);
+
+	int UpdateCaseForConsumerRecord_999120(string stringConsumeId, string stringKtCaseId, string stringCaseTypeId);
+
+	//北京心医接口
+	int ValidatePay_XinJie(string stringRrn, string stringLocalDate);
+	int NotifyCheck_XinJie(string stringRrn, string stringLocalDate);
+
+	//电信健康小屋接口
+	int UserAuthorize_Telecom(string stringPersonId, string stringName, string stringNation, string stringAddress, string stringRoomId);
+	int BloodPressureUpload_Telecom(string stringPersonType, string stringPersonId, string stringSBP, string stringDBP, string stringAverageValue, string stringPulseRate, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int BloodOxygenUpload_Telecom(string stringPersonType, string stringPersonId, string stringBloodOxygen, string stringPulseRate, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int BloodSugarUpload_Telecom(string stringPersonType, string stringPersonId, string stringBloodSugar, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int HeightWeightUpload_Telecom(string stringPersonType, string stringPersonId, string stringHeight, string stringWeight, string stringBMI, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int LungUpload_Telecom(string stringPersonType, string stringPersonId, string stringM_B1, string stringBSA, string stringBSA1, string stringMMF, string stringMefSeventyFive, string stringMefFifty, 
+		string stringMefTwentyFive, string stringMefFVST, string stringIC, string stringIRV, string stringERV, string stringFevOne, string stringFevTwo, string stringFevThree, 
+		string stringFevOnePer, string stringFevTwoPer, string stringFevThreePer, string stringRR, string stringFVC, string stringPEF, string stringTV, string stringVC, string stringMVV, 
+		string stringMV, string stringVSTHeight, string stringVSMvvBsa, string stringVSMvvOne, string stringSVC, string stringFevOneZeroFive, string stringFevOneZeroFivePer, string stringPefOne, 
+		string stringPefTwo, string stringPefThree, string stringFive, string stringFiveOne, string stringFiveTwo, string stringFiveThree, string stringPIF, string stringMifFifty, 
+		string stringDetectionTime, string stringEquCode, string stringRoomId);
+	int ECGUpload_Telecom(string stringPersonType, string stringPersonId, string stringDetectionTime, string stringEquCode, string stringRoomId, TELCOM_ECG ecgData);
+
+	//东软熙康定制
+	int Login_XiKang(string stringUsername, string stringPassword);
+	int RegisterPatientId_XiKang(string stringName, string stringSex, string stringPhoneNum, string stringProofNum);
+	int RegisterPatientInfo_XiKang(string stringPatientOpenId, string stringName, string stringSex, string stringPhoneNum, string stringProofNum, string stringPassword);
+	int BindPatient_XiKang(string stringDoctorOpenId, string stringPatientOpenId);
+	int GetPatientIdList_XiKang(string stringDoctorOpenId);
+	int SearchPatientId_XiKang(string stringKey, string stringValue);
+	int GetPatientInfo_XiKang(string stringPatientOpenId);
+	int GetCaseList_XiKang(vector<string> vPatientOpenId);
+	int SubmitCase_XiKang(string stringPatientOpenId, string stringAdvice, string stringCaseType, string stringEcgXmlContent);
+	int GetReportFile_XiKang(string stringCaseId);
+	int UploadFile_XiKang(string stringCaseId, string stringCaseFilePath);
+
+	//公卫接口
+	int ExecuteGWService(string stringLastPath, string stringJson, string stringFilePath);
+	int ExecuteCommonRESTful(string stringIp, string stringPort, string stringUrl, string stringContentType, string stringPayload);
+};

+ 41 - 0
MsgListPush.cpp

@@ -0,0 +1,41 @@
+#include "MsgListPush.h"
+#include "ErrorCode.h"
+#include "PhmsLogger.h"
+#include "Util.h"
+#include <string>
+
+using namespace std;
+
+CMsgListPush::CMsgListPush(string stringUuid, string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgType, string stringMsgDirection, string stringVersion, pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback)
+:CPushBase(pCallback, pFailCallback, MSG_LIST_PUSH), m_stringUuid(stringUuid), m_stringSenderId(stringSenderId), m_stringCaseId(stringCaseId), m_stringCaseType(stringCaseType), m_stringMsgType(stringMsgType), m_stringMsgDirection(stringMsgDirection), m_stringVersion(stringVersion)
+{
+}
+
+CMsgListPush::~CMsgListPush(void)
+{
+}
+
+void CMsgListPush::ExecutePushSession()
+{
+	m_pPhmsPushSession->SetPushCallback(m_pHttpPushCallback);
+	while(m_bStopRetry==false)
+	{
+		int nRet = PHMS_SUCCESSFUL_RESULT;
+		nRet = m_pPhmsPushSession->PushMsg(m_stringSenderId, m_stringCaseId, m_stringCaseType, m_stringMsgType, m_stringMsgDirection, m_stringVersion);
+		if(nRet!=PHMS_SUCCESSFUL_RESULT)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+			if(nRet==COMMON_SESSION_INVALID || nRet==COMMON_LOGIN_ANOTHER_PLACE || nRet==COMMON_SERVER_NO_SUPPORT || nRet==COMMON_INVALID_CHARSET || nRet==COMMON_NET_CONFIG_ERROR || nRet==COMMON_URL_NOT_FOUND || nRet==COMMON_NO_NET_CONFIG_FILE)
+			{
+				m_pHttpPushFailCallback(nRet/*, (NET_HANDLE)m_stringUuid.c_str()*/);
+				break;
+			}
+			else
+			{
+				//只回调通知,不退出推送线程
+				m_pHttpPushFailCallback(nRet);
+				Poco::Thread::sleep(2000);
+			}
+		}
+	}
+}

+ 22 - 0
MsgListPush.h

@@ -0,0 +1,22 @@
+#pragma once
+#include "PushBase.h"
+#include "PhmsDataType.h"
+
+class CMsgListPush :
+	public CPushBase
+{
+public:
+	CMsgListPush(string stringUuid, string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgType, string stringMsgDirection, string stringVersion, 
+		pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback);
+	~CMsgListPush(void);
+
+	void ExecutePushSession();
+private:
+	string m_stringUuid;
+	string m_stringSenderId;
+	string m_stringCaseId;
+	string m_stringCaseType;
+	string m_stringMsgType;
+	string m_stringMsgDirection;
+	string m_stringVersion;
+};

+ 178 - 0
NetConfig.cpp

@@ -0,0 +1,178 @@
+#include "NetConfig.h"
+#include "ErrorCode.h"
+#include "PhmsLogger.h"
+#include "Util.h"
+
+CNetConfig::CNetConfig(void):m_nPort(0), m_enumProxyType(NO_PROXY), m_nProxyPort(0)
+{
+}
+
+CNetConfig::~CNetConfig(void)
+{
+}
+
+CNetConfig::CNetConfig(bool bSsl, string stringAddr, unsigned short nPort, EnumProxyType enumProxyType, string stringProxyAddr, unsigned short nProxyPort,
+					string stringProxyUsername, string stringProxyPassword, string stringUrl):m_bSsl(bSsl), m_stringAddr(stringAddr), m_nPort(nPort),
+					m_enumProxyType(enumProxyType), m_stringProxyAddr(stringProxyAddr), m_nProxyPort(nProxyPort), m_stringProxyUsername(stringProxyUsername),
+					m_stringProxyPassword(stringProxyPassword), m_stringUrl(stringUrl)
+{
+}
+
+//Setter
+void CNetConfig::SetSsl(bool bSsl)
+{
+	m_bSsl = bSsl;
+}
+void CNetConfig::SetAddr(string stringAddr)
+{
+	m_stringAddr = stringAddr;
+}
+void CNetConfig::SetHost(string stringHost)
+{
+	m_stringHost = stringHost;
+}
+void CNetConfig::SetPort(unsigned short nPort)
+{
+	m_nPort = nPort;
+}
+void CNetConfig::SetProxyType(EnumProxyType nProxyType)
+{
+	m_enumProxyType = nProxyType;
+}
+void CNetConfig::SetProxyAddr(string stringProxyAddr)
+{
+	m_stringProxyAddr = stringProxyAddr;
+}
+void CNetConfig::SetProxyPort(unsigned short nProxyPort)
+{
+	m_nProxyPort = nProxyPort;
+}
+void CNetConfig::SetProxyUsername(string stringProxyUsername)
+{
+	m_stringProxyUsername = stringProxyUsername;
+}
+void CNetConfig::SetProxyPassword(string stringProxyPassword)
+{
+	m_stringProxyPassword = stringProxyPassword;
+}
+void CNetConfig::SetUrl(string stringUrl)
+{
+	m_stringUrl = stringUrl;
+}
+void CNetConfig::SetIp(string stringIp)
+{
+	m_stringIp = stringIp;
+}
+
+//Getter
+bool CNetConfig::GetSsl()
+{
+	return m_bSsl;
+}
+string CNetConfig::GetAddr()
+{
+	return m_stringAddr;
+}
+string CNetConfig::GetHost()
+{
+	return m_stringHost;
+}
+unsigned short CNetConfig::GetPort()
+{
+	return m_nPort;
+}
+EnumProxyType CNetConfig::GetPrpxyType()
+{
+	return m_enumProxyType;
+}
+string CNetConfig::GetProxyAddr()
+{
+	return m_stringProxyAddr;
+}
+unsigned short CNetConfig::GetProxyPort()
+{
+	return m_nProxyPort;
+}
+string CNetConfig::GetProxyUsername()
+{
+	return m_stringProxyUsername;
+}
+string CNetConfig::GetProxyPassword()
+{
+	return m_stringProxyPassword;
+}
+string CNetConfig::GetUrl()
+{
+	return m_stringUrl;
+}
+string CNetConfig::GetIp()
+{
+	return m_stringIp;
+}
+
+bool CNetConfig::ValidatePort()
+{
+	if(m_nPort>=1 && m_nPort<=65535)
+	{
+		if(m_enumProxyType == HTTP_PROXY || m_enumProxyType == SOCK_PROXY)
+		{
+			if(m_nProxyPort>1 && m_nProxyPort<=65535)
+			{
+				return true;
+			}
+			else
+			{
+				CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_PORT), __FUNCTION__, __FILE__, __LINE__);
+				return false;
+			}
+		}
+
+	}
+	return true;
+}
+bool CNetConfig::ValidAddrAndUrl()
+{
+	if(m_stringAddr.size() == 0)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_IP), __FUNCTION__, __FILE__, __LINE__);
+		return false;
+	}
+	if(m_stringHost.size() == 0)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_IP), __FUNCTION__, __FILE__, __LINE__);
+		return false;
+	}
+	if(m_stringUrl.size() == 0)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_URL), __FUNCTION__, __FILE__, __LINE__);
+		return false;
+	}
+	if(m_enumProxyType == HTTP_PROXY || m_enumProxyType == SOCK_PROXY)
+	{
+		if(m_stringProxyAddr.size() == 0)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_IP), __FUNCTION__, __FILE__, __LINE__);
+			return false;
+		}
+	}
+	return true;
+}
+bool CNetConfig::ValidateProxyInfo()
+{
+	if(m_enumProxyType != HTTP_PROXY && m_enumProxyType != SOCK_PROXY)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PROXY_INFO_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return false;
+	}
+	if(m_stringProxyAddr.size() == 0)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PROXY_INFO_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return false;
+	}
+	if(m_nProxyPort>1 && m_nProxyPort<=65535)
+	{
+		return true;
+	}
+	CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PROXY_INFO_ERROR), __FUNCTION__, __FILE__, __LINE__);
+	return false;
+}

+ 65 - 0
NetConfig.h

@@ -0,0 +1,65 @@
+#pragma once
+
+#include <string>
+
+using namespace std;
+
+
+enum EnumProxyType
+{
+	NO_PROXY=0,
+	HTTP_PROXY,
+	SOCK_PROXY
+};
+
+class CNetConfig
+{
+public:
+	CNetConfig(void);
+	CNetConfig(bool bSsl, string stringAddr, unsigned short nPort, EnumProxyType enumProxyType, string stringProxyAddr, unsigned short nProxyPort,
+		string stringProxyUsername, string stringProxyPassword, string stringUrl);
+	~CNetConfig(void);
+private:
+	bool m_bSsl;
+	string m_stringAddr;
+	string m_stringHost;
+	unsigned short m_nPort;
+	EnumProxyType m_enumProxyType;
+	string m_stringProxyAddr;
+	unsigned short m_nProxyPort;
+	string m_stringProxyUsername;
+	string m_stringProxyPassword;
+	string m_stringUrl;
+	string m_stringIp;
+	
+public:
+	//Setter
+	void SetSsl(bool bSsl);
+	void SetAddr(string stringAddr);
+	void SetHost(string stringHost);
+	void SetPort(unsigned short nPort);
+	void SetProxyType(EnumProxyType enumProxyType);
+	void SetProxyAddr(string stringProxyAddr);
+	void SetProxyPort(unsigned short nProxyPort);
+	void SetProxyUsername(string stringProxyUsername);
+	void SetProxyPassword(string stringProxyPassword);
+	void SetUrl(string stringUrl);
+	void SetIp(string stringIp);
+
+	//Getter
+	bool GetSsl();
+	string GetAddr();
+	string GetHost();
+	unsigned short GetPort();
+	EnumProxyType GetPrpxyType();
+	string GetProxyAddr();
+	unsigned short GetProxyPort();
+	string GetProxyUsername();
+	string GetProxyPassword();
+	string GetUrl();
+	string GetIp();
+
+	bool ValidatePort();
+	bool ValidAddrAndUrl();
+	bool ValidateProxyInfo();
+};

+ 213 - 0
NetThreadManager.cpp

@@ -0,0 +1,213 @@
+#include "NetThreadManager.h"
+#include "AllObjectManagerUtil.h"
+#include "ErrorCode.h"
+#include "Poco/Exception.h"
+#include "Util.h"
+#include "PhmsLogger.h"
+
+using Poco::FileNotFoundException;
+
+map<string, CExternalNetInterface*> CNetThreadManager::m_map;
+map<Thread::TID, string> CNetThreadManager::m_mapTidAndHandle;
+map<string, Thread::TID> CNetThreadManager::m_mapHandleAndTid;
+
+int CNetThreadManager::InsertNetThread(string stringUuid)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	Thread::TID nThreadId = Thread::currentTid();
+	if(m_mapTidAndHandle.find(nThreadId) != m_mapTidAndHandle.end())
+	{
+		//说明该线程已经初始化过了
+		return PHMS_SUCCESSFUL_RESULT;
+	}
+	CExternalNetInterface* pNetInterface = NULL;
+	try
+	{
+		pNetInterface = new CExternalNetInterface();
+	}
+	catch(FileNotFoundException& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_NET_CONFIG_FILE), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NO_NET_CONFIG_FILE;
+	}
+	catch(Exception& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NET_CONFIG_READ_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NET_CONFIG_READ_ERROR;
+	}
+	m_map.insert(map<string, CExternalNetInterface*>::value_type(stringUuid, pNetInterface));
+	m_mapTidAndHandle.insert(map<Thread::TID, string>::value_type(nThreadId, stringUuid));
+	m_mapHandleAndTid.insert(map<string, Thread::TID>::value_type(stringUuid, nThreadId));
+	string stringSessionId;
+	if(CNetThreadManager::m_map.size() != 0)
+	{
+		map<string, CExternalNetInterface*>::const_iterator iter;
+		for(iter=CNetThreadManager::m_map.begin(); iter!=CNetThreadManager::m_map.end(); iter++)
+		{
+			if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
+			{
+				stringSessionId = iter->second->GetSessionId();
+				pNetInterface->SetSessionId(stringSessionId);
+				break;
+			}
+		}
+		//设置公卫系统的SessionId
+		for(iter=CNetThreadManager::m_map.begin(); iter!=CNetThreadManager::m_map.end(); iter++)
+		{
+			if(iter->second->GetGWSessionId().size()!=0 && iter->second->GetGWSessionId()!="00000000000000000000000000000000")
+			{
+				stringSessionId = iter->second->GetGWSessionId();
+				pNetInterface->SetGWSessionId(stringSessionId);
+				break;
+			}
+		}
+	}
+	else
+	{
+		map<string, CPushBase*>::const_iterator iter;
+		for(iter=CPushObjectManager::m_map.begin(); iter!=CPushObjectManager::m_map.end(); iter++)
+		{
+			if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
+			{
+				stringSessionId = iter->second->GetSessionId();
+				pNetInterface->SetSessionId(stringSessionId);
+				break;
+			}
+		}
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+
+int CNetThreadManager::DeleteNetThread(string stringUuid)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	CExternalNetInterface* pNetInterface = NULL;
+	if(m_map.find(stringUuid) != m_map.end())
+	{
+		pNetInterface = m_map[stringUuid];
+	}
+	if(pNetInterface != NULL)
+	{
+		m_map.erase(stringUuid);
+		Thread::TID nThreadId = m_mapHandleAndTid[stringUuid];
+		m_mapTidAndHandle.erase(nThreadId);
+		m_mapHandleAndTid.erase(stringUuid);
+		delete pNetInterface;
+		//CommonNetInterface中执行ReleasePhmsLogger
+		return PHMS_SUCCESSFUL_RESULT;
+	}
+	else
+	{
+		return COMMON_INVALID_HANDLE;
+	}
+}
+
+string CNetThreadManager::GetHandleByThreadId(Thread::TID nThreadId)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	string stringUuid;
+	if(m_mapTidAndHandle.find(nThreadId) != m_mapTidAndHandle.end())
+	{
+		stringUuid = m_mapTidAndHandle[nThreadId];
+	}
+	return stringUuid;
+}
+
+CExternalNetInterface* CNetThreadManager::GetNetThread(string stringUuid, bool bCrossingThread)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	CExternalNetInterface* pNetInterface = NULL;
+	if(m_map.find(stringUuid) != m_map.end())
+	{
+		if(!bCrossingThread)
+		{
+			Thread::TID nThreadId = m_mapHandleAndTid[stringUuid];
+			if(nThreadId != Thread::currentTid())
+			{
+				CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_HANDLE_THREAD_MISMATCH), __FUNCTION__, __FILE__, __LINE__);
+				return NULL;
+			}
+		}
+		pNetInterface = m_map[stringUuid];
+	}
+	return pNetInterface;
+}
+
+
+int CNetThreadManager::GetSessionId(string& stringSessionId)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	map<string, CExternalNetInterface*>::const_iterator iter;
+	for(iter=m_map.begin(); iter!=m_map.end(); iter++)
+	{
+		if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
+		{
+			stringSessionId = iter->second->GetSessionId();
+			break;
+		}
+	}
+	if(iter == m_map.end())
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_VALID_SESSIONID), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NO_VALID_SESSIONID;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CNetThreadManager::SetSessionId(string stringSessionId)
+{
+	HandleSessionSync(stringSessionId);
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+
+void CNetThreadManager::HandleSessionSync(string stringSessionId)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	map<string, CExternalNetInterface*>::iterator iter;
+	for(iter=m_map.begin(); iter!=m_map.end(); iter++)
+	{
+		iter->second->SetSessionId(stringSessionId);
+	}
+	return;
+}
+
+int CNetThreadManager::SetGWSessionId(string stringSessionId)
+{
+	HandleGWSessionSync(stringSessionId);
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CNetThreadManager::GetGWSessionId(string& stringSessionId)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	map<string, CExternalNetInterface*>::const_iterator iter;
+	for(iter=m_map.begin(); iter!=m_map.end(); iter++)
+	{
+		if(iter->second->GetGWSessionId().size()!=0 && iter->second->GetGWSessionId()!="00000000000000000000000000000000")
+		{
+			stringSessionId = iter->second->GetGWSessionId();
+			break;
+		}
+	}
+	if(iter == m_map.end())
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_VALID_SESSIONID), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NO_VALID_SESSIONID;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+void CNetThreadManager::HandleGWSessionSync(string stringSessionId)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	map<string, CExternalNetInterface*>::iterator iter;
+	for(iter=m_map.begin(); iter!=m_map.end(); iter++)
+	{
+		iter->second->SetGWSessionId(stringSessionId);
+	}
+	return;
+}

+ 34 - 0
NetThreadManager.h

@@ -0,0 +1,34 @@
+#pragma once
+#include "ExternalNetInterface.h"
+#include <string>
+#include "Poco/Mutex.h"
+#include "Poco/Thread.h"
+
+using namespace::std;
+using Poco::FastMutex;
+using Poco::Mutex;
+using Poco::Thread;
+
+
+class CNetThreadManager
+{
+public:
+	static int InsertNetThread(string);
+	static int DeleteNetThread(string);
+	static string GetHandleByThreadId(Thread::TID nThreadId);
+	static CExternalNetInterface* GetNetThread(string stringUuid, bool bCrossingThread=false);
+	
+	//sessionidÏà¹Ø
+	static int GetSessionId(string& stringSessionId);
+	static int SetSessionId(string stringSessionId);
+	static void HandleSessionSync(string stringSessionId);
+	//¹«ÎÀsessionidÏà¹Ø
+	static int SetGWSessionId(string stringSessionId);
+	static int GetGWSessionId(string& stringSessionId);
+	static void HandleGWSessionSync(string stringSessionId);
+public:
+	static map<string, CExternalNetInterface*> m_map;
+	static map<Thread::TID, string> m_mapTidAndHandle;
+	static map<string, Thread::TID> m_mapHandleAndTid;
+	static map<string, Mutex*> m_mapHandleAndMutex;
+};

+ 299 - 0
PhmsDataType.h

@@ -0,0 +1,299 @@
+#pragma once
+typedef struct tagBLOODSUGER_DATA
+{
+	double bloodsuger;
+	const char* flag; 
+}BLOODSUGER_DATA;
+
+typedef struct tagSPO2_DATA
+{
+	double spo2;
+	double pr;
+}SPO2_DATA;
+
+typedef struct tagBP_DATA
+{
+	double sys;
+	double mean;
+	double dia;
+}BP_DATA;
+
+typedef struct tagFETAL_DATA
+{
+	double fetalHeartRate;
+	double palacePressure;
+	double quickening;
+}FETAL_DATA;
+
+typedef struct tagFVC_DATA
+{
+	double fvc;
+	double fev1;
+	double pef;
+	double fev1Rate;
+	double fef25;
+	double fef2575;
+	double fef75;
+}FVC_DATA;
+
+typedef struct tagPEDOMETER_DATA
+{
+	double setps;
+	double distance;
+	double calories;
+}PEDOMETER_DATA;
+
+typedef struct tagURINE
+{
+	const char* urineValue;
+	const char* urineValueAdd;
+	const char* urineValueNew;
+}URINE_DATA;
+
+typedef struct tagHR_CONCLUSION
+{
+	double vaule;
+	const char* conclusion;
+}HR_CONCLUSION;
+
+typedef struct tagBLOOD_TEST
+{
+	double CHOL;
+	double HDL;
+	double TG;
+	double LDL;
+	double HB;
+	double HCT;
+}BLOOD_TEST, *pBLOOD_TEST;
+
+typedef struct tagRECORD_DATA
+{
+	double hr;
+	double weight;
+	double height;
+	double temp;
+	double resp;
+	double chol;
+	double ua;
+	BLOODSUGER_DATA bloodsugerData;
+	SPO2_DATA spo2Data;
+	BP_DATA bpData;
+	FETAL_DATA fetalData;
+	FVC_DATA fvcData;
+	PEDOMETER_DATA pedometerData;
+	const char* checkTime;
+	URINE_DATA urineData;
+	HR_CONCLUSION hrConclusion;
+	BLOOD_TEST	bloodTest;
+}RECORD_DATA;
+
+
+typedef struct tagBLOODSUGER_DATA_STRING
+{
+	const char* bloodsuger;
+	const char* flag; 
+}BLOODSUGER_DATA_STRING;
+
+typedef struct tagSPO2_DATA_STRING
+{
+	const char* spo2;
+	const char* pr;
+}SPO2_DATA_STRING;
+
+typedef struct tagBP_DATA_STRING
+{
+	const char* sys;
+	const char* mean;
+	const char* dia;
+}BP_DATA_STRING;
+
+typedef struct tagFETAL_DATA_STRING
+{
+	const char* fetalHeartRate;
+	const char* palacePressure;
+	const char* quickening;
+}FETAL_DATA_STRING;
+
+typedef struct tagFVC_DATA_STRING
+{
+	const char* fvc;
+	const char* fev1;
+	const char* pef;
+	const char* fev1Rate;
+	const char* fef25;
+	const char* fef2575;
+	const char* fef75;
+}FVC_DATA_STRING;
+
+typedef struct tagPEDOMETER_DATA_STRING
+{
+	const char* setps;
+	const char* distance;
+	const char* calories;
+}PEDOMETER_DATA_STRING;
+
+typedef struct tagURINE_STRING
+{
+	const char* urineValue;
+	const char* urineValueAdd;
+	const char* urineValueNew;
+}URINE_DATA_STRING;
+
+typedef struct tagHR_CONCLUSION_STRING
+{
+	const char* vaule;
+	const char* conclusion;
+}HR_CONCLUSION_STRING;
+
+typedef struct tagBLOOD_TEST_STRING
+{
+	const char*  CHOL;
+	const char*  HDL;
+	const char*  TG;
+	const char*  LDL;
+	const char*  HB;
+	const char*  HCT;
+}BLOOD_TEST_STRING, *pBLOOD_TEST_STRING;
+
+
+typedef struct tagRECORD_DATA_STRING
+{
+	const char* hr;
+	const char* weight;
+	const char* height;
+	const char* temp;
+	const char* resp;
+	const char* chol;
+	const char* ua;
+	const char* ag;
+	BLOODSUGER_DATA_STRING bloodsugerData;
+	SPO2_DATA_STRING spo2Data;
+	BP_DATA_STRING bpData;
+	FETAL_DATA_STRING fetalData;
+	FVC_DATA_STRING fvcData;
+	PEDOMETER_DATA_STRING pedometerData;
+	const char* checkTime;
+	URINE_DATA_STRING urineData;
+	HR_CONCLUSION_STRING hrConclusion;
+	BLOOD_TEST_STRING bloodTest;
+}RECORD_DATA_STRING;
+
+
+typedef struct tagHEALTHY_KNOWLEDGE
+{
+	const char* title;			//健康知识的标题
+	const char* description;	//健康知识的描述
+	const char* url;			//健康知识全文URI
+	const char* picurl;			//健康知识的图片URI
+}HEALTHY_KNOWLEDGE, *pHEALTHY_KNOWLEDGE;
+
+
+typedef struct tagTELCOM_ECG
+{
+	const char** pArrayData;
+	unsigned int nArrayLength;
+	const char* adRate;
+	const char* adAccuracy;
+	const char* rangeMin;
+	const char* rangeMax;
+	const char* heartValue;
+	const char* stLevel;
+	const char* prInterval;
+	const char* qtInterval;
+	const char* rrInterval;
+	const char* pWave;
+	const char* rWave;
+	const char* tWave;
+	const char* result1;
+	const char* result2;
+	const char* result3;
+	const char* result4;
+	const char* result5;
+}TELCOM_ECG, *pTELCOM_ECG;
+
+typedef struct tagGUANXIN_DATA
+{
+	const char* id;
+	const char* ArchiveId;
+	const char* OperatorNo;
+	const char* OperatorName;
+	const char* MachineNo;
+	const char* IdCard;
+	const char* Height;
+	const char* Weight;
+	const char* Temperature;
+	const char* Glucose;
+	const char* Systolic;
+	const char* Diastolic;
+	const char* Oxygen;
+	const char* PulseRate;
+	const char* HR;
+	const char* Paxis;
+	const char* Taxis;
+	const char* QRSaxis;
+	const char* PR;
+	const char* QRS;
+	const char* QT;
+	const char* QTc;
+	const char* RV5;
+	const char* SV1;
+	const char* URO;
+	const char* BLD;
+	const char* BIL;
+	const char* KET;
+	const char* GLU;
+	const char* PRO;
+	const char* PH;
+	const char* NIT;
+	const char* WBC;
+	const char* SG;
+	const char* VC;
+	const char* Diagnosis01;
+	const char* ExamTime;
+	const char* RTime;
+	const char* Diagnosis02;
+	const char* Diagnosis03;
+	const char* Diagnosis04;
+	const char* Diagnosis05;
+	const char* Diagnosis06;
+	const char* Diagnosis07;
+}GUANXIN_DATA, *pGUANXIN_DATA;
+
+typedef struct tagQUERY_RANGE
+{
+	const char* upperLimit;
+	const char* lowerLimit;
+}QUERY_RANGE, *pQUERY_RANGE;
+
+typedef struct tagQUERY_ECG
+{
+	QUERY_RANGE hr;
+	QUERY_RANGE pr_int;
+	QUERY_RANGE qt_int;
+	QUERY_RANGE qtc_int;
+	QUERY_RANGE p_dur;
+	QUERY_RANGE qrs_dur;
+	QUERY_RANGE p_axis;
+	QUERY_RANGE qrs_axis;
+	QUERY_RANGE t_axis;
+	QUERY_RANGE rv5;
+	QUERY_RANGE sv1;
+
+}QUERY_ECG, *pQUERY_ECG;
+
+typedef char* NET_HANDLE;
+typedef void (*pProgressAndSpeedCallback)(double dProgress, double dSpeed, const char* stringServerFilePath, const char* stringLocalFilePath);
+
+//以下为推送成功与失败回调,※※不可以在回调函数中执行关闭推送操作,否则库报错※※
+typedef void (*pHttpPushCallback)(const char* stringContent, unsigned long nContentSize);
+//推送错误回调,nErrorCode取值COMMON_SESSION_INVALID:session失效,目前只有服务器重启才有可能;COMMON_LOGIN_ANOTHER_PLACE:相同账号异地登录;COMMON_SERVER_NO_SUPPORT:该用户类型不支持该种推送,咱无其他可能;COMMON_NET_CONFIG_ERROR:配置文件中文推送地址
+typedef void (*pHttpPushFailCallback)(int nErrorCode/*, NET_HANDLE handle*/);
+
+#define PC_DOCTOR_TERMINAL_TYPE		("contec-ctype1/1.0")
+#define PC_USER_TERMINAL_TYPE		("contec-ctype2/1.0")
+#define HM_TERMINAL_TYPE			("contec-ctype3/1.0")
+#define CM_TERMINAL_TYPE			("contec-ctype4/1.0")
+#define FOUR_SERIES_TERMINAL_TYPE	("contec-ctype5/1.0")
+#define SEVEN_SERIES_TERMINAL_TYPE	("contec-ctype6/1.0")
+#define ANDROID_TERMINAL_TYPE		("contec-ctype7/1.0")
+

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 474 - 0
PhmsHttp.vcproj


+ 65 - 0
PhmsHttp.vcproj.wh-PC.wh.user

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioUserFile
+	ProjectType="Visual C++"
+	Version="8.00"
+	ShowAllFiles="false"
+	>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			>
+			<DebugSettings
+				Command=""
+				WorkingDirectory=""
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine="WH-PC"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			>
+			<DebugSettings
+				Command=""
+				WorkingDirectory=""
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine="WH-PC"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+	</Configurations>
+</VisualStudioUserFile>

+ 147 - 0
PhmsLogger.cpp

@@ -0,0 +1,147 @@
+#include "PhmsLogger.h"
+#include "Util.h"
+#include "AllObjectManagerUtil.h"
+#include "Poco/Logger.h"
+#include "Poco/FileChannel.h"
+#include "Poco/Message.h"
+#include "Poco/AutoPtr.h"
+#include "Poco/File.h"
+#include "Poco/DateTime.h"
+#include "Poco/DateTimeFormatter.h"
+#include "Poco/Timestamp.h"
+#include "Poco/Timezone.h"
+#include "Poco/Timespan.h"
+#include "Poco/Exception.h"
+#include <stdio.h>
+#include <sstream>
+#include <iostream>
+
+using Poco::Logger;
+using Poco::FileChannel;
+using Poco::AutoPtr;
+using Poco::File;
+using Poco::Message;
+using Poco::Timestamp;
+using Poco::DateTime;
+using Poco::DateTimeFormatter;
+using Poco::Timestamp;
+using Poco::Timezone;
+using Poco::Timespan;
+using Poco::Exception;
+using std::ostringstream;
+
+
+CPhmsLogger* CPhmsLogger::m_pPhmsLogger = NULL;
+Mutex CPhmsLogger::m_mutex;
+
+CPhmsLogger::CPhmsLogger(void)
+{
+	try
+	{
+		string stringWorkingDir = CUtil::GetCurrentAppDir();
+		File fileDir(stringWorkingDir+"log/NET_LOG/", "gbk");
+		fileDir.createDirectories();
+		File fileLog(stringWorkingDir+"log/NET_LOG/log_phms_netlib.log", "gbk");
+		fileLog.createFile();
+		AutoPtr<FileChannel> pFileChannel = new FileChannel(fileLog.path());
+#if defined(POCO_OS_FAMILY_UNIX)
+		pFileChannel->setProperty(FileChannel::PROP_ROTATION, "1 M");
+#else
+		pFileChannel->setProperty(FileChannel::PROP_ROTATION, "1 days");
+#endif
+		pFileChannel->setProperty(FileChannel::PROP_ARCHIVE, "timestamp");
+		pFileChannel->setProperty(FileChannel::PROP_COMPRESS, "false");
+#if defined(POCO_OS_FAMILY_UNIX)
+		pFileChannel->setProperty(FileChannel::PROP_PURGECOUNT, "2");
+#else
+		pFileChannel->setProperty(FileChannel::PROP_PURGECOUNT, "30");
+#endif
+		pFileChannel->setProperty(FileChannel::PROP_TIMES, "utc");
+		Logger& logPhms = Logger::get("PHMS.NETLIB");
+		logPhms.setChannel(pFileChannel);
+		logPhms.setLevel(Message::PRIO_ERROR);
+	}
+	catch(Exception& e)
+	{
+		std::cout<<"PhmsHttp:"<<e.what()<<"	File:"<<__FILE__<<"	Line:"<<__LINE__<<std::endl;
+		std::cout<<"PhmsHttp:"<<CUtil::GetCurrentAppDir()<<"	File:"<<__FILE__<<"	Line:"<<__LINE__<<std::endl;
+	}
+	catch(...)
+	{
+
+	}
+}
+
+CPhmsLogger::~CPhmsLogger(void)
+{
+	Logger::shutdown();
+}
+
+
+CPhmsLogger* CPhmsLogger::GetPhmsLogger()
+{
+	Mutex::ScopedLock lock(m_mutex);
+	if(CPhmsLogger::m_pPhmsLogger == NULL)
+	{
+		m_pPhmsLogger = new CPhmsLogger;
+	}
+	return m_pPhmsLogger;
+}
+
+void CPhmsLogger::ReleasePhmsLogger()
+{
+	//因为在CAllObjectManagerUtil::ReleasePhmsLogger中已经有锁控制了,所以此处不再用m_mutex控制
+	if(m_pPhmsLogger != NULL)
+	{
+		delete m_pPhmsLogger;
+		m_pPhmsLogger = NULL;
+	}
+}
+
+
+void CPhmsLogger::WriteLog(string stringText, const char* stringFunction, const char* stringFile, int nLine)
+{
+	try
+	{
+		Logger& logPhms = Logger::get("PHMS.NETLIB");
+		DateTime dt;
+		dt += Timespan(Timezone::utcOffset(), 0);
+		string stringDateTime = DateTimeFormatter::format(dt, "%Y-%m-%d %H:%M:%S");
+		string stringSourceFile = "source file: ";
+		stringSourceFile += stringFile;
+		ostringstream oStringStream;
+		oStringStream<<"line: "<<nLine;
+		string stringNLine = oStringStream.str();
+		Message logMessage("PHMS.NETLIB", stringDateTime+"---"+stringText+"---"+stringFunction+"---"+stringSourceFile+"---"+stringNLine, Message::PRIO_ERROR);
+		logPhms.log(logMessage);
+	}
+	catch(Exception&)
+	{
+
+	}
+}
+
+
+void CPhmsLogger::WriteLog(const Exception& e, const char* stringFunction, const char* stringFile, int nLine)
+{
+	try
+	{
+		Logger& logPhms = Logger::get("PHMS.NETLIB");
+		string stringException;
+		stringException = e.displayText();
+		DateTime dt;
+		dt += Timespan(Timezone::utcOffset(), 0);
+		string stringDateTime = DateTimeFormatter::format(dt, "%Y-%m-%d %H:%M:%S");
+		string stringSourceFile = "source file: ";
+		stringSourceFile += stringFile;
+		ostringstream oStringStream;
+		oStringStream<<"line: "<<nLine;
+		string stringNLine = oStringStream.str();
+		Message logMessage("PHMS.NETLIB", stringDateTime+"---"+stringException+"---"+stringFunction+"---"+stringSourceFile+"---"+stringNLine, Message::PRIO_ERROR);
+		logPhms.log(logMessage);
+	}
+	catch(Exception&)
+	{
+
+	}
+}

+ 23 - 0
PhmsLogger.h

@@ -0,0 +1,23 @@
+#pragma once
+#include "Poco/Exception.h"
+#include "Poco/Mutex.h"
+#include "string"
+
+using Poco::Exception;
+using Poco::Mutex;
+using namespace std;
+
+class CPhmsLogger
+{
+private:
+	CPhmsLogger(void);
+	~CPhmsLogger(void);
+private:
+	static CPhmsLogger* m_pPhmsLogger;
+	static Mutex m_mutex;
+public:
+	static CPhmsLogger* GetPhmsLogger();
+	static void ReleasePhmsLogger();
+	void WriteLog(string stringText, const char* stringFunction, const char* stringFile, int nLine);
+	void WriteLog(const Exception& e, const char* stringFunction, const char* stringFile, int nLine);
+};

+ 326 - 0
PhmsPushSession.cpp

@@ -0,0 +1,326 @@
+#include "PhmsPushSession.h"
+#include "PhmsLogger.h"
+#include "PhmsRequestHead.h"
+#include "PhmsRequestBody.h"
+#include "Util.h"
+#include "ErrorCode.h"
+#include "Poco/Exception.h"
+#include "Poco/AutoPtr.h"
+#include "Poco/Util/IniFileConfiguration.h"
+#include "Poco/DOM/Document.h"
+#include "Poco/DOM/Element.h"
+#include "Poco/DOM/Text.h"
+#include "Poco/DOM/ProcessingInstruction.h"
+#include "Poco/DOM/DOMWriter.h"
+#include "Poco/XML/XMLWriter.h"
+#include "Poco/TextEncoding.h"
+#include "Poco/GBKEncoding.h"
+#include "Poco/KOI8REncoding.h"
+#include "Poco/Base64Encoder.h"
+#include <sstream>
+#include <fstream>
+#include "AllObjectManagerUtil.h"
+
+using Poco::Exception;
+using Poco::FileNotFoundException;
+using Poco::AutoPtr;
+using Poco::Util::IniFileConfiguration;
+using Poco::XML::Document;
+using Poco::XML::Element;
+using Poco::XML::Text;
+using Poco::XML::ProcessingInstruction;
+using Poco::XML::DOMWriter;
+using Poco::XML::XMLWriter;
+using Poco::Base64Encoder;
+using Poco::GBKEncoding;
+using Poco::KOI8REncoding;
+using Poco::TextEncoding;
+
+CPhmsPushSession::CPhmsPushSession(void):m_pHttpPushSession(NULL), m_bSsl(false)
+{
+	//获得ssl环境
+	{
+		string stringWorkingDir = CUtil::GetCurrentAppDir();
+		CNetConfig netConfig;
+		this->GetNetConfig(stringWorkingDir+"PhmsConfig.ini", netConfig);
+		m_bSsl = netConfig.GetSsl();
+	}
+	m_pHttpPushSession = new CHttpPushSession(m_bSsl);
+}
+
+CPhmsPushSession::~CPhmsPushSession(void)
+{
+	delete m_pHttpPushSession;
+	m_pHttpPushSession = NULL;
+}
+
+void CPhmsPushSession::abort()
+{
+	Mutex::ScopedLock lock(m_mutexAbortAndSslSwitch);
+	m_pHttpPushSession->abort();
+}
+
+string CPhmsPushSession::GetSessionId()
+{
+	return m_stringSessionId;
+}
+
+void CPhmsPushSession::SetSessionId(string stringSessionId)
+{
+	m_stringSessionId = stringSessionId;
+}
+
+void CPhmsPushSession::SetPushCallback(pHttpPushCallback pCallback)
+{
+	m_pCallback = pCallback;
+}
+
+int CPhmsPushSession::PushMsg(string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgType, string stringMsgDirection, string stringVersion)
+{
+	AutoPtr<Document> pDoc = new Document;
+	//AutoPtr<ProcessingInstruction> pi = pDoc->createProcessingInstruction("xml", "version='1.0' encoding='GBK'"); 
+	AutoPtr<Element> pRoot = pDoc->createElement("request");
+	AutoPtr<Element> pChildSenderId = pDoc->createElement("senderid");
+	AutoPtr<Element> pChildCaseId = pDoc->createElement("caseid");
+	AutoPtr<Element> pChildCaseType = pDoc->createElement("casetype");
+	AutoPtr<Element> pChildMsgType = pDoc->createElement("msgtype");
+	AutoPtr<Element> pChildMsgDirection = pDoc->createElement("msgdirection");
+	AutoPtr<Element> pChildVersion = pDoc->createElement("version");
+	AutoPtr<Text> pTextSenderId = pDoc->createTextNode(stringSenderId);
+	AutoPtr<Text> pTextCaseId = pDoc->createTextNode(stringCaseId);
+	AutoPtr<Text> pTextCaseType = pDoc->createTextNode(stringCaseType);
+	AutoPtr<Text> pTextMsgType = pDoc->createTextNode(stringMsgType);
+	AutoPtr<Text> pTextMsgDirection = pDoc->createTextNode(stringMsgDirection);
+	AutoPtr<Text> pTextVersion = pDoc->createTextNode(stringVersion);
+	pChildSenderId->appendChild(pTextSenderId);
+	pChildCaseId->appendChild(pTextCaseId);
+	pChildCaseType->appendChild(pTextCaseType);
+	pChildMsgType->appendChild(pTextMsgType);
+	pChildMsgDirection->appendChild(pTextMsgDirection);
+	pChildVersion->appendChild(pTextVersion);
+	pRoot->appendChild(pChildSenderId);
+	pRoot->appendChild(pChildCaseId);
+	pRoot->appendChild(pChildCaseType);
+	pRoot->appendChild(pChildMsgType);
+	pRoot->appendChild(pChildMsgDirection);
+	pRoot->appendChild(pChildVersion);
+	//pDoc->appendChild(pi);
+	pDoc->appendChild(pRoot);
+
+	string stringXmlContent;
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = this->GetRequestXml(pDoc, stringXmlContent);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+		return nRet;
+	}
+
+	CPhmsRequestHead phmsRequestHead("10", "1031", m_stringSessionId, "11");
+	CPhmsRequestBody phmsRequestBody(stringXmlContent);
+	CPhmsRequest phmsRequest(phmsRequestHead, phmsRequestBody, "");
+	phmsRequest.GenerateAndSetSign();
+	CPhmsResponse phmsResponse;
+	nRet = ExecutePhmsPushSession(phmsRequest);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+		return nRet;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CPhmsPushSession::ExecutePhmsPushSession(CPhmsRequest& phmsRequest)
+{	
+	CNetConfig netConfig;
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	//设置网络环境
+	try
+	{
+		string stringWorkingDir = CUtil::GetCurrentAppDir();
+		nRet = this->GetNetConfig(stringWorkingDir+"PhmsConfig.ini", netConfig);
+		if(nRet != PHMS_SUCCESSFUL_RESULT)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+			return nRet;
+		}
+		Mutex::ScopedLock lock(m_mutexAbortAndSslSwitch);
+		if(m_bSsl != netConfig.GetSsl())
+		{
+			delete m_pHttpPushSession;
+			m_pHttpPushSession = new CHttpPushSession(netConfig.GetSsl());
+			m_bSsl = netConfig.GetSsl();
+		}
+	}
+	catch(FileNotFoundException& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_NET_CONFIG_FILE), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NO_NET_CONFIG_FILE;
+	}
+
+	if(!phmsRequest.ValidataPhmsRequest())
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PHMS_REQUEST_VALIDATE_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_PHMS_REQUEST_VALIDATE_FAIL;
+	}
+	nRet = m_pHttpPushSession->ExecuteHttpPushSession(netConfig, phmsRequest, m_pCallback);
+	if(nRet != PHMS_SUCCESSFUL_RESULT)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+		return nRet;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+
+int CPhmsPushSession::GetNetConfig(string stringFilePath, CNetConfig& netConfig)
+{
+	try
+	{
+		AutoPtr<IniFileConfiguration> iniFile = new IniFileConfiguration(stringFilePath, "gbk");
+		string stringContent;
+		unsigned short nContent;
+		istringstream iStringStream;
+
+		string stringPriorIp = CAllObjectManagerUtil::GetPriorIp();
+		if(stringPriorIp.size() != 0)
+		{
+			stringContent = stringPriorIp;
+		}
+		else
+		{
+			if(iniFile->has("NET.IP"))
+			{
+				stringContent = iniFile->getString("NET.IP", "");
+				if(stringContent.size() == 0)
+				{
+					stringContent = iniFile->getString("NET.SERVER_NAME", "data2.contec365.com");
+					if(stringContent.size() == 0)
+					{
+						stringContent = "data2.contec365.com";
+					}
+				}
+			}
+			else
+			{
+				stringContent = iniFile->getString("NET.SERVER_NAME", "data2.contec365.com");
+				if(stringContent.size() == 0)
+				{
+					stringContent = "data2.contec365.com";
+				}
+			}
+		}
+		netConfig.SetAddr(stringContent);
+
+		stringContent = iniFile->getString("NET.SERVER_NAME", "data2.contec365.com");
+		if(stringContent.size() == 0)
+		{
+			stringContent = "data2.contec365.com";
+		}
+		netConfig.SetHost(stringContent);
+
+		stringContent = iniFile->getString("NET.PORT", "80");
+		iStringStream.str(stringContent);
+		iStringStream>>nContent;
+		netConfig.SetPort(nContent);
+
+		stringContent = iniFile->getString("NET.SSL", "0");
+		if(stringContent == "1")
+		{
+			netConfig.SetSsl(true);
+		}
+		else
+		{
+			netConfig.SetSsl(false);
+		}
+		//推送暂时只有一个地址
+		stringContent = iniFile->getString("NET.HTTP_PUSH", "/submsg");
+		netConfig.SetUrl(stringContent);
+
+		stringContent = iniFile->getString("GENERAL.NETWORK", "0");
+		iStringStream.clear();
+		iStringStream.str(stringContent);
+		iStringStream>>nContent;
+		switch (nContent)
+		{
+		case 0:
+			netConfig.SetProxyType(NO_PROXY);
+			break;
+		case 1:
+			netConfig.SetProxyType(HTTP_PROXY);
+			break;
+		case 2:
+			netConfig.SetProxyType(SOCK_PROXY);
+			break;
+		default:
+			netConfig.SetProxyType(NO_PROXY);
+			break;
+		}
+
+		stringContent = iniFile->getString("PROXY.IP", "");
+		netConfig.SetProxyAddr(stringContent);
+
+		stringContent = iniFile->getString("PROXY.PORT", "");
+		iStringStream.clear();
+		iStringStream.str(stringContent);
+		iStringStream>>nContent;
+		netConfig.SetProxyPort(nContent);
+
+		stringContent = iniFile->getString("PROXY.USERNAME", "");
+		netConfig.SetProxyUsername(stringContent);
+
+		stringContent = iniFile->getString("PROXY.PASSWORD", "");
+		netConfig.SetProxyPassword(stringContent);
+	}
+	catch(FileNotFoundException& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_NET_CONFIG_FILE), __FUNCTION__, __FILE__, __LINE__);
+		throw;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CPhmsPushSession::GetRequestXml(AutoPtr<Document> pDoc, string& stringXmlContent)
+{
+	string stringWorkingDir = CUtil::GetCurrentAppDir();
+	string stringIniFilePath = stringWorkingDir+"PhmsConfig.ini";
+	AutoPtr<IniFileConfiguration> iniFile = new IniFileConfiguration(stringIniFilePath, "gbk");
+	string stringEncoding = iniFile->getString("OTHER.Encoding", "GBK");
+
+	DOMWriter domWriter;
+	//ProcessingInstruction和XMLWriter::WRITE_XML_DECLARATION 只用一个就好,都用会写两个头
+	domWriter.setOptions(XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT);
+	domWriter.setNewLine(XMLWriter::NEWLINE_CRLF);
+	domWriter.setIndent("	");
+	TextEncoding* pEnvEncoding = TextEncoding::find(stringEncoding);
+	TextEncoding* pUtf8Encoding = TextEncoding::find("UTF-8");
+	//domWriter.setEncoding(stringEncoding, *pEnvEncoding);
+	domWriter.setEncoding("UTF-8", *pUtf8Encoding);
+	domWriter.setInputEncoding(*pEnvEncoding);
+
+
+	std::ostringstream oStringStream;
+	Base64Encoder encoderBase64(oStringStream);
+	encoderBase64.rdbuf()->setLineLength(0);
+	try
+	{
+		domWriter.writeNode(encoderBase64,pDoc);
+		ostringstream oStringStreamXmlContent;
+		domWriter.writeNode(oStringStreamXmlContent, pDoc);
+		//domWriter.writeNode(cout, pDoc);
+		//cout<<endl<<endl;
+	}
+	catch(Exception& e)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_WRITE_XML_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_WRITE_XML_ERROR;
+	}
+	encoderBase64.close();
+	stringXmlContent = oStringStream.str();
+	return PHMS_SUCCESSFUL_RESULT;
+}

+ 46 - 0
PhmsPushSession.h

@@ -0,0 +1,46 @@
+#pragma once
+#include <string>
+#include "HttpPushSession.h"
+#include "PhmsRequest.h"
+#include "NetConfig.h"
+
+#include "Poco/AutoPtr.h"
+#include "Poco/DOM/Document.h"
+#include "Poco/Mutex.h"
+
+
+//推送的返回说明:
+//如果推送成功,调用成功回调函数
+//如果推送失败,调用失败回调函数
+
+//其中失败中的网络失败情况比较复杂。网络失败大致分类:超时、本地正常关闭或异常关闭、服务器正常关闭或异常关闭、其他
+//其中,因为推送无发送和接受超时,所以超时只有连接过程中才会出现。
+//以目前的程序结构来看,所有网络错误都不需要调用失败回调,只有其他逻辑错误才调用失败回调,由应用程序决定来处理。
+//网络错误:不调用失败回调;如果用户未调用推动退出,线程会继续重试,再发一次请求;如果用户调用了推送退出,线程退出
+//逻辑错误:调用失败回调,通知用户错误码
+using namespace std;
+using Poco::XML::Document;
+using Poco::AutoPtr;
+using Poco::Mutex;
+class CPhmsPushSession
+{
+public:
+	CPhmsPushSession(void);
+	~CPhmsPushSession(void);
+
+	void abort();
+	string GetSessionId();
+	void SetSessionId(string stringSessionId);
+	void SetPushCallback(pHttpPushCallback pCallback);
+	int PushMsg(string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgType, string stringMsgDirection, string stringVersion);
+private:
+	int ExecutePhmsPushSession(CPhmsRequest& phmsRequest);
+	int GetNetConfig(string stringFilePath, CNetConfig& netConfig);
+	int GetRequestXml(AutoPtr<Document> pDoc, string& stringXmlContent);
+private:
+	CHttpPushSession* m_pHttpPushSession;
+	bool m_bSsl;
+	string m_stringSessionId;
+	pHttpPushCallback m_pCallback;
+	Mutex m_mutexAbortAndSslSwitch;
+};

+ 147 - 0
PhmsRequest.cpp

@@ -0,0 +1,147 @@
+#include "PhmsRequest.h"
+#include "Poco/MD5Engine.h"
+#include "Util.h"
+#include "GlobalTerminalLogoString.h"
+
+using namespace Poco;
+
+string CPhmsRequest::m_stringUsername = "";
+string CPhmsRequest::m_stringPassword = "";
+CPhmsRequest::CPhmsRequest(void)
+{
+}
+
+CPhmsRequest::~CPhmsRequest(void)
+{
+}
+
+CPhmsRequest::CPhmsRequest(CPhmsRequest& phmsRequest)
+{
+	this->m_phmsRequestHead = phmsRequest.GetPhmsRequestHead();
+	this->m_phmsRequestBody = phmsRequest.GetPhmsRequestBody();
+	this->m_stringFilePath =  phmsRequest.GetFilePath();
+}
+CPhmsRequest::CPhmsRequest(CPhmsRequestHead& phmsRequestHead, CPhmsRequestBody& phmsRequestBody, string stringFilePath)
+				:m_phmsRequestHead(phmsRequestHead), m_phmsRequestBody(phmsRequestBody), m_stringFilePath(stringFilePath)
+{
+
+}
+
+CPhmsRequest& CPhmsRequest::operator=(CPhmsRequest& phmsRequest)
+{
+	this->m_phmsRequestHead = phmsRequest.GetPhmsRequestHead();
+	this->m_phmsRequestBody = phmsRequest.GetPhmsRequestBody();
+	this->m_stringFilePath =  phmsRequest.GetFilePath();
+	return *this;
+}
+
+
+CPhmsRequestHead& CPhmsRequest::GetPhmsRequestHead()
+{
+	return this->m_phmsRequestHead;
+}
+CPhmsRequestBody& CPhmsRequest::GetPhmsRequestBody()
+{
+	return this->m_phmsRequestBody;
+}
+string CPhmsRequest::GetFilePath()
+{
+	return this->m_stringFilePath;
+}
+string CPhmsRequest::GetUsername()
+{
+	return CPhmsRequest::m_stringUsername;
+}
+string CPhmsRequest::GetPassword()
+{
+	return CPhmsRequest::m_stringPassword;
+}
+
+
+//Setter
+void CPhmsRequest::SetPhmsRequestHead(CPhmsRequestHead& phmsRequestHead)
+{
+	m_phmsRequestHead = phmsRequestHead;
+}
+void CPhmsRequest::SetPhmsRequestBody(CPhmsRequestBody& phmsRequestBody)
+{
+	m_phmsRequestBody = phmsRequestBody;
+}
+void CPhmsRequest::SetFilePath(string stringFilePath)
+{
+	m_stringFilePath = stringFilePath;
+}
+void CPhmsRequest::SetUsername(string stringUsername)
+{
+	CPhmsRequest::m_stringUsername = stringUsername;
+}
+void CPhmsRequest::SetPassword(string stringPassword)
+{
+	CPhmsRequest::m_stringPassword = stringPassword;
+}
+
+//用户名和密码具体保存到哪里以后再说
+string CPhmsRequest::GenerateAndSetSign()
+{
+	string username;
+	string password;
+	//获得用户名和密码
+	{
+		username = CPhmsRequest::GetUsername();
+		password = CPhmsRequest::GetPassword();
+		if(username.size()==0 || password.size()==0)
+		{
+			username = g_stringUsername;
+			password = g_stringPassword;
+		}
+	}
+	
+	string md5_1;
+	string stringSrc1 = username+password;
+	md5_1 = CUtil::GetMd5(stringSrc1.c_str(), stringSrc1.size());
+	string stringSrc2;
+	stringSrc2 = md5_1 + m_phmsRequestHead.GetVersion() + m_phmsRequestHead.GetOperationCode() + m_phmsRequestHead.GetSessionId() + 
+		m_phmsRequestHead.GetMessageFormat() + m_phmsRequestBody.GetXmlContent();
+	
+	string md5_2 ;
+	md5_2 = CUtil::GetMd5(stringSrc2.c_str(), stringSrc2.size());
+	m_phmsRequestHead.SetSign(md5_2);
+
+// 	cout<<username<<":"<<password<<endl;
+// 	cout<<m_phmsRequestHead.GetSessionId()<<endl;
+// 	cout<<m_phmsRequestHead.GetVersion()<<endl;
+// 	cout<<m_phmsRequestHead.GetOperationCode()<<endl;
+// 	cout<<m_phmsRequestHead.GetMessageFormat()<<endl;
+// 	cout<<m_phmsRequestBody.GetXmlContent()<<endl;
+// 	cout<<"md5_1:"<<md5_1<<endl;
+// 	cout<<"md5_2:"<<md5_2<<endl;
+	return md5_2;
+}
+
+
+bool CPhmsRequest::ValidataPhmsRequest()
+{
+	if(!m_phmsRequestHead.ValidatePhmsRequestHead())
+	{
+		return false;
+	}
+	if(m_phmsRequestHead.GetPhmsRequestMessageFormat()==WRONG_PHMS_REQUEST_MESSAGE_FORMAT)
+	{
+		return false;
+	}
+	if(m_phmsRequestHead.GetPhmsRequestMessageFormat()==HAVE_PHMS_REQUEST_BODY && m_phmsRequestBody.GetXmlContent().size()==0)
+	{
+		return false;
+	}
+	if(m_phmsRequestHead.GetPhmsRequestMessageFormat()==NO_PHMS_REQUEST_BODY && m_phmsRequestBody.GetXmlContent().size()!=0)
+	{
+		return false;
+	}
+	return true;
+}
+
+
+string CPhmsRequest::ToString()
+{
+	return m_phmsRequestHead.ToString()+m_phmsRequestBody.ToString();
+}

+ 40 - 0
PhmsRequest.h

@@ -0,0 +1,40 @@
+#pragma once
+#include "PhmsRequestHead.h"
+#include "PhmsRequestBody.h"
+
+class CPhmsRequest
+{
+public:
+	CPhmsRequest(void);
+	CPhmsRequest(CPhmsRequest& phmsRequest);
+	CPhmsRequest(CPhmsRequestHead& phmsRequestHead, CPhmsRequestBody& phmsRequestBody, string stringFilePath="");
+	CPhmsRequest& operator=(CPhmsRequest& phmsRequest);
+	~CPhmsRequest(void);
+private:
+	CPhmsRequestHead m_phmsRequestHead;
+	CPhmsRequestBody m_phmsRequestBody;
+	string m_stringFilePath;
+
+	//用于保存当前在线的用户名和密码
+	//限制:同一时刻一个应用程序只能有一个在线账户
+	static string m_stringUsername;
+	static string m_stringPassword;
+public:
+	//Getter
+	CPhmsRequestHead& GetPhmsRequestHead();
+	CPhmsRequestBody& GetPhmsRequestBody();
+	string GetFilePath();
+	static string GetUsername();
+	static string GetPassword();
+
+	//Setter
+	void SetPhmsRequestHead(CPhmsRequestHead& phmsRequestHead);
+	void SetPhmsRequestBody(CPhmsRequestBody& phmsRequestBody);
+	void SetFilePath(string stringFilePath);
+	static void SetUsername(string stringUsername);
+	static void SetPassword(string stringPassword);
+
+	string GenerateAndSetSign();
+	bool ValidataPhmsRequest();
+	string ToString();
+};

+ 49 - 0
PhmsRequestBody.cpp

@@ -0,0 +1,49 @@
+#include "PhmsRequestBody.h"
+
+CPhmsRequestBody::CPhmsRequestBody(void)
+{
+}
+
+
+CPhmsRequestBody::CPhmsRequestBody(string xmlContent):m_xmlContent(xmlContent)
+{
+}
+
+CPhmsRequestBody::CPhmsRequestBody(CPhmsRequestBody& phmsRequestBody)
+{
+	m_xmlContent = phmsRequestBody.GetXmlContent();
+}
+
+CPhmsRequestBody& CPhmsRequestBody::operator=(CPhmsRequestBody& phmsRequestBody)
+{
+	m_xmlContent = phmsRequestBody.GetXmlContent();
+	return *this;
+}
+
+
+CPhmsRequestBody::~CPhmsRequestBody(void)
+{
+}
+
+
+
+//Getter
+string CPhmsRequestBody::GetXmlContent()
+{
+	return m_xmlContent;
+}
+
+//Setter
+void CPhmsRequestBody::SetXmlContent(string xmlContent)
+{
+	m_xmlContent = xmlContent;
+}
+
+
+string CPhmsRequestBody::ToString()
+{
+	return m_xmlContent;
+}
+
+
+

+ 20 - 0
PhmsRequestBody.h

@@ -0,0 +1,20 @@
+#pragma once
+#include <string>
+#include <iostream>
+using namespace std;
+class CPhmsRequestBody
+{
+public:
+	CPhmsRequestBody(void);
+	CPhmsRequestBody(string xmlContent);
+	CPhmsRequestBody(CPhmsRequestBody& phmsRequestBody);
+	CPhmsRequestBody& operator=(CPhmsRequestBody& phmsRequestBody);
+	~CPhmsRequestBody(void);
+	//Getter
+	string GetXmlContent();
+	//Setter
+	void SetXmlContent(string xmlContent);
+	string ToString();
+private:
+	string m_xmlContent;
+};

+ 125 - 0
PhmsRequestHead.cpp

@@ -0,0 +1,125 @@
+#include "PhmsRequestHead.h"
+#include "PhmsLogger.h"
+
+
+
+CPhmsRequestHead::CPhmsRequestHead(void)
+{
+}
+
+CPhmsRequestHead::CPhmsRequestHead(string version, string operationCode, string sessionId, string messageFormat)
+	:m_sign("00000000000000000000000000000000"), m_version(version),m_operationCode(operationCode),m_sessionId(sessionId),m_messageFormat(messageFormat)
+{
+	
+}
+CPhmsRequestHead::CPhmsRequestHead(CPhmsRequestHead& phmsRequestHead)
+{
+	m_sign = phmsRequestHead.GetSign();
+	m_version = phmsRequestHead.GetVersion();
+	m_sessionId = phmsRequestHead.GetSessionId();
+	m_operationCode = phmsRequestHead.GetOperationCode();
+	m_messageFormat = phmsRequestHead.GetMessageFormat();
+}
+
+CPhmsRequestHead& CPhmsRequestHead::operator=(CPhmsRequestHead& phmsRequestHead)
+{
+	m_sign = phmsRequestHead.GetSign();
+	m_version = phmsRequestHead.GetVersion();
+	m_sessionId = phmsRequestHead.GetSessionId();
+	m_operationCode = phmsRequestHead.GetOperationCode();
+	m_messageFormat = phmsRequestHead.GetMessageFormat();
+	return *this;
+}
+
+CPhmsRequestHead::~CPhmsRequestHead(void)
+{
+}
+
+
+//Getter
+string CPhmsRequestHead::GetSign()
+{
+	return m_sign;
+}
+string CPhmsRequestHead::GetVersion()
+{
+	return m_version;
+}
+string CPhmsRequestHead::GetOperationCode()
+{
+	return m_operationCode;
+}
+string CPhmsRequestHead::GetSessionId()
+{
+	return m_sessionId;
+}
+string CPhmsRequestHead::GetMessageFormat()
+{
+	return m_messageFormat;
+}
+//Setter
+void CPhmsRequestHead::SetSign(string sign)
+{
+	m_sign = sign;
+}
+void CPhmsRequestHead::SetVersion(string version)
+{
+	m_version = version;
+}
+void CPhmsRequestHead::SetOperationCode(string operationCode)
+{
+	m_operationCode = operationCode;
+}
+void CPhmsRequestHead::SetSessionId(string sessionId)
+{
+	m_sessionId = sessionId;
+}
+void CPhmsRequestHead::SetMessageFormat(string messageFormat)
+{
+	m_messageFormat = messageFormat;
+}
+
+
+bool CPhmsRequestHead::ValidatePhmsRequestHead()
+{
+	if(m_sign.size() != this->SIGN_LENGTH || m_version.size() != this->VERSION_LENGTH ||
+		m_operationCode.size() != this->OPERATION_LENGTH || m_sessionId.size() != this->SESSIONID_LENGTH ||
+		m_messageFormat.size() != this->MESSAGEFORMAT_LENGTH)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(m_sign, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(m_version, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(m_operationCode, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(m_sessionId, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(m_messageFormat, __FUNCTION__, __FILE__, __LINE__);
+		return false;
+	}
+	return true;
+}
+
+string CPhmsRequestHead::ToString()
+{
+	string phmsHead;
+	phmsHead = m_sign + m_version + m_operationCode + m_sessionId + m_messageFormat;
+	return phmsHead;
+}
+
+
+int CPhmsRequestHead::GetHeadLength()
+{
+	return TOTAL_HEAD_LENGTH;
+}
+
+EnumPhmsRequestMessageFormat CPhmsRequestHead::GetPhmsRequestMessageFormat()
+{
+	if(m_messageFormat == "10")
+	{
+		return NO_PHMS_REQUEST_BODY;
+	}
+	if(m_messageFormat=="11" || m_messageFormat=="12" || m_messageFormat=="13")
+	{
+		return HAVE_PHMS_REQUEST_BODY;
+	}else
+	{
+		return WRONG_PHMS_REQUEST_MESSAGE_FORMAT;
+	}
+}

+ 57 - 0
PhmsRequestHead.h

@@ -0,0 +1,57 @@
+#pragma once
+#include "PhmsRequestBody.h"
+#include <string>
+using namespace std;
+
+
+enum EnumPhmsRequestMessageFormat{
+		WRONG_PHMS_REQUEST_MESSAGE_FORMAT=-1,
+		NO_PHMS_REQUEST_BODY,
+		HAVE_PHMS_REQUEST_BODY
+	};
+
+class CPhmsRequestHead
+{
+public:
+	CPhmsRequestHead(void);
+	CPhmsRequestHead(string version, string operationCode, string sessionId, string messageFormat);
+	CPhmsRequestHead(CPhmsRequestHead& phmsRequestHead);
+	CPhmsRequestHead& operator=(CPhmsRequestHead& phmsRequestHead);
+	~CPhmsRequestHead(void);
+	
+	//Getter
+	string GetSign();
+	string GetVersion();
+	string GetOperationCode();
+	string GetSessionId();
+	string GetMessageFormat();
+	//Setter
+	void SetSign(string sign);
+	void SetVersion(string version);
+	void SetOperationCode(string operationCode);
+	void SetSessionId(string sessionId);
+	void SetMessageFormat(string messageFormat);
+
+	string ToString();
+	static int GetHeadLength();
+	bool ValidatePhmsRequestHead();
+	bool HavePhmsBody();
+	EnumPhmsRequestMessageFormat GetPhmsRequestMessageFormat();
+private:
+	string m_sign;
+	string m_version;
+	string m_operationCode;
+	string m_sessionId;
+	string m_messageFormat;
+	//EnumHeadStringLength enumHeadStringLength;
+	enum EnumPhmsRequestHeadStringLength
+	{
+		SIGN_LENGTH=32,
+		VERSION_LENGTH=2,
+		OPERATION_LENGTH=4,
+		SESSIONID_LENGTH=32,
+		MESSAGEFORMAT_LENGTH=2,
+		TOTAL_HEAD_LENGTH=72
+	};
+
+};

+ 402 - 0
PhmsResponse.cpp

@@ -0,0 +1,402 @@
+#include "PhmsResponse.h"
+#include "Poco/Buffer.h"
+#include <fstream>
+#include <sstream>
+#include "ErrorCode.h"
+#include "Poco/Exception.h"
+#include "Poco/MD5Engine.h"
+#include "Poco/Path.h"
+#include "Poco/AutoPtr.h"
+#include "Poco/Util/IniFileConfiguration.h"
+#include "Poco/TextEncoding.h"
+#include "Poco/StreamConverter.h"
+#include "Poco/StreamCopier.h"
+#include "PhmsSession.h"
+#include "PhmsLogger.h"
+#include "Util.h"
+#include "GlobalTerminalLogoString.h"
+
+using Poco::MD5Engine;
+using Poco::DigestEngine;
+using Poco::Buffer;
+using Poco::Exception;
+using Poco::TimeoutException;
+using Poco::Path;
+using Poco::AutoPtr;
+using Poco::Util::IniFileConfiguration;
+using Poco::TextEncoding;
+using Poco::InputStreamConverter;
+using Poco::StreamCopier;
+
+
+
+CPhmsResponse::CPhmsResponse()
+{
+	
+}
+
+CPhmsResponse::CPhmsResponse(CPhmsResponse& phmsResponse)
+{
+	this->m_phmsResponseHead = phmsResponse.GetPhmsResponseHead();
+	this->m_phmsResponseBody = phmsResponse.GetPhmsResponseBody();
+}
+
+CPhmsResponse& CPhmsResponse::operator=(CPhmsResponse& phmsResponse)
+{
+	this->m_phmsResponseHead = phmsResponse.GetPhmsResponseHead();
+	this->m_phmsResponseBody = phmsResponse.GetPhmsResponseBody();
+	return *this;
+}
+
+CPhmsResponse::~CPhmsResponse(void)
+{
+}
+
+
+//Getter
+CPhmsResponseHead& CPhmsResponse::GetPhmsResponseHead()
+{
+	return m_phmsResponseHead;
+}
+CPhmsResponseBody& CPhmsResponse::GetPhmsResponseBody()
+{
+	return m_phmsResponseBody;
+}
+
+
+//Setter
+void CPhmsResponse::SetPhmsResponseHead(CPhmsResponseHead phmsResponseHead)
+{
+	m_phmsResponseHead = phmsResponseHead;
+}
+void CPhmsResponse::SetPhmsResponseBody(CPhmsResponseBody phmsResponseBody)
+{
+	m_phmsResponseBody = phmsResponseBody;
+}
+
+//pInputStream:用于获得HttpSession中服务器返回的内容
+//pPhmsSession:应传入CPhmsSession*,用于在流异常的状态情况下获得Http异常信息,并写入日志;同时也是为将来扩展使用Http长连接
+//时,如果发生http流异常调用HttpSession::reset函数使用
+
+int CPhmsResponse::SetPhmsResponse(istream* pInputStream, void* pPhmsSession)
+{
+	int nPhmsResponseHeadTotalLength = CPhmsResponseHead::GetPhmsResposeHeadTotalLength();
+	Buffer<char> bufPhmsResponseHead(nPhmsResponseHeadTotalLength+1);
+	memset(bufPhmsResponseHead.begin(), 0, nPhmsResponseHeadTotalLength+1);
+	pInputStream->exceptions(ios::failbit);
+	try
+	{
+		pInputStream->read(bufPhmsResponseHead.begin(), nPhmsResponseHeadTotalLength);
+	}
+	catch(const std::ios::failure& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(bufPhmsResponseHead.begin(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e.what(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RESPONSE_FORMAT_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RESPONSE_FORMAT_ERROR;
+	}
+	catch(const TimeoutException& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_TIMEOUT), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_TIMEOUT;
+	}
+	catch(Exception& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_FAIL;
+	}
+	string stringPhmsResponseHead = bufPhmsResponseHead.begin();
+	m_phmsResponseHead.SetPhmsResponseHead(stringPhmsResponseHead);
+	m_phmsResponseBody.SetInputStreamPointer(pInputStream);
+	m_phmsResponseBody.SetPhmsSessionPointer(pPhmsSession);
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+//错误信息一定通过stringMsgContent返回
+int CPhmsResponse::GetResult(int nSaveType, string& stringMsgContent, string& stringFilePath, bool bFileClearBeforeWrite, bool bNeedConvertEncoding)
+{
+	EnumPhmsResponseReturnCode enumReturnCode = FAIL_RETURN_CODE;
+	enumReturnCode = m_phmsResponseHead.GetPhmsResponseReturnCode();
+
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	if(enumReturnCode != SUCCESS_RETURN_CODE)
+	{
+		//错误信息一定通过stringMsgContent返回
+		nRet = m_phmsResponseBody.InputStreamToString(stringMsgContent);
+		if(nRet != PHMS_SUCCESSFUL_RESULT)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+			return nRet;
+		}
+		else
+		{
+			//服务器返回错误信息写日志
+			int nResultErrorCode = atoi(m_phmsResponseHead.GetReturnCode().c_str());
+			if(nResultErrorCode!=220403 && nResultErrorCode!=220405 && nResultErrorCode!=220303)
+			{
+				CPhmsLogger::GetPhmsLogger()->WriteLog(stringMsgContent, __FUNCTION__, __FILE__, __LINE__);
+			}
+			nSaveType = 1;//错误信息都用字符串保存,并写入日志,设置nSaveType为1是为了后面正确计算签名
+		}
+	}
+	else
+	{
+		switch(nSaveType)
+		{
+		case 0:
+			//残余的响应内容也收回来,防止影响下次接收
+			nRet = m_phmsResponseBody.InputStreamToString(stringMsgContent);
+			break;
+		case 1:
+			nRet = m_phmsResponseBody.InputStreamToString(stringMsgContent);
+			if(nRet != PHMS_SUCCESSFUL_RESULT)
+			{
+				CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+				return nRet;
+			}
+			break;
+		case 2:
+			nRet = m_phmsResponseBody.InputStreamToFile(stringFilePath, bFileClearBeforeWrite);
+			if(nRet != PHMS_SUCCESSFUL_RESULT)
+			{
+				CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+				return nRet;
+			}
+			break;
+		default:
+			break;
+		}
+	}
+	//在istream读之前获得流长度的话,不知道所得流长度是否正确,所以把签名验证放到最后,已确定md5源串size
+	//放到这也因为到这里流的内容全部都读出来了。
+	//但是对于保存到文件并续写文件的情况,暂时不支持签名验证,将来再说(可以在CPhmsResponseBody中加一个成员变量来保存)
+	if(!(nSaveType==2&&bFileClearBeforeWrite==false))
+	{
+		if(this->ValidateSign(nSaveType, stringMsgContent, stringFilePath) == false)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RESPONSE_SIGN_VALIDATE_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_RESPONSE_SIGN_VALIDATE_FAIL;
+		}
+	}
+	
+	if(bNeedConvertEncoding && (nSaveType==1||nSaveType==2) )
+	{
+		nRet = ConvertEncodingFromUtf8(nSaveType, stringMsgContent, stringFilePath);
+		if(nRet != PHMS_SUCCESSFUL_RESULT)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(nRet), __FUNCTION__, __FILE__, __LINE__);
+			return nRet;
+		}
+	}
+	return atoi(m_phmsResponseHead.GetReturnCode().c_str());
+}
+
+bool CPhmsResponse::ValidateSign(int nSaveType, string& stringMsgContent, string& stringFilePath)
+{
+	//首先排除无需验证的情况
+	if(m_phmsResponseHead.GetReturnCode() == "100001" || m_phmsResponseHead.GetReturnCode() == "100002" || 
+		m_phmsResponseHead.GetReturnCode() == "100005" || m_phmsResponseHead.GetReturnCode() == "100006" || 
+		m_phmsResponseHead.GetReturnCode() == "100007")
+	{
+		return true;
+	}
+	if(m_phmsResponseHead.GetSign() == "00000000000000000000000000000000")//只为1068\1099命令而加
+	{
+		return true;
+	}
+	//生成第一个md5
+	string username;
+	string password;
+	//获得用户名和密码
+	{
+		username = CPhmsRequest::GetUsername();
+		password = CPhmsRequest::GetPassword();
+		if(username.size()==0 || password.size()==0)
+		{
+			username = g_stringUsername;
+			password = g_stringPassword;
+		}
+	}
+	string stringSrc1 = username+password;
+	string md5_1;
+	md5_1= CUtil::GetMd5(stringSrc1.c_str(), stringSrc1.size());
+
+	//获得buf总长度
+	int nLength = 0;
+	int nHeadLengthExceptSign = 0;
+	nHeadLengthExceptSign = m_phmsResponseHead.GetPhmsResposeHeadTotalLength()-(int)m_phmsResponseHead.GetSign().size();
+	int nIStreamLength = 0;
+	ifstream ifLocalTargetFile;
+	streampos pos = 0;
+	
+	switch(nSaveType)
+	{
+	case 0:
+		nIStreamLength = 0;
+		break;
+	case 1:
+		nIStreamLength = (int)stringMsgContent.size();
+		break;
+	case 2:
+		ifLocalTargetFile.exceptions(ios::failbit|ios::badbit);
+		try
+		{
+			ifLocalTargetFile.open(stringFilePath.c_str(), ios::in|ios::binary);
+		}
+		catch(const ios::failure& error)
+		{
+			//写日志
+			CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+			return false;
+		}
+		pos = ifLocalTargetFile.tellg();
+		ifLocalTargetFile.seekg(0,ios::end);   
+		nIStreamLength = ifLocalTargetFile.tellg();   
+		ifLocalTargetFile.seekg(pos);
+		break;
+	default:
+		nIStreamLength = 0;
+		break;
+	}
+	//获得总长度并构造bufSrc
+	char* bufSrc = NULL;
+	nLength = (int)md5_1.size()+nHeadLengthExceptSign+nIStreamLength;
+	bufSrc = new char[nLength+1];
+	memset(bufSrc, 0, nLength+1);
+	//md5_1内容
+	memcpy(bufSrc, md5_1.c_str(), md5_1.size());
+	//PhmsResponseHead内容
+	string stringHeadExceptSign;
+	stringHeadExceptSign = m_phmsResponseHead.GetVersion()+m_phmsResponseHead.GetReturnCode()+m_phmsResponseHead.GetMessageFormat();
+	memcpy(bufSrc+md5_1.size(), stringHeadExceptSign.c_str(), nHeadLengthExceptSign);
+	//PhmsResponseBody内容
+	switch(nSaveType)
+	{
+	case 0:
+		break;
+	case 1:
+		memcpy(bufSrc+md5_1.size()+nHeadLengthExceptSign, stringMsgContent.c_str(), stringMsgContent.size());
+		break;
+	case 2:
+		//int nTempLength = 0;
+		try
+		{
+			ifLocalTargetFile.read(bufSrc+md5_1.size()+nHeadLengthExceptSign, nIStreamLength);
+			ifLocalTargetFile.close();
+		}
+		catch (const ios::failure& error)
+		{
+			//写日志
+			ifLocalTargetFile.close();
+			delete bufSrc;
+			CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_FILE_READ_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return false;
+		}
+		break;
+	}
+	//生成最终的md5,校验
+	string md5_2 ;
+	md5_2 = CUtil::GetMd5(bufSrc, nLength);
+	if(md5_2 != m_phmsResponseHead.GetSign())
+	{
+		delete bufSrc;
+		return false;
+	}
+	delete bufSrc;
+	return true;
+}
+
+int CPhmsResponse::ConvertEncodingFromUtf8(int nSaveType, string& stringMsgContent, string& stringFilePath)
+{
+	string stringTempXmlContent;
+	string stringWorkingDir = CUtil::GetCurrentAppDir();
+	string stringIniFilePath = stringWorkingDir+"PhmsConfig.ini";
+	AutoPtr<IniFileConfiguration> iniFile = new IniFileConfiguration(stringIniFilePath, "gbk");
+	string stringEncoding = iniFile->getString("OTHER.Encoding", "GBK");
+	TextEncoding* pEnvEncoding = TextEncoding::find(stringEncoding);
+	TextEncoding* pUtf8Encoding = TextEncoding::find("UTF-8");
+
+	ostringstream ostr;
+	if(nSaveType == 1)
+	{
+		istringstream istr(stringMsgContent);
+		istr.exceptions(ios::badbit);
+		InputStreamConverter converter(istr, *pUtf8Encoding, *pEnvEncoding);
+		try
+		{
+			StreamCopier::copyStream(converter, ostr);
+		}
+		catch(const std::ios::failure& e)
+		{
+			CPhmsLogger::GetPhmsLogger()->WriteLog(e.what(), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_INPUT_STREAM_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_INPUT_STREAM_FAIL;
+		}
+		stringTempXmlContent = ostr.str();
+	}
+	if(nSaveType == 2)
+	{
+		ifstream istr;
+		istr.exceptions(ios::badbit);
+		try
+		{
+			istr.open(stringFilePath.c_str());
+		}
+		catch(const ios::failure& error)
+		{
+			//写日志
+			CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_FILE_OPEN_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_FILE_OPEN_FAIL;
+		}
+		InputStreamConverter converter(istr, *pUtf8Encoding, *pEnvEncoding);
+		try
+		{
+			StreamCopier::copyStream(converter, ostr);
+		}
+		catch(const std::ios::failure& e)
+		{
+			istr.close();
+			CPhmsLogger::GetPhmsLogger()->WriteLog(e.what(), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_INPUT_STREAM_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_INPUT_STREAM_FAIL;
+		}
+		istr.close();
+		stringTempXmlContent = ostr.str();
+	}
+
+
+
+	string stringSrc = "encoding=\"UTF-8\"?>";
+	string stringDst = "encoding=\"";
+	stringDst += stringEncoding;
+	stringDst += "\"?>";
+	CUtil::ReplaceString(stringTempXmlContent, stringSrc, stringDst);
+	if(nSaveType == 1)
+	{
+		stringMsgContent = stringTempXmlContent;
+	}
+	if(nSaveType == 2)
+	{
+		ofstream ofs;
+		ofs.exceptions(ios::failbit | ios::badbit);
+		try
+		{
+			ofs.open(stringFilePath.c_str(), ios::out|ios::trunc);
+			ofs.write(stringTempXmlContent.c_str(), stringTempXmlContent.size());
+			ofs.close();
+		}
+		catch(const std::ios::failure& e)
+		{
+			ofs.close();
+			CPhmsLogger::GetPhmsLogger()->WriteLog(e.what(), __FUNCTION__, __FILE__, __LINE__);
+			CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_INPUT_STREAM_FAIL), __FUNCTION__, __FILE__, __LINE__);
+			return COMMON_INPUT_STREAM_FAIL;
+		}
+
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}

+ 33 - 0
PhmsResponse.h

@@ -0,0 +1,33 @@
+#pragma once
+#include <istream>
+#include <string>
+#include "PhmsResponseHead.h"
+#include "PhmsResponseBody.h"
+
+
+using namespace std;
+
+class CPhmsResponse
+{
+public:
+	CPhmsResponse();
+	CPhmsResponse(CPhmsResponse& phmsResponse);
+	CPhmsResponse& operator=(CPhmsResponse& phmsResponse);
+	~CPhmsResponse(void);
+private:
+	CPhmsResponseHead m_phmsResponseHead;
+	CPhmsResponseBody m_phmsResponseBody;
+public:
+	//Getter
+	CPhmsResponseHead& GetPhmsResponseHead();
+	CPhmsResponseBody& GetPhmsResponseBody();
+	//Setter
+	void SetPhmsResponseHead(CPhmsResponseHead phmsResponseHead);
+	void SetPhmsResponseBody(CPhmsResponseBody phmsResponseBody);
+
+	int SetPhmsResponse(istream* pInputStream, void* pPhmsSession=NULL);
+	int GetResult(int nSaveType, string& stringMsgContent, string& stringFilePath, bool bFileClearBeforeWrite=true, bool bNeedConvertEncoding=true);
+	bool ValidateSign(int nSaveType, string& stringMsgContent, string& stringFilePath);
+private:
+	int ConvertEncodingFromUtf8(int nSaveType, string& stringMsgContent, string& stringFilePath);
+};

+ 175 - 0
PhmsResponseBody.cpp

@@ -0,0 +1,175 @@
+#include "PhmsResponseBody.h"
+#include "Poco/StreamCopier.h"
+#include "Poco/Buffer.h"
+#include <fstream>
+#include <sstream>
+#include "ErrorCode.h"
+#include "Poco/Exception.h"
+#include "Poco/File.h"
+#include "PhmsSession.h"
+#include "PhmsLogger.h"
+#include "Util.h"
+
+using Poco::StreamCopier;
+using Poco::Buffer;
+using Poco::Exception;
+using Poco::TimeoutException;
+using Poco::File;
+
+
+CPhmsResponseBody::CPhmsResponseBody(void):m_pInputStream(NULL), m_pPhmsSession(NULL)
+{
+}
+
+
+CPhmsResponseBody::CPhmsResponseBody(istream* pInputStream, void* pPhmsSession)
+:m_pInputStream(pInputStream), m_pPhmsSession(pPhmsSession)
+{
+}
+
+CPhmsResponseBody::CPhmsResponseBody(CPhmsResponseBody& phmsResponseBody)
+{
+	this->m_pInputStream = phmsResponseBody.GetInputStreamPointer();
+	this->m_pPhmsSession = phmsResponseBody.GetPhmsSessionPointer();
+}
+
+CPhmsResponseBody& CPhmsResponseBody::operator=(CPhmsResponseBody& phmsResponseBody)
+{
+	this->m_pInputStream = phmsResponseBody.GetInputStreamPointer();
+	this->m_pPhmsSession = phmsResponseBody.GetPhmsSessionPointer();
+	return *this;
+}
+
+CPhmsResponseBody::~CPhmsResponseBody(void)
+{
+}
+
+
+//Getter
+istream* CPhmsResponseBody::GetInputStreamPointer()
+{
+	return this->m_pInputStream;
+}
+void* CPhmsResponseBody::GetPhmsSessionPointer()
+{
+	return this->m_pPhmsSession;
+}
+//Setter
+void CPhmsResponseBody::SetInputStreamPointer(istream* pInputStream)
+{
+	this->m_pInputStream = pInputStream;
+}
+void CPhmsResponseBody::SetPhmsSessionPointer(void* pPhmsSession)
+{
+	this->m_pPhmsSession = pPhmsSession;
+}
+
+int CPhmsResponseBody::InputStreamToString(string& stringContent)
+{
+	//流形式实现,此处用string输出流可能有问题,因为用户可能将二进制数据也保存到buffer,用string流可能会出问题。
+	//应该使用Poco::MemoryIOS
+	//不过目前系统中暂时没有这么使用的,有这么用的再说
+	ostringstream oStringStream;
+	oStringStream.exceptions(ios::failbit|ios::badbit);
+	m_pInputStream->exceptions(ios::badbit);
+	try
+	{
+		StreamCopier::copyStream(*m_pInputStream, oStringStream);
+	}
+	catch(const std::ios::failure& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e.what(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_INPUT_STREAM_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_INPUT_STREAM_FAIL;
+	}
+	catch(const TimeoutException& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_TIMEOUT), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_TIMEOUT;
+	}
+	catch(const Exception& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_FAIL;
+	}
+	stringContent = oStringStream.str();
+	return PHMS_SUCCESSFUL_RESULT;
+}
+int CPhmsResponseBody::InputStreamToFile(string& stringFilePath, bool bFileClearBeforeWrite)
+{
+	try
+	{
+		File fileTarget(stringFilePath, "gbk");
+		fileTarget.createFile();
+	}
+	catch(Exception& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_FILE_OPEN_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_FILE_OPEN_FAIL;
+	}
+	ofstream ofLocalTargetFile;
+	ofLocalTargetFile.exceptions(ios::failbit|ios::badbit);
+	m_pInputStream->exceptions(ios::goodbit);
+	try
+	{
+		if(bFileClearBeforeWrite)
+		{
+			ofLocalTargetFile.open(stringFilePath.c_str(), ios_base::trunc|ios_base::binary);
+		}
+		else
+		{
+			//locale localePre = ofLocalTargetFile.imbue(locale(""));//imbue不起作用
+			ofLocalTargetFile.open(stringFilePath.c_str(), ios_base::app|ios_base::binary);
+			//ofLocalTargetFile.imbue(localePre);
+		}
+	}
+	catch(const ios::failure& error)
+	{
+		//写日志
+		CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_FILE_OPEN_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_FILE_OPEN_FAIL;
+	}
+	m_pInputStream->exceptions(ios::badbit);
+	ofLocalTargetFile.exceptions(ios::failbit|ios::badbit);
+	try
+	{
+		StreamCopier::copyStream(*m_pInputStream, ofLocalTargetFile);
+	}
+	catch(const std::ios::failure& e)
+	{
+		ofLocalTargetFile.close();
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e.what(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_INPUT_STREAM_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_INPUT_STREAM_FAIL;
+	}
+	catch(const TimeoutException& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_TIMEOUT), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_TIMEOUT;
+	}
+	catch(const Exception& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_RECV_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_RECV_FAIL;
+	}
+	try
+	{
+		ofLocalTargetFile.flush();
+	}
+	catch(const ios::failure& error)
+	{
+		//写日志
+		ofLocalTargetFile.close();
+		CPhmsLogger::GetPhmsLogger()->WriteLog(error.what(), __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_FILE_WRITE_FAIL), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_FILE_WRITE_FAIL;
+	}
+	ofLocalTargetFile.close();
+	return PHMS_SUCCESSFUL_RESULT;
+}

+ 27 - 0
PhmsResponseBody.h

@@ -0,0 +1,27 @@
+#pragma once
+#include <string>
+using namespace std;
+
+class CPhmsResponseBody
+{
+public:
+	CPhmsResponseBody(void);
+	CPhmsResponseBody(istream* pInputStream, void* pPhmsSession);
+	CPhmsResponseBody(CPhmsResponseBody&);
+	CPhmsResponseBody& operator=(CPhmsResponseBody&);
+	~CPhmsResponseBody(void);
+private:
+	istream* m_pInputStream;//该变量用于获得Http返回内容
+	void*  m_pPhmsSession;//用于将来的长连接扩展
+public:
+	//Getter
+	istream*  GetInputStreamPointer();
+	void* GetPhmsSessionPointer();
+
+	//Setter
+	void SetInputStreamPointer(istream* pInputStream);
+	void SetPhmsSessionPointer(void* pPhmsSession);
+
+	int InputStreamToString(string& stringContent);
+	int InputStreamToFile(string& stringFilePath, bool bFileClearBeforeWrite=true);
+};

+ 120 - 0
PhmsResponseHead.cpp

@@ -0,0 +1,120 @@
+#include "PhmsResponseHead.h"
+
+CPhmsResponseHead::CPhmsResponseHead(void)
+{
+}
+
+CPhmsResponseHead::CPhmsResponseHead(string stringPhmsResponseHead)
+{
+	this->m_stringSign = stringPhmsResponseHead.substr(0, SIGN_LENGTH);
+	this->m_stringVersion = stringPhmsResponseHead.substr(SIGN_LENGTH, VERSION_LENGTH);
+	this->m_stringReturnCode = stringPhmsResponseHead.substr(SIGN_LENGTH+VERSION_LENGTH, RETURNCODE_LENGTH);
+	this->m_stringMessageFormat = stringPhmsResponseHead.substr(SIGN_LENGTH+VERSION_LENGTH+RETURNCODE_LENGTH, MESSAGEFORMAT_LENGTH);
+}
+CPhmsResponseHead::CPhmsResponseHead(string stringSign, string stringVersion, string stringReturnCode, string stringMessageFormat)
+{
+	this->m_stringSign = stringSign;
+	this->m_stringVersion = stringVersion;
+	this->m_stringReturnCode = stringReturnCode;
+	this->m_stringMessageFormat = stringMessageFormat;
+}
+CPhmsResponseHead::CPhmsResponseHead(CPhmsResponseHead& phmsResponseHead)
+{
+	this->m_stringSign = phmsResponseHead.m_stringSign;
+	this->m_stringVersion = phmsResponseHead.m_stringVersion;
+	this->m_stringReturnCode = phmsResponseHead.m_stringReturnCode;
+	this->m_stringMessageFormat = phmsResponseHead.m_stringMessageFormat;
+}
+CPhmsResponseHead& CPhmsResponseHead::operator=(CPhmsResponseHead& phmsResponseHead)
+{
+	this->m_stringSign = phmsResponseHead.m_stringSign;
+	this->m_stringVersion = phmsResponseHead.m_stringVersion;
+	this->m_stringReturnCode = phmsResponseHead.m_stringReturnCode;
+	this->m_stringMessageFormat = phmsResponseHead.m_stringMessageFormat;
+	return *this;
+}
+
+CPhmsResponseHead::~CPhmsResponseHead(void)
+{
+}
+
+
+//Getter
+string CPhmsResponseHead::GetSign()
+{
+	return this->m_stringSign;
+}
+string CPhmsResponseHead::GetVersion()
+{
+	return this->m_stringVersion;
+}
+string CPhmsResponseHead::GetReturnCode()
+{
+	return this->m_stringReturnCode;
+}
+string CPhmsResponseHead::GetMessageFormat()
+{
+	return this->m_stringMessageFormat;
+}
+
+//Setter
+void CPhmsResponseHead::SetSign(string stringSign)
+{
+	this->m_stringSign = stringSign;
+}
+void CPhmsResponseHead::SetVersion(string stringVersion)
+{
+	this->m_stringVersion = stringVersion;
+}
+void CPhmsResponseHead::SetReturnCode(string stringReturnCode)
+{
+	this->m_stringReturnCode = stringReturnCode;
+}
+void CPhmsResponseHead::SetMessageFormat(string stringMessageFormat)
+{
+	this->m_stringMessageFormat = stringMessageFormat;
+}
+
+
+EnumPhmsResponseMessageFormat CPhmsResponseHead::GetPhmsResponseMessageFormat()
+{
+	if(this->m_stringMessageFormat == "10")
+	{
+		return NO_PHMS_RESPONSE_BODY;
+	}
+	if(this->m_stringMessageFormat == "11")
+	{
+		return XML_PHMS_RESPONSE_BODY;
+	}
+	if(this->m_stringMessageFormat == "12")
+	{
+		return FILE_OR_ECHORSTRING_PHMS_RESPONSE_BODY;
+	}
+	if(this->m_stringMessageFormat == "13")
+	{
+		return JSON_PHMS_RESPONSE_BODY;
+	}
+	return WRONG_PHMS_RESPONSE_MESSAGE_FORMAT;
+}
+
+EnumPhmsResponseReturnCode CPhmsResponseHead::GetPhmsResponseReturnCode()
+{
+	if(this->m_stringReturnCode == "100000")
+	{
+		return SUCCESS_RETURN_CODE;
+	}
+	return FAIL_RETURN_CODE;
+}
+
+int CPhmsResponseHead::GetPhmsResposeHeadTotalLength()
+{
+	return TOTAL_HEAD_LENGTH;
+}
+
+void CPhmsResponseHead::SetPhmsResponseHead(string stringPhmsResponseHead)
+{
+	this->m_stringSign = stringPhmsResponseHead.substr(0, SIGN_LENGTH);
+	this->m_stringVersion = stringPhmsResponseHead.substr(SIGN_LENGTH, VERSION_LENGTH);
+	this->m_stringReturnCode = stringPhmsResponseHead.substr(SIGN_LENGTH+VERSION_LENGTH, RETURNCODE_LENGTH);
+	this->m_stringMessageFormat = stringPhmsResponseHead.substr(SIGN_LENGTH+VERSION_LENGTH+RETURNCODE_LENGTH, MESSAGEFORMAT_LENGTH);
+}

+ 63 - 0
PhmsResponseHead.h

@@ -0,0 +1,63 @@
+#pragma once
+#include <string>
+
+using namespace std;
+
+
+enum EnumPhmsResponseMessageFormat
+{
+	WRONG_PHMS_RESPONSE_MESSAGE_FORMAT=-1,
+	NO_PHMS_RESPONSE_BODY,
+	XML_PHMS_RESPONSE_BODY,
+	FILE_OR_ECHORSTRING_PHMS_RESPONSE_BODY,
+	JSON_PHMS_RESPONSE_BODY
+};
+
+enum EnumPhmsResponseReturnCode
+{
+	SUCCESS_RETURN_CODE=0,
+	FAIL_RETURN_CODE
+};
+
+class CPhmsResponseHead
+{
+public:
+	CPhmsResponseHead(void);
+	CPhmsResponseHead(string stringPhmsResponseHead);
+	CPhmsResponseHead(string stringSign, string stringVersion, string stringReturnCode, string stringMessageFormat);
+	CPhmsResponseHead(CPhmsResponseHead& phmsResponseHead);
+	CPhmsResponseHead& operator=(CPhmsResponseHead& phmsResponseHead);
+	~CPhmsResponseHead(void);
+private:
+	string m_stringSign;
+	string m_stringVersion;
+	string m_stringReturnCode;
+	string m_stringMessageFormat;
+	enum EnumPhmsResponseHeadStringLength
+	{
+		SIGN_LENGTH=32,
+		VERSION_LENGTH=2,
+		RETURNCODE_LENGTH=6,
+		MESSAGEFORMAT_LENGTH=2,
+		TOTAL_HEAD_LENGTH=42
+	};
+public:
+	//Getter
+	string GetSign();
+	string GetVersion();
+	string GetReturnCode();
+	string GetMessageFormat();
+
+	//Setter
+	void SetSign(string stringSign);
+	void SetVersion(string stringVersion);
+	void SetReturnCode(string stringReturnCode);
+	void SetMessageFormat(string stringMessageFormat);
+
+	void SetPhmsResponseHead(string stringPhmsResponseHead);
+
+
+	EnumPhmsResponseMessageFormat GetPhmsResponseMessageFormat();
+	EnumPhmsResponseReturnCode GetPhmsResponseReturnCode();
+	static int GetPhmsResposeHeadTotalLength();
+};

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 13844 - 0
PhmsSession.cpp


+ 446 - 0
PhmsSession.h

@@ -0,0 +1,446 @@
+/*以后与其他公司做对接以GuanXin实现为标准*/
+#pragma once
+#include "NetConfig.h"
+#include "PhmsRequest.h"
+#include "PhmsResponse.h"
+#include "HttpSession.h"
+#include "PhmsDataType.h"
+#include "Poco/DOM/Document.h"
+#include "Poco/AutoPtr.h"
+#include "Poco/Mutex.h"
+
+using Poco::Mutex;
+
+enum EnumPhmsCommandType{
+	LOGIN_TYPE=0,
+	MAIN_TYPE,
+	CHANGE_INFO_TYPE,
+	REGISTER_TYPE
+};
+
+enum EnumXmlCommandType
+{
+	SELECT_DOCTOR_TYPE=0,
+	PAY_VERIFICATION_TYPE,
+	PAY_VERIFICATION_CASE_TYPE
+};
+
+enum EnumXmlCommandType_Telecom
+{
+	USER_AUTH=0,
+	SYNC_BP,
+	SYNC_BO,
+	SYNC_BS,
+	SYNC_HW,
+	SYNC_LUNG,
+	SYNC_ECG
+};
+
+enum EnumXinJieCommandType
+{
+	VALIDATE_PAY=0,
+	NOTIFY_PAY
+};
+
+enum EnumGuanXinCommandType
+{
+	ACCESSTOKEN=0,
+	PERSONINFO,
+	SESSION,
+	UPLOADECG,
+	UPLOADNONECG,
+	UPLOADMONITOR,
+	UPLOADPERSONINFO
+};
+
+enum EnumXiKangCommandType
+{
+	GET_TOKEN_XIKANG=0,
+	LOGIN_XIKANG,
+	REGISTER_PATIENT_XIKANG,
+	REGISTER_PATIENT_INFO_XIKANG,
+	BIND_PATIENT_XIKANG,
+	GET_PATIENT_ID_XIKANG,
+	GET_PATIENT_INFO_XIKANG,
+	SEARCH_PATIENT_ID_XIKANG,
+	GET_CASE_LIST_XIKANG,
+	SUBMIT_CASE_XIKANG,
+	UPLOAD_FILE_XIKANG,
+	GET_REPORT_URL_XIKANG
+};
+
+enum EnumPhmsCaseState
+{
+	CASE_STAT_NEW=0,
+	CASE_STAT_UPLOADING,
+	CASE_STAT_UPLOADED,
+	CASE_STAT_DOWNLOADING,
+	CASE_STAT_DOWNLOADED,
+	CASE_STAT_DIAGNOSIS,
+	CASE_STAT_VOID,
+	CASE_STAT_DIAGNOSISED,
+	CASE_STAT_TRANSMITING,
+	CASE_STAT_TRANSMITED
+};
+
+enum EnumNetConfigType
+{
+	ORIGINAL_PHMS=0,
+	DAOYI_XML,
+	TELECOM_XML,
+	GUANXIN_FORM,
+	XIKANG_FORM,
+	XINJIE_XML,
+	DIRECTLY_TO_HIS,
+	GW_FORM
+};
+
+class CPhmsSession
+{
+public:
+	CPhmsSession(void);
+	~CPhmsSession(void);
+private:
+	CHttpSession* m_pHttpSession;
+	bool m_bSsl;//记录当前ssl的使用情况,即上一次ssl使用情况
+	string m_stringSessionId;//只有Login/Logout函数才能改变这个值(即要想改变SessionId,必须重新登录),每个PhmsSession对象都用一个SessionId,且对用户透明
+	string m_stringGWSessionId;//保存公卫系统的sessionid
+	//以下三个参数用户指定服务器返回数据保存方式
+	int m_nSaveType;
+	string m_stringContent;
+	string m_stringFilePath;
+	EnumPhmsCommandType m_enumPhmsCommandType;
+	bool m_bUseIp;
+	string m_stringIp;
+	Mutex m_mutexAbortAndSslSwitch;
+	static string m_stringKey;//用于东亚医讯
+	static string m_stringToken_XiKang;//用于东软熙康
+	static string m_stringClientId_XiKang;
+	static string m_stringClientSecret_XiKang;
+	static string m_stringGWSecretKey;
+	EnumXmlCommandType m_enumXmlCommandType;//用于东亚医讯
+	EnumXmlCommandType_Telecom m_enumXmlCommandType_Telecom;//用于电信健康小屋
+	EnumXinJieCommandType m_enumXinJieCommandType;//用于北京心界
+	EnumGuanXinCommandType m_enumGuanXinCommandType;//用于冠新公共卫生平台
+	EnumXiKangCommandType m_enumXiKangCommandType;//用于东软熙康
+	EnumNetConfigType m_enumNetConfigType;
+private:
+	int ExecutePhmsSession(CPhmsRequest& phmsReuest, CPhmsResponse& phmsResponse, bool bMustSsl=false);
+	int ExecuteXmlSession(string stringXmlContent, bool bMustSsl=false);
+	int ExecuteXinJieSession(string stringBase64Content, bool bMustSsl=false);
+	int ExecuteXmlSession_Telecom(string stringXmlContent, bool bMustSsl=false);
+	int ExecuteGuanXinSession(map<string, string> mapParam, string stringDataPath, bool bMustSsl=false);
+	int ExecuteXiKangSession(map<string, string> mapParam, string stringDataPath, string stringUrlOpenId, bool bMustSsl=false);
+	//从服务器的登录命令返回xml内容中获得sessionid
+	int GetSessionId(int nSaveType, string stringContent, string stringFilePath);
+	string GetXiKangToken(int nSaveType, string stringContent, string stringFilePath);
+	int GetRequestXml(Poco::AutoPtr<Poco::XML::Document> pDoc, string& stringXmlContent);
+	int GetRequestXml(string stringFilePath, string& stringXmlContent);
+	int GetRequestXmlNoBase64(Poco::AutoPtr<Poco::XML::Document> pDoc, string& stringXmlContent, bool bUtf8=false);
+	int GetRequestXmlForAESAndBase64(Poco::AutoPtr<Poco::XML::Document> pDoc, string& stringXmlContent);
+	int GetNetConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl, EnumNetConfigType enumNetConfigType);//20171025添加,用于在不同业务找不同网络配置的时候,根据enum调用不同的函数GetXXXNetConfig函数
+	int GetNetConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetNoPhmsNetConfig(string stringFilePath, CNetConfig& netConfig, string stringUrl, bool bMustSsl);
+	int GetXmlNetConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetXmlNetConfig_Telecom(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetXinJieNetConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetGuanXinNetConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetXiKangNetConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetDirectlyToHisConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetGWNetConfig(string stringFilePath, CNetConfig& netConfig, bool bMustSsl);
+	int GetFormNetConfig(string stringFilePath, CNetConfig& netConfig, string stringHost, string stringUrl, bool bMustSsl);
+	int NoPhmsGetResult(istream* pInputStream, int bContinue=0);
+	int NoPhmsInputStreamToString(istream* pInputStream, string& stringContent);
+	int NoPhmsInputStreamToFile(istream* pInputStream, string& stringFilePath, bool bFileClearBeforeWrite);
+public:
+	int GetHttpExceptionInfo(int& nCode, string& stringMsgName, string& stringMsgText);
+	int AbortSession();
+public:
+	//Setter
+	void SetSaveType(int nSaveType);
+	void SetFilePath(string stringFilePath);
+	void SetSessionId(string stringSessionId);
+	void SetGWSessionId(string stringSessionId);
+	void SetCommandType(EnumPhmsCommandType enumCommandType);
+	void SetXmlCommandType(EnumXmlCommandType enumXmlCommandType);
+	void SetXmlCommandType_Telecom(EnumXmlCommandType_Telecom enumXmlCommandType_Telecom);
+	void SetXinJieCommandType(EnumXinJieCommandType enumXinJieCommandType);
+	void SetGuanXinCommandType(EnumGuanXinCommandType enumGuanXinCommandType);
+	void SetXiKangCommandType(EnumXiKangCommandType enumXiKangCommandType);
+	void SetNetConfigType(EnumNetConfigType enumNetConfigType);
+	void SetUseIp(bool bUseIp);
+	void SetGWSecretKey(string stringGWSecretKey);
+	//Getter
+	int GetSaveType();
+	string GetContent();
+	string GetSessionId();
+	string GetGWSessionId();
+	EnumPhmsCommandType GetCommandType();
+	EnumXmlCommandType GetXmlCommandType();
+	EnumXmlCommandType_Telecom GetXmlCommandType_Telecom();
+	EnumXinJieCommandType GetXinJieCommandType();
+	EnumGuanXinCommandType GetGuanXinCommandType();
+	EnumNetConfigType GetNetConfigType();
+	string GetIp();
+	string GetGWSecretKey();
+public:
+	//PHMS接口
+	int Login(string stringRole, string stringUsername, string stringPassword, string stringLanguage, string stringToken, bool bMustSsl);
+	int MechineRegister(string stringCountry, string stringAreaId, string stringArea, 
+		string stringDevide, string stringSignature, string stringSerialnum);
+	int Logout();
+	int SetDoctorSign(string stringMd5, string stringFilePath);
+	int SetDoctorPhoto(string stringMd5, string stringFilePath);
+	int ApplyNewCase(string stringName, string stringThirdId, string stringDataType, string stringDataTypeName, string stringNotes, string stringHospitalId,
+		string stringHospitalName, string stringDoctorId, string stringDoctorName, string stringCheckTime, string stringOtherParams, string stringDeviceId, 
+		string stringDeviceName, string stringMd5, string stringCaseOrigin, string stringYzlb, string stringSex, string stringApplicationNo, string stringAutoMatic);
+	int UploadCaseSegment(string stringCaseId, string stringOrder, string stringTotalSize, string stringServerUri, string stringStart1, 
+		string stringEnd1, string stringMd51, string stringStart2, string stringEnd2, string stringMd52, string stringStart3, 
+		string stringEnd3,string stringMd53, string stringFilePath);
+	int CaseHoldPlace(string stringCaseId, string stringReceiverId);
+	int GetAutoDownloadCase(string stringCaseType,string stringSenderId,string stringCaseOrigin);
+	int DownloadCaseBegin(string stringCaseId, string stringReceiverId);
+	int DownloadFileSegment(string stringUri, string stringStart, string stringEnd);
+	int DownloadCaseComplete(string stringCaseId, string stringReceiverId);
+	int InvalidCase(string stringCaseId, string stringReceiverId, string stringReason);
+	int TransmitCase(string stringCaseId, string stringReceiverId, string stringForwardToH, string stringForwardToHospitalName, 
+		string stringForwardToD, string stringForwardToDoctorName);
+	int Rollback(string stringCaseId, string stringReceiverId, string stringBackTo);
+	int GetHospitalListOfGroup(string stringGroupId, string stringType, string stringCaseType, string stringPageTo, string stringPageSize);
+	int GetDoctorListOfHospital(string stringHospitalId, string stringDoctorId, string stringCaseType, string stringDoctorType, string stringPageTo, string stringPageSize);
+	int AnalyzeBegin(string stringCaseId, string stringReceiverId, string stringCaseType);
+	int AnalyzeComplete(string stringCaseId, string stringReceiverId, string stringCaseType);
+	int ApplyNewReport(string stringCaseId, string stringReceiverId, string stringDiagnosis, string stringMd5, string stringDigitalSign, string stringTimestampSign, string stringCaseType);
+	int UploadReportSegment(string stringCaseId, string stringReceiverId, string stringCaseType, string stringReportId, string stringOrder, string stringTotalSize, 
+		string stringServerUri, string stringStart1, string stringEnd1, string stringMd51, string stringStart2, string stringEnd2, 
+		string stringMd52, string stringStart3, string stringEnd3, string stringMd53, string stringFilePath, string stringFileType);
+	int DownloadReportBegin(string stringCaseId, string stringReportId);
+	int DownloadReportComplete(string stringCaseId, string stringReportId);
+	int GetAlreadyUploadFileSize(string stringServerUri);
+	int GetReviewReportList(string stringReportStartDate, string stringReportEndDate, string stringReviewStartDate, string stringReviewEndDate, 
+		string stringReviewState, string stringCaseType, string stringPtName, string stringSenderId, string stringYzlb, string stringAId, 
+		string stringReviewerId, string stringReceiverId, string stringCaseId, string stringPageTo, string stringPageSize);
+	int ReviewReport(string stringReportId, string stringReviewState, string stringPath, string stringDiagnostic, 
+		string stringDigitalSign, string stringTimeStampSign);
+	int GetReportStateOfCase(string stringCaseId);
+	int GetCaseListOfDoctor(string stringCaseId, string stringCaseType, string stringCaseSource, string stringCaseState, string stringPatientName, 
+		string stringSenderId, string stringReceiverId, string stringStartDate, string stringEndDate, string stringCheckStartDate, string stringCheckEndDate, 
+		string stringSenderName, string stringDiagnostic, string stringCaseOrigin, string stringYzlb, string stringAId, string stringSex, string stringOrderBy, string stringThirdId, 
+		string stringLang, string stringIsFullName, string stringPageTo, string stringPageSize);
+	int GetHospitalInfo(string stringHospitalId);
+	int UploadIm(string stringSenderId, string stringSenderName, string stringReceiverId, string stringMsgDirection, string stringMsgType, 
+		string stringMsgContent, string stringCaseId, string stringCaseType);
+	int GetImList(string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgDirection, string stringMsgType);
+	int GetImList2(string stringNextId);
+	int ImDownloadComplete(string stringId);
+	int SendPhoneMsg(string stringCaseId, string stringPhone, string stringMsg);
+	int UploadTrendData(string stringCardId, string stringDeviceId, string stringDeviceName, string stringCaseId, vector<RECORD_DATA> vRecordData);
+	int UploadTrendDataString(string stringCardId, string stringDeviceId, string stringDeviceName, string stringCaseId, vector<RECORD_DATA_STRING> vRecordData);
+	int UploadTrendDataFile(string stringFilePath);
+	int UploadAudioSegment(string stringMsgId, string stringOrder, string stringTotalSize, string stringServerUri, string stringStart1, 
+		string stringEnd1, string stringMd51, string stringStart2, string stringEnd2, string stringMd52, string stringStart3, 
+		string stringEnd3, string stringMd53, string stringFilePath);
+	int UploadAdvice(string stringUserId, string stringUsername, string stringMsg, string stringType, string stringIsSendMsg);
+	int GetAdvice(string stringSgId, string stringUserId, string stringDoctorId, string stringDownloadState, string stringType, string stringStartDate, 
+		string stringEndDate, string stringPageTo, string stringPageSize);
+	int DownloadAdviceComplete(string stringAdviceId);
+	int GetReportListOfCase(string stringCaseId);
+	int GetSelfInfo(string stringSenderId);//接口有变动,加了一个参数senderid,表示要查找信息的人,如为空表示自己
+	int ChangePwd(string stringOldPassword, string stringNewPassword);
+	int DoctorChangeSelfInfo(string stringName, string stringSex, string stringTel, string stringBirthYear, string stringPosition, 
+		string stringNotes, string stringAgentId);
+	int CliniqueChangeSelfInfo(string stringPersonId, string stringName, string stringTel, string stringNotes);
+	int CardUserChangeSelfInfo(string stringPersonId, string stringName, string stringSex, string stringTel, string stringBirthday, 
+		string stringAddress, string stringLmp, string stringToken, string stringHeight, string stringWeight, string stringPhoto, 
+		string stringVCodeBeFollowed, string stringHospitalId, string stringOtherInfo);
+	int GetCaseListOfUser(string stringCaseId, string stringCaseType, string stringCaseState, string stringThirdId, string stringName, 
+		string stringStartDate, string stringEndDate, string stringCheckStartDate, string stringCheckEndDate, string stringCaseOrigin, 
+		string stringYzlb, string stringSex, string stringIsRead, string stringOrderBy, string stringPageTo, string stringPageSize);
+	int GetReportListOfUser(string stringReportId, string stringReportStartDate, string stringReportEndDate, string stringCaseType, 
+		string stringState, string stringOrderBy, string stringPageTo, string stringPageSize);
+	int GetCardUserList(string stringCardId, string stringSenderId, string stringPersonId, string stringTel, string stringName, string stringType,
+		string stringPageTo, string stringPageSize);
+	int KeepSession();
+	int MarkCaseException(string stringCaseId, string stringReceiverId, int nResultFlag);
+	int MarkReportRead(string stringReportId);
+	int Feedback(string stringTitle, string stringNotes, string stringPhone, string stringFilePath);
+	int UploadTrendData2(string stringTargetPath);
+	int GetAllTeamList();
+	int GetDoctorListOfTeam(string stringTeamId);
+	int GetEventStream(string stringCaseId, string stringOriginalHospital);
+	int GetCaseTypeList(string stringLanguage);
+	int DoctorHandledCaseStatistics(string stringCaseType, string stringStartTime, string stringEndTime);
+	int UserRegister(string stringPhone, string stringName, string stringHeigth);
+	int GetTrendData(string stringUId, string stringInterUId, string stringTrendType, string stringStartDate, string stringEndDate, string stringNextId);//该接口目前只支持保存到文件
+	int GetLastPhysiologicalData();
+	int GetHealthDegree(string stringUId, string stringInterUId, string stringDate);
+	int GetUserOfNoAdviceAndMostData(string stringDays);
+	int AdviceDelay(string stringUId, string stringMinutes);
+	int AdviceComplete(string stringUId, string stringOptionType, string stringAdvice);
+	int GetUserListOfNoAdvice(string stringDays, string stringPageTo, string stringPageSize);
+	int AdviceBegin(string stringUId);
+	int GetUserListOfAdvicing(string stringPageTo, string stringPageSize);
+	int VerifyThirdId(string stringUId, string stringType);
+	int PersonIdRegister(string stringType, string stringRegFrom, string stringPersonId, string stringName, string stringSex, string stringBirthday, string stringAddress, 
+		string stringPhone, string stringHeigth, string stringUploadUnitId, string stringHospitalId, string stringHGroupId, string stringScode, string stringWxUId, string stringLmp, string stringWeight, string stringPassword, 
+		string stringThirdCode, string stringIsRegister);
+	int GetVerificationCode(string stringType, string stringPhone);
+	int GetAskList(string stringAskType, string stringAskEnd, string stringDoctorId, string stringIsAsk, string stringUserId, string stringStartTime, string stringEndTime, string stringPageTo, string stringPageSize);
+	int GetAskDetail(string stringAskId);
+	int GetQuestionList(string stringDoctorId, string stringReportType, string stringAskId);
+	int SubmitQuestion(string stringUserId, string stringAdvise, string stringReportType, string stringAskId, string stringAskedId, string stringDoctorPhotoPath);
+	int GetDataDictionary();
+	int LoggingHealthBaseInfo(string stringUserId, string stringWeblock, string stringNation, string stringProfression, string stringCrowd, string stringBloodType, 
+		string stringJwsJiBing, string stringJwsShouShu, string stringJwsWaiShang, string stringJwsShuXue, string stringJwsBaoLuShi, string stringJwsBaoLuShiBz, 
+		string stringJwsYiChuanJiBing, string stringGmsGuoMinShi, string stringGmsGuoMinShiBz, string stringJzsFuQin, string stringJzsFuQinBz, string stringJzsMuQin, 
+		string stringJzsMuQinBz, string stringJzsXdjm, string stringJzsXdjmBz, string stringJzsZiNv, string stringJzsZiNvBz, string stringJzsQiTa);
+	int LoggingHealthCurrentInfo(string stringUserId, string stringShfsYinShi, string stringShfsXlzk, string stringShfsXlzkBz, string stringShfsXltz, string stringShfsXiYan, 
+		string stringShfsYinJiu, string stringShfsSyqk, string stringShfsYunDong, string stringShfsYunDongShiJian, string stringSysjcDanGuChun, string stringSysjcXueChangGui, 
+		string stringSysjcXueChangGuiBz, string stringSysjcNiaoChangGui, string stringSysjcNiaoChangGuiBz, string stringSysjcQiTa, string stringYongYao, string stringZhuYuan, 
+		string stringJkwtNaoXueGuan, string stringJkwtNaoXueGuanBz, string stringJkwtShenZang, string stringJkwtShenZangBz, string stringJkwtXinZang, string stringJkwtXinZangBz, 
+		string stringJkwtXueGuan, string stringJkwtXueGuanBz, string stringJkwtYanBu, string stringJkwtYanBuBz, string stringJkwtShenJing, string stringJkwtQiTa, string stringDate);
+	int GetCliniqueListOfHospital(string stringHospitalId);
+	int GetStatisticsInfo(string stringTypeId, string stringMonth, string stringMonthDay, string stringPageTo, string stringPageSize);
+	int UpdateCaseInfo(string stringHospitalId, string stringCaseId, string stringOtherParam, string stringFlag, string stringNotes, string stringReceiverId);
+	int GetUserHealthList(string stringNextId, string stringTypeId, string stringSecondTypeId, string stringName, string stringSex, string strinThirdIdType, 
+		string stringThirdId, string stringHospitalId, string stringUnitSenderId, string stringIsData, string stringIntervalTime, string stringPopulations, string stringContractDoctor, string stringIsContract, string stringPageSize);
+	int GetAdviceImplemention(string stringThirdId, string stringHospitalId);
+	int ChangePersonType(string stringThirdId, string stringPeopleType, string stringHospitalId);
+	int SetNextVisitTime(string stringThirdId, string stringInterViewTime, string stringHospitalId);
+	int GetPersonTypeList(string stringLanguage);
+	int PersonIdRegisterAndLogin(string stringRole, string stringPId, string stringName, string stringSex, string stringBirthday, string stringAddress, string stringDeviceId, string stringMd5, 
+		string stringLang, string stringRegFrom);
+	int CardBindPhone(string stringPhone, string stringScode);
+	int ResetPassword(string stringPhone, string stringScode, string stringNewPwd);
+	int UploadDaily(string stringType, string stringCreateTime, string stringFiles);
+	int GetDateListOfDaily(string stringYear, string stringMonth);
+	int GetDailyOfDate(string stringDate, string stringType);
+	int ShareDaily(string stringType, string stringCreateTime);
+	int DeleteDaily(string stringType, string stringDate);
+	int PhoneScanQR(string stringQRCode);
+	int PhoneScanQRVerify(string stringQRCode);
+	int ApplyQRCode(string stringType, string stringScene);
+	int ValidateUserAccount(string stringLoginId, string stringPassword, string stringRole);
+	int RegisterBluetoothDevice(string stringUniqueSN, string stringSerial, string stringBluetoothAddress, string stringBluetoothName, string stringDeviceType);
+	int GetBluetoothInfoOfDevice(string stringUniqueSN);
+	int ChangeDeviceType(string stringUniqueSN, string stringDeviceType);
+	int UnregisterBluetoothDevice(string stringUniqueSN);
+	int GetHospitalListOfArea(string stringAreaId, string stringRank, string stringBeta);
+	int UploadCommonFileSegment(string stringType, string stringExtra, string stringOrder, string stringTotalSize, 
+		string stringServerUri, string stringStart1, string stringEnd1, string stringMd51, string stringStart2, string stringEnd2, string stringMd52, string stringStart3, string stringEnd3, string stringMd53, string stringFilePath, string stringFileType);
+	int SearchSomebody(string stringUserId);
+	int FollowSomebody(string stringUserId, string stringUsername, string stringNickname, string stringVCode);
+	int MyFollowing(string stringUserId, string stringNextId, string stringFType);
+	int MyFans(string stringUserId, string stringNextId);
+	int ChangeNicknameOfFollowed(string stringUserId, string stringNickname);
+	int CancelFollowing(string stringUserId);
+	int PublishHealthyKnowledge(vector<HEALTHY_KNOWLEDGE> vHealthKnowledge);
+	int GetListOfHealthyKnowledge(string stringSenderId, string stringNextId, string stringIds, string stringPageSize, string stringOrderBy);
+	int GenerateOrDeletePngZlibReport(string stringServerPath, string stringFlag);
+	int GetDailyList(string stringType, string stringStartDate, string stringEndDate, string stringOrderBy, string stringNextId, string stringPageSize);
+
+	int GetCardUserReportList(string stringReportId, string stringReportStartDate, string stringReportEndDate, string stringCaseType, string stringState, string stringOrderBy, 
+		string stringThirdIdType, string stringThirdId, string stringNextId, string stringPageSize);
+	int ChangeViewLikeCollectCount(string stringHealthTipId, string stringUri, string stringTitle, string stringLike, string stringRead, string stringCollect);
+	int ChangeAdviceExecutiveState(string stringSgId, string stringState);
+	int GetTrendRangeValue();
+	int GetCliniqueReportList(string stringCliniqueSenderId, string stringStartDate, 
+		string stringEndDate, string stringState, string stringName, string stringPatientSourceCode, string stringYzlb, string stringPIdType, string stringPId, string stringHb, string stringASectionId, string stringNextId, string stringPageSize);
+	int GetUserListBindingOrNot(string stringNextId, string stringPageSize, string stringIsBind, string stringIsActive);
+	int BindUser(string stringUId, string stringUName);
+	int UnbindUser(string stringUId);
+	int GetCardUserListOfCustomer(string stringThirdId, string stringName, string stringCaseType, string stringStartDate, string stringEndDate, string stringNextId, string stringPageSize);
+	int SearchCaseAdvanced(string stringHospitalId, string stringDiagnostic, 
+		string stringName, string stringSex, QUERY_RANGE rangeAge, QUERY_RANGE rangeCreateTime, string stringMode, 
+		string stringCaseType, QUERY_ECG ecg, string stringFrom, string stringSize);
+	int SearchCaseAdvancedString(string stringHospitalId, string stringDiagnostic, 
+		string stringName, string stringSex, string stringJsonAge, string stringJsonCreateTime, string stringMode, 
+		string stringCaseType, string stringJsonEcg, string stringFrom, string stringSize);
+	int GetPayCode(string stringType, string stringCaseId);
+	int GetOrderInfo(string stringType, string stringCaseId);
+	int SignDoctor(string stringUId);
+	int RefundFee(string stringType, string stringCaseId, string stringRefundFee);
+	int HoldPlaceReview(string stringReportId);
+	int RollBackReview(string stringReportId);
+	int ResetReviewHoldPlace(string stringReportId, string stringOccupantId, string stringOccupantName, string stringSuperKey);
+	int ResetCaseHoldPlace(string stringCaseId, string stringReceiverId, string stringOccupantId, string stringOccupantName, string stringSuperKey);
+	int AddTag(string stringTagName, string stringTagDescription);
+	int GetTagList(string stringSenderId);
+	int AddCaseToTag(string stringTagId, string stringTagName, string stringCaseId, string stringCaseType, string stringCaseTypeName, string stringPatientName);
+	int GetCaseListOfTag(string stringTagId, string stringSenderId, string stringCaseType);
+
+	//冠新接口
+//	int CreateSession_GuanXin(string stringUsername, string stringPassword);
+	int GetAccessToken_GuanXin(string stringUsername, string stringPassword);
+	int GetPersonInfo_GuanXin(string stringAccessToken, string stringPersonName, string stringPersonGender, string stringPersonIdentity, string stringPersonBirthDate);
+	int UploadECGData_GuanXin(string stringECGXmlPath, string stringECGDataPath);
+	int UploadOtherData_GuanXin(string stringOtherXmlPath);
+	int UploadCheckData_GuanXin(string stringCheckXmlPath);
+	int UploadPersonInfo_GuanXin(string stringPersonInfoXmlPath);
+
+
+	//院内使用接口
+	int SetCliniqueState(string stringCliniqueId, string stringState);
+	int GetPatientInfoByAppNum(string stringHospitalId, string stringOrderType, string stringOrderId, string stringReqDepart, string stringOrderState, string stringCheckType, string stringStartDate, string stringEndDate, string stringClinicId);
+	int GetPatientInfoByAppNumToHis(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int GetPatientInfoByAppNumToPhmsAndHis(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int ApplyCheck(string stringCliniqueId, string stringOrderId, string stringOrderType);
+	int GetWaitingCheck(string stringCliniqueId);
+	int GetCliniqueState(string stringCliniqueId);
+	int NotifyCaseState(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int NotifyReportState(string stringReportId);
+	int NotifyAppState(string stringUnitId, string stringOrderId, string stringOrderType, string stringState);
+	int VerifyAppState(string stringOrderId, string stringOrderType);
+	int GetHisReportState(string stringHospitalId, string stringOrderType, string stringOrderId);
+	int SetHisCriticalValue(string stringHospitalId, string stringCaseId, string stringCriticalValues);
+	//第三方组织命令暂时不支持
+
+	//非PHMS协议接口
+	int ExecuteNoPhmsSession(string stringUrl, int bContinue, bool bMustSsl=false);
+	int ExecuteFormHttpSession(string stringHost, string stringUrl, map<string, string> mapParam, bool bMustSsl=false);
+
+	//东亚医讯Xml接口
+	int GetDoctorList_999120(string stringKtCliniqueId, string stringCaseTypeId);
+	int ValidatePay_999120(string stringConsumeId, string stringKtCliniqueId, string stringCardNumber, string stringKtDoctorId, string stringConsumeMoney, string stringCaseTypeId);
+	int UpdateCaseForConsumerRecord_999120(string stringConsumeId, string stringKtCaseId, string stringCaseTypeId);
+
+	//北京心界Xml接口
+	int ValidatePay_XinJie(string stringRrn, string stringLocalDate);
+	int NotifyCheck_XinJie(string stringRrn, string stringLocalDate);
+
+	//电信健康小屋接口
+	int UserAuthorize_Telecom(string stringPersonId, string stringName, string stringNation, string stringAddress, string stringRoomId);
+	int BloodPressureUpload_Telecom(string stringPersonType, string stringPersonId, string stringSBP, string stringDBP, string stringAverageValue, string stringPulseRate, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int BloodOxygenUpload_Telecom(string stringPersonType, string stringPersonId, string stringBloodOxygen, string stringPulseRate, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int BloodSugarUpload_Telecom(string stringPersonType, string stringPersonId, string stringBloodSugar, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int HeightWeightUpload_Telecom(string stringPersonType, string stringPersonId, string stringHeight, string stringWeight, string stringBMI, string stringDetectionTime, 
+		string stringEquCode, string stringRoomId);
+	int LungUpload_Telecom(string stringPersonType, string stringPersonId, string stringM_B1, string stringBSA, string stringBSA1, string stringMMF, string stringMefSeventyFive, string stringMefFifty, 
+		string stringMefTwentyFive, string stringMefFVST, string stringIC, string stringIRV, string stringERV, string stringFevOne, string stringFevTwo, string stringFevThree, 
+		string stringFevOnePer, string stringFevTwoPer, string stringFevThreePer, string stringRR, string stringFVC, string stringPEF, string stringTV, string stringVC, string stringMVV, 
+		string stringMV, string stringVSTHeight, string stringVSMvvBsa, string stringVSMvvOne, string stringSVC, string stringFevOneZeroFive, string stringFevOneZeroFivePer, string stringPefOne, 
+		string stringPefTwo, string stringPefThree, string stringFive, string stringFiveOne, string stringFiveTwo, string stringFiveThree, string stringPIF, string stringMifFifty, 
+		string stringDetectionTime, string stringEquCode, string stringRoomId);
+	int ECGUpload_Telecom(string stringPersonType, string stringPersonId, string stringDetectionTime, string stringEquCode, string stringRoomId, TELCOM_ECG ecgData);
+
+	//东软熙康定制软件接口
+	int GetToken_XiKang();
+	int Login_XiKang(string stringUsername, string stringPassword);
+	int RegisterPatientId_XiKang(string stringName, string stringSex, string stringPhoneNum, string stringProofNum);
+	int RegisterPatientInfo_XiKang(string stringPatientOpenId, string stringName, string stringSex, string stringPhoneNum, string stringProofNum, string stringPassword);
+	int BindPatient_XiKang(string stringDoctorOpenId, string stringPatientOpenId);
+	int GetPatientIdList_XiKang(string stringDoctorOpenId);
+	int SearchPatientId_XiKang(string stringKey, string stringValue);
+	int GetPatientInfo_XiKang(string stringPatientOpenId);
+	int GetCaseList_XiKang(vector<string> vPatientOpenId);
+	int SubmitCase_XiKang(string stringPatientOpenId, string stringAdvice, string stringCaseType, string stringEcgXmlContent);
+	int GetReportFile_XiKang(string stringCaseId);
+	int UploadFile_XiKang(string stringCaseId, string stringCaseFilePath);
+
+	//公卫系统接口
+	int ExecuteGWService(string stringLastPath, map<string, string> mapParam, string stringFilePath, bool bMustSsl=false);
+	int ExecuteCommonRESTful(string stringIp, string stringPort, string stringUrl, string stringContentType, string stringPayload);
+};

+ 43 - 0
PushBase.cpp

@@ -0,0 +1,43 @@
+#include "PushBase.h"
+#include "Poco/Thread.h"
+
+CPushBase::CPushBase(pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback, int nPushType):m_pHttpPushCallback(pCallback), m_pHttpPushFailCallback(pFailCallback), m_nPushType(nPushType), m_bStopRetry(false), m_pPhmsPushSession(NULL)
+{
+	m_pPhmsPushSession = new CPhmsPushSession;//¿ÉÄÜÅ×Òì³£
+	m_threadPush.start(*this);
+}
+
+CPushBase::~CPushBase(void)
+{
+}
+
+void CPushBase::run()
+{
+	Poco::Thread::sleep(3000*2);
+	ExecutePushSession();
+	return;
+}
+
+void CPushBase::EndPush()
+{
+	m_bStopRetry = true;
+	m_pPhmsPushSession->abort();
+	m_threadPush.join();
+	delete m_pPhmsPushSession;
+	m_pPhmsPushSession = NULL;
+}
+
+string CPushBase::GetSessionId()
+{
+	return m_pPhmsPushSession->GetSessionId();
+}
+
+void CPushBase::SetSessionId(string stringSessionId)
+{
+	return m_pPhmsPushSession->SetSessionId(stringSessionId);
+}
+
+int CPushBase::GetPushType()
+{
+	return m_nPushType;
+}

+ 31 - 0
PushBase.h

@@ -0,0 +1,31 @@
+#pragma once
+#include "PhmsDataType.h"
+#include "Poco/Thread.h"
+#include "Poco/Runnable.h"
+#include "PhmsPushSession.h"
+
+using Poco::Thread;
+using Poco::Runnable;
+
+#define MSG_LIST_PUSH	(0)
+class CPushBase:public Runnable
+{
+public:
+	CPushBase(pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback, int nPushType);
+	virtual ~CPushBase(void);
+	void run();
+	void EndPush();
+	string GetSessionId();
+	void SetSessionId(string stringSessionId);
+	int GetPushType();
+protected:
+	virtual void ExecutePushSession()=0;
+protected:
+	pHttpPushCallback m_pHttpPushCallback;
+	pHttpPushFailCallback m_pHttpPushFailCallback;
+	CPhmsPushSession* m_pPhmsPushSession;
+	bool m_bStopRetry;
+private:
+	Thread m_threadPush;
+	int m_nPushType;
+};

+ 144 - 0
PushObjectManager.cpp

@@ -0,0 +1,144 @@
+#include "PushObjectManager.h"
+#include "AllObjectManagerUtil.h"
+#include "ErrorCode.h"
+#include "Poco/Exception.h"
+#include "Util.h"
+#include "PhmsLogger.h"
+#include "MsgListPush.h"
+
+using Poco::FileNotFoundException;
+
+map<string, CPushBase*> CPushObjectManager::m_map;
+
+int CPushObjectManager::InsertPushMsgListObject(string stringUuid, string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgType, string stringMsgDirection, string stringVersion, 
+												pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	CPushBase* pNetInterface = NULL;
+	try
+	{
+		pNetInterface = new CMsgListPush(stringUuid, stringSenderId, stringCaseId, stringCaseType, stringMsgType, stringMsgDirection, stringVersion, pCallback, pFailCallback);
+	}
+	catch(FileNotFoundException& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_NET_CONFIG_FILE), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NO_NET_CONFIG_FILE;
+	}
+	catch(Exception& e)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(e, __FUNCTION__, __FILE__, __LINE__);
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NET_CONFIG_READ_ERROR), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NET_CONFIG_READ_ERROR;
+	}
+	m_map.insert(map<string, CPushBase*>::value_type(stringUuid, pNetInterface));
+	string stringSessionId;
+	if(CNetThreadManager::m_map.size() != 0)
+	{
+		map<string, CExternalNetInterface*>::const_iterator iter;
+		for(iter=CNetThreadManager::m_map.begin(); iter!=CNetThreadManager::m_map.end(); iter++)
+		{
+			if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
+			{
+				stringSessionId = iter->second->GetSessionId();
+				pNetInterface->SetSessionId(stringSessionId);
+				break;
+			}
+		}
+	}
+	else
+	{
+		map<string, CPushBase*>::const_iterator iter;
+		for(iter=CPushObjectManager::m_map.begin(); iter!=CPushObjectManager::m_map.end(); iter++)
+		{
+			if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
+			{
+				stringSessionId = iter->second->GetSessionId();
+				pNetInterface->SetSessionId(stringSessionId);
+				break;
+			}
+		}
+	}
+	if(stringSessionId.size() == 0)
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_VALID_SESSIONID), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NO_VALID_SESSIONID;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+
+int CPushObjectManager::DeletePushObject(string stringUuid)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	CPushBase* pNetInterface = NULL;
+	if(m_map.find(stringUuid) != m_map.end())
+	{
+		pNetInterface = m_map[stringUuid];
+	}
+	if(pNetInterface != NULL)
+	{
+		pNetInterface->EndPush();
+		m_map.erase(stringUuid);
+		delete pNetInterface;
+		return PHMS_SUCCESSFUL_RESULT;
+	}
+	else
+	{
+		return COMMON_INVALID_HANDLE;
+	}
+
+}
+
+
+int CPushObjectManager::GetSessionId(string& stringSessionId)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	map<string, CPushBase*>::const_iterator iter;
+	for(iter=m_map.begin(); iter!=m_map.end(); iter++)
+	{
+		if(iter->second->GetSessionId().size()!=0 && iter->second->GetSessionId()!="00000000000000000000000000000000")
+		{
+			stringSessionId = iter->second->GetSessionId();
+			break;
+		}
+	}
+	if(iter == m_map.end())
+	{
+		CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_VALID_SESSIONID), __FUNCTION__, __FILE__, __LINE__);
+		return COMMON_NO_VALID_SESSIONID;
+	}
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CPushObjectManager::SetSessionId(string stringSessionId)
+{
+	HandleSessionSync(stringSessionId);
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+
+void CPushObjectManager::HandleSessionSync(string stringSessionId)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	map<string, CPushBase*>::iterator iter;
+	for(iter=m_map.begin(); iter!=m_map.end(); iter++)
+	{
+		iter->second->SetSessionId(stringSessionId);
+	}
+	return;
+}
+
+bool CPushObjectManager::SomeTypePushIsRun(int nPushType)
+{
+	Mutex::ScopedLock lock(CAllObjectManagerUtil::m_mutex);
+	map<string, CPushBase*>::iterator iter;
+	for(iter=m_map.begin(); iter!=m_map.end(); iter++)
+	{
+		if(iter->second->GetPushType() == nPushType)
+		{
+			return true;
+		}
+	}
+	return false;
+}

+ 17 - 0
PushObjectManager.h

@@ -0,0 +1,17 @@
+#pragma once
+#include <map>
+#include "PushBase.h"
+
+class CPushObjectManager
+{
+public:
+	static int InsertPushMsgListObject(string stringUuid, string stringSenderId, string stringCaseId, string stringCaseType, string stringMsgType, string stringMsgDirection, string stringVersion, 
+		pHttpPushCallback pCallback, pHttpPushFailCallback pFailCallback);
+	static int DeletePushObject(string);
+	static void HandleSessionSync(string stringSessionId);
+	static bool SomeTypePushIsRun(int nPushType);
+	static int GetSessionId(string&);
+	static int SetSessionId(string);
+public:
+	static map<string, CPushBase*> m_map;
+};

+ 51 - 0
SessionIdManager.cpp

@@ -0,0 +1,51 @@
+#include "SessionIdManager.h"
+#include "ExternalNetInterface.h"
+#include "ErrorCode.h"
+#include "NetThreadManager.h"
+#include "PushObjectManager.h"
+
+
+
+int CSessionIdManager::SetSessionId(string stringSessionId)
+{
+	CNetThreadManager::SetSessionId(stringSessionId);
+	CPushObjectManager::SetSessionId(stringSessionId);
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+
+
+int CSessionIdManager::GetSessionId(string& stringSessionId)
+{
+	int nRet = PHMS_SUCCESSFUL_RESULT;
+	nRet = CNetThreadManager::GetSessionId(stringSessionId);
+	if(nRet == COMMON_NO_VALID_SESSIONID)
+	{
+		return nRet=CPushObjectManager::GetSessionId(stringSessionId);
+	}
+	return nRet;
+}
+
+
+void CSessionIdManager::HandleSessionSync(string stringSessionId)
+{
+	CNetThreadManager::HandleSessionSync(stringSessionId);
+	CPushObjectManager::HandleSessionSync(stringSessionId);
+}
+
+
+int CSessionIdManager::SetGWSessionId(string stringSessionId)
+{
+	CNetThreadManager::SetGWSessionId(stringSessionId);
+	return PHMS_SUCCESSFUL_RESULT;
+}
+
+int CSessionIdManager::GetGWSessionId(string& stringSessionId)
+{
+	return CNetThreadManager::GetGWSessionId(stringSessionId);
+}
+
+void CSessionIdManager::HandleGWSessionSync(string stringSessionId)
+{
+	CNetThreadManager::HandleGWSessionSync(stringSessionId);
+}

+ 16 - 0
SessionIdManager.h

@@ -0,0 +1,16 @@
+#pragma once
+#include "PhmsDataType.h"
+#include <string>
+
+using namespace::std;
+class CSessionIdManager
+{
+public:
+	static int SetSessionId(string stringSessionId);
+	static int GetSessionId(string& stringSessionId);
+	static void HandleSessionSync(string stringSessionId);
+
+	static int SetGWSessionId(string stringSessionId);
+	static int GetGWSessionId(string& stringSessionId);
+	static void HandleGWSessionSync(string stringSessionId);
+};

+ 151 - 0
TelecomHealthInterface.cpp

@@ -0,0 +1,151 @@
+#define PHMS_DLL_EXPORTS
+#include "TelecomHealthInterface.h"
+#include "ExternalNetInterface.h"
+#include "ErrorCode.h"
+#include <map>
+#include <string>
+#include "NetThreadManager.h"
+
+using namespace std;
+
+int UserAuthorize_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonId, const char* stringName, const char* stringNation, const char* stringAddress, const char* stringRoomId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringPersonId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->UserAuthorize_Telecom(stringLocalFilePath, stringPersonId, stringName, stringNation, stringAddress, stringRoomId);
+}
+
+int BloodPressureUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringSBP, const char* stringDBP, const char* stringAverageValue, const char* stringPulseRate, const char* stringDetectionTime, 
+								const char* stringEquCode, const char* stringRoomId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringPersonId==NULL || stringSBP==NULL || stringDBP==NULL || stringAverageValue==NULL || stringPulseRate==NULL || stringDetectionTime==NULL || stringEquCode==NULL || stringRoomId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->BloodPressureUpload_Telecom(stringLocalFilePath, stringPersonType, stringPersonId, stringSBP, stringDBP, stringAverageValue, stringPulseRate, stringDetectionTime, stringEquCode, stringRoomId);
+}
+
+int BloodOxygenUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringBloodOxygen, const char* stringPulseRate, const char* stringDetectionTime, 
+									  const char* stringEquCode, const char* stringRoomId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringPersonId==NULL || stringBloodOxygen==NULL || stringPulseRate==NULL || stringDetectionTime==NULL || stringEquCode==NULL || stringRoomId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->BloodOxygenUpload_Telecom(stringLocalFilePath, stringPersonType, stringPersonId, stringBloodOxygen, stringPulseRate, stringDetectionTime, stringEquCode, stringRoomId);
+}
+
+int BloodSugarUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringBloodSugar, const char* stringDetectionTime, 
+									 const char* stringEquCode, const char* stringRoomId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringPersonId==NULL || stringBloodSugar==NULL || stringDetectionTime==NULL || stringEquCode==NULL || stringRoomId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->BloodSugarUpload_Telecom(stringLocalFilePath, stringPersonType, stringPersonId, stringBloodSugar, stringDetectionTime, stringEquCode, stringRoomId);
+}
+
+int HeightWeightUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringHeight, const char* stringWeight, const char* stringBMI, const char* stringDetectionTime, 
+							 const char* stringEquCode, const char* stringRoomId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringPersonId==NULL || stringHeight==NULL || stringWeight==NULL || stringBMI==NULL || stringDetectionTime==NULL || stringEquCode==NULL || stringRoomId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->HeightWeightUpload_Telecom(stringLocalFilePath, stringPersonType, stringPersonId, stringHeight, stringWeight, stringBMI, stringDetectionTime, stringEquCode, stringRoomId);
+}
+
+
+int LungUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringM_B1, const char* stringBSA, const char* stringBSA1, const char* stringMMF, const char* stringMefSeventyFive, const char* stringMefFifty, 
+							   const char* stringMefTwentyFive, const char* stringMefFVST, const char* stringIC, const char* stringIRV, const char* stringERV, const char* stringFevOne, const char* stringFevTwo, const char* stringFevThree, 
+							   const char* stringFevOnePer, const char* stringFevTwoPer, const char* stringFevThreePer, const char* stringRR, const char* stringFVC, const char* stringPEF, const char* stringTV, const char* stringVC, const char* stringMVV, 
+							   const char* stringMV, const char* stringVSTHeight, const char* stringVSMvvBsa, const char* stringVSMvvOne, const char* stringSVC, const char* stringFevOneZeroFive, const char* stringFevOneZeroFivePer, const char* stringPefOne, 
+							   const char* stringPefTwo, const char* stringPefThree, const char* stringFive, const char* stringFiveOne, const char* stringFiveTwo, const char* stringFiveThree, const char* stringPIF, const char* stringMifFifty, 
+							   const char* stringDetectionTime, const char* stringEquCode, const char* stringRoomId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringPersonId==NULL || stringM_B1==NULL || stringBSA==NULL || stringBSA1==NULL || stringMMF==NULL || stringMefSeventyFive==NULL || stringMefFifty==NULL || stringMefTwentyFive==NULL || 
+		stringMefFVST==NULL || stringIC==NULL || stringIRV==NULL || stringERV==NULL || stringFevOne==NULL || stringFevTwo==NULL || stringFevThree==NULL || stringFevOnePer==NULL || stringFevTwoPer==NULL || stringFevThreePer==NULL || 
+		stringRR==NULL || stringFVC==NULL || stringPEF==NULL || stringTV==NULL || stringVC==NULL || stringMVV==NULL || stringMV==NULL || stringVSTHeight==NULL || stringVSMvvBsa==NULL || stringVSMvvOne==NULL || stringSVC==NULL || 
+		stringFevOneZeroFive==NULL || stringFevOneZeroFivePer==NULL || stringPefOne==NULL || stringPefTwo==NULL || stringPefThree==NULL || stringFive==NULL || stringFiveOne==NULL || stringFiveTwo==NULL || stringFiveThree==NULL || 
+		stringPIF==NULL || stringMifFifty==NULL || stringDetectionTime==NULL || stringEquCode==NULL || stringRoomId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->LungUpload_Telecom(stringLocalFilePath, stringPersonType, stringPersonId, stringM_B1, stringBSA, stringBSA1, stringMMF, stringMefSeventyFive, stringMefFifty, stringMefTwentyFive, stringMefFVST, stringIC, 
+		stringIRV, stringERV, stringFevOne, stringFevTwo, stringFevThree, stringFevOnePer, stringFevTwoPer, stringFevThreePer, stringRR, stringFVC, stringPEF, stringTV, stringVC, stringMVV, stringMV, 
+		stringVSTHeight, stringVSMvvBsa, stringVSMvvOne, stringSVC, stringFevOneZeroFive, stringFevOneZeroFivePer, stringPefOne, stringPefTwo, stringPefThree, stringFive, stringFiveOne, stringFiveTwo, stringFiveThree, 
+		stringPIF, stringMifFifty, stringDetectionTime, stringEquCode, stringRoomId);
+}
+
+
+int ECGUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringDetectionTime, 
+							  const char* stringEquCode, const char* stringRoomId, TELCOM_ECG ecgData)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringPersonId==NULL || stringDetectionTime==NULL || stringEquCode==NULL || stringRoomId==NULL || 
+		ecgData.pArrayData==NULL || ecgData.adRate==NULL || ecgData.adAccuracy==NULL || ecgData.rangeMin==NULL || ecgData.rangeMax==NULL || ecgData.heartValue==NULL || 
+		ecgData.stLevel==NULL || ecgData.prInterval==NULL || ecgData.qtInterval==NULL || ecgData.rrInterval==NULL || ecgData.pWave==NULL || ecgData.rWave==NULL || 
+		ecgData.tWave==NULL || ecgData.result1==NULL || ecgData.result2==NULL || ecgData.result3==NULL || ecgData.result4==NULL || ecgData.result5==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->ECGUpload_Telecom(stringLocalFilePath, stringPersonType, stringPersonId, stringDetectionTime, stringEquCode, stringRoomId, ecgData);
+}
+

+ 213 - 0
TelecomHealthInterface.h

@@ -0,0 +1,213 @@
+#ifndef PHMS_TELECOM_HEALTH_INTERFACE
+#define PHMS_TELECOM_HEALTH_INTERFACE
+#include "PhmsDataType.h"
+
+
+
+#if defined(_WIN32) || defined(_WIN32_WCE)
+#if defined(PHMS_DLL_EXPORTS)
+#define NET_API __declspec(dllexport)
+#else
+#define NET_API __declspec(dllimport)	
+#endif
+#endif
+
+
+#if !defined(NET_API)
+#define NET_API
+#endif
+
+
+
+#ifdef __cplusplus 
+extern "C" { 
+#endif 
+
+//==================================================================
+//函数名:UserAuthorize_Telecom
+//作者:YangJiannan
+//日期:2015.6.3
+//功能:验证身份证
+//输入参数:handle					网络对象句柄		
+//			stringLocalFilePath		本地文件路径保存
+//			stringPersonId			身份证号
+//			stringName				姓名
+//			stringNation			民族
+//			stringAddress			地址
+//			stringRoomId			健康小屋号
+//返回值: 正常或错误返回码
+//使用范围:电信健康小屋设备集成软件
+//修改记录:
+//==================================================================
+int NET_API UserAuthorize_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonId, const char* stringName, const char* stringNation, const char* stringAddress, const char* stringRoomId);
+
+
+//==================================================================
+//函数名:BloodPressureUpload_Telecom
+//作者:YangJiannan
+//日期:2015.6.3
+//功能:上传血压数据
+//输入参数:handle					网络对象句柄		
+//			stringLocalFilePath		本地文件路径保存
+//			stringPersonType		用户身份类型
+//			stringPersonId			用户身份ID
+//			stringSBP				收缩压
+//			stringDBP				舒张压
+//			stringAverageValue		平均压
+//			stringPulseRate			脉率
+//			stringDetectionTime		检查时间
+//			stringEquCode			设备编号
+//			stringRoomId			房间编号
+//返回值: 正常或错误返回码
+//使用范围:电信健康小屋设备集成软件
+//修改记录:
+//==================================================================
+int NET_API BloodPressureUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringSBP, const char* stringDBP, const char* stringAverageValue, const char* stringPulseRate, const char* stringDetectionTime, 
+								const char* stringEquCode, const char* stringRoomId);
+
+
+//==================================================================
+//函数名:BloodOxygenUpload_Telecom
+//作者:YangJiannan
+//日期:2015.6.3
+//功能:上传血氧数据
+//输入参数:handle					网络对象句柄		
+//			stringLocalFilePath		本地文件路径保存
+//			stringPersonType		用户身份类型
+//			stringPersonId			身份证号
+//			stringBloodOxygen		血氧值
+//			stringPulseRate			脉率
+//			stringDetectionTime		检查时间
+//			stringEquCode			设备编号
+//			stringRoomId			房间编号
+//返回值: 正常或错误返回码
+//使用范围:电信健康小屋设备集成软件
+//修改记录:
+//==================================================================
+int NET_API BloodOxygenUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringBloodOxygen, const char* stringPulseRate, const char* stringDetectionTime, 
+							  const char* stringEquCode, const char* stringRoomId);
+
+
+//==================================================================
+//函数名:BloodSugarUpload_Telecom
+//作者:YangJiannan
+//日期:2015.6.3
+//功能:上传血糖数据
+//输入参数:handle					网络对象句柄		
+//			stringLocalFilePath		本地文件路径保存
+//			stringPersonType		用户身份类型
+//			stringPersonId			身份证号
+//			stringBloodSugar		血糖值
+//			stringDetectionTime		检查时间
+//			stringEquCode			设备编号
+//			stringRoomId			房间编号
+//返回值: 正常或错误返回码
+//使用范围:电信健康小屋设备集成软件
+//修改记录:
+//==================================================================
+int NET_API BloodSugarUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringBloodSugar, const char* stringDetectionTime, 
+							 const char* stringEquCode, const char* stringRoomId);
+
+
+//==================================================================
+//函数名:HeightWeightUpload_Telecom
+//作者:YangJiannan
+//日期:2015.6.3
+//功能:上传身高体重数据
+//输入参数:handle					网络对象句柄		
+//			stringLocalFilePath		本地文件路径保存
+//			stringPersonType		用户身份类型
+//			stringPersonId			身份证号
+//			stringHeight			身高
+//			stringWeight			体重
+//			stirngBMI				BMI
+//			stringDetectionTime		检查时间
+//			stringEquCode			设备编号
+//			stringRoomId			房间编号
+//返回值: 正常或错误返回码
+//使用范围:电信健康小屋设备集成软件
+//修改记录:
+//==================================================================
+int NET_API HeightWeightUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringHeight, const char* stringWeight, const char* stringBMI, const char* stringDetectionTime, 
+							   const char* stringEquCode, const char* stringRoomId);
+
+
+
+
+//==================================================================
+//函数名:HeightWeightUpload_Telecom
+//作者:YangJiannan
+//日期:2015.6.3
+//功能:上传肺功能数据
+//输入参数:handle					网络对象句柄		
+//			stringLocalFilePath		本地文件路径保存
+//			stringPersonType		用户身份类型
+//			stringPersonId			身份证号
+//			stringM_B1				M/B1
+//			stringBSA				体表面积
+//			stringBSA1				BSA1
+//			stringMMF				最大呼气中段流速 
+//			stringMefSeventyFive	呼气至 75%时肺活量对应流速值 
+//			stringMefFifty			呼气至 50%时肺活量对应流速值
+//			stringMefTwentyFive		呼气至 25%时肺活量对应流速值
+//			stringMefFVST			呼气至 50%25%肺活量时对应比
+//			stringIC				深吸气量 
+//			stringIRV				补吸气量 
+//			stringERV				补呼气量 
+//			stringFevOne			1 秒钟肺活量 
+//			stringFevTwo			2 秒钟肺活量 
+//			stringFevThree			3 秒钟肺活量 
+//			stringFevOnePer			1 秒钟肺活量百分比 
+//			stringFevTwoPer			2 秒钟肺活量百分比 
+//			stringFevThreePer		3 秒钟肺活量百分比 
+//			stringRR				呼吸频率 
+//			stringFVC				用力肺活量 
+//			stringPEF				峰值流量 
+//			stringTV				潮气量 
+//			stringVC				实测肺活量 
+//			stringMVV				实测最大通气量 
+//			stringMV				静息通气量 
+//			stringVSTHeight			V25 与身高之比 
+//			stringVSMvvBsa			实测最大通气量与体表面积之比 
+//			stringVSMvvOne			最大通气量/1 秒量 
+//			stringDetectionTime		检查时间
+//			stringEquCode			设备编号
+//			stringRoomId			房间编号
+//返回值: 正常或错误返回码
+//使用范围:电信健康小屋设备集成软件
+//修改记录:
+//==================================================================
+int NET_API LungUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringM_B1, const char* stringBSA, const char* stringBSA1, const char* stringMMF, const char* stringMefSeventyFive, const char* stringMefFifty, 
+					   const char* stringMefTwentyFive, const char* stringMefFVST, const char* stringIC, const char* stringIRV, const char* stringERV, const char* stringFevOne, const char* stringFevTwo, const char* stringFevThree, 
+					   const char* stringFevOnePer, const char* stringFevTwoPer, const char* stringFevThreePer, const char* stringRR, const char* stringFVC, const char* stringPEF, const char* stringTV, const char* stringVC, const char* stringMVV, 
+					   const char* stringMV, const char* stringVSTHeight, const char* stringVSMvvBsa, const char* stringVSMvvOne, const char* stringSVC, const char* stringFevOneZeroFive, const char* stringFevOneZeroFivePer, const char* stringPefOne, 
+					   const char* stringPefTwo, const char* stringPefThree, const char* stringFive, const char* stringFiveOne, const char* stringFiveTwo, const char* stringFiveThree, const char* stringPIF, const char* stringMifFifty, 
+					   const char* stringDetectionTime, const char* stringEquCode, const char* stringRoomId);
+
+
+//==================================================================
+//函数名:ECGUpload_Telecom
+//作者:YangJiannan
+//日期:2015.8.6
+//功能:上传心电数据
+//输入参数:handle					网络对象句柄		
+//			stringLocalFilePath		本地文件路径保存
+//			stringPersonType		用户身份类型
+//			stringPersonId			身份证号
+//			stringDetectionTime		检查时间
+//			stringEquCode			设备编号
+//			stringRoomId			房间编号
+//			ECGData					心电数据
+//返回值: 正常或错误返回码
+//使用范围:电信健康小屋设备集成软件
+//修改记录:
+//==================================================================
+int NET_API ECGUpload_Telecom(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringPersonType, const char* stringPersonId, const char* stringDetectionTime, 
+									   const char* stringEquCode, const char* stringRoomId, TELCOM_ECG ecgData);
+
+
+#ifdef __cplusplus 
+} 
+#endif 
+
+#endif

+ 59 - 0
UploadTimerCallback.cpp

@@ -0,0 +1,59 @@
+#include "UploadTimerCallback.h"
+#include "Util.h"
+#include "Poco/Util/IniFileConfiguration.h"
+#include "Poco/AutoPtr.h"
+
+using Poco::Util::IniFileConfiguration;
+using Poco::AutoPtr;
+
+
+CUploadTimerCallback::CUploadTimerCallback(pProgressAndSpeedCallback pCallback, string stringIniFilePath, unsigned long nAlreadyUploadSize, unsigned long nTotalSize, string stringLocalFilePath)
+:m_pCallback(pCallback), m_stringIniFilePath(stringIniFilePath), m_nCurrentUploadFileSize(nAlreadyUploadSize), 
+ m_nPreUploadFileSize(nAlreadyUploadSize), m_nTotalSize(nTotalSize), m_stringLocalFilePath(stringLocalFilePath), m_nSeconds(0)
+{
+}
+
+CUploadTimerCallback::~CUploadTimerCallback(void)
+{
+}
+
+
+void CUploadTimerCallback::onTimer(Timer& timer)
+{
+	m_nSeconds++;
+	AutoPtr<IniFileConfiguration> iniFile = new IniFileConfiguration(m_stringIniFilePath, "gbk");
+	m_nCurrentUploadFileSize = CUtil::StringToULong(iniFile->getString("ALREADY_UPLOAD_SIZE", "0"));
+	//¼ÆËã½ø¶È
+	double dProgress = 0.0;
+	if(m_nCurrentUploadFileSize <= m_nTotalSize)
+	{
+		dProgress = ((double)(m_nCurrentUploadFileSize))/m_nTotalSize*100;
+	}
+	else
+	{
+		dProgress = 100.0;
+	}
+	//¼ÆËãËÙ¶È
+	static double dSpeed = 0.0;
+	long nInterval = 1000;
+// 	if(timer.getPeriodicInterval() == 0)
+// 	{
+// 		nInterval = 1000;
+// 	}
+// 	else
+// 	{
+// 		nInterval = timer.getPeriodicInterval();
+// 	}
+	unsigned long nTimeCount = m_nSeconds*nInterval/1000;
+	if(m_nCurrentUploadFileSize>m_nPreUploadFileSize && nTimeCount!=0)
+	{
+		dSpeed = (m_nCurrentUploadFileSize-m_nPreUploadFileSize)/nTimeCount;
+		m_nPreUploadFileSize = m_nCurrentUploadFileSize;
+		m_nSeconds = 0;
+	}
+	if(m_pCallback != NULL)
+	{
+		m_pCallback(dProgress, dSpeed, "", m_stringLocalFilePath.c_str());
+	}
+	return;
+}

+ 24 - 0
UploadTimerCallback.h

@@ -0,0 +1,24 @@
+#pragma once
+#include "Poco/Timer.h"
+#include "PhmsDataType.h"
+#include <string>
+
+using Poco::Timer;
+using namespace std;
+
+class CUploadTimerCallback
+{
+public:
+	CUploadTimerCallback(pProgressAndSpeedCallback pCallback, string stringIniFilePath, unsigned long nAlreadyUploadSize, unsigned long nTotalSize, string stringLocalFilePath);
+	~CUploadTimerCallback(void);
+private:
+	pProgressAndSpeedCallback m_pCallback;
+	string m_stringIniFilePath;
+	unsigned long m_nCurrentUploadFileSize;
+	unsigned long m_nPreUploadFileSize;
+	unsigned long m_nTotalSize;
+	string m_stringLocalFilePath;
+	int m_nSeconds;
+public:
+	void onTimer(Timer& timer); 
+};

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1348 - 0
UserNetInterface.cpp


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1175 - 0
UserNetInterface.h


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1100 - 0
Util.cpp


+ 48 - 0
Util.h

@@ -0,0 +1,48 @@
+#pragma once
+#include <string>
+#include <vector>
+#include <map>
+using std::string;
+using std::vector;
+using std::map;
+#include "Poco/Types.h"
+
+
+class CUtil
+{
+public:
+	static string& Ltrim(string &str);
+	static string& Rtrim(string &str);
+	static string& Trim(string &str);
+	static string DoubleToString(long double dValue, int decplaces=6);
+	static string ULongToString(unsigned long nValue);
+	static unsigned long StringToULong(string stringValue);
+	static string UIntToString(unsigned int nValue);
+	static string Int64ToString(Poco::Int64 nValue);
+	static string GetMd5(const char* bufSrc, int nLength);
+	static int GetMd5(string stringFilePath, string& stringMd5);
+	static int GetFileSize(string stringFilePath, unsigned long& nFileSize);
+	static unsigned long GetFileSize(string stringFilePath);
+	static int GetXmlFieldVaule(int nSaveType, string stringXmlContent, string stringXmlPath, string stringField, string& stringVaule);
+	static int GetOrReplaceImagePathVector(int nSaveType, string stringXmlContent, string stringXmlPath, vector<string>& vImagePath);//不再处理Replace
+	static int GetMapFromRequestXml(string stringXmlContent, string stringKey, map<string, string>& mapParam);
+	static string GetErrorMsg(int nError);
+	static int GBKToUTF8(string stringGbk, string& stringUtf8);
+	static int UTF8ToGBK(string stringUtf8, string& stringGBK);
+	static int EnvToUtf8(string stringEnv, string& stringUtf8);
+	static string EnvToUtf8(string stringEnv);
+	static int UTF8ToEnv(string stringUtf8, string& stringEnv);
+	static string GetCurrentAppDir();
+	static bool IsLegalGBK(string stringSrc);
+	static bool IsLegalKOI8R(string stringSrc);
+	static bool IsLegalUTF8(string stringSrc);
+	static void SetAppDir(string stringWorkDir);//用于Android外部设置工作目录
+	static void ReplaceStringInFile(string stringPath, string stringSrc, string stringDst);
+	static void ReplaceString(string& stringContent, string stringSrc, string stringDst);//替换源字符串中的所有stringSrc,而非第一个
+	static string GetFileNameFromPath(string stringPath);
+	static void ParseJsonObjectWithoutArray(int nSaveType, string stringJsonContent, string stringJsonPath, map<string, string>& mapResult);
+	static string MapToJson(map<string, string> mapParam);
+	static int ParseStandardQueryString(string stringQuery, string& stringId, string& stringIdType);
+private:
+	static string m_stringAppDir;
+};

+ 309 - 0
WithinHospitalNetInterface.cpp

@@ -0,0 +1,309 @@
+#define PHMS_DLL_EXPORTS
+#include "WithinHospitalNetInterface.h"
+#include "ExternalNetInterface.h"
+#include "ErrorCode.h"
+#include <map>
+#include <string>
+#include "NetThreadManager.h"
+
+using namespace std;
+
+
+int SetCliniqueBusy(NET_HANDLE handle, const char* stringCliniqueId)
+{
+	if(handle==NULL || stringCliniqueId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->SetCliniqueBusy(stringCliniqueId);
+}
+
+
+int SetCliniqueFree(NET_HANDLE handle, const char* stringCliniqueId)
+{
+	if(handle==NULL || stringCliniqueId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->SetCliniqueFree(stringCliniqueId);
+}
+
+
+int NET_API SetCliniqueChecking(NET_HANDLE handle, const char* stringCliniqueId)
+{
+	if(handle==NULL || stringCliniqueId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->SetCliniqueChecking(stringCliniqueId);
+}
+
+
+int NET_API SetCliniqueShoutComplete(NET_HANDLE handle, const char* stringCliniqueId)
+{
+	if(handle==NULL || stringCliniqueId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->SetCliniqueShoutComplete(stringCliniqueId);
+}
+
+
+
+int GetPatientInfoByAppNum(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId, 
+								   const char* stringReqDepart, const char* stringOrderState, const char* stringCheckType, const char* stringStartDate, const char* stringEndDate,const char* stringClinicId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringHospitalId==NULL || stringOrderType==NULL || stringOrderId==NULL || stringReqDepart==NULL || stringOrderState==NULL || 
+		stringCheckType==NULL || stringStartDate==NULL || stringEndDate==NULL || stringClinicId == NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetPatientInfoByAppNum(stringLocalFilePath, stringHospitalId, stringOrderType, stringOrderId, stringReqDepart, stringOrderState, stringCheckType, stringStartDate, stringEndDate,stringClinicId);
+}
+
+int GetPatientInfoByAppNumToHis(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringHospitalId==NULL || stringOrderType==NULL || stringOrderId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetPatientInfoByAppNumToHis(stringLocalFilePath, stringHospitalId, stringOrderType, stringOrderId);
+}
+
+int GetPatientInfoByAppNumToPhmsAndHis(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringHospitalId==NULL || stringOrderType==NULL || stringOrderId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetPatientInfoByAppNumToPhmsAndHis(stringLocalFilePath, stringHospitalId, stringOrderType, stringOrderId);
+}
+
+
+int ApplyCheck(NET_HANDLE handle, const char* stringCliniqueId, const char* stringOrderId, const char* stringOrderType)
+{
+	if(handle==NULL || stringCliniqueId==NULL || stringOrderType==NULL || stringOrderId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->ApplyCheck(stringCliniqueId, stringOrderId, stringOrderType);
+}
+
+
+int GetWaitingCheck(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCliniqueId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringCliniqueId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetWaitingCheck(stringLocalFilePath, stringCliniqueId);
+}
+
+
+int GetCliniqueState(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCliniqueId)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringCliniqueId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetCliniqueState(stringLocalFilePath, stringCliniqueId);
+}
+
+int NotifyCaseState(NET_HANDLE handle, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId)
+{
+	if(handle==NULL || stringHospitalId==NULL || stringOrderType==NULL || stringOrderId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->NotifyCaseState(stringHospitalId, stringOrderType, stringOrderId);
+}
+
+int NotifyReportState(NET_HANDLE handle, const char* stringReportId)
+{
+	if(handle==NULL || stringReportId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->NotifyReportState(stringReportId);
+}
+
+int SetDoctorAgentId(NET_HANDLE handle, const char* stringDoctorAgentId)
+{
+	if(handle==NULL || stringDoctorAgentId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->SetDoctorAgentId(stringDoctorAgentId);
+}
+
+int NotifyAppState(NET_HANDLE handle, const char* stringUnitId, const char* stringOrderId, const char* stringOrderType, const char* stringState)
+{
+	if(handle==NULL || stringUnitId==NULL || stringOrderId==NULL || stringOrderType==NULL || stringState==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->NotifyAppState(stringUnitId, stringOrderId, stringOrderType, stringState);
+}
+
+int VerifyAppState(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringOrderId, const char* stringOrderType)
+{
+	if(handle==NULL || stringLocalFilePath==NULL || stringOrderId==NULL || stringOrderType==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->VerifyAppState(stringLocalFilePath, stringOrderId, stringOrderType);
+}
+
+int GetHisReportState(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId)
+{
+	if(handle==NULL || stringHospitalId==NULL || stringOrderType==NULL || stringOrderId==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->GetHisReportState(stringLocalFilePath, stringHospitalId, stringOrderType, stringOrderId);
+}
+
+int SetHisCriticalValue(NET_HANDLE handle, const char* stringHospitalId, const char* stringCaseId, const char* stringCriticalValues)
+{
+	if(handle==NULL || stringHospitalId==NULL || stringCaseId==NULL || stringCriticalValues==NULL)
+	{
+		return COMMON_PARAMETER_NULL;
+	}
+	string stringUuid = handle;
+	CExternalNetInterface* pNetInterface = NULL;
+	pNetInterface = CNetThreadManager::GetNetThread(stringUuid);
+	if(pNetInterface == NULL)
+	{
+		//写日志
+		return COMMON_INVALID_HANDLE;
+	}
+	return pNetInterface->SetHisCriticalValue(stringHospitalId, stringCaseId, stringCriticalValues);
+}

+ 285 - 0
WithinHospitalNetInterface.h

@@ -0,0 +1,285 @@
+#ifndef PHMS_WITHIN_HOSPITAL_INTERFACE
+#define PHMS_WITHIN_HOSPITAL_INTERFACE
+#include "PhmsDataType.h"
+
+
+
+#if defined(_WIN32) || defined(_WIN32_WCE)
+#if defined(PHMS_DLL_EXPORTS)
+#define NET_API __declspec(dllexport)
+#else
+#define NET_API __declspec(dllimport)	
+#endif
+#endif
+
+
+#if !defined(NET_API)
+#define NET_API
+#endif
+
+
+
+#ifdef __cplusplus 
+extern "C" { 
+#endif 
+
+//==================================================================
+//函数名:SetCliniqueBusy
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:设置上传点状态为忙碌  
+//输入参数:handle					网络对象句柄
+//			stringCliniqueId		上传点id
+//返回值: 正常或错误返回码
+//使用范围:终端、叫号软件
+//修改记录:
+//==================================================================
+int NET_API SetCliniqueBusy(NET_HANDLE handle, const char* stringCliniqueId);
+
+//==================================================================
+//函数名:SetCliniqueFree
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:设置上传点状态为空闲
+//输入参数:handle					网络对象句柄
+//			stringCliniqueId		上传点id
+//返回值: 正常或错误返回码
+//使用范围:终端
+//修改记录:
+//==================================================================
+int NET_API SetCliniqueFree(NET_HANDLE handle, const char* stringCliniqueId);
+
+//==================================================================
+//函数名:SetCliniqueChecking
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:设置上传点状态为检查中  
+//输入参数:handle					网络对象句柄
+//			stringCliniqueId		上传点id
+//返回值: 正常或错误返回码
+//使用范围:终端
+//修改记录:
+//==================================================================
+int NET_API SetCliniqueChecking(NET_HANDLE handle, const char* stringCliniqueId);
+
+//==================================================================
+//函数名:SetCliniqueShoutComplete
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:设置上传点状态为叫号完成 
+//输入参数:handle					网络对象句柄
+//			stringCliniqueId		上传点id
+//返回值: 正常或错误返回码
+//使用范围:叫号软件
+//修改记录:
+//==================================================================
+int NET_API SetCliniqueShoutComplete(NET_HANDLE handle, const char* stringCliniqueId);
+
+
+//==================================================================
+//函数名:GetPatientInfoByAppNum
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:根据申请单号获得病人信息
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringOrderType			申请单类型(1:门诊  2:住院  3:急诊  4:体检)
+//			stringOrderId			申请单号(S:申请单号 M:门诊号 Z:住院号 T:体检号 K:卡号 W:未知)
+//			stringReqDepart			申请科室代码
+//			stringOrderState		申请单状态(0:全部   1:待检查   2:已检查)
+//			stringCheckType			检查类别
+//			stringStartDate			开单日期开始时间
+//			stringEndDate			开单日期结束时间
+//			stringClinicId			诊室id
+//输出参数:
+//返回值: 正常或错误返回码
+//使用范围:叫号软件、整合客户端、设备
+//修改记录:
+//==================================================================
+int NET_API GetPatientInfoByAppNum(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId, 
+								   const char* stringReqDepart, const char* stringOrderState, const char* stringCheckType, const char* stringStartDate, const char* stringEndDate, const char* stringClinicId);
+
+//==================================================================
+//函数名:GetPatientInfoByAppNumToHis
+//作者:YangJiannan
+//日期:2017.10.20
+//功能:根据申请单号获得病人信息
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringOrderType			申请单类型(1:门诊  2:住院  3:急诊  4:体检)
+//			stringOrderId			申请单号(S:申请单号 M:门诊号 Z:住院号 T:体检号 K:卡号 W:未知)
+//输出参数:
+//返回值: 正常或错误返回码
+//使用范围:叫号软件、整合客户端、设备
+//修改记录:
+//==================================================================
+int NET_API GetPatientInfoByAppNumToHis(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId);
+
+//==================================================================
+//函数名:GetPatientInfoByAppNumToPhmsAndHis
+//作者:YangJiannan
+//日期:2017.10.20
+//功能:根据申请单号获得病人信息
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringOrderType			申请单类型(1:门诊  2:住院  3:急诊  4:体检)
+//			stringOrderId			申请单号(S:申请单号 M:门诊号 Z:住院号 T:体检号 K:卡号 W:未知)
+//输出参数:
+//返回值: 正常或错误返回码
+//使用范围:叫号软件、整合客户端、设备
+//修改记录:
+//==================================================================
+int NET_API GetPatientInfoByAppNumToPhmsAndHis(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId);
+
+//==================================================================
+//函数名:ApplyCheck
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:申请检查  
+//输入参数:handle					网络对象句柄
+//			stringCliniqueId		上传点号
+//			stringOrderId			申请单号
+//			stringOrderType			申请单类型(0:门诊  1:住院  空:全部)
+//返回值: 正常或错误返回码
+//使用范围:叫号软件
+//修改记录:
+//==================================================================
+int NET_API ApplyCheck(NET_HANDLE handle, const char* stringCliniqueId, const char* stringOrderId, const char* stringOrderType);
+
+//==================================================================
+//函数名:GetWaitingCheck
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:获得等待检查患者信息  
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringCliniqueId		上传点号
+//返回值: 正常或错误返回码
+//使用范围:终端
+//修改记录:
+//==================================================================
+int NET_API GetWaitingCheck(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCliniqueId);
+
+//==================================================================
+//函数名:GetCliniqueState
+//作者:YangJiannan
+//日期:2014.10.30
+//功能:获得上传点状态  
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringCliniqueId		上传点号
+//返回值: 正常或错误返回码
+//使用范围:叫号软件
+//修改记录:
+//==================================================================
+int NET_API GetCliniqueState(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringCliniqueId);
+
+//==================================================================
+//函数名:NotifyCaseState
+//作者:YangJiannan
+//日期:2014.11.17
+//功能:通知HIS病例状态改变  
+//输入参数:handle					网络对象句柄
+//			stringHospitalId		医院号
+//			stringOrderType			申请单类型(0:门诊   1:住院)
+//			stringOrderId			申请单号
+//返回值: 正常或错误返回码
+//使用范围:客户端
+//修改记录:
+//==================================================================
+int NET_API NotifyCaseState(NET_HANDLE handle, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId);
+
+//==================================================================
+//函数名:NotifyReportState
+//作者:YangJiannan
+//日期:2014.11.17
+//功能:通知HIS报告状态改变  
+//输入参数:handle					网络对象句柄
+//			stringReportId			报告id
+//返回值: 正常或错误返回码
+//使用范围:专家端
+//修改记录:
+//==================================================================
+int NET_API NotifyReportState(NET_HANDLE handle, const char* stringReportId);
+
+//==================================================================
+//函数名:SetDoctorAgentId
+//作者:YangJiannan
+//日期:2015.2.28
+//功能:设置PHMS系统院内医生工号,只有在院内对接时会用到
+//输入参数:handle					网络对象句柄
+//			stringDoctorAgentId		院内医生工号
+//返回值: 正常或错误返回码
+//使用范围:专家端
+//修改记录:
+//==================================================================
+int NET_API SetDoctorAgentId(NET_HANDLE handle, const char* stringDoctorAgentId);
+
+//==================================================================
+//函数名:NotifyAppState
+//作者:YangJiannan
+//日期:2017.10.27
+//功能:通知服务器申请单状态(已检查或跳过)
+//输入参数:handle					网络对象句柄
+//			stringUnitId			上传点登录号
+//			stringOrderId			申请单号
+//			stringOrderType			对应GetPatientInfoByAppNum接口返回的patient_source_code
+//			stringState				状态(1:已检查, 2跳过)
+//返回值: 正常或错误返回码
+//使用范围:客户端或设备终端
+//修改记录:
+//==================================================================
+int NET_API NotifyAppState(NET_HANDLE handle, const char* stringUnitId, const char* stringOrderId, const char* stringOrderType, const char* stringState);
+
+//==================================================================
+//函数名:VerifyAppState
+//作者:YangJiannan
+//日期:2017.10.27
+//功能:通过服务器验证申请单是否已被跳过或者已检查
+//输入参数:handle					网络对象句柄
+//			stringLocalFilePath		本地文件保存路径
+//			stringOrderId			申请单号
+//			stringOrderType			对应GetPatientInfoByAppNum接口返回的patient_source_code
+//返回值: 正常或错误返回码
+//使用范围:客户端或设备终端
+//修改记录:
+//==================================================================
+int NET_API VerifyAppState(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringOrderId, const char* stringOrderType);
+
+
+//==================================================================
+//函数名:GetHisReportState
+//作者:YangJiannan
+//日期:2016.6.15
+//功能:获得申请单在HIS中对应报告的状态
+//输入参数:handle					网络对象句柄
+//			stringHospitalId		医院ID
+//			stringOrderType			申请单类型
+//			stringOrderId			申请单号
+//返回值: 正常或错误返回码
+//使用范围:专家端
+//修改记录:
+//==================================================================
+int NET_API GetHisReportState(NET_HANDLE handle, const char* stringLocalFilePath, const char* stringHospitalId, const char* stringOrderType, const char* stringOrderId);
+
+
+//==================================================================
+//函数名:SetHisCriticalValue
+//作者:YangJiannan
+//日期:2016.6.15
+//功能:设置病例危急值
+//输入参数:handle					网络对象句柄
+//			stringHospitalId		医院ID
+//			stringCaseId			病例号
+//			stringCriticalValues	危急值
+//返回值: 正常或错误返回码
+//使用范围:专家端
+//修改记录:
+//==================================================================
+int NET_API SetHisCriticalValue(NET_HANDLE handle, const char* stringHospitalId, const char* stringCaseId, const char* stringCriticalValues);
+
+#ifdef __cplusplus 
+} 
+#endif 
+
+#endif

+ 19 - 0
jsoncpp-src-0.5.0/include/json/autolink.h

@@ -0,0 +1,19 @@
+#ifndef JSON_AUTOLINK_H_INCLUDED
+# define JSON_AUTOLINK_H_INCLUDED
+
+# include "config.h"
+
+# ifdef JSON_IN_CPPTL
+#  include <cpptl/cpptl_autolink.h>
+# endif
+
+# if !defined(JSON_NO_AUTOLINK)  &&  !defined(JSON_DLL_BUILD)  &&  !defined(JSON_IN_CPPTL)
+#  define CPPTL_AUTOLINK_NAME "json"
+#  undef CPPTL_AUTOLINK_DLL
+#  ifdef JSON_DLL
+#   define CPPTL_AUTOLINK_DLL
+#  endif
+#  include "autolink.h"
+# endif
+
+#endif // JSON_AUTOLINK_H_INCLUDED

+ 43 - 0
jsoncpp-src-0.5.0/include/json/config.h

@@ -0,0 +1,43 @@
+#ifndef JSON_CONFIG_H_INCLUDED
+# define JSON_CONFIG_H_INCLUDED
+
+/// If defined, indicates that json library is embedded in CppTL library.
+//# define JSON_IN_CPPTL 1
+
+/// If defined, indicates that json may leverage CppTL library
+//#  define JSON_USE_CPPTL 1
+/// If defined, indicates that cpptl vector based map should be used instead of std::map
+/// as Value container.
+//#  define JSON_USE_CPPTL_SMALLMAP 1
+/// If defined, indicates that Json specific container should be used
+/// (hash table & simple deque container with customizable allocator).
+/// THIS FEATURE IS STILL EXPERIMENTAL!
+//#  define JSON_VALUE_USE_INTERNAL_MAP 1
+/// Force usage of standard new/malloc based allocator instead of memory pool based allocator.
+/// The memory pools allocator used optimization (initializing Value and ValueInternalLink
+/// as if it was a POD) that may cause some validation tool to report errors.
+/// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined.
+//#  define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
+
+/// If defined, indicates that Json use exception to report invalid type manipulation
+/// instead of C assert macro.
+# define JSON_USE_EXCEPTION 1
+
+# ifdef JSON_IN_CPPTL
+#  include <cpptl/config.h>
+#  ifndef JSON_USE_CPPTL
+#   define JSON_USE_CPPTL 1
+#  endif
+# endif
+
+# ifdef JSON_IN_CPPTL
+#  define JSON_API CPPTL_API
+# elif defined(JSON_DLL_BUILD)
+#  define JSON_API __declspec(dllexport)
+# elif defined(JSON_DLL)
+#  define JSON_API __declspec(dllimport)
+# else
+#  define JSON_API
+# endif
+
+#endif // JSON_CONFIG_H_INCLUDED

+ 42 - 0
jsoncpp-src-0.5.0/include/json/features.h

@@ -0,0 +1,42 @@
+#ifndef CPPTL_JSON_FEATURES_H_INCLUDED
+# define CPPTL_JSON_FEATURES_H_INCLUDED
+
+# include "forwards.h"
+
+namespace Json {
+
+   /** \brief Configuration passed to reader and writer.
+    * This configuration object can be used to force the Reader or Writer
+    * to behave in a standard conforming way.
+    */
+   class JSON_API Features
+   {
+   public:
+      /** \brief A configuration that allows all features and assumes all strings are UTF-8.
+       * - C & C++ comments are allowed
+       * - Root object can be any JSON value
+       * - Assumes Value strings are encoded in UTF-8
+       */
+      static Features all();
+
+      /** \brief A configuration that is strictly compatible with the JSON specification.
+       * - Comments are forbidden.
+       * - Root object must be either an array or an object value.
+       * - Assumes Value strings are encoded in UTF-8
+       */
+      static Features strictMode();
+
+      /** \brief Initialize the configuration like JsonConfig::allFeatures;
+       */
+      Features();
+
+      /// \c true if comments are allowed. Default: \c true.
+      bool allowComments_;
+
+      /// \c true if root must be either an array or an object value. Default: \c false.
+      bool strictRoot_;
+   };
+
+} // namespace Json
+
+#endif // CPPTL_JSON_FEATURES_H_INCLUDED

+ 39 - 0
jsoncpp-src-0.5.0/include/json/forwards.h

@@ -0,0 +1,39 @@
+#ifndef JSON_FORWARDS_H_INCLUDED
+# define JSON_FORWARDS_H_INCLUDED
+
+# include "config.h"
+
+namespace Json {
+
+   // writer.h
+   class FastWriter;
+   class StyledWriter;
+
+   // reader.h
+   class Reader;
+
+   // features.h
+   class Features;
+
+   // value.h
+   typedef int Int;
+   typedef unsigned int UInt;
+   class StaticString;
+   class Path;
+   class PathArgument;
+   class Value;
+   class ValueIteratorBase;
+   class ValueIterator;
+   class ValueConstIterator;
+#ifdef JSON_VALUE_USE_INTERNAL_MAP
+   class ValueAllocator;
+   class ValueMapAllocator;
+   class ValueInternalLink;
+   class ValueInternalArray;
+   class ValueInternalMap;
+#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
+
+} // namespace Json
+
+
+#endif // JSON_FORWARDS_H_INCLUDED

+ 10 - 0
jsoncpp-src-0.5.0/include/json/json.h

@@ -0,0 +1,10 @@
+#ifndef JSON_JSON_H_INCLUDED
+# define JSON_JSON_H_INCLUDED
+
+# include "autolink.h"
+# include "value.h"
+# include "reader.h"
+# include "writer.h"
+# include "features.h"
+
+#endif // JSON_JSON_H_INCLUDED

+ 196 - 0
jsoncpp-src-0.5.0/include/json/reader.h

@@ -0,0 +1,196 @@
+#ifndef CPPTL_JSON_READER_H_INCLUDED
+# define CPPTL_JSON_READER_H_INCLUDED
+
+# include "features.h"
+# include "value.h"
+# include <deque>
+# include <stack>
+# include <string>
+# include <iostream>
+
+namespace Json {
+
+   /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a Value.
+    *
+    */
+   class JSON_API Reader
+   {
+   public:
+      typedef char Char;
+      typedef const Char *Location;
+
+      /** \brief Constructs a Reader allowing all features
+       * for parsing.
+       */
+      Reader();
+
+      /** \brief Constructs a Reader allowing the specified feature set
+       * for parsing.
+       */
+      Reader( const Features &features );
+
+      /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
+       * \param document UTF-8 encoded string containing the document to read.
+       * \param root [out] Contains the root value of the document if it was
+       *             successfully parsed.
+       * \param collectComments \c true to collect comment and allow writing them back during
+       *                        serialization, \c false to discard comments.
+       *                        This parameter is ignored if Features::allowComments_
+       *                        is \c false.
+       * \return \c true if the document was successfully parsed, \c false if an error occurred.
+       */
+      bool parse( const std::string &document, 
+                  Value &root,
+                  bool collectComments = true );
+
+      /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
+       * \param document UTF-8 encoded string containing the document to read.
+       * \param root [out] Contains the root value of the document if it was
+       *             successfully parsed.
+       * \param collectComments \c true to collect comment and allow writing them back during
+       *                        serialization, \c false to discard comments.
+       *                        This parameter is ignored if Features::allowComments_
+       *                        is \c false.
+       * \return \c true if the document was successfully parsed, \c false if an error occurred.
+       */
+      bool parse( const char *beginDoc, const char *endDoc, 
+                  Value &root,
+                  bool collectComments = true );
+
+      /// \brief Parse from input stream.
+      /// \see Json::operator>>(std::istream&, Json::Value&).
+      bool parse( std::istream &is,
+                  Value &root,
+                  bool collectComments = true );
+
+      /** \brief Returns a user friendly string that list errors in the parsed document.
+       * \return Formatted error message with the list of errors with their location in 
+       *         the parsed document. An empty string is returned if no error occurred
+       *         during parsing.
+       */
+      std::string getFormatedErrorMessages() const;
+
+   private:
+      enum TokenType
+      {
+         tokenEndOfStream = 0,
+         tokenObjectBegin,
+         tokenObjectEnd,
+         tokenArrayBegin,
+         tokenArrayEnd,
+         tokenString,
+         tokenNumber,
+         tokenTrue,
+         tokenFalse,
+         tokenNull,
+         tokenArraySeparator,
+         tokenMemberSeparator,
+         tokenComment,
+         tokenError
+      };
+
+      class Token
+      {
+      public:
+         TokenType type_;
+         Location start_;
+         Location end_;
+      };
+
+      class ErrorInfo
+      {
+      public:
+         Token token_;
+         std::string message_;
+         Location extra_;
+      };
+
+      typedef std::deque<ErrorInfo> Errors;
+
+      bool expectToken( TokenType type, Token &token, const char *message );
+      bool readToken( Token &token );
+      void skipSpaces();
+      bool match( Location pattern, 
+                  int patternLength );
+      bool readComment();
+      bool readCStyleComment();
+      bool readCppStyleComment();
+      bool readString();
+      void readNumber();
+      bool readValue();
+      bool readObject( Token &token );
+      bool readArray( Token &token );
+      bool decodeNumber( Token &token );
+      bool decodeString( Token &token );
+      bool decodeString( Token &token, std::string &decoded );
+      bool decodeDouble( Token &token );
+      bool decodeUnicodeCodePoint( Token &token, 
+                                   Location &current, 
+                                   Location end, 
+                                   unsigned int &unicode );
+      bool decodeUnicodeEscapeSequence( Token &token, 
+                                        Location &current, 
+                                        Location end, 
+                                        unsigned int &unicode );
+      bool addError( const std::string &message, 
+                     Token &token,
+                     Location extra = 0 );
+      bool recoverFromError( TokenType skipUntilToken );
+      bool addErrorAndRecover( const std::string &message, 
+                               Token &token,
+                               TokenType skipUntilToken );
+      void skipUntilSpace();
+      Value &currentValue();
+      Char getNextChar();
+      void getLocationLineAndColumn( Location location,
+                                     int &line,
+                                     int &column ) const;
+      std::string getLocationLineAndColumn( Location location ) const;
+      void addComment( Location begin, 
+                       Location end, 
+                       CommentPlacement placement );
+      void skipCommentTokens( Token &token );
+   
+      typedef std::stack<Value *> Nodes;
+      Nodes nodes_;
+      Errors errors_;
+      std::string document_;
+      Location begin_;
+      Location end_;
+      Location current_;
+      Location lastValueEnd_;
+      Value *lastValue_;
+      std::string commentsBefore_;
+      Features features_;
+      bool collectComments_;
+   };
+
+   /** \brief Read from 'sin' into 'root'.
+
+    Always keep comments from the input JSON.
+
+    This can be used to read a file into a particular sub-object.
+    For example:
+    \code
+    Json::Value root;
+    cin >> root["dir"]["file"];
+    cout << root;
+    \endcode
+    Result:
+    \verbatim
+    {
+	"dir": {
+	    "file": {
+		// The input stream JSON would be nested here.
+	    }
+	}
+    }
+    \endverbatim
+    \throw std::exception on parse error.
+    \see Json::operator<<()
+   */
+   std::istream& operator>>( std::istream&, Value& );
+
+} // namespace Json
+
+#endif // CPPTL_JSON_READER_H_INCLUDED

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1069 - 0
jsoncpp-src-0.5.0/include/json/value.h


+ 174 - 0
jsoncpp-src-0.5.0/include/json/writer.h

@@ -0,0 +1,174 @@
+#ifndef JSON_WRITER_H_INCLUDED
+# define JSON_WRITER_H_INCLUDED
+
+# include "value.h"
+# include <vector>
+# include <string>
+# include <iostream>
+
+namespace Json {
+
+   class Value;
+
+   /** \brief Abstract class for writers.
+    */
+   class JSON_API Writer
+   {
+   public:
+      virtual ~Writer();
+
+      virtual std::string write( const Value &root ) = 0;
+   };
+
+   /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format without formatting (not human friendly).
+    *
+    * The JSON document is written in a single line. It is not intended for 'human' consumption,
+    * but may be usefull to support feature such as RPC where bandwith is limited.
+    * \sa Reader, Value
+    */
+   class JSON_API FastWriter : public Writer
+   {
+   public:
+      FastWriter();
+      virtual ~FastWriter(){}
+
+      void enableYAMLCompatibility();
+
+   public: // overridden from Writer
+      virtual std::string write( const Value &root );
+
+   private:
+      void writeValue( const Value &value );
+
+      std::string document_;
+      bool yamlCompatiblityEnabled_;
+   };
+
+   /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way.
+    *
+    * The rules for line break and indent are as follow:
+    * - Object value:
+    *     - if empty then print {} without indent and line break
+    *     - if not empty the print '{', line break & indent, print one value per line
+    *       and then unindent and line break and print '}'.
+    * - Array value:
+    *     - if empty then print [] without indent and line break
+    *     - if the array contains no object value, empty array or some other value types,
+    *       and all the values fit on one lines, then print the array on a single line.
+    *     - otherwise, it the values do not fit on one line, or the array contains
+    *       object or non empty array, then print one value per line.
+    *
+    * If the Value have comments then they are outputed according to their #CommentPlacement.
+    *
+    * \sa Reader, Value, Value::setComment()
+    */
+   class JSON_API StyledWriter: public Writer
+   {
+   public:
+      StyledWriter();
+      virtual ~StyledWriter(){}
+
+   public: // overridden from Writer
+      /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
+       * \param root Value to serialize.
+       * \return String containing the JSON document that represents the root value.
+       */
+      virtual std::string write( const Value &root );
+
+   private:
+      void writeValue( const Value &value );
+      void writeArrayValue( const Value &value );
+      bool isMultineArray( const Value &value );
+      void pushValue( const std::string &value );
+      void writeIndent();
+      void writeWithIndent( const std::string &value );
+      void indent();
+      void unindent();
+      void writeCommentBeforeValue( const Value &root );
+      void writeCommentAfterValueOnSameLine( const Value &root );
+      bool hasCommentForValue( const Value &value );
+      static std::string normalizeEOL( const std::string &text );
+
+      typedef std::vector<std::string> ChildValues;
+
+      ChildValues childValues_;
+      std::string document_;
+      std::string indentString_;
+      int rightMargin_;
+      int indentSize_;
+      bool addChildValues_;
+   };
+
+   /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way,
+        to a stream rather than to a string.
+    *
+    * The rules for line break and indent are as follow:
+    * - Object value:
+    *     - if empty then print {} without indent and line break
+    *     - if not empty the print '{', line break & indent, print one value per line
+    *       and then unindent and line break and print '}'.
+    * - Array value:
+    *     - if empty then print [] without indent and line break
+    *     - if the array contains no object value, empty array or some other value types,
+    *       and all the values fit on one lines, then print the array on a single line.
+    *     - otherwise, it the values do not fit on one line, or the array contains
+    *       object or non empty array, then print one value per line.
+    *
+    * If the Value have comments then they are outputed according to their #CommentPlacement.
+    *
+    * \param indentation Each level will be indented by this amount extra.
+    * \sa Reader, Value, Value::setComment()
+    */
+   class JSON_API StyledStreamWriter
+   {
+   public:
+      StyledStreamWriter( std::string indentation="\t" );
+      ~StyledStreamWriter(){}
+
+   public:
+      /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
+       * \param out Stream to write to. (Can be ostringstream, e.g.)
+       * \param root Value to serialize.
+       * \note There is no point in deriving from Writer, since write() should not return a value.
+       */
+      void write( std::ostream &out, const Value &root );
+
+   private:
+      void writeValue( const Value &value );
+      void writeArrayValue( const Value &value );
+      bool isMultineArray( const Value &value );
+      void pushValue( const std::string &value );
+      void writeIndent();
+      void writeWithIndent( const std::string &value );
+      void indent();
+      void unindent();
+      void writeCommentBeforeValue( const Value &root );
+      void writeCommentAfterValueOnSameLine( const Value &root );
+      bool hasCommentForValue( const Value &value );
+      static std::string normalizeEOL( const std::string &text );
+
+      typedef std::vector<std::string> ChildValues;
+
+      ChildValues childValues_;
+      std::ostream* document_;
+      std::string indentString_;
+      int rightMargin_;
+      std::string indentation_;
+      bool addChildValues_;
+   };
+
+   std::string JSON_API valueToString( Int value );
+   std::string JSON_API valueToString( UInt value );
+   std::string JSON_API valueToString( double value );
+   std::string JSON_API valueToString( bool value );
+   std::string JSON_API valueToQuotedString( const char *value );
+
+   /// \brief Output using the StyledStreamWriter.
+   /// \see Json::operator>>()
+   std::ostream& operator<<( std::ostream&, const Value &root );
+
+} // namespace Json
+
+
+
+#endif // JSON_WRITER_H_INCLUDED

+ 125 - 0
jsoncpp-src-0.5.0/src/lib_json/json_batchallocator.h

@@ -0,0 +1,125 @@
+#ifndef JSONCPP_BATCHALLOCATOR_H_INCLUDED
+# define JSONCPP_BATCHALLOCATOR_H_INCLUDED
+
+# include <stdlib.h>
+# include <assert.h>
+
+# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
+
+namespace Json {
+
+/* Fast memory allocator.
+ *
+ * This memory allocator allocates memory for a batch of object (specified by
+ * the page size, the number of object in each page).
+ *
+ * It does not allow the destruction of a single object. All the allocated objects
+ * can be destroyed at once. The memory can be either released or reused for future
+ * allocation.
+ * 
+ * The in-place new operator must be used to construct the object using the pointer
+ * returned by allocate.
+ */
+template<typename AllocatedType
+        ,const unsigned int objectPerAllocation>
+class BatchAllocator
+{
+public:
+   typedef AllocatedType Type;
+
+   BatchAllocator( unsigned int objectsPerPage = 255 )
+      : freeHead_( 0 )
+      , objectsPerPage_( objectsPerPage )
+   {
+//      printf( "Size: %d => %s\n", sizeof(AllocatedType), typeid(AllocatedType).name() );
+      assert( sizeof(AllocatedType) * objectPerAllocation >= sizeof(AllocatedType *) ); // We must be able to store a slist in the object free space.
+      assert( objectsPerPage >= 16 );
+      batches_ = allocateBatch( 0 );   // allocated a dummy page
+      currentBatch_ = batches_;
+   }
+
+   ~BatchAllocator()
+   {
+      for ( BatchInfo *batch = batches_; batch;  )
+      {
+         BatchInfo *nextBatch = batch->next_;
+         free( batch );
+         batch = nextBatch;
+      }
+   }
+
+   /// allocate space for an array of objectPerAllocation object.
+   /// @warning it is the responsability of the caller to call objects constructors.
+   AllocatedType *allocate()
+   {
+      if ( freeHead_ ) // returns node from free list.
+      {
+         AllocatedType *object = freeHead_;
+         freeHead_ = *(AllocatedType **)object;
+         return object;
+      }
+      if ( currentBatch_->used_ == currentBatch_->end_ )
+      {
+         currentBatch_ = currentBatch_->next_;
+         while ( currentBatch_  &&  currentBatch_->used_ == currentBatch_->end_ )
+            currentBatch_ = currentBatch_->next_;
+
+         if ( !currentBatch_  ) // no free batch found, allocate a new one
+         { 
+            currentBatch_ = allocateBatch( objectsPerPage_ );
+            currentBatch_->next_ = batches_; // insert at the head of the list
+            batches_ = currentBatch_;
+         }
+      }
+      AllocatedType *allocated = currentBatch_->used_;
+      currentBatch_->used_ += objectPerAllocation;
+      return allocated;
+   }
+
+   /// Release the object.
+   /// @warning it is the responsability of the caller to actually destruct the object.
+   void release( AllocatedType *object )
+   {
+      assert( object != 0 );
+      *(AllocatedType **)object = freeHead_;
+      freeHead_ = object;
+   }
+
+private:
+   struct BatchInfo
+   {
+      BatchInfo *next_;
+      AllocatedType *used_;
+      AllocatedType *end_;
+      AllocatedType buffer_[objectPerAllocation];
+   };
+
+   // disabled copy constructor and assignement operator.
+   BatchAllocator( const BatchAllocator & );
+   void operator =( const BatchAllocator &);
+
+   static BatchInfo *allocateBatch( unsigned int objectsPerPage )
+   {
+      const unsigned int mallocSize = sizeof(BatchInfo) - sizeof(AllocatedType)* objectPerAllocation
+                                + sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
+      BatchInfo *batch = static_cast<BatchInfo*>( malloc( mallocSize ) );
+      batch->next_ = 0;
+      batch->used_ = batch->buffer_;
+      batch->end_ = batch->buffer_ + objectsPerPage;
+      return batch;
+   }
+
+   BatchInfo *batches_;
+   BatchInfo *currentBatch_;
+   /// Head of a single linked list within the allocated space of freeed object
+   AllocatedType *freeHead_;
+   unsigned int objectsPerPage_;
+};
+
+
+} // namespace Json
+
+# endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION
+
+#endif // JSONCPP_BATCHALLOCATOR_H_INCLUDED
+

+ 448 - 0
jsoncpp-src-0.5.0/src/lib_json/json_internalarray.inl

@@ -0,0 +1,448 @@
+// included by json_value.cpp
+// everything is within Json namespace
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueInternalArray
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+ValueArrayAllocator::~ValueArrayAllocator()
+{
+}
+
+// //////////////////////////////////////////////////////////////////
+// class DefaultValueArrayAllocator
+// //////////////////////////////////////////////////////////////////
+#ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
+class DefaultValueArrayAllocator : public ValueArrayAllocator
+{
+public: // overridden from ValueArrayAllocator
+   virtual ~DefaultValueArrayAllocator()
+   {
+   }
+
+   virtual ValueInternalArray *newArray()
+   {
+      return new ValueInternalArray();
+   }
+
+   virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other )
+   {
+      return new ValueInternalArray( other );
+   }
+
+   virtual void destructArray( ValueInternalArray *array )
+   {
+      delete array;
+   }
+
+   virtual void reallocateArrayPageIndex( Value **&indexes, 
+                                          ValueInternalArray::PageIndex &indexCount,
+                                          ValueInternalArray::PageIndex minNewIndexCount )
+   {
+      ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1;
+      if ( minNewIndexCount > newIndexCount )
+         newIndexCount = minNewIndexCount;
+      void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount );
+      if ( !newIndexes )
+         throw std::bad_alloc();
+      indexCount = newIndexCount;
+      indexes = static_cast<Value **>( newIndexes );
+   }
+   virtual void releaseArrayPageIndex( Value **indexes, 
+                                       ValueInternalArray::PageIndex indexCount )
+   {
+      if ( indexes )
+         free( indexes );
+   }
+
+   virtual Value *allocateArrayPage()
+   {
+      return static_cast<Value *>( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) );
+   }
+
+   virtual void releaseArrayPage( Value *value )
+   {
+      if ( value )
+         free( value );
+   }
+};
+
+#else // #ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
+/// @todo make this thread-safe (lock when accessign batch allocator)
+class DefaultValueArrayAllocator : public ValueArrayAllocator
+{
+public: // overridden from ValueArrayAllocator
+   virtual ~DefaultValueArrayAllocator()
+   {
+   }
+
+   virtual ValueInternalArray *newArray()
+   {
+      ValueInternalArray *array = arraysAllocator_.allocate();
+      new (array) ValueInternalArray(); // placement new
+      return array;
+   }
+
+   virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other )
+   {
+      ValueInternalArray *array = arraysAllocator_.allocate();
+      new (array) ValueInternalArray( other ); // placement new
+      return array;
+   }
+
+   virtual void destructArray( ValueInternalArray *array )
+   {
+      if ( array )
+      {
+         array->~ValueInternalArray();
+         arraysAllocator_.release( array );
+      }
+   }
+
+   virtual void reallocateArrayPageIndex( Value **&indexes, 
+                                          ValueInternalArray::PageIndex &indexCount,
+                                          ValueInternalArray::PageIndex minNewIndexCount )
+   {
+      ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1;
+      if ( minNewIndexCount > newIndexCount )
+         newIndexCount = minNewIndexCount;
+      void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount );
+      if ( !newIndexes )
+         throw std::bad_alloc();
+      indexCount = newIndexCount;
+      indexes = static_cast<Value **>( newIndexes );
+   }
+   virtual void releaseArrayPageIndex( Value **indexes, 
+                                       ValueInternalArray::PageIndex indexCount )
+   {
+      if ( indexes )
+         free( indexes );
+   }
+
+   virtual Value *allocateArrayPage()
+   {
+      return static_cast<Value *>( pagesAllocator_.allocate() );
+   }
+
+   virtual void releaseArrayPage( Value *value )
+   {
+      if ( value )
+         pagesAllocator_.release( value );
+   }
+private:
+   BatchAllocator<ValueInternalArray,1> arraysAllocator_;
+   BatchAllocator<Value,ValueInternalArray::itemsPerPage> pagesAllocator_;
+};
+#endif // #ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
+
+static ValueArrayAllocator *&arrayAllocator()
+{
+   static DefaultValueArrayAllocator defaultAllocator;
+   static ValueArrayAllocator *arrayAllocator = &defaultAllocator;
+   return arrayAllocator;
+}
+
+static struct DummyArrayAllocatorInitializer {
+   DummyArrayAllocatorInitializer() 
+   {
+      arrayAllocator();      // ensure arrayAllocator() statics are initialized before main().
+   }
+} dummyArrayAllocatorInitializer;
+
+// //////////////////////////////////////////////////////////////////
+// class ValueInternalArray
+// //////////////////////////////////////////////////////////////////
+bool 
+ValueInternalArray::equals( const IteratorState &x, 
+                            const IteratorState &other )
+{
+   return x.array_ == other.array_  
+          &&  x.currentItemIndex_ == other.currentItemIndex_  
+          &&  x.currentPageIndex_ == other.currentPageIndex_;
+}
+
+
+void 
+ValueInternalArray::increment( IteratorState &it )
+{
+   JSON_ASSERT_MESSAGE( it.array_  &&
+      (it.currentPageIndex_ - it.array_->pages_)*itemsPerPage + it.currentItemIndex_
+      != it.array_->size_,
+      "ValueInternalArray::increment(): moving iterator beyond end" );
+   ++(it.currentItemIndex_);
+   if ( it.currentItemIndex_ == itemsPerPage )
+   {
+      it.currentItemIndex_ = 0;
+      ++(it.currentPageIndex_);
+   }
+}
+
+
+void 
+ValueInternalArray::decrement( IteratorState &it )
+{
+   JSON_ASSERT_MESSAGE( it.array_  &&  it.currentPageIndex_ == it.array_->pages_ 
+                        &&  it.currentItemIndex_ == 0,
+      "ValueInternalArray::decrement(): moving iterator beyond end" );
+   if ( it.currentItemIndex_ == 0 )
+   {
+      it.currentItemIndex_ = itemsPerPage-1;
+      --(it.currentPageIndex_);
+   }
+   else
+   {
+      --(it.currentItemIndex_);
+   }
+}
+
+
+Value &
+ValueInternalArray::unsafeDereference( const IteratorState &it )
+{
+   return (*(it.currentPageIndex_))[it.currentItemIndex_];
+}
+
+
+Value &
+ValueInternalArray::dereference( const IteratorState &it )
+{
+   JSON_ASSERT_MESSAGE( it.array_  &&
+      (it.currentPageIndex_ - it.array_->pages_)*itemsPerPage + it.currentItemIndex_
+      < it.array_->size_,
+      "ValueInternalArray::dereference(): dereferencing invalid iterator" );
+   return unsafeDereference( it );
+}
+
+void 
+ValueInternalArray::makeBeginIterator( IteratorState &it ) const
+{
+   it.array_ = const_cast<ValueInternalArray *>( this );
+   it.currentItemIndex_ = 0;
+   it.currentPageIndex_ = pages_;
+}
+
+
+void 
+ValueInternalArray::makeIterator( IteratorState &it, ArrayIndex index ) const
+{
+   it.array_ = const_cast<ValueInternalArray *>( this );
+   it.currentItemIndex_ = index % itemsPerPage;
+   it.currentPageIndex_ = pages_ + index / itemsPerPage;
+}
+
+
+void 
+ValueInternalArray::makeEndIterator( IteratorState &it ) const
+{
+   makeIterator( it, size_ );
+}
+
+
+ValueInternalArray::ValueInternalArray()
+   : pages_( 0 )
+   , size_( 0 )
+   , pageCount_( 0 )
+{
+}
+
+
+ValueInternalArray::ValueInternalArray( const ValueInternalArray &other )
+   : pages_( 0 )
+   , pageCount_( 0 )
+   , size_( other.size_ )
+{
+   PageIndex minNewPages = other.size_ / itemsPerPage;
+   arrayAllocator()->reallocateArrayPageIndex( pages_, pageCount_, minNewPages );
+   JSON_ASSERT_MESSAGE( pageCount_ >= minNewPages, 
+                        "ValueInternalArray::reserve(): bad reallocation" );
+   IteratorState itOther;
+   other.makeBeginIterator( itOther );
+   Value *value;
+   for ( ArrayIndex index = 0; index < size_; ++index, increment(itOther) )
+   {
+      if ( index % itemsPerPage == 0 )
+      {
+         PageIndex pageIndex = index / itemsPerPage;
+         value = arrayAllocator()->allocateArrayPage();
+         pages_[pageIndex] = value;
+      }
+      new (value) Value( dereference( itOther ) );
+   }
+}
+
+
+ValueInternalArray &
+ValueInternalArray::operator =( const ValueInternalArray &other )
+{
+   ValueInternalArray temp( other );
+   swap( temp );
+   return *this;
+}
+
+
+ValueInternalArray::~ValueInternalArray()
+{
+   // destroy all constructed items
+   IteratorState it;
+   IteratorState itEnd;
+   makeBeginIterator( it);
+   makeEndIterator( itEnd );
+   for ( ; !equals(it,itEnd); increment(it) )
+   {
+      Value *value = &dereference(it);
+      value->~Value();
+   }
+   // release all pages
+   PageIndex lastPageIndex = size_ / itemsPerPage;
+   for ( PageIndex pageIndex = 0; pageIndex < lastPageIndex; ++pageIndex )
+      arrayAllocator()->releaseArrayPage( pages_[pageIndex] );
+   // release pages index
+   arrayAllocator()->releaseArrayPageIndex( pages_, pageCount_ );
+}
+
+
+void 
+ValueInternalArray::swap( ValueInternalArray &other )
+{
+   Value **tempPages = pages_;
+   pages_ = other.pages_;
+   other.pages_ = tempPages;
+   ArrayIndex tempSize = size_;
+   size_ = other.size_;
+   other.size_ = tempSize;
+   PageIndex tempPageCount = pageCount_;
+   pageCount_ = other.pageCount_;
+   other.pageCount_ = tempPageCount;
+}
+
+void 
+ValueInternalArray::clear()
+{
+   ValueInternalArray dummy;
+   swap( dummy );
+}
+
+
+void 
+ValueInternalArray::resize( ArrayIndex newSize )
+{
+   if ( newSize == 0 )
+      clear();
+   else if ( newSize < size_ )
+   {
+      IteratorState it;
+      IteratorState itEnd;
+      makeIterator( it, newSize );
+      makeIterator( itEnd, size_ );
+      for ( ; !equals(it,itEnd); increment(it) )
+      {
+         Value *value = &dereference(it);
+         value->~Value();
+      }
+      PageIndex pageIndex = (newSize + itemsPerPage - 1) / itemsPerPage;
+      PageIndex lastPageIndex = size_ / itemsPerPage;
+      for ( ; pageIndex < lastPageIndex; ++pageIndex )
+         arrayAllocator()->releaseArrayPage( pages_[pageIndex] );
+      size_ = newSize;
+   }
+   else if ( newSize > size_ )
+      resolveReference( newSize );
+}
+
+
+void 
+ValueInternalArray::makeIndexValid( ArrayIndex index )
+{
+   // Need to enlarge page index ?
+   if ( index >= pageCount_ * itemsPerPage )
+   {
+      PageIndex minNewPages = (index + 1) / itemsPerPage;
+      arrayAllocator()->reallocateArrayPageIndex( pages_, pageCount_, minNewPages );
+      JSON_ASSERT_MESSAGE( pageCount_ >= minNewPages, "ValueInternalArray::reserve(): bad reallocation" );
+   }
+
+   // Need to allocate new pages ?
+   ArrayIndex nextPageIndex = 
+      (size_ % itemsPerPage) != 0 ? size_ - (size_%itemsPerPage) + itemsPerPage
+                                  : size_;
+   if ( nextPageIndex <= index )
+   {
+      PageIndex pageIndex = nextPageIndex / itemsPerPage;
+      PageIndex pageToAllocate = (index - nextPageIndex) / itemsPerPage + 1;
+      for ( ; pageToAllocate-- > 0; ++pageIndex )
+         pages_[pageIndex] = arrayAllocator()->allocateArrayPage();
+   }
+
+   // Initialize all new entries
+   IteratorState it;
+   IteratorState itEnd;
+   makeIterator( it, size_ );
+   size_ = index + 1;
+   makeIterator( itEnd, size_ );
+   for ( ; !equals(it,itEnd); increment(it) )
+   {
+      Value *value = &dereference(it);
+      new (value) Value(); // Construct a default value using placement new
+   }
+}
+
+Value &
+ValueInternalArray::resolveReference( ArrayIndex index )
+{
+   if ( index >= size_ )
+      makeIndexValid( index );
+   return pages_[index/itemsPerPage][index%itemsPerPage];
+}
+
+Value *
+ValueInternalArray::find( ArrayIndex index ) const
+{
+   if ( index >= size_ )
+      return 0;
+   return &(pages_[index/itemsPerPage][index%itemsPerPage]);
+}
+
+ValueInternalArray::ArrayIndex 
+ValueInternalArray::size() const
+{
+   return size_;
+}
+
+int 
+ValueInternalArray::distance( const IteratorState &x, const IteratorState &y )
+{
+   return indexOf(y) - indexOf(x);
+}
+
+
+ValueInternalArray::ArrayIndex 
+ValueInternalArray::indexOf( const IteratorState &iterator )
+{
+   if ( !iterator.array_ )
+      return ArrayIndex(-1);
+   return ArrayIndex(
+      (iterator.currentPageIndex_ - iterator.array_->pages_) * itemsPerPage 
+      + iterator.currentItemIndex_ );
+}
+
+
+int 
+ValueInternalArray::compare( const ValueInternalArray &other ) const
+{
+   int sizeDiff( size_ - other.size_ );
+   if ( sizeDiff != 0 )
+      return sizeDiff;
+   
+   for ( ArrayIndex index =0; index < size_; ++index )
+   {
+      int diff = pages_[index/itemsPerPage][index%itemsPerPage].compare( 
+         other.pages_[index/itemsPerPage][index%itemsPerPage] );
+      if ( diff != 0 )
+         return diff;
+   }
+   return 0;
+}

+ 607 - 0
jsoncpp-src-0.5.0/src/lib_json/json_internalmap.inl

@@ -0,0 +1,607 @@
+// included by json_value.cpp
+// everything is within Json namespace
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueInternalMap
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+/** \internal MUST be safely initialized using memset( this, 0, sizeof(ValueInternalLink) );
+   * This optimization is used by the fast allocator.
+   */
+ValueInternalLink::ValueInternalLink()
+   : previous_( 0 )
+   , next_( 0 )
+{
+}
+
+ValueInternalLink::~ValueInternalLink()
+{ 
+   for ( int index =0; index < itemPerLink; ++index )
+   {
+      if ( !items_[index].isItemAvailable() )
+      {
+         if ( !items_[index].isMemberNameStatic() )
+            free( keys_[index] );
+      }
+      else
+         break;
+   }
+}
+
+
+
+ValueMapAllocator::~ValueMapAllocator()
+{
+}
+
+#ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
+class DefaultValueMapAllocator : public ValueMapAllocator
+{
+public: // overridden from ValueMapAllocator
+   virtual ValueInternalMap *newMap()
+   {
+      return new ValueInternalMap();
+   }
+
+   virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other )
+   {
+      return new ValueInternalMap( other );
+   }
+
+   virtual void destructMap( ValueInternalMap *map )
+   {
+      delete map;
+   }
+
+   virtual ValueInternalLink *allocateMapBuckets( unsigned int size )
+   {
+      return new ValueInternalLink[size];
+   }
+
+   virtual void releaseMapBuckets( ValueInternalLink *links )
+   {
+      delete [] links;
+   }
+
+   virtual ValueInternalLink *allocateMapLink()
+   {
+      return new ValueInternalLink();
+   }
+
+   virtual void releaseMapLink( ValueInternalLink *link )
+   {
+      delete link;
+   }
+};
+#else
+/// @todo make this thread-safe (lock when accessign batch allocator)
+class DefaultValueMapAllocator : public ValueMapAllocator
+{
+public: // overridden from ValueMapAllocator
+   virtual ValueInternalMap *newMap()
+   {
+      ValueInternalMap *map = mapsAllocator_.allocate();
+      new (map) ValueInternalMap(); // placement new
+      return map;
+   }
+
+   virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other )
+   {
+      ValueInternalMap *map = mapsAllocator_.allocate();
+      new (map) ValueInternalMap( other ); // placement new
+      return map;
+   }
+
+   virtual void destructMap( ValueInternalMap *map )
+   {
+      if ( map )
+      {
+         map->~ValueInternalMap();
+         mapsAllocator_.release( map );
+      }
+   }
+
+   virtual ValueInternalLink *allocateMapBuckets( unsigned int size )
+   {
+      return new ValueInternalLink[size];
+   }
+
+   virtual void releaseMapBuckets( ValueInternalLink *links )
+   {
+      delete [] links;
+   }
+
+   virtual ValueInternalLink *allocateMapLink()
+   {
+      ValueInternalLink *link = linksAllocator_.allocate();
+      memset( link, 0, sizeof(ValueInternalLink) );
+      return link;
+   }
+
+   virtual void releaseMapLink( ValueInternalLink *link )
+   {
+      link->~ValueInternalLink();
+      linksAllocator_.release( link );
+   }
+private:
+   BatchAllocator<ValueInternalMap,1> mapsAllocator_;
+   BatchAllocator<ValueInternalLink,1> linksAllocator_;
+};
+#endif
+
+static ValueMapAllocator *&mapAllocator()
+{
+   static DefaultValueMapAllocator defaultAllocator;
+   static ValueMapAllocator *mapAllocator = &defaultAllocator;
+   return mapAllocator;
+}
+
+static struct DummyMapAllocatorInitializer {
+   DummyMapAllocatorInitializer() 
+   {
+      mapAllocator();      // ensure mapAllocator() statics are initialized before main().
+   }
+} dummyMapAllocatorInitializer;
+
+
+
+// h(K) = value * K >> w ; with w = 32 & K prime w.r.t. 2^32.
+
+/*
+use linked list hash map. 
+buckets array is a container.
+linked list element contains 6 key/values. (memory = (16+4) * 6 + 4 = 124)
+value have extra state: valid, available, deleted
+*/
+
+
+ValueInternalMap::ValueInternalMap()
+   : buckets_( 0 )
+   , tailLink_( 0 )
+   , bucketsSize_( 0 )
+   , itemCount_( 0 )
+{
+}
+
+
+ValueInternalMap::ValueInternalMap( const ValueInternalMap &other )
+   : buckets_( 0 )
+   , tailLink_( 0 )
+   , bucketsSize_( 0 )
+   , itemCount_( 0 )
+{
+   reserve( other.itemCount_ );
+   IteratorState it;
+   IteratorState itEnd;
+   other.makeBeginIterator( it );
+   other.makeEndIterator( itEnd );
+   for ( ; !equals(it,itEnd); increment(it) )
+   {
+      bool isStatic;
+      const char *memberName = key( it, isStatic );
+      const Value &aValue = value( it );
+      resolveReference(memberName, isStatic) = aValue;
+   }
+}
+
+
+ValueInternalMap &
+ValueInternalMap::operator =( const ValueInternalMap &other )
+{
+   ValueInternalMap dummy( other );
+   swap( dummy );
+   return *this;
+}
+
+
+ValueInternalMap::~ValueInternalMap()
+{
+   if ( buckets_ )
+   {
+      for ( BucketIndex bucketIndex =0; bucketIndex < bucketsSize_; ++bucketIndex )
+      {
+         ValueInternalLink *link = buckets_[bucketIndex].next_;
+         while ( link )
+         {
+            ValueInternalLink *linkToRelease = link;
+            link = link->next_;
+            mapAllocator()->releaseMapLink( linkToRelease );
+         }
+      }
+      mapAllocator()->releaseMapBuckets( buckets_ );
+   }
+}
+
+
+void 
+ValueInternalMap::swap( ValueInternalMap &other )
+{
+   ValueInternalLink *tempBuckets = buckets_;
+   buckets_ = other.buckets_;
+   other.buckets_ = tempBuckets;
+   ValueInternalLink *tempTailLink = tailLink_;
+   tailLink_ = other.tailLink_;
+   other.tailLink_ = tempTailLink;
+   BucketIndex tempBucketsSize = bucketsSize_;
+   bucketsSize_ = other.bucketsSize_;
+   other.bucketsSize_ = tempBucketsSize;
+   BucketIndex tempItemCount = itemCount_;
+   itemCount_ = other.itemCount_;
+   other.itemCount_ = tempItemCount;
+}
+
+
+void 
+ValueInternalMap::clear()
+{
+   ValueInternalMap dummy;
+   swap( dummy );
+}
+
+
+ValueInternalMap::BucketIndex 
+ValueInternalMap::size() const
+{
+   return itemCount_;
+}
+
+bool 
+ValueInternalMap::reserveDelta( BucketIndex growth )
+{
+   return reserve( itemCount_ + growth );
+}
+
+bool 
+ValueInternalMap::reserve( BucketIndex newItemCount )
+{
+   if ( !buckets_  &&  newItemCount > 0 )
+   {
+      buckets_ = mapAllocator()->allocateMapBuckets( 1 );
+      bucketsSize_ = 1;
+      tailLink_ = &buckets_[0];
+   }
+//   BucketIndex idealBucketCount = (newItemCount + ValueInternalLink::itemPerLink) / ValueInternalLink::itemPerLink;
+   return true;
+}
+
+
+const Value *
+ValueInternalMap::find( const char *key ) const
+{
+   if ( !bucketsSize_ )
+      return 0;
+   HashKey hashedKey = hash( key );
+   BucketIndex bucketIndex = hashedKey % bucketsSize_;
+   for ( const ValueInternalLink *current = &buckets_[bucketIndex]; 
+         current != 0; 
+         current = current->next_ )
+   {
+      for ( BucketIndex index=0; index < ValueInternalLink::itemPerLink; ++index )
+      {
+         if ( current->items_[index].isItemAvailable() )
+            return 0;
+         if ( strcmp( key, current->keys_[index] ) == 0 )
+            return &current->items_[index];
+      }
+   }
+   return 0;
+}
+
+
+Value *
+ValueInternalMap::find( const char *key )
+{
+   const ValueInternalMap *constThis = this;
+   return const_cast<Value *>( constThis->find( key ) );
+}
+
+
+Value &
+ValueInternalMap::resolveReference( const char *key,
+                                    bool isStatic )
+{
+   HashKey hashedKey = hash( key );
+   if ( bucketsSize_ )
+   {
+      BucketIndex bucketIndex = hashedKey % bucketsSize_;
+      ValueInternalLink **previous = 0;
+      BucketIndex index;
+      for ( ValueInternalLink *current = &buckets_[bucketIndex]; 
+            current != 0; 
+            previous = &current->next_, current = current->next_ )
+      {
+         for ( index=0; index < ValueInternalLink::itemPerLink; ++index )
+         {
+            if ( current->items_[index].isItemAvailable() )
+               return setNewItem( key, isStatic, current, index );
+            if ( strcmp( key, current->keys_[index] ) == 0 )
+               return current->items_[index];
+         }
+      }
+   }
+
+   reserveDelta( 1 );
+   return unsafeAdd( key, isStatic, hashedKey );
+}
+
+
+void 
+ValueInternalMap::remove( const char *key )
+{
+   HashKey hashedKey = hash( key );
+   if ( !bucketsSize_ )
+      return;
+   BucketIndex bucketIndex = hashedKey % bucketsSize_;
+   for ( ValueInternalLink *link = &buckets_[bucketIndex]; 
+         link != 0; 
+         link = link->next_ )
+   {
+      BucketIndex index;
+      for ( index =0; index < ValueInternalLink::itemPerLink; ++index )
+      {
+         if ( link->items_[index].isItemAvailable() )
+            return;
+         if ( strcmp( key, link->keys_[index] ) == 0 )
+         {
+            doActualRemove( link, index, bucketIndex );
+            return;
+         }
+      }
+   }
+}
+
+void 
+ValueInternalMap::doActualRemove( ValueInternalLink *link, 
+                                  BucketIndex index,
+                                  BucketIndex bucketIndex )
+{
+   // find last item of the bucket and swap it with the 'removed' one.
+   // set removed items flags to 'available'.
+   // if last page only contains 'available' items, then desallocate it (it's empty)
+   ValueInternalLink *&lastLink = getLastLinkInBucket( index );
+   BucketIndex lastItemIndex = 1; // a link can never be empty, so start at 1
+   for ( ;   
+         lastItemIndex < ValueInternalLink::itemPerLink; 
+         ++lastItemIndex ) // may be optimized with dicotomic search
+   {
+      if ( lastLink->items_[lastItemIndex].isItemAvailable() )
+         break;
+   }
+   
+   BucketIndex lastUsedIndex = lastItemIndex - 1;
+   Value *valueToDelete = &link->items_[index];
+   Value *valueToPreserve = &lastLink->items_[lastUsedIndex];
+   if ( valueToDelete != valueToPreserve )
+      valueToDelete->swap( *valueToPreserve );
+   if ( lastUsedIndex == 0 )  // page is now empty
+   {  // remove it from bucket linked list and delete it.
+      ValueInternalLink *linkPreviousToLast = lastLink->previous_;
+      if ( linkPreviousToLast != 0 )   // can not deleted bucket link.
+      {
+         mapAllocator()->releaseMapLink( lastLink );
+         linkPreviousToLast->next_ = 0;
+         lastLink = linkPreviousToLast;
+      }
+   }
+   else
+   {
+      Value dummy;
+      valueToPreserve->swap( dummy ); // restore deleted to default Value.
+      valueToPreserve->setItemUsed( false );
+   }
+   --itemCount_;
+}
+
+
+ValueInternalLink *&
+ValueInternalMap::getLastLinkInBucket( BucketIndex bucketIndex )
+{
+   if ( bucketIndex == bucketsSize_ - 1 )
+      return tailLink_;
+   ValueInternalLink *&previous = buckets_[bucketIndex+1].previous_;
+   if ( !previous )
+      previous = &buckets_[bucketIndex];
+   return previous;
+}
+
+
+Value &
+ValueInternalMap::setNewItem( const char *key, 
+                              bool isStatic,
+                              ValueInternalLink *link, 
+                              BucketIndex index )
+{
+   char *duplicatedKey = valueAllocator()->makeMemberName( key );
+   ++itemCount_;
+   link->keys_[index] = duplicatedKey;
+   link->items_[index].setItemUsed();
+   link->items_[index].setMemberNameIsStatic( isStatic );
+   return link->items_[index]; // items already default constructed.
+}
+
+
+Value &
+ValueInternalMap::unsafeAdd( const char *key, 
+                             bool isStatic, 
+                             HashKey hashedKey )
+{
+   JSON_ASSERT_MESSAGE( bucketsSize_ > 0, "ValueInternalMap::unsafeAdd(): internal logic error." );
+   BucketIndex bucketIndex = hashedKey % bucketsSize_;
+   ValueInternalLink *&previousLink = getLastLinkInBucket( bucketIndex );
+   ValueInternalLink *link = previousLink;
+   BucketIndex index;
+   for ( index =0; index < ValueInternalLink::itemPerLink; ++index )
+   {
+      if ( link->items_[index].isItemAvailable() )
+         break;
+   }
+   if ( index == ValueInternalLink::itemPerLink ) // need to add a new page
+   {
+      ValueInternalLink *newLink = mapAllocator()->allocateMapLink();
+      index = 0;
+      link->next_ = newLink;
+      previousLink = newLink;
+      link = newLink;
+   }
+   return setNewItem( key, isStatic, link, index );
+}
+
+
+ValueInternalMap::HashKey 
+ValueInternalMap::hash( const char *key ) const
+{
+   HashKey hash = 0;
+   while ( *key )
+      hash += *key++ * 37;
+   return hash;
+}
+
+
+int 
+ValueInternalMap::compare( const ValueInternalMap &other ) const
+{
+   int sizeDiff( itemCount_ - other.itemCount_ );
+   if ( sizeDiff != 0 )
+      return sizeDiff;
+   // Strict order guaranty is required. Compare all keys FIRST, then compare values.
+   IteratorState it;
+   IteratorState itEnd;
+   makeBeginIterator( it );
+   makeEndIterator( itEnd );
+   for ( ; !equals(it,itEnd); increment(it) )
+   {
+      if ( !other.find( key( it ) ) )
+         return 1;
+   }
+
+   // All keys are equals, let's compare values
+   makeBeginIterator( it );
+   for ( ; !equals(it,itEnd); increment(it) )
+   {
+      const Value *otherValue = other.find( key( it ) );
+      int valueDiff = value(it).compare( *otherValue );
+      if ( valueDiff != 0 )
+         return valueDiff;
+   }
+   return 0;
+}
+
+
+void 
+ValueInternalMap::makeBeginIterator( IteratorState &it ) const
+{
+   it.map_ = const_cast<ValueInternalMap *>( this );
+   it.bucketIndex_ = 0;
+   it.itemIndex_ = 0;
+   it.link_ = buckets_;
+}
+
+
+void 
+ValueInternalMap::makeEndIterator( IteratorState &it ) const
+{
+   it.map_ = const_cast<ValueInternalMap *>( this );
+   it.bucketIndex_ = bucketsSize_;
+   it.itemIndex_ = 0;
+   it.link_ = 0;
+}
+
+
+bool 
+ValueInternalMap::equals( const IteratorState &x, const IteratorState &other )
+{
+   return x.map_ == other.map_  
+          &&  x.bucketIndex_ == other.bucketIndex_  
+          &&  x.link_ == other.link_
+          &&  x.itemIndex_ == other.itemIndex_;
+}
+
+
+void 
+ValueInternalMap::incrementBucket( IteratorState &iterator )
+{
+   ++iterator.bucketIndex_;
+   JSON_ASSERT_MESSAGE( iterator.bucketIndex_ <= iterator.map_->bucketsSize_,
+      "ValueInternalMap::increment(): attempting to iterate beyond end." );
+   if ( iterator.bucketIndex_ == iterator.map_->bucketsSize_ )
+      iterator.link_ = 0;
+   else
+      iterator.link_ = &(iterator.map_->buckets_[iterator.bucketIndex_]);
+   iterator.itemIndex_ = 0;
+}
+
+
+void 
+ValueInternalMap::increment( IteratorState &iterator )
+{
+   JSON_ASSERT_MESSAGE( iterator.map_, "Attempting to iterator using invalid iterator." );
+   ++iterator.itemIndex_;
+   if ( iterator.itemIndex_ == ValueInternalLink::itemPerLink )
+   {
+      JSON_ASSERT_MESSAGE( iterator.link_ != 0,
+         "ValueInternalMap::increment(): attempting to iterate beyond end." );
+      iterator.link_ = iterator.link_->next_;
+      if ( iterator.link_ == 0 )
+         incrementBucket( iterator );
+   }
+   else if ( iterator.link_->items_[iterator.itemIndex_].isItemAvailable() )
+   {
+      incrementBucket( iterator );
+   }
+}
+
+
+void 
+ValueInternalMap::decrement( IteratorState &iterator )
+{
+   if ( iterator.itemIndex_ == 0 )
+   {
+      JSON_ASSERT_MESSAGE( iterator.map_, "Attempting to iterate using invalid iterator." );
+      if ( iterator.link_ == &iterator.map_->buckets_[iterator.bucketIndex_] )
+      {
+         JSON_ASSERT_MESSAGE( iterator.bucketIndex_ > 0, "Attempting to iterate beyond beginning." );
+         --(iterator.bucketIndex_);
+      }
+      iterator.link_ = iterator.link_->previous_;
+      iterator.itemIndex_ = ValueInternalLink::itemPerLink - 1;
+   }
+}
+
+
+const char *
+ValueInternalMap::key( const IteratorState &iterator )
+{
+   JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." );
+   return iterator.link_->keys_[iterator.itemIndex_];
+}
+
+const char *
+ValueInternalMap::key( const IteratorState &iterator, bool &isStatic )
+{
+   JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." );
+   isStatic = iterator.link_->items_[iterator.itemIndex_].isMemberNameStatic();
+   return iterator.link_->keys_[iterator.itemIndex_];
+}
+
+
+Value &
+ValueInternalMap::value( const IteratorState &iterator )
+{
+   JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." );
+   return iterator.link_->items_[iterator.itemIndex_];
+}
+
+
+int 
+ValueInternalMap::distance( const IteratorState &x, const IteratorState &y )
+{
+   int offset = 0;
+   IteratorState it = x;
+   while ( !equals( it, y ) )
+      increment( it );
+   return offset;
+}

+ 885 - 0
jsoncpp-src-0.5.0/src/lib_json/json_reader.cpp

@@ -0,0 +1,885 @@
+#include <json/reader.h>
+#include <json/value.h>
+#include <utility>
+#include <cstdio>
+#include <cassert>
+#include <cstring>
+#include <iostream>
+#include <stdexcept>
+
+#if _MSC_VER >= 1400 // VC++ 8.0
+#pragma warning( disable : 4996 )   // disable warning about strdup being deprecated.
+#endif
+
+namespace Json {
+
+// Implementation of class Features
+// ////////////////////////////////
+
+Features::Features()
+   : allowComments_( true )
+   , strictRoot_( false )
+{
+}
+
+
+Features 
+Features::all()
+{
+   return Features();
+}
+
+
+Features 
+Features::strictMode()
+{
+   Features features;
+   features.allowComments_ = false;
+   features.strictRoot_ = true;
+   return features;
+}
+
+// Implementation of class Reader
+// ////////////////////////////////
+
+
+static inline bool 
+in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4 )
+{
+   return c == c1  ||  c == c2  ||  c == c3  ||  c == c4;
+}
+
+static inline bool 
+in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5 )
+{
+   return c == c1  ||  c == c2  ||  c == c3  ||  c == c4  ||  c == c5;
+}
+
+
+static bool 
+containsNewLine( Reader::Location begin, 
+                 Reader::Location end )
+{
+   for ( ;begin < end; ++begin )
+      if ( *begin == '\n'  ||  *begin == '\r' )
+         return true;
+   return false;
+}
+
+static std::string codePointToUTF8(unsigned int cp)
+{
+   std::string result;
+   
+   // based on description from http://en.wikipedia.org/wiki/UTF-8
+
+   if (cp <= 0x7f) 
+   {
+      result.resize(1);
+      result[0] = static_cast<char>(cp);
+   } 
+   else if (cp <= 0x7FF) 
+   {
+      result.resize(2);
+      result[1] = static_cast<char>(0x80 | (0x3f & cp));
+      result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
+   } 
+   else if (cp <= 0xFFFF) 
+   {
+      result.resize(3);
+      result[2] = static_cast<char>(0x80 | (0x3f & cp));
+      result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
+      result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
+   }
+   else if (cp <= 0x10FFFF) 
+   {
+      result.resize(4);
+      result[3] = static_cast<char>(0x80 | (0x3f & cp));
+      result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
+      result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
+      result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
+   }
+
+   return result;
+}
+
+
+// Class Reader
+// //////////////////////////////////////////////////////////////////
+
+Reader::Reader()
+   : features_( Features::all() )
+{
+}
+
+
+Reader::Reader( const Features &features )
+   : features_( features )
+{
+}
+
+
+bool
+Reader::parse( const std::string &document, 
+               Value &root,
+               bool collectComments )
+{
+   document_ = document;
+   const char *begin = document_.c_str();
+   const char *end = begin + document_.length();
+   return parse( begin, end, root, collectComments );
+}
+
+
+bool
+Reader::parse( std::istream& sin,
+               Value &root,
+               bool collectComments )
+{
+   //std::istream_iterator<char> begin(sin);
+   //std::istream_iterator<char> end;
+   // Those would allow streamed input from a file, if parse() were a
+   // template function.
+
+   // Since std::string is reference-counted, this at least does not
+   // create an extra copy.
+   std::string doc;
+   std::getline(sin, doc, (char)EOF);
+   return parse( doc, root, collectComments );
+}
+
+bool 
+Reader::parse( const char *beginDoc, const char *endDoc, 
+               Value &root,
+               bool collectComments )
+{
+   if ( !features_.allowComments_ )
+   {
+      collectComments = false;
+   }
+
+   begin_ = beginDoc;
+   end_ = endDoc;
+   collectComments_ = collectComments;
+   current_ = begin_;
+   lastValueEnd_ = 0;
+   lastValue_ = 0;
+   commentsBefore_ = "";
+   errors_.clear();
+   while ( !nodes_.empty() )
+      nodes_.pop();
+   nodes_.push( &root );
+   
+   bool successful = readValue();
+   Token token;
+   skipCommentTokens( token );
+   if ( collectComments_  &&  !commentsBefore_.empty() )
+      root.setComment( commentsBefore_, commentAfter );
+   if ( features_.strictRoot_ )
+   {
+      if ( !root.isArray()  &&  !root.isObject() )
+      {
+         // Set error location to start of doc, ideally should be first token found in doc
+         token.type_ = tokenError;
+         token.start_ = beginDoc;
+         token.end_ = endDoc;
+         addError( "A valid JSON document must be either an array or an object value.",
+                   token );
+         return false;
+      }
+   }
+   return successful;
+}
+
+
+bool
+Reader::readValue()
+{
+   Token token;
+   skipCommentTokens( token );
+   bool successful = true;
+
+   if ( collectComments_  &&  !commentsBefore_.empty() )
+   {
+      currentValue().setComment( commentsBefore_, commentBefore );
+      commentsBefore_ = "";
+   }
+
+
+   switch ( token.type_ )
+   {
+   case tokenObjectBegin:
+      successful = readObject( token );
+      break;
+   case tokenArrayBegin:
+      successful = readArray( token );
+      break;
+   case tokenNumber:
+      successful = decodeNumber( token );
+      break;
+   case tokenString:
+      successful = decodeString( token );
+      break;
+   case tokenTrue:
+      currentValue() = true;
+      break;
+   case tokenFalse:
+      currentValue() = false;
+      break;
+   case tokenNull:
+      currentValue() = Value();
+      break;
+   default:
+      return addError( "Syntax error: value, object or array expected.", token );
+   }
+
+   if ( collectComments_ )
+   {
+      lastValueEnd_ = current_;
+      lastValue_ = &currentValue();
+   }
+
+   return successful;
+}
+
+
+void 
+Reader::skipCommentTokens( Token &token )
+{
+   if ( features_.allowComments_ )
+   {
+      do
+      {
+         readToken( token );
+      }
+      while ( token.type_ == tokenComment );
+   }
+   else
+   {
+      readToken( token );
+   }
+}
+
+
+bool 
+Reader::expectToken( TokenType type, Token &token, const char *message )
+{
+   readToken( token );
+   if ( token.type_ != type )
+      return addError( message, token );
+   return true;
+}
+
+
+bool 
+Reader::readToken( Token &token )
+{
+   skipSpaces();
+   token.start_ = current_;
+   Char c = getNextChar();
+   bool ok = true;
+   switch ( c )
+   {
+   case '{':
+      token.type_ = tokenObjectBegin;
+      break;
+   case '}':
+      token.type_ = tokenObjectEnd;
+      break;
+   case '[':
+      token.type_ = tokenArrayBegin;
+      break;
+   case ']':
+      token.type_ = tokenArrayEnd;
+      break;
+   case '"':
+      token.type_ = tokenString;
+      ok = readString();
+      break;
+   case '/':
+      token.type_ = tokenComment;
+      ok = readComment();
+      break;
+   case '0':
+   case '1':
+   case '2':
+   case '3':
+   case '4':
+   case '5':
+   case '6':
+   case '7':
+   case '8':
+   case '9':
+   case '-':
+      token.type_ = tokenNumber;
+      readNumber();
+      break;
+   case 't':
+      token.type_ = tokenTrue;
+      ok = match( "rue", 3 );
+      break;
+   case 'f':
+      token.type_ = tokenFalse;
+      ok = match( "alse", 4 );
+      break;
+   case 'n':
+      token.type_ = tokenNull;
+      ok = match( "ull", 3 );
+      break;
+   case ',':
+      token.type_ = tokenArraySeparator;
+      break;
+   case ':':
+      token.type_ = tokenMemberSeparator;
+      break;
+   case 0:
+      token.type_ = tokenEndOfStream;
+      break;
+   default:
+      ok = false;
+      break;
+   }
+   if ( !ok )
+      token.type_ = tokenError;
+   token.end_ = current_;
+   return true;
+}
+
+
+void 
+Reader::skipSpaces()
+{
+   while ( current_ != end_ )
+   {
+      Char c = *current_;
+      if ( c == ' '  ||  c == '\t'  ||  c == '\r'  ||  c == '\n' )
+         ++current_;
+      else
+         break;
+   }
+}
+
+
+bool 
+Reader::match( Location pattern, 
+               int patternLength )
+{
+   if ( end_ - current_ < patternLength )
+      return false;
+   int index = patternLength;
+   while ( index-- )
+      if ( current_[index] != pattern[index] )
+         return false;
+   current_ += patternLength;
+   return true;
+}
+
+
+bool
+Reader::readComment()
+{
+   Location commentBegin = current_ - 1;
+   Char c = getNextChar();
+   bool successful = false;
+   if ( c == '*' )
+      successful = readCStyleComment();
+   else if ( c == '/' )
+      successful = readCppStyleComment();
+   if ( !successful )
+      return false;
+
+   if ( collectComments_ )
+   {
+      CommentPlacement placement = commentBefore;
+      if ( lastValueEnd_  &&  !containsNewLine( lastValueEnd_, commentBegin ) )
+      {
+         if ( c != '*'  ||  !containsNewLine( commentBegin, current_ ) )
+            placement = commentAfterOnSameLine;
+      }
+
+      addComment( commentBegin, current_, placement );
+   }
+   return true;
+}
+
+
+void 
+Reader::addComment( Location begin, 
+                    Location end, 
+                    CommentPlacement placement )
+{
+   assert( collectComments_ );
+   if ( placement == commentAfterOnSameLine )
+   {
+      assert( lastValue_ != 0 );
+      lastValue_->setComment( std::string( begin, end ), placement );
+   }
+   else
+   {
+      if ( !commentsBefore_.empty() )
+         commentsBefore_ += "\n";
+      commentsBefore_ += std::string( begin, end );
+   }
+}
+
+
+bool 
+Reader::readCStyleComment()
+{
+   while ( current_ != end_ )
+   {
+      Char c = getNextChar();
+      if ( c == '*'  &&  *current_ == '/' )
+         break;
+   }
+   return getNextChar() == '/';
+}
+
+
+bool 
+Reader::readCppStyleComment()
+{
+   while ( current_ != end_ )
+   {
+      Char c = getNextChar();
+      if (  c == '\r'  ||  c == '\n' )
+         break;
+   }
+   return true;
+}
+
+
+void 
+Reader::readNumber()
+{
+   while ( current_ != end_ )
+   {
+      if ( !(*current_ >= '0'  &&  *current_ <= '9')  &&
+           !in( *current_, '.', 'e', 'E', '+', '-' ) )
+         break;
+      ++current_;
+   }
+}
+
+bool
+Reader::readString()
+{
+   Char c = 0;
+   while ( current_ != end_ )
+   {
+      c = getNextChar();
+      if ( c == '\\' )
+         getNextChar();
+      else if ( c == '"' )
+         break;
+   }
+   return c == '"';
+}
+
+
+bool 
+Reader::readObject( Token &tokenStart )
+{
+   Token tokenName;
+   std::string name;
+   currentValue() = Value( objectValue );
+   while ( readToken( tokenName ) )
+   {
+      bool initialTokenOk = true;
+      while ( tokenName.type_ == tokenComment  &&  initialTokenOk )
+         initialTokenOk = readToken( tokenName );
+      if  ( !initialTokenOk )
+         break;
+      if ( tokenName.type_ == tokenObjectEnd  &&  name.empty() )  // empty object
+         return true;
+      if ( tokenName.type_ != tokenString )
+         break;
+      
+      name = "";
+      if ( !decodeString( tokenName, name ) )
+         return recoverFromError( tokenObjectEnd );
+
+      Token colon;
+      if ( !readToken( colon ) ||  colon.type_ != tokenMemberSeparator )
+      {
+         return addErrorAndRecover( "Missing ':' after object member name", 
+                                    colon, 
+                                    tokenObjectEnd );
+      }
+      Value &value = currentValue()[ name ];
+      nodes_.push( &value );
+      bool ok = readValue();
+      nodes_.pop();
+      if ( !ok ) // error already set
+         return recoverFromError( tokenObjectEnd );
+
+      Token comma;
+      if ( !readToken( comma )
+            ||  ( comma.type_ != tokenObjectEnd  &&  
+                  comma.type_ != tokenArraySeparator &&
+		  comma.type_ != tokenComment ) )
+      {
+         return addErrorAndRecover( "Missing ',' or '}' in object declaration", 
+                                    comma, 
+                                    tokenObjectEnd );
+      }
+      bool finalizeTokenOk = true;
+      while ( comma.type_ == tokenComment &&
+              finalizeTokenOk )
+         finalizeTokenOk = readToken( comma );
+      if ( comma.type_ == tokenObjectEnd )
+         return true;
+   }
+   return addErrorAndRecover( "Missing '}' or object member name", 
+                              tokenName, 
+                              tokenObjectEnd );
+}
+
+
+bool 
+Reader::readArray( Token &tokenStart )
+{
+   currentValue() = Value( arrayValue );
+   skipSpaces();
+   if ( *current_ == ']' ) // empty array
+   {
+      Token endArray;
+      readToken( endArray );
+      return true;
+   }
+   int index = 0;
+   while ( true )
+   {
+      Value &value = currentValue()[ index++ ];
+      nodes_.push( &value );
+      bool ok = readValue();
+      nodes_.pop();
+      if ( !ok ) // error already set
+         return recoverFromError( tokenArrayEnd );
+
+      Token token;
+      // Accept Comment after last item in the array.
+      ok = readToken( token );
+      while ( token.type_ == tokenComment  &&  ok )
+      {
+         ok = readToken( token );
+      }
+      bool badTokenType = ( token.type_ == tokenArraySeparator  &&  
+                            token.type_ == tokenArrayEnd );
+      if ( !ok  ||  badTokenType )
+      {
+         return addErrorAndRecover( "Missing ',' or ']' in array declaration", 
+                                    token, 
+                                    tokenArrayEnd );
+      }
+      if ( token.type_ == tokenArrayEnd )
+         break;
+   }
+   return true;
+}
+
+
+bool 
+Reader::decodeNumber( Token &token )
+{
+   bool isDouble = false;
+   for ( Location inspect = token.start_; inspect != token.end_; ++inspect )
+   {
+      isDouble = isDouble  
+                 ||  in( *inspect, '.', 'e', 'E', '+' )  
+                 ||  ( *inspect == '-'  &&  inspect != token.start_ );
+   }
+   if ( isDouble )
+      return decodeDouble( token );
+   Location current = token.start_;
+   bool isNegative = *current == '-';
+   if ( isNegative )
+      ++current;
+   Value::UInt threshold = (isNegative ? Value::UInt(-Value::minInt) 
+                                       : Value::maxUInt) / 10;
+   Value::UInt value = 0;
+   while ( current < token.end_ )
+   {
+      Char c = *current++;
+      if ( c < '0'  ||  c > '9' )
+         return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token );
+      if ( value >= threshold )
+         return decodeDouble( token );
+      value = value * 10 + Value::UInt(c - '0');
+   }
+   if ( isNegative )
+      currentValue() = -Value::Int( value );
+   else if ( value <= Value::UInt(Value::maxInt) )
+      currentValue() = Value::Int( value );
+   else
+      currentValue() = value;
+   return true;
+}
+
+
+bool 
+Reader::decodeDouble( Token &token )
+{
+   double value = 0;
+   const int bufferSize = 32;
+   int count;
+   int length = int(token.end_ - token.start_);
+   if ( length <= bufferSize )
+   {
+      Char buffer[bufferSize];
+      memcpy( buffer, token.start_, length );
+      buffer[length] = 0;
+      count = sscanf( buffer, "%lf", &value );
+   }
+   else
+   {
+      std::string buffer( token.start_, token.end_ );
+      count = sscanf( buffer.c_str(), "%lf", &value );
+   }
+
+   if ( count != 1 )
+      return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token );
+   currentValue() = value;
+   return true;
+}
+
+
+bool 
+Reader::decodeString( Token &token )
+{
+   std::string decoded;
+   if ( !decodeString( token, decoded ) )
+      return false;
+   currentValue() = decoded;
+   return true;
+}
+
+
+bool 
+Reader::decodeString( Token &token, std::string &decoded )
+{
+   decoded.reserve( token.end_ - token.start_ - 2 );
+   Location current = token.start_ + 1; // skip '"'
+   Location end = token.end_ - 1;      // do not include '"'
+   while ( current != end )
+   {
+      Char c = *current++;
+      if ( c == '"' )
+         break;
+      else if ( c == '\\' )
+      {
+         if ( current == end )
+            return addError( "Empty escape sequence in string", token, current );
+         Char escape = *current++;
+         switch ( escape )
+         {
+         case '"': decoded += '"'; break;
+         case '/': decoded += '/'; break;
+         case '\\': decoded += '\\'; break;
+         case 'b': decoded += '\b'; break;
+         case 'f': decoded += '\f'; break;
+         case 'n': decoded += '\n'; break;
+         case 'r': decoded += '\r'; break;
+         case 't': decoded += '\t'; break;
+         case 'u':
+            {
+               unsigned int unicode;
+               if ( !decodeUnicodeCodePoint( token, current, end, unicode ) )
+                  return false;
+               decoded += codePointToUTF8(unicode);
+            }
+            break;
+         default:
+            return addError( "Bad escape sequence in string", token, current );
+         }
+      }
+      else
+      {
+         decoded += c;
+      }
+   }
+   return true;
+}
+
+bool
+Reader::decodeUnicodeCodePoint( Token &token, 
+                                     Location &current, 
+                                     Location end, 
+                                     unsigned int &unicode )
+{
+
+   if ( !decodeUnicodeEscapeSequence( token, current, end, unicode ) )
+      return false;
+   if (unicode >= 0xD800 && unicode <= 0xDBFF)
+   {
+      // surrogate pairs
+      if (end - current < 6)
+         return addError( "additional six characters expected to parse unicode surrogate pair.", token, current );
+      unsigned int surrogatePair;
+      if (*(current++) == '\\' && *(current++)== 'u')
+      {
+         if (decodeUnicodeEscapeSequence( token, current, end, surrogatePair ))
+         {
+            unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
+         } 
+         else
+            return false;
+      } 
+      else
+         return addError( "expecting another \\u token to begin the second half of a unicode surrogate pair", token, current );
+   }
+   return true;
+}
+
+bool 
+Reader::decodeUnicodeEscapeSequence( Token &token, 
+                                     Location &current, 
+                                     Location end, 
+                                     unsigned int &unicode )
+{
+   if ( end - current < 4 )
+      return addError( "Bad unicode escape sequence in string: four digits expected.", token, current );
+   unicode = 0;
+   for ( int index =0; index < 4; ++index )
+   {
+      Char c = *current++;
+      unicode *= 16;
+      if ( c >= '0'  &&  c <= '9' )
+         unicode += c - '0';
+      else if ( c >= 'a'  &&  c <= 'f' )
+         unicode += c - 'a' + 10;
+      else if ( c >= 'A'  &&  c <= 'F' )
+         unicode += c - 'A' + 10;
+      else
+         return addError( "Bad unicode escape sequence in string: hexadecimal digit expected.", token, current );
+   }
+   return true;
+}
+
+
+bool 
+Reader::addError( const std::string &message, 
+                  Token &token,
+                  Location extra )
+{
+   ErrorInfo info;
+   info.token_ = token;
+   info.message_ = message;
+   info.extra_ = extra;
+   errors_.push_back( info );
+   return false;
+}
+
+
+bool 
+Reader::recoverFromError( TokenType skipUntilToken )
+{
+   int errorCount = int(errors_.size());
+   Token skip;
+   while ( true )
+   {
+      if ( !readToken(skip) )
+         errors_.resize( errorCount ); // discard errors caused by recovery
+      if ( skip.type_ == skipUntilToken  ||  skip.type_ == tokenEndOfStream )
+         break;
+   }
+   errors_.resize( errorCount );
+   return false;
+}
+
+
+bool 
+Reader::addErrorAndRecover( const std::string &message, 
+                            Token &token,
+                            TokenType skipUntilToken )
+{
+   addError( message, token );
+   return recoverFromError( skipUntilToken );
+}
+
+
+Value &
+Reader::currentValue()
+{
+   return *(nodes_.top());
+}
+
+
+Reader::Char 
+Reader::getNextChar()
+{
+   if ( current_ == end_ )
+      return 0;
+   return *current_++;
+}
+
+
+void 
+Reader::getLocationLineAndColumn( Location location,
+                                  int &line,
+                                  int &column ) const
+{
+   Location current = begin_;
+   Location lastLineStart = current;
+   line = 0;
+   while ( current < location  &&  current != end_ )
+   {
+      Char c = *current++;
+      if ( c == '\r' )
+      {
+         if ( *current == '\n' )
+            ++current;
+         lastLineStart = current;
+         ++line;
+      }
+      else if ( c == '\n' )
+      {
+         lastLineStart = current;
+         ++line;
+      }
+   }
+   // column & line start at 1
+   column = int(location - lastLineStart) + 1;
+   ++line;
+}
+
+
+std::string
+Reader::getLocationLineAndColumn( Location location ) const
+{
+   int line, column;
+   getLocationLineAndColumn( location, line, column );
+   char buffer[18+16+16+1];
+   sprintf( buffer, "Line %d, Column %d", line, column );
+   return buffer;
+}
+
+
+std::string 
+Reader::getFormatedErrorMessages() const
+{
+   std::string formattedMessage;
+   for ( Errors::const_iterator itError = errors_.begin();
+         itError != errors_.end();
+         ++itError )
+   {
+      const ErrorInfo &error = *itError;
+      formattedMessage += "* " + getLocationLineAndColumn( error.token_.start_ ) + "\n";
+      formattedMessage += "  " + error.message_ + "\n";
+      if ( error.extra_ )
+         formattedMessage += "See " + getLocationLineAndColumn( error.extra_ ) + " for detail.\n";
+   }
+   return formattedMessage;
+}
+
+
+std::istream& operator>>( std::istream &sin, Value &root )
+{
+    Json::Reader reader;
+    bool ok = reader.parse(sin, root, true);
+    //JSON_ASSERT( ok );
+    if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages());
+    return sin;
+}
+
+
+} // namespace Json

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1718 - 0
jsoncpp-src-0.5.0/src/lib_json/json_value.cpp


+ 292 - 0
jsoncpp-src-0.5.0/src/lib_json/json_valueiterator.inl

@@ -0,0 +1,292 @@
+// included by json_value.cpp
+// everything is within Json namespace
+
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueIteratorBase
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+ValueIteratorBase::ValueIteratorBase()
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   : current_()
+   , isNull_( true )
+{
+}
+#else
+   : isArray_( true )
+   , isNull_( true )
+{
+   iterator_.array_ = ValueInternalArray::IteratorState();
+}
+#endif
+
+
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator &current )
+   : current_( current )
+   , isNull_( false )
+{
+}
+#else
+ValueIteratorBase::ValueIteratorBase( const ValueInternalArray::IteratorState &state )
+   : isArray_( true )
+{
+   iterator_.array_ = state;
+}
+
+
+ValueIteratorBase::ValueIteratorBase( const ValueInternalMap::IteratorState &state )
+   : isArray_( false )
+{
+   iterator_.map_ = state;
+}
+#endif
+
+Value &
+ValueIteratorBase::deref() const
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   return current_->second;
+#else
+   if ( isArray_ )
+      return ValueInternalArray::dereference( iterator_.array_ );
+   return ValueInternalMap::value( iterator_.map_ );
+#endif
+}
+
+
+void 
+ValueIteratorBase::increment()
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   ++current_;
+#else
+   if ( isArray_ )
+      ValueInternalArray::increment( iterator_.array_ );
+   ValueInternalMap::increment( iterator_.map_ );
+#endif
+}
+
+
+void 
+ValueIteratorBase::decrement()
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   --current_;
+#else
+   if ( isArray_ )
+      ValueInternalArray::decrement( iterator_.array_ );
+   ValueInternalMap::decrement( iterator_.map_ );
+#endif
+}
+
+
+ValueIteratorBase::difference_type 
+ValueIteratorBase::computeDistance( const SelfType &other ) const
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+# ifdef JSON_USE_CPPTL_SMALLMAP
+   return current_ - other.current_;
+# else
+   // Iterator for null value are initialized using the default
+   // constructor, which initialize current_ to the default
+   // std::map::iterator. As begin() and end() are two instance 
+   // of the default std::map::iterator, they can not be compared.
+   // To allow this, we handle this comparison specifically.
+   if ( isNull_  &&  other.isNull_ )
+   {
+      return 0;
+   }
+
+
+   // Usage of std::distance is not portable (does not compile with Sun Studio 12 RogueWave STL,
+   // which is the one used by default).
+   // Using a portable hand-made version for non random iterator instead:
+   //   return difference_type( std::distance( current_, other.current_ ) );
+   difference_type myDistance = 0;
+   for ( Value::ObjectValues::iterator it = current_; it != other.current_; ++it )
+   {
+      ++myDistance;
+   }
+   return myDistance;
+# endif
+#else
+   if ( isArray_ )
+      return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ );
+   return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ );
+#endif
+}
+
+
+bool 
+ValueIteratorBase::isEqual( const SelfType &other ) const
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   if ( isNull_ )
+   {
+      return other.isNull_;
+   }
+   return current_ == other.current_;
+#else
+   if ( isArray_ )
+      return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ );
+   return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ );
+#endif
+}
+
+
+void 
+ValueIteratorBase::copy( const SelfType &other )
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   current_ = other.current_;
+#else
+   if ( isArray_ )
+      iterator_.array_ = other.iterator_.array_;
+   iterator_.map_ = other.iterator_.map_;
+#endif
+}
+
+
+Value 
+ValueIteratorBase::key() const
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   const Value::CZString czstring = (*current_).first;
+   if ( czstring.c_str() )
+   {
+      if ( czstring.isStaticString() )
+         return Value( StaticString( czstring.c_str() ) );
+      return Value( czstring.c_str() );
+   }
+   return Value( czstring.index() );
+#else
+   if ( isArray_ )
+      return Value( ValueInternalArray::indexOf( iterator_.array_ ) );
+   bool isStatic;
+   const char *memberName = ValueInternalMap::key( iterator_.map_, isStatic );
+   if ( isStatic )
+      return Value( StaticString( memberName ) );
+   return Value( memberName );
+#endif
+}
+
+
+UInt 
+ValueIteratorBase::index() const
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   const Value::CZString czstring = (*current_).first;
+   if ( !czstring.c_str() )
+      return czstring.index();
+   return Value::UInt( -1 );
+#else
+   if ( isArray_ )
+      return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) );
+   return Value::UInt( -1 );
+#endif
+}
+
+
+const char *
+ValueIteratorBase::memberName() const
+{
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+   const char *name = (*current_).first.c_str();
+   return name ? name : "";
+#else
+   if ( !isArray_ )
+      return ValueInternalMap::key( iterator_.map_ );
+   return "";
+#endif
+}
+
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueConstIterator
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+ValueConstIterator::ValueConstIterator()
+{
+}
+
+
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator &current )
+   : ValueIteratorBase( current )
+{
+}
+#else
+ValueConstIterator::ValueConstIterator( const ValueInternalArray::IteratorState &state )
+   : ValueIteratorBase( state )
+{
+}
+
+ValueConstIterator::ValueConstIterator( const ValueInternalMap::IteratorState &state )
+   : ValueIteratorBase( state )
+{
+}
+#endif
+
+ValueConstIterator &
+ValueConstIterator::operator =( const ValueIteratorBase &other )
+{
+   copy( other );
+   return *this;
+}
+
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueIterator
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+ValueIterator::ValueIterator()
+{
+}
+
+
+#ifndef JSON_VALUE_USE_INTERNAL_MAP
+ValueIterator::ValueIterator( const Value::ObjectValues::iterator &current )
+   : ValueIteratorBase( current )
+{
+}
+#else
+ValueIterator::ValueIterator( const ValueInternalArray::IteratorState &state )
+   : ValueIteratorBase( state )
+{
+}
+
+ValueIterator::ValueIterator( const ValueInternalMap::IteratorState &state )
+   : ValueIteratorBase( state )
+{
+}
+#endif
+
+ValueIterator::ValueIterator( const ValueConstIterator &other )
+   : ValueIteratorBase( other )
+{
+}
+
+ValueIterator::ValueIterator( const ValueIterator &other )
+   : ValueIteratorBase( other )
+{
+}
+
+ValueIterator &
+ValueIterator::operator =( const SelfType &other )
+{
+   copy( other );
+   return *this;
+}

+ 829 - 0
jsoncpp-src-0.5.0/src/lib_json/json_writer.cpp

@@ -0,0 +1,829 @@
+#include <json/writer.h>
+#include <utility>
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+
+#if _MSC_VER >= 1400 // VC++ 8.0
+#pragma warning( disable : 4996 )   // disable warning about strdup being deprecated.
+#endif
+
+namespace Json {
+
+static bool isControlCharacter(char ch)
+{
+   return ch > 0 && ch <= 0x1F;
+}
+
+static bool containsControlCharacter( const char* str )
+{
+   while ( *str ) 
+   {
+      if ( isControlCharacter( *(str++) ) )
+         return true;
+   }
+   return false;
+}
+static void uintToString( unsigned int value, 
+                          char *&current )
+{
+   *--current = 0;
+   do
+   {
+      *--current = (value % 10) + '0';
+      value /= 10;
+   }
+   while ( value != 0 );
+}
+
+std::string valueToString( Int value )
+{
+   char buffer[32];
+   char *current = buffer + sizeof(buffer);
+   bool isNegative = value < 0;
+   if ( isNegative )
+      value = -value;
+   uintToString( UInt(value), current );
+   if ( isNegative )
+      *--current = '-';
+   assert( current >= buffer );
+   return current;
+}
+
+
+std::string valueToString( UInt value )
+{
+   char buffer[32];
+   char *current = buffer + sizeof(buffer);
+   uintToString( value, current );
+   assert( current >= buffer );
+   return current;
+}
+
+std::string valueToString( double value )
+{
+   char buffer[32];
+#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning. 
+   sprintf_s(buffer, sizeof(buffer), "%#.16g", value); 
+#else	
+   sprintf(buffer, "%#.16g", value); 
+#endif
+   char* ch = buffer + strlen(buffer) - 1;
+   if (*ch != '0') return buffer; // nothing to truncate, so save time
+   while(ch > buffer && *ch == '0'){
+     --ch;
+   }
+   char* last_nonzero = ch;
+   while(ch >= buffer){
+     switch(*ch){
+     case '0':
+     case '1':
+     case '2':
+     case '3':
+     case '4':
+     case '5':
+     case '6':
+     case '7':
+     case '8':
+     case '9':
+       --ch;
+       continue;
+     case '.':
+       // Truncate zeroes to save bytes in output, but keep one.
+       *(last_nonzero+2) = '\0';
+       return buffer;
+     default:
+       return buffer;
+     }
+   }
+   return buffer;
+}
+
+
+std::string valueToString( bool value )
+{
+   return value ? "true" : "false";
+}
+
+std::string valueToQuotedString( const char *value )
+{
+   // Not sure how to handle unicode...
+   if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL && !containsControlCharacter( value ))
+      return std::string("\"") + value + "\"";
+   // We have to walk value and escape any special characters.
+   // Appending to std::string is not efficient, but this should be rare.
+   // (Note: forward slashes are *not* rare, but I am not escaping them.)
+   unsigned maxsize = strlen(value)*2 + 3; // allescaped+quotes+NULL
+   std::string result;
+   result.reserve(maxsize); // to avoid lots of mallocs
+   result += "\"";
+   for (const char* c=value; *c != 0; ++c)
+   {
+      switch(*c)
+      {
+         case '\"':
+            result += "\\\"";
+            break;
+         case '\\':
+            result += "\\\\";
+            break;
+         case '\b':
+            result += "\\b";
+            break;
+         case '\f':
+            result += "\\f";
+            break;
+         case '\n':
+            result += "\\n";
+            break;
+         case '\r':
+            result += "\\r";
+            break;
+         case '\t':
+            result += "\\t";
+            break;
+         //case '/':
+            // Even though \/ is considered a legal escape in JSON, a bare
+            // slash is also legal, so I see no reason to escape it.
+            // (I hope I am not misunderstanding something.
+            // blep notes: actually escaping \/ may be useful in javascript to avoid </ 
+            // sequence.
+            // Should add a flag to allow this compatibility mode and prevent this 
+            // sequence from occurring.
+         default:
+            if ( isControlCharacter( *c ) )
+            {
+               std::ostringstream oss;
+               oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*c);
+               result += oss.str();
+            }
+            else
+            {
+               result += *c;
+            }
+            break;
+      }
+   }
+   result += "\"";
+   return result;
+}
+
+// Class Writer
+// //////////////////////////////////////////////////////////////////
+Writer::~Writer()
+{
+}
+
+
+// Class FastWriter
+// //////////////////////////////////////////////////////////////////
+
+FastWriter::FastWriter()
+   : yamlCompatiblityEnabled_( false )
+{
+}
+
+
+void 
+FastWriter::enableYAMLCompatibility()
+{
+   yamlCompatiblityEnabled_ = true;
+}
+
+
+std::string 
+FastWriter::write( const Value &root )
+{
+   document_ = "";
+   writeValue( root );
+   document_ += "\n";
+   return document_;
+}
+
+
+void 
+FastWriter::writeValue( const Value &value )
+{
+   switch ( value.type() )
+   {
+   case nullValue:
+      document_ += "null";
+      break;
+   case intValue:
+      document_ += valueToString( value.asInt() );
+      break;
+   case uintValue:
+      document_ += valueToString( value.asUInt() );
+      break;
+   case realValue:
+      document_ += valueToString( value.asDouble() );
+      break;
+   case stringValue:
+      document_ += valueToQuotedString( value.asCString() );
+      break;
+   case booleanValue:
+      document_ += valueToString( value.asBool() );
+      break;
+   case arrayValue:
+      {
+         document_ += "[";
+         int size = value.size();
+         for ( int index =0; index < size; ++index )
+         {
+            if ( index > 0 )
+               document_ += ",";
+            writeValue( value[index] );
+         }
+         document_ += "]";
+      }
+      break;
+   case objectValue:
+      {
+         Value::Members members( value.getMemberNames() );
+         document_ += "{";
+         for ( Value::Members::iterator it = members.begin(); 
+               it != members.end(); 
+               ++it )
+         {
+            const std::string &name = *it;
+            if ( it != members.begin() )
+               document_ += ",";
+            document_ += valueToQuotedString( name.c_str() );
+            document_ += yamlCompatiblityEnabled_ ? ": " 
+                                                  : ":";
+            writeValue( value[name] );
+         }
+         document_ += "}";
+      }
+      break;
+   }
+}
+
+
+// Class StyledWriter
+// //////////////////////////////////////////////////////////////////
+
+StyledWriter::StyledWriter()
+   : rightMargin_( 74 )
+   , indentSize_( 3 )
+{
+}
+
+
+std::string 
+StyledWriter::write( const Value &root )
+{
+   document_ = "";
+   addChildValues_ = false;
+   indentString_ = "";
+   writeCommentBeforeValue( root );
+   writeValue( root );
+   writeCommentAfterValueOnSameLine( root );
+   document_ += "\n";
+   return document_;
+}
+
+
+void 
+StyledWriter::writeValue( const Value &value )
+{
+   switch ( value.type() )
+   {
+   case nullValue:
+      pushValue( "null" );
+      break;
+   case intValue:
+      pushValue( valueToString( value.asInt() ) );
+      break;
+   case uintValue:
+      pushValue( valueToString( value.asUInt() ) );
+      break;
+   case realValue:
+      pushValue( valueToString( value.asDouble() ) );
+      break;
+   case stringValue:
+      pushValue( valueToQuotedString( value.asCString() ) );
+      break;
+   case booleanValue:
+      pushValue( valueToString( value.asBool() ) );
+      break;
+   case arrayValue:
+      writeArrayValue( value);
+      break;
+   case objectValue:
+      {
+         Value::Members members( value.getMemberNames() );
+         if ( members.empty() )
+            pushValue( "{}" );
+         else
+         {
+            writeWithIndent( "{" );
+            indent();
+            Value::Members::iterator it = members.begin();
+            while ( true )
+            {
+               const std::string &name = *it;
+               const Value &childValue = value[name];
+               writeCommentBeforeValue( childValue );
+               writeWithIndent( valueToQuotedString( name.c_str() ) );
+               document_ += " : ";
+               writeValue( childValue );
+               if ( ++it == members.end() )
+               {
+                  writeCommentAfterValueOnSameLine( childValue );
+                  break;
+               }
+               document_ += ",";
+               writeCommentAfterValueOnSameLine( childValue );
+            }
+            unindent();
+            writeWithIndent( "}" );
+         }
+      }
+      break;
+   }
+}
+
+
+void 
+StyledWriter::writeArrayValue( const Value &value )
+{
+   unsigned size = value.size();
+   if ( size == 0 )
+      pushValue( "[]" );
+   else
+   {
+      bool isArrayMultiLine = isMultineArray( value );
+      if ( isArrayMultiLine )
+      {
+         writeWithIndent( "[" );
+         indent();
+         bool hasChildValue = !childValues_.empty();
+         unsigned index =0;
+         while ( true )
+         {
+            const Value &childValue = value[index];
+            writeCommentBeforeValue( childValue );
+            if ( hasChildValue )
+               writeWithIndent( childValues_[index] );
+            else
+            {
+               writeIndent();
+               writeValue( childValue );
+            }
+            if ( ++index == size )
+            {
+               writeCommentAfterValueOnSameLine( childValue );
+               break;
+            }
+            document_ += ",";
+            writeCommentAfterValueOnSameLine( childValue );
+         }
+         unindent();
+         writeWithIndent( "]" );
+      }
+      else // output on a single line
+      {
+         assert( childValues_.size() == size );
+         document_ += "[ ";
+         for ( unsigned index =0; index < size; ++index )
+         {
+            if ( index > 0 )
+               document_ += ", ";
+            document_ += childValues_[index];
+         }
+         document_ += " ]";
+      }
+   }
+}
+
+
+bool 
+StyledWriter::isMultineArray( const Value &value )
+{
+   int size = value.size();
+   bool isMultiLine = size*3 >= rightMargin_ ;
+   childValues_.clear();
+   for ( int index =0; index < size  &&  !isMultiLine; ++index )
+   {
+      const Value &childValue = value[index];
+      isMultiLine = isMultiLine  ||
+                     ( (childValue.isArray()  ||  childValue.isObject())  &&  
+                        childValue.size() > 0 );
+   }
+   if ( !isMultiLine ) // check if line length > max line length
+   {
+      childValues_.reserve( size );
+      addChildValues_ = true;
+      int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]'
+      for ( int index =0; index < size  &&  !isMultiLine; ++index )
+      {
+         writeValue( value[index] );
+         lineLength += int( childValues_[index].length() );
+         isMultiLine = isMultiLine  &&  hasCommentForValue( value[index] );
+      }
+      addChildValues_ = false;
+      isMultiLine = isMultiLine  ||  lineLength >= rightMargin_;
+   }
+   return isMultiLine;
+}
+
+
+void 
+StyledWriter::pushValue( const std::string &value )
+{
+   if ( addChildValues_ )
+      childValues_.push_back( value );
+   else
+      document_ += value;
+}
+
+
+void 
+StyledWriter::writeIndent()
+{
+   if ( !document_.empty() )
+   {
+      char last = document_[document_.length()-1];
+      if ( last == ' ' )     // already indented
+         return;
+      if ( last != '\n' )    // Comments may add new-line
+         document_ += '\n';
+   }
+   document_ += indentString_;
+}
+
+
+void 
+StyledWriter::writeWithIndent( const std::string &value )
+{
+   writeIndent();
+   document_ += value;
+}
+
+
+void 
+StyledWriter::indent()
+{
+   indentString_ += std::string( indentSize_, ' ' );
+}
+
+
+void 
+StyledWriter::unindent()
+{
+   assert( int(indentString_.size()) >= indentSize_ );
+   indentString_.resize( indentString_.size() - indentSize_ );
+}
+
+
+void 
+StyledWriter::writeCommentBeforeValue( const Value &root )
+{
+   if ( !root.hasComment( commentBefore ) )
+      return;
+   document_ += normalizeEOL( root.getComment( commentBefore ) );
+   document_ += "\n";
+}
+
+
+void 
+StyledWriter::writeCommentAfterValueOnSameLine( const Value &root )
+{
+   if ( root.hasComment( commentAfterOnSameLine ) )
+      document_ += " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) );
+
+   if ( root.hasComment( commentAfter ) )
+   {
+      document_ += "\n";
+      document_ += normalizeEOL( root.getComment( commentAfter ) );
+      document_ += "\n";
+   }
+}
+
+
+bool 
+StyledWriter::hasCommentForValue( const Value &value )
+{
+   return value.hasComment( commentBefore )
+          ||  value.hasComment( commentAfterOnSameLine )
+          ||  value.hasComment( commentAfter );
+}
+
+
+std::string 
+StyledWriter::normalizeEOL( const std::string &text )
+{
+   std::string normalized;
+   normalized.reserve( text.length() );
+   const char *begin = text.c_str();
+   const char *end = begin + text.length();
+   const char *current = begin;
+   while ( current != end )
+   {
+      char c = *current++;
+      if ( c == '\r' ) // mac or dos EOL
+      {
+         if ( *current == '\n' ) // convert dos EOL
+            ++current;
+         normalized += '\n';
+      }
+      else // handle unix EOL & other char
+         normalized += c;
+   }
+   return normalized;
+}
+
+
+// Class StyledStreamWriter
+// //////////////////////////////////////////////////////////////////
+
+StyledStreamWriter::StyledStreamWriter( std::string indentation )
+   : document_(NULL)
+   , rightMargin_( 74 )
+   , indentation_( indentation )
+{
+}
+
+
+void
+StyledStreamWriter::write( std::ostream &out, const Value &root )
+{
+   document_ = &out;
+   addChildValues_ = false;
+   indentString_ = "";
+   writeCommentBeforeValue( root );
+   writeValue( root );
+   writeCommentAfterValueOnSameLine( root );
+   *document_ << "\n";
+   document_ = NULL; // Forget the stream, for safety.
+}
+
+
+void 
+StyledStreamWriter::writeValue( const Value &value )
+{
+   switch ( value.type() )
+   {
+   case nullValue:
+      pushValue( "null" );
+      break;
+   case intValue:
+      pushValue( valueToString( value.asInt() ) );
+      break;
+   case uintValue:
+      pushValue( valueToString( value.asUInt() ) );
+      break;
+   case realValue:
+      pushValue( valueToString( value.asDouble() ) );
+      break;
+   case stringValue:
+      pushValue( valueToQuotedString( value.asCString() ) );
+      break;
+   case booleanValue:
+      pushValue( valueToString( value.asBool() ) );
+      break;
+   case arrayValue:
+      writeArrayValue( value);
+      break;
+   case objectValue:
+      {
+         Value::Members members( value.getMemberNames() );
+         if ( members.empty() )
+            pushValue( "{}" );
+         else
+         {
+            writeWithIndent( "{" );
+            indent();
+            Value::Members::iterator it = members.begin();
+            while ( true )
+            {
+               const std::string &name = *it;
+               const Value &childValue = value[name];
+               writeCommentBeforeValue( childValue );
+               writeWithIndent( valueToQuotedString( name.c_str() ) );
+               *document_ << " : ";
+               writeValue( childValue );
+               if ( ++it == members.end() )
+               {
+                  writeCommentAfterValueOnSameLine( childValue );
+                  break;
+               }
+               *document_ << ",";
+               writeCommentAfterValueOnSameLine( childValue );
+            }
+            unindent();
+            writeWithIndent( "}" );
+         }
+      }
+      break;
+   }
+}
+
+
+void 
+StyledStreamWriter::writeArrayValue( const Value &value )
+{
+   unsigned size = value.size();
+   if ( size == 0 )
+      pushValue( "[]" );
+   else
+   {
+      bool isArrayMultiLine = isMultineArray( value );
+      if ( isArrayMultiLine )
+      {
+         writeWithIndent( "[" );
+         indent();
+         bool hasChildValue = !childValues_.empty();
+         unsigned index =0;
+         while ( true )
+         {
+            const Value &childValue = value[index];
+            writeCommentBeforeValue( childValue );
+            if ( hasChildValue )
+               writeWithIndent( childValues_[index] );
+            else
+            {
+	       writeIndent();
+               writeValue( childValue );
+            }
+            if ( ++index == size )
+            {
+               writeCommentAfterValueOnSameLine( childValue );
+               break;
+            }
+            *document_ << ",";
+            writeCommentAfterValueOnSameLine( childValue );
+         }
+         unindent();
+         writeWithIndent( "]" );
+      }
+      else // output on a single line
+      {
+         assert( childValues_.size() == size );
+         *document_ << "[ ";
+         for ( unsigned index =0; index < size; ++index )
+         {
+            if ( index > 0 )
+               *document_ << ", ";
+            *document_ << childValues_[index];
+         }
+         *document_ << " ]";
+      }
+   }
+}
+
+
+bool 
+StyledStreamWriter::isMultineArray( const Value &value )
+{
+   int size = value.size();
+   bool isMultiLine = size*3 >= rightMargin_ ;
+   childValues_.clear();
+   for ( int index =0; index < size  &&  !isMultiLine; ++index )
+   {
+      const Value &childValue = value[index];
+      isMultiLine = isMultiLine  ||
+                     ( (childValue.isArray()  ||  childValue.isObject())  &&  
+                        childValue.size() > 0 );
+   }
+   if ( !isMultiLine ) // check if line length > max line length
+   {
+      childValues_.reserve( size );
+      addChildValues_ = true;
+      int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]'
+      for ( int index =0; index < size  &&  !isMultiLine; ++index )
+      {
+         writeValue( value[index] );
+         lineLength += int( childValues_[index].length() );
+         isMultiLine = isMultiLine  &&  hasCommentForValue( value[index] );
+      }
+      addChildValues_ = false;
+      isMultiLine = isMultiLine  ||  lineLength >= rightMargin_;
+   }
+   return isMultiLine;
+}
+
+
+void 
+StyledStreamWriter::pushValue( const std::string &value )
+{
+   if ( addChildValues_ )
+      childValues_.push_back( value );
+   else
+      *document_ << value;
+}
+
+
+void 
+StyledStreamWriter::writeIndent()
+{
+  /*
+    Some comments in this method would have been nice. ;-)
+
+   if ( !document_.empty() )
+   {
+      char last = document_[document_.length()-1];
+      if ( last == ' ' )     // already indented
+         return;
+      if ( last != '\n' )    // Comments may add new-line
+         *document_ << '\n';
+   }
+  */
+   *document_ << '\n' << indentString_;
+}
+
+
+void 
+StyledStreamWriter::writeWithIndent( const std::string &value )
+{
+   writeIndent();
+   *document_ << value;
+}
+
+
+void 
+StyledStreamWriter::indent()
+{
+   indentString_ += indentation_;
+}
+
+
+void 
+StyledStreamWriter::unindent()
+{
+   assert( indentString_.size() >= indentation_.size() );
+   indentString_.resize( indentString_.size() - indentation_.size() );
+}
+
+
+void 
+StyledStreamWriter::writeCommentBeforeValue( const Value &root )
+{
+   if ( !root.hasComment( commentBefore ) )
+      return;
+   *document_ << normalizeEOL( root.getComment( commentBefore ) );
+   *document_ << "\n";
+}
+
+
+void 
+StyledStreamWriter::writeCommentAfterValueOnSameLine( const Value &root )
+{
+   if ( root.hasComment( commentAfterOnSameLine ) )
+      *document_ << " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) );
+
+   if ( root.hasComment( commentAfter ) )
+   {
+      *document_ << "\n";
+      *document_ << normalizeEOL( root.getComment( commentAfter ) );
+      *document_ << "\n";
+   }
+}
+
+
+bool 
+StyledStreamWriter::hasCommentForValue( const Value &value )
+{
+   return value.hasComment( commentBefore )
+          ||  value.hasComment( commentAfterOnSameLine )
+          ||  value.hasComment( commentAfter );
+}
+
+
+std::string 
+StyledStreamWriter::normalizeEOL( const std::string &text )
+{
+   std::string normalized;
+   normalized.reserve( text.length() );
+   const char *begin = text.c_str();
+   const char *end = begin + text.length();
+   const char *current = begin;
+   while ( current != end )
+   {
+      char c = *current++;
+      if ( c == '\r' ) // mac or dos EOL
+      {
+         if ( *current == '\n' ) // convert dos EOL
+            ++current;
+         normalized += '\n';
+      }
+      else // handle unix EOL & other char
+         normalized += c;
+   }
+   return normalized;
+}
+
+
+std::ostream& operator<<( std::ostream &sout, const Value &root )
+{
+   Json::StyledStreamWriter writer;
+   writer.write(sout, root);
+   return sout;
+}
+
+
+} // namespace Json

+ 8 - 0
jsoncpp-src-0.5.0/src/lib_json/sconscript

@@ -0,0 +1,8 @@
+Import( 'env buildLibrary' )
+
+buildLibrary( env, Split( """
+    json_reader.cpp 
+    json_value.cpp 
+    json_writer.cpp
+     """ ),
+    'json' )