From 11636a3c0eaf15f78ed30bc72d9fadf5d2da8652 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Wed, 5 May 2021 00:52:47 +0100 Subject: [PATCH] KAFKA Consummer Started --- lib/components/base/basicEvent.h | 5 +- lib/data/protocol/protocolKAFKA.cpp | 628 +++++++++------------------- lib/data/protocol/protocolKAFKA.h | 61 +-- lib/rgoose/rgooseDBConnector.h | 5 - lib/rgoose/rgooseKafkaModule.cpp | 28 +- lib/rgoose/rgooseKafkaModule.h | 6 +- lib/rgoose/rgooseKernel.cpp | 49 ++- lib/rgoose/rgooseKernel.h | 2 +- lib/rgoose/rgooseModule.cpp | 2 +- lib/rgoose/rgooseModule.h | 2 +- lib/rgoose/rgooseModuleFactory.cpp | 37 ++ lib/rgoose/rgooseModuleFactory.h | 3 + lib/rgoose/rgooseNodeFactory.cpp | 4 +- lib/rgoose/rgooseNodeFactory.h | 2 +- 14 files changed, 310 insertions(+), 524 deletions(-) diff --git a/lib/components/base/basicEvent.h b/lib/components/base/basicEvent.h index 8e49c836..65c15ac8 100644 --- a/lib/components/base/basicEvent.h +++ b/lib/components/base/basicEvent.h @@ -51,7 +51,7 @@ typedef enum E_basicEventTypeID { EVT_COUNT = 24 } basicEventTypeID; -#define MAX_EVENT_ID 17 +//#define MAX_EVENT_ID 17 typedef enum E_basicEventClassID{ EVT_CLASS_SYSTEM = 0, @@ -67,7 +67,8 @@ typedef enum E_basicEventClassID{ EVT_CLASS_SENSOR_3D = 11, EVT_CLASS_SENSOR_ACC = 12, EVT_CLASS_FLY_HUNTER = 13, - EVT_CLASS_COUNT = 14 + EVT_CLASS_EXTERNAL_CMD = 14, + EVT_CLASS_COUNT = 15 } basicEventClassID; typedef struct S_basicEvent{ diff --git a/lib/data/protocol/protocolKAFKA.cpp b/lib/data/protocol/protocolKAFKA.cpp index c4c364a6..93902bec 100644 --- a/lib/data/protocol/protocolKAFKA.cpp +++ b/lib/data/protocol/protocolKAFKA.cpp @@ -30,14 +30,14 @@ protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){ m_pLog = basicLogCollection::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "INFOSTRESS_CONNECTION"); - m_pKafka = NULL; - m_pKafkaBrokerSTR = (CSTR)malloc(CLOG); - if( m_pKafkaBrokerSTR == NULL ) return; - memset( m_pKafkaBrokerSTR, 0 , CLOG); - m_pKafkaTopicSTR= (CSTR)malloc(CLOG); - if( m_pKafkaTopicSTR == NULL ) return; - memset( m_pKafkaTopicSTR, 0 , CLOG); - m_pKafkaTopic = NULL; + n_pProducer = NULL; + n_pProducerBrokerSTR = (CSTR)malloc(CLOG); + if( n_pProducerBrokerSTR == NULL ) return; + memset( n_pProducerBrokerSTR, 0 , CLOG); + n_pProducerTopicSTR= (CSTR)malloc(CLOG); + if( n_pProducerTopicSTR == NULL ) return; + memset( n_pProducerTopicSTR, 0 , CLOG); + n_pProducerTopic = NULL; m_pScannerName = (CSTR)malloc(OS_SCANNER_NAME_SIZE); if( m_pScannerName == NULL ) return; @@ -119,15 +119,15 @@ protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){ config_setting_set_int(pSetting, m_nServerPort); basicSettingsProvider::getInstance()->compromise(); }; - sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort ); - LOG( m_pKafkaBrokerSTR ); - if (!config_setting_lookup_string(m_pSettings, "KAFKA_TOPIC", (const char**)&m_pKafkaTopicSTR)) { - strncpy( m_pKafkaTopicSTR, DFSL_INFOSTRESS_DEFAULT_KAFKA_TOPIC, CTEXT ); + sprintf( n_pProducerBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort ); + LOG( n_pProducerBrokerSTR ); + if (!config_setting_lookup_string(m_pSettings, "KAFKA_TOPIC", (const char**)&n_pProducerTopicSTR)) { + strncpy( n_pProducerTopicSTR, DFSL_INFOSTRESS_DEFAULT_KAFKA_TOPIC, CTEXT ); pSetting = config_setting_add(m_pSettings, "KAFKA_TOPIC", CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_pKafkaTopicSTR); + config_setting_set_string(pSetting, n_pProducerTopicSTR); basicSettingsProvider::getInstance()->compromise(); }; - LOG( m_pKafkaTopicSTR ); + LOG( n_pProducerTopicSTR ); basicSettingsProvider::getInstance()->validate(); }; @@ -136,7 +136,7 @@ protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){ protocolKAFKA::protocolKAFKA( KAFKA_SETTINGS *Settings ){ m_pLog = basicLogCollection::getInstance(); - m_pKafka = NULL; + n_pProducer = NULL; m_pServerIP = NULL; memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR )); if( Settings!= NULL ) { @@ -151,7 +151,7 @@ protocolKAFKA::protocolKAFKA( KAFKA_SETTINGS *Settings ){ protocolKAFKA::protocolKAFKA( CSTR ServerAddress, uint16_t Port ){ m_pLog = basicLogCollection::getInstance(); - m_pKafka = NULL; + n_pProducer = NULL; m_pServerIP = NULL; if( ServerAddress == 0 || Port == 0 ) return; m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE); @@ -191,17 +191,17 @@ static void dr_msg_cb( rd_kafka_t *rk, const rd_kafka_message_t *rkmessage, void protocolKAFKA::~protocolKAFKA(){ //m_bEnabled = false; - if( m_pKafka != NULL ){ + if( n_pProducer != NULL ){ /* Wait for final messages to be delivered or fail. * rd_kafka_flush() is an abstraction over rd_kafka_poll() which * waits for all messages to be delivered. */ LOG("Flushing final messages.."); - m_pKafka->flush( 3000 /* wait for max 3 seconds */); + n_pProducer->flush( 3000 /* wait for max 3 seconds */); /* If the output queue is still not empty there is an issue * with producing messages to the clusters. */ - if (m_pKafka->outq_len() > 0) LOG_ERROR("Some messages are not delivered!"); - delete m_pKafka; - //if( m_pKafkaTopic!= NULL ) delete m_pKafkaTopic; + if (n_pProducer->outq_len() > 0) LOG_ERROR("Some messages are not delivered!"); + delete n_pProducer; + //if( n_pProducerTopic!= NULL ) delete n_pProducerTopic; }; //if( m_pScannerName != NULL ) free(m_pScannerName); if( m_pServerIP != NULL ) free(m_pServerIP); @@ -228,48 +228,33 @@ void protocolKAFKA::dr_cb( RdKafka::Message &message ){ }; bool protocolKAFKA::init(){ - RdKafka::Conf * tProducerConf; + RdKafka::Conf * tGlobalConf; std::string tBuffer; std::string brokers = m_pKafkaBrokerSTR; - //std::string topic = m_pKafkaTopicSTR; LOG("INIT Begin"); if( strlen( m_pKafkaBrokerSTR ) == 0 ) { LOG_ERROR("No Kafka Brokers are defined!"); return false; }; - tProducerConf = RdKafka::Conf::create( RdKafka::Conf::CONF_GLOBAL ); - if( tProducerConf == NULL ) { + tGlobalConf = RdKafka::Conf::create( RdKafka::Conf::CONF_GLOBAL ); + if( tGlobalConf == NULL ) { LOG_ERROR("Eror Creating Producer Conf!"); return false; }; LOG("RdKafka::Conf::CONF_GLOBAL Created"); - //tTopicConf = RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC); - //if( tTopicConf==NULL ){ - // LOG_ERROR("Eror Creating Topic Conf!"); - // delete( tProducerConf ); - // tProducerConf = NULL; - // return false; - //}; - //LOG("RdKafka::Conf::CONF_TOPIC Created"); - if( tProducerConf->set( "bootstrap.servers", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){ + if( tGlobalConf->set( "bootstrap.servers", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){ LOG_ERROR( tBuffer.c_str() ); - delete( tProducerConf ); - //delete( tTopicConf ); - //tProducerConf = NULL; - //tTopicConf = NULL; + delete( tGlobalConf ); return false; }; LOG( m_pKafkaBrokerSTR ); LOG("bootstrap.servers is SET"); - if( tProducerConf->set("metadata.broker.list", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){ + if( tGlobalConf->set("metadata.broker.list", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){ LOG_ERROR( tBuffer.c_str() ); - delete( tProducerConf ); - //delete( tTopicConf ); - //tProducerConf = NULL; - //tTopicConf = NULL; + delete( tGlobalConf ); return false; }; LOG("metadata.broker.list is SET"); @@ -281,12 +266,9 @@ bool protocolKAFKA::init(){ * rd_kafka_flush(). */ //tProducerConf->set("queue.buffering.max.ms", "100", tBuffer ); //tProducerConf->set("socket.blocking.max.ms", "100", tBuffer ); - if( tProducerConf->set( "dr_cb", this, tBuffer ) != RdKafka::Conf::CONF_OK ){ + if( tGlobalConf->set( "dr_cb", (RdKafka::DeliveryReportCb *) this, tBuffer ) != RdKafka::Conf::CONF_OK ){ LOG_ERROR( tBuffer.c_str() ); - delete( tProducerConf ); - //delete( tTopicConf ); - //tProducerConf = NULL; - //tTopicConf = NULL; + delete( tGlobalConf ); return false; }; LOG("dr_cb is SET"); @@ -306,22 +288,33 @@ bool protocolKAFKA::init(){ * and the application must not reference it again after * this call. */ - m_pKafka = RdKafka::Producer::create( tProducerConf, tBuffer ); - if( m_pKafka == NULL ){ + n_pProducer = RdKafka::Producer::create( tGlobalConf, tBuffer ); + if( n_pProducer == NULL ){ LOG_ERROR( tBuffer.c_str() ); - delete( tProducerConf ); - //delete( tTopicConf ); - //tProducerConf = NULL; - //tTopicConf = NULL; + delete( tGlobalConf ); return false; }; LOG("RdKafka::Producer Created"); - delete( tProducerConf ); - -// tProducerConf = NULL; + if( tGlobalConf->set( "enable.partition.eof", "true", tBuffer ) != RdKafka::Conf::CONF_OK ){ + delete( n_pProducer ); + delete( tGlobalConf ); + LOG_ERROR( tBuffer.c_str() ); + return false; + }; + LOG("enable.partition.eof is SET"); + + m_pConsumer = RdKafka::Consumer::create( tGlobalConf, tBuffer ); + if( m_pConsumer == NULL ){ + delete( n_pProducer ); + delete( tGlobalConf ); + LOG_ERROR( "Failed to create consumer:"); + LOG_ERROR( tBuffer.c_str() ); + return false; + } + LOG("RdKafka::Consumer Created"); LOG("INIT Complete"); -// m_bEnabled = true; + delete( tGlobalConf ); return true; }; @@ -332,10 +325,10 @@ bool protocolKAFKA::issuePost( CSTR tpc, CSTR Buffer, int BufferSize ){ RdKafka::Conf * tTopicConf = NULL; RdKafka::Topic * tKafkaTopic = NULL; std::string tBuffer; - std::string brokers = m_pKafkaBrokerSTR; + //std::string brokers = m_pKafkaBrokerSTR; std::string topic = tpc; - if( m_pKafka == NULL) return false; + if( n_pProducer == NULL) return false; tTopicConf = RdKafka::Conf::create( RdKafka::Conf::CONF_TOPIC ); if( tTopicConf==NULL ){ @@ -345,8 +338,8 @@ bool protocolKAFKA::issuePost( CSTR tpc, CSTR Buffer, int BufferSize ){ #ifdef DEBUG LOG("RdKafka::Conf::CONF_TOPIC Created"); #endif - tKafkaTopic = RdKafka::Topic::create( m_pKafka, topic, tTopicConf, tBuffer ); - if( m_pKafkaTopic == NULL ) { + tKafkaTopic = RdKafka::Topic::create( n_pProducer, topic, tTopicConf, tBuffer ); + if( tKafkaTopic == NULL ) { LOG_ERROR( "No Topic Created!!" ); LOG_ERROR( tpc ); LOG_ERROR( tBuffer.c_str() ); @@ -369,7 +362,7 @@ bool protocolKAFKA::issuePost( CSTR tpc, CSTR Buffer, int BufferSize ){ #endif //*/ retry: - err = m_pKafka->produce( + err = n_pProducer->produce( tKafkaTopic, RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, @@ -394,7 +387,7 @@ retry: * The internal queue is limited by the * configuration property * queue.buffering.max.messages */ - m_pKafka->poll(1000/*block for max 1000ms*/); + n_pProducer->poll(1000/*block for max 1000ms*/); if( rCnt-- ) goto retry; }; } @@ -415,12 +408,12 @@ retry: * to make sure previously produced messages have their * delivery report callback served (and any other callbacks * you register). */ - m_pKafka->poll(100); + n_pProducer->poll(100); //uint8_t cnt = 100; - //while ( cnt && m_pKafka->outq_len() > 0) { + //while ( cnt && n_pProducer->outq_len() > 0) { // LOG("Wait ..."); // cnt--; - // m_pKafka->poll(100); + // n_pProducer->poll(100); //}; delete( tKafkaTopic ); delete( tTopicConf ); @@ -429,385 +422,152 @@ retry: return true; }; - - - - -/* -void protocolKAFKA::setScannerName( CSTR Name ){ - sprintf( m_pScannerName, "%s", Name ); -}; -void protocolKAFKA::setProtocolType( bool DeviceIs3D ){ - if( DeviceIs3D ) { - m_nScannerDimentions = 3; - } else { - m_nScannerDimentions = 2; - }; -}; -CSTR protocolKAFKA::assembleStatusData( bool StatusOK ){ - CSTR RetVal = NULL; - CSTR TIME_STAMP; - CSTR tSRC; - CSTR tTARGET; - CSTR tID; - RetVal = (CSTR) malloc(CLOG); - if ( RetVal != NULL ) { - TIME_STAMP = getSHDTimeStamp(); - if( TIME_STAMP != NULL ) { - tTARGET = (CSTR) malloc(128); - if( tTARGET!= NULL) { - tSRC = (CSTR) malloc(128); - if( tSRC ) { - tID = (CSTR) malloc(64); - if( tID != NULL ) { - sprintf( tID, "%s", MD5String( TIME_STAMP ) ); - sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName ); - sprintf( tTARGET, DFSL_STATUS_DTO, TIME_STAMP , defenderStatusMode[((StatusOK)?1:0)] ); - sprintf( RetVal, - PACKAGE_SE_STATUS_DATA_ELEMENT, - defenderTypeDescription[DC_STATUS], - TIME_STAMP, - tSRC, - "DFSL_LIDAR_SENSOR_STATUS", - DFSL_DATA_TYPE_STATUS, - tID, - tTARGET - ); - free( tID ); - free( tSRC ); - free( tTARGET ); - free( TIME_STAMP ); - } else { - free( tSRC ); - free( tTARGET ); - free( TIME_STAMP ); - free( RetVal ); - } - } else { - free( tTARGET ); - free( TIME_STAMP ); - free( RetVal ); - }; - } else { - free( TIME_STAMP ); - free( RetVal ); - }; - } else { - free( RetVal ); - RetVal = NULL; - }; - }; - return RetVal; -}; -CSTR protocolKAFKA::assembleFaultData( uint8_t Code, CSTR Desc ){ - CSTR RetVal; - CSTR TIME_STAMP; - CSTR tSRC; - CSTR tTARGET; - CSTR tID; - RetVal = (CSTR) malloc(CLOG); - if ( RetVal != NULL ) { - TIME_STAMP = getSHDTimeStamp(); - if( TIME_STAMP != NULL ) { - tTARGET = (CSTR) malloc(128); - if( tTARGET!= NULL) { - tSRC = (CSTR) malloc(128); - if( tSRC ) { - tID = (CSTR) malloc(64); - if( tID != NULL ) { - sprintf( tID, "%s", MD5String( TIME_STAMP ) ); - sprintf( tSRC, DFSL_SENSOR_SOURCE_DTO, DFSL_HARDWARE_TYPE, DFRL_PROVIDER_ID, m_pScannerName ); - sprintf( tTARGET, DFSL_ERROR_DTO, TIME_STAMP, Code, Desc ); - sprintf( RetVal, - PACKAGE_SE_STATUS_DATA_ELEMENT, - Desc, - TIME_STAMP, - tSRC, - "DFSL_LIDARE_SENSOR_FAULT_DATA", - DFSL_DATA_TYPE_ERROR, - tID, - tTARGET - ); - free( tID ); - free( tSRC ); - free( tTARGET ); - free( TIME_STAMP ); - } else { - free( tSRC ); - free( tTARGET ); - free( TIME_STAMP ); - free( RetVal ); - } - } else { - free( tTARGET ); - free( TIME_STAMP ); - free( RetVal ); - }; - } else { - free( TIME_STAMP ); - free( RetVal ); - }; - } else { - free( RetVal ); - RetVal = NULL; - }; - }; - return RetVal; -}; -CSTR protocolKAFKA::assembleTargetData( bool is3D, int targetID, int Range, int Width, int Azimuth, int Elevation ){ - CSTR RetVal = NULL; - RetVal = (CSTR) malloc(CLOG); - if ( RetVal != NULL ) { - CSTR TIME_STAMP = NULL; - TIME_STAMP = getTStr(); - if( TIME_STAMP!= NULL ) { - char tID[64]; - float Az; - float Ra; - sprintf( tID, "%s", MD5String( TIME_STAMP ) ); - free( TIME_STAMP ); - Ra = Range; - Az = Azimuth; - if( is3D ) { - float El; - El = Elevation; - sprintf( RetVal, PACKAGE_INFOSTRESS_DATA_3D, tID, m_pScannerName, Az, El, Ra ); - } else { - sprintf( RetVal, PACKAGE_INFOSTRESS_DATA_2D, tID, m_pScannerName, Az, Ra, Width ); +void protocolKAFKA::consume_cb( RdKafka::Message& A, void* B ){ + char tBuff[256]; + /* + switch (message->err()) { + case RdKafka::ERR__TIMED_OUT: break; + case RdKafka::ERR_NO_ERROR: + // Real message + sprintf( tBuff, "Read msg at offset %dd ", message->offset() ); + LOG( tBuff ); + if( message->key() ){ + sprintf( tBuff, "Key: %s ", *message->key()->c_str() ); + LOG( tBuff ); }; - } else { - free( RetVal ); - RetVal = NULL; - }; - }; - return RetVal; + //* + RdKafka::Headers *headers = message->headers(); + if( headers ){ + std::vector hdrs = headers->get_all(); + for (size_t i = 0 ; i < hdrs.size() ; i++) { + const RdKafka::Headers::Header hdr = hdrs[i]; + if (hdr.value() != NULL) { + sprintf( tBuff, " Header: %s = \"%.*s\"\n", hdr.key().c_str(), (int)hdr.value_size(), (const char *)hdr.value()); + } else { + sprintf( tBuff, " Header: %s = NULL\n", hdr.key().c_str()); + }; + LOG( tBuff ); + }; + }; + //* / + //printf("%.*s\n", static_cast(message->len()), static_cast(message->payload())); + break; + case RdKafka::ERR__PARTITION_EOF: + // Last message + //if (exit_eof) { + + //} + break; + case RdKafka::ERR__UNKNOWN_TOPIC: + case RdKafka::ERR__UNKNOWN_PARTITION: + default: + LOG_ERROR( "Consume failed!" ); + LOG_ERROR( message->errstr().c_str() ); + }; */ }; -static uint32_t INFOSTRESS_MESSAGE_ID = 0; -size_t protocolKAFKA::assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data ){ - char tBuffer[CLOG]; - size_t RetVal; - CSTR tBuf; - RetVal = 0; - tBuf = getSHDTimeStamp(); - INFOSTRESS_MESSAGE_ID++; - //memset( tBuffer, 0, CLOG ); - if( tBuf != NULL ){ - //char ID[64]; - switch ( Type ) { - case DC_STATUS: - Severity = 0; - break; - case DC_ERROR: - Severity = 2; - break; - case DC_ALARM: - Severity = 4; - break; - default: - Severity = 2; - }; - //sprintf( ID, "%s", MD5String( tBuf ) ); - if( (m_nScannerDimentions > 2) && ( Type == DC_ALARM ) ) Type = DC_ALARM_3D; - sprintf( tBuffer, - DFSL_SE_ENVELOPE, - //DEFENDER_MESSAGE_ID, - defenderCategories[Type], - defenderTypeSeverity[Severity], - tBuf, tBuf, - Location, - Data - ); - RetVal = strlen(tBuffer); - memcpy( Buffer, tBuffer, RetVal ); - Buffer[RetVal] = (char) 0; - free( tBuf ); - }; - return RetVal; -}; - -bool protocolKAFKA::buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status ){ - if( Buffer!= NULL ){ - CSTR tBuf; - tBuf = assembleStatusData( Status ); -#ifdef DEBUG - //LOG(tBuf); -#endif - if( tBuf != NULL ) { - char DFSL_LOCATION[256]; - sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat ); - BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_STATUS, ((Status)?0:2), DFSL_LOCATION, tBuf ); -#ifdef DEBUG - LOG((CSTR)Buffer); -#endif - free( tBuf ); - return true; - } - }; - return false; -}; - - -bool protocolKAFKA::buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description ){ - if( Buffer!= NULL ){ - CSTR tBuf; - tBuf = assembleFaultData( Type, Description ); - if( tBuf != NULL ){ - char DFSL_LOCATION[256]; - sprintf(DFSL_LOCATION, DFSL_LOCATION_DTO, m_fLon, m_fLat ); - BufferSize = assembleDefenderJSON( (CSTR)Buffer, DC_ERROR, 3, DFSL_LOCATION, tBuf ); - free( tBuf ); - return true; - }; - }; - return false; -}; +bool protocolKAFKA::receivePost( CSTR Channel, int32_t Partition, int64_t Offset, CSTR Buffer, int &BufferSize ){ + uint8_t rCnt = 3; + char tBuf[128]; + RdKafka::ErrorCode err; + RdKafka::Conf * tTopicConf = NULL; + RdKafka::Topic * tKafkaTopic = NULL; + std::string tBuffer; + std::string topic = Channel; -bool protocolKAFKA::buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width){ - if( Buffer!= NULL ){ - CSTR tBuf; - tBuf = assembleTargetData( false, targetID, Range, Width, Angle, 0 ); - if( tBuf != NULL ){ - BufferSize = strlen( tBuf ); - strncpy( (char *)Buffer, tBuf, BufferSize ); - Buffer[BufferSize] = (char) 0; -#ifdef DEBUG - LOG((CSTR)Buffer); -#endif - free( tBuf ); - return true; - }; - }; - return false; -}; + BufferSize = 0; -bool protocolKAFKA::buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range ){ - if( Buffer!= NULL ){ - CSTR tBuf; - tBuf = assembleTargetData( true, targetID, Range, 0, Angle1, Angle2 ); - if( tBuf != NULL ){ - BufferSize = strlen( tBuf ); - strncpy( (char *)Buffer, tBuf, BufferSize ); - Buffer[BufferSize] = (char) 0; + if( m_pConsumer == NULL) return false; + tTopicConf = RdKafka::Conf::create( RdKafka::Conf::CONF_TOPIC ); + if( tTopicConf==NULL ){ + LOG_ERROR("Eror Creating Consumer Topic Conf!"); + return false; + }; #ifdef DEBUG - LOG((CSTR)Buffer); + LOG("Consumer RdKafka::Conf::CONF_TOPIC Created"); #endif - free( tBuf ); - return true; - }; - }; - return false; -}; - -bool protocolKAFKA::buildClockSyncPackage( unsigned char *Buffer, int &BufferSize ){ - if( Buffer!= NULL ){ - CSTR tBuf; - tBuf = getSHTimeStamp(); - if( tBuf != NULL ){ - sprintf( - ((char *)(Buffer+BufferSize)), - PACKAGE_ENVELOPE_TEMPLATE_CLOCKSYNC, - tBuf - ); - BufferSize = strlen( (char *)Buffer ); - free( tBuf ); - return true; - }; - }; - return false; -}; - -bool protocolKAFKA::buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ){ - if( Buffer!= NULL ){ - sprintf( - ((char *)(Buffer+BufferSize)), - PACKAGE_ENVELOPE_TEMPLATE_REG_CALL, - CallBackPath - ); - BufferSize = strlen( (char *)Buffer ); - return true; - }; - return false; -}; -bool protocolKAFKA::Alarm2D( float Angle, float Range, float Width, int ID ){ - bool RetVal= false; - char Buffer[1024]; - int BufferSize = 0; - CSTR UID; - if(!m_bEnabled) return false; - UID = buildUniqID(); - if( UID!= NULL ){ - RetVal = buildEvent2DPackage( ( unsigned char *) Buffer, BufferSize, UID, ID, Angle, Range, Width ); - RetVal = issuePost( Buffer, BufferSize ); - free( UID ); - }; - return RetVal; -}; -bool protocolKAFKA::Alarm3D( float Angle1, float Angle2, float Range, int ID ){ - bool RetVal= false; - char Buffer[1024]; - int BufferSize = 0; - CSTR UID; - if(!m_bEnabled) return false; - UID = buildUniqID(); - if( UID!= NULL ){ - RetVal = buildEvent3DPackage( ( unsigned char *) Buffer, BufferSize, UID, ID, Angle1, Angle2, Range ); - RetVal = issuePost( Buffer, BufferSize ); - free( UID ); - }; - return RetVal; -}; - -bool protocolKAFKA::VisibilityChanged( bool Worsened ){ - if( !m_bEnableStatus ) return true; - bool RetVal= false; - char Buffer[1024]; - int BufferSize = 0; - if(!m_bEnabled) return false; - RetVal = buildStatusPackage( ( unsigned char *) Buffer, BufferSize, !Worsened ); - RetVal = issuePost( Buffer, BufferSize ); - return RetVal; -}; - -bool protocolKAFKA::StatusUpdate( void ){ - if( !m_bEnableStatus ) return true; - bool RetVal= false; - char Buffer[1024]; - int BufferSize = 0; - if(!m_bEnabled) return false; - RetVal = buildStatusPackage( ( unsigned char *) Buffer, BufferSize, m_bCurrentStatus ); - RetVal = issuePost( Buffer, BufferSize ); - return RetVal; -}; + tKafkaTopic = RdKafka::Topic::create( m_pConsumer, topic, tTopicConf, tBuffer ); + if( tKafkaTopic == NULL ) { + LOG_ERROR( "Failed to create Consumer topic!"); + delete( tTopicConf ); + return false; + }; -bool protocolKAFKA::ErrorReporting( int lvl, CSTR Descr ){ - if( !m_bEnableStatus ) return true; - bool RetVal= false; - char Buffer[1024]; - int BufferSize = 0; - if(!m_bEnabled) return false; - RetVal = buildFaultPackage( ( unsigned char *) Buffer, BufferSize, lvl, Descr ); - RetVal = issuePost( Buffer, BufferSize ); - return RetVal; + /* + * Start consumer for topic+partition at start offset + */ + RdKafka::ErrorCode resp = m_pConsumer->start( tKafkaTopic, Partition, Offset ); + if (resp != RdKafka::ERR_NO_ERROR) { + LOG_ERROR( "Failed to start consumer!" ); + LOG_ERROR( RdKafka::err2str(resp).c_str() ); + delete( tKafkaTopic ); + delete( tTopicConf ); + return false; + }; + RdKafka::Message *message = m_pConsumer->consume( tKafkaTopic, Partition, 1000 ); + if( message == NULL ) { + delete( tKafkaTopic ); + delete( tTopicConf ); + return false; + } else { + switch (message->err()) { + case RdKafka::ERR__TIMED_OUT: break; + case RdKafka::ERR_NO_ERROR: + /* Real message */ + sprintf( tBuf, "Read msg at offset %dd ", message->offset() ); + LOG( tBuf ); + if( message->key() ){ + sprintf( tBuf, "Key: %s ", *message->key()->c_str() ); + LOG( tBuf ); + }; + //printf("%.*s\n", static_cast(message->len()), static_cast(message->payload())); + BufferSize = message->len(); + memcpy( Buffer, message->payload(), BufferSize ); + break; + case RdKafka::ERR__PARTITION_EOF: + + break; + case RdKafka::ERR__UNKNOWN_TOPIC: + case RdKafka::ERR__UNKNOWN_PARTITION: + default: + LOG_ERROR( "Consume failed!" ); + LOG_ERROR( message->errstr().c_str() ); + delete( message ); + delete( tKafkaTopic ); + delete( tTopicConf ); + return false; + }; + } + delete( message ); + m_pConsumer->stop( tKafkaTopic, Partition ); + m_pConsumer->poll( 1000 ); + delete( tKafkaTopic ); + delete( tTopicConf ); + return true; }; -bool protocolKAFKA::StartTimeSynch( void ){ - if( !m_bEnableStatus ) return true; - bool RetVal= false; - //LOG("TimeSYnc"); - char Buffer[1024]; - int BufferSize = 0; - CSTR URL = NULL; - URL = buildURL( SERVICE_URL_TEMPLATE_CLOCKSYNC, m_nScannerDimentions, m_pScannerName ); - RetVal = buildClockSyncPackage(( unsigned char *) Buffer, BufferSize ); - if( URL != NULL ){ - RetVal = issuePost( URL, Buffer, BufferSize ); - free( URL ); - }; - return RetVal; +void protocolKAFKA::event_cb( RdKafka::Event &event ){ + /* switch (event.type()){ + case RdKafka::Event::EVENT_ERROR: + if (event.fatal()) { + std::cerr << "FATAL "; + run = 0; + } + std::cerr << "ERROR (" << RdKafka::err2str(event.err()) << "): " << event.str() << std::endl; + break; + + case RdKafka::Event::EVENT_STATS: + std::cerr << "\"STATS\": " << event.str() << std::endl; + break; + case RdKafka::Event::EVENT_LOG: + fprintf(stderr, "LOG-%i-%s: %s\n", event.severity(), event.fac().c_str(), event.str().c_str()); + break; + default: + std::cerr << "EVENT " << event.type() << " (" << RdKafka::err2str(event.err()) << "): " << event.str() << std::endl; + break; + }; */ }; -*/ #undef LOG #undef LOG_ERROR diff --git a/lib/data/protocol/protocolKAFKA.h b/lib/data/protocol/protocolKAFKA.h index 8f35fb86..a0c545a3 100644 --- a/lib/data/protocol/protocolKAFKA.h +++ b/lib/data/protocol/protocolKAFKA.h @@ -23,75 +23,34 @@ * * @author gagua */ -class protocolKAFKA:public RdKafka::DeliveryReportCb { +class protocolKAFKA: public RdKafka::DeliveryReportCb, public RdKafka::ConsumeCb, public RdKafka::EventCb{ private: basicLogCollection * m_pLog; //config_setting_t * m_pSettings; //rd_kafka_t * m_pKafka; /* Producer instance handle */ - RdKafka::Producer * m_pKafka; /* Producer instance handle */ + RdKafka::Consumer * m_pConsumer; + RdKafka::Producer * n_pProducer; /* Producer instance handle */ //rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */ //RdKafka::Conf * m_pKafkaConf; /* Temporary configuration object */ char m_pKafkaBrokerSTR[OS_CEP_ADDRESS_SIZE]; //CSTR m_pKafkaTopicSTR; - RdKafka::Topic * m_pKafkaTopic; - // bool m_bUseCompression; - // bool m_bEnableStatus; - //uint8_t m_bKafkaBrokersCount; - - //int m_nScannerDimentions; - //CSTR m_pScannerName; - CSTR m_pServerIP; - //CSTR m_pAccessURL; - //bool m_bEnabled; - //bool m_bUseSSL; - //bool m_bMitigationStatus; - //float m_fLon; - //float m_fLat; - int m_nServerPort; - //bool m_bCurrentStatus; - //CSTR buildURL( CSTR templ, int dim, CSTR devID ); - //CSTR buildUniqID( void ); - //bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize ); - //bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ); - //bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status ); - //bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description ); - //bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle, float Range, float Width ); - //bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, float Angle1, float Angle2, float Range ); - - //CSTR assembleStatusData( bool StatusOK ); - //CSTR assembleFaultData( uint8_t Code, CSTR Desc ); - //CSTR assembleTargetData( bool is3D, int targetID, int Range, int Width, int Azimuth, int Elevation = 0 ); - //size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data ); + //RdKafka::Topic * m_pKafkaTopic; + CSTR m_pServerIP; + int m_nServerPort; public: // Constructor - //explicit protocolKAFKA( config_setting_t *Settings ); explicit protocolKAFKA( KAFKA_SETTINGS *Settings ); explicit protocolKAFKA( CSTR ServerAddr, uint16_t Port ); - //ToDo: change Serial to BaseClass of some kind of socket - //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL ); // Destructor virtual ~protocolKAFKA(); bool init(); bool issuePost( CSTR Channel, CSTR Buffer, int BufferSize ); -// bool Alarm2D( float Angle, float Range, float Width, int ID=0 ); - // bool Alarm3D( float Angle1, float Angle2, float Range, int ID=0 ); - // bool VisibilityChanged( bool Worsened ); - // bool StatusUpdate( void ); - // void SetStatus( bool A ){ m_bCurrentStatus = A; }; - // bool ErrorReporting( int lvl, CSTR Descr ); - // bool StartTimeSynch( void ); + bool receivePost( CSTR Channel, int32_t Partition, int64_t Offset, CSTR Buffer, int &BufferSize ); + /* Implementation of RdKafka::EventCb */ + virtual void event_cb( RdKafka::Event &event ); + virtual void consume_cb( RdKafka::Message& A, void* B ); /* Implementation of RdKafka::DeliveryReportCb */ virtual void dr_cb( RdKafka::Message &message ); - #ifdef __linux__ - //bool FinishTimeSynch( unsigned long long *tVals ); - #else - //bool FinishTimeSynch( unsigned __int64 *tVals ); - #endif -// bool SetupCallBack( CSTR CallBackPath ); -// void setProtocolType( bool DeviceIs3D ); -// void setScannerName( CSTR Name ); -// void setScannerPosition( float Lat, float Lon ){ m_fLon = Lon; m_fLat = Lat; }; -// bool getMitigationStatus(void) { return m_bMitigationStatus; }; }; #endif \ No newline at end of file diff --git a/lib/rgoose/rgooseDBConnector.h b/lib/rgoose/rgooseDBConnector.h index bdafb237..093f18f9 100644 --- a/lib/rgoose/rgooseDBConnector.h +++ b/lib/rgoose/rgooseDBConnector.h @@ -146,11 +146,6 @@ typedef struct S_DBC_MEDIA_SERVER_STREAM_DATA{ char mrl[128]; } DBC_MEDIA_SERVER_STREAM_DATA; -typedef struct S_DBC_UART_DATA{ - char device[256]; - uint32_t speed; -}DBC_UART_DATA; - typedef struct S_DBC_LRF3D_DATA{ char master_host[64]; char slave_host[64]; diff --git a/lib/rgoose/rgooseKafkaModule.cpp b/lib/rgoose/rgooseKafkaModule.cpp index 688e86f5..d8805911 100644 --- a/lib/rgoose/rgooseKafkaModule.cpp +++ b/lib/rgoose/rgooseKafkaModule.cpp @@ -15,6 +15,11 @@ argusKafkaModule::argusKafkaModule( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_KAFKA ){ m_pProtocol = NULL; + m_bConsumerEnabled = false; + + partition = RdKafka::Topic::PARTITION_UA; + start_offset = RdKafka::Topic::OFFSET_BEGINNING; + m_pEvtTemplates = (KAFKA_TEMPLATE***) calloc(EVT_CLASS_COUNT, sizeof(KAFKA_TEMPLATE**)); if( m_pEvtTemplates!= NULL ) { memset( m_pEvtTemplates, 0, EVT_CLASS_COUNT * sizeof(KAFKA_TEMPLATE**)); @@ -105,12 +110,17 @@ void argusKafkaModule::m_fThreadProc( void ){ }; #endif }; - /* No need for time Sync - if( m_llTicks % 350 == 0 ) { // each 35 seconds - StartTimeSynch(); - //m_lCycleCounter == 0; - }; - */ + if( m_bConsumerEnabled ) { + for( uint8_t idx = 0; idx < EVT_COUNT; idx++ ) { + if( m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx] != NULL ){ + char BUF[1024]; + int len; + if( m_pProtocol->receivePost( m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx]->topic, partition, start_offset, BUF, len ) ){ + LOG(" HAVE MESSAGE "); + }; + }; + }; + }; SLEEP(100); }; }; @@ -167,6 +177,12 @@ bool argusKafkaModule::reloadSettings(){ if( m_pEvtTemplates[i]== NULL ) { m_pEvtTemplates[i]=(KAFKA_TEMPLATE**)calloc(EVT_COUNT,sizeof(KAFKA_TEMPLATE*)); memset( m_pEvtTemplates[i], 0, EVT_COUNT * sizeof(KAFKA_TEMPLATE*)); + if( i == EVT_CLASS_EXTERNAL_CMD ) { + m_bConsumerEnabled = true; +#ifdef DEBUG + LOG( "Consumer Enabled" ); +#endif + } }; m_pEvtTemplates[i][j] = tT; }; diff --git a/lib/rgoose/rgooseKafkaModule.h b/lib/rgoose/rgooseKafkaModule.h index 31aae34b..7e7bce46 100644 --- a/lib/rgoose/rgooseKafkaModule.h +++ b/lib/rgoose/rgooseKafkaModule.h @@ -22,8 +22,12 @@ class argusKafkaModule: public basicThread, public argusKernelModule { private: KAFKA_SETTINGS *m_pSettings; protocolKAFKA *m_pProtocol; + bool m_bConsumerEnabled; KAFKA_TEMPLATE ***m_pEvtTemplates; - + + int32_t partition; + int64_t start_offset; + unsigned long long m_llTicks; CSTR buildTemplate( CSTR tpl, uint32_t source_id, diff --git a/lib/rgoose/rgooseKernel.cpp b/lib/rgoose/rgooseKernel.cpp index ce1bc16a..bd0b3589 100644 --- a/lib/rgoose/rgooseKernel.cpp +++ b/lib/rgoose/rgooseKernel.cpp @@ -298,30 +298,27 @@ void argusKernel::m_fThreadProc( void ){ }; //*/ //* - // Event Processing Loop + // Web CTRL Event Processing Loop if( !m_pDBC->getLastEvents( m_vEvtRecords, lastTSS, lastTMS ) ){ // Error In DB Access m_bThreadStatus = TH_ENDED; m_bExitCause = 1; continue; }; - -/* if( m_vEvtRecords.size() > 0 ){ - validateEvents( lastTSS, lastTMS ); - }; - */ - //*/ if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process tTimeTSeconds = m_tTimeTSeconds; if( m_pModuleFactory != NULL ) { m_pModuleFactory->validate(); }; - //if( m_pNodeFactory != NULL ) { - //m_pNodeFactory->validate(); - //}; + if( m_pNodeFactory != NULL ) { + m_pNodeFactory->validate(); + }; }; - SLEEP( SLEEP_KERNEL_INTERVAL ); + if( m_vEvtRecords.size() > 0 ){ + validateEvents( lastTSS, lastTMS ); + // SLEEP( 2 ); // short loop if had an events + } else SLEEP( SLEEP_KERNEL_INTERVAL ); }; }; @@ -365,31 +362,30 @@ void argusKernel::validateCameras( void ){ LOG("No Online IP Cameras in Network"); }; }; -/* -void ARGUS_Kernel::validateEvents( int &lastTSS, int &lastTMS ){ + +void argusKernel::validateEvents( int &lastTSS, int &lastTMS ){ EventRecordDBC *tPtr = NULL; basicEvent *tEvt = NULL; if(m_vEvtRecords.size()) { lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s; lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms; #ifndef ONE_EVENT_PER_LOOP - while(m_vEvtRecords.size()) { + while( m_vEvtRecords.size() ){ #endif tPtr = *m_vEvtRecords.begin(); if( tPtr != NULL ) { if( tEvt != NULL ) { m_pEventHeap->broadcast( tEvt ); - //free( tEvt ); }; free( tPtr ); }; - m_vEvtRecords.erase(m_vEvtRecords.begin()); + m_vEvtRecords.erase( m_vEvtRecords.begin() ); #ifndef ONE_EVENT_PER_LOOP }; #endif }; }; -*/ + bool argusKernel::signalEvent( void ){ if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){ @@ -404,7 +400,7 @@ int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){ RA = NULL; int cnt = 0; if( m_pNodeFactory != NULL ){ - cnt = m_pNodeFactory->getNodeCount( type ); + cnt = m_pNodeFactory->getNodesCount( type ); if( cnt ) { RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) ); m_pNodeFactory->fetchNodes(type, RA ); @@ -414,14 +410,29 @@ int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){ }; argusNetNode *argusKernel::getNetNode( int id ){ + if( m_pNodeFactory != NULL ){ + return m_pNodeFactory->getNode( id ); + }; return NULL; }; int argusKernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){ - return 0; + RA = NULL; + int cnt = 0; + if( m_pModuleFactory != NULL ){ + cnt = m_pModuleFactory->getModulesCount( type ); + if( cnt ) { + RA = (argusKernelModule **) calloc( cnt, sizeof( argusKernelModule * ) ); + m_pModuleFactory->fetchModules( type, RA ); + }; + }; + return cnt; }; argusKernelModule *argusKernel::getModule( int id ){ + if( m_pModuleFactory != NULL ){ + return m_pModuleFactory->getModule( id ); + }; return NULL; }; diff --git a/lib/rgoose/rgooseKernel.h b/lib/rgoose/rgooseKernel.h index c6dc60a7..02e87e48 100644 --- a/lib/rgoose/rgooseKernel.h +++ b/lib/rgoose/rgooseKernel.h @@ -105,7 +105,7 @@ class argusKernel: public basicThread { //servletWS * m_pServletWS; int isCameraListed( CSTR uid ); void validateCameras( void ); - //void validateEvents( int &lastTSS, int &lastTMS ); + void validateEvents( int &lastTSS, int &lastTMS ); //void enumerateHardware( void ); protected: void m_fThreadProc( void ); diff --git a/lib/rgoose/rgooseModule.cpp b/lib/rgoose/rgooseModule.cpp index 0a0feb52..c29910f9 100644 --- a/lib/rgoose/rgooseModule.cpp +++ b/lib/rgoose/rgooseModule.cpp @@ -20,7 +20,7 @@ argusKernelModule::argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param ):bas free( tData ); }; }; - for( int i = 0; i < MAX_EVENT_ID; i++ ) m_bEvtFlags[i] = false; + for( int i = 0; i < EVT_COUNT; i++ ) m_bEvtFlags[i] = false; }; argusKernelModule::~argusKernelModule(){ diff --git a/lib/rgoose/rgooseModule.h b/lib/rgoose/rgooseModule.h index 4efd528e..d95f8049 100644 --- a/lib/rgoose/rgooseModule.h +++ b/lib/rgoose/rgooseModule.h @@ -27,7 +27,7 @@ class argusKernelModule: public basicEventHandler, basicObject{ argusKernel * m_pKernel; bool m_bEnabled; bool m_bDetached; - bool m_bEvtFlags[MAX_EVENT_ID]; + bool m_bEvtFlags[EVT_COUNT]; public: ARGUS_MODULE_TYPE m_eType; explicit argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param = ARGUS_MODULE_UNKNOWN ); diff --git a/lib/rgoose/rgooseModuleFactory.cpp b/lib/rgoose/rgooseModuleFactory.cpp index 008b55f1..97244e3b 100644 --- a/lib/rgoose/rgooseModuleFactory.cpp +++ b/lib/rgoose/rgooseModuleFactory.cpp @@ -120,6 +120,43 @@ void argusModuleFactory::deleteModule( int id ){ }; }; +uint32_t argusModuleFactory::getModulesCount( ARGUS_MODULE_TYPE t ){ + uint32_t cnt = 0; + if( m_vKernelModules.size() ) { + for( int i=0; i < m_vKernelModules.size(); i++ ) { + if( m_vKernelModules.at(i)->getType() == t ) cnt++; + }; + }; + return cnt; +}; + +uint32_t argusModuleFactory::fetchModules( ARGUS_MODULE_TYPE t, argusKernelModule**&RA ){ + uint32_t cnt = getModulesCount( t ); + RA = NULL; + if( cnt > 0 ) { + RA = ( argusKernelModule** ) calloc( cnt, sizeof( argusKernelModule* ) ); + if( RA!= NULL ) { + if( m_vKernelModules.size() ) { + uint32_t idx = 0; + for( int i=0; i < m_vKernelModules.size(); i++ ) { + if( m_vKernelModules.at(i)->getType() == t ) { + RA[idx] = m_vKernelModules.at(i); + idx++; + }; + }; + }; + } else cnt = 0; + }; + return cnt; +}; + +argusKernelModule *argusModuleFactory::getModule( uint32_t id ){ + if( m_vKernelModules.size() > id ) { + + }; + return NULL; +}; + void argusModuleFactory::validate( void ){ if(m_pDBC == NULL) return; DBC_INT_LIST *tList = NULL; diff --git a/lib/rgoose/rgooseModuleFactory.h b/lib/rgoose/rgooseModuleFactory.h index 817a97ce..9defeb8a 100644 --- a/lib/rgoose/rgooseModuleFactory.h +++ b/lib/rgoose/rgooseModuleFactory.h @@ -18,6 +18,9 @@ class argusModuleFactory{ argusKernelModule * createModule( int id ); void deleteModule( argusKernelModule * ); void deleteModule( int id ); + argusKernelModule * getModule( uint32_t id ); + uint32_t getModulesCount( ARGUS_MODULE_TYPE t ); + uint32_t fetchModules( ARGUS_MODULE_TYPE, argusKernelModule**&RA ); bool loadModules( uint32_t SiteID = 0 ); void validate( void ); protected: diff --git a/lib/rgoose/rgooseNodeFactory.cpp b/lib/rgoose/rgooseNodeFactory.cpp index cb38442b..82261ee0 100644 --- a/lib/rgoose/rgooseNodeFactory.cpp +++ b/lib/rgoose/rgooseNodeFactory.cpp @@ -332,7 +332,7 @@ void argusNodeFactory::validate( void ){ #endif }; -uint32_t argusNodeFactory::getNodeCount( ARGUS_NODE_TYPE type ){ +uint32_t argusNodeFactory::getNodesCount( ARGUS_NODE_TYPE type ){ uint32_t RetVal = 0; if( m_vNetNodes.size() ) for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) if( (*index)->getType() == type ) RetVal++; return RetVal; @@ -341,7 +341,7 @@ uint32_t argusNodeFactory::getNodeCount( ARGUS_NODE_TYPE type ){ uint32_t argusNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){ uint32_t RetVal = 0; if( RA == NULL ) { - RetVal = getNodeCount( type ); + RetVal = getNodesCount( type ); if( RetVal > 0 ) { RA = (argusNetNode **) calloc( RetVal, sizeof(argusNetNode *)); if( RA == NULL ) return 0; diff --git a/lib/rgoose/rgooseNodeFactory.h b/lib/rgoose/rgooseNodeFactory.h index a14422fc..7334f01a 100644 --- a/lib/rgoose/rgooseNodeFactory.h +++ b/lib/rgoose/rgooseNodeFactory.h @@ -22,7 +22,7 @@ class argusNodeFactory{ void deleteNode( uint32_t id ); uint32_t fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ); argusNetNode * getNode( uint32_t id ); - uint32_t getNodeCount( ARGUS_NODE_TYPE type ); + uint32_t getNodesCount( ARGUS_NODE_TYPE type ); bool loadNodes( uint32_t SiteID = 0 ); void validate( void ); protected: