ResDataNode.cpp 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  1. // ResDataNode.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include "ResDataNode.h"
  5. #include "PacketAnalizer.h"
  6. ResDataSubNodeContext::ResDataSubNodeContext(ResDataNode *Parent)
  7. {
  8. m_pParent = Parent;
  9. vector<string> *m_pKeyDepth = new vector<string>();
  10. }
  11. ResDataSubNodeContext::~ResDataSubNodeContext()
  12. {
  13. delete m_pKeyDepth;
  14. }
  15. //get context
  16. ResDataSubNodeContext::operator int()
  17. {
  18. int ret = 0;
  19. ResDataObject &Obj = m_pParent->m_Data;
  20. m_pParent->Thread_Lock();
  21. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  22. {
  23. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  24. }
  25. ret = (int)Obj;
  26. m_pParent->Thread_UnLock();
  27. return ret;
  28. }
  29. ResDataSubNodeContext::operator unsigned int()
  30. {
  31. unsigned int ret = 0;
  32. ResDataObject &Obj = m_pParent->m_Data;
  33. m_pParent->Thread_Lock();
  34. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  35. {
  36. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  37. }
  38. ret = (unsigned int)Obj;
  39. m_pParent->Thread_UnLock();
  40. return ret;
  41. }
  42. ResDataSubNodeContext::operator INT64()
  43. {
  44. INT64 ret = 0;
  45. ResDataObject &Obj = m_pParent->m_Data;
  46. m_pParent->Thread_Lock();
  47. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  48. {
  49. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  50. }
  51. ret = (INT64)Obj;
  52. m_pParent->Thread_UnLock();
  53. return ret;
  54. }
  55. ResDataSubNodeContext::operator UINT64()
  56. {
  57. UINT64 ret = 0;
  58. ResDataObject &Obj = m_pParent->m_Data;
  59. m_pParent->Thread_Lock();
  60. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  61. {
  62. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  63. }
  64. ret = (UINT64)Obj;
  65. m_pParent->Thread_UnLock();
  66. return ret;
  67. }
  68. ResDataSubNodeContext::operator float()
  69. {
  70. float ret = 0;
  71. ResDataObject &Obj = m_pParent->m_Data;
  72. m_pParent->Thread_Lock();
  73. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  74. {
  75. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  76. }
  77. ret = (float)Obj;
  78. m_pParent->Thread_UnLock();
  79. return ret;
  80. }
  81. ResDataSubNodeContext::operator double()
  82. {
  83. double ret = 0;
  84. ResDataObject &Obj = m_pParent->m_Data;
  85. m_pParent->Thread_Lock();
  86. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  87. {
  88. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  89. }
  90. ret = (double)Obj;
  91. m_pParent->Thread_UnLock();
  92. return ret;
  93. }
  94. ResDataSubNodeContext::operator const char*()
  95. {
  96. const char* ret = 0;
  97. ResDataObject &Obj = m_pParent->m_Data;
  98. m_pParent->Thread_Lock();
  99. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  100. {
  101. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  102. }
  103. ret = (const char*)Obj;
  104. m_pParent->Thread_UnLock();
  105. return ret;
  106. }
  107. ResDataSubNodeContext::operator ResDataObject()
  108. {
  109. ResDataObject ret;
  110. ResDataObject &Obj = m_pParent->m_Data;
  111. m_pParent->Thread_Lock();
  112. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  113. {
  114. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  115. }
  116. ret = Obj;
  117. m_pParent->Thread_UnLock();
  118. return ret;
  119. }
  120. ResDataSubNodeContext ResDataSubNodeContext::operator [](const char *pKey)
  121. {
  122. ResDataSubNodeContext ret(m_pParent);
  123. ret = (*this);
  124. ret.m_pKeyDepth->push_back(pKey);
  125. return ret;
  126. }
  127. //set context
  128. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const int tValue)
  129. {
  130. ResDataObject &Obj = m_pParent->m_Data;
  131. m_pParent->Thread_Lock();
  132. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  133. {
  134. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  135. }
  136. if ((int)Obj == tValue)
  137. {
  138. //do nothing
  139. }
  140. else
  141. {
  142. //assign
  143. Obj = tValue;
  144. //make notify
  145. //多层结构是个问题.
  146. //通知1层,2层都算作Context.
  147. if (m_pParent->m_pDevice)
  148. {
  149. ResDataObject Notify;
  150. ResDataObject NotifyData;
  151. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  152. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  153. m_pParent->m_pMainKey->c_str(),
  154. Notify);
  155. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  156. }
  157. }
  158. m_pParent->Thread_UnLock();
  159. return (*this);
  160. }
  161. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const unsigned int tValue)
  162. {
  163. ResDataObject &Obj = m_pParent->m_Data;
  164. m_pParent->Thread_Lock();
  165. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  166. {
  167. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  168. }
  169. if ((unsigned int)Obj == tValue)
  170. {
  171. //do nothing
  172. }
  173. else
  174. {
  175. //assign
  176. Obj = tValue;
  177. //make notify
  178. //多层结构是个问题.
  179. //通知1层,2层都算作Context.
  180. if (m_pParent->m_pDevice)
  181. {
  182. ResDataObject Notify;
  183. ResDataObject NotifyData;
  184. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  185. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  186. m_pParent->m_pMainKey->c_str(),
  187. Notify);
  188. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  189. }
  190. }
  191. m_pParent->Thread_UnLock();
  192. return (*this);
  193. }
  194. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const INT64 tValue)
  195. {
  196. ResDataObject &Obj = m_pParent->m_Data;
  197. m_pParent->Thread_Lock();
  198. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  199. {
  200. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  201. }
  202. if ((INT64)Obj == tValue)
  203. {
  204. //do nothing
  205. }
  206. else
  207. {
  208. //assign
  209. Obj = tValue;
  210. //make notify
  211. //多层结构是个问题.
  212. //通知1层,2层都算作Context.
  213. if (m_pParent->m_pDevice)
  214. {
  215. ResDataObject Notify;
  216. ResDataObject NotifyData;
  217. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  218. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  219. m_pParent->m_pMainKey->c_str(),
  220. Notify);
  221. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  222. }
  223. }
  224. m_pParent->Thread_UnLock();
  225. return (*this);
  226. }
  227. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const UINT64 tValue)
  228. {
  229. ResDataObject &Obj = m_pParent->m_Data;
  230. m_pParent->Thread_Lock();
  231. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  232. {
  233. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  234. }
  235. if ((UINT64)Obj == tValue)
  236. {
  237. //do nothing
  238. }
  239. else
  240. {
  241. //assign
  242. Obj = tValue;
  243. //make notify
  244. //多层结构是个问题.
  245. //通知1层,2层都算作Context.
  246. if (m_pParent->m_pDevice)
  247. {
  248. ResDataObject Notify;
  249. ResDataObject NotifyData;
  250. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  251. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  252. m_pParent->m_pMainKey->c_str(),
  253. Notify);
  254. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  255. }
  256. }
  257. m_pParent->Thread_UnLock();
  258. return (*this);
  259. }
  260. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const float tValue)
  261. {
  262. ResDataObject &Obj = m_pParent->m_Data;
  263. m_pParent->Thread_Lock();
  264. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  265. {
  266. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  267. }
  268. if ((float)Obj == tValue)
  269. {
  270. //do nothing
  271. }
  272. else
  273. {
  274. //assign
  275. Obj = tValue;
  276. //make notify
  277. //多层结构是个问题.
  278. //通知1层,2层都算作Context.
  279. if (m_pParent->m_pDevice)
  280. {
  281. ResDataObject Notify;
  282. ResDataObject NotifyData;
  283. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  284. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  285. m_pParent->m_pMainKey->c_str(),
  286. Notify);
  287. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  288. }
  289. }
  290. m_pParent->Thread_UnLock();
  291. return (*this);
  292. }
  293. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const double tValue)
  294. {
  295. ResDataObject &Obj = m_pParent->m_Data;
  296. m_pParent->Thread_Lock();
  297. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  298. {
  299. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  300. }
  301. if ((double)Obj == tValue)
  302. {
  303. //do nothing
  304. }
  305. else
  306. {
  307. //assign
  308. Obj = tValue;
  309. //make notify
  310. //多层结构是个问题.
  311. //通知1层,2层都算作Context.
  312. if (m_pParent->m_pDevice)
  313. {
  314. ResDataObject Notify;
  315. ResDataObject NotifyData;
  316. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  317. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  318. m_pParent->m_pMainKey->c_str(),
  319. Notify);
  320. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  321. }
  322. }
  323. m_pParent->Thread_UnLock();
  324. return (*this);
  325. }
  326. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const char* pVal)
  327. {
  328. ResDataObject &Obj = m_pParent->m_Data;
  329. m_pParent->Thread_Lock();
  330. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  331. {
  332. Obj = Obj[(*m_pKeyDepth)[i].c_str()];
  333. }
  334. if (Obj == pVal)
  335. {
  336. //do nothing
  337. }
  338. else
  339. {
  340. //assign
  341. Obj = pVal;
  342. //make notify
  343. //多层结构是个问题.
  344. //通知1层,2层都算作Context.
  345. if (m_pParent->m_pDevice)
  346. {
  347. ResDataObject Notify;
  348. ResDataObject NotifyData;
  349. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  350. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  351. m_pParent->m_pMainKey->c_str(),
  352. Notify);
  353. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  354. }
  355. }
  356. m_pParent->Thread_UnLock();
  357. return (*this);
  358. }
  359. ResDataSubNodeContext& ResDataSubNodeContext::operator = (const ResDataSubNodeContext &tValue)
  360. {
  361. ResDataObject &SrcObj = tValue.m_pParent->m_Data;
  362. ResDataObject &ThisObj = m_pParent->m_Data;
  363. m_pParent->Thread_Lock();
  364. tValue.m_pParent->Thread_Lock();
  365. for (size_t i = 0; i < m_pKeyDepth->size(); i++)
  366. {
  367. ThisObj = ThisObj[(*m_pKeyDepth)[i].c_str()];
  368. }
  369. for (size_t i = 0; i < tValue.m_pKeyDepth->size(); i++)
  370. {
  371. SrcObj = SrcObj[(*tValue.m_pKeyDepth)[i].c_str()];
  372. }
  373. if (ThisObj == SrcObj)
  374. {
  375. //do nothing
  376. }
  377. else
  378. {
  379. //assign
  380. ThisObj = SrcObj;
  381. //make notify
  382. //多层结构是个问题.
  383. //通知1层,2层都算作Context.
  384. if (m_pParent->m_pDevice)
  385. {
  386. ResDataObject Notify;
  387. ResDataObject NotifyData;
  388. Notify.add((*m_pKeyDepth)[0].c_str(), m_pParent->m_Data[(*m_pKeyDepth)[0].c_str()]);
  389. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_PART_UPDATE,
  390. m_pParent->m_pMainKey->c_str(),
  391. Notify);
  392. m_pParent->m_pDevice->CmdFromLogicDev(&NotifyData);
  393. }
  394. }
  395. m_pParent->Thread_UnLock();
  396. tValue.m_pParent->Thread_UnLock();
  397. return (*this);
  398. }
  399. //---------------------------------------------------------------------
  400. ResDataNode::ResDataNode()
  401. {
  402. m_pDevice = 0;
  403. m_pMainKey = new string();
  404. }
  405. ResDataNode::ResDataNode(const char *pkey)
  406. {
  407. m_pDevice = 0;
  408. m_pMainKey = new string();
  409. (*m_pMainKey) = pkey;
  410. }
  411. ResDataNode::~ResDataNode(void)
  412. {
  413. delete m_pMainKey;
  414. m_pMainKey = 0;
  415. }
  416. size_t ResDataNode::Size()
  417. {
  418. return m_Data.size();
  419. }
  420. const char *ResDataNode::GetKey()
  421. {
  422. const char *pResource = 0;
  423. Thread_Lock();
  424. pResource = m_pMainKey->c_str();
  425. Thread_UnLock();
  426. return pResource;
  427. }
  428. void ResDataNode::SetKey(const char *pKey)
  429. {
  430. Thread_Lock();
  431. (*m_pMainKey) = pKey;
  432. Thread_UnLock();
  433. }
  434. ResDataNode& ResDataNode::operator = (ResDataObject &tValue)
  435. {
  436. Thread_Lock();
  437. if (m_Data == tValue)
  438. {
  439. //do nothing
  440. }
  441. else
  442. {
  443. //assign
  444. m_Data = tValue;
  445. //make notify
  446. if (m_pDevice)
  447. {
  448. ResDataObject NotifyData;
  449. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), m_Data);
  450. m_pDevice->CmdFromLogicDev(&NotifyData);
  451. }
  452. }
  453. Thread_UnLock();
  454. return (*this);
  455. }
  456. void ResDataNode::SetLogicDevice(LogicDevice *pDevice)
  457. {
  458. Thread_Lock();
  459. m_pDevice = pDevice;
  460. Thread_UnLock();
  461. }
  462. bool ResDataNode::AddStaticDesc(const char *pkey, ResDataObject &Context)
  463. {
  464. bool ret = true;
  465. Thread_Lock();
  466. m_StaticDescript.update(pkey, Context);
  467. Thread_UnLock();
  468. return ret;
  469. }
  470. bool ResDataNode::AddStaticDesc(const char *pKey, const char *pDesc)
  471. {
  472. bool ret = true;
  473. Thread_Lock();
  474. m_StaticDescript.update(pKey, pDesc);
  475. Thread_UnLock();
  476. return ret;
  477. }
  478. bool ResDataNode::AddStaticDesc(const char *pKey, FLOAT DescVal)
  479. {
  480. bool ret = true;
  481. Thread_Lock();
  482. m_StaticDescript.update(pKey, DescVal);
  483. Thread_UnLock();
  484. return ret;
  485. }
  486. bool ResDataNode::AddStaticDesc(const char *pKey, INT DescIdx)
  487. {
  488. bool ret = true;
  489. Thread_Lock();
  490. m_StaticDescript.update(pKey, DescIdx);
  491. Thread_UnLock();
  492. return ret;
  493. }
  494. ResDataObject &ResDataNode::GetStaticDescript()
  495. {
  496. return m_StaticDescript;
  497. }
  498. //GET-----
  499. ResDataNode::operator int()
  500. {
  501. int ret = 0;
  502. Thread_Lock();
  503. ret = m_Data;
  504. Thread_UnLock();
  505. return ret;
  506. }
  507. ResDataNode::operator unsigned int()
  508. {
  509. unsigned int ret = 0;
  510. Thread_Lock();
  511. ret = m_Data;
  512. Thread_UnLock();
  513. return ret;
  514. }
  515. ResDataNode::operator INT64()
  516. {
  517. INT64 ret = 0;
  518. Thread_Lock();
  519. ret = m_Data;
  520. Thread_UnLock();
  521. return ret;
  522. }
  523. ResDataNode::operator UINT64()
  524. {
  525. UINT64 ret = 0;
  526. Thread_Lock();
  527. ret = m_Data;
  528. Thread_UnLock();
  529. return ret;
  530. }
  531. ResDataNode::operator float()
  532. {
  533. float ret = 0;
  534. Thread_Lock();
  535. ret = m_Data;
  536. Thread_UnLock();
  537. return ret;
  538. }
  539. ResDataNode::operator double()
  540. {
  541. double ret = 0;
  542. Thread_Lock();
  543. ret = m_Data;
  544. Thread_UnLock();
  545. return ret;
  546. }
  547. ResDataNode::operator const char*()
  548. {
  549. const char* ret = 0;
  550. Thread_Lock();
  551. ret = m_Data;
  552. Thread_UnLock();
  553. return ret;
  554. }
  555. ResDataNode::operator ResDataObject()
  556. {
  557. ResDataObject ret;
  558. Thread_Lock();
  559. ret = m_Data;
  560. Thread_UnLock();
  561. return ret;
  562. }
  563. ResDataSubNodeContext ResDataNode::operator [](const char* pkey)
  564. {
  565. ResDataSubNodeContext ret(this);
  566. return ret[pkey];
  567. }
  568. ResDataSubNodeContext ResDataNode::operator [](size_t Idx)
  569. {
  570. const char *pKey = 0;
  571. ResDataSubNodeContext ret(this);
  572. Thread_Lock();
  573. pKey = m_Data.GetKey(Idx);
  574. Thread_UnLock();
  575. return ret[pKey];
  576. }
  577. //SET----------
  578. ResDataNode& ResDataNode::operator = (int tValue)
  579. {
  580. Thread_Lock();
  581. if ((int)m_Data == tValue)
  582. {
  583. //do nothing
  584. }
  585. else
  586. {
  587. if (m_pDevice)
  588. {
  589. ResDataObject Notify;
  590. ResDataObject NotifyData;
  591. Notify.add(m_pMainKey->c_str(), tValue);
  592. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  593. m_pDevice->CmdFromLogicDev(&NotifyData);
  594. }
  595. m_Data = tValue;
  596. }
  597. Thread_UnLock();
  598. return (*this);
  599. }
  600. ResDataNode& ResDataNode::operator = (unsigned int tValue)
  601. {
  602. Thread_Lock();
  603. if ((unsigned int)m_Data == tValue)
  604. {
  605. //do nothing
  606. }
  607. else
  608. {
  609. if (m_pDevice)
  610. {
  611. ResDataObject Notify;
  612. ResDataObject NotifyData;
  613. Notify.add(m_pMainKey->c_str(), tValue);
  614. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  615. m_pDevice->CmdFromLogicDev(&NotifyData);
  616. }
  617. m_Data = tValue;
  618. }
  619. Thread_UnLock();
  620. return (*this);
  621. }
  622. ResDataNode& ResDataNode::operator = (INT64 tValue)
  623. {
  624. Thread_Lock();
  625. if ((INT64)m_Data == tValue)
  626. {
  627. //do nothing
  628. }
  629. else
  630. {
  631. if (m_pDevice)
  632. {
  633. ResDataObject Notify;
  634. ResDataObject NotifyData;
  635. Notify.add(m_pMainKey->c_str(), tValue);
  636. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  637. m_pDevice->CmdFromLogicDev(&NotifyData);
  638. }
  639. m_Data = tValue;
  640. }
  641. Thread_UnLock();
  642. return (*this);
  643. }
  644. ResDataNode& ResDataNode::operator = (UINT64 tValue)
  645. {
  646. Thread_Lock();
  647. if ((UINT64)m_Data == tValue)
  648. {
  649. //do nothing
  650. }
  651. else
  652. {
  653. if (m_pDevice)
  654. {
  655. ResDataObject Notify;
  656. ResDataObject NotifyData;
  657. Notify.add(m_pMainKey->c_str(), tValue);
  658. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  659. m_pDevice->CmdFromLogicDev(&NotifyData);
  660. }
  661. m_Data = tValue;
  662. }
  663. Thread_UnLock();
  664. return (*this);
  665. }
  666. ResDataNode& ResDataNode::operator = (float tValue)
  667. {
  668. Thread_Lock();
  669. if ((float)m_Data == tValue)
  670. {
  671. //do nothing
  672. }
  673. else
  674. {
  675. if (m_pDevice)
  676. {
  677. ResDataObject Notify;
  678. ResDataObject NotifyData;
  679. Notify.add(m_pMainKey->c_str(), tValue);
  680. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  681. m_pDevice->CmdFromLogicDev(&NotifyData);
  682. }
  683. m_Data = tValue;
  684. }
  685. Thread_UnLock();
  686. return (*this);
  687. }
  688. ResDataNode& ResDataNode::operator = (double tValue)
  689. {
  690. Thread_Lock();
  691. if ((double)m_Data == tValue)
  692. {
  693. //do nothing
  694. }
  695. else
  696. {
  697. if (m_pDevice)
  698. {
  699. ResDataObject Notify;
  700. ResDataObject NotifyData;
  701. Notify.add(m_pMainKey->c_str(), tValue);
  702. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  703. m_pDevice->CmdFromLogicDev(&NotifyData);
  704. }
  705. m_Data = tValue;
  706. }
  707. Thread_UnLock();
  708. return (*this);
  709. }
  710. ResDataNode& ResDataNode::operator = (const char* pVal)
  711. {
  712. string StrVal = pVal;
  713. Thread_Lock();
  714. if ((const char *)m_Data == StrVal)
  715. {
  716. //do nothing
  717. }
  718. else
  719. {
  720. if (m_pDevice)
  721. {
  722. ResDataObject Notify;
  723. ResDataObject NotifyData;
  724. Notify.add(m_pMainKey->c_str(), pVal);
  725. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  726. m_pDevice->CmdFromLogicDev(&NotifyData);
  727. }
  728. m_Data = pVal;
  729. }
  730. Thread_UnLock();
  731. return (*this);
  732. }
  733. ResDataNode& ResDataNode::operator = (ResDataNode &tValue)
  734. {
  735. Thread_Lock();
  736. tValue.Thread_Lock();
  737. //
  738. (*this) = tValue.m_Data;
  739. tValue.Thread_UnLock();
  740. Thread_UnLock();
  741. return (*this);
  742. }
  743. ResDataNode& ResDataNode::operator = (ResDataSubNodeContext &tValue)
  744. {
  745. ResDataObject ret = tValue;
  746. (*this) = ret;
  747. return (*this);
  748. }
  749. //ADD----------
  750. bool ResDataNode::Add(ResDataObject &NodeObject)
  751. {
  752. const char *pKey = NodeObject.GetKey(0);
  753. return Add(pKey, NodeObject[pKey]);
  754. }
  755. bool ResDataNode::Add(const char *pkey, ResDataObject &Context)
  756. {
  757. bool ret = false;
  758. Thread_Lock();
  759. int idx = m_Data.GetFirstOf(pkey);
  760. if (idx >= 0)
  761. {
  762. //exist
  763. TPRINTA_WARN("key[%s] already exist in add", pkey);
  764. }
  765. else
  766. {
  767. //new
  768. m_Data.add(pkey, Context);
  769. //make notify
  770. if (m_pDevice)
  771. {
  772. ResDataObject Notify;
  773. ResDataObject NotifyData;
  774. Notify.add(pkey, Context);
  775. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_ADD, m_pMainKey->c_str(), Notify);
  776. m_pDevice->CmdFromLogicDev(&NotifyData);
  777. }
  778. ret = true;
  779. }
  780. Thread_UnLock();
  781. return ret;
  782. }
  783. //DEL----------
  784. bool ResDataNode::Del(const char *pkey)
  785. {
  786. bool ret = false;
  787. Thread_Lock();
  788. int idx = m_Data.GetFirstOf(pkey);
  789. if (idx >= 0)
  790. {
  791. //exist
  792. //make notify
  793. if (m_pDevice)
  794. {
  795. ResDataObject Notify;
  796. ResDataObject NotifyData;
  797. //不要对象,只要KEY
  798. //Notify.add(pkey, m_Data[pkey]);
  799. Notify = pkey;
  800. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_DEL, m_pMainKey->c_str(), Notify);
  801. m_pDevice->CmdFromLogicDev(&NotifyData);
  802. }
  803. ret = m_Data.eraseOneOf(pkey, (size_t)idx);
  804. }
  805. else
  806. {
  807. //new
  808. TPRINTA_WARN("key[%s] not exist in del", pkey);
  809. }
  810. Thread_UnLock();
  811. return ret;
  812. }
  813. bool ResDataNode::Del(size_t Idx)
  814. {
  815. bool ret = false;
  816. Thread_Lock();
  817. if (m_Data.size() > Idx)
  818. {
  819. //exist
  820. const char *pkey = m_Data.GetKey(Idx);
  821. ret = Del(pkey);
  822. }
  823. else
  824. {
  825. //new
  826. TPRINTA_WARN("key[%d] not exist in del", Idx);
  827. }
  828. Thread_UnLock();
  829. return ret;
  830. }
  831. ResValue::ResValue()
  832. {
  833. AddStaticDesc(RES_CLASS_TYPE, RES_CLASS_VALUE);
  834. };
  835. ResValue::~ResValue(void)
  836. {
  837. };
  838. //SET----------
  839. ResValue& ResValue::operator = (int tValue)
  840. {
  841. Thread_Lock();
  842. if ((int)m_Data == tValue)
  843. {
  844. //do nothing
  845. }
  846. else
  847. {
  848. if (m_pDevice)
  849. {
  850. ResDataObject Notify;
  851. ResDataObject NotifyData;
  852. Notify.add(m_pMainKey->c_str(), tValue);
  853. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  854. m_pDevice->CmdFromLogicDev(&NotifyData);
  855. }
  856. m_Data = tValue;
  857. }
  858. Thread_UnLock();
  859. return (*this);
  860. }
  861. ResValue& ResValue::operator = (unsigned int tValue)
  862. {
  863. Thread_Lock();
  864. if ((unsigned int)m_Data == tValue)
  865. {
  866. //do nothing
  867. }
  868. else
  869. {
  870. if (m_pDevice)
  871. {
  872. ResDataObject Notify;
  873. ResDataObject NotifyData;
  874. Notify.add(m_pMainKey->c_str(), tValue);
  875. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  876. m_pDevice->CmdFromLogicDev(&NotifyData);
  877. }
  878. m_Data = tValue;
  879. }
  880. Thread_UnLock();
  881. return (*this);
  882. }
  883. ResValue& ResValue::operator = (INT64 tValue)
  884. {
  885. Thread_Lock();
  886. if ((INT64)m_Data == tValue)
  887. {
  888. //do nothing
  889. }
  890. else
  891. {
  892. if (m_pDevice)
  893. {
  894. ResDataObject Notify;
  895. ResDataObject NotifyData;
  896. Notify.add(m_pMainKey->c_str(), tValue);
  897. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  898. m_pDevice->CmdFromLogicDev(&NotifyData);
  899. }
  900. m_Data = tValue;
  901. }
  902. Thread_UnLock();
  903. return (*this);
  904. }
  905. ResValue& ResValue::operator = (UINT64 tValue)
  906. {
  907. Thread_Lock();
  908. if ((UINT64)m_Data == tValue)
  909. {
  910. //do nothing
  911. }
  912. else
  913. {
  914. if (m_pDevice)
  915. {
  916. ResDataObject Notify;
  917. ResDataObject NotifyData;
  918. Notify.add(m_pMainKey->c_str(), tValue);
  919. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  920. m_pDevice->CmdFromLogicDev(&NotifyData);
  921. }
  922. m_Data = tValue;
  923. }
  924. Thread_UnLock();
  925. return (*this);
  926. }
  927. ResValue& ResValue::operator = (float tValue)
  928. {
  929. Thread_Lock();
  930. if ((float)m_Data == tValue)
  931. {
  932. //do nothing
  933. }
  934. else
  935. {
  936. if (m_pDevice)
  937. {
  938. ResDataObject Notify;
  939. ResDataObject NotifyData;
  940. Notify.add(m_pMainKey->c_str(), tValue);
  941. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  942. m_pDevice->CmdFromLogicDev(&NotifyData);
  943. }
  944. m_Data = tValue;
  945. }
  946. Thread_UnLock();
  947. return (*this);
  948. }
  949. ResValue& ResValue::operator = (double tValue)
  950. {
  951. Thread_Lock();
  952. if ((double)m_Data == tValue)
  953. {
  954. //do nothing
  955. }
  956. else
  957. {
  958. if (m_pDevice)
  959. {
  960. ResDataObject Notify;
  961. ResDataObject NotifyData;
  962. Notify.add(m_pMainKey->c_str(), tValue);
  963. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  964. m_pDevice->CmdFromLogicDev(&NotifyData);
  965. }
  966. m_Data = tValue;
  967. }
  968. Thread_UnLock();
  969. return (*this);
  970. }
  971. ResValue& ResValue::operator = (const char* pVal)
  972. {
  973. string StrVal = pVal;
  974. Thread_Lock();
  975. if ((const char *)m_Data == StrVal)
  976. {
  977. //do nothing
  978. }
  979. else
  980. {
  981. if (m_pDevice)
  982. {
  983. ResDataObject Notify;
  984. ResDataObject NotifyData;
  985. Notify.add(m_pMainKey->c_str(), pVal);
  986. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), Notify);
  987. m_pDevice->CmdFromLogicDev(&NotifyData);
  988. }
  989. m_Data = pVal;
  990. }
  991. Thread_UnLock();
  992. return (*this);
  993. }
  994. ResValue& ResValue::operator = (ResDataNode &tValue)
  995. {
  996. Thread_Lock();
  997. ResDataObject Obj = tValue;
  998. //
  999. (*this) = Obj;
  1000. Thread_UnLock();
  1001. return (*this);
  1002. }
  1003. ResValue& ResValue::operator = (ResDataObject &tValue)
  1004. {
  1005. Thread_Lock();
  1006. if (m_Data == tValue)
  1007. {
  1008. //do nothing
  1009. }
  1010. else
  1011. {
  1012. //assign
  1013. m_Data = tValue;
  1014. //make notify
  1015. if (m_pDevice)
  1016. {
  1017. ResDataObject NotifyData;
  1018. PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, m_pMainKey->c_str(), m_Data);
  1019. m_pDevice->CmdFromLogicDev(&NotifyData);
  1020. }
  1021. }
  1022. Thread_UnLock();
  1023. return (*this);
  1024. }
  1025. ResValue& ResValue::operator = (ResDataSubNodeContext &tValue)
  1026. {
  1027. ResDataObject ret = tValue;
  1028. (*this) = ret;
  1029. return (*this);
  1030. }
  1031. //GET----------:使用下标不要
  1032. ResDataSubNodeContext ResValue::operator [](const char* pkey)
  1033. {
  1034. throw ResDataObjectExption("deserted function for resValue::operator[str] ");
  1035. ResDataSubNodeContext ret(this);
  1036. return ret;
  1037. };
  1038. ResDataSubNodeContext ResValue::operator [](size_t Idx)
  1039. {
  1040. throw ResDataObjectExption("deserted function for resValue::operator[idx]");
  1041. ResDataSubNodeContext ret(this);
  1042. return ret;
  1043. };
  1044. //ADD----------:不要
  1045. bool ResValue::Add(ResDataObject &NodeObject)
  1046. {
  1047. throw ResDataObjectExption("deserted function for resValue::Add1");
  1048. return false;
  1049. };
  1050. bool ResValue::Add(const char *pkey, ResDataObject &Context)
  1051. {
  1052. throw ResDataObjectExption("deserted function for resValue::Add2");
  1053. return false;
  1054. };
  1055. //DEL----------:不要
  1056. bool ResValue::Del(const char *pkey)
  1057. {
  1058. throw ResDataObjectExption("deserted function for resValue::Del[str]");
  1059. return false;
  1060. };
  1061. bool ResValue::Del(size_t Idx)
  1062. {
  1063. throw ResDataObjectExption("deserted function for resValue::Del[idx]");
  1064. return false;
  1065. };
  1066. //--------------------------------------------
  1067. ResStruct::ResStruct()
  1068. {
  1069. AddStaticDesc(RES_CLASS_TYPE, RES_CLASS_STRUCT);
  1070. };
  1071. ResStruct::~ResStruct(void)
  1072. {
  1073. };
  1074. //FULL GET:use ResDataNode::GetContext
  1075. //FULL SET
  1076. ResStruct& ResStruct::operator = (ResStruct &Val)
  1077. {
  1078. ResDataNode &Target = (*this);
  1079. ResDataNode &Src = Val;
  1080. Target = Src;
  1081. return (*this);
  1082. };
  1083. //get: use operator []
  1084. //ADD&DEL不支持
  1085. //ADD----------:不要
  1086. bool ResStruct::Add(ResDataObject &NodeObject)
  1087. {
  1088. throw ResDataObjectExption("deserted function for ResStruct::Add1");
  1089. return false;
  1090. };
  1091. bool ResStruct::Add(const char *pkey, ResDataObject &Context)
  1092. {
  1093. throw ResDataObjectExption("deserted function for ResStruct::Add1");
  1094. return false;
  1095. };
  1096. //DEL----------:不要
  1097. bool ResStruct::Del(const char *pkey)
  1098. {
  1099. throw ResDataObjectExption("deserted function for ResStruct::Del[str]");
  1100. return false;
  1101. };
  1102. bool ResStruct::Del(size_t Idx)
  1103. {
  1104. throw ResDataObjectExption("deserted function for resValue::Del[idx]");
  1105. return false;
  1106. };
  1107. //-----------------------------------
  1108. ResMap::ResMap()
  1109. {
  1110. AddStaticDesc(RES_CLASS_TYPE, RES_CLASS_MAP);
  1111. };
  1112. ResMap::~ResMap(void)
  1113. {
  1114. };