Browse Source

Modified Certificate Builder

master
Evgeny Gagua 39 minutes ago
parent
commit
cb9126eff9
  1. 18
      Distro/pp_cc/c01675b17ad33a131826ce2041ab2e47.crt
  2. 42
      Distro/pp_cc/create_backup_cert.php
  3. 1
      Distro/pp_cc/rootCA.srl
  4. 4
      lib/App/common/kernelEventFilterYOLO.h
  5. 9
      lib/App/common/kernelPrototype.cpp
  6. 102
      lib/App/common/targetPipeLine.cpp
  7. 6
      lib/App/common/targetPipeLine.h
  8. 2
      lib/App/mojo/mojoBackend.cpp
  9. 2
      lib/components/base/basicEventHandler.cpp
  10. 140
      lib/components/base/basicEventHeap.cpp

18
Distro/pp_cc/c01675b17ad33a131826ce2041ab2e47.crt

@ -1,18 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIC5jCCAc6gAwIBAgIUWO8/0UBBOyymuBEiPtu2sMuSbxgwDQYJKoZIhvcNAQEL
BQAwITEfMB0GA1UEAwwWRHIuIEZydWNodCBTeXN0ZW1zIEx0ZDAeFw0yMzAzMjAx
MjExMDBaFw0yNDAzMTkxMjExMDBaMB4xHDAaBgNVBAMME0FyZ3VzIFNlbnNvciBN
b2R1bGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDVPCh/epFcwyrG
swfntx7uv1pNZ2NrvgLbQvk77IIBSkNPkejeLpS+XDBbluN2C7x9Yl4pJHDUOC4f
5wxCX63q3Qb0eDS0foHnuCReyUZ54tyJ8iENkgy8QSEc/RitWiwkIWFUlrz0Ho3U
j8UTwpS61otR7G6tuiShm63sXQG2pxGgBzHqCvFeUwb9Tswc+IcTXHCP9HP26/dL
/l9EMkNq2Gp7Xw7RPV2nOgFsD32xtfWuQCTfQwZ8CFdqmBTGVGSXhLAot/eUZp8M
sC20k2oFnGb9+HhLT1v/IdXpKyq8nU6mRfFJGNIW/sZVwvK/iJcWBekVZ8//CGkE
p3GhZp6JAgMBAAGjGTAXMBUGA1UdEQQOMAyHBAoAAAGHBMCoyG8wDQYJKoZIhvcN
AQELBQADggEBADMwgQrosnGhwwH0YV/35D1AQNfcPZJWL+cpWv5MAHENREBF6U+1
W+LepOiJoalKzhDd9SnA8N4NV5BGu6pMZDt4qtrhspHipVBt8X0m285a8oivl7of
GH1Eto7ZRSiTpGN0kknagxvWnYPXufINHY+fA2nbtpEJTQfFwCsdJGcPeq6Rw/+l
SGNNsgQ3O30Og1chBMqYd6BuvjRUulp3Gra8fKW/3OI54QxWWlEO7XP6XwU98ErQ
jj4uDCfhX9bN4rAs+I0NZaPyO/AiAZbFwPujdIcMtfQrG9f5Luq0bDpIZ+TUdz3f
96tDzV4iezXCIzckVg84LbEDWUueRpVPbUQ=
-----END CERTIFICATE-----

42
Distro/pp_cc/create_backup_cert.php

