Message.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "servant/Message.h"
  2. #include "servant/ServantProxy.h"
  3. #include "servant/Communicator.h"
  4. namespace tars
  5. {
  6. void ReqMessage::init(CallType eCallType, ServantProxy *prx)
  7. {
  8. eStatus = ReqMessage::REQ_REQ;
  9. eType = eCallType;
  10. bFromRpc = false;
  11. callback = NULL;
  12. proxy = prx;
  13. pObjectProxy = NULL;
  14. request.iRequestId = 1;
  15. response = std::make_shared<ResponsePacket>();
  16. sReqData = std::make_shared<TC_NetWorkBuffer::Buffer>();
  17. pMonitor = NULL;
  18. iBeginTime = TNOWMS;
  19. iEndTime = 0;
  20. adapter = NULL;
  21. bPush = false;
  22. sched = NULL;
  23. iCoroId = 0;
  24. }
  25. const string &ReqMessage::moduleName()
  26. {
  27. return proxy->tars_communicator()->clientConfig().ModuleName;
  28. }
  29. ReqMessage::~ReqMessage()
  30. {
  31. if(deconstructor)
  32. {
  33. deconstructor();
  34. }
  35. if(pMonitor != NULL)
  36. {
  37. delete pMonitor;
  38. pMonitor = NULL;
  39. }
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. void ReqMonitor::wait()
  43. {
  44. if(!bMonitorFin)
  45. {
  46. std::unique_lock<std::mutex> lock(mutex);
  47. if (!bMonitorFin)
  48. {
  49. cond.wait(lock, [&]
  50. { return bMonitorFin || msg->proxy->tars_communicator()->isTerminating(); });
  51. }
  52. }
  53. }
  54. void ReqMonitor::notify()
  55. {
  56. std::unique_lock<std::mutex> lock(mutex);
  57. bMonitorFin = true;
  58. cond.notify_one();
  59. }
  60. }