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.
148 lines
4.8 KiB
148 lines
4.8 KiB
#include "IM_Kernel.h"
|
|
#include "IM_ClientHandler.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
|
|
#ifdef DEBUG
|
|
#define LOG_ERROR( X ) {\
|
|
char _tBfrErrMSG234[256];\
|
|
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
|
|
m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\
|
|
}
|
|
#else
|
|
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
|
|
#endif
|
|
|
|
IM_Kernel *IM_Kernel::_instance = NULL;
|
|
|
|
IM_Kernel *IM_Kernel::getInstance(){
|
|
if( _instance == NULL ) {
|
|
_instance = new IM_Kernel;
|
|
};
|
|
return _instance;
|
|
};
|
|
|
|
// Constructor implementation
|
|
inline IM_Kernel::IM_Kernel( config_setting_t *Settings ) : networkServiceEngine(), basicThread(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
|
|
m_pEvtHeap = basicEventHeap::getInstance();
|
|
m_bExitCause = 0;
|
|
m_pWorker = NULL;
|
|
m_pRecognizer = NULL;
|
|
m_pDBA = NULL;
|
|
m_pActiveJob = NULL;
|
|
};
|
|
|
|
// Destructor implementation
|
|
inline IM_Kernel::~IM_Kernel(){
|
|
waitThreadEnd( true );
|
|
if( m_pWorker ) delete( m_pWorker );
|
|
if( m_pRecognizer ) delete( m_pRecognizer );
|
|
if( m_pDBA ) delete( m_pDBA );
|
|
_instance = NULL;
|
|
};
|
|
|
|
bool IM_Kernel::start(){
|
|
m_pDBA = IM_DataBaseAdapter::getInstance( m_pSettings );
|
|
if( m_pDBA ==NULL ) {
|
|
LOG_ERROR("Error Creating DataBase Adapter!");
|
|
return false;
|
|
};
|
|
m_pWorker = new IM_DnnWorker( m_pSettings );
|
|
if( m_pWorker ) {
|
|
if( !m_pWorker->create() ){
|
|
LOG_ERROR( "DNN Worker INIT Failure!" );
|
|
return false;
|
|
};
|
|
} else LOG_ERROR( "DNN Worker Create Failure!" );
|
|
|
|
m_pRecognizer = new IM_DlibWorker( m_pSettings );
|
|
if( m_pRecognizer ) {
|
|
if( !m_pRecognizer->create() ){
|
|
LOG_ERROR( "DLib Worker INIT Failure!" );
|
|
return false;
|
|
};
|
|
} else LOG_ERROR( "DLib Worker Create Failure!" );
|
|
return init();
|
|
};
|
|
|
|
bool IM_Kernel::stop( bool Force ){
|
|
waitThreadEnd( Force );
|
|
return true;
|
|
};
|
|
|
|
networkClientHandler *IM_Kernel::attachNewClient( int SocketID ){
|
|
IM_ClientHandler *tVal;
|
|
tVal = new IM_ClientHandler( SocketID, this );
|
|
return (networkClientHandler *) tVal;
|
|
};
|
|
|
|
bool IM_Kernel::detachClient( networkClientHandler *ptr ){
|
|
delete( (IM_ClientHandler *) ptr );
|
|
return true;
|
|
};
|
|
|
|
|
|
void IM_Kernel::m_fThreadProc( void ){
|
|
m_bThreadStatus = TH_WORKING;
|
|
while( m_bThreadStatus < TH_ENDED ) {
|
|
if( m_qJOBS.size() ) {
|
|
if( m_pWorker ){
|
|
m_pActiveJob = m_qJOBS.front();
|
|
m_qJOBS.pop();
|
|
switch( m_pActiveJob->job_type ) {
|
|
case IM_PROC_TYPE_FACE:
|
|
if( !m_pRecognizer->enqueueJob( m_pActiveJob ) ) {
|
|
#ifdef DEBUG
|
|
LOG("Not Inserted Job Must generate EVT");
|
|
#endif
|
|
EVENT_CONTAINER *tEVT;
|
|
tEVT = (EVENT_CONTAINER *)malloc(sizeof(EVENT_CONTAINER));
|
|
if( tEVT ) {
|
|
memset(tEVT,0,sizeof(EVENT_CONTAINER));
|
|
tEVT->m_eClass = EVT_CLASS_IMAGE;
|
|
tEVT->m_eType = EVT_READY;
|
|
m_pEvtHeap->broadcast( tEVT );
|
|
} else {
|
|
LOG_ERROR( "Failure to Emmit EVENT!");
|
|
};
|
|
};
|
|
break;
|
|
default:
|
|
if( !m_pWorker->enqueueJob( m_pActiveJob ) ) {
|
|
#ifdef DEBUG
|
|
LOG("Not Inserted Job Must generate EVT");
|
|
#endif
|
|
EVENT_CONTAINER *tEVT;
|
|
tEVT = (EVENT_CONTAINER *)malloc(sizeof(EVENT_CONTAINER));
|
|
if( tEVT ) {
|
|
memset(tEVT,0,sizeof(EVENT_CONTAINER));
|
|
tEVT->m_eClass = EVT_CLASS_IMAGE;
|
|
tEVT->m_eType = EVT_READY;
|
|
m_pEvtHeap->broadcast( tEVT );
|
|
} else {
|
|
LOG_ERROR( "Failure to Emmit EVENT!");
|
|
};
|
|
};
|
|
};
|
|
} else LOG_ERROR( "DNN Worker Not Created!" );
|
|
};
|
|
SLEEP( DEFAULT_THREAD_SLEEP_TIME );
|
|
};
|
|
};
|
|
|
|
bool IM_Kernel::enqueueJob( IM_JOB *ptr ){
|
|
if( m_pWorker ) {
|
|
if( ptr!= NULL ) {
|
|
#ifdef DEBUG
|
|
LOG( "New Job Enqueued" );
|
|
#endif
|
|
m_qJOBS.push( ptr );
|
|
};
|
|
} else LOG_ERROR( "DNN Worker Not Created!" );
|
|
return false;
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|