@ -1,27 +1,28 @@
<?php <?php
$Data = array();
$Data[] = "oid_section = OIDs";
$Data[] = "[ req ]";
$Data[] = "default_bits = 2048";
$Data[] = "encrypt_key = no";
$Data[] = "default_md = sha256";
$Data[] = "distinguished_name = dn";
$Data[] = "prompt = no";
$Data[] = "[ OIDs ]";
$Data[] = "MySensationalOID=1.2.3.4";
$Data[] = "MyOutstandingOID=2.3.4.56";
$Data[] = "[ dn ]";
$Data[] = "CN = Evgeny Gagua";
$Data[] = "emailAddress = poocka@gmail.com";
$Data[] = "O = Dr. Frucht Systems Ltd.";
$Data[] = "C = IL";
$Data[] = "MySensationalOID={$argv[1]}";
$Data[] = "[ req_ext ]";
$Data[] = "subjectAltName = email:gagua@gmail.com";
$Data[] = "MyOutstandingOID=Evgeny Gagua";
if( count( $argv ) > 1 ){ if( count( $argv ) > 1 ){
$Data = array();
$Data[] = "oid_section = OIDs";
$Data[] = "[ req ]";
$Data[] = "default_bits = 2048";
$Data[] = "encrypt_key = no";
$Data[] = "default_md = sha256";
$Data[] = "distinguished_name = dn";
$Data[] = "prompt = no";
$Data[] = "[ OIDs ]";
$Data[] = "MySensationalOID=1.2.3.4";
$Data[] = "MyOutstandingOID=2.3.4.56";
$Data[] = "[ dn ]";
$Data[] = "CN = Evgeny Gagua";
$Data[] = "emailAddress = poocka@gmail.com";
$Data[] = "O = Dr. Frucht Systems Ltd.";
$Data[] = "C = IL";
$Data[] = "MySensationalOID={$argv[1]}";
$Data[] = "[ req_ext ]";
$Data[] = "subjectAltName = email:gagua@gmail.com";
$Data[] = "MyOutstandingOID=Evgeny Gagua";
$TMP = md5(time()); $TMP = md5(time());
$FD = fopen( $TMP.".conf", "w+" ); $FD = fopen( $TMP.".conf", "w+" );
if( $FD ){ if( $FD ){
@ -37,6 +38,7 @@
$L = `openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in {$TMP}.csr -out {$TMP}.crt -days 365 -CAcreateserial`; $L = `openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in {$TMP}.csr -out {$TMP}.crt -days 365 -CAcreateserial`;
unlink( $TMP . '.conf' ); unlink( $TMP . '.conf' );
unlink( $TMP . '.csr' ); unlink( $TMP . '.csr' );
unlink( 'rootCA.srl' );
echo "{$TMP}.crt"; echo "{$TMP}.crt";
}; };
}; };

1
Distro/pp_cc/rootCA.srl

@ -1 +0,0 @@
58EF3FD140413B2CA6B811223EDBB6B0CB926FB0

4
lib/App/common/kernelEventFilterYOLO.h

