Browse Source

New KAFKA adapter - MultiTopics

Evgeny Gagua 6 years ago
parent
commit
6c802b4de9
  1. 1
      Linux_Workspace.vpw
  2. 216
      Projects/img_mill/img_mill.vpj
  3. 89
      Projects/img_mill/makefile
  4. 20
      lib/components/base/basicEvent.h
  5. 121
      lib/components/base/basicFunctionality.cpp
  6. 16
      lib/components/base/basicFunctionality.h
  7. 6
      lib/components/base/basicTypes.h
  8. 66
      lib/data/protocol/protocolEuropeanGeneral.cpp
  9. 232
      lib/data/protocol/protocolKAFKA.cpp
  10. 85
      lib/data/protocol/protocolKAFKA.h
  11. 69
      lib/rgoose/rgooseDBConnector.cpp
  12. 2
      lib/rgoose/rgooseDBConnector.h
  13. 155
      lib/rgoose/rgooseKafkaModule.cpp
  14. 19
      lib/rgoose/rgooseKafkaModule.h
  15. 9
      lib/rgoose/rgooseModule.cpp
  16. 4
      lib/rgoose/rgooseModule.h
  17. 14
      lib/rgoose/rgooseModuleFactory.cpp
  18. 48
      lib/rgoose/rgooseNode3D.cpp

1
Linux_Workspace.vpw

@ -6,6 +6,7 @@
<Project File="Projects/defender-dc-trig/defender-dc-trig.vpj"/>
<Project File="Projects/DirectMemo/DirectMemo.vpj"/>
<Project File="Projects/DirectPRU/DirectPRU.vpj"/>
<Project File="Projects/img_mill/img_mill.vpj"/>
<Project File="Projects/JustADCTest/JustADCTest.vpj"/>
<Project File="Projects/LRF_Server/LRF_Server.vpj"/>
<Project File="Projects/LRF_Slave/LRF_Slave.vpj"/>

216
Projects/img_mill/img_mill.vpj

@ -0,0 +1,216 @@
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
<Project
Version="10.0"
VendorName="SlickEdit"
TemplateName="GNU C/C++"
WorkingDir="."
BuildSystem="automakefile"
BuildMakeFile="makefile">
<Config
Name="Debug"
Type="gnuc"
DebugCallbackName="gdb"
Version="1"
OutputFile="%bdimg_mill"
CompilerConfigName="Latest Version">
<Menu>
<Target
Name="Compile"
MenuCaption="&amp;Compile"
Dialog="_gnuc_options_form Compile"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
OutputExts="*.o"
SaveOption="SaveCurrent"
RunFromDir="%rw">
<Exec CmdLine='g++ -c %xup %defd -g -o "%bd%n%oe" %i "%f"'/>
</Target>
<Target
Name="Link"
MenuCaption="&amp;Link"
ShowOnMenu="Never"
Dialog="_gnuc_options_form Link"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveCurrent"
RunFromDir="%rw">
<Exec CmdLine='g++ %xup -g -o "%o" %f %libs'/>
</Target>
<Target
Name="Build"
MenuCaption="&amp;Build"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveWorkspaceFiles"
RunFromDir="%rw">
<Exec CmdLine='make -f "makefile" CFG=%b'/>
</Target>
<Target
Name="Rebuild"
MenuCaption="&amp;Rebuild"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveWorkspaceFiles"
RunFromDir="%rw">
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/>
</Target>
<Target
Name="Debug"
MenuCaption="&amp;Debug"
Dialog="_gnuc_options_form Run/Debug"
BuildFirst="1"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveNone"
RunFromDir="%rw">
<Exec CmdLine='vsdebugio -prog "%o"'/>
</Target>
<Target
Name="Execute"
MenuCaption="E&amp;xecute"
Dialog="_gnuc_options_form Run/Debug"
BuildFirst="1"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveWorkspaceFiles"
RunFromDir="%rw">
<Exec CmdLine='"%o"'/>
</Target>
<Target
Name="dash"
MenuCaption="-"
Deletable="0">
<Exec/>
</Target>
<Target
Name="GNU C Options"
MenuCaption="GNU C &amp;Options..."
ShowOnMenu="HideIfNoCmdLine"
Deletable="0"
SaveOption="SaveNone">
<Exec
CmdLine="gnucoptions"
Type="Slick-C"/>
</Target>
</Menu>
<List Name="GNUC Options">
<Item
Name="LinkerOutputType"
Value="Executable"/>
</List>
</Config>
<Config
Name="Release"
Type="gnuc"
DebugCallbackName="gdb"
Version="1"
OutputFile="%bdimg_mill"
CompilerConfigName="Latest Version">
<Menu>
<Target
Name="Compile"
MenuCaption="&amp;Compile"
Dialog="_gnuc_options_form Compile"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
OutputExts="*.o"
SaveOption="SaveCurrent"
RunFromDir="%rw">
<Exec CmdLine='g++ -c %xup %defd -o "%bd%n%oe" %i "%f"'/>
</Target>
<Target
Name="Link"
MenuCaption="&amp;Link"
ShowOnMenu="Never"
Dialog="_gnuc_options_form Link"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveCurrent"
RunFromDir="%rw">
<Exec CmdLine='g++ %xup -o "%o" %f %libs'/>
</Target>
<Target
Name="Build"
MenuCaption="&amp;Build"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveWorkspaceFiles"
RunFromDir="%rw">
<Exec CmdLine='make -f "makefile" CFG=%b'/>
</Target>
<Target
Name="Rebuild"
MenuCaption="&amp;Rebuild"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveWorkspaceFiles"
RunFromDir="%rw">
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/>
</Target>
<Target
Name="Debug"
MenuCaption="&amp;Debug"
Dialog="_gnuc_options_form Run/Debug"
BuildFirst="1"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveNone"
RunFromDir="%rw">
<Exec CmdLine='vsdebugio -prog "%o"'/>
</Target>
<Target
Name="Execute"
MenuCaption="E&amp;xecute"
Dialog="_gnuc_options_form Run/Debug"
BuildFirst="1"
CaptureOutputWith="ProcessBuffer"
Deletable="0"
SaveOption="SaveWorkspaceFiles"
RunFromDir="%rw">
<Exec CmdLine='"%o"'/>
</Target>
<Target
Name="dash"
MenuCaption="-"
Deletable="0">
<Exec/>
</Target>
<Target
Name="GNU C Options"
MenuCaption="GNU C &amp;Options..."
ShowOnMenu="HideIfNoCmdLine"
Deletable="0"
SaveOption="SaveNone">
<Exec
CmdLine="gnucoptions"
Type="Slick-C"/>
</Target>
</Menu>
<List Name="GNUC Options">
<Item
Name="LinkerOutputType"
Value="Executable"/>
</List>
</Config>
<Files>
<Folder
Name="Source Files"
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d"/>
<Folder
Name="Header Files"
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if"/>
<Folder
Name="Resource Files"
Filters="*.ico;*.cur;*.dlg"/>
<Folder
Name="Bitmaps"
Filters="*.bmp"/>
<Folder
Name="Other Files"
Filters="">
<F
N="makefile"
Type="Makefile"/>
</Folder>
</Files>
</Project>

