DevBusManager.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479
  1. #include <stdio.h>
  2. #include "DevBusManager.h"
  3. #include "LocalConfig.h"
  4. #include "common_api.h"
  5. #include "PacketAnalizer.h"
  6. #include "P2PModule.h"
  7. #include "LogLocalHelper.h"
  8. #include "Log4CPP.h"
  9. #ifndef _CRT_SECURE_NO_WARNINGS
  10. #define _CRT_SECURE_NO_WARNINGS
  11. #endif
  12. inline string CurrentDateTime()
  13. {
  14. std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
  15. char buf[100] = { 0 };
  16. std::strftime(buf, sizeof(buf), " %Y-%m-%d %H:%M:%S ", std::localtime(&now));
  17. return buf;
  18. }
  19. DevBusManager g_BusManager;
  20. //Log4CPP::Logger* gLogger;
  21. //------------bus manager---------------------------
  22. DevBusManager::DevBusManager()
  23. {
  24. //m_pBusLocal = NULL;
  25. m_pLocalChannelClient = NULL;
  26. //m_pBusEth = NULL;
  27. //2025-2-21 m_pEthChannelClient = NULL;
  28. m_EnableEth = 0;//default is 0
  29. m_prootClient = NULL;
  30. SetName("DevBusManager");
  31. }
  32. DevBusManager::~DevBusManager()
  33. {
  34. UnloadBusDrv();
  35. }
  36. //#define NOTIFYCHANNEL ("Dev.DeviceService")
  37. //void DevBusManager::NotifyChannel_old(bool Local, bool Connect)
  38. //{
  39. // bool ret;
  40. // //criticalsection
  41. // pthread_mutex_lock(&m_Critical);
  42. // if (m_prootClient->GetDeviceStatus() == 1)
  43. // {
  44. // ResDataObject sub;
  45. // try {
  46. // sub.add("Source", getLocalEbusId());
  47. // sub.add("Sender", "");
  48. // sub.add("Content", getRootpath());
  49. // sub.add("MediaType", "");
  50. // sub.add("RequestId", "");
  51. // sub.add("PrivateData", "");
  52. // sub.add("ResourceNodeName", NOTIFYCHANNEL);
  53. // sub.add("AppRequest", "");
  54. // sub.add("Timestamp", "");
  55. //
  56. // if (Local == true)
  57. // {
  58. // if (m_pBusLocal != NULL && m_pBusLocal->IsConnected() == true)
  59. // {
  60. // if (Connect)
  61. // {
  62. // //make packet
  63. // sub.add("RequestOperation", "Create");
  64. // printf("Send Notify to Local Channel Create\n");
  65. // }
  66. // else
  67. // {
  68. // //make packet
  69. // sub.add("RequestOperation", "Delete");
  70. // printf("Send Notify to Local Channel Delete\n");
  71. // }
  72. // //Send
  73. // ret = m_pBusLocal->SendRawPacket(NOTIFYCHANNEL, sub.encode(), CCOS_HW_CHANNEL + 2);
  74. // if (ret == true)
  75. // {
  76. // printf("Send Notify to Local Channel OK\n");
  77. // }
  78. // else
  79. // {
  80. // printf("Send Notify to Local Channel Failed\n");
  81. // }
  82. //
  83. // }
  84. // else
  85. // {
  86. // printf("can't Send Notify to Local Channel .Local bus is Disconnected\n");
  87. // }
  88. // }
  89. // else
  90. // {
  91. // if (m_pBusEth != NULL && m_pBusEth->IsConnected() == true)
  92. // {
  93. // if (Connect)
  94. // {
  95. // //make packet
  96. // sub.add("RequestOperation", "Create");
  97. // printf("Send Notify to Eth Channel Create\n");
  98. // }
  99. // else
  100. // {
  101. // //make packet
  102. // sub.add("RequestOperation", "Delete");
  103. // printf("Send Notify to Eth Channel Delete\n");
  104. // }
  105. // //Send
  106. // ret = m_pBusEth->SendRawPacket(NOTIFYCHANNEL, sub.encode(), CCOS_HW_CHANNEL + 2);
  107. // if (ret == true)
  108. // {
  109. // printf("Send Notify to Eth Channel OK\n");
  110. // }
  111. // else
  112. // {
  113. // printf("Send Notify to Eth Channel Failed\n");
  114. // }
  115. //
  116. // }
  117. // else
  118. // {
  119. // printf("can't Send Notify to Eth Channel .Eth bus is Disconnected\n");
  120. // }
  121. //
  122. // }
  123. //
  124. //
  125. //
  126. // }
  127. // catch (...)
  128. // {
  129. // printf("Send Notify to Eth Channel Failed.unknown exp happen\n");
  130. //
  131. // }
  132. //
  133. // }
  134. // else
  135. // {
  136. // printf("Can't Send Notify to Channel:%d with Notify:%d .Device is not ready\n", Local, Connect);
  137. // }
  138. //
  139. // pthread_mutex_unlock(&m_Critical);
  140. //}
  141. //good
  142. void DevBusManager::NotifyChannel(bool Local, bool Connect)
  143. {
  144. //DeviceBUS *pBus = NULL;
  145. BusUnitClient *pClient = NULL;
  146. if (Local)
  147. {
  148. //pBus = m_pBusLocal;
  149. pClient = m_pLocalChannelClient;
  150. }
  151. else
  152. {
  153. //pBus = m_pBusEth;
  154. //2025-2-21 pClient = m_pEthChannelClient;
  155. }
  156. //criticalsection
  157. pthread_mutex_lock(&m_Critical);
  158. try {
  159. if ( pClient != NULL && pClient->IsClosed() == false)
  160. {
  161. //machineid
  162. //localbusid
  163. //procid
  164. //address
  165. ResDataObject Path;
  166. CcosDevFileHandle Handle;
  167. if (m_prootClient->GetFileHandle(Handle) && m_prootClient->GetFilePath(Path))
  168. {
  169. CCOS_PROC_TYPE master = GetConfigMode();
  170. bool NotChannel = (master != CCOS_PROC_CHANNEL);
  171. if (Connect)
  172. {
  173. //printf("AddDevice Dev:%s", (const char*)Path);
  174. FINFO("AddDevice Dev:{$},MachineId:{$},PId:{$} ,Addr:{$} ,Force:{$}", (const char*)Path, (const char*)Handle.GetTarget(false)[CCOS_PACK_TARGET_MACHINEID], (UINT64)Handle.GetTarget(false)[CCOS_PACK_TARGET_PROCID], (UINT64)Handle.GetTarget(false)[CCOS_PACK_TARGET_ADDR], NotChannel );
  175. //regist rootdev to channel
  176. pClient->AddDeviceDescrpt(
  177. (const char*)Path,
  178. (const char *)"Root",
  179. Handle.GetTarget(false)[CCOS_PACK_TARGET_MACHINEID],
  180. Handle.GetTarget(false)[CCOS_PACK_TARGET_PROCID],
  181. Handle.GetTarget(false)[CCOS_PACK_TARGET_ADDR],
  182. NotChannel
  183. );//force to update
  184. }
  185. else
  186. {
  187. //unregist rootdev from channel
  188. //exption:channel can't del itself
  189. if (NotChannel)
  190. {
  191. //printf("DelDevice Dev:%s", (const char*)Path);
  192. FINFO("DelDevice Dev:{$}", (const char*)Path);
  193. pClient->DelDeviceDescrpt((const char*)Path);
  194. }
  195. }
  196. }
  197. }
  198. else
  199. {
  200. FINFO("Notify Channels env is not right");
  201. }
  202. }
  203. catch (...)
  204. {
  205. //printf("Send Notify to Channel Failed.unknown exp happen\n");
  206. FINFO("Send Notify to Channel Failed.unknown exp happen\n");
  207. }
  208. pthread_mutex_unlock(&m_Critical);
  209. }
  210. //good
  211. void DevBusManager::ClearChannelList(bool Local)
  212. {
  213. pthread_mutex_lock(&m_Critical);
  214. if (Local)
  215. {
  216. m_LocalChannelDevList.clear();
  217. }
  218. else
  219. {
  220. m_EthChannelDevList.clear();
  221. }
  222. pthread_mutex_unlock(&m_Critical);
  223. }
  224. //good
  225. void DevBusManager::UpdateChannelList(bool Local)
  226. {
  227. BusUnitClient *pClient = NULL;
  228. vector<DeviceDescript> ddlist;
  229. FINFO("UpdateChannelList {$}", Local);
  230. if (Local)
  231. {
  232. pClient = m_pLocalChannelClient;
  233. }
  234. else
  235. {
  236. //2025-2-21 pClient = m_pEthChannelClient;
  237. }
  238. if (pClient && pClient->IsClosed() == false)
  239. {
  240. UINT64 Proc = 0;
  241. UINT64 Addr = 0;
  242. ResDataObject DevType,DevPath, MId;
  243. for (DWORD i = 0; i < pClient->GetDeviceCount(); i++)
  244. {
  245. if (pClient->GetDeviceDescript(i, DevPath, DevType, MId, Proc, Addr) == false)
  246. {
  247. break;
  248. }
  249. DeviceDescript dev;
  250. dev.SetKey((const char*)DevPath);
  251. dev.m_TargetType = (const char*)DevType;
  252. dev.m_MachineId = (const char*)MId;
  253. dev.m_ProcId = Proc;
  254. dev.m_Address = Addr;
  255. ddlist.push_back(dev);
  256. }
  257. }
  258. pthread_mutex_lock(&m_Critical);
  259. string lBusId;
  260. if (Local)
  261. {
  262. m_LocalChannelDevList.clear();
  263. for (size_t i = 0; i < ddlist.size(); i++)
  264. {
  265. lBusId = "";
  266. if (getBusIdFromFilePath(ddlist[i].GetKey(), lBusId))
  267. {
  268. //got busId from path
  269. map<string, DeviceDescript>::iterator proc_iter = m_LocalChannelDevList.find(lBusId);
  270. if (proc_iter != m_LocalChannelDevList.end())
  271. {
  272. //printf("dd exist\n");
  273. //for debug
  274. //for (size_t ei = 0; ei < ddlist.size(); ei++)
  275. //{
  276. //printf("ddlist[%zu].BusId:%s\n",ei, ddlist[ei].GetKey());
  277. //}
  278. //printf("Channel exist\n");
  279. map<string, DeviceDescript>::iterator iterdebug = m_LocalChannelDevList.begin();
  280. while (iterdebug != m_LocalChannelDevList.end())
  281. {
  282. //printf("channelexist.BusId:%s\n", iterdebug->first.c_str());
  283. ++iterdebug;
  284. }
  285. FERROR("same name Multiple busid exist in the Local Channel.BusId:{$}",lBusId);
  286. continue;
  287. }
  288. //insert
  289. m_LocalChannelDevList[lBusId] = ddlist[i];
  290. }
  291. else
  292. {
  293. FERROR("Wrong Dev Path:{$}", ddlist[i].GetKey());
  294. }
  295. }
  296. }
  297. else
  298. {
  299. m_EthChannelDevList.clear();
  300. for (size_t i = 0; i < ddlist.size(); i++)
  301. {
  302. lBusId = "";
  303. if (getBusIdFromFilePath(ddlist[i].GetKey(), lBusId))
  304. {
  305. //got busId from path
  306. map<string, DeviceDescript>::iterator proc_iter = m_EthChannelDevList.find(lBusId);
  307. if (proc_iter != m_EthChannelDevList.end())
  308. {
  309. FERROR("same name Multiple busid exist in the Eth Channel.BusId:{$}", lBusId);
  310. continue;
  311. }
  312. //insert
  313. m_EthChannelDevList[lBusId] = ddlist[i];
  314. }
  315. else
  316. {
  317. FERROR("Wrong Dev Path:{$}", ddlist[i].GetKey());
  318. }
  319. }
  320. }
  321. pthread_mutex_unlock(&m_Critical);
  322. }
  323. //good
  324. bool DevBusManager::DoLocalChannelPrcedure(void)
  325. {
  326. FINFO("do..something local");
  327. ResDataObject packet, Context;
  328. try {
  329. //printf("Thread:%d,DrvTree Thread Loop\n", GetCurrentThreadId());
  330. //Local Channel存在 且 所有的设置都正常(其他判断应该在TIMEOUT里面进行)
  331. if (m_pLocalChannelClient->IsClosed() == false)
  332. {
  333. //只接收通知
  334. //设备更新通知,ADD&DEL DEVICE,
  335. //Ready通知,退出通知,UPDATE exitFlag
  336. PACKET_CMD cmd;
  337. do {
  338. cmd = m_pLocalChannelClient->ReadCmd(packet);
  339. if (cmd == PACKET_CMD_UPDATE)
  340. {
  341. if (m_pLocalChannelClient->GetDeviceUsage() == false)
  342. {
  343. //channel not ready
  344. continue;
  345. }
  346. }
  347. if (cmd == PACKET_CMD_ADD || cmd == PACKET_CMD_DEL)
  348. {
  349. UpdateChannelList(true);
  350. }
  351. else
  352. {
  353. //ignore others
  354. //printf("Thread:%d,DrvTree Thread Ignore\n", GetCurrentThreadId(), cmd);
  355. }
  356. } while (cmd != PACKET_CMD_NONE);
  357. }
  358. else
  359. {
  360. //printf("Thread:%d,Local Channel not in Open State\n", GetCurrentThreadId());
  361. TryConnectChannel(true);
  362. }
  363. }
  364. catch (...)
  365. {
  366. //printf("Thread:%d,Exeption in DrvTree Thread\n", GetCurrentThreadId());
  367. return false;
  368. }
  369. return true;
  370. }
  371. //good
  372. bool DevBusManager::DoEthChannelPrcedure(void)
  373. {
  374. return true;
  375. //2025.2.21
  376. /*
  377. FINFO("do..something Eth");
  378. ResDataObject packet, Context;
  379. try {
  380. //printf("Thread:%d,DrvTree Thread Loop\n", GetCurrentThreadId());
  381. //2025-2-21 if (m_pEthChannelClient == NULL)
  382. {
  383. return false;
  384. }
  385. PACKET_CMD cmd;
  386. //Local Channel存在 且 所有的设置都正常(其他判断应该在TIMEOUT里面进行)
  387. if (m_EnableEth)
  388. {
  389. if (m_pEthChannelClient->IsClosed() == false)
  390. {
  391. //只接收通知
  392. //设备更新通知,ADD&DEL DEVICE,
  393. //Ready通知,退出通知,UPDATE exitFlag
  394. do {
  395. cmd = m_pEthChannelClient->ReadCmd(packet);
  396. if (cmd == PACKET_CMD_UPDATE)
  397. {
  398. if (m_pEthChannelClient->GetDeviceUsage() == false)
  399. {
  400. //channel not ready
  401. continue;
  402. }
  403. }
  404. if (cmd == PACKET_CMD_ADD || cmd == PACKET_CMD_DEL)
  405. {
  406. UpdateChannelList(false);
  407. }
  408. else
  409. {
  410. //ignore others
  411. //printf("Thread:%d,DrvTree Thread Ignore\n", GetCurrentThreadId(), cmd);
  412. }
  413. } while (cmd != PACKET_CMD_NONE);
  414. }
  415. else
  416. {
  417. //printf("Thread:%d,Eth Channel not in Open State\n", GetCurrentThreadId());
  418. TryConnectChannel(false);
  419. }
  420. }
  421. else
  422. {
  423. //already disconnected
  424. //just clear the packet in the Client
  425. do {
  426. cmd = m_pEthChannelClient->ReadCmd(packet);
  427. } while (cmd != PACKET_CMD_NONE);
  428. }
  429. }
  430. catch (...)
  431. {
  432. //printf("Thread:%d,Exeption in DrvTree Thread\n", GetCurrentThreadId());
  433. return false;
  434. }
  435. */
  436. return true;
  437. }
  438. //good
  439. CCOS_PACKET_ROUTE DevBusManager::GetBusIdDirection(string &BusId)
  440. {
  441. string lBusId;
  442. if (BusId.size() == 0)
  443. {
  444. return CCOS_PACKET_ROUTE_NOTARGET;
  445. }
  446. pthread_mutex_lock(&m_Critical);
  447. map<string, DeviceDescript>::iterator proc_iter = m_LocalChannelDevList.find(BusId);
  448. if (proc_iter != m_LocalChannelDevList.end())
  449. {
  450. //got match
  451. //got match
  452. pthread_mutex_unlock(&m_Critical);
  453. return CCOS_PACKET_ROUTE_LOCAL;
  454. }
  455. proc_iter = m_EthChannelDevList.find(BusId);
  456. if (proc_iter != m_EthChannelDevList.end())
  457. {
  458. //got match
  459. //got match
  460. pthread_mutex_unlock(&m_Critical);
  461. return CCOS_PACKET_ROUTE_ETH;
  462. }
  463. pthread_mutex_unlock(&m_Critical);
  464. return CCOS_PACKET_ROUTE_ANY;
  465. }
  466. //good
  467. /// <summary>
  468. /// 测试连接Channel,本进程是否OK
  469. /// </summary>
  470. /// <param name="Local">是否本地</param>
  471. /// <returns></returns>
  472. bool DevBusManager::TryConnectChannel(bool Local)
  473. {
  474. return true;
  475. //DeviceBUS *pBus = NULL;
  476. BusUnitClient *pClient = NULL;
  477. //printf("TryConnectChannel Local:%d\n", Local);
  478. FINFO("TryConnectChannel Local:{$}\n", Local);
  479. if (Local)
  480. {
  481. //pBus = m_pBusLocal;
  482. pClient = m_pLocalChannelClient;
  483. }
  484. else
  485. {
  486. //pBus = m_pBusEth;
  487. //2025.2.21 pClient = m_pEthChannelClient;
  488. }
  489. if ( pClient != NULL)
  490. {
  491. //disconnect first
  492. //printf("Disconnect Local(%d) first \n",Local);
  493. FINFO("Disconnect Local({$}) first \n", Local);
  494. if (pClient->IsClosed() == false)
  495. {
  496. NotifyChannel(Local, false);
  497. pClient->Close();
  498. }
  499. BusUnitClient ThisProc("CCOS_CHANNEL_TEST_CLIENT");
  500. DWORD tick = GetTickCount();
  501. if (ThisProc.Open(getRootpath(), ALL_ACCESS, MAX_CHECK_TIME_PERIOD*4 ) >= RET_SUCCEED)
  502. {
  503. tick = GetTickCount() - tick;
  504. if (ThisProc.GetDeviceUsage())
  505. {
  506. //this proc is ready
  507. //reconnect sec
  508. //printf("open Local(%d) channel:%s \n", Local, (const char*)getChannelRootpath());
  509. FINFO("open Local({$}) channel:{$} \n", Local, (const char*)getChannelRootpath());
  510. RET_STATUS ret = (RET_STATUS)pClient->Open((const char*)getChannelRootpath(), ALL_ACCESS, MAX_CHECK_TIME_PERIOD / 2);
  511. if (ret >= RET_SUCCEED)
  512. {
  513. if (pClient->GetDeviceUsage())
  514. {
  515. //it's ready
  516. UpdateChannelList(Local);
  517. //regist procRoot as device
  518. NotifyChannel(Local, true);
  519. //second clear
  520. ThisProc.Close();
  521. //printf("TryConnectChannel Local(%d) Ready.ClientStatus:%d\n", Local, pClient->IsClosed());
  522. FINFO("TryConnectChannel Local({$}) Ready.ClientStatus:{$}\n", Local, pClient->IsClosed());
  523. return true;
  524. }
  525. //printf("TryConnectChannel Local(%d).channel exist,but not ready\n", Local);
  526. FINFO("TryConnectChannel Local({$}).channel exist,but not ready\n", Local);
  527. //channel exist,but not ready
  528. pClient->Close();
  529. }
  530. else
  531. {
  532. //printf("open Local(%d) channel:%s Failed.RetCode:%d\n", Local, (const char*)getChannelRootpath(),ret);
  533. FERROR("open Local({$}) channel:{$} Failed.RetCode:{$}\n", Local, (const char*)getChannelRootpath(), (int)ret);
  534. }
  535. }
  536. else
  537. {
  538. FINFO("Dev {$} Is not in Usage State", (const char*)getRootpath());
  539. }
  540. ThisProc.Close();
  541. }
  542. else
  543. {
  544. FINFO("Open {$} Failed", (const char*)getRootpath());
  545. }
  546. }
  547. ClearChannelList(Local);
  548. //printf("TryConnectChannel Local(%d) Not Ready\n", Local);
  549. FINFO("TryConnectChannel Local({$}) Not Ready\n", Local);
  550. return false;
  551. }
  552. //good
  553. bool DevBusManager::TryDisConnectChannel(bool Local)
  554. {
  555. //DeviceBUS *pBus = NULL;
  556. BusUnitClient *pClient = NULL;
  557. if (Local)
  558. {
  559. //pBus = m_pBusLocal;
  560. pClient = m_pLocalChannelClient;
  561. }
  562. else
  563. {
  564. //pBus = m_pBusEth;
  565. //2025.2.21 pClient = m_pEthChannelClient;
  566. }
  567. if ( pClient != NULL )
  568. {
  569. if (pClient->IsClosed() == false)
  570. {
  571. if (pClient->GetDeviceUsage())
  572. {
  573. //unregist procRoot as device
  574. NotifyChannel(Local, false);
  575. }
  576. pClient->Close();
  577. }
  578. }
  579. ClearChannelList(Local);
  580. return true;
  581. }
  582. //using set_ws_param = std::tuple< SubSystemDevImpl*, const char*, int >;
  583. void* DevBusManagerExecThreadFunc(void* pPara)
  584. {
  585. DevBusManager* pDevManger = (DevBusManager*)pPara;
  586. pDevManger->ExecFunc();
  587. return 0;
  588. }
  589. bool DevBusManager::ExecFunc(void)
  590. {
  591. DWORD waitcount = 3;
  592. std::vector<std::shared_ptr<LinuxEvent>> vec;
  593. vec.resize(3);
  594. vec[0] = m_ExitFlag;
  595. vec[1] = m_prootClient->GetNotifyHandle();
  596. vec[2] = m_pLocalChannelClient->GetNotifyHandle();
  597. //if (m_pEthChannelClient)
  598. //{
  599. // vec[3] = m_pEthChannelClient->GetNotifyHandle();
  600. // waitcount = 4;
  601. //}
  602. DWORD wait = LinuxEvent::WaitForMultipleEvents(vec, MAX_CHECK_TIME_PERIOD);
  603. //printf("Thread:%d,hit DrvTree Entry.code:%d\n", GetCurrentThreadId(), wait);
  604. if (wait == WAIT_TIMEOUT)
  605. {
  606. //timeout
  607. //检查 LocalChannel 和EthChannel 的状态,并更新
  608. //just try it
  609. //在Bus处于连接状态下,检查Client的状态
  610. //2025.2.21 B
  611. //if (m_pLocalChannelClient->IsClosed() == true)
  612. //{
  613. // FINFO("LocalChannelClient is Closed.try connect local channel");
  614. // TryConnectChannel(true);
  615. //}
  616. //if (m_pBusEth != NULL && m_pBusEth->IsConnected())
  617. // //2025.2.21
  618. //if(m_pEthChannelClient)
  619. //{
  620. // if (m_pEthChannelClient->IsClosed() == true)
  621. // {
  622. // FINFO("EthChannelClient is Closed.try connect eth channel");
  623. // TryConnectChannel(false);
  624. // }
  625. //}
  626. }
  627. else if (wait == WAIT_OBJECT_0)
  628. {
  629. FINFO("Exit Evt .Exit Thread");
  630. return false;
  631. }
  632. else if (wait == WAIT_OBJECT_0 + 1)
  633. {
  634. //got notify
  635. if (DoRootDevPrcedure() == false)
  636. {
  637. return false;
  638. }
  639. }
  640. else if (wait == WAIT_OBJECT_0 + 2)
  641. {
  642. //do local channel work
  643. //got notify
  644. if (DoLocalChannelPrcedure() == false)
  645. {
  646. return false;
  647. }
  648. }
  649. else if (wait == WAIT_OBJECT_0 + 3)
  650. {
  651. //do eth channel work
  652. //got notify
  653. if (DoEthChannelPrcedure() == false)
  654. {
  655. return false;
  656. }
  657. }
  658. //if (m_pBusEth)
  659. //{
  660. // if (m_pBusEth->IsConnected() == false && m_EnableEth != 0)
  661. // {
  662. // printf("Eth DisConnected.Enable Eth is TRUE: Try Connect\n");
  663. // FINFO("Eth DisConnected.Enable Eth is TRUE: Try Connect\n");
  664. // if (m_pBusEth->Connect(m_EthConnection))
  665. // {
  666. // printf("Eth Connection: Succeed\n");
  667. // FINFO("Eth Connection: Succeed\n");
  668. // TryConnectChannel(false);
  669. // }
  670. // else
  671. // {
  672. // printf("Eth Connection: Failed\n");
  673. // FINFO("Eth Connection: Failed\n");
  674. // }
  675. // }
  676. //}
  677. //if (m_pBusLocal)
  678. //{
  679. // //check local
  680. // if (m_pBusLocal->IsConnected() == false)
  681. // {
  682. // printf("Local Connection: Try Connect\n");
  683. // FERROR("Local Connection: Try Connect\n");
  684. // if (m_pBusLocal->Connect(m_LocalConnection))
  685. // {
  686. // printf("Local Connection: Succeed\n");
  687. // FINFO("Local Connection: Succeed\n");
  688. // TryConnectChannel(true);
  689. // }
  690. // else
  691. // {
  692. // printf("Local Connection: Failed\n");
  693. // FERROR("Local Connection: Failed\n");
  694. // }
  695. // }
  696. //}
  697. return true;
  698. }
  699. //good
  700. bool DevBusManager::Exec(void)
  701. {
  702. pthread_t threadID;
  703. pthread_attr_t attr;
  704. struct timespec ts;
  705. int ret = 0;
  706. // 初始化线程属性(可连接状态)
  707. pthread_attr_init(&attr);
  708. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  709. // 创建线程
  710. if (pthread_create(&threadID, &attr, DevBusManagerExecThreadFunc, this) != 0) {
  711. pthread_attr_destroy(&attr);
  712. return false;
  713. }
  714. pthread_attr_destroy(&attr);
  715. // 计算45秒后的绝对时间(用于超时控制)
  716. struct timeval now;
  717. gettimeofday(&now, NULL);
  718. ts.tv_sec = now.tv_sec + 45;
  719. ts.tv_nsec = now.tv_usec * 1000;
  720. // 带超时的线程等待
  721. ret = pthread_timedjoin_np(threadID, NULL, &ts);
  722. if (ret == 0) {
  723. usleep(1000000); // 睡眠1秒(1000毫秒)
  724. return true;
  725. }
  726. // 超时或错误处理
  727. if (ret == ETIMEDOUT) {
  728. pthread_detach(threadID); // 防止资源泄漏
  729. }
  730. return false;
  731. }
  732. //good
  733. void DevBusManager::UpdateEthConnectOption(int Enable, ResDataObject &routerIp)
  734. {
  735. string temp;
  736. m_EthConnection.clear();
  737. m_EnableEth = Enable;
  738. m_EthConnection.add(EBUS_CONNECTION_LOCAL, 0);
  739. temp = (const char*)getLocalEbusId();
  740. if (temp.size() > 0)
  741. {
  742. m_EthConnection.add(EBUS_CONNECTION_BUSID, temp.c_str());
  743. }
  744. temp = (const char*)getLocalEbusPort();
  745. if (temp.size() > 0)
  746. {
  747. m_EthConnection.add(EBUS_CONNECTION_PORT, temp.c_str());
  748. }
  749. if (m_EnableEth)
  750. {
  751. //go eth
  752. temp = (const char*)routerIp;
  753. if (temp.size() > 0)
  754. {
  755. m_EthRouterIp = temp.c_str();
  756. m_EthConnection.add(EBUS_CONNECTION_ROUTERIP, temp.c_str());
  757. }
  758. else
  759. {
  760. temp = (const char*)getLocalEbusRouterIp();
  761. if (temp.size() > 0)
  762. {
  763. m_EthRouterIp = temp.c_str();
  764. }
  765. else
  766. {
  767. m_EthRouterIp = "127.0.0.1";
  768. }
  769. m_EthConnection.add(EBUS_CONNECTION_ROUTERIP, temp.c_str());
  770. }
  771. }
  772. }
  773. //good
  774. bool DevBusManager::DoRootDevPrcedure(void)
  775. {
  776. ResDataObject packet, Context;
  777. try {
  778. //printf("Thread:%d,DrvTree Thread Loop\n", GetCurrentThreadId());
  779. if (m_prootClient->IsClosed() == false)
  780. {
  781. PACKET_CMD cmd;
  782. do {
  783. cmd = m_prootClient->ReadCmd(packet);
  784. if (cmd == PACKET_CMD_UPDATE)
  785. {
  786. string key = PacketAnalizer::GetPacketKey(&packet);
  787. if (key == "Status")
  788. {
  789. if (m_prootClient->GetDeviceUsage())
  790. {
  791. FINFO("Got Root Status Usage Evt.regist rootdev to channels ");
  792. NotifyChannel(true, true);//local
  793. NotifyChannel(false, true);//eth
  794. }
  795. else
  796. {
  797. //this proc not ready
  798. continue;
  799. }
  800. }
  801. else
  802. {
  803. //printf("Got Eth Connection Update\n");
  804. //printf("Got Eth Connection Update\n");
  805. FINFO("Got Other Updates");
  806. ResDataObject Ip;
  807. m_prootClient->GetEthBusRouterIp(Ip);
  808. AdjustEthConnection(m_prootClient->GetEthBusSwitch(), Ip);
  809. }
  810. }
  811. else
  812. {
  813. //ignore others
  814. //printf("Thread:%d,DrvTree Thread Ignore\n", GetCurrentThreadId(), cmd);
  815. }
  816. } while (cmd != PACKET_CMD_NONE);
  817. }
  818. else
  819. {
  820. {
  821. //printf("Thread:%d,WTF Happen?? Failed\n", GetCurrentThreadId());
  822. FINFO("Thread:{$},WTF Happen?? Failed\n", GetCurrentThreadId());
  823. return false;
  824. }
  825. }
  826. }
  827. catch (...)
  828. {
  829. //printf("Thread:%d,Exeption in DrvTree Thread\n", GetCurrentThreadId());
  830. FINFO("Thread:{$},Exeption in DrvTree Thread\n", GetCurrentThreadId());
  831. return false;
  832. }
  833. return true;
  834. }
  835. //good
  836. void DevBusManager::AdjustEthConnection(int Enable, ResDataObject &routerIp)
  837. {
  838. //if (m_pBusEth)
  839. //{
  840. // string temp;
  841. // //check the ip
  842. // const char* pIp = (const char*)routerIp;
  843. // bool sameip = false;
  844. //
  845. // if (pIp[0] != 0)
  846. // {
  847. // sameip = (m_EthRouterIp == routerIp);
  848. // }
  849. // else
  850. // {
  851. // sameip = true;
  852. // }
  853. // //printf("Eth Connection: Enable:%d,Ip:%s\n",Enable,(const char*)routerIp);
  854. // bool Changed = ((Enable != m_EnableEth) || !sameip);
  855. // if (Changed)
  856. // {
  857. // printf("Eth Connection: Changed.Disconnect\n");
  858. // FINFO("Eth Connection: Changed.Disconnect Eth first.oldip:{$},newip:{$},oldEnableFlag:{$},newEnableFlag:{$}",(const char*)m_EthRouterIp ,pIp, m_EnableEth, Enable);
  859. // ///TODO : 需要将HANDLEmanger 接口转出
  860. // //clear handles from eth
  861. // //g_HandleManager.ClearRemoteHandles();
  862. // //unregist from channel
  863. // TryDisConnectChannel(false);
  864. // //update connections
  865. // UpdateEthConnectOption(Enable, routerIp);
  866. // //Disconnect ethbus here
  867. // m_pBusEth->DisConnect();
  868. // }
  869. // if (m_EnableEth && m_pBusEth->IsConnected() == false)
  870. // {
  871. // //go eth or local
  872. // printf("Adjust Eth Connection: Try Connect\n");
  873. // FINFO("Adjust Eth Connection: Try Connect\n");
  874. // if (m_pBusEth->Connect(m_EthConnection))
  875. // {
  876. // printf("Eth Connection: Succeed\n");
  877. // FINFO("Eth Connection: Succeed\n");
  878. // TryConnectChannel(false);
  879. // }
  880. // else
  881. // {
  882. // printf("Eth Connection: Failed\n");
  883. // FINFO("Eth Connection: Failed\n");
  884. // }
  885. // }
  886. //}
  887. }
  888. //good
  889. bool DevBusManager::OnStartThread()
  890. {
  891. //printf("========== DevBusManager::OnStartThread 0X%08X \n", GetCurrentThreadId());
  892. FINFO("This is {$} BusManager Thread", (const char*)getRootpath());
  893. //Sleep(5000);
  894. std::cout << "DevBusManager::OnStartThread - Thread ID: 0X"
  895. << std::hex << std::uppercase << GetCurrentThreadId()
  896. << std::dec << std::endl;
  897. std::cout << "DevBusManager::OnStartThread - Attempting to open root client with path: "
  898. << (const char*)getRootpath() << std::endl;
  899. if (m_prootClient->Open((const char*)getRootpath(), ALL_ACCESS) < RET_SUCCEED)
  900. {
  901. std::cout << "ERROR: DevBusManager OnStartThread m_prootClient Open FAILED - Path: "
  902. << (const char*)getRootpath() << std::endl;
  903. return false;
  904. }
  905. std::cout << "DevBusManager::OnStartThread - Successfully opened root client" << std::endl;
  906. //just try it
  907. //TryConnectChannel(true);
  908. //TryConnectChannel(false);
  909. return true;
  910. }
  911. //good
  912. bool DevBusManager::OnEndThread()
  913. {
  914. //printf("========== DevBusManager::OnEndThread 0X%08X \n", GetCurrentThreadId());
  915. return true;
  916. }
  917. void DevBusManager::InitLog()
  918. {
  919. //string logfile = GetProcessDirectory() + "\\logs\\eBus_Status.log";
  920. //Logger *p = CreateLogger();
  921. //p->SetLogFilepath(logfile.c_str());
  922. //SetLogger(p);
  923. }
  924. //good
  925. bool DevBusManager::LoadBusDrv()
  926. {
  927. CCOS_PROC_TYPE master = GetConfigMode();
  928. string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
  929. string LogHost = (string)getRootpath();
  930. std::string moduleName = "eBus";
  931. bool logret = initLogModule(
  932. LogHost, // 主机名(用于日志路径中的{host}占位符)
  933. moduleName, // 唯一模块名
  934. strLogPath, // 配置文件路径
  935. true // 是否输出到控制台(可选)
  936. );
  937. if (!logret) {
  938. std::cerr << "Log init failed!" << std::endl;
  939. }
  940. // 绑定当前动态库的模块名(调用自身实现的接口)
  941. DeviceBusSetLocalModuleName(moduleName);
  942. //share memory settting
  943. std::cout << "-*-*-* LoadBusDrv Start" << CurrentDateTime() << "" << endl;
  944. FINFO("InitEbusEnv");
  945. //InitEbusEnv(getEbusLogFlag());
  946. ResDataObject P2pServer;
  947. ResDataObject P2pClient;
  948. bool P2pEnable = getP2pFlag();
  949. if (P2pEnable)
  950. {
  951. P2pServer = getP2pServerIp();
  952. P2pClient = getP2pRole();
  953. }
  954. //load local
  955. //if (master == 0 || master == 1 || master == 2)
  956. {
  957. //Slave&Master&Channel&Client
  958. m_pLocalChannelClient = new BusUnitClient("LocalChannelClient");
  959. m_pLocalChannelClient->SetRouter(CCOS_PACKET_ROUTE_LOCAL);
  960. //m_pLocalChannelClient->SetClientRootID(, "");
  961. //m_pBusLocal = (DeviceBUS*)new eBus();
  962. //if (master == CCOS_PROC_MASTER && P2pEnable)
  963. //{
  964. // if ((bool)P2pClient == true)
  965. // {
  966. // FINFO("InitP2P {$}", (const char*)P2pServer);
  967. // m_pBusLocal->InitP2P((const char*)P2pServer, (const char*)getLocalEbusId(), false);
  968. // }
  969. //}
  970. //m_pBusLocalThread = new BusThread();
  971. //string logfile = GetProcessDirectory() + "\\logs\\Local_ebusDispathlog.log";
  972. //m_pBusLocalLog = CreateLogger();
  973. //m_pBusLocalLog->SetLogFilepath(logfile.c_str());
  974. //m_pBusLocalThread->SetLogger(m_pBusLocalLog);
  975. //m_pBusLocalThread->SetName("BusLocalThread");
  976. //m_pBusLocal->SetReceiveThread(m_pBusLocalThread);
  977. //
  978. //logfile = GetProcessDirectory() + "\\logs\\Local_ebuslog.log";
  979. //m_pBusLocal->SetLogPath(logfile.c_str());
  980. }
  981. std::cout << "-*-*-* LocalChannelClient over." << CurrentDateTime() << "" << endl;
  982. FINFO("LocalChannelClient over.");
  983. //load eth
  984. //if (master == 1 || master == 3)
  985. //Channel & Slave no need to connect eth
  986. if (master == CCOS_PROC_MASTER )
  987. {
  988. //Master&Client
  989. // //2025.2.21
  990. //m_pEthChannelClient = new BusUnitClient("EthChannelClient");
  991. //m_pEthChannelClient->SetRouter(CCOS_PACKET_ROUTE_ETH);
  992. //m_pEthChannelClient->SetClientRootID(, "")
  993. //m_pBusEth = (DeviceBUS*)new eBus();
  994. //if (master == CCOS_PROC_MASTER && P2pEnable)
  995. //{
  996. // if ((bool)P2pClient == false)
  997. // {
  998. // m_pBusEth->InitP2P((const char*)P2pServer, (const char*)getLocalEbusId(), true);
  999. // }
  1000. //}
  1001. //m_pBusEthThread = new BusThread();
  1002. //m_pBusEthThread->m_bLocal = false;//make thread notice packet they received is from where
  1003. //string logfile = GetProcessDirectory() + "\\logs\\Eth_ebusDispathlog.log";
  1004. //m_pBusEthLog = CreateLogger();
  1005. //m_pBusEthLog->SetLogFilepath(logfile.c_str());
  1006. //m_pBusEthThread->SetLogger(m_pBusEthLog);
  1007. //m_pBusEthThread->SetName("BusEthThread");
  1008. //m_pBusEth->SetReceiveThread(m_pBusEthThread);
  1009. //logfile = GetProcessDirectory() + "\\logs\\Eth_ebuslog.log";
  1010. //m_pBusEth->SetLogPath(logfile.c_str());
  1011. }
  1012. if (m_prootClient == NULL)
  1013. {
  1014. m_prootClient = new BusUnitClient("DevBusManager_rootClient");
  1015. }
  1016. //connect local
  1017. //if (m_pBusLocal)
  1018. //{
  1019. // FINFO("Connect Local Ebus");
  1020. // m_LocalConnection.add(EBUS_CONNECTION_LOCAL, 1);
  1021. // //m_LocalConnection.add(EBUS_CONNECTION_BUSID, (UINT64)GetCurrentProcessId());
  1022. // m_LocalConnection.add(EBUS_CONNECTION_BUSID, (const char*)getLocalEbusId());
  1023. // //
  1024. // if (m_pBusLocal->Connect(m_LocalConnection) == false)
  1025. // {
  1026. // return false;
  1027. // }
  1028. // if (m_pBusLocalThread->StartThread() == false)
  1029. // {
  1030. // return false;
  1031. // }
  1032. // FINFO("Connect Local Ebus Over.");
  1033. //}
  1034. //if (m_pBusEth)
  1035. //{
  1036. // FINFO("Connect Eth Ebus");
  1037. // //try connect eth
  1038. // int EnableEth = m_prootClient->GetEthBusSwitch();
  1039. // ResDataObject Ip;
  1040. // m_prootClient->GetEthBusRouterIp(Ip);
  1041. // UpdateEthConnectOption(EnableEth, Ip);
  1042. // if (m_EnableEth)
  1043. // {
  1044. // if (m_pBusEth->Connect(m_EthConnection))
  1045. // {
  1046. // printf("ETH Connect Succeed in the Entry\n");
  1047. // //just try it
  1048. // }
  1049. // else
  1050. // {
  1051. // printf("ETH Connect Failed in the Entry\n");
  1052. // }
  1053. // }
  1054. // if (m_pBusEthThread->StartThread() == false)
  1055. // {
  1056. // return false;
  1057. // }
  1058. // FINFO("Connect Eth Ebus over.");
  1059. //}
  1060. //std::cout << "-*-*-* Connect Ebus over." << CurrentDateTime() << "" << endl;
  1061. InitLog();
  1062. bool ret = StartThread();
  1063. std::cout << "-*-*-* StartThread over." << CurrentDateTime() << "" << endl;
  1064. return ret;
  1065. }
  1066. //good
  1067. bool DevBusManager::UnloadBusDrv()
  1068. {
  1069. StopThread(100);
  1070. //if (m_pBusLocal)
  1071. {
  1072. NotifyChannel(true, false);
  1073. }
  1074. //if (m_pBusEth)
  1075. {
  1076. NotifyChannel(false, false);
  1077. }
  1078. if (m_pLocalChannelClient)
  1079. {
  1080. FINFO("Disconnect Local EBUS");
  1081. //if (m_pBusLocal->IsConnected())
  1082. {
  1083. m_pLocalChannelClient->Close();
  1084. }
  1085. //m_pBusLocal->DisConnect();
  1086. //m_pBusLocal->Quit();
  1087. //FINFO("Stop Local Ebus Thread");
  1088. //if (m_pBusLocalThread->StopThread(100) == false)
  1089. //{
  1090. // FINFO("Local Receive Bus Thread:StopThread Used Terminate!!!!!!!!!!!!!!!");
  1091. //}
  1092. //FINFO("Del Local Ebus Handles");
  1093. //if (m_pBusLocalLog)
  1094. //{
  1095. // ReleseLogger(m_pBusLocalLog);
  1096. // m_pBusLocalLog = NULL;
  1097. //}
  1098. delete m_pLocalChannelClient;
  1099. m_pLocalChannelClient = NULL;
  1100. //delete m_pBusLocal;
  1101. //m_pBusLocal = NULL;
  1102. //delete m_pBusLocalThread;
  1103. //m_pBusLocalThread = NULL;
  1104. }
  1105. //if (m_pBusEth)
  1106. {
  1107. FINFO("Disconnect Eth EBUS");
  1108. //if (m_pBusEth->IsConnected())
  1109. // //2025.2.21
  1110. //if(m_pEthChannelClient)
  1111. //{
  1112. // m_pEthChannelClient->Close();
  1113. // delete m_pEthChannelClient;
  1114. // m_pEthChannelClient = NULL;
  1115. //}
  1116. //m_pBusEth->DisConnect();
  1117. //m_pBusEth->Quit();
  1118. //FINFO("Stop Eth Ebus Thread");
  1119. //if (m_pBusEthThread->StopThread(100) == false)
  1120. //{
  1121. // FINFO("Eth Receive Bus Thread:StopThread Used Terminate!!!!!!!!!!!!!!!");
  1122. //}
  1123. //FINFO("Del Eth Ebus Handles");
  1124. //if (m_pBusEthLog)
  1125. //{
  1126. // ReleseLogger(m_pBusEthLog);
  1127. // m_pBusEthLog = NULL;
  1128. //}
  1129. //delete m_pBusEth;
  1130. //m_pBusEth = NULL;
  1131. //delete m_pBusEthThread;
  1132. //m_pBusEthThread = NULL;
  1133. }
  1134. if (m_prootClient)
  1135. {
  1136. FINFO("Del Root Drv Handle");
  1137. m_prootClient->Close();
  1138. delete m_prootClient;
  1139. m_prootClient = NULL;
  1140. }
  1141. //Logger *pBusLogger = (Logger *)GetLogger();
  1142. //if (pBusLogger)
  1143. //{
  1144. // ReleseLogger(pBusLogger);
  1145. // SetLogger(NULL);
  1146. //}
  1147. //QuitEbusEnv();
  1148. FINFO("Done Clear DevBusManager");
  1149. return true;
  1150. }
  1151. //good
  1152. bool DevBusManager::SendSMPacket(ResDataObject &packet, bool Local, string &TargetbusId, unsigned long long nShareMemID)
  1153. {
  1154. //DeviceBUS *pBus = NULL;
  1155. //if (Local)
  1156. //{
  1157. // if (m_pBusLocal)
  1158. // {
  1159. // pBus = m_pBusLocal;
  1160. // }
  1161. //}
  1162. //else
  1163. //{
  1164. // if (m_pBusEth)
  1165. // {
  1166. // pBus = m_pBusEth;
  1167. // }
  1168. //}
  1169. //if (pBus)
  1170. //{
  1171. // return pBus->SendSMPacket(TargetbusId.c_str(), packet.encode(), nShareMemID);
  1172. //}
  1173. return false;
  1174. }
  1175. //good
  1176. bool DevBusManager::SendPacket(ResDataObject &packet, bool Local, string &TargetbusId, char* pBlockData, DWORD Size)
  1177. {
  1178. //DeviceBUS *pBus = NULL;
  1179. //if (Local)
  1180. //{
  1181. // if (m_pBusLocal)
  1182. // {
  1183. // FINFO("Select Local Bus");
  1184. // pBus = m_pBusLocal;
  1185. // }
  1186. //}
  1187. //else
  1188. //{
  1189. // if (m_pBusEth)
  1190. // {
  1191. // FINFO("Select Eth Bus");
  1192. // pBus = m_pBusEth;
  1193. // }
  1194. //}
  1195. //if (pBus)
  1196. //{
  1197. // return pBus->SendPacket(TargetbusId.c_str(), packet.encode(), pBlockData, Size);
  1198. //}
  1199. //FINFO("Select None Bus");
  1200. return false;
  1201. }
  1202. void DevBusManager::UnRegistThread(DWORD Tid)
  1203. {
  1204. //if (m_pBusLocal)
  1205. //{
  1206. // m_pBusLocal->UnRegistThread(Tid);
  1207. //}
  1208. //if (m_pBusEth)
  1209. //{
  1210. // m_pBusEth->UnRegistThread(Tid);
  1211. //}
  1212. }
  1213. DEVICEBUS_API bool LoadBusDrv() {
  1214. return g_BusManager.LoadBusDrv();
  1215. }
  1216. DEVICEBUS_API bool UnloadBusDrv() {
  1217. return g_BusManager.UnloadBusDrv();
  1218. }
  1219. DEVICEBUS_API void BusUnRegistThread(DWORD tid)
  1220. {
  1221. //g_BusManager.UnRegistThread(tid);
  1222. }
  1223. DEVICEBUS_API CCOS_PACKET_ROUTE GetBusIdDirection(string& BusId)
  1224. {
  1225. return CCOS_PACKET_ROUTE_NOTARGET;// g_BusManager.GetBusIdDirection(BusId);
  1226. }
  1227. DEVICEBUS_API bool BusSendSMPacket(ResDataObject& packet, bool Local, string& TargetbusId, unsigned long long nShareMemID)
  1228. {
  1229. return true;// g_BusManager.SendSMPacket(packet, Local, TargetbusId, nShareMemID);
  1230. }
  1231. DEVICEBUS_API bool BusSendPacket(ResDataObject& packet, bool Local, string& TargetbusId, char* pBlockData, DWORD Size)
  1232. {
  1233. return true;// g_BusManager.SendPacket(packet, Local, TargetbusId, pBlockData, Size);
  1234. }