Browse Source

CurlManager Fixes

AGP
Evgeny Gagua 3 years ago
parent
commit
7e65c3a871
  1. 4
      Projects/la_mojo/build
  2. 206
      lib/App/common/kernelModuleFactory.cpp
  3. 5
      lib/App/common/kernelModuleFactory.h
  4. 62
      lib/data/curl/curlRequestsManager.cpp
  5. 3898
      lib/data/ponvif/ponvif.cpp

4
Projects/la_mojo/build

@ -4,8 +4,8 @@
#make clean -e "CFG=Debug"
#make -e "CFG=Debug" -j6
#make clean -e "CFG=Debug86"
make -e "CFG=Debug86" -j2
make clean -e "CFG=Debug86"
make -e "CFG=Debug86" -j4
#make clean -e "CFG=Release86"
#make -e "CFG=Release86" -j4

206
lib/App/common/kernelModuleFactory.cpp

@ -34,14 +34,14 @@ kernelModuleFactory* kernelModuleFactory::getInstance( uint32_t InstanceID ) {
kernelModuleFactory::kernelModuleFactory( uint32_t InstanceID ):basicThread(){
m_nInstanceID = InstanceID;
m_bInitialValidatioonDone = false;
m_bInitialValidationDone = false;
m_bInitialLoadModulesDone = false;
m_pLog = basicLogCollection::getInstance();
#ifdef USE_MYSQL
m_pDBC = mysqlDBC::getInstance();
#else
m_pDBC = sqliteDBC::getInstance();
#endif
// Don't INIT Thread -> init in LoadModules
init();
};
@ -100,11 +100,10 @@ bool kernelModuleFactory::loadModules(){
if( tList->size() ) {
#ifdef DEBUG
char tB[128];
sprintf( tB, "Have %d Modules to create!", tList->size() );
sprintf( tB, "Have %d Modules to Load!", tList->size() );
LOG( tB );
#endif
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ){
LOG("**MOMO**");
createModule( *idx );
};
tList->clear();
@ -120,18 +119,20 @@ bool kernelModuleFactory::loadModules(){
else {
LOG("No Modules Defined");
}
#endif
return init();
#endif
return m_bInitialLoadModulesDone = true;
};
kernelModule *kernelModuleFactory::createModule( int id ){
kernelModule *tVal = NULL;
uint8_t cType = 0;
if( m_pDBC != NULL ){
DBC_MODULE_DATA *tData = NULL;
tData = m_pDBC->getModuleData( id );
if( tData!= NULL ) {
switch( tData->type ) {
if( tData!= NULL ) {
cType = tData->type;
switch( cType ) {
case KERNEL_MODULE_DCBUSB:
#ifdef DEBUG
LOG("Creating Dry Contact USB Module");
@ -198,10 +199,42 @@ kernelModule *kernelModuleFactory::createModule( int id ){
LOG_ERROR("No Database Object Assigned!");
};
if( tVal != NULL ){
tVal->startService();
m_mModulesProtector.lock();
m_vKernelModules.push_back( tVal );
m_mModulesProtector.unlock();
if( tVal->startService() ){
m_mModulesProtector.lock();
m_vKernelModules.push_back( tVal );
m_mModulesProtector.unlock();
} else {
switch( cType ) {
case KERNEL_MODULE_DCBUSB:
delete( (kernelModuleUSBRelay * ) tVal );
break;
case KERNEL_MODULE_KAFKA:
delete( (kernelModuleKafka * ) tVal );
break;
case KERNEL_MODULE_FLYHUNTER:
delete( (kernelModuleFlyHunter * ) tVal );
break;
case KERNEL_MODULE_SSDP_ANONCE:
delete( (kernelModuleSSDPAnnouncer * ) tVal );
break;
case KERNEL_MODULE_ONVIF_OBSERVER:
if ( m_pDBC->isLocal() ) {
delete( (kernelModuleOnvifObserver * ) tVal );
};
break;
case KERNEL_MODULE_EMBED_VIDEO:
if ( m_pDBC->isLocal() ){
delete( (kernelModuleEmbedVideo * ) tVal );
};
break;
case KERNEL_MODULE_MODEM_MANAGER:
delete( (kernelModuleModemManager * ) tVal );
break;
};
delete( tVal );
tVal = NULL;
LOG_ERROR("Error Starting Module Service!");
};
};
return tVal;
};
@ -315,83 +348,86 @@ void kernelModuleFactory::m_fThreadProc( void ){
#endif
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) {
#ifdef MEM_DEBUG
memStart = getCurrentRSS();
#endif
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
DBC_INT_LIST tL;
for( int cm = 0; cm < m_vKernelModules.size(); cm++ ) tL.push_back( m_vKernelModules.at(cm)->getId() );
tList = m_pDBC->listNewModules( &tL );
tL.clear();
} else {
tList = m_pDBC->listNewModules( NULL );
};
m_mModulesProtector.unlock();
if( tList != NULL ) {
#ifdef DEBUG
LOG("New Modules Exists!");
#endif
for( int index=0; index< tList->size(); index++) createModule(tList->at(index));
tList->clear();
delete( tList );
};
#ifdef MEM_DEBUG
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
//Get Full List
//tList = NULL;
tList = m_pDBC->listModules();
if ( m_bInitialLoadModulesDone ) {
#ifdef MEM_DEBUG
memStart = getCurrentRSS();
#endif
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
DBC_INT_LIST tL;
for( int cm = 0; cm < m_vKernelModules.size(); cm++ ) tL.push_back( m_vKernelModules.at(cm)->getId() );
tList = m_pDBC->listNewModules( &tL );
tL.clear();
} else {
tList = m_pDBC->listNewModules( NULL );
};
m_mModulesProtector.unlock();
if( tList != NULL ) {
int cm = 0;
while( cm < m_vKernelModules.size() ) {
//check if module removed
bool tRemoved = true;
for( int lm = 0; lm < tList->size(); lm++ ) {
if( tList->at(lm) == m_vKernelModules.at( cm )->getId() ) {
tRemoved = false;
break;
};
};
if( !tRemoved ) {
// validate module
m_vKernelModules.at( cm )->validate();
cm++;
} else {
#ifdef DEBUG
LOG("Delete Module!");
#endif
deleteModule( cm );
};
};
#ifdef DEBUG
LOG("New Modules Exists!");
#endif
for( int index=0; index< tList->size(); index++) createModule(tList->at(index));
tList->clear();
delete( tList );
} else {
#ifdef DEBUG
LOG("All Modules Must be Deleted!");
#endif
while( m_vKernelModules.size() ) deleteModule( 0 );
};
}
#ifdef DEBUG_EXTRA
else {
LOG("No Modules to Validate!");
}
#endif
;
m_mModulesProtector.unlock();
#ifdef MEM_DEBUG
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
if( !m_bInitialValidatioonDone ) m_bInitialValidatioonDone = true;
#ifdef MEM_DEBUG
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
//Get Full List
//tList = NULL;
tList = m_pDBC->listModules();
if( tList != NULL ) {
int cm = 0;
while( cm < m_vKernelModules.size() ) {
//check if module removed
bool tRemoved = true;
for( int lm = 0; lm < tList->size(); lm++ ) {
if( tList->at(lm) == m_vKernelModules.at( cm )->getId() ) {
tRemoved = false;
break;
};
};
if( !tRemoved ) {
// validate module
m_vKernelModules.at( cm )->validate();
cm++;
} else {
#ifdef DEBUG
LOG("Delete Module!");
#endif
deleteModule( cm );
};
};
tList->clear();
delete( tList );
} else {
#ifdef DEBUG
LOG("All Modules Must be Deleted!");
#endif
while( m_vKernelModules.size() ) deleteModule( 0 );
};
}
#ifdef DEBUG_EXTRA
else {
LOG("No Modules to Validate!");
}
#endif
;
m_mModulesProtector.unlock();
#ifdef MEM_DEBUG
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
if( !m_bInitialValidationDone ) m_bInitialValidationDone = true;
};
for( int i = ( 5000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
};

5
lib/App/common/kernelModuleFactory.h

@ -15,7 +15,8 @@ class kernelModuleFactory: public basicThread{
uint32_t m_nInstanceID;
vectorKernelModules m_vKernelModules;
basicMutex m_mModulesProtector;
bool m_bInitialValidatioonDone;
bool m_bInitialValidationDone;
bool m_bInitialLoadModulesDone;
void deleteModule( kernelModule * );
public:
static kernelModuleFactory * getInstance( uint32_t InstanceID = 0 );
@ -29,7 +30,7 @@ class kernelModuleFactory: public basicThread{
bool loadModules( void );
bool validate( void );
void shutdownServices( bool force = false );
bool isValidationDone( void ){ return m_bInitialValidatioonDone; };
bool isValidationDone( void ){ return m_bInitialValidationDone; };
protected:
explicit kernelModuleFactory( uint32_t InstanceID );
virtual void m_fThreadProc( void );

62
lib/data/curl/curlRequestsManager.cpp

@ -8,7 +8,11 @@ curlRequestsManager::curlRequestsManager(){
m_pLog = basicLogCollection::getInstance();
curl_global_init(CURL_GLOBAL_ALL);
m_pCURLM = curl_multi_init();
init();
if( m_pCURLM ){
init();
} else {
LOG_ERROR( "Curl Muti Handle Cannot be created!!");
};
};
@ -44,17 +48,24 @@ void curlRequestsManager::m_fThreadProc( void ){
fd_set mExcepFD;
int mMaxFD = -1;
long mCURLTimeOut;
int mStillRunning;
#ifdef DEBUG
int mStillRunning;
bool bProceedThread = false;
#ifdef DEBUG_EXTRA
LOG("Starting Finished Requests Reaper");
#endif
//BugCurl Multi cannot starty if MR = empty ....
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
/* we start some action by calling perform right away */
curl_multi_perform( m_pCURLM, &mStillRunning );
do{
while( ( m_bThreadStatus < TH_ENDED ) && !bProceedThread ){
SLEEP( 10 );
m_mPoolProtector.lock();
if (m_vRequestPool.size()) bProceedThread = true;
m_mPoolProtector.unlock();
};
while( m_bThreadStatus < TH_ENDED ){
/* we start some action by calling perform right away */
curl_multi_perform( m_pCURLM, &mStillRunning );
do{
curl_multi_timeout( m_pCURLM, &mCURLTimeOut );
if( mCURLTimeOut < 0 ) mCURLTimeOut = 1000;
mTimeOut.tv_sec = mCURLTimeOut / 1000;
@ -66,14 +77,19 @@ void curlRequestsManager::m_fThreadProc( void ){
/* get file descriptors from the transfers */
mRetCode = curl_multi_fdset( m_pCURLM, &mReadFD, &mWriteFD, &mExcepFD, &mMaxFD );
if( mRetCode != CURLM_OK) {
char tT[256];
sprintf( tT, "curl_multi_fdset() failed, code %d!", mRetCode );
LOG_ERROR( tT );
break;
};
if( mMaxFD == -1 ){
SLEEP( 10 );
RetVal = 0;
break;
} else {
RetVal = select( mMaxFD + 1, &mReadFD, &mWriteFD, &mExcepFD, &mTimeOut );
};
switch( RetVal ){
case -1:
/* select error */
@ -95,8 +111,8 @@ void curlRequestsManager::m_fThreadProc( void ){
#endif
/* Find out which handle this message is about */
m_mPoolProtector.lock();
for (RequestPool::iterator index = m_vRequestPool.begin(); index < m_vRequestPool.end(); index++){
if ((*index)->getEH() == mMsg->easy_handle){
for( RequestPool::iterator index = m_vRequestPool.begin(); index < m_vRequestPool.end(); index++ ){
if( (*index)->getEH() == mMsg->easy_handle ){
mRetCode = curl_multi_remove_handle( m_pCURLM, (*index)->getEH());
if( rC == CURLE_OK ){
(*index)->issue();
@ -139,35 +155,37 @@ void curlRequestsManager::m_fThreadProc( void ){
*/
SLEEP( 10 );
};
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Ending Finished Requests Reaper");
#endif
};
bool curlRequestsManager::accomplish(curlRequest *RC){
bool curlRequestsManager::accomplish( curlRequest *RC ){
if( RC ){
#ifdef DEBUG_EXTRA
#ifdef DEBUG
LOG("New Request");
#endif
m_mPoolProtector.lock();
CURLMcode RetCode = curl_multi_add_handle( m_pCURLM, RC->getEH());
CURLMcode RetCode = curl_multi_add_handle( m_pCURLM, RC->getEH() );
if( RetCode == CURLM_OK ) {
m_mPoolProtector.lock();
m_vRequestPool.push_back( RC );
m_mPoolProtector.unlock();
#ifdef DEBUG
LOG("Added OK");
#endif
return true;
} else {
LOG_ERROR(curl_multi_strerror(RetCode));
};
m_mPoolProtector.unlock();
};
return false;
};
bool curlRequestsManager::get(CSTR URL, CSTR contentType ){
bool curlRequestsManager::get( CSTR URL, CSTR contentType ){
curlRequest *tRC;
tRC = new curlRequest( URL, contentType );
if (tRC != NULL){
if( tRC != NULL ){
return accomplish(tRC);
};
return false;
@ -176,9 +194,9 @@ bool curlRequestsManager::get(CSTR URL, CSTR contentType ){
bool curlRequestsManager::post(CSTR URL, CSTR postData, CSTR contentType ){
curlRequest *tRC;
tRC = new curlRequest( URL, contentType );
if (tRC != NULL){
if( tRC != NULL ){
tRC->setPOST( postData, strlen(postData) );
return accomplish(tRC);
return accomplish( tRC );
};
return false;
};

3898
lib/data/ponvif/ponvif.cpp
File diff suppressed because it is too large
View File

Loading…
Cancel
Save