DevBusManager.cpp 32 KB

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