89
Projects/img_mill/makefile

@ -0,0 +1,89 @@
# SlickEdit generated file. Do not edit this file except in designated areas.
# Make command to use for dependencies
MAKE=make
RM=rm
MKDIR=mkdir
# -----Begin user-editable area-----
# -----End user-editable area-----
# If no configuration is specified, "Debug" will be used
ifndef CFG
CFG=Debug
endif
#
# Configuration: Debug
#
ifeq "$(CFG)" "Debug"
OUTDIR=Debug
OUTFILE=$(OUTDIR)/img_mill
CFG_INC=
CFG_LIB=
CFG_OBJ=
COMMON_OBJ=
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
ALL_OBJ=
COMPILE=g++ -c -g -o "$(OUTDIR)/$(*F).o" $(CFG_INC) "$<"
LINK=g++ -g -o "$(OUTFILE)" $(OBJ) $(CFG_LIB)
# Build rules
all: $(OUTFILE)
$(OUTFILE): $(OUTDIR) $(OBJ)
$(LINK)
$(OUTDIR):
$(MKDIR) -p "$(OUTDIR)"
# Rebuild this project
rebuild: cleanall all
# Clean this project
clean:
$(RM) -f $(OUTFILE)
$(RM) -f $(OBJ)
# Clean this project and all dependencies
cleanall: clean
endif
#
# Configuration: Release
#
ifeq "$(CFG)" "Release"
OUTDIR=Release
OUTFILE=$(OUTDIR)/img_mill
CFG_INC=
CFG_LIB=
CFG_OBJ=
COMMON_OBJ=
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
ALL_OBJ=
COMPILE=g++ -c -o "$(OUTDIR)/$(*F).o" $(CFG_INC) "$<"
LINK=g++ -o "$(OUTFILE)" $(OBJ) $(CFG_LIB)
# Build rules
all: $(OUTFILE)
$(OUTFILE): $(OUTDIR) $(OBJ)
$(LINK)
$(OUTDIR):
$(MKDIR) -p "$(OUTDIR)"
# Rebuild this project
rebuild: cleanall all
# Clean this project
clean:
$(RM) -f $(OUTFILE)
$(RM) -f $(OBJ)
# Clean this project and all dependencies
cleanall: clean
endif

20
lib/components/base/basicEvent.h

