la_mojo nodes and modules: register for events only when fully built #20

Merged
ClaudeAI merged 1 commits from fix/event-handler-attach-detach into master 41 minutes ago
  1. 9
      lib/App/common/deviceNodePTZCamControl.cpp
  2. 9
      lib/App/common/deviceNodePresetCamControl.cpp
  3. 9
      lib/App/common/deviceNodeStaticCamControl.cpp
  4. 5
      lib/App/common/kernelModule.cpp
  5. 1
      lib/App/common/kernelModuleAttentionCloud.cpp
  6. 1
      lib/App/common/kernelModuleBosch.cpp
  7. 2
      lib/App/common/kernelModuleEmbedVideo.cpp
  8. 2
      lib/App/common/kernelModuleFactory.cpp
  9. 1
      lib/App/common/kernelModuleFlyHunter.cpp
  10. 1
      lib/App/common/kernelModuleKafka.cpp
  11. 1
      lib/App/common/kernelModuleModemManager.cpp
  12. 1
      lib/App/common/kernelModuleOnvifObserver.cpp
  13. 4
      lib/App/common/kernelModuleReportBackupper.cpp
  14. 1
      lib/App/common/kernelModuleSSDP.cpp
  15. 4
      lib/App/common/kernelModuleUSBRelay.cpp
  16. 10
      lib/components/base/basicEventHeap.cpp

9
lib/App/common/deviceNodePTZCamControl.cpp

@ -6,22 +6,27 @@
deviceNodePTZCamControl::deviceNodePTZCamControl(DBC_NODE_DATA * Data) :
deviceNodeCamera(Data),
basicEventHandler()
basicEventHandler(false) // registered at the end of the constructor
{
// Receive events only now that the object is completely constructed
attachEvents();
}
deviceNodePTZCamControl::deviceNodePTZCamControl(uint32_t id) :
deviceNodeCamera(id),
basicEventHandler()
basicEventHandler(false) // registered at the end of the constructor
{
m_sMediaSource.mediaSourceId = m_sNodeData.aux_id;
strncpy(m_sMediaSource.mediaName, m_sNodeData.name, 128);
m_sMediaSource.mediaName[127] = (char) 0;
memset(&m_sCtrlData, 0, sizeof(CAMERA_CTRL_DATA));
// Receive events only now that the object is completely constructed
attachEvents();
}
deviceNodePTZCamControl::~deviceNodePTZCamControl()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
stopService();
}

9
lib/App/common/deviceNodePresetCamControl.cpp

@ -6,22 +6,27 @@
deviceNodePresetCamControl::deviceNodePresetCamControl(DBC_NODE_DATA * Data) :
deviceNodeCamera(Data),
basicEventHandler()
basicEventHandler(false) // registered at the end of the constructor
{
// Receive events only now that the object is completely constructed
attachEvents();
}
deviceNodePresetCamControl::deviceNodePresetCamControl(uint32_t id) :
deviceNodeCamera(id),
basicEventHandler()
basicEventHandler(false) // registered at the end of the constructor
{
m_sMediaSource.mediaSourceId = m_sNodeData.aux_id;
strncpy(m_sMediaSource.mediaName, m_sNodeData.name, 128);
m_sMediaSource.mediaName[127] = (char) 0;
memset(&m_sCtrlData, 0, sizeof(CAMERA_CTRL_DATA));
// Receive events only now that the object is completely constructed
attachEvents();
}
deviceNodePresetCamControl::~deviceNodePresetCamControl()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
stopService();
}

9
lib/App/common/deviceNodeStaticCamControl.cpp

@ -5,7 +5,7 @@
deviceNodeStaticCamControl::deviceNodeStaticCamControl(DBC_NODE_DATA * Data) :
deviceNodeCamera(Data),
basicEventHandler()
basicEventHandler(false) // registered at the end of the constructor
{
// m_pLog = basicLogCollection::getInstance();
/*
@ -39,20 +39,25 @@ deviceNodeStaticCamControl::deviceNodeStaticCamControl(DBC_NODE_DATA * Data) :
#endif
m_pPosition = new basicPosition( m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
*/
// Receive events only now that the object is completely constructed
attachEvents();
}
deviceNodeStaticCamControl::deviceNodeStaticCamControl(uint32_t id) :
deviceNodeCamera(id),
basicEventHandler()
basicEventHandler(false) // registered at the end of the constructor
{
m_sMediaSource.mediaSourceId = m_sNodeData.aux_id;
strncpy(m_sMediaSource.mediaName, m_sNodeData.name, 128);
m_sMediaSource.mediaName[127] = (char) 0;
memset(&m_sCtrlData, 0, sizeof(CAMERA_CTRL_DATA));
// Receive events only now that the object is completely constructed
attachEvents();
}
deviceNodeStaticCamControl::~deviceNodeStaticCamControl()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
LOG("Destructor");
stopService();
}

5
lib/App/common/kernelModule.cpp

