PhmsRequestHead.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "PhmsRequestHead.h"
  2. #include "PhmsLogger.h"
  3. CPhmsRequestHead::CPhmsRequestHead(void)
  4. {
  5. }
  6. CPhmsRequestHead::CPhmsRequestHead(string version, string operationCode, string sessionId, string messageFormat)
  7. :m_sign("00000000000000000000000000000000"), m_version(version),m_operationCode(operationCode),m_sessionId(sessionId),m_messageFormat(messageFormat)
  8. {
  9. }
  10. CPhmsRequestHead::CPhmsRequestHead(CPhmsRequestHead& phmsRequestHead)
  11. {
  12. m_sign = phmsRequestHead.GetSign();
  13. m_version = phmsRequestHead.GetVersion();
  14. m_sessionId = phmsRequestHead.GetSessionId();
  15. m_operationCode = phmsRequestHead.GetOperationCode();
  16. m_messageFormat = phmsRequestHead.GetMessageFormat();
  17. }
  18. CPhmsRequestHead& CPhmsRequestHead::operator=(CPhmsRequestHead& phmsRequestHead)
  19. {
  20. m_sign = phmsRequestHead.GetSign();
  21. m_version = phmsRequestHead.GetVersion();
  22. m_sessionId = phmsRequestHead.GetSessionId();
  23. m_operationCode = phmsRequestHead.GetOperationCode();
  24. m_messageFormat = phmsRequestHead.GetMessageFormat();
  25. return *this;
  26. }
  27. CPhmsRequestHead::~CPhmsRequestHead(void)
  28. {
  29. }
  30. //Getter
  31. string CPhmsRequestHead::GetSign()
  32. {
  33. return m_sign;
  34. }
  35. string CPhmsRequestHead::GetVersion()
  36. {
  37. return m_version;
  38. }
  39. string CPhmsRequestHead::GetOperationCode()
  40. {
  41. return m_operationCode;
  42. }
  43. string CPhmsRequestHead::GetSessionId()
  44. {
  45. return m_sessionId;
  46. }
  47. string CPhmsRequestHead::GetMessageFormat()
  48. {
  49. return m_messageFormat;
  50. }
  51. //Setter
  52. void CPhmsRequestHead::SetSign(string sign)
  53. {
  54. m_sign = sign;
  55. }
  56. void CPhmsRequestHead::SetVersion(string version)
  57. {
  58. m_version = version;
  59. }
  60. void CPhmsRequestHead::SetOperationCode(string operationCode)
  61. {
  62. m_operationCode = operationCode;
  63. }
  64. void CPhmsRequestHead::SetSessionId(string sessionId)
  65. {
  66. m_sessionId = sessionId;
  67. }
  68. void CPhmsRequestHead::SetMessageFormat(string messageFormat)
  69. {
  70. m_messageFormat = messageFormat;
  71. }
  72. bool CPhmsRequestHead::ValidatePhmsRequestHead()
  73. {
  74. if(m_sign.size() != this->SIGN_LENGTH || m_version.size() != this->VERSION_LENGTH ||
  75. m_operationCode.size() != this->OPERATION_LENGTH || m_sessionId.size() != this->SESSIONID_LENGTH ||
  76. m_messageFormat.size() != this->MESSAGEFORMAT_LENGTH)
  77. {
  78. CPhmsLogger::GetPhmsLogger()->WriteLog(m_sign, __FUNCTION__, __FILE__, __LINE__);
  79. CPhmsLogger::GetPhmsLogger()->WriteLog(m_version, __FUNCTION__, __FILE__, __LINE__);
  80. CPhmsLogger::GetPhmsLogger()->WriteLog(m_operationCode, __FUNCTION__, __FILE__, __LINE__);
  81. CPhmsLogger::GetPhmsLogger()->WriteLog(m_sessionId, __FUNCTION__, __FILE__, __LINE__);
  82. CPhmsLogger::GetPhmsLogger()->WriteLog(m_messageFormat, __FUNCTION__, __FILE__, __LINE__);
  83. return false;
  84. }
  85. return true;
  86. }
  87. string CPhmsRequestHead::ToString()
  88. {
  89. string phmsHead;
  90. phmsHead = m_sign + m_version + m_operationCode + m_sessionId + m_messageFormat;
  91. return phmsHead;
  92. }
  93. int CPhmsRequestHead::GetHeadLength()
  94. {
  95. return TOTAL_HEAD_LENGTH;
  96. }
  97. EnumPhmsRequestMessageFormat CPhmsRequestHead::GetPhmsRequestMessageFormat()
  98. {
  99. if(m_messageFormat == "10")
  100. {
  101. return NO_PHMS_REQUEST_BODY;
  102. }
  103. if(m_messageFormat=="11" || m_messageFormat=="12" || m_messageFormat=="13")
  104. {
  105. return HAVE_PHMS_REQUEST_BODY;
  106. }else
  107. {
  108. return WRONG_PHMS_REQUEST_MESSAGE_FORMAT;
  109. }
  110. }