recordinfo.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "recordinfo.h"
  2. #include "strutil.h"
  3. #include "Event.h"
  4. void HttpsLogCallBack(const char* logtxt) {
  5. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI("HttpsLogCallBack")("HttpsLogCallBack: %s.", logtxt);
  6. }
  7. int post_video_recordinfo_list(unsigned int& uposttime, CSimpleStringA& errormsg, video_record_info_t* pinfo, int itimeout, bool bprintdbg)
  8. {
  9. int iret = -1;
  10. IHttpFunc* client = create_http(HttpsLogCallBack);
  11. RecordInfoHTTPReq req;
  12. req.m_timeOut = itimeout;
  13. if (bprintdbg) {
  14. req.m_printDbg = true;
  15. }
  16. const char* pData = pinfo->strServerURL.GetData();
  17. if (pData) {
  18. req.m_url = pData;
  19. }
  20. pData = pinfo->strAPI.GetData();
  21. if (pData) {
  22. req.m_url.append(pData);
  23. }
  24. Json::Value rootReq;
  25. pData = pinfo->strTerminalNo.GetData();
  26. if (pData) {
  27. rootReq["terminal_no"] = pData;
  28. }
  29. pData = pinfo->strAppVersion.GetData();
  30. if (pData) {
  31. rootReq["app_version"] = pData;
  32. }
  33. pData = pinfo->strRecordEndTime.GetData();
  34. if (pData) {
  35. rootReq["upload_time"] = pData;
  36. }
  37. pData = pinfo->strRecordID.GetData();
  38. if (pData) {
  39. rootReq["video_serial_id"] = pData;
  40. }
  41. rootReq["business_status"] = pinfo->iBusinessStatus;
  42. for (vector<record_item_t>::iterator it = pinfo->vRecordList.begin(); it < pinfo->vRecordList.end(); ++it) {
  43. Json::Value item;
  44. item["file_name"] = it->file_name;
  45. item["file_path"] = it->file_path;
  46. item["file_length"] = it->file_length;
  47. rootReq["file_list"].append(item);
  48. }
  49. Json::StyledWriter sw;
  50. req.m_reqContent = sw.write(rootReq);
  51. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_reqContent is %s.", req.m_reqContent.c_str());
  52. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin http get request, timeout is %d, printdbg flag is %s.", req.m_timeOut, req.m_printDbg ? "true" : "false");
  53. unsigned int ustarttime = get_millisec_time();
  54. RecordInfoHTTPRet ret;
  55. if (client->Post(req, ret)) {
  56. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("post result is %s, returnCode:%s, code:%s, errorMsg:%s, message:%s.",
  57. ret.m_success ? "success" : "failed", ret.m_returnCode.c_str(), ret.m_code.c_str(), ret.m_errorMsg.c_str(), ret.m_message.c_str());
  58. uposttime = get_millisec_time() - ustarttime;
  59. iret = 0;
  60. }
  61. else {
  62. errormsg = CSimpleStringA::Format("post video record infos fail, url=%s, syscode=%d, usercode=%s, errmsg=%s", req.m_url.c_str(), ret.m_sysCode, ret.m_userCode.c_str(), ret.m_errMsg.c_str());
  63. }
  64. return iret;
  65. }
  66. unsigned int get_millisec_time()
  67. {
  68. #ifdef RVC_OS_LINUX
  69. unsigned int uptime = 0;
  70. struct timespec on;
  71. if (clock_gettime(CLOCK_MONOTONIC, &on) == 0) {
  72. uptime = on.tv_sec * 1000 + on.tv_nsec / 1000000;
  73. }
  74. return uptime;
  75. # else
  76. return GetTickCount();
  77. #endif
  78. }