You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.4 KiB

12 months ago
12 months ago
12 months ago
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
12 months ago
​
​
​
​
​
​
​
12 months ago
​
12 months ago
12 months ago
​
​
​
12 months ago
12 months ago
​
​
​
12 months ago
​
​
​
​
​
​
12 months ago
​
​
​
12 months ago
​
​
​
​
​
​
​
12 months ago
​
​
​
12 months ago
12 months ago
​
​
​
12 months ago
​
​
12 months ago
​
​
​
​
​
​
​
​
​
12 months ago
12 months ago
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
12 months ago
​
​
​
​
​
​
12 months ago
​
​
​
12 months ago
​
​
​
​
​
​
​
  1. #include "targetPipeLine.h"
  2. #include "kernelPrototype.h"
  3. #define LOG( X ) m_pLog->Log( "TPIPE", this, X )
  4. #ifdef DEBUG
  5. #define LOG_ERROR( X ) {\
  6. char _tBfrErrMSG234[256];\
  7. sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  8. m_pLog->Log( "TPIPE", this, _LOG_ERROR, _tBfrErrMSG234 );\
  9. }
  10. #else
  11. #define LOG_ERROR( X ) m_pLog->Log( "TPIPE", this, _LOG_ERROR, X );
  12. #endif
  13. #ifdef USE_MYSQL
  14. #include "MySQL_dataBinder.h"
  15. #else
  16. #include "SQLite_dataBinder.h"
  17. #endif
  18. targetPipeLine::targetPipeLine( uint32_t node_id, uint32_t bind_cam_id):basicThread(){
  19. m_nNodeId = node_id;
  20. m_nTargetCamId = bind_cam_id;
  21. m_pLog = basicLogCollection::getInstance();
  22. m_pEventHeap = basicEventHeap::getInstance();
  23. #ifdef USE_MYSQL
  24. m_pDBC = mysqlDBC::getInstance();
  25. #else
  26. m_pDBC = sqliteDBC::getInstance();
  27. #endif
  28. loadFilters();
  29. init();
  30. };
  31. targetPipeLine::~targetPipeLine(){
  32. waitThreadEnd( true );
  33. if ( m_vTargetFilters.size() ) m_vTargetFilters.clear();
  34. while ( m_qTargets.size() ){
  35. TARGET_DATA *tData = m_qTargets.front();
  36. m_qTargets.pop();
  37. free( tData );
  38. };
  39. };
  40. void targetPipeLine::m_fThreadProc( void ){
  41. m_bThreadStatus = TH_WORKING;
  42. while( m_bThreadStatus < TH_ENDED ) {
  43. m_mTargetProtector.lock();
  44. if ( m_qTargets.size() ){
  45. TARGET_DATA *tData = m_qTargets.front();
  46. m_qTargets.pop();
  47. m_mTargetProtector.unlock();
  48. if ( tData ) {
  49. bool propogateTarget = true;
  50. if ( m_vTargetFilters.size() ) {
  51. for (vectorKernelEventFilters::iterator idx = m_vTargetFilters.begin(); (idx != m_vTargetFilters.end()) && (m_bThreadStatus < TH_ENDED); idx++) {
  52. if( (*idx)->isActive() ) {
  53. if( (*idx)->validateTarget( m_nNodeId, tData ) ) {
  54. propogateTarget = false;
  55. break;
  56. };
  57. };
  58. };
  59. };
  60. if ( propogateTarget && m_bThreadStatus < TH_ENDED ) {
  61. #ifdef DEBUG_EXTRA
  62. LOG("Gen EVT!");
  63. #endif
  64. //Triggering Session in Kernel
  65. kernelPrototype *AK = kernelPrototype::getInstance();
  66. if ( AK ) AK->startSession();
  67. EVENT_CONTAINER * bEVT = createBasicEvent( m_nNodeId, EVT_CLASS_SENSOR_LFS, EVT_TARGET_2D_WHITE, NULL, NULL, tData );
  68. if( bEVT != NULL ) {
  69. if( m_nTargetCamId ) {
  70. bEVT->m_nDestinationNodeID = m_nTargetCamId;
  71. };
  72. m_pEventHeap->broadcast( bEVT );
  73. } else {
  74. free( tData );
  75. };
  76. } else {
  77. #ifdef DEBUG_EXTRA
  78. LOG("Skip EVT!");
  79. #endif
  80. free( tData );
  81. };
  82. };
  83. } else {
  84. m_mTargetProtector.unlock();
  85. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  86. };
  87. };
  88. };
  89. bool targetPipeLine::push(TARGET_DATA *ptr){
  90. m_mTargetProtector.lock();
  91. m_qTargets.push( ptr );
  92. m_mTargetProtector.unlock();
  93. return true;
  94. };
  95. bool targetPipeLine::loadFilters(){
  96. if( m_pDBC ){
  97. kernelPrototype *AK = kernelPrototype::getInstance();
  98. if( AK==NULL ){
  99. LOG_ERROR("KERNEL <<< GRAB >>> Failure!");
  100. return false;
  101. };
  102. #ifdef DEBUG
  103. LOG("Assigning Filters To Sensor's PipeLine");
  104. #endif
  105. DBC_INT_LIST *IDS = m_pDBC->listNodeFilters( m_nNodeId );
  106. if ( IDS ) {
  107. if ( IDS->size() ) {
  108. for ( DBC_INT_LIST::iterator idx = IDS->begin(); idx != IDS->end(); idx++ ) {
  109. #ifdef DEBUG_EXTRA
  110. LOG("Request Filter from Kernel");
  111. #endif
  112. kernelEventFilter * tFilter = AK->getFilter( *idx );
  113. if( tFilter ) m_vTargetFilters.push_back( tFilter );
  114. };
  115. };
  116. delete(IDS);
  117. #ifdef DEBUG
  118. LOG("Assigning Filters Done");
  119. #endif
  120. return true;
  121. };
  122. #ifdef DEBUG
  123. LOG("No Filters to Assign!");
  124. #endif
  125. };
  126. return false;
  127. };
  128. #undef LOG
  129. #undef LOG_ERROR