@ -40,16 +40,26 @@ typedef enum E_basicEventTypeID {
EVT_CAPTURE_START = 13,
EVT_CAPTURE_END = 14,
EVT_CAPTURE_DONE = 15,
EVT_ERROR = 16
EVT_ERROR = 16,
EVT_COUNT = 17
} basicEventTypeID;
#define MAX_EVENT_ID 17
typedef enum E_basicEventClassID{
EVT_CLASS_SYSTEM = 0,
EVT_CLASS_SENSOR = 1,
EVT_CLASS_VIDEO = 2,
EVT_CLASS_IMAGE = 3
EVT_CLASS_SYSTEM = 0,
EVT_CLASS_VIDEO = 2,
EVT_CLASS_IMAGE = 3,
EVT_CLASS_SENSOR_CLD = 4,
EVT_CLASS_SENSOR_LGS = 5,
EVT_CLASS_SENSOR_LFS = 6,
EVT_CLASS_SENSOR_MND = 7,
EVT_CLASS_SENSOR_PLS_210 = 8,
EVT_CLASS_SENSOR_PLS_360 = 9,
EVT_CLASS_SENSOR_ALS = 10,
EVT_CLASS_SENSOR_3D = 11,
EVT_CLASS_SENSOR_ACC = 12,
EVT_CLASS_COUNT = 13
} basicEventClassID;
typedef struct S_basicEvent{

121
lib/components/base/basicFunctionality.cpp

@ -1,4 +1,6 @@
#include "basicFunctionality.h"
#include "../../alg/generic/md5.h"
#ifdef DEBUG
#include "basicLogCollection.h"
#define URGANT_LOG(X) basicLogCollection::getInstance()->Log("basic Functionality", NULL, X )
@ -34,6 +36,78 @@ CSTR getBuildID( void ){
return NULL;
};
/* Global Time Diff Value to correct Timestamps */
static int g_iTimeDiff = 0;
#ifdef __linux__
unsigned long long getSHDTimeValue( void ){
unsigned long long tMilliseconds;
struct timeval tData;
struct timezone tTZ;
tMilliseconds = 0;
tTZ.tz_minuteswest = 0;
tTZ.tz_dsttime = 0;
if( gettimeofday( &tData, &tTZ ) == -1 ){
} else {
tMilliseconds = tData.tv_sec;
tMilliseconds = tMilliseconds *1000;
tMilliseconds += tData.tv_usec / 1000;
};
#else
/*
void TimetToFileTime( time_t t, LPFILETIME pft ){
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD) ll;
pft->dwHighDateTime = ll >>32;
}*/
unsigned __int64 getSHDTimeValue( void ){
unsigned __int64 tMilliseconds;
SYSTEMTIME Ztime;
GetSystemTime(&Ztime);
SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
tMilliseconds -= UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT;
tMilliseconds = tMilliseconds / 10000;
#endif
tMilliseconds += g_iTimeDiff;
return tMilliseconds;
};
CSTR getSHDTimeStamp( void ){
CSTR RetVal = NULL;
time_t rawtime;
uint32_t msec;
struct tm * ptm = NULL;
time ( &rawtime );
ptm = gmtime ( &rawtime );
msec = getSHDTimeValue() % 1000;
//2019-03-24T12:32:59.670Z
if( ptm != NULL ) {
RetVal = (CSTR) malloc( 128 );
if( RetVal!=NULL ){
sprintf( RetVal, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
(ptm->tm_year+1900),
(ptm->tm_mon+1),
ptm->tm_mday,
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
msec
);
};
};
return RetVal;
};
CSTR getUniqID_MD5( void ){
CSTR RetVal;
RetVal = (CSTR) malloc(64);
if(RetVal) sprintf( RetVal, "%s", MD5String( getSHDTimeStamp() ) );
return RetVal;
};
CSTR getUniqID_SHA256(void){ return NULL;};
CSTR getUniqID_UUID(void){ return NULL;};
CSTR trim( CSTR val ){
int i = 0;
int j = strlen( val );
@ -46,6 +120,53 @@ CSTR trim( CSTR val ){
return val;
};
// You must free the result if result is non-NULL.
CSTR strReplace( CSTR orig, CSTR rep, CSTR with ){
char *result; // the return string
char *ins; // the next insert point
char *tmp; // varies
int len_rep; // length of rep (the string to remove)
int len_with; // length of with (the string to replace rep with)
int len_front; // distance between rep and end of last rep
int count; // number of replacements
// sanity checks and initialization
if (!orig || !rep)
return NULL;
len_rep = strlen(rep);
if (len_rep == 0)
return NULL; // empty rep causes infinite loop during count
if (!with)
with = "";
len_with = strlen(with);
// count the number of replacements needed
ins = orig;
for (count = 0; tmp = strstr(ins, rep); ++count) {
ins = tmp + len_rep;
}
tmp = result = (CSTR) malloc(strlen(orig) + (len_with - len_rep) * count + 1);
if (!result)
return NULL;
// first time through the loop, all the variable are set correctly
// from here on,
// tmp points to the end of the result string
// ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep"
while (count--) {
ins = strstr(orig, rep);
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep"
}
strcpy(tmp, orig);
return result;
};
uint8_t checksum8( uint8_t *Buffer, size_t BufferSize ){
uint16_t TempVal;
TempVal = 0;

16
lib/components/base/basicFunctionality.h

@ -34,6 +34,22 @@ uint8_t checksumLGS( uint8_t *Buffer, size_t BufferSize );
CArray * explode( char Delim, CSTR S_Str );
CSTR implode( CArray *Data, CSTR S_Str, U8 Start, U8 End );
CSTR getTStr( CSTR Fmt = NULL );
CSTR getUniqID_SHA256(void);
CSTR getUniqID_MD5(void);
CSTR getUniqID_UUID(void);
CSTR strReplace( CSTR orig, CSTR rep, CSTR with );
//#define EPOCH_DIFF 11644473600LL
#define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
#ifdef __linux__
unsigned long long getSHTimeValue( void );
#else
unsigned __int64 getSHTimeValue( void );
#endif
CSTR getSHDTimeStamp(void);
#ifdef __linux__
inline PF_TIMESTAMP * getPFTS( PF_TIMESTAMP * ptr = NULL ){
struct timeval tData;

6
lib/components/base/basicTypes.h

@ -576,8 +576,12 @@ typedef struct S_SOL_PORT_SETTINGS{
}SOL_PORT_SETTINGS;
typedef struct S_KAFKA_SETTINGS{
char brocker_addr[128];
char brocker_addr[256];
uint16_t brocker_port;
}KAFKA_SETTINGS;
typedef struct S_KAFKA_TEMPLATE{
char topic[128];
CSTR tpl;
}KAFKA_TEMPLATE;
#endif

66
lib/data/protocol/protocolEuropeanGeneral.cpp

@ -34,75 +34,9 @@ CSTR defenderTypeSeverity[] = {
"very-high"
};
/* Global Time Diff Value to correct Timestamps */
static int g_iTimeDiff = 0;
/**
* number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
*/
//#define EPOCH_DIFF 11644473600LL
#define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
#ifdef __linux__
unsigned long long getSHDTimeValue( void ){
unsigned long long tMilliseconds;
struct timeval tData;
struct timezone tTZ;
tMilliseconds = 0;
tTZ.tz_minuteswest = 0;
tTZ.tz_dsttime = 0;
if( gettimeofday( &tData, &tTZ ) == -1 ){
} else {
tMilliseconds = tData.tv_sec;
tMilliseconds = tMilliseconds *1000;
tMilliseconds += tData.tv_usec / 1000;
};
#else
/*
void TimetToFileTime( time_t t, LPFILETIME pft ){
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD) ll;
pft->dwHighDateTime = ll >>32;
}*/
unsigned __int64 getSHDTimeValue( void ){
unsigned __int64 tMilliseconds;
SYSTEMTIME Ztime;
GetSystemTime(&Ztime);
SystemTimeToFileTime( &Ztime, (FILETIME*) &tMilliseconds );
tMilliseconds -= UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT;
tMilliseconds = tMilliseconds / 10000;
#endif
tMilliseconds += g_iTimeDiff;
return tMilliseconds;
};
CSTR getSHDTimeStamp( void ){
CSTR RetVal = NULL;
time_t rawtime;
uint32_t msec;
struct tm * ptm = NULL;
time ( &rawtime );
ptm = gmtime ( &rawtime );
msec = getSHDTimeValue() % 1000;
//2019-03-24T12:32:59.670Z
if( ptm != NULL ) {
RetVal = (CSTR) malloc( 128 );
if( RetVal!=NULL ){
sprintf( RetVal, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
(ptm->tm_year+1900),
(ptm->tm_mon+1),
ptm->tm_mday,
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
msec
);
};
};
return RetVal;
};
bool correctSHDTime( int diff ){
#ifdef __linux__

232
lib/data/protocol/protocolKAFKA.cpp

@ -24,15 +24,8 @@ CSTR protocolKAFKA::buildURL( CSTR templ, int dim, CSTR devID ){
return RetVal;
};
*/
CSTR protocolKAFKA::buildUniqID( void ){
CSTR RetVal;
RetVal = (CSTR) malloc(64);
if(RetVal) sprintf( RetVal, "%s", MD5String( getSHDTimeStamp() ) );
return RetVal;
};
/* Default Constructor */
/*
protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){
m_pLog = basicLogCollection::getInstance();
@ -138,40 +131,38 @@ protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){
basicSettingsProvider::getInstance()->validate();
};
};
}
;*/
protocolKAFKA::protocolKAFKA( KAFKA_SETTINGS *Settings ){
m_pLog = basicLogCollection::getInstance();
m_pSettings = NULL;
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;
m_pScannerName = (CSTR)malloc(OS_SCANNER_NAME_SIZE);
if( m_pScannerName == NULL ) return;
memset( m_pScannerName, 0 , OS_SCANNER_NAME_SIZE);
m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE);
if( m_pServerIP == NULL ) return;
memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE);
m_pAccessURL = (CSTR)malloc(CTEXT);
if (m_pAccessURL == NULL) return;
memset(m_pAccessURL, 0, CTEXT);
m_bCurrentStatus = false;
m_bMitigationStatus = false;
m_bEnabled = false;
m_bEnableStatus = false;
if( Settings!= NULL ) {
strncpy( m_pServerIP, Settings->brocker_addr, 16 );
m_pServerIP = NULL;
memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR ));
if( Settings!= NULL ) {
m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE);
if( m_pServerIP == NULL ) return;
memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE);
strncpy( m_pServerIP, Settings->brocker_addr, OS_CEP_ADDRESS_SIZE );
m_nServerPort = Settings->brocker_port;
sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort );
};
};
protocolKAFKA::protocolKAFKA( CSTR ServerAddress, uint16_t Port ){
m_pLog = basicLogCollection::getInstance();
m_pKafka = NULL;
m_pServerIP = NULL;
if( ServerAddress == 0 || Port == 0 ) return;
m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE);
if( m_pServerIP == NULL ) return;
memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE);
memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR ));
strncpy( m_pServerIP, ServerAddress, OS_CEP_ADDRESS_SIZE );
m_nServerPort = Port;
sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort );
};
/**
* @brief Message delivery report callback.
*
@ -199,7 +190,7 @@ static void dr_msg_cb( rd_kafka_t *rk, const rd_kafka_message_t *rkmessage, void
*/
protocolKAFKA::~protocolKAFKA(){
m_bEnabled = false;
//m_bEnabled = false;
if( m_pKafka != NULL ){
/* Wait for final messages to be delivered or fail.
* rd_kafka_flush() is an abstraction over rd_kafka_poll() which
@ -210,10 +201,11 @@ protocolKAFKA::~protocolKAFKA(){
* 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( m_pScannerName != NULL ) free(m_pScannerName);
//if( m_pScannerName != NULL ) free(m_pScannerName);
if( m_pServerIP != NULL ) free(m_pServerIP);
if( m_pAccessURL != NULL ) free(m_pAccessURL);
//if( m_pAccessURL != NULL ) free(m_pAccessURL);
};
//https://github.com/edenhill/librdkafka/blob/master/examples/producer.c
//https://github.com/edenhill/librdkafka/blob/master/examples/producer.cpp
@ -221,7 +213,7 @@ protocolKAFKA::~protocolKAFKA(){
void protocolKAFKA::dr_cb( RdKafka::Message &message ){
/* If message.err() is non-zero the message delivery failed permanently
* for the message. */
char tBuffer[1024];
char tBuffer[CTEXT];
if( message.err() ){
sprintf(tBuffer,"Message delivery failed: %s", message.errstr().c_str() );
LOG_ERROR( tBuffer );
@ -237,11 +229,9 @@ void protocolKAFKA::dr_cb( RdKafka::Message &message ){
bool protocolKAFKA::init(){
RdKafka::Conf * tProducerConf;
RdKafka::Conf * tTopicConf;
std::string tBuffer;
std::string brokers = m_pKafkaBrokerSTR;
std::string topic = m_pKafkaTopicSTR;
//std::string topic = m_pKafkaTopicSTR;
LOG("Begin Init");
if( strlen( m_pKafkaBrokerSTR ) == 0 ) {
@ -254,31 +244,32 @@ bool protocolKAFKA::init(){
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");
//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( tProducerConf->set( "bootstrap.servers", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){
LOG_ERROR( tBuffer.c_str() );
delete( tProducerConf );
delete( tTopicConf );
tProducerConf = NULL;
tTopicConf = NULL;
//delete( tTopicConf );
//tProducerConf = NULL;
//tTopicConf = NULL;
return false;
};
LOG( m_pKafkaBrokerSTR );
LOG("bootstrap.servers is SET");
if( tProducerConf->set("metadata.broker.list", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){
LOG_ERROR( tBuffer.c_str() );
delete( tProducerConf );
delete( tTopicConf );
tProducerConf = NULL;
tTopicConf = NULL;
//delete( tTopicConf );
//tProducerConf = NULL;
//tTopicConf = NULL;
return false;
};
LOG("metadata.broker.list is SET");
@ -293,21 +284,21 @@ bool protocolKAFKA::init(){
if( tProducerConf->set( "dr_cb", this, tBuffer ) != RdKafka::Conf::CONF_OK ){
LOG_ERROR( tBuffer.c_str() );
delete( tProducerConf );
delete( tTopicConf );
tProducerConf = NULL;
tTopicConf = NULL;
//delete( tTopicConf );
//tProducerConf = NULL;
//tTopicConf = NULL;
return false;
};
LOG("dr_cb is SET");
if( tProducerConf->set("default_topic_conf", tTopicConf, tBuffer ) != RdKafka::Conf::CONF_OK ){
LOG_ERROR( tBuffer.c_str() );
delete( tProducerConf );
delete( tTopicConf );
tProducerConf = NULL;
tTopicConf = NULL;
return false;
};
LOG("default_topic_conf is SET");
//if( tProducerConf->set("default_topic_conf", tTopicConf, tBuffer ) != RdKafka::Conf::CONF_OK ){
// LOG_ERROR( tBuffer.c_str() );
// delete( tProducerConf );
// delete( tTopicConf );
// tProducerConf = NULL;
// tTopicConf = NULL;
// return false;
//};
//LOG("default_topic_conf is SET");
/*
* Create producer instance.
*
@ -319,37 +310,65 @@ bool protocolKAFKA::init(){
if( m_pKafka == NULL ){
LOG_ERROR( tBuffer.c_str() );
delete( tProducerConf );
delete( tTopicConf );
tProducerConf = NULL;
tTopicConf = NULL;
//delete( tTopicConf );
//tProducerConf = NULL;
//tTopicConf = NULL;
return false;
};
LOG("RdKafka::Producer Created");
m_pKafkaTopic = RdKafka::Topic::create( m_pKafka, topic, tTopicConf, tBuffer );
delete( tProducerConf );
// tProducerConf = NULL;
LOG("INIT Complete");
// m_bEnabled = true;
return true;
};
bool protocolKAFKA::issuePost( CSTR tpc, 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 brokers = m_pKafkaBrokerSTR;
std::string topic = tpc;
if( m_pKafka == NULL) return false;
tTopicConf = RdKafka::Conf::create( RdKafka::Conf::CONF_TOPIC );
if( tTopicConf==NULL ){
LOG_ERROR("Eror Creating Topic Conf!");
return false;
};
#ifdef DEBUG
LOG("RdKafka::Conf::CONF_TOPIC Created");
#endif
tKafkaTopic = RdKafka::Topic::create( m_pKafka, topic, tTopicConf, tBuffer );
if( m_pKafkaTopic == NULL ) {
LOG_ERROR( tBuffer.c_str() );
delete( tProducerConf );
delete( tTopicConf );
return false;
};
#ifdef DEBUG
LOG("RdKafka::Topic Created");
#endif
/*
if( tProducerConf->set( "default_topic_conf", tTopicConf, tBuffer ) != RdKafka::Conf::CONF_OK ){
LOG_ERROR( tBuffer.c_str() );
delete( tTopicConf );
tProducerConf = NULL;
tTopicConf = NULL;
return false;
};
LOG("RdKafka::Topic Created");
delete( tProducerConf );
delete( tTopicConf );
tProducerConf = NULL;
tTopicConf = NULL;
LOG("INIT Complete");
m_bEnabled = true;
return true;
};
bool protocolKAFKA::issuePost( CSTR Buffer, int BufferSize ){
if( m_pKafka == NULL) return false;
RdKafka::ErrorCode err;
#ifdef DEBUG
LOG("default_topic_conf is SET");
#endif
//*/
retry:
err = m_pKafka->produce(
m_pKafkaTopic,
tKafkaTopic,
RdKafka::Topic::PARTITION_UA,
RdKafka::Producer::RK_MSG_COPY,
(void *)Buffer,
@ -359,9 +378,10 @@ retry:
);
if( err != RdKafka::ERR_NO_ERROR ) {
///std::cerr << "% Failed to produce to topic " << topic << ": " << RdKafka::err2str(err) << std::endl;
LOG_ERROR("Failed to produce to topic");
sprintf( tBuf, "Failed to produce to topic[%s]: %s", topic.c_str(), RdKafka::err2str(err).c_str() );
LOG_ERROR( tBuf );
if( err == RdKafka::ERR__QUEUE_FULL ){
LOG("Internal queue is full!");
LOG_ERROR("Internal queue is full!");
/* If the internal queue is full, wait for
* messages to be delivered and then retry.
* The internal queue represents both
@ -373,17 +393,16 @@ retry:
* configuration property
* queue.buffering.max.messages */
m_pKafka->poll(1000/*block for max 1000ms*/);
goto retry;
if( rCnt-- ) goto retry;
};
}
#ifdef DEBUG
else {
LOG("MSG Queued OK");
//std::cerr << "% Enqueued message (" << line.size() << " bytes) " << "for topic " << topic << std::endl;
sprintf( tBuf, "Enqueued message (%d bytes) for topic %s", BufferSize, topic.c_str() );
LOG( tBuf );
}
#endif
;
;
/* A producer application should continually serve
* the delivery report queue by calling poll()
* at frequent intervals.
@ -401,9 +420,18 @@ retry:
// cnt--;
// m_pKafka->poll(100);
//};
delete( tKafkaTopic );
delete( tTopicConf );
tKafkaTopic = NULL;
tTopicConf = NULL;
return true;
};
/*
void protocolKAFKA::setScannerName( CSTR Name ){
sprintf( m_pScannerName, "%s", Name );
};
@ -670,7 +698,7 @@ bool protocolKAFKA::buildEvent3DPackage( unsigned char *Buffer, int &BufferSize,
};
bool protocolKAFKA::buildClockSyncPackage( unsigned char *Buffer, int &BufferSize ){
/*if( Buffer!= NULL ){
if( Buffer!= NULL ){
CSTR tBuf;
tBuf = getSHTimeStamp();
if( tBuf != NULL ){
@ -683,12 +711,12 @@ bool protocolKAFKA::buildClockSyncPackage( unsigned char *Buffer, int &BufferSiz
free( tBuf );
return true;
};
};*/
};
return false;
};
bool protocolKAFKA::buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath ){
/*if( Buffer!= NULL ){
if( Buffer!= NULL ){
sprintf(
((char *)(Buffer+BufferSize)),
PACKAGE_ENVELOPE_TEMPLATE_REG_CALL,
@ -696,11 +724,9 @@ bool protocolKAFKA::buildCallBackPackage( unsigned char *Buffer, int &BufferSize
);
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];
@ -768,7 +794,7 @@ bool protocolKAFKA::StartTimeSynch( void ){
if( !m_bEnableStatus ) return true;
bool RetVal= false;
//LOG("TimeSYnc");
/*char Buffer[1024];
char Buffer[1024];
int BufferSize = 0;
CSTR URL = NULL;
URL = buildURL( SERVICE_URL_TEMPLATE_CLOCKSYNC, m_nScannerDimentions, m_pScannerName );
@ -776,10 +802,10 @@ bool protocolKAFKA::StartTimeSynch( void ){
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );
free( URL );
};*/
};
return RetVal;
};
*/
#undef LOG
#undef LOG_ERROR

85
lib/data/protocol/protocolKAFKA.h

@ -26,59 +26,60 @@
class protocolKAFKA:public RdKafka::DeliveryReportCb {
private:
basicLogCollection * m_pLog;
config_setting_t * m_pSettings;
//config_setting_t * m_pSettings;
//rd_kafka_t * m_pKafka; /* Producer instance handle */
RdKafka::Producer * m_pKafka; /* Producer instance handle */
//rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */
//RdKafka::Conf * m_pKafkaConf; /* Temporary configuration object */
CSTR m_pKafkaBrokerSTR;
CSTR m_pKafkaTopicSTR;
char m_pKafkaBrokerSTR[OS_CEP_ADDRESS_SIZE];
//CSTR m_pKafkaTopicSTR;
RdKafka::Topic * m_pKafkaTopic;
bool m_bUseCompression;
bool m_bEnableStatus;
// bool m_bUseCompression;
// bool m_bEnableStatus;
//uint8_t m_bKafkaBrokersCount;
int m_nScannerDimentions;
CSTR m_pScannerName;
//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;
//CSTR m_pAccessURL;
//bool m_bEnabled;
//bool m_bUseSSL;
//bool m_bMitigationStatus;
//float m_fLon;
//float m_fLat;
int m_nServerPort;
bool m_bCurrentStatus;
//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 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 );
bool issuePost( CSTR Buffer, int BufferSize );
//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 );
public:
// Constructor
explicit protocolKAFKA( config_setting_t *Settings );
//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 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 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 );
/* Implementation of RdKafka::DeliveryReportCb */
virtual void dr_cb( RdKafka::Message &message );
#ifdef __linux__
@ -86,17 +87,11 @@ class protocolKAFKA:public RdKafka::DeliveryReportCb {
#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; };
// 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; };
};
#ifdef __linux__
unsigned long long getSHTimeValue( void );
#else
unsigned __int64 getSHTimeValue( void );
#endif
#endif

69
lib/rgoose/rgooseDBConnector.cpp

@ -1382,8 +1382,73 @@ CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
return NULL;
};
KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t NodeID ){
return NULL;
KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
KAFKA_SETTINGS *tVal = NULL;
if( m_bIsConnected ) {
char tQBuf[CTEXT];
AAssoc *result;
sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
#ifdef DEBUG
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
if( tVal != NULL ) {
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("brocker_address");
if( it != cArr->end() ){
strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
};
it = cArr->find("brocker_port");
if( it != cArr->end() ){
tVal->brocker_port = atoi( it->second.c_str() );
};
};
};
};
deleteResult( result );
};
return tVal;
};
KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
KAFKA_TEMPLATE *tVal = NULL;
if( m_bIsConnected ) {
char tQBuf[CTEXT];
AAssoc *result;
sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
#ifdef DEBUG
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
if( tVal != NULL ) {
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("topic");
if( it != cArr->end() ){
strncpy( tVal->topic , it->second.c_str(), 127 );
};
it = cArr->find("template");
if( it != cArr->end() ){
tVal->tpl = (CSTR)malloc( it->second.length() );
if( tVal->tpl!= NULL) {
strncpy( tVal->tpl, it->second.c_str(), 255 );
};
};
};
};
};
deleteResult( result );
};
return tVal;
};
DBC_UART_DATA *argusDBC::getSettingsUART( uint32_t SocketID ){

2
lib/rgoose/rgooseDBConnector.h

@ -151,7 +151,6 @@ typedef struct S_DBC_UART_DATA{
uint32_t speed;
}DBC_UART_DATA;
typedef std::vector<uint32_t> DBC_INT_LIST;
typedef std::vector<DBC_CAM_DATA*> vectorCamRecords;
typedef std::vector<EventRecordDBC*> vectorEventRecords;
@ -213,6 +212,7 @@ class argusDBC{
void setNodeOnline( uint32_t NodeID );
void setNodeOffline( uint32_t NodeID );
KAFKA_SETTINGS * getSettingsKAFKA( uint32_t NodeID );
KAFKA_TEMPLATE * getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID );
DBC_UART_DATA * getSettingsUART( uint32_t SocketID );
private:
static argusDBC * _instance;

155
lib/rgoose/rgooseKafkaModule.cpp

@ -15,26 +15,33 @@
argusKafkaModule::argusKafkaModule( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_KAFKA ){
m_pProtocol = NULL;
/*
if( DBC != NULL ) {
m_pProtocol = new protocolInfoStress();
if( m_pProtocol != NULL ) {
if( !basicThread::init() ){
LOG_ERROR("Error Create Thread!");
} else {
if( !m_pProtocol->init() ) {
LOG_ERROR("Error INIT KAFKA!");
};
};
};
};
*/
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**));
} else LOG_ERROR("EVT Templates Memory Allocation Error!");
};
argusKafkaModule::~argusKafkaModule(){
waitThreadEnd( true );
if( m_pProtocol!= NULL ) {
delete( m_pProtocol );
};
if( m_pEvtTemplates!= NULL ) {
for(int i=0; i < EVT_CLASS_COUNT; i++ ) {
if( m_pEvtTemplates[i] != NULL ){
for( int j=0; j< EVT_COUNT; j++ ) {
if( m_pEvtTemplates[i][j] != NULL ){
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl );
free( m_pEvtTemplates[i][j] );
};
};
free( m_pEvtTemplates[i] );
};
};
free( m_pEvtTemplates );
};
};
/* Periodical Job Handler */
void argusKafkaModule::m_fThreadProc( void ){
@ -42,8 +49,12 @@ void argusKafkaModule::m_fThreadProc( void ){
while( m_bThreadStatus < TH_ENDED ) {
m_llTicks ++;//= getMilliseconds();
if( m_llTicks % 20 == 0 ) { // each 2 seconds
m_pProtocol->StatusUpdate();
//m_pProtocol->StatusUpdate();
//m_lCycleCounter == 0;
//char tBuff[256];
//sprintf(tBuff,"MY MESSAGE %dd", m_llTicks );
//LOG( tBuff );
//m_pProtocol->issuePost( "My_TEST_TOPIC", tBuff, strlen( tBuff ) );
};
/* No need for time Sync
if( m_llTicks % 350 == 0 ) { // each 35 seconds
@ -60,6 +71,8 @@ bool argusKafkaModule::startService(){
if( m_pSettings!= NULL ){
m_pProtocol = new protocolKAFKA( m_pSettings );
if( m_pProtocol->init() ){
// No need pereodical jobs
//return init();
return true;
};
};
@ -68,27 +81,110 @@ bool argusKafkaModule::startService(){
};
bool argusKafkaModule::stopService(){
waitThreadEnd( true );
return true;
};
bool argusKafkaModule::reloadSettings(){
if( m_pDBC==NULL ) return false;
m_pSettings = m_pDBC->getSettingsKAFKA( m_nDBID );
m_pSettings = m_pDBC->getSettingsKAFKA( m_nDBAUXID );
if( m_pSettings != NULL ) {
if( m_pEvtTemplates != NULL ) {
// Clear Templates
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){
for(int j = 0; j < EVT_COUNT; j++ ){
if( m_pEvtTemplates[i] != NULL ){
if( m_pEvtTemplates[i][j] != NULL ){
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl );
free( m_pEvtTemplates[i][j] );
m_pEvtTemplates[i][j] = NULL;
};
};
};
free( m_pEvtTemplates[i] );
m_pEvtTemplates[i] = NULL;
};
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){
for(int j = 0; j < EVT_COUNT; j++ ){
KAFKA_TEMPLATE * tT;
tT = m_pDBC->getKafkaTemplateForEvent( m_nDBID, i, j );
if( tT != NULL ) {
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*));
};
m_pEvtTemplates[i][j] = tT;
};
};
};
};
return true;
};
return false;
};
CSTR argusKafkaModule::buildTemplate(
CSTR tpl,
uint32_t source_id,
CSTR ts,
CSTR uuid,
CSTR az,
CSTR range,
CSTR el
){
CSTR ct1, ct2;
char tVar[64];
if( tpl == NULL ) return NULL;
sprintf( tVar, "%d", source_id );
ct1 = strReplace( tpl, KAFKA_TPL_SUBST_ID, tVar );
if( ct1 ) {
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_TS, ts );
if( ct2 ) {
free( ct1 );
ct1 = ct2;
};
if( uuid ){
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_UUID, uuid );
if( ct2 ) {
free( ct1 );
ct1 = ct2;
};
};
if( az ){
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_AZ, az );
if( ct2 ) {
free( ct1 );
ct1 = ct2;
};
};
if( range ){
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_RANGE, range );
if( ct2 ) {
free( ct1 );
ct1 = ct2;
};
};
if( el ){
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_EL, el );
if( ct2 ) {
free( ct1 );
ct1 = ct2;
};
};
return ct1;
};
return NULL;
};
void argusKafkaModule::dispatchEvent( basicEvent *Evt ){
#ifdef DEBUG
LOG( "CLIENT's DISPATCHER");
LOG( "EVT DISPATCHER");
#endif
if( Evt == NULL ) {
LOG( "Evt NULL");
return;
};
if( Evt->m_eClass == EVT_CLASS_SENSOR ) {
if( m_pEvtTemplates[ Evt->m_eClass ]!= NULL ) {
// We have defined Channel for that class Events
#ifdef DEBUG
char tBuffer[256];
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType );
@ -97,6 +193,20 @@ void argusKafkaModule::dispatchEvent( basicEvent *Evt ){
// Skip Event Handling by flags
if( !m_bEvtFlags[ Evt->m_eType ] ) return;
// Hadle Event
CSTR tDATA;
if( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ] != NULL ) {
CLIENT_EVENT *tCEVT;
tCEVT = ( CLIENT_EVENT *) Evt->m_pEvtData;
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl,
Evt->m_nSourceUID,
getUniqID_MD5()
);
if( tDATA!= NULL ) {
m_pProtocol->issuePost( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->topic, tDATA, strlen( tDATA ) );
};
};
/*
switch( Evt->m_eType ) {
case EVT_TARGET_1D:
case EVT_TARGET_2D_WHITE:
@ -104,7 +214,7 @@ void argusKafkaModule::dispatchEvent( basicEvent *Evt ){
case EVT_TARGET_3D_WHITE:
case EVT_TARGET_3D_BLACK:{
CLIENT_EVENT *tCEVT;
tCEVT = (CLIENT_EVENT *) Evt->m_pEvtData;
tCEVT = ( CLIENT_EVENT *) Evt->m_pEvtData;
if( tCEVT != NULL ){
float Az, El;
uint32_t cRange;
@ -133,11 +243,8 @@ void argusKafkaModule::dispatchEvent( basicEvent *Evt ){
default:
LOG_ERROR("Unknown Event!");
};
} else {
#ifdef DEBUG
LOG( "No SENSOR EVT ");
#endif
}
*/
};
};
#undef LOG

19
lib/rgoose/rgooseKafkaModule.h

@ -6,11 +6,28 @@
#include "../components/base/basicThread.h"
#include "../data/protocol/protocolKAFKA.h"
class argusKafkaModule: public basicThread, argusKernelModule {
#define KAFKA_TPL_SUBST_ID "%%ID%%"
#define KAFKA_TPL_SUBST_UUID "%%UUID%%"
#define KAFKA_TPL_SUBST_TS "%%TIMESTAMP%%"
#define KAFKA_TPL_SUBST_AZ "%%AZIMUTH%%"
#define KAFKA_TPL_SUBST_RANGE "%%RANGE%%"
#define KAFKA_TPL_SUBST_EL "%%ELEVATION%%"
class argusKafkaModule: public basicThread, public argusKernelModule {
private:
KAFKA_SETTINGS *m_pSettings;
protocolKAFKA *m_pProtocol;
KAFKA_TEMPLATE ***m_pEvtTemplates;
unsigned long long m_llTicks;
CSTR buildTemplate( CSTR tpl,
uint32_t source_id,
CSTR ts,
CSTR uuid = NULL,
CSTR az = NULL,
CSTR range = NULL,
CSTR el = NULL
);
protected:
virtual void m_fThreadProc( void );
public:

9
lib/rgoose/rgooseModule.cpp

@ -8,7 +8,16 @@ argusKernelModule::argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param ):bas
m_eType = param;
m_nDBID = id;
m_bDetached = false;
m_nDBAUXID = 0;
// Clear Events flags
if( m_pDBC ) {
DBC_MODULE_DATA *tData = NULL;
tData = m_pDBC->getModuleData( m_nDBID );
if( tData ) {
m_nDBAUXID = tData->aux_id;
free( tData );
};
};
for( int i = 0; i < MAX_EVENT_ID; i++ ) m_bEvtFlags[i] = false;
};

4
lib/rgoose/rgooseModule.h

@ -23,6 +23,7 @@ class argusKernelModule: public basicEventHandler, basicObject{
basicLogCollection * m_pLog;
argusDBC * m_pDBC;
uint32_t m_nDBID;
uint32_t m_nDBAUXID;
argusKernel * m_pKernel;
bool m_bDetached;
bool m_bEvtFlags[MAX_EVENT_ID];
@ -30,7 +31,8 @@ class argusKernelModule: public basicEventHandler, basicObject{
ARGUS_MODULE_TYPE m_eType;
explicit argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param = ARGUS_MODULE_UNKNOWN );
virtual ~argusKernelModule();
uint32_t getId() const { return m_nDBID;};
uint32_t getId() const { return m_nDBID; };
uint32_t getAuxId() const { return m_nDBAUXID; };
ARGUS_MODULE_TYPE getType() const { return m_eType; };
bool isDetached() const { return m_bDetached; };
bool isAttached() const { return !m_bDetached; };

14
lib/rgoose/rgooseModuleFactory.cpp

@ -1,6 +1,7 @@
#include "rgooseModuleFactory.h"
#include "rgooseZLMediaModule.h"
#include "rgooseUSBRelayModule.h"
#include "rgooseKafkaModule.h"
#ifdef MEM_DEBUG
#include "../alg/generic/heapDebug.h"
@ -78,7 +79,7 @@ argusKernelModule *argusModuleFactory::createModule( int id ){
#ifdef DEBUG
LOG("Creating ZLMedia Connector Module");
#endif
tVal = new ARGUS_ZLMedia( tData->aux_id );
tVal = new ARGUS_ZLMedia( tData->module_id );
break;
case ARGUS_MODULE_DCBUSB:
#ifdef DEBUG
@ -86,12 +87,21 @@ argusKernelModule *argusModuleFactory::createModule( int id ){
#endif
break;
case ARGUS_MODULE_KAFKA:
#ifdef DEBUG
LOG("Creating KAFKA Module");
#endif
tVal = new argusKafkaModule( tData->module_id );
break;
};
};
free(tData);
};
};
if( tVal != NULL ) m_vKernelModules.push_back( tVal );
if( tVal != NULL ){
tVal->startService();
m_vKernelModules.push_back( tVal );
};
return tVal;
};

