DiosChannel.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // DiosChannel.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include <Windows.h>
  5. #include <conio.h>
  6. #include <ctype.h>
  7. #include "cdi.h"
  8. #include "BusUnitClient.h"
  9. #include "LogicClient.h"
  10. #include "LocalConfig.h"
  11. #include "PacketAnalizer.h"
  12. #include "ConsoleThread.h"
  13. #include "AutoDmp.h"
  14. //#include "Vga_Demo.h"
  15. #include <chrono>
  16. #include "common_api.h"
  17. #include <set>
  18. inline std::string CurrentDateTime()
  19. {
  20. // 获取当前时间点
  21. auto now = std::chrono::system_clock::now();
  22. // 将时间长度转换为微秒数
  23. auto now_us = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch());
  24. // 再转成tm格式
  25. auto now_time_t = std::chrono::system_clock::to_time_t(now);
  26. auto now_tm = std::localtime(&now_time_t);
  27. // 可以直接输出到标准输出
  28. // std::cout << std::put_time(now_tm, "%Y-%m-%d %H:%M:%S.") << std::setfill('0') << std::setw(6) << now_us.count() % 1000000 << std::endl;
  29. // 格式化字符,年月日时分秒
  30. std::string now_time_str;
  31. char buf[64];
  32. std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", now_tm);
  33. now_time_str += buf;
  34. // 格式化微秒
  35. snprintf(buf, sizeof(buf), ".%06lld ", now_us.count() % 1000000);
  36. now_time_str += buf;
  37. //printf("%s\n", now_time_str.c_str());
  38. return now_time_str;
  39. }
  40. AutoDmp atdmp;
  41. //CommonLogicClient WheelClient;
  42. #define MAX_THREAD_TEST (1)
  43. DWORD ConsoleThreadCount = MAX_THREAD_TEST;
  44. ConsoleThread g_ConsoleThread[MAX_THREAD_TEST];
  45. //UI_Thread g_UIThread;
  46. //Vga_Demo g_VgaDemoThread;
  47. bool StartConsoleThreads(bool start)
  48. {
  49. bool ret = true;
  50. //return ret;//
  51. for (DWORD i = 0; i < ConsoleThreadCount; i++)
  52. {
  53. if (start)
  54. {
  55. g_ConsoleThread[i].SetName("ConsoleThread");
  56. ret &= (g_ConsoleThread[i]).StartThread();
  57. printf("start console Thread:%d!\n", i);
  58. }
  59. else
  60. {
  61. (g_ConsoleThread[i]).StopThread(100);
  62. }
  63. }
  64. return ret;
  65. }
  66. bool WINAPI ConsoleHandler(DWORD msgType)
  67. {
  68. if ((msgType == CTRL_CLOSE_EVENT) ||
  69. (msgType == CTRL_SHUTDOWN_EVENT))
  70. {
  71. printf("Close console window!\n");
  72. StartConsoleThreads(false);
  73. GetCommandDispathIF()->WaitExit(500, true);
  74. /* Note: The system gives you very limited time to exit in this condition */
  75. return true;
  76. }
  77. /*
  78. Other messages:
  79. CTRL_BREAK_EVENT Ctrl-Break pressed
  80. CTRL_LOGOFF_EVENT User log off
  81. CTRL_SHUTDOWN_EVENT System shutdown
  82. */
  83. return false;
  84. }
  85. std::set<string> g_arrWhiteDirectory;
  86. string procdir;
  87. void KeepParent(string dir)
  88. {
  89. if (dir == procdir)
  90. return;
  91. g_arrWhiteDirectory.insert(dir);
  92. string parent = GetFileDirectory(dir);
  93. if (parent == procdir || parent.length() <= 0)
  94. return;
  95. KeepParent(parent);
  96. }
  97. void CheckWhiteDir(ResDataObject & driverConf, string& driverPath, string& sdkPath)
  98. {
  99. if (driverConf.GetFirstOf("oemdriver") > 0)
  100. {
  101. driverPath = (const char*)driverConf["oemdriver"];
  102. driverPath = ReplaceSubString(driverPath, string("%ROOT%"), procdir);
  103. if (driverConf.GetFirstOf("SDKPath") > 0)
  104. {
  105. sdkPath = (const char*)driverConf["SDKPath"];
  106. if (sdkPath.length() > 0)
  107. {
  108. if (sdkPath[0] != '\\')
  109. sdkPath = procdir + "\\" + sdkPath;
  110. else
  111. sdkPath = procdir + sdkPath;
  112. if (sdkPath[sdkPath.length() - 1] == '\\')
  113. sdkPath.erase(sdkPath.length() - 1, 1);
  114. }
  115. }
  116. }
  117. else if (driverConf.GetFirstOf("driver") > 0)
  118. {
  119. //普通驱动
  120. driverPath = (const char*)driverConf["driver"];
  121. driverPath = ReplaceSubString(driverPath, string("%ROOT%"), procdir);
  122. }
  123. driverPath = GetFileDirectory(driverPath);
  124. g_arrWhiteDirectory.insert(driverPath);
  125. KeepParent(driverPath);
  126. cout<< endl << "Keep Driver White Path " << driverPath << endl;
  127. if (sdkPath.length() > 0)
  128. {
  129. bool isSub = false;
  130. string sdkPpath;
  131. sdkPpath = GetFileDirectory(sdkPath);
  132. if (sdkPpath.length() >= driverPath.length())
  133. {
  134. //if (sdkPath.substr(0, driverPath.length()) == driverPath)
  135. if(sdkPpath == driverPath)
  136. {
  137. //sdk目录在driver子目录
  138. isSub = true;
  139. }
  140. }
  141. if (!isSub)
  142. {
  143. g_arrWhiteDirectory.insert(sdkPath);
  144. KeepParent(sdkPath);
  145. cout << "Keep Driver S D K Path " << sdkPath << endl;
  146. }
  147. else
  148. {
  149. cout << "With Driver S D K Path " << sdkPath << endl;
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// 清理已安装Driver驱动目录,保留白名单驱动
  155. /// </summary>
  156. /// <param name="whitelist"></param>
  157. void CleanDriver(ResDataObject* whitelist)
  158. {
  159. procdir = GetProcessDirectory();
  160. ResDataObject fileList;
  161. GetSpecificDriverConfigFiles(fileList, false);
  162. for (int x = 0; x < fileList.size(); x++)
  163. {
  164. string filename = fileList.GetKey(x);
  165. bool bFind = false;
  166. //std::cout << "CleanDriver " << fileList.GetKey(x) << " white list " << whitelist->encode() << endl;
  167. for (int y = 0; y < whitelist->size(); y++)
  168. {
  169. string key = (*whitelist)[y];
  170. if (filename.find(key) != string::npos)
  171. {
  172. bFind = true;
  173. //
  174. }
  175. }
  176. ResDataObject driverConfFile;
  177. ResDataObject driverConf;
  178. string driverPath,sdkPath;
  179. if (driverConfFile.loadFile(filename.c_str()))
  180. {
  181. if (driverConfFile.GetFirstOf("CONFIGURATION") < 0)
  182. continue;
  183. driverConf = driverConfFile["CONFIGURATION"];
  184. }
  185. if (!bFind)
  186. {
  187. DeleteFile(filename.c_str());
  188. }
  189. else
  190. {
  191. CheckWhiteDir(driverConf, driverPath, sdkPath);
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// 校验驱动,不在列表的需要移除配置
  197. /// </summary>
  198. /// <param name="fileList">驱动配置文件列表in/out paht:bool </param>
  199. /// <param name="driverList">要保留的驱动目录out</param>
  200. /// <param name="oneDriver">当前要检查的驱动信息 in</param>
  201. /// <param name="driverType">驱动类型如Detector/SynBox等</param>
  202. /// <returns></returns>
  203. bool CheckInDriver(ResDataObject& fileList, ResDataObject& driverList, ResDataObject& oneDriver, const char* driverType)
  204. {
  205. string procdir = GetProcessDirectory();
  206. for (int x = 0; x < fileList.size(); x++)
  207. {
  208. ResDataObject driverConfFile;
  209. if (driverConfFile.loadFile(fileList.GetKey(x)))
  210. {
  211. ResDataObject driverConf;
  212. if (driverConfFile.GetFirstOf("CONFIGURATION") < 0)
  213. continue;
  214. driverConf = driverConfFile["CONFIGURATION"];
  215. if (driverConf.GetFirstOf("MajorID") < 0)
  216. continue;
  217. string MajorID = (const char*)driverConf["MajorID"];
  218. if (strcmp(driverType, MajorID.c_str()) != 0)
  219. {
  220. continue;
  221. }
  222. if (driverConf.GetFirstOf("VendorID") >= 0 && oneDriver.GetFirstOf("VendorID") >= 0)
  223. {
  224. if (driverConf.GetFirstOf("ProductID") >= 0 && oneDriver.GetFirstOf("ProductID") >= 0)
  225. {
  226. if (strcmp(driverConf["ProductID"], oneDriver["ProductID"]) == 0 &&
  227. strcmp(driverConf["VendorID"], oneDriver["VendorID"]) == 0)
  228. {
  229. //匹配了
  230. if (driverConf.GetFirstOf("oemdriver") > 0)
  231. {
  232. string sdkPath, driverPath = driverConf["oemdriver"];
  233. driverPath = ReplaceSubString(driverPath, string("%ROOT%"), procdir);
  234. FILE* f = fopen(driverPath.c_str(), "r");
  235. if (f != NULL)
  236. {
  237. fileList[x] = true;
  238. fclose(f);
  239. if (oneDriver.GetFirstOf("Install") >= 0)
  240. {
  241. const char* install = oneDriver["Install"];
  242. if (strcmp(install, "true") == 0)
  243. {
  244. string dstPath = ReplaceSubString(fileList.GetKey(x), string("FullConfig"), string("DriverConfig"));
  245. //拷贝安装驱动到DriverConfig,暂时不预装
  246. //CopyFile(fileList.GetKey(x), dstPath.c_str(), FALSE);
  247. //std::cout << "Install Driver: " << dstPath << endl;
  248. }
  249. }
  250. //记录驱动保留目录
  251. //存在多个设备共享驱动情况
  252. //只要有一个需要安装,驱动不能删除
  253. driverPath = GetFileDirectory(driverPath);
  254. driverList.update(driverPath.c_str(), true);
  255. CheckWhiteDir(driverConf, driverPath, sdkPath);
  256. return true;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. }
  263. }
  264. return false;
  265. }
  266. // 删除文件(第二个参数bDelete表示是否删除至回收站,默认删除到回收站)
  267. bool RecycleFileOrFolder(string strPath, bool bDelete = true)
  268. {
  269. strPath += '\0';
  270. SHFILEOPSTRUCT shDelFile;
  271. memset(&shDelFile, 0, sizeof(SHFILEOPSTRUCT));
  272. shDelFile.fFlags |= FOF_SILENT; // 不显示进度
  273. shDelFile.fFlags |= FOF_NOERRORUI; // 不报告错误信息
  274. shDelFile.fFlags |= FOF_NOCONFIRMATION; // 直接删除,不进行确认
  275. // 设置SHFILEOPSTRUCT的参数为删除做准备
  276. shDelFile.wFunc = FO_DELETE; // 执行的操作
  277. shDelFile.pFrom = strPath.c_str(); // 操作的对象,也就是目录(注意:以“\0\0”结尾)
  278. shDelFile.pTo = NULL; // 必须设置为NULL
  279. if (bDelete) //根据传递的bDelete参数确定是否删除到回收站
  280. {
  281. shDelFile.fFlags &= ~FOF_ALLOWUNDO; //直接删除,不进入回收站
  282. }
  283. else
  284. {
  285. shDelFile.fFlags |= FOF_ALLOWUNDO; //删除到回收站
  286. }
  287. BOOL bres = SHFileOperation(&shDelFile); //删除
  288. return !bres;
  289. }
  290. /// <summary>
  291. /// 移除驱动,配置文件和驱动目录
  292. /// </summary>
  293. /// <param name="pszDriverConf">要移除的驱动文件路径</param>
  294. /// <param name="resRetainDriverList">要保留的驱动目录列表</param>
  295. void DeleteDriver(const char* pszDriverConf, ResDataObject& resRetainDriverList)
  296. {
  297. string procdir = GetProcessDirectory();
  298. ResDataObject driverConfFile;
  299. if (driverConfFile.loadFile(pszDriverConf))
  300. {
  301. ResDataObject driverConf;
  302. if (driverConfFile.GetFirstOf("CONFIGURATION") >= 0)
  303. {
  304. driverConf = driverConfFile["CONFIGURATION"];
  305. if (driverConf.GetFirstOf("oemdriver") > 0)
  306. {
  307. string driverPath = driverConf["oemdriver"];
  308. driverPath = ReplaceSubString(driverPath, string("%ROOT%"), procdir);
  309. driverPath = GetFileDirectory(driverPath);
  310. if (resRetainDriverList.GetFirstOf(driverPath.c_str()) < 0)
  311. {
  312. RecycleFileOrFolder(driverPath.c_str());
  313. std::cout << "Remove Driver Module: " << driverPath << endl;
  314. }
  315. }
  316. }
  317. }
  318. DeleteFile(pszDriverConf);
  319. std::cout << "Delete Driver Config: " << pszDriverConf << endl;
  320. }
  321. /// <summary>
  322. /// 校验驱动配置
  323. /// </summary>
  324. /// <param name="pszFileName">驱动配置文件名,不含路径,文件必须在设备目录里</param>
  325. void DefineDriver(const char* pszFileName)
  326. {
  327. string procdir = GetProcessDirectory();
  328. ResDataObject resDriver;
  329. string driverFile = procdir + "\\" + pszFileName;
  330. g_arrWhiteDirectory.clear();
  331. if (resDriver.loadFile(driverFile.c_str()))
  332. {
  333. string canInsstall = procdir + "\\DriverDefine\\DriverDefine.json";
  334. CopyFile(driverFile.c_str(), canInsstall.c_str(), FALSE);
  335. //先清理已安装驱动
  336. ResDataObject whitelist;
  337. if (resDriver.GetFirstOf("WhiteList") >= 0)
  338. {
  339. whitelist = resDriver["WhiteList"];
  340. CleanDriver(&whitelist);
  341. }
  342. if (resDriver.GetFirstOf("Drivers") >= 0)
  343. {
  344. //获取所有配置
  345. ResDataObject fileList, driverList;
  346. GetSpecificDriverConfigFiles(fileList, true);
  347. for (int fn = 0; fn < fileList.size(); fn++)
  348. {
  349. fileList[fn] = false;
  350. }
  351. //校验每个驱动
  352. ResDataObject ResDrivers = resDriver["Drivers"];
  353. for (int x = 0; x < ResDrivers.size(); x++)
  354. {
  355. //Detector/Generator/...
  356. ResDataObject resDrConf = ResDrivers[x];
  357. for (int y = 0; y < resDrConf.size(); y++)
  358. {
  359. ResDataObject oneDriver = resDrConf[y];
  360. CheckInDriver(fileList, driverList, oneDriver, ResDrivers.GetKey(x));
  361. }
  362. }
  363. //移除没有驱动程序的驱动配置
  364. //移除未在驱动配置列表的驱动
  365. //白名单驱动要保留
  366. for (int afn = 0; afn < fileList.size(); afn++)
  367. {
  368. if ((bool)fileList[afn] == false)
  369. {
  370. bool isWhite = false;
  371. string driverFile = fileList.GetKey(afn);
  372. for (int wn = 0; wn < whitelist.size(); wn++)
  373. {
  374. if (driverFile.find((const char*)whitelist[wn]) != string::npos)
  375. {
  376. isWhite = true;
  377. break;
  378. }
  379. }
  380. if (!isWhite)
  381. DeleteDriver(driverFile.c_str(), driverList);
  382. }
  383. }
  384. }
  385. }
  386. std::vector<string> dirList;
  387. FindSubFiles(procdir + "\\OEMDrivers", dirList, true, "*", true, 3, 2);
  388. FindSubFiles(procdir + "\\ServiceDrivers", dirList, true, "*", true, 2, 2);
  389. FindSubFiles(procdir + "\\SystemDrivers", dirList, true, "*", true, 2, 2);
  390. cout << endl << "After Define Left Driver Dirs." << endl;
  391. for (string td : dirList)
  392. {
  393. cout << td << endl;
  394. string tmp = td.substr(td.length() - 4);
  395. //size_t pos = td.find_last_of("conf");
  396. if (tmp == "conf" )
  397. {
  398. g_arrWhiteDirectory.insert(td);
  399. cout << "Keeped." << endl;
  400. }
  401. else
  402. {
  403. if (tmp == "Conf")
  404. {
  405. g_arrWhiteDirectory.insert(td);
  406. cout << "Keeped." << endl;
  407. }
  408. else
  409. {
  410. if (g_arrWhiteDirectory.find(td) != g_arrWhiteDirectory.end())
  411. {
  412. //
  413. cout << "Keeped." << endl;
  414. }
  415. else
  416. {
  417. cout << "Removed. Useless Dir" << endl;
  418. RecycleFileOrFolder(td);
  419. }
  420. }
  421. }
  422. }
  423. cout << endl <<endl << "After Define Left Driver Diretory " << endl;
  424. for (string dir : g_arrWhiteDirectory)
  425. {
  426. cout << dir << endl;
  427. }
  428. }
  429. int _tmain(int argc, _TCHAR* argv[])
  430. {
  431. bool status = true;
  432. printf("Main Thread:%d\n", GetCurrentThreadId());
  433. int nTotal = 0;
  434. int nMsgCount = 0;
  435. char szName[20][256];
  436. int count[10] = {0,0,0,0,0,0,0,0,0,0};
  437. if (argc > 1)
  438. {
  439. if (strcmp(argv[1], "test") == 0)
  440. {
  441. int nConnNum = 1;
  442. if (argc > 2)
  443. nConnNum = atoi(argv[2]);
  444. if (nConnNum > 20)
  445. {
  446. nConnNum = 20;
  447. }
  448. dios_mqtt_connection** pConns = new dios_mqtt_connection * [nConnNum];
  449. for (int x = 0; x < nConnNum; x++)
  450. {
  451. sprintf(szName[x], "TEST_MQTT_Server_%d", x);
  452. pConns[x] = NewConnection(szName[x], [szName,x,&count, &nTotal, &nMsgCount](ResDataObject* rsp, const char* topic, void* conn_void) {
  453. dios_mqtt_connection* conn = (dios_mqtt_connection*)conn_void;
  454. std::cout << "Server [" << szName[x] << "] " << CurrentDateTime() << "Get Msg from " << topic << " Msg Body " << rsp->encode() << endl;
  455. string tickSend = PacketAnalizer::GetPacketKey(rsp);
  456. DWORD dwTick = GetTickCount() - atoi(tickSend.c_str());
  457. nTotal += dwTick;
  458. nMsgCount++;
  459. if (dwTick < 3)
  460. {
  461. count[0]++;
  462. }
  463. else if (dwTick < 5)
  464. {
  465. count[1]++;
  466. }
  467. else if (dwTick < 10)
  468. {
  469. count[2]++;
  470. }
  471. else if (dwTick < 15)
  472. {
  473. count[3]++;
  474. }
  475. else if (dwTick < 20)
  476. {
  477. count[4]++;
  478. }
  479. else
  480. {
  481. count[5]++;
  482. //std::cout << "Receive Packet Use Time [" << dwTick << "]ms " << endl;
  483. }
  484. if (PacketAnalizer::GetPacketType(rsp) == PACKET_TYPE_RES)
  485. {
  486. //check cmd
  487. if ((PacketAnalizer::GetPacketCmd(rsp) == PACKET_CMD_OPEN) /*&& (PacketAnalizer::GetPacketKey(rsp) == realPath)*/)
  488. {
  489. //std::cout << "\n\n-----------" << CurrentDateTime() << "LogicClient::Open OK [" << m_strClientName << "] try open path:" << realPath << endl << endl;
  490. //ret = ProcessOpenResponse(*rsp);
  491. //if (m_bNeedNotify) {
  492. string notifyTopic = "DIOS/Tetst/";
  493. notifyTopic += "/Notify/#";
  494. SubscribeTopic(conn, notifyTopic.c_str());
  495. //}
  496. }
  497. else
  498. {
  499. std::cout << szName[x] << CurrentDateTime() << "Try Conn callback get unkown packet pointer [" << (UINT64)conn << endl;
  500. std::cout << "Unkown Packet: cmd [" << PacketAnalizer::GetPacketCmd(rsp) << "] packet key: " << PacketAnalizer::GetPacketKey(rsp) << "" << endl;
  501. //if (m_pPacketArrivedCallbackFunc != nullptr)
  502. //{
  503. // m_pPacketArrivedCallbackFunc(rsp, topic, conn);
  504. //}
  505. //else
  506. //{
  507. // m_pPacketReceivedQue->Lock();
  508. // m_pPacketReceivedQue->InQueue(*rsp);
  509. // //SetEvent(m_NotifyEvent);//notify to user
  510. // SetEvent(m_ResponseEvent);
  511. // m_pPacketReceivedQue->UnLock();
  512. //}
  513. }
  514. }
  515. else
  516. {
  517. }
  518. });
  519. char szTopic[256];
  520. //sprintf(szTopic, "DIOS/TEST/Notify/%d/%d/TestV", GetCurrentProcessId(), m_nIndex);
  521. sprintf(szTopic, "DIOS/TEST/Notify/+/%d/#", x);
  522. SubscribeTopic(pConns[x], szTopic);
  523. SubscribeTopic(pConns[x], "DIOS/TEST/Action/#", true);
  524. }
  525. std::cout << "Waiting quit..." << endl;
  526. while (1)
  527. {
  528. char cmd = getchar();
  529. if (cmd == 'q')
  530. break;
  531. else if (cmd == 'p')
  532. {
  533. std::cout << "Time < 3 : " << count[0] << endl;
  534. std::cout << "Time < 5 : " << count[1] << endl;
  535. std::cout << "Time < 10 : " << count[2] << endl;
  536. std::cout << "Time < 15 : " << count[3] << endl;
  537. std::cout << "Time < 20 : " << count[4] << endl;
  538. std::cout << "Time > 20 : " << count[5] << endl;
  539. memset(count, 0, sizeof(count));
  540. std::cout << "TotalTime " << nTotal << " ms , msg count : " << nMsgCount << "Average : " << nTotal*1.0/nMsgCount << endl;
  541. nTotal = nMsgCount = 0;
  542. }
  543. else if (cmd == 'x')
  544. {
  545. for (int x = 0; x < nConnNum; x++)
  546. {
  547. ResetConnection(pConns[x]);
  548. }
  549. }
  550. Sleep(10);
  551. }
  552. for (int x = 0; x < nConnNum; x++)
  553. {
  554. CloseConnection(pConns[x]);
  555. }
  556. delete[] pConns;
  557. std::cout << "Hello World!\n";
  558. return 0;
  559. }
  560. else
  561. {
  562. std::cout << "Starting Process Driver Define....." << endl;
  563. DefineDriver(argv[1]);
  564. std::cout << "Driver Define Done." << endl;
  565. return 0;
  566. }
  567. }
  568. setLogRootpath(((string)getChannelRootpath()).c_str());
  569. if (GetCommandDispathIF()->InitAs(DIOS_PROC_CHANNEL, (UINT64)GetCurrentProcessId()))
  570. {
  571. if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, true))
  572. {
  573. {
  574. LogicClient buClient("channel_temp", "", "", false);
  575. if (buClient.Open((const char*)getRootpath(), ALL_ACCESS) == RET_SUCCEED)
  576. {
  577. //buClient.ExitDriverProc();
  578. buClient.Close();
  579. /*DWORD count = buClient.GetDeviceCount();
  580. for (DWORD i = 0; i < count; i++)
  581. {
  582. UINT64 ProcId, Addr;
  583. ResDataObject DevType,devpath, MachineId;
  584. buClient.GetDeviceDescript(i, devpath, DevType, MachineId, ProcId, Addr);
  585. printf("path:%s\nProc:%I64u\nAddr:%I64u\n", (const char*)devpath, ProcId, Addr);
  586. LogicClient DevClient("channel_exe_temp","channel");
  587. if (DevClient.Open((const char*)devpath, ALL_ACCESS) >= RET_SUCCEED)
  588. {
  589. DevClient.Close();
  590. printf("Open Succeed\n");
  591. }
  592. else
  593. {
  594. printf("Open Failed\n");
  595. }
  596. }*/
  597. status = true;
  598. }
  599. else
  600. {
  601. status = false;
  602. }
  603. }
  604. //start work
  605. if (status)
  606. {
  607. if (StartConsoleThreads(true))
  608. {
  609. printf("Done Init Channel.going to sleep...\n");
  610. while (1){
  611. if (GetCommandDispathIF()->WaitExit(500) == true)
  612. {
  613. StartConsoleThreads(false);
  614. //ShareMemory_ServerStop();
  615. return 1;
  616. }
  617. }
  618. }
  619. }
  620. printf("Can't Start Console Thread.Exit in 3sec\n");
  621. Sleep(3000);
  622. }
  623. }
  624. //ShareMemory_ServerStop();
  625. return 0;
  626. }