mod_SalesRecorder.cpp 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  1. #include "stdafx.h"
  2. #include "mod_SalesRecorder.h"
  3. #include "Event.h"
  4. #include "rvcmediacommon/rvc_media_common.h"
  5. #include "fileutil.h"
  6. #include "array.h"
  7. #include <memutil.h>
  8. #include <algorithm>
  9. #ifdef RVC_OS_WIN
  10. #include <Windows.h>
  11. #endif
  12. #include "mod_customeraware/Event.h"
  13. #include "mod_facetracking/sysvar.h"
  14. #include <assert.h>
  15. #include "EventCode.h"
  16. #include <string.h>
  17. #include "mod_interactivecontrol/InteractiveControl_client_g.h"
  18. #include "mod_interactivecontrol/InteractiveControl_def_g.h"
  19. #include "../mod_interactivecontrol/Event.h"
  20. #ifndef RVC_MIN_FILESIZE
  21. #define RVC_MIN_FILESIZE 10240
  22. #endif
  23. #define SYSVAR_CALLTYPE "CallType"
  24. #define CALLTYPE_NORMAL 'N' // 呼叫类型,普通模式
  25. #define CALLTYPE_MOBILE 'M' // 呼叫类型,手机模式
  26. #define MAX_DISK_PERCENT 95 // 磁盘最大占用百分比
  27. static const char* record_failed_case_table[] = {
  28. "[RTA3L01] 启动录像失败,初始化失败",
  29. "[RTA3L02] 启动录像失败,字体为空,添加水印失败",
  30. "[RTA3L03] 开始录像失败,请稍后(约30秒)再试",
  31. "[RTA3L04] 录像失败,摄像头故障,获取不到视频,请联系厂商进行维修",
  32. "[RTA3L05] 录像失败,获取不到远端音频,请检查风险提示音是否正常播放且音量大小是否正常",
  33. "[RTA3L06] 录像失败,麦克风故障,获取不到本地音频,请联系厂商进行维修",
  34. "[RTA3L07] 录像失败,系统不支持当前音频采样率",
  35. "[RTA3L08] 录像失败,音频流写入失败,请稍后(约30秒)再试",
  36. "[RTA3L09] 录像失败,获取不到远端视频,请稍后(约30秒)再试"
  37. };
  38. static BOOL CheckDiskStatus(const char *szRoot, int nPercent, int *pFreeRatio)
  39. {
  40. #ifdef RVC_OS_WIN
  41. _ULARGE_INTEGER lpFreeBytesAvailableToCaller = {}, lpTotalNumberOfBytes = {}, lpTotalNumberOfFreeBytes = {};
  42. BOOL ret = GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
  43. if (ret == 0)
  44. {
  45. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CheckDiskStatus.GetDiskFreeSpaceEx failed(%d).",GetLastError());
  46. return FALSE;
  47. }
  48. DWORD dwTotal = lpTotalNumberOfBytes.QuadPart/1048576;
  49. DWORD dwTotalFree = lpTotalNumberOfFreeBytes.QuadPart/1048576;
  50. int ratio = dwTotalFree*100/dwTotal;
  51. *pFreeRatio = ratio;
  52. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("free disk %d MB, %d percent free.\n", dwTotalFree, ratio);
  53. //if (ratio < (100-MAX_DISK_PERCENT))
  54. if (ratio < (100-nPercent))
  55. {
  56. return FALSE;
  57. }
  58. return TRUE;
  59. #else
  60. //todo 调用resourcewatcher
  61. return TRUE;
  62. #endif
  63. }
  64. static int hch2int(char hch)
  65. {
  66. if (hch >= '0' && hch <= '9')
  67. return hch-'0';
  68. else if (hch >= 'a' && hch <= 'f')
  69. return hch-'a'+10;
  70. else if (hch >= 'A' && hch <= 'F')
  71. return hch-'A'+10;
  72. return 0;
  73. }
  74. static long hexstr2int(const char *str, int len)
  75. {
  76. long result = 0;
  77. if (str && len <= strlen(str)) {
  78. for (int i = 0; i < len; ++i) {
  79. result += (hch2int(str[i]) << ((len-i-1) << 2));
  80. }
  81. }
  82. return result;
  83. }
  84. static CSimpleStringA VideoSerialID2TimeString(const char *videoserialid)
  85. {
  86. DWORD nTimeTicks = hexstr2int(videoserialid,8);
  87. return ((CSmallDateTime)nTimeTicks).ToTimeString();
  88. }
  89. static void CStringSplit(char* str, char** result, const char* del)
  90. {
  91. char* ptr = NULL;
  92. char* p = strtok_r(str, del, &ptr);
  93. while (p != NULL){
  94. *result++ = p;
  95. p = strtok_r(NULL, del, &ptr);
  96. }
  97. }
  98. #ifdef RVC_OS_WIN
  99. // 寻找某目录下与通配符匹配的文件
  100. static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, ULONGLONG& uCountFile)
  101. {
  102. char sPath[MAX_PATH];
  103. ZeroMemory(sPath, MAX_PATH);
  104. char sFormatFileName[MAX_PATH + 2] = "*";
  105. WIN32_FIND_DATA FindFileData;
  106. HANDLE hFind;
  107. BOOL fFinished = FALSE;
  108. strcpy(sFormatFileName, sFindPath);
  109. if (sFindPath[strlen(sFindPath) - 1] != SPLIT_SLASH)
  110. {
  111. strcat(sFormatFileName, SPLIT_SLASH_STR);
  112. strcat(sFormatFileName, "*");
  113. }
  114. else
  115. {
  116. strcat(sFormatFileName, "*");
  117. }
  118. strcat(sFormatFileName, sFindFileName);
  119. strcat(sFormatFileName, "*");
  120. hFind = FindFirstFile(sFormatFileName, &FindFileData);
  121. if (hFind == INVALID_HANDLE_VALUE)
  122. {
  123. return FALSE;
  124. }
  125. else
  126. {
  127. while (!fFinished)
  128. {
  129. strcpy(sPath, sFindPath);
  130. if (sPath[strlen(sPath) - 1] != SPLIT_SLASH)
  131. {
  132. strcat(sPath, SPLIT_SLASH_STR);
  133. }
  134. strcat(sPath, FindFileData.cFileName);
  135. if (!(FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes))
  136. {
  137. ++uCountFile;
  138. }
  139. if (!FindNextFile(hFind, &FindFileData))
  140. {
  141. if (GetLastError() == ERROR_NO_MORE_FILES)
  142. {
  143. fFinished = TRUE;
  144. }
  145. else
  146. {
  147. break;
  148. }
  149. }
  150. }
  151. FindClose(hFind);
  152. }
  153. return TRUE;
  154. }
  155. #else
  156. static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, ULONGLONG& uCountFile)
  157. {
  158. DIR* pDir = NULL;
  159. struct dirent* pFile = NULL;
  160. CSimpleStringA tmpFindFileName = sFindFileName;
  161. pDir = opendir(sFindPath);
  162. if (pDir == NULL) return FALSE;
  163. //linux不支持*查找,去掉后缀
  164. char strsuffix[MAX_PATH] = { 0 };
  165. snprintf(strsuffix, MAX_PATH, "*.%s", RECORD_MP4_SUFFIX);
  166. if (tmpFindFileName.IsEndWith(strsuffix)) {
  167. tmpFindFileName = tmpFindFileName.SubString(0, tmpFindFileName.GetLength() - 5);
  168. }
  169. while ((pFile = readdir(pDir)) != NULL) {
  170. if (pFile->d_type & DT_DIR) {
  171. //m_pHostApi->Debug("FindMatchedFile DIR name: %s.", pFile->d_name);
  172. if (strcmp(pFile->d_name, ".") == 0
  173. || strcmp(pFile->d_name, "..") == 0) continue;
  174. char Path[256];
  175. int len = strlen(sFindPath);
  176. strncpy(Path, sFindPath, len + 1);
  177. if (sFindPath[len - 1] != '/') strncat(Path, "/", 2);
  178. strncat(Path, pFile->d_name, strlen(pFile->d_name) + 1);
  179. //m_pHostApi->Debug("FindMatchedFile Path: %s.", Path);
  180. FindMatchedFile(Path, (LPCTSTR)tmpFindFileName, uCountFile);
  181. }
  182. else {
  183. //m_pHostApi->Debug("FindMatchedFile FILE name: %s.", pFile->d_name);
  184. if (strstr(pFile->d_name, (LPCTSTR)tmpFindFileName) != NULL) {
  185. ++uCountFile;
  186. }
  187. }
  188. }
  189. closedir(pDir);
  190. return TRUE;
  191. }
  192. #endif
  193. static CSimpleStringA DecryptString(LPCTSTR lpszEncrpyted)
  194. {
  195. if (NULL == lpszEncrpyted) {
  196. return CSimpleStringA("");
  197. }
  198. int iEncrypt = 0;
  199. int len = strlen(lpszEncrpyted);
  200. CSimpleStringA csPlainTxt('\0', (len) / 2 + 1);
  201. int iCh = 0;
  202. for (int i = 0; i < len; i += 2) {
  203. sscanf(lpszEncrpyted + i, "%02X", &iCh);
  204. csPlainTxt[i / 2] = (char)(((char)iCh) ^ (128 | (iEncrypt++ & 127)));
  205. }
  206. return CSimpleStringA((LPCTSTR)csPlainTxt);
  207. }
  208. void SalesRecordServiceSession::Handle_GetOFLVideoRecords( SpReqAnsContext<SalesRecorderSerVice_GetOFLVideoRecords_Req, SalesRecorderSerVice_GetOFLVideoRecords_Ans>::Pointer ctx )
  209. {
  210. ctx->Answer(Error_Succeed);
  211. }
  212. void SalesRecordServiceSession::Handle_CheckVideoDiskStatus( SpReqAnsContext<SalesRecorderSerVice_CheckVideoDiskStatus_Req, SalesRecorderSerVice_CheckVideoDiskStatus_Ans>::Pointer ctx )
  213. {
  214. int nFreeRatio = 0;
  215. int bSufficient = CheckDiskStatus((LPCTSTR)ctx->Req.DriveLetter,m_pEntity->m_max_disk_percent,&nFreeRatio);
  216. ctx->Ans.IsSufficient = bSufficient;
  217. ctx->Ans.FreeRatio = nFreeRatio;
  218. ctx->Answer(Error_Succeed);
  219. }
  220. void SalesRecordServiceSession::Handle_PlayVideo(SpReqAnsContext<SalesRecorderSerVice_PlayVideo_Req, SalesRecorderSerVice_PlayVideo_Ans>::Pointer ctx)
  221. {
  222. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("PlayVideo.");
  223. ErrorCodeEnum ErrorCode = m_pEntity->HandleDisplayVideo();
  224. ctx->Answer(ErrorCode);
  225. }
  226. void SalesRecordServiceSession::Handle_SaveVideo(SpReqAnsContext<SalesRecorderSerVice_SaveVideo_Req, SalesRecorderSerVice_SaveVideo_Ans>::Pointer ctx)
  227. {
  228. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Save Video.");
  229. ErrorCodeEnum ErrorCode = m_pEntity->HandleSaveVideo();
  230. ctx->Answer(ErrorCode);
  231. }
  232. void SalesRecordServiceSession::Handle_StopRecord(SpReqAnsContext<SalesRecorderSerVice_StopRecord_Req, SalesRecorderSerVice_StopRecord_Ans>::Pointer ctx)
  233. {
  234. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop Record.");
  235. ErrorCodeEnum ErrorCode = m_pEntity->HandleStopRecord((LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  236. ctx->Answer(ErrorCode);
  237. }
  238. void SalesRecordServiceSession::Handle_SetAudioTransFlag(SpReqAnsContext<SalesRecorderSerVice_SetAudioTransFlag_Req, SalesRecorderSerVice_SetAudioTransFlag_Ans>::Pointer ctx)
  239. {
  240. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Audio transmission flag is %s.", ctx->Req.TransFlag ? "true" : "false");
  241. ctx->Answer(Error_Succeed);
  242. }
  243. void SalesRecordServiceSession::Handle_StopShowVideo(SpReqAnsContext<SalesRecorderSerVice_StopShowVideo_Req, SalesRecorderSerVice_StopShowVideo_Ans>::Pointer ctx)
  244. {
  245. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop Show Video.");
  246. ErrorCodeEnum ErrorCode = m_pEntity->HandleStopShowVideo();
  247. ctx->Answer(ErrorCode);
  248. }
  249. void SalesRecordServiceSession::Handle_PlaySalesRecord(SpReqAnsContext<SalesRecorderSerVice_PlaySalesRecord_Req, SalesRecorderSerVice_PlaySalesRecord_Ans>::Pointer ctx)
  250. {
  251. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop Show Video.");
  252. ErrorCodeEnum ErrorCode = m_pEntity->HandlePlaySalesRecordVideo(ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  253. ctx->Answer(ErrorCode);
  254. }
  255. void SalesRecordServiceSession::Handle_StartRemoteRecord(SpReqAnsContext<SalesRecorderSerVice_StartRemoteRecord_Req, SalesRecorderSerVice_StartRemoteRecord_Ans>::Pointer ctx)
  256. {
  257. ErrorCodeEnum ErrorCode = m_pEntity->HandleStartRecord(ctx->Req.VideoName.GetData(), true);
  258. ctx->Answer(ErrorCode);
  259. }
  260. CServerSessionBase * CSalesRecorderEntity::OnNewSession( const char* pszRemoteEntityName, const char * pszClass )
  261. {
  262. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s connected class = %s!", pszRemoteEntityName, pszClass);
  263. return new SalesRecordServiceSession(this);
  264. }
  265. void CSalesRecorderEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext )
  266. {
  267. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  268. pTransactionContext->SendAnswer(Error);
  269. }
  270. ErrorCodeEnum CSalesRecorderEntity::__OnStart( ErrorCodeEnum preOperationError )
  271. {
  272. //MessageBoxA(0,0,0,0);
  273. m_eDeviceType = eStand2sType;
  274. m_nSysCallType = 0;
  275. m_bNeedRestart = false;
  276. m_eAudioOutQuality = eUltraHD;
  277. m_bIsAudioNsOn = false;
  278. m_iAudioNsPolicy = 2;
  279. m_iAudioChannels = 1;
  280. m_eDeviceType = RvcGetDeviceType();
  281. int iAudioQuality = 3;
  282. int iAudioNsPolicy = 2;
  283. int iIsAudioNsOn = 0;
  284. int iAudioChannels = 1;
  285. int iLogLevel = 1;
  286. int iLowestLevel = 1;
  287. int iRecordType = 0;
  288. m_max_disk_percent = MAX_DISK_PERCENT;
  289. m_audio_samplerate = 8;
  290. CSmartPointer<IConfigInfo> spConfig;
  291. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  292. if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed) {
  293. spConfig->ReadConfigValueInt("SalesRecorder","MaxDiskPercent",m_max_disk_percent);
  294. spConfig->ReadConfigValueInt("SalesRecorder","AudioSampleRate",m_audio_samplerate);
  295. spConfig->ReadConfigValueInt("SalesRecorder","AudioBitRate",m_audio_out_bitrate);
  296. spConfig->ReadConfigValueInt("SalesRecorder","AudioNsPolicy",iAudioNsPolicy);
  297. spConfig->ReadConfigValueInt("SalesRecorder","IsAudioNsOn",iIsAudioNsOn);
  298. spConfig->ReadConfigValueInt("SalesRecorder","AudioQuality",iAudioQuality);
  299. spConfig->ReadConfigValueInt("SalesRecorder","AudioChannels",iAudioChannels);
  300. spConfig->ReadConfigValueInt("SalesRecorder","LogLevel",iLogLevel);
  301. spConfig->ReadConfigValueInt("SalesRecorder","LowestLevel",iLowestLevel);
  302. }
  303. if (m_max_disk_percent <= 0 || m_max_disk_percent >= 100) {
  304. m_max_disk_percent = MAX_DISK_PERCENT;
  305. }
  306. if (iLogLevel <= RECORD_LOG_ERROR && iLogLevel > 0){
  307. m_loglevel = (record_loglevel)iLogLevel;
  308. }
  309. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_loglevel:%d", m_loglevel);
  310. if (iLowestLevel <= RECORD_LOG_ERROR && iLowestLevel > 0){
  311. m_lowestlevel = (record_loglevel)iLowestLevel;
  312. }
  313. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_lowestlevel:%d", m_lowestlevel);
  314. SetRecordAudioQuality(iAudioQuality);
  315. SetRecordAudioNsPolicy(iAudioNsPolicy);
  316. SetRecordAudioChannles(iAudioChannels);
  317. if (0 != iIsAudioNsOn){
  318. m_bIsAudioNsOn = true;
  319. }
  320. if (m_bWholeSection != 0 && m_bWholeSection != 1){
  321. m_bWholeSection = FALSE;
  322. }
  323. if (m_bApplyHighQuality != 0 && m_bApplyHighQuality != 1){
  324. m_bApplyHighQuality = FALSE;
  325. }
  326. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_bApplyHighQuality:%d",m_bApplyHighQuality);
  327. if (preOperationError != Error_Succeed) {
  328. return preOperationError;
  329. }
  330. ErrorCodeEnum Error = Error_Succeed;
  331. m_iActiveCamera = CAMERA_TYPE_ENV;
  332. m_iCameraState = 'N';
  333. int i = 0;
  334. m_arrListener.Init(4);
  335. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_DELETEVIDEO, NULL, false);
  336. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  337. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
  338. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  339. GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
  340. GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
  341. CSimpleStringA strValue;
  342. GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  343. m_iCameraState = strValue[0];
  344. if (strValue[0] == 'E'){
  345. m_iActiveCamera = CAMERA_TYPE_OPT;
  346. }
  347. else{
  348. m_iActiveCamera = CAMERA_TYPE_ENV;
  349. }
  350. GetFunction()->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
  351. GetFunction()->GetSysVar(SYSVAR_CALLTYPE, strValue);
  352. if (strValue[0] == CALLTYPE_NORMAL) {
  353. m_nSysCallType = 0;
  354. }
  355. else if (strValue[0] == CALLTYPE_MOBILE) {
  356. m_nSysCallType = 1;
  357. }
  358. else {
  359. assert(0);
  360. }
  361. Error = GetFunction()->RegistSysVarEvent("SessionID", this);
  362. if (Error != Error_Succeed)
  363. {
  364. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("register sysvar %s failed!", "SessionID");
  365. }
  366. Error = GetFunction()->GetPath("Temp", m_TempDir);
  367. if (Error != Error_Succeed) {
  368. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record temp path failed!");
  369. }
  370. if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != SPLIT_SLASH) {
  371. m_TempDir += SPLIT_SLASH_STR;
  372. }
  373. Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
  374. if (Error != Error_Succeed) {
  375. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get global record save path failed!");
  376. }
  377. if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != SPLIT_SLASH) {
  378. m_RecordSaveDir += SPLIT_SLASH_STR;
  379. }
  380. return Error;
  381. }
  382. void CSalesRecorderEntity::OnStarted()
  383. {
  384. InitSalesRecorder();
  385. LogEvent(Severity_Middle, LOG_EVT_MOD_SALESRECORDER_STARTED_SUCCESS, "sales recorder entity started successfully.");
  386. }
  387. void CSalesRecorderEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
  388. {
  389. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  390. pTransactionContext->SendAnswer(Error);
  391. }
  392. ErrorCodeEnum CSalesRecorderEntity::__OnClose( ErrorCodeEnum preOperationError )
  393. {
  394. if (preOperationError != Error_Succeed) {
  395. return preOperationError;
  396. }
  397. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  398. for (int i = 0; i < m_arrListener.GetCount(); ++i) {
  399. spFunction->UnsubscribeLog(m_arrListener[i]);
  400. }
  401. GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  402. GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  403. StopRecord();
  404. ReleaseSalesRecorder();
  405. return Error_Succeed;
  406. }
  407. void CSalesRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  408. {
  409. if (Test_ShakeHand == eTestType)
  410. {
  411. if (m_bNeedRestart){
  412. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[OnSelfTest] entity need restart now.");
  413. pTransactionContext->SendAnswer(Error_Unexpect);
  414. }
  415. else{
  416. pTransactionContext->SendAnswer(Error_Succeed);
  417. }
  418. }
  419. }
  420. int CSalesRecorderEntity::GetActiveCamera()
  421. {
  422. return m_iActiveCamera;
  423. }
  424. int CSalesRecorderEntity::GetCameraState()
  425. {
  426. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get active camera = %d", m_iCameraState);
  427. return m_iCameraState;
  428. }
  429. void CSalesRecorderEntity::OnRecordFailed(eRvcRecordFailedCase eCase, const char* pszMessage, bool bRecordDevFault )
  430. {
  431. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnSalesRecordFailed for [%d]:%s.", (int)eCase, record_failed_case_table[eCase]);
  432. if (eCase < eDefault && eCase >= 0) {
  433. LogEvent(Severity_Middle, LOG_EVT_UI_RECORDFAILED, record_failed_case_table[eCase]);
  434. }
  435. char strmsg[MAX_PATH] = { 0 };
  436. snprintf(strmsg, MAX_PATH, "{%s}.", pszMessage ? pszMessage : " ");
  437. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_SALESRECORD_FAILED, strmsg);
  438. if (eBeginFailed == eCase) {
  439. m_bNeedRestart = true;
  440. RealSelfCheck();
  441. }
  442. }
  443. void CSalesRecorderEntity::OnRecordEntityExcption()
  444. {
  445. LogEvent(Severity_High,LOG_EVT_SALESRECORD_ENTITY_EXCEPTION,"现场销售双录出现异常,请稍候重录,系统正在恢复中,预计60秒!");
  446. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_ENTITY_EXCEPTION, "sales record entity exception!");
  447. }
  448. void CSalesRecorderEntity::OnRecordFinished()
  449. {
  450. LogEvent(Severity_High, LOG_EVT_SALESRECORD_FINISHED, "现场销售双录已完成.");
  451. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FINISHED, "现场销售双录已完成.");
  452. }
  453. void CSalesRecorderEntity::Debug(record_loglevel elevel, const char* fmt, ...)
  454. {
  455. record_loglevel entitylevel = (m_lowestlevel > m_loglevel) ? m_lowestlevel : m_loglevel;
  456. if (entitylevel <= elevel) {
  457. va_list arg;
  458. va_start(arg, fmt);
  459. int n = vsnprintf(NULL, 0, fmt, arg);
  460. if (n >= MAX_PATH) {
  461. char* buf = (char*)malloc((size_t)(n + 1));
  462. vsnprintf(buf, n + 1, fmt, arg);
  463. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  464. free(buf);
  465. }
  466. else {
  467. char strlog[MAX_PATH] = { 0 };
  468. vsnprintf(strlog, MAX_PATH, fmt, arg);
  469. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  470. }
  471. va_end(arg);
  472. }
  473. }
  474. void CSalesRecorderEntity::vDebug(record_loglevel elevel, const char* str, va_list list)
  475. {
  476. record_loglevel entitylevel = (m_lowestlevel > m_loglevel) ? m_lowestlevel : m_loglevel;
  477. if (entitylevel <= elevel) {
  478. int n = vsnprintf(NULL, 0, str, list);
  479. if (n >= MAX_PATH) {
  480. char* buf = (char*)malloc((size_t)(n + 1));
  481. vsnprintf(buf, n + 1, str, list);
  482. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  483. free(buf);
  484. }
  485. else {
  486. char strlog[MAX_PATH] = { 0 };
  487. vsnprintf(strlog, MAX_PATH, str, list);
  488. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  489. }
  490. }
  491. }
  492. #ifdef RVC_OS_WIN
  493. void CSalesRecorderEntity::WmpDebug( const char *fmt, ... )
  494. {
  495. va_list arg;
  496. va_start(arg, fmt);
  497. vDbg(fmt, arg);
  498. va_end(arg);
  499. }
  500. #else
  501. void CSalesRecorderEntity::Debug(media_loglevel log_level, const char* fmt, ...)
  502. {
  503. if (log_level >= MEDIA_LOG_ERROR) {
  504. va_list arg;
  505. va_start(arg, fmt);
  506. int n = vsnprintf(NULL, 0, fmt, arg);
  507. if (n >= MAX_PATH) {
  508. char* buf = (char*)malloc((size_t)(n + 1));
  509. vsnprintf(buf, n + 1, fmt, arg);
  510. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  511. free(buf);
  512. }
  513. else {
  514. char strlog[MAX_PATH] = { 0 };
  515. vsnprintf(strlog, MAX_PATH, fmt, arg);
  516. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  517. }
  518. va_end(arg);
  519. }
  520. }
  521. #endif // RVC_OS_WIN
  522. void CSalesRecorderEntity::OnTimeout( DWORD dwTimerID )
  523. {
  524. }
  525. void CSalesRecorderEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
  526. {
  527. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  528. {
  529. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
  530. m_iCameraState = pszValue[0];
  531. if (pszValue[0] == 'E')
  532. {
  533. m_iActiveCamera = CAMERA_TYPE_OPT;
  534. }
  535. else
  536. {
  537. m_iActiveCamera = CAMERA_TYPE_ENV;
  538. }
  539. }
  540. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  541. {
  542. if (m_iCameraState == 'N')
  543. {
  544. if (pszValue[0] == 'E')
  545. {
  546. m_iActiveCamera = CAMERA_TYPE_ENV;
  547. }
  548. else if (pszValue[0] == 'O')
  549. {
  550. m_iActiveCamera = CAMERA_TYPE_OPT;
  551. }
  552. }
  553. }
  554. else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
  555. {
  556. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]);
  557. if(pszValue[0] == CALLTYPE_NORMAL)
  558. {
  559. m_nSysCallType = 0;
  560. }
  561. else if(pszValue[0] == CALLTYPE_MOBILE)
  562. {
  563. m_nSysCallType = 1;
  564. }
  565. else
  566. {
  567. m_nSysCallType = -1;
  568. }
  569. }
  570. }
  571. void CSalesRecorderEntity::OnLog( const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel, const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
  572. {
  573. // 响应客户经理销售录像相关的事件
  574. switch (dwUserCode)
  575. {
  576. case LOG_EVT_UI_SHOWVIDEO:
  577. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("show video record.");
  578. HandleDisplayVideo();
  579. break;
  580. case LOG_EVT_UI_SAVEVIDEO:
  581. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("save record!");
  582. HandleSaveVideo();
  583. break;
  584. case LOG_EVT_UI_DELETEVIDEO:
  585. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("delete record!");
  586. HandleDeleteVideo();
  587. break;
  588. case LOG_EVT_UI_RETURNMENU:
  589. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return menu.");
  590. //HandleReturnMenu();
  591. break;
  592. case LOG_EVT_UI_VIDEOAPPENDWATERMARK:
  593. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("handle video append water mark param is %s.", pszMessage);
  594. HandleVideoAppendWatermark(pszMessage);
  595. break;
  596. case LOG_EVT_SALESRECORD_ENTITY_EXCEPTION:
  597. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("handle sales record entity exception, and message is %s.", pszMessage);
  598. HandleSalesRecordEntityException(pszMessage);
  599. break;
  600. default:
  601. break;
  602. }
  603. }
  604. bool CSalesRecorderEntity::GetStandardQualityOnSiteSalesRecorder()
  605. {
  606. bool bRet = FALSE;
  607. m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  608. REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  609. return bRet;
  610. }
  611. bool CSalesRecorderEntity::GetHighQualityOnSiteSalesRecorder()
  612. {
  613. bool bRet = false;
  614. m_pRecorder = new Clibvideorecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  615. REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  616. return bRet;
  617. }
  618. void CSalesRecorderEntity::StartOnSiteSalesRecord(const int fps, const char* videofilename, int videoquality, int audioOutBitRate, SubtitleParam* subtitleParam, BOOL bWholeSection, BOOL bSessionManage, eRvcRecordType eRecordType)
  619. {
  620. Rvc_RecordAudioParam_t tAudioParams;
  621. tAudioParams.eRecordType = eRecordType;
  622. tAudioParams.eOutPutType = m_eAudioOutQuality;
  623. tAudioParams.bIsNsOn = m_bIsAudioNsOn;
  624. tAudioParams.iNsPolicy = m_iAudioNsPolicy;
  625. tAudioParams.iAudioOutBitRate = audioOutBitRate;
  626. tAudioParams.iAudioChannels = m_iAudioChannels;
  627. if (eStand2Agent == eRecordType || ePad2Agent == eRecordType) {
  628. tAudioParams.eOutPutType = eLowDefinition;
  629. tAudioParams.bIsNsOn = false;
  630. }
  631. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("init lib video record success! and record type is %s and output audio quality is %s, audio noise suppression flag is %s. noise suppression policy is %d.", record_type_table[eRecordType], audio_quality_type_table[m_eAudioOutQuality], tAudioParams.bIsNsOn ? "true" : "false", tAudioParams.iNsPolicy);
  632. if (m_pRecorder->StartVideoRecord(fps, videoquality, eMP4, &tAudioParams, subtitleParam, bWholeSection, false, (LPCSTR)m_TempDir,
  633. m_TempDir.GetLength(), videofilename, strlen(videofilename)))
  634. {
  635. m_bStarted = true;
  636. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start VideoRecord success!");
  637. }
  638. else {
  639. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start VideoRecord failed!");
  640. }
  641. }
  642. void CSalesRecorderEntity::StartRecord(const char * videofilename, int videoquality, int audioOutBitRate, SubtitleParam *subtitleParam /* = NULL */, BOOL bWholeSection /* = FALSE */, BOOL bSessionManage /* = FALSE */, eRvcRecordType eRecordType /* = eSingleSide */)
  643. {
  644. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("videofilename = %s", videofilename);
  645. StartOnSiteSalesRecord(10, videofilename, videoquality, audioOutBitRate, subtitleParam, bWholeSection, bSessionManage, eRecordType);
  646. }
  647. ErrorCodeEnum CSalesRecorderEntity::StopRecord()
  648. {
  649. ErrorCodeEnum eCode = Error_Succeed;
  650. if (m_bStarted) {
  651. m_pRecorder->StopVideoRecord();
  652. m_bStarted = FALSE;
  653. }
  654. else{
  655. eCode = Error_InvalidState;
  656. }
  657. return eCode;
  658. }
  659. ErrorCodeEnum CSalesRecorderEntity::ShowVideo( const char *videofilename)
  660. {
  661. ErrorCodeEnum ErrorCode = Error_Succeed;
  662. return ErrorCode;
  663. }
  664. ErrorCodeEnum CSalesRecorderEntity::PlaySalesRecordVideo( const char *videofilename, int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  665. {
  666. ErrorCodeEnum ErrorCode = Error_Succeed;
  667. return ErrorCode;
  668. }
  669. void CSalesRecorderEntity::DeleteVideo( const char *videofilename)
  670. {
  671. if(!m_bStarted)
  672. {
  673. CSimpleStringA strPath;
  674. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  675. if (Error == Error_Succeed) {
  676. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  677. strPath += SPLIT_SLASH_STR;
  678. }
  679. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", videofilename, RECORD_MP4_SUFFIX);
  680. ULONGLONG uVideoCount = 0;
  681. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  682. if(bRet)
  683. {
  684. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to get record count while delete video!");
  685. CSimpleStringA fileName;
  686. BOOL bDeleteSucc = TRUE;
  687. for(int i = 0; i != uVideoCount; ++i)
  688. {
  689. fileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)strPath, videofilename, i, RECORD_MP4_SUFFIX);
  690. if(remove(fileName.GetData())) {
  691. bDeleteSucc = FALSE;
  692. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while delete %s ", errno, fileName.GetData());
  693. }
  694. }
  695. if (bDeleteSucc) {
  696. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to delete videos!");
  697. }
  698. }
  699. else
  700. {
  701. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[DeleteVideo] videos not exist or have been deleted!");
  702. }
  703. }
  704. }
  705. }
  706. /*
  707. SaveVideo包含两步,找到录像和移动录像
  708. Error_Succeed 提交上传成功
  709. Error_NotExist not exist
  710. Error_NotImpl 方法执行失败
  711. */
  712. static unsigned long GetFileSize(const char* filename)
  713. {
  714. struct stat statbuf;
  715. stat(filename, &statbuf);
  716. return statbuf.st_size;
  717. }
  718. ErrorCodeEnum CSalesRecorderEntity::SaveVideo( const char * videofilename)
  719. {
  720. ErrorCodeEnum ErrorCode = Error_Succeed;
  721. if(!m_bStarted)
  722. {
  723. CSimpleStringA sourPath;
  724. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  725. if(Error == Error_Succeed)
  726. {
  727. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  728. sourPath += SPLIT_SLASH_STR;
  729. }
  730. ULONGLONG uVideoCount = 0;
  731. // 移动销售录像 edit by ly 2018/03/05
  732. CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.%s", videofilename, RECORD_MP4_SUFFIX);
  733. BOOL bRet = FindMatchedFile((LPCSTR)sourPath, (LPCSTR)strFindFileName, uVideoCount);
  734. if(bRet)
  735. {
  736. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  737. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to get sales record count while save video!");
  738. CSimpleStringA destPath;
  739. Error = GetFunction()->GetPath("UploadVideo", destPath);
  740. if(Error == Error_Succeed)
  741. {
  742. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  743. destPath += SPLIT_SLASH_STR;
  744. }
  745. CSimpleStringA sourFileName, destFileName;
  746. BOOL bMoveSucc = TRUE;
  747. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("strFindFileName=%s", (LPCSTR)strFindFileName);
  748. for(int i = 0; i != uVideoCount; ++i)
  749. {
  750. sourFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)sourPath, (LPCSTR)strFindFileName, i, RECORD_MP4_SUFFIX);
  751. destFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)destPath, (LPCSTR)strFindFileName, i, RECORD_MP4_SUFFIX);
  752. unsigned long ufilesize = GetFileSize(sourFileName.GetData());
  753. char strtext[MAX_PATH] = {0};
  754. snprintf(strtext, MAX_PATH, "%s file size is %u byte.", (LPCSTR)sourFileName, ufilesize);
  755. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FILESIZE, strtext);
  756. if(rename(sourFileName.GetData(), destFileName.GetData())) {
  757. bMoveSucc = FALSE;
  758. ErrorCode = Error_NotImpl;
  759. char strinfo[MAX_PATH] = { 0 };
  760. snprintf(strinfo, MAX_PATH, "Error Code %lu while move %s.", errno, (LPCSTR)sourFileName);
  761. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, strinfo);
  762. }
  763. if (ufilesize > RVC_MIN_FILESIZE){
  764. }
  765. else{
  766. char strmsg[MAX_PATH] = {0};
  767. snprintf(strmsg, MAX_PATH, "%s file size is %u.", (LPCSTR)sourFileName, ufilesize);
  768. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_INVALID_FILE, strmsg);
  769. }
  770. }
  771. if (bMoveSucc) {
  772. char strmsg[MAX_PATH] = { 0 };
  773. snprintf(strmsg, MAX_PATH, "succeed to save sales video, move it from %s to %s.", sourFileName.GetData(), destFileName.GetData());
  774. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_SUCCESS, strmsg);
  775. }
  776. }
  777. }
  778. else
  779. {
  780. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, "sales videos not exist or have been deleted");
  781. ErrorCode = Error_NotExist;
  782. }
  783. }
  784. }
  785. else{
  786. ErrorCode = Error_InvalidState;
  787. }
  788. return ErrorCode;
  789. }
  790. CSimpleStringA CSalesRecorderEntity::GetTerminalStage()
  791. {
  792. CSmartPointer<IEntityFunction> Func = GetFunction();
  793. CSimpleStringA strValue = "";
  794. Func->GetSysVar("TerminalStage", strValue);
  795. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("TerminalStage:%s", (LPCTSTR)strValue);
  796. return strValue;
  797. }
  798. bool CSalesRecorderEntity::SecureClientConnect()
  799. {
  800. SecureClientRelease();
  801. return true;
  802. }
  803. void CSalesRecorderEntity::SecureClientRelease()
  804. {
  805. }
  806. // 请求InteractiveControl结束录像 add by ly 2018/03/12
  807. ErrorCodeEnum CSalesRecorderEntity::StopRecordVideo()
  808. {
  809. auto rc = Error_Succeed;
  810. auto pUIClient = new InteractiveControl::UIService_ClientBase(this);
  811. if(pUIClient->Connect() != Error_Succeed)
  812. {
  813. pUIClient->SafeDelete();
  814. pUIClient = NULL;
  815. rc = Error_DevConnFailed;
  816. }
  817. else
  818. {
  819. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("UIClient connected success!");
  820. InteractiveControl::UIService_StopRecordVideo_Req req;
  821. InteractiveControl::UIService_StopRecordVideo_Ans ans;
  822. rc = (*pUIClient)(EntityResource::getLink().upgradeLink())->StopRecordVideo(req, ans, 5000);
  823. if(rc != Error_Succeed)
  824. {
  825. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Stop record video failed return 0x%08x", rc);
  826. }
  827. pUIClient->GetFunction()->CloseSession();
  828. pUIClient = NULL;
  829. }
  830. return rc;
  831. }
  832. ErrorCodeEnum CSalesRecorderEntity::HandleStartRecord(const char *pszMessage, const bool bRemoteRecord)
  833. {
  834. ErrorCodeEnum Error = Error_Succeed;
  835. eRvcRecordType eRecordType = eSingleSide;
  836. if (NULL == pszMessage){
  837. return Error_Param;
  838. }
  839. size_t ulen = strlen(pszMessage);
  840. char *tmp = new char[ulen+1];
  841. strncpy(tmp, pszMessage, ulen);
  842. char *result[32] = {0};
  843. CStringSplit(tmp, result, "@");
  844. memset(m_SalesVideoName, 0, MAX_PATH);
  845. if (result[4]) {
  846. snprintf(m_SalesVideoName, MAX_PATH, "%s", result[4]);//录像名:录像类型标志_录像流水号(如S_C13213EF)
  847. }
  848. RecordSubTitle subTitle;
  849. ZeroMemory(&subTitle,sizeof(RecordSubTitle));
  850. if (result[5]) {
  851. CSimpleStringA strCardNo = DecryptString(result[5]);
  852. if (sizeof(subTitle.CustCardNo) > strCardNo.GetLength()) {
  853. strcpy_s(subTitle.CustCardNo, 24, strCardNo.GetData());
  854. }
  855. else {
  856. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CustCardNo.");
  857. }
  858. }
  859. char* pStr = result[6];
  860. if (pStr) {
  861. CSimpleStringW szCustName = CSimpleStringA2W(pStr);
  862. if (szCustName.GetLength() <= 4) {
  863. strcpy(subTitle.CustName, pStr);
  864. }
  865. else {
  866. CSimpleStringW aa = szCustName.SubString(0, 4);
  867. sprintf(subTitle.CustName, "%s...", (LPCTSTR)CSimpleStringW2A(aa));
  868. }
  869. }
  870. pStr = result[7];
  871. if (pStr) {
  872. int nProductCodeLen = strlen(pStr);
  873. if (nProductCodeLen <= 10) {
  874. strcpy(subTitle.ProductCode, pStr);
  875. }
  876. else {
  877. char aa[5] = { 0 }, bb[5] = { 0 };
  878. strncpy(aa, pStr, 4);
  879. strncpy(bb, pStr + nProductCodeLen - 4, 4);
  880. sprintf(subTitle.ProductCode, "%s...%s", aa, bb);
  881. }
  882. }
  883. pStr = result[8];
  884. if (pStr) {
  885. CSimpleStringW szProductName = CSimpleStringA2W(pStr);
  886. if (szProductName.GetLength() <= 5) {
  887. strcpy(subTitle.ProductName, pStr);
  888. }
  889. else {
  890. CSimpleStringW aa = szProductName.SubString(0, 3);
  891. CSimpleStringW bb = szProductName.SubString(szProductName.GetLength() - 2, 2);
  892. sprintf(subTitle.ProductName, "%s...%s", (LPCTSTR)CSimpleStringW2A(aa), (LPCTSTR)CSimpleStringW2A(bb));
  893. }
  894. }
  895. if (result[9]) {
  896. strcpy(subTitle.SapID, result[9]);
  897. } else {
  898. subTitle.SapID[0] = '\0';
  899. }
  900. if (result[10]) {
  901. pStr = result[10];
  902. CSimpleStringW szCustManagerName = CSimpleStringA2W(pStr);
  903. if (szCustManagerName.GetLength() <= 4) {
  904. strcpy(subTitle.CustManagerName, result[10]);
  905. }
  906. else {
  907. CSimpleStringW aa = szCustManagerName.SubString(0,4);
  908. sprintf(subTitle.CustManagerName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  909. }
  910. } else {
  911. subTitle.CustManagerName[0] = '\0';
  912. }
  913. delete[] tmp;
  914. tmp = NULL;
  915. SubtitleParam subtitleParam;
  916. ZeroMemory(&subtitleParam,sizeof(SubtitleParam));
  917. subtitleParam.bSubtitle = TRUE;
  918. subtitleParam.bSubtitleSection = TRUE;
  919. subtitleParam.topSubtitleData[0] = '\0';
  920. if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0)
  921. {
  922. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
  923. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
  924. }
  925. else
  926. {
  927. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s", subTitle.CustCardNo, subTitle.CustName);
  928. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s", subTitle.ProductCode, subTitle.ProductName);
  929. }
  930. int i_audio_out_bitrate = m_audio_out_bitrate;
  931. if (bRemoteRecord){
  932. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType) { //如果是大机
  933. eRecordType = eStand2Agent; //可视柜台大机的双向录像
  934. }
  935. else{
  936. eRecordType = ePad2Agent; //可视柜台pad的双向录像
  937. }
  938. if(256 == m_audio_out_bitrate){
  939. i_audio_out_bitrate = 128;
  940. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("change remote record audio out bitrate to %d.", i_audio_out_bitrate);
  941. }
  942. }
  943. StartRecord(m_SalesVideoName, 90, i_audio_out_bitrate, &subtitleParam, m_bWholeSection, FALSE, eRecordType);
  944. char strmsg[MAX_PATH] = { 0 };
  945. snprintf(strmsg, MAX_PATH, "start remote record %s.", m_SalesVideoName);
  946. LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_REMOTERECORD, strmsg);
  947. return Error;
  948. }
  949. ErrorCodeEnum CSalesRecorderEntity::HandleStopRecord(const char *pszMessage)
  950. {
  951. ErrorCodeEnum ErrorCode = StopRecord();
  952. return ErrorCode;
  953. }
  954. ErrorCodeEnum CSalesRecorderEntity::HandleDisplayVideo()
  955. {
  956. // 视频播放 libwmpplayer
  957. m_bIsShowVideo = TRUE;
  958. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play record file name is %s!", m_SalesVideoName);
  959. ErrorCodeEnum ErrorCode = ShowVideo(m_SalesVideoName);
  960. return ErrorCode;
  961. }
  962. ErrorCodeEnum CSalesRecorderEntity::HandlePlaySalesRecordVideo(int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  963. {
  964. // 视频播放 libwmpplayer
  965. m_bIsShowVideo = TRUE;
  966. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play sales record video file name is %s!", m_SalesVideoName);
  967. ErrorCodeEnum ErrorCode = PlaySalesRecordVideo(m_SalesVideoName, iWndX, iWndY, iWndWidth, iWndHeight);
  968. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play sales record video return code is 0x%08x.", ErrorCode);
  969. return ErrorCode;
  970. }
  971. ErrorCodeEnum CSalesRecorderEntity::HandleStopShowVideo()
  972. {
  973. // 视频播放 libwmpplayer
  974. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop show video record file name is %s!", m_SalesVideoName);
  975. ErrorCodeEnum ErrorCode = Error_Succeed;
  976. if(m_bIsShowVideo)
  977. {
  978. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_pPlayer = %p while play!", m_pPlayer);
  979. //m_pPlayer->Close();
  980. m_bIsShowVideo = FALSE;
  981. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to stop show video!");
  982. }
  983. else{
  984. ErrorCode = Error_NotImpl;
  985. }
  986. return ErrorCode;
  987. }
  988. ErrorCodeEnum CSalesRecorderEntity::HandleSaveVideo()
  989. {
  990. ErrorCodeEnum ErrorCode = Error_Succeed;
  991. // 将视频从tmp移动到uploadvideo
  992. if (!strstr(m_SalesVideoName, "OFL")) // edit by ly 20180228
  993. {
  994. ErrorCode = SaveVideo(m_SalesVideoName+2);
  995. }
  996. else
  997. {
  998. ErrorCode = SaveVideo(m_SalesVideoName+4);
  999. }
  1000. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1001. return ErrorCode;
  1002. }
  1003. void CSalesRecorderEntity::HandleDeleteVideo()
  1004. {
  1005. // 删除tmp中的视频
  1006. DeleteVideo(m_SalesVideoName);
  1007. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1008. }
  1009. void CSalesRecorderEntity::HandleReturnMenu()
  1010. {
  1011. CSimpleStringA strValue;
  1012. GetFunction()->GetSysVar("DesktopType", strValue);
  1013. if (strValue != CSimpleStringA("U"))
  1014. {
  1015. if (m_bStarted) // 如果正在进行客户经理录像
  1016. {
  1017. // 停止录像
  1018. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop record and return menu!");
  1019. StopRecord();
  1020. }
  1021. ZeroMemory(m_SalesVideoName, sizeof(m_SalesVideoName));
  1022. }
  1023. }
  1024. void CSalesRecorderEntity::HandleVideoAppendWatermark(const char* pszMessage)
  1025. {
  1026. if (NULL == pszMessage){
  1027. return;
  1028. }
  1029. wchar_t*result[10] = {0};
  1030. auto arr1 = CSimpleStringA2W(pszMessage).Split('|');
  1031. auto arr2 = CAutoArray<CSimpleStringW>(arr1.GetCount());
  1032. int icount = sizeof(result)/sizeof(char*);
  1033. for (int i = 0; i < arr1.GetCount() && i < sizeof(result)/sizeof(char*); i++)
  1034. {
  1035. arr2[i] = CSimpleStringW(arr1[i]);
  1036. result[i] = (wchar_t*)arr2[i].GetData();
  1037. }
  1038. if (m_bStarted && (NULL != m_pRecorder))
  1039. {
  1040. m_pRecorder->SetRightVideoWaterMark(result[1]);
  1041. }
  1042. }
  1043. ErrorCodeEnum CSalesRecorderEntity::HandleSalesRecordEntityException(const char* pszMessage)
  1044. {
  1045. // 通知到业务中台
  1046. SalesRecordException evt;
  1047. evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"现场销售双录过程出现异常!":pszMessage);
  1048. SpSendBroadcast(GetFunction(), SP_MSG_OF(SalesRecordException), SP_MSG_SIG_OF(SalesRecordException), evt);
  1049. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] SalesRecord entity exception broadcast sent!");
  1050. //停止录像
  1051. StopRecord();
  1052. m_bNeedRestart = true;
  1053. //重启实体
  1054. RealSelfCheck();
  1055. return Error_Succeed;
  1056. }
  1057. bool CSalesRecorderEntity::InitSalesRecorder()
  1058. {
  1059. bool bRet = FALSE;
  1060. if (m_bApplyHighQuality)
  1061. {
  1062. bRet = GetHighQualityOnSiteSalesRecorder();
  1063. }
  1064. else
  1065. {
  1066. bRet = GetStandardQualityOnSiteSalesRecorder();
  1067. }
  1068. return bRet;
  1069. }
  1070. bool CSalesRecorderEntity::ReleaseSalesRecorder()
  1071. {
  1072. if (m_pRecorder) {
  1073. delete m_pRecorder;
  1074. m_pRecorder = NULL;
  1075. }
  1076. return true;
  1077. }
  1078. ErrorCodeEnum CSalesRecorderEntity::RealSelfCheck()
  1079. {
  1080. ErrorCodeEnum Error = Error_Succeed;
  1081. SelfChekerClient* pSelfcheckClient = new SelfChekerClient(this);
  1082. Error = pSelfcheckClient->Connect();
  1083. if (Error != Error_Succeed)
  1084. {
  1085. pSelfcheckClient->SafeDelete();
  1086. pSelfcheckClient = NULL;
  1087. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SelfcheckClient connect fail!");
  1088. }
  1089. else
  1090. {
  1091. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SelfcheckClient connect success!");
  1092. }
  1093. if (pSelfcheckClient)
  1094. {
  1095. SelfChecker::SelfCheckerService_RealCheck_Req req;
  1096. req.name = GetEntityName();
  1097. SelfChecker::SelfCheckerService_RealCheck_Ans ans;
  1098. DWORD Timeout = 500;
  1099. Error = pSelfcheckClient->RealCheck(req,ans,Timeout);
  1100. if (Error!=Error_Succeed)
  1101. {
  1102. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RealSelfcheck fail!");
  1103. }
  1104. else
  1105. {
  1106. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("RealSelfcheck success!");
  1107. }
  1108. }
  1109. LogWarn(Severity_Middle, Error_Debug, LOG_EVT_ENTITY_RESTART, "sales record entity self restart.");
  1110. return Error;
  1111. }
  1112. #ifdef RVC_OS_WIN
  1113. bool IsMatchedVideo(WIN32_FIND_DATA fileData)
  1114. {
  1115. bool bRet = false;
  1116. if ('S' == fileData.cFileName[0] || 'W' == fileData.cFileName[0]){
  1117. SYSTEMTIME sysTime;
  1118. FileTimeToSystemTime(&fileData.ftCreationTime, &sysTime);
  1119. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("File %s create data info is %d %d %d.", fileData.cFileName, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  1120. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)){
  1121. if (sysTime.wDay >= 3 && sysTime.wDay <= 10){
  1122. bRet = true;
  1123. }
  1124. }
  1125. }
  1126. return bRet;
  1127. }
  1128. void CSalesRecorderEntity::UploadTempPathVideos()
  1129. {
  1130. CSimpleStringA sourPath;
  1131. CSimpleStringA destPath;
  1132. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1133. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1134. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  1135. sourPath += SPLIT_SLASH_STR;
  1136. }
  1137. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  1138. destPath += SPLIT_SLASH_STR;
  1139. }
  1140. if(Error == Error_Succeed)
  1141. {
  1142. char srcFilePath[MAX_PATH]={0};
  1143. WIN32_FIND_DATA FindFileData;
  1144. HANDLE hFind;
  1145. BOOL fFinished = FALSE;
  1146. sprintf_s(srcFilePath, MAX_PATH, "%s*.%s", sourPath, m_eRecordType == eMP4 ? RECORD_MP4_SUFFIX : RECORD_WMV_SUFFIX);
  1147. hFind = FindFirstFile(srcFilePath, &FindFileData);
  1148. if (INVALID_HANDLE_VALUE != hFind)
  1149. {
  1150. while (!fFinished)
  1151. {
  1152. if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
  1153. {
  1154. continue;
  1155. }
  1156. if (IsMatchedVideo(FindFileData)){
  1157. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, FindFileData.cFileName);
  1158. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, FindFileData.cFileName);
  1159. if(!MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName)) {
  1160. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  1161. }else{
  1162. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Move File %s success.", (LPCSTR)sourFileName);
  1163. }
  1164. }
  1165. else{
  1166. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File (%s) is not matched.", FindFileData.cFileName);
  1167. }
  1168. if (!FindNextFile(hFind, &FindFileData))
  1169. {
  1170. if (GetLastError() == ERROR_NO_MORE_FILES)
  1171. {
  1172. fFinished = TRUE;
  1173. }
  1174. else
  1175. {
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. FindClose(hFind);
  1181. }
  1182. }
  1183. }
  1184. #else
  1185. /*
  1186. **time_t转SYSTEMTIME
  1187. */
  1188. SYSTEMTIME Time_tToSystemTime(time_t t)
  1189. {
  1190. tm temptm = *localtime(&t);
  1191. SYSTEMTIME st = { 1900 + temptm.tm_year,
  1192. 1 + temptm.tm_mon,
  1193. temptm.tm_wday,
  1194. temptm.tm_mday,
  1195. temptm.tm_hour,
  1196. temptm.tm_min,
  1197. temptm.tm_sec,
  1198. 0 };
  1199. return st;
  1200. }
  1201. bool IsMatchedVideo(LPCTSTR path, struct dirent* file)
  1202. {
  1203. bool bRet = false;
  1204. if ((file->d_reclen > 0) && ('S' == file->d_name[0] || 'W' == file->d_name[0])){
  1205. struct stat fileInfo;
  1206. char ttp[256];
  1207. bzero(ttp, sizeof(ttp));
  1208. strcat(ttp, path);
  1209. if (strcmp(ttp, "/") != 0)strcat(ttp, "/");//如果是根目录不需要加
  1210. strcat(ttp, file->d_name);
  1211. if (stat(ttp, &fileInfo) == 0) {
  1212. SYSTEMTIME sysTime;
  1213. sysTime = Time_tToSystemTime(fileInfo.st_mtime);
  1214. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File %s create data info is %d %d %d.", file->d_name, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  1215. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)) {
  1216. if (sysTime.wDay >= 3 && sysTime.wDay <= 10) {
  1217. bRet = true;
  1218. }
  1219. }
  1220. }
  1221. }
  1222. return bRet;
  1223. }
  1224. void CSalesRecorderEntity::UploadTempPathVideos() {
  1225. CSimpleStringA sourPath;
  1226. CSimpleStringA destPath;
  1227. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1228. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1229. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength() - 1] != SPLIT_SLASH) {
  1230. sourPath += SPLIT_SLASH_STR;
  1231. }
  1232. if (destPath.GetLength() > 0 && destPath[destPath.GetLength() - 1] != SPLIT_SLASH) {
  1233. destPath += SPLIT_SLASH_STR;
  1234. }
  1235. if (Error == Error_Succeed)
  1236. {
  1237. char srcFilePath[MAX_PATH] = { 0 };
  1238. DIR* pDir = NULL;
  1239. struct dirent* pFile = NULL;
  1240. snprintf(srcFilePath, MAX_PATH, "%s*.%s", sourPath, RECORD_MP4_SUFFIX);
  1241. pDir = opendir(sourPath);
  1242. if (pDir == NULL) return ;
  1243. while ((pFile = readdir(pDir)) != NULL) {
  1244. if (pFile->d_type & DT_DIR) {
  1245. //m_pHostApi->Debug("MoveTempPathVideos DIR name: %s.", pFile->d_name);
  1246. continue;
  1247. }
  1248. else {
  1249. //m_pHostApi->Debug("MoveTempPathVideos FILE name: %s.", pFile->d_name);
  1250. if (IsMatchedVideo((LPCSTR)sourPath, pFile)) {
  1251. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, pFile->d_name);
  1252. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, pFile->d_name);
  1253. if (rename(sourFileName.GetData(), destFileName.GetData())) {
  1254. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while move %s.", errno, sourFileName.GetData());
  1255. }
  1256. else {
  1257. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Move File %s success.", sourFileName.GetData());
  1258. }
  1259. }
  1260. else {
  1261. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File (%s) is not matched.", pFile->d_name);
  1262. }
  1263. }
  1264. }
  1265. closedir(pDir);
  1266. }
  1267. }
  1268. #endif
  1269. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioQuality(int iAudioQuality)
  1270. {
  1271. ErrorCodeEnum eRet = Error_Succeed;
  1272. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("iAudioQuality == %d.", iAudioQuality);
  1273. switch (iAudioQuality)
  1274. {
  1275. case 1:
  1276. m_eAudioOutQuality = eLowDefinition;
  1277. break;
  1278. case 2:
  1279. m_eAudioOutQuality = eStandardDefinition;
  1280. break;
  1281. case 3:
  1282. m_eAudioOutQuality = eHighDefinition;
  1283. break;
  1284. case 4:
  1285. m_eAudioOutQuality = eUltraHD;
  1286. break;
  1287. default:
  1288. m_eAudioOutQuality = eUltraHD;
  1289. break;
  1290. }
  1291. return eRet;
  1292. }
  1293. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioNsPolicy(int iNsPolicy)
  1294. {
  1295. ErrorCodeEnum eRet = Error_Succeed;
  1296. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("iNsPolicy == %d.", iNsPolicy);
  1297. if (1 == iNsPolicy || 3 == iNsPolicy){
  1298. m_iAudioNsPolicy = iNsPolicy;
  1299. }
  1300. else{
  1301. m_iAudioNsPolicy = 2;
  1302. }
  1303. return eRet;
  1304. }
  1305. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioChannles(int iAudioChannles)
  1306. {
  1307. ErrorCodeEnum eRet = Error_Succeed;
  1308. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Get iAudioChannles == %d.", iAudioChannles);
  1309. m_iAudioChannels = 2;
  1310. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set AudioChannles == %d.", m_iAudioChannels);
  1311. return eRet;
  1312. }
  1313. DeviceTypeEnum CSalesRecorderEntity::RvcGetDeviceType()
  1314. {
  1315. DeviceTypeEnum eType = eStand2sType;
  1316. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1317. CSystemStaticInfo stStaticinfo;
  1318. spFunction->GetSystemStaticInfo(stStaticinfo);
  1319. m_terminalNo = stStaticinfo.strTerminalID;
  1320. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  1321. eType = eStand1SPlusType;
  1322. }
  1323. else if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  1324. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  1325. eType = eMobilePadType;
  1326. }
  1327. else {
  1328. eType = ePadtype;
  1329. }
  1330. }
  1331. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  1332. eType = eDesk2SType;
  1333. WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
  1334. WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
  1335. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("MachineVersion is %d.%d", nMajor, nMinor);
  1336. if (2 == nMajor) {
  1337. eType = eDesk2SIntegratedType;
  1338. }
  1339. }
  1340. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  1341. eType = eRpm1sType;
  1342. }
  1343. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  1344. eType = eDesk1SType;
  1345. }
  1346. else {
  1347. eType = eStand2sType;
  1348. }
  1349. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1350. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  1351. }
  1352. return eType;
  1353. }
  1354. SelfChekerClient::SelfChekerClient( CSalesRecorderEntity *pEntity ) : SelfChecker::SelfCheckerService_ClientBase(pEntity)
  1355. {
  1356. }
  1357. SP_BEGIN_ENTITY_MAP()
  1358. SP_ENTITY(CSalesRecorderEntity)
  1359. SP_END_ENTITY_MAP()