48
lib/rgoose/rgooseNode3D.cpp

@ -285,7 +285,7 @@ void objectLGS::m_fThreadAProc(void){
m_mStatusMutex.unlock();
basicEvent *tEVT;
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Device is connected");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_READY, "Device is connected");
m_pEventHeap->broadcast(tEVT);
} else {
//handle no connection
@ -302,7 +302,7 @@ void objectLGS::m_fThreadAProc(void){
basicEvent *tEVT;
//ToDo: Change Device Name!
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Device is Not Connected");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_ERROR, "Device is Not Connected");
m_pEventHeap->broadcast( tEVT );
};
} else {
@ -325,9 +325,9 @@ void objectLGS::m_fThreadAProc(void){
basicEvent *tEVT;
if( m_bIsMaster ) {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Master Device is connected");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_READY, "Master Device is connected");
}else{
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Slave Device is connected");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_READY, "Slave Device is connected");
};
m_pEventHeap->broadcast(tEVT);
} else {
@ -345,9 +345,9 @@ void objectLGS::m_fThreadAProc(void){
basicEvent *tEVT;
if( m_bIsMaster ) {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device is disconnected");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_ERROR, "Master Device is disconnected");
}else{
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device is disconnected");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_ERROR, "Slave Device is disconnected");
};
m_pEventHeap->broadcast( tEVT );
};
@ -526,9 +526,9 @@ void objectLGS::m_fThreadAProc(void){
// Handle device's time out
basicEvent *tEVT;
if( m_bIsMaster ) {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Master Device communication Time Out");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_ERROR, "Master Device communication Time Out");
} else {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Slave Device communication Time Out");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_ERROR, "Slave Device communication Time Out");
};
m_pEventHeap->broadcast( tEVT );
//m_bComIsBusy = false;
@ -846,21 +846,21 @@ bool objectLGS::packetHandler(protocolPackage* Package) {
case STG_STUDY: {
m_mStatusMutex.unlock();
basicEvent* tEVT;
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_STUDY, "Device in STUDY mode");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_STUDY, "Device in STUDY mode");
m_pEventHeap->broadcast(tEVT);
break;
};
case STG_REDY: {
m_mStatusMutex.unlock();
basicEvent* tEVT;
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_READY, "Device in DETECTION mode");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_READY, "Device in DETECTION mode");
m_pEventHeap->broadcast(tEVT);
break;
};
case STG_BUSY: {
m_mStatusMutex.unlock();
basicEvent* tEVT;
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_ERROR, "Device in BUSY mode");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_ERROR, "Device in BUSY mode");
m_pEventHeap->broadcast(tEVT);
break;
};
@ -899,7 +899,7 @@ bool objectLGS::packetHandler(protocolPackage* Package) {
tEVT[xindex].ums,
tData->area
);
bEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData);
bEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData);
if (bEVT != NULL) {
m_pEventHeap->broadcast(bEVT);
} else {
@ -957,23 +957,23 @@ bool objectLGS::packetHandler(protocolPackage* Package) {
case CMD_EVT:
break;
case CMD_FLIP_COMPLETE: {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_FLIP, "Flip Complete");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_FLIP, "Flip Complete");
m_pEventHeap->broadcast(tEVT);
break;
};
case CMD_SCAN_COMPLETE: {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_SCAN, "Scan Complete");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_SCAN, "Scan Complete");
m_pEventHeap->broadcast(tEVT);
break;
};
case CMD_TARGET: {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_TARGET_3D_WHITE, "Target");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_WHITE, "Target");
m_pEventHeap->broadcast(tEVT);
break;
};
case CMD_TARGET_WW: {
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR, EVT_TARGET_3D_WHITE, "Target with Width");
tEVT = createBasicEvent( getObjectId(), EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_WHITE, "Target with Width");
m_pEventHeap->broadcast(tEVT);
break;
};
@ -1313,21 +1313,21 @@ void objectLGS::m_fThreadBProc(void){
case STG_STUDY:{
m_mStatusMutex.unlock();
basicEvent *tEVT;
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_STUDY, "Device in STUDY mode");
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR_3D, EVT_STUDY, "Device in STUDY mode");
m_pEventHeap->broadcast( tEVT );
break;
};
case STG_REDY:{
m_mStatusMutex.unlock();
basicEvent *tEVT;
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, EVT_READY, "Device in DETECTION mode");
tEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR_3D, EVT_READY, "Device in DETECTION mode");
m_pEventHeap->broadcast(tEVT);
break;
};
case STG_BUSY:{
m_mStatusMutex.unlock();
basicEvent *tEVT;
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_ERROR, "Device in BUSY mode");
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR_3D, EVT_ERROR, "Device in BUSY mode");
m_pEventHeap->broadcast( tEVT );
break;
};
@ -1375,7 +1375,7 @@ void objectLGS::m_fThreadBProc(void){
tData = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
if( tData!= NULL ){
memcpy( tData, &tEVT[xindex], sizeof(CLIENT_EVENT));
bEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, (basicEventTypeID) tEVT[xindex].type, tBuffer, tData );
bEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR_3D, (basicEventTypeID) tEVT[xindex].type, tBuffer, tData );
if( bEVT!= NULL ) m_pEventHeap->broadcast( bEVT );
};
};
@ -1429,23 +1429,23 @@ void objectLGS::m_fThreadBProc(void){
case CMD_EVT:
break;
case CMD_FLIP_COMPLETE:{
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_FLIP, "Flip Complete");
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR_3D, EVT_FLIP, "Flip Complete");
m_pEventHeap->broadcast( tEVT );
break;
};
case CMD_SCAN_COMPLETE:{
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_SCAN, "Scan Complete");
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR_3D, EVT_SCAN, "Scan Complete");
m_pEventHeap->broadcast( tEVT );
break;
};
case CMD_TARGET:{
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target");
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR_3D, EVT_TARGET, "Target");
m_pEventHeap->broadcast( tEVT );
break;
};
case CMD_TARGET_WW:{
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR, EVT_TARGET, "Target with Width");
tEVT = createBasicEvent( getID(), EVT_CLASS_SENSOR_3D, EVT_TARGET, "Target with Width");
m_pEventHeap->broadcast( tEVT );
break;
};

Loading…
Cancel
Save