@ -32,6 +32,10 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
typedef struct S_AI_ASSIGNMENT{
//BUBBLE;
}AI_ASSIGNMENT;
class kernelEventFilterYOLO : public kernelEventFilter, public basicEventHandler, public basicThread { class kernelEventFilterYOLO : public kernelEventFilter, public basicEventHandler, public basicThread {
private: private:
basicLogCollection * m_pLog; basicLogCollection * m_pLog;

9
lib/App/common/kernelPrototype.cpp

@ -127,19 +127,16 @@ uint8_t kernelPrototype::getExitCause()
void kernelPrototype::WaitFinish(bool Force) void kernelPrototype::WaitFinish(bool Force)
{ {
if (Force)
{
if( Force ){
#ifdef DEBUG #ifdef DEBUG
LOG("Forced Exit"); LOG("Forced Exit");
#endif #endif
}
else
{
} else {
#ifdef DEBUG #ifdef DEBUG
LOG("Start Waiting for Thread to End (usually at MAIN)."); LOG("Start Waiting for Thread to End (usually at MAIN).");
#endif #endif
}; };
waitThreadEnd(Force);
waitThreadEnd( Force );
} }
#ifndef USE_SERVER_MYSQL #ifndef USE_SERVER_MYSQL

102
lib/App/common/targetPipeLine.cpp

@ -51,86 +51,118 @@ targetPipeLine::~targetPipeLine()
}; };
} }
void targetPipeLine::m_fThreadProc(void)
{
void targetPipeLine::m_fThreadProc(void){
m_bThreadStatus = TH_WORKING; m_bThreadStatus = TH_WORKING;
pthread_setname_np(pthread_self(), "targetPipeLine"); pthread_setname_np(pthread_self(), "targetPipeLine");
while (m_bThreadStatus < TH_ENDED)
{
while (m_bThreadStatus < TH_ENDED){
m_mTargetProtector.lock(); m_mTargetProtector.lock();
if (m_qTargets.size())
{
if (m_qTargets.size()){
TARGET_DATA * tData = m_qTargets.front(); TARGET_DATA * tData = m_qTargets.front();
m_qTargets.pop(); m_qTargets.pop();
m_mTargetProtector.unlock(); m_mTargetProtector.unlock();
if (tData)
{
if (tData){
bool propogateTarget = true; bool propogateTarget = true;
if (m_vTargetFilters.size())
{
for (vectorKernelEventFilters::iterator idx = m_vTargetFilters.begin(); (idx != m_vTargetFilters.end()) && (m_bThreadStatus < TH_ENDED); idx++)
{
if ((*idx)->isActive())
{
if ((*idx)->validateTarget(m_nNodeId, tData))
{
if (m_vTargetFilters.size()){
for (vectorKernelEventFilters::iterator idx = m_vTargetFilters.begin(); (idx != m_vTargetFilters.end()) && (m_bThreadStatus < TH_ENDED); idx++){
if ((*idx)->isActive()){
if ((*idx)->validateTarget(m_nNodeId, tData)){
propogateTarget = false; propogateTarget = false;
break; break;
}; };
}; };
}; };
}; };
if (propogateTarget && m_bThreadStatus < TH_ENDED)
{
//Sink Target into a Kernel Event
if (propogateTarget && m_bThreadStatus < TH_ENDED){
#ifdef DEBUG_EXTRA #ifdef DEBUG_EXTRA
LOG("Gen EVT!"); LOG("Gen EVT!");
#endif #endif
// Triggering Session in Kernel // Triggering Session in Kernel
kernelPrototype * AK = kernelPrototype::getInstance(); kernelPrototype * AK = kernelPrototype::getInstance();
if (AK)
{
if (AK){
AK->startSession(); AK->startSession();
} }
EVENT_CONTAINER * bEVT = createBasicEvent(m_nNodeId, EVT_CLASS_SENSOR_LFS, EVT_TARGET_2D_WHITE, NULL, NULL, tData); EVENT_CONTAINER * bEVT = createBasicEvent(m_nNodeId, EVT_CLASS_SENSOR_LFS, EVT_TARGET_2D_WHITE, NULL, NULL, tData);
if (bEVT != NULL)
{
if (m_nTargetCamId)
{
if (bEVT != NULL){
if (m_nTargetCamId){
bEVT->m_nDestinationNodeID = m_nTargetCamId; bEVT->m_nDestinationNodeID = m_nTargetCamId;
}; };
m_pEventHeap->broadcast(bEVT); m_pEventHeap->broadcast(bEVT);
}
else
{
} else {
free(tData); free(tData);
}; };
}
else
{
} else {
#ifdef DEBUG_EXTRA #ifdef DEBUG_EXTRA
LOG("Skip EVT!"); LOG("Skip EVT!");
#endif #endif
free(tData); free(tData);
}; };
}; };
}
else
{
} else {
m_mTargetProtector.unlock(); m_mTargetProtector.unlock();
SLEEP(DEFAULT_THREAD_SLEEP_TIME); SLEEP(DEFAULT_THREAD_SLEEP_TIME);
}; };
}; };
} }
bool targetPipeLine::push(TARGET_DATA * ptr)
{
bool targetPipeLine::push(TARGET_DATA * ptr){
m_mTargetProtector.lock(); m_mTargetProtector.lock();
m_qTargets.push(ptr); m_qTargets.push(ptr);
m_mTargetProtector.unlock(); m_mTargetProtector.unlock();
return true; return true;
} }
bool targetPipeLine::inject( kernelEventFilter *instance, TARGET_DATA * tData ){
// Propogates target Manually
bool propogateTarget = true;
bool DownStreamFilter = false;
if (m_vTargetFilters.size()){
for (vectorKernelEventFilters::iterator idx = m_vTargetFilters.begin(); (idx != m_vTargetFilters.end()) && (m_bThreadStatus < TH_ENDED); idx++){
if ( (*idx) == instance ) {
DownStreamFilter = true;
} else {
if ( DownstreamFilter ) {
if ((*idx)->isActive()) {
if ((*idx)->validateTarget(m_nNodeId, tData)){
propogateTarget = false;
break;
};
};
};
};
};
};
//Sink Target into a Kernel Event
if (propogateTarget && m_bThreadStatus < TH_ENDED){
#ifdef DEBUG_EXTRA
LOG("Gen EVT!");
#endif
// Triggering Session in Kernel
kernelPrototype * AK = kernelPrototype::getInstance();
if (AK){
AK->startSession();
}
EVENT_CONTAINER * bEVT = createBasicEvent(m_nNodeId, EVT_CLASS_SENSOR_LFS, EVT_TARGET_2D_WHITE, NULL, NULL, tData);
if (bEVT != NULL){
if (m_nTargetCamId){
bEVT->m_nDestinationNodeID = m_nTargetCamId;
};
m_pEventHeap->broadcast(bEVT);
} else {
free(tData);
};
} else {
#ifdef DEBUG_EXTRA
LOG("Skip EVT!");
#endif
free(tData);
};
};
return false;
}
bool targetPipeLine::loadFilters() bool targetPipeLine::loadFilters()
{ {
if (m_pDBC) if (m_pDBC)

6
lib/App/common/targetPipeLine.h

@ -31,12 +31,14 @@ class targetPipeLine : public basicThread
protected: protected:
virtual void m_fThreadProc(void); virtual void m_fThreadProc(void);
bool inject( kernelEventFilter *instance, TARGET_DATA * ptr ); // Injects target down to the pipe (to next filter instance)
public: public:
explicit targetPipeLine(uint32_t node_id, uint32_t bind_cam_id = 0); explicit targetPipeLine(uint32_t node_id, uint32_t bind_cam_id = 0);
virtual ~targetPipeLine(); virtual ~targetPipeLine();
bool push(TARGET_DATA * ptr);
bool push( TARGET_DATA * ptr );
friend:
class kernelEventFilter;
}; };
#endif #endif