@ -6,8 +6,11 @@
#include "SQLite_dataBinder.h"
#endif
// Not registered for events here: the derived module's members are not built yet. The module factory
// calls attachEvents() once the module is constructed; each module calls detachEvents() first thing in
// its destructor.
kernelModule::kernelModule(uint32_t id, KERNEL_MODULE_TYPE type) :
basicEventHandler(),
basicEventHandler(false),
basicEngine()
{
m_pLog = basicLogCollection::getInstance();

1
lib/App/common/kernelModuleAttentionCloud.cpp

@ -11,6 +11,7 @@ kernelAttentionCloud::kernelAttentionCloud( uint32_t id ): kernelModule( id , KE
};
kernelAttentionCloud::~kernelAttentionCloud(){
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
stopService( true );
waitThreadEnd( true );
};

1
lib/App/common/kernelModuleBosch.cpp

@ -26,6 +26,7 @@ kernelModuleBosch::kernelModuleBosch(uint32_t ModuleID) :
}
kernelModuleBosch::~kernelModuleBosch(){
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
m_bEnabled = false;
if ( m_pCURL ){
curl_easy_cleanup(m_pCURL);

2
lib/App/common/kernelModuleEmbedVideo.cpp

@ -186,6 +186,7 @@ kernelModuleEmbedVideo::kernelModuleEmbedVideo(uint32_t moduleID) :
kernelModuleEmbedVideo::~kernelModuleEmbedVideo()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
#ifdef DEBUG
LOG("Destructor");
#endif
@ -2436,6 +2437,7 @@ kernelModuleEmbedVideo::kernelModuleEmbedVideo(uint32_t moduleID) :
kernelModuleEmbedVideo::~kernelModuleEmbedVideo()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
}

2
lib/App/common/kernelModuleFactory.cpp

@ -249,6 +249,8 @@ kernelModule * kernelModuleFactory::createModule(int id)
};
if (tVal != NULL)
{
// Receive events only now that the module object is completely constructed
tVal->attachEvents();
if (tVal->startService())
{
m_mModulesProtector.lock();

1
lib/App/common/kernelModuleFlyHunter.cpp

@ -30,6 +30,7 @@ kernelModuleFlyHunter::kernelModuleFlyHunter(uint32_t ModuleID) :
kernelModuleFlyHunter::~kernelModuleFlyHunter()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
m_bEnabled = false;
waitThreadEnd(true);
#ifndef SIMULATE_FH

1
lib/App/common/kernelModuleKafka.cpp

@ -98,6 +98,7 @@ kernelModuleKafka::kernelModuleKafka(uint32_t ModuleID) :
kernelModuleKafka::~kernelModuleKafka()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
m_bEnabled = false;

1
lib/App/common/kernelModuleModemManager.cpp

@ -55,6 +55,7 @@ kernelModuleModemManager::kernelModuleModemManager(uint32_t moduleID) :
kernelModuleModemManager::~kernelModuleModemManager()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
// if ( m_vUserData.size() ) {
// for ( VECTOR_MDM_USER_DATA::iterator idx = m_vUserData.begin(); idx < m_vUserData.end(); idx++ ) {
// if ( !(*idx)->finished ) pthread_join( (*idx)->handler, NULL);

1
lib/App/common/kernelModuleOnvifObserver.cpp

@ -105,6 +105,7 @@ kernelModuleOnvifObserver::kernelModuleOnvifObserver(uint32_t ModuleID) :
kernelModuleOnvifObserver::~kernelModuleOnvifObserver()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
if (! m_bDetached)
{
stopService(true);

4
lib/App/common/kernelModuleReportBackupper.cpp

@ -30,7 +30,9 @@ kernelModuleReportBackupper::kernelModuleReportBackupper(uint32_t moduleID) :
m_bBackupIsWorking = false;
}
kernelModuleReportBackupper::~kernelModuleReportBackupper() {}
kernelModuleReportBackupper::~kernelModuleReportBackupper() {
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
}
bool kernelModuleReportBackupper::validate()
{

1
lib/App/common/kernelModuleSSDP.cpp

@ -98,6 +98,7 @@ kernelModuleSSDPAnnouncer::kernelModuleSSDPAnnouncer(uint32_t ModuleID) :
kernelModuleSSDPAnnouncer::~kernelModuleSSDPAnnouncer()
{
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
if (m_iSocketFID != -1)
{
close_socket();

4
lib/App/common/kernelModuleUSBRelay.cpp

@ -307,7 +307,9 @@ kernelModuleUSBRelay::kernelModuleUSBRelay(uint32_t ModuleID) :
{
}
kernelModuleUSBRelay::~kernelModuleUSBRelay() {}
kernelModuleUSBRelay::~kernelModuleUSBRelay() {
detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
}
bool kernelModuleUSBRelay::dispatchEvent(EVENT_CONTAINER * Evt)
{

10
lib/components/base/basicEventHeap.cpp

@ -127,10 +127,11 @@ void basicEventHeap::moveHandlerBottom(basicEventHandler * handler)
{
std::lock_guard<std::mutex> tLock(m_mHandlers);
V_EVT_HANDLER::iterator idx = std::find(m_vHandlers.begin(), m_vHandlers.end(), handler);
if (idx != m_vHandlers.end())
if (idx == m_vHandlers.end())
{
m_vHandlers.erase(idx);
return; // not registered (not attached yet / detached): moving must not register it
};
m_vHandlers.erase(idx);
m_vHandlers.push_back(handler);
}
@ -138,10 +139,11 @@ void basicEventHeap::moveHandlerTop(basicEventHandler * handler)
{
std::lock_guard<std::mutex> tLock(m_mHandlers);
V_EVT_HANDLER::iterator idx = std::find(m_vHandlers.begin(), m_vHandlers.end(), handler);
if (idx != m_vHandlers.end())
if (idx == m_vHandlers.end())
{
m_vHandlers.erase(idx);
return; // not registered (not attached yet / detached): moving must not register it
};
m_vHandlers.erase(idx);
m_vHandlers.insert(m_vHandlers.begin(), handler);
}

Loading…
Cancel
Save