2
lib/App/mojo/mojoBackend.cpp

@ -651,7 +651,7 @@ int main(int argc, char * argv[])
// Stop the event dispatch thread before the log (and the process) goes away; it was never stopped // Stop the event dispatch thread before the log (and the process) goes away; it was never stopped
basicEventHeap::destroyInstance(); basicEventHeap::destroyInstance();
LOG("Event Heap Stopped"); LOG("Event Heap Stopped");
delete(m_pLog);
delete( m_pLog );
return 0; return 0;
} }

2
lib/components/base/basicEventHandler.cpp

@ -24,7 +24,7 @@ void basicEventHandler::attachEvents(void)
void basicEventHandler::detachEvents(void) void basicEventHandler::detachEvents(void)
{ {
if ( ! m_bEventsAttached ) return;
if ( !m_bEventsAttached ) return;
m_bEventsAttached = false; m_bEventsAttached = false;
// Only an existing heap: after basicEventHeap::destroyInstance() (application exit) a late // Only an existing heap: after basicEventHeap::destroyInstance() (application exit) a late
// destructor must not create a new heap and dispatch thread // destructor must not create a new heap and dispatch thread

140
lib/components/base/basicEventHeap.cpp

@ -14,30 +14,24 @@ std::mutex basicEventHeap::_instanceLock;
/** /**
* Returns the single instance of the object. * Returns the single instance of the object.
*/ */
basicEventHeap * basicEventHeap::getInstance()
{
basicEventHeap * basicEventHeap::getInstance(){
std::lock_guard<std::mutex> tLock(_instanceLock); std::lock_guard<std::mutex> tLock(_instanceLock);
if (0 == _instance)
{
if (0 == _instance){
_instance = new basicEventHeap; _instance = new basicEventHeap;
}; };
return _instance; return _instance;
} }
basicEventHeap * basicEventHeap::existingInstance()
{
basicEventHeap * basicEventHeap::existingInstance(){
std::lock_guard<std::mutex> tLock(_instanceLock); std::lock_guard<std::mutex> tLock(_instanceLock);
return _instance; return _instance;
} }
void basicEventHeap::destroyInstance()
{
if (existingInstance())
{
void basicEventHeap::destroyInstance(){
if (existingInstance()){
// A handler stuck in dispatchEvent(): deleting would wait for that thread forever (the // A handler stuck in dispatchEvent(): deleting would wait for that thread forever (the
// basicThread destructor joins it) - leave the object to the process exit instead of hanging // basicThread destructor joins it) - leave the object to the process exit instead of hanging
if (! _instance->pause())
{
if (! _instance->pause()){
_instance->m_pLog->Log("basicEventHeap", _instance, _LOG_ERROR, "Dispatch thread does not stop - not waiting for it"); _instance->m_pLog->Log("basicEventHeap", _instance, _LOG_ERROR, "Dispatch thread does not stop - not waiting for it");
return; return;
}; };
@ -51,8 +45,7 @@ void basicEventHeap::destroyInstance()
}; };
} }
basicEventHeap::basicEventHeap()
{
basicEventHeap::basicEventHeap(){
m_pLog = basicLogCollection::getInstance(); m_pLog = basicLogCollection::getInstance();
m_pDispatchingMutex = new basicMutex(); m_pDispatchingMutex = new basicMutex();
m_pCurrentHandler = NULL; m_pCurrentHandler = NULL;
@ -62,8 +55,7 @@ basicEventHeap::basicEventHeap()
basicThread::init(); basicThread::init();
} }
basicEventHeap::~basicEventHeap()
{
basicEventHeap::~basicEventHeap(){
pause(); pause();
waitThreadEnd(true); waitThreadEnd(true);
clearQueue(); clearQueue();
@ -74,25 +66,19 @@ basicEventHeap::~basicEventHeap()
delete (m_pDispatchingMutex); delete (m_pDispatchingMutex);
} }
bool basicEventHeap::isDispatchThread(void)
{
bool basicEventHeap::isDispatchThread(void){
return (m_bThreadStatus >= TH_WORKING) && pthread_equal(pthread_self(), m_tDispatchThread); return (m_bThreadStatus >= TH_WORKING) && pthread_equal(pthread_self(), m_tDispatchThread);
} }
bool basicEventHeap::isRegistered(basicEventHandler * handler)
{
bool basicEventHeap::isRegistered(basicEventHandler * handler){
return std::find(m_vHandlers.begin(), m_vHandlers.end(), handler) != m_vHandlers.end(); return std::find(m_vHandlers.begin(), m_vHandlers.end(), handler) != m_vHandlers.end();
} }
void basicEventHeap::addHandler(basicEventHandler * handler, bool atBottom)
{
void basicEventHeap::addHandler(basicEventHandler * handler, bool atBottom){
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
if (atBottom)
{
if (atBottom){
m_vHandlers.push_back(handler); m_vHandlers.push_back(handler);
}
else
{
} else {
m_vHandlers.insert(m_vHandlers.begin(), handler); m_vHandlers.insert(m_vHandlers.begin(), handler);
}; };
} }
@ -106,94 +92,76 @@ void basicEventHeap::addHandler(basicEventHandler * handler, bool atBottom)
Now the list is not locked during dispatchEvent(): this waits until the handler is no longer being Now the list is not locked during dispatchEvent(): this waits until the handler is no longer being
called (unless called from that very call, which cannot be waited for). called (unless called from that very call, which cannot be waited for).
*/ */
void basicEventHeap::removeHandler(basicEventHandler * handler)
{
void basicEventHeap::removeHandler(basicEventHandler * handler){
std::unique_lock<std::mutex> tLock(m_mHandlers); std::unique_lock<std::mutex> tLock(m_mHandlers);
V_EVT_HANDLER::iterator idx = std::find(m_vHandlers.begin(), m_vHandlers.end(), handler); 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); m_vHandlers.erase(idx);
}; };
if (m_pCurrentHandler == handler && ! isDispatchThread())
{
if (! m_cvDispatch.wait_for(tLock, std::chrono::milliseconds(EVENT_HEAP_WAIT_DISPATCH_MS), [&] { return m_pCurrentHandler != handler; }))
{
if (m_pCurrentHandler == handler && ! isDispatchThread()){
if (! m_cvDispatch.wait_for(tLock, std::chrono::milliseconds(EVENT_HEAP_WAIT_DISPATCH_MS), [&] { return m_pCurrentHandler != handler; })){
LOG_ERROR("removeHandler: handler still busy in dispatchEvent() - continuing anyway"); LOG_ERROR("removeHandler: handler still busy in dispatchEvent() - continuing anyway");
}; };
}; };
} }
void basicEventHeap::moveHandlerBottom(basicEventHandler * handler)
{
void basicEventHeap::moveHandlerBottom(basicEventHandler * handler){
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
V_EVT_HANDLER::iterator idx = std::find(m_vHandlers.begin(), m_vHandlers.end(), handler); V_EVT_HANDLER::iterator idx = std::find(m_vHandlers.begin(), m_vHandlers.end(), handler);
if (idx == m_vHandlers.end())
{
if (idx == m_vHandlers.end()){
return; // not registered (not attached yet / detached): moving must not register it return; // not registered (not attached yet / detached): moving must not register it
}; };
m_vHandlers.erase(idx); m_vHandlers.erase(idx);
m_vHandlers.push_back(handler); m_vHandlers.push_back(handler);
} }
void basicEventHeap::moveHandlerTop(basicEventHandler * handler)
{
void basicEventHeap::moveHandlerTop(basicEventHandler * handler){
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
V_EVT_HANDLER::iterator idx = std::find(m_vHandlers.begin(), m_vHandlers.end(), handler); V_EVT_HANDLER::iterator idx = std::find(m_vHandlers.begin(), m_vHandlers.end(), handler);
if (idx == m_vHandlers.end())
{
if (idx == m_vHandlers.end()){
return; // not registered (not attached yet / detached): moving must not register it return; // not registered (not attached yet / detached): moving must not register it
}; };
m_vHandlers.erase(idx); m_vHandlers.erase(idx);
m_vHandlers.insert(m_vHandlers.begin(), handler); m_vHandlers.insert(m_vHandlers.begin(), handler);
} }
void basicEventHeap::m_fThreadProc(void)
{
void basicEventHeap::m_fThreadProc(void){
{ {
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
m_tDispatchThread = pthread_self(); m_tDispatchThread = pthread_self();
} }
m_bThreadStatus = TH_WORKING; m_bThreadStatus = TH_WORKING;
pthread_setname_np(pthread_self(), "EventHeap"); pthread_setname_np(pthread_self(), "EventHeap");
while (m_bThreadStatus < TH_ENDED)
{
while (m_bThreadStatus < TH_ENDED){
// Enter a dispatch round only while not paused (pause() waits for m_bInDispatch == false) // Enter a dispatch round only while not paused (pause() waits for m_bInDispatch == false)
V_EVT_HANDLER tHandlers; V_EVT_HANDLER tHandlers;
{ {
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
if (m_bPaused)
{
if (m_bPaused){
m_bInDispatch = false; m_bInDispatch = false;
}
else
{
} else {
m_bInDispatch = true; m_bInDispatch = true;
tHandlers = m_vHandlers; // snapshot: the list may change while handlers are called tHandlers = m_vHandlers; // snapshot: the list may change while handlers are called
}; };
} }
if (! m_bInDispatch)
{
if (! m_bInDispatch){
SLEEP(1); SLEEP(1);
continue; continue;
}; };
EVENT_CONTAINER * mpEvent = NULL; EVENT_CONTAINER * mpEvent = NULL;
m_pDispatchingMutex->lock(); m_pDispatchingMutex->lock();
if (! m_vEventQueue.empty())
{
if (! m_vEventQueue.empty()){
mpEvent = m_vEventQueue.front(); mpEvent = m_vEventQueue.front();
m_vEventQueue.pop(); m_vEventQueue.pop();
}; };
m_pDispatchingMutex->unlock(); m_pDispatchingMutex->unlock();
if (mpEvent != NULL)
{
for (V_EVT_HANDLER::iterator idx = tHandlers.begin(); idx != tHandlers.end(); idx++)
{
if (mpEvent != NULL){
for (V_EVT_HANDLER::iterator idx = tHandlers.begin(); idx != tHandlers.end(); idx++){
basicEventHandler * mpHandler = (*idx); basicEventHandler * mpHandler = (*idx);
{ {
// skip handlers removed since the snapshot (they may be deleted already) // skip handlers removed since the snapshot (they may be deleted already)
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
if (mpHandler == NULL || ! isRegistered(mpHandler))
{
if (mpHandler == NULL || ! isRegistered(mpHandler)){
continue; continue;
} }
m_pCurrentHandler = mpHandler; m_pCurrentHandler = mpHandler;
@ -204,8 +172,7 @@ void basicEventHeap::m_fThreadProc(void)
m_pCurrentHandler = NULL; m_pCurrentHandler = NULL;
} }
m_cvDispatch.notify_all(); // a removeHandler() may wait for this handler m_cvDispatch.notify_all(); // a removeHandler() may wait for this handler
if (! tPropagate)
{
if (! tPropagate){
break; // Stop Propogation if false break; // Stop Propogation if false
} }
}; };
@ -216,8 +183,7 @@ void basicEventHeap::m_fThreadProc(void)
m_bInDispatch = false; m_bInDispatch = false;
} }
m_cvDispatch.notify_all(); // pause() may wait for the end of the round m_cvDispatch.notify_all(); // pause() may wait for the end of the round
if (mpEvent == NULL)
{
if (mpEvent == NULL){
SLEEP(1); SLEEP(1);
}; };
}; };
@ -229,38 +195,30 @@ void basicEventHeap::m_fThreadProc(void)
m_cvDispatch.notify_all(); m_cvDispatch.notify_all();
} }
void basicEventHeap::broadcast(EVENT_CONTAINER * Evt)
{
if (Evt)
{
void basicEventHeap::broadcast(EVENT_CONTAINER * Evt){
if( Evt ){
m_pDispatchingMutex->lock(); m_pDispatchingMutex->lock();
m_vEventQueue.push(Evt); m_vEventQueue.push(Evt);
m_pDispatchingMutex->unlock(); m_pDispatchingMutex->unlock();
}; };
} }
bool basicEventHeap::flush(uint32_t timeoutMs)
{
if (isDispatchThread())
{
bool basicEventHeap::flush(uint32_t timeoutMs){
if (isDispatchThread()){
return false; // a handler cannot wait for its own dispatch return false; // a handler cannot wait for its own dispatch
}; };
uint32_t tWaited = 0; uint32_t tWaited = 0;
while (tWaited < timeoutMs)
{
while (tWaited < timeoutMs){
m_pDispatchingMutex->lock(); m_pDispatchingMutex->lock();
bool tEmpty = m_vEventQueue.empty(); bool tEmpty = m_vEventQueue.empty();
m_pDispatchingMutex->unlock(); m_pDispatchingMutex->unlock();
if (tEmpty)
{
if (tEmpty){
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
if (! m_bInDispatch || m_bPaused || m_bThreadStatus >= TH_ENDED)
{
if (! m_bInDispatch || m_bPaused || m_bThreadStatus >= TH_ENDED){
return true; return true;
} }
}; };
if (m_bPaused || m_bThreadStatus >= TH_ENDED)
{
if (m_bPaused || m_bThreadStatus >= TH_ENDED){
return false; // nothing will be delivered return false; // nothing will be delivered
}; };
SLEEP(5); SLEEP(5);
@ -270,34 +228,28 @@ bool basicEventHeap::flush(uint32_t timeoutMs)
return false; return false;
} }
bool basicEventHeap::pause(void)
{
bool basicEventHeap::pause(void){
std::unique_lock<std::mutex> tLock(m_mHandlers); std::unique_lock<std::mutex> tLock(m_mHandlers);
m_bPaused = true; m_bPaused = true;
if (isDispatchThread() || m_bThreadStatus >= TH_ENDED)
{
if (isDispatchThread() || m_bThreadStatus >= TH_ENDED){
return true; // the current round ends when the caller returns return true; // the current round ends when the caller returns
}; };
if (! m_cvDispatch.wait_for(tLock, std::chrono::milliseconds(EVENT_HEAP_WAIT_DISPATCH_MS), [&] { return ! m_bInDispatch; }))
{
if (! m_cvDispatch.wait_for(tLock, std::chrono::milliseconds(EVENT_HEAP_WAIT_DISPATCH_MS), [&] { return ! m_bInDispatch; })){
LOG_ERROR("pause: a dispatchEvent() is still running - continuing anyway"); LOG_ERROR("pause: a dispatchEvent() is still running - continuing anyway");
return false; return false;
}; };
return true; return true;
} }
void basicEventHeap::resume(void)
{
void basicEventHeap::resume(void){
std::lock_guard<std::mutex> tLock(m_mHandlers); std::lock_guard<std::mutex> tLock(m_mHandlers);
m_bPaused = false; m_bPaused = false;
} }
size_t basicEventHeap::clearQueue(void)
{
size_t basicEventHeap::clearQueue(void){
size_t tCount = 0; size_t tCount = 0;
m_pDispatchingMutex->lock(); m_pDispatchingMutex->lock();
while (! m_vEventQueue.empty())
{
while (! m_vEventQueue.empty()){
EVENT_CONTAINER * tEvt = m_vEventQueue.front(); EVENT_CONTAINER * tEvt = m_vEventQueue.front();
m_vEventQueue.pop(); m_vEventQueue.pop();
utilizeBasicEvent(tEvt); utilizeBasicEvent(tEvt);

Loading…
Cancel
Save