Browse Source

Fixed Mem Leak in AVLIB decoder

AGP
Evgeny Gagua 5 years ago
parent
commit
6e04007dc5
  1. 1
      Projects/argus/argus.vpj
  2. 6
      Projects/argus/makefile
  3. 4
      lib/App/argus/ArgusBackend.cpp
  4. 2
      lib/components/base/basicThread.cpp
  5. 4
      lib/data/curl/curlRequest.cpp
  6. 2
      lib/data/curl/curlRequest.h
  7. 165
      lib/data/media/video/videoAVLIBSource.cpp
  8. 7
      lib/data/ponvif/ponvif.cpp
  9. 32
      lib/data/protocol/protocolPTZ_ONVIF.cpp
  10. 2
      lib/rgoose/rgooseCamera.cpp
  11. 208
      lib/rgoose/rgooseDBConnector.cpp
  12. 4
      lib/rgoose/rgooseDBConnector.h
  13. 4
      lib/rgoose/rgooseHardwareManager.cpp
  14. 126
      lib/rgoose/rgooseKernel.cpp
  15. 3
      lib/rgoose/rgooseModule.cpp
  16. 289
      lib/rgoose/rgooseModuleEmbedVideo.cpp
  17. 192
      lib/rgoose/rgooseModuleFactory.cpp
  18. 16
      lib/rgoose/rgooseModuleFactory.h
  19. 67
      lib/rgoose/rgooseModuleOnvifObserver.cpp
  20. 1
      lib/rgoose/rgooseModuleOnvifObserver.h
  21. 2
      lib/rgoose/rgooseModuleSSDP.cpp
  22. 175
      lib/rgoose/rgooseNodeFactory.cpp
  23. 44
      lib/rgoose/rgooseNodeFactory.h
  24. 21
      lib/rgoose/rgooseNodeStaticCamControl.cpp

1
Projects/argus/argus.vpj

@ -129,7 +129,6 @@
<Lib File="`pkg-config"/>
<Lib File="--libs"/>
<Lib File="openssl"/>
<Lib File="libssl"/>
<Lib File="opencv4"/>
<Lib File="rdkafka++`"/>
</Libs>

6
Projects/argus/makefile

@ -24,8 +24,8 @@ CFG_INC=
CFG_LIB=-lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig \
-lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec libavdevice \
libavfilter libavformat libavutil libpostproc libswresample \
libswscale --libs` -latomic `pkg-config --libs openssl libssl \
opencv4 rdkafka++`
libswscale --libs` -latomic `pkg-config --libs openssl opencv4 \
rdkafka++`
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
$(OUTDIR)/basicCameraInfo.o $(OUTDIR)/basicDualThread.o \
@ -131,7 +131,7 @@ ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
-lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 \
-lhidapi-libusb `pkg-config libavcodec libavdevice libavfilter \
libavformat libavutil libpostproc libswresample libswscale --libs` \
-latomic `pkg-config --libs openssl libssl opencv4 rdkafka++`
-latomic `pkg-config --libs openssl opencv4 rdkafka++`
COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O0 -g3 -ggdb -std=c++11 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $<
LINK=g++ -O0 -g3 -ggdb -o "$(OUTFILE)" $(ALL_OBJ)

4
lib/App/argus/ArgusBackend.cpp

@ -261,8 +261,8 @@ int main (int argc, char *argv[]){
LOG_ERROR("Kernel create failure!");
} else {
//Install Signal Listeners
old_kill_handler_15 = signal( 15, signal_SIGKILL_handler );
old_kill_handler_9 = signal( 9, signal_SIGKILL_handler );
old_kill_handler_15 = signal( SIGTERM /* 15 */, signal_SIGKILL_handler );
old_kill_handler_9 = signal( SIGKILL /* 9 */, signal_SIGKILL_handler );
// Waiting for Worker to Shut Down
Kernel->WaitFinish( false );
m_bKernelExitCode = Kernel->getExitCause();

2
lib/components/base/basicThread.cpp

@ -7,7 +7,7 @@
#define SLOG_ERROR( X ) mThis->m_pLog->Log( "BasicThreadS", mThis, _LOG_ERROR, X )
bool basicThread::init( void ){
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Init Single Thread");
#endif
if (m_bThreadStatus == TH_PRE_INIT) {

4
lib/data/curl/curlRequest.cpp

@ -59,7 +59,7 @@ curlRequest::~curlRequest(){
if( m_pMemoryBuffer ) free(m_pMemoryBuffer);
};
#ifdef DEBUG
#ifdef DEBUG_EXTRA
int curlRequest::debug_callback( CURL *handle, curl_infotype type, char *data, size_t size, void *userptr ){
FILE *tdFD = fopen("CURL_DEBUG.TXT","ab+");
if( tdFD ) {
@ -122,7 +122,7 @@ void curlRequest::init_CURL(){
curl_easy_setopt( m_pCURL, CURLOPT_TIMEOUT, 20 );
curl_easy_setopt( m_pCURL, CURLOPT_SSL_VERIFYPEER, 0 );
curl_easy_setopt( m_pCURL, CURLOPT_SSL_VERIFYHOST, 0 );
#ifdef DEBUG
#ifdef DEBUG_EXTRA
curl_easy_setopt( m_pCURL, CURLOPT_VERBOSE, 1 );
curl_easy_setopt( m_pCURL, CURLOPT_DEBUGFUNCTION, debug_callback );
curl_easy_setopt( m_pCURL, CURLOPT_DEBUGDATA, this );

2
lib/data/curl/curlRequest.h

@ -41,7 +41,7 @@ class curlRequest{
void init_CURL();
void * (*m_pSignalFunc) (void *, void*);
static size_t m_fWriteMemoryHandler(void *ptr, size_t nsize, size_t nmemb, void *data);
#ifdef DEBUG
#ifdef DEBUG_EXTRA
static int debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr );
#endif
public:

165
lib/data/media/video/videoAVLIBSource.cpp

@ -296,7 +296,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
} else {
m_bSizeIsAutomatic = true;
};
av_dict_set(&options, "movflags", "faststart", 0);
//av_dict_set(&options, "movflags", "faststart", 0);
av_dict_set(&options, "rtsp_transport", "tcp", 0);
av_dict_set(&options, "max_delay", "300000", 0);
av_dict_set(&options, "stimeout", "1000000", 0);
@ -527,99 +527,130 @@ void videoAVLIBSource::m_fThreadProc( void ){
//cv::setBreakOnError( true );
m_pVideoState->m_bStatus = MS_STOPED;
while( m_pMediaDestination == NULL && m_bThreadStatus == TH_WORKING ){
SLEEP(10);
SLEEP(20);
};
#ifdef DEBUG
LOG("Presentation Started.");
#endif
//m_pVideoState->m_bStatus = MS_PRESENT;
av_read_play( m_pVideoState->m_pFormatCtx );
while( m_pVideoState->m_bStatus < MS_CLOSING && m_bThreadStatus != TH_ENDED ){
if ( m_pMediaDestination != NULL ){
if( av_read_frame( m_pVideoState->m_pFormatCtx, m_pPacket ) >= 0 ){
if( m_pPacket->stream_index == m_pVideoState->m_iVideoStreamID ){
//Video Packet
int dec_ret = avcodec_send_packet( m_pVideoState->m_pCodecCtx, m_pPacket );
if( dec_ret < 0 ){
//char tB[256];
//sprintf( tB, "Error decoding video frame (%s)\n", av_err2str( dec_ret ));
LOG_ERROR( "Error decoding video frame" );
m_pVideoState->m_bStatus = MS_CLOSING;
m_bThreadStatus = TH_ENDED;
break;
};
while( dec_ret >= 0 && m_bThreadStatus != TH_ENDED ) {
dec_ret = avcodec_receive_frame( m_pVideoState->m_pCodecCtx, m_pFrame );
if( dec_ret == AVERROR(EAGAIN) || dec_ret == AVERROR_EOF ){
continue;//Skip to next data
} else if( dec_ret < 0 ){
LOG_ERROR("Error in video decoding");
m_pVideoState->m_bStatus = MS_STOPED;
m_bThreadStatus = TH_ENDED;
break;
};
#ifdef PROCESS_YUV420P
sws_scale( img_convert_ctx, (const uint8_t* const*) m_pFrame->data, m_pFrame->linesize, 0, m_pVideoState->m_pCodecCtx->height, m_pFrameYUV->data, m_pFrameYUV->linesize );
//SDL_UpdateYUVTexture(m_pTexture, &m_oRect, m_pFrameYUV->data[0], m_pFrameYUV->linesize[0], m_pFrameYUV->data[1], m_pFrameYUV->linesize[1], m_pFrameYUV->data[2], m_pFrameYUV->linesize[2]);
if (m_pMediaDestination != NULL) m_pMediaDestination->pushFrame( m_pFrameYUV, m_pOpaque );
#else // PROCESS_BGR24
sws_scale( img_convert_ctx, (const uint8_t* const*)m_pFrame->data, m_pFrame->linesize, 0, m_pVideoState->m_pCodecCtx->height, m_pFrameBGR->data, m_pFrameBGR->linesize );
try{
#ifdef USE_QVideoFrame
QVideoFrame *tFrame;
tFrame = new QVideoFrame(m_pFrameBGR->linesize[0] * m_nHeight, QSize(m_nHeight, m_nWidth), m_pFrameBGR->linesize[0], QVideoFrame::Format_BGR24);
memcpy(tFrame->bits(), m_pFrameBGR->data[0], m_pFrameBGR->linesize[0] * m_nHeight);
if (m_pMediaDestination != NULL) m_pMediaDestination->pushFrame(tFrame, m_pOpaque );
#else
#ifdef _OPENCV_
memcpy( mRGB.data, m_pFrameBGR->data[0], m_pFrameBGR->linesize[0] * m_nHeight );
#endif
#ifdef _SDL_
SDL_Surface* mRGB;
mRGB = SDL_CreateRGBSurfaceFrom(
m_pFrameBGR->data[0],
m_nHeight, m_nWidth,
int depth,
Uint32 Rmask,
Uint32 Gmask,
Uint32 Bmask,
Uint32 Amask
);
#endif
if (m_pMediaDestination != NULL) {
m_pMediaDestination->pushFrame( mRGB, m_pOpaque);
} else LOG(">");
#ifdef _OPENCV_
//delete(mRGB);
#endif
#ifdef _SDL_
SDL_FreeSurface(mRGB);
#endif
#endif // !USE_QVideoFrame
} catch (cv::Exception & e) {
LOG_ERROR(e.msg.c_str()); // output exception message
} else {
while( dec_ret >= 0 && m_bThreadStatus != TH_ENDED ) {
dec_ret = avcodec_receive_frame( m_pVideoState->m_pCodecCtx, m_pFrame );
if( dec_ret == AVERROR(EAGAIN) || dec_ret == AVERROR_EOF ){
continue;//Skip to next data
} else if( dec_ret < 0 ){
LOG_ERROR("Error in video decoding");
m_pVideoState->m_bStatus = MS_STOPED;
m_bThreadStatus = TH_ENDED;
break;
};
#ifdef PROCESS_YUV420P
sws_scale( img_convert_ctx, (const uint8_t* const*)m_pFrame->data, m_pFrame->linesize, 0, m_pVideoState->m_pCodecCtx->height, m_pFrameYUV->data, m_pFrameYUV->linesize );
//SDL_UpdateYUVTexture(m_pTexture, &m_oRect, m_pFrameYUV->data[0], m_pFrameYUV->linesize[0], m_pFrameYUV->data[1], m_pFrameYUV->linesize[1], m_pFrameYUV->data[2], m_pFrameYUV->linesize[2]);
m_pMediaDestination->pushFrame( m_pFrameYUV, m_pOpaque );
#else // PROCESS_BGR24
sws_scale( img_convert_ctx, (const uint8_t* const*)m_pFrame->data, m_pFrame->linesize, 0, m_pVideoState->m_pCodecCtx->height, m_pFrameBGR->data, m_pFrameBGR->linesize );
try{
#ifdef USE_QVideoFrame
QVideoFrame *tFrame;
tFrame = new QVideoFrame(m_pFrameBGR->linesize[0] * m_nHeight, QSize(m_nHeight, m_nWidth), m_pFrameBGR->linesize[0], QVideoFrame::Format_BGR24);
memcpy(tFrame->bits(), m_pFrameBGR->data[0], m_pFrameBGR->linesize[0] * m_nHeight);
if (m_pMediaDestination != NULL) m_pMediaDestination->pushFrame(tFrame, m_pOpaque );
#else
#ifdef _OPENCV_
memcpy( mRGB.data, m_pFrameBGR->data[0], m_pFrameBGR->linesize[0] * m_nHeight );
#endif
#ifdef _SDL_
SDL_Surface* mRGB = SDL_CreateRGBSurfaceFrom( m_pFrameBGR->data[0], m_nHeight, m_nWidth, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask );
#endif
m_pMediaDestination->pushFrame( mRGB, m_pOpaque );
#ifdef _SDL_
SDL_FreeSurface(mRGB);
#endif
#ifdef _OPENCV_
//delete(mRGB);
#endif
#endif // !USE_QVideoFrame
} catch (cv::Exception & e) {
LOG_ERROR(e.msg.c_str()); // output exception message
};
#endif
//Unref Frame
//av_freep( m_pFrame->data[0] );
//av_frame_unref( m_pFrame );
};
#endif
};
};
} else {
m_pVideoState->m_bStatus = MS_CLOSED;
m_bThreadStatus = TH_ENDED;
};
} else {
#if ( LIBAVCODEC_VERSION_MAJOR < 58 ) //&& ( LIBAVCODEC_VERSION_MINOR < 50 )
av_free_packet(m_pPacket);
av_free_packet( m_pPacket );
#else
av_packet_unref(m_pPacket);
av_packet_unref( m_pPacket );
#endif
m_pVideoState->m_bStatus = MS_CLOSED;
m_bThreadStatus = TH_ENDED;
};
} else SLEEP( 20 );
};
m_pVideoState->m_bStatus = MS_CLOSED;
m_bThreadStatus = TH_ENDED;
};
/*
JPEG2000 isn't jpeg. To encode JPEG images, use AV_CODEC_ID_MJPEG. MJPEG stands for "motion JPEG", which is how a sequence of JPEG pictures making up a video stream is typically called.
int save_frame_as_jpeg(AVCodecContext *pCodecCtx, AVFrame *pFrame, int FrameNo) {
AVCodec *jpegCodec = avcodec_find_encoder(AV_CODEC_ID_JPEG2000);
if (!jpegCodec) {
return -1;
}
AVCodecContext *jpegContext = avcodec_alloc_context3(jpegCodec);
if (!jpegContext) {
return -1;
}
jpegContext->pix_fmt = pCodecCtx->pix_fmt;
jpegContext->height = pFrame->height;
jpegContext->width = pFrame->width;
if (avcodec_open2(jpegContext, jpegCodec, NULL) < 0) {
return -1;
}
FILE *JPEGFile;
char JPEGFName[256];
AVPacket packet = {.data = NULL, .size = 0};
av_init_packet(&packet);
int gotFrame;
if (avcodec_encode_video2(jpegContext, &packet, pFrame, &gotFrame) < 0) {
return -1;
}
sprintf(JPEGFName, "dvr-%06d.jpg", FrameNo);
JPEGFile = fopen(JPEGFName, "wb");
fwrite(packet.data, 1, packet.size, JPEGFile);
fclose(JPEGFile);
av_free_packet(&packet);
avcodec_close(jpegContext);
return 0;
}
*/
#undef TLOG
#undef TLOG_ERROR
#undef LOG

7
lib/data/ponvif/ponvif.cpp

@ -1790,16 +1790,15 @@ bool pOnvif::_send_request( CSTR url, CSTR post_string, bool mustReturnData ){
if( m_pHttpAccessManager->accomplish( tRC ) ){
parser_done = false;
uint8_t cnt = 200; // TO = 2 second
bool chk = false;
while( !chk && cnt-- ){
chk = parser_done;
while( !RetVal && cnt-- ){
RetVal = parser_done;
SLEEP( 10 );
};
if( chk )RetVal = true;
};
} else {
RetVal = m_pHttpAccessManager->accomplish( tRC );
};
LOG( "->" );
};
m_mResponseProtector.unlock();
};

32
lib/data/protocol/protocolPTZ_ONVIF.cpp

@ -67,14 +67,9 @@ bool protocolPTZ_ONVIF::setPassword( CSTR password ){
bool protocolPTZ_ONVIF::create( void ){
if (!protocolPTZ::create()){
LOG_ERROR("protocolPTZ::create Failure!");
return false;
};
if (!protocolPTZ::create()) return false;
if( m_pSettings!= NULL ) {
config_setting_t *pSetting;
LOG("Reading Settings!");
pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
if (pSetting == NULL) return false;
sprintf( m_pUser, "%s", config_setting_get_string(pSetting));
@ -95,22 +90,20 @@ bool protocolPTZ_ONVIF::create( void ){
#ifdef USE_PONVIF
m_pOnVif = new pOnvif();
if( m_pOnVif == NULL ){
LOG_ERROR("PONVIF NEW FAILURE!");
LOG_ERROR("pOnvif NEW FAILURE!");
return false;
};
m_pOnVif->setDeviceUri( m_pDeviceURI );
m_pOnVif->setUsername( m_pUser );
m_pOnVif->setPassword( m_pPassword );
LOG("PONVIF BEFORE CREATE");
if( m_pOnVif->create() ){
LOG("CREATE OK -> Get Profile");
m_pProfile = m_pOnVif->getProfiles()->at(0);
LOG("Get Profile OK");
return true;
} else {
LOG("PONVIF CREATION ERROR!");
LOG_ERROR("pOnvif CREATE FAILURE!");
delete( m_pOnVif );
m_pOnVif = NULL;
return false;
};
#else
std::string A(m_pUser);
@ -240,29 +233,30 @@ bool protocolPTZ_ONVIF::move( uint32_t MoveMatrix ){
bool protocolPTZ_ONVIF::goAbsolute( float dPan, float dTilt, float dZoom ){
#ifdef USE_PONVIF
//if (m_bStatus == 0) return false;
//LOG("ABS Move");
#ifdef DEBUG_EXTRA
LOG("ABS Move");
#endif
if( m_pProfile == NULL ){
LOG_ERROR("No PTZ Profile!!");
return false;
};
if ( dZoom < 0.0f ) dZoom = 0.0f;
uint8_t TO = 100;
uint8_t TO = 10; // 3.6 second max
if ( m_pOnVif->ptz_AbsoluteMove( m_pProfile->profiletoken, dPan, dTilt, dZoom ) ){
SLEEP(10);
SLEEP( 333 );
ptzStatus tVal;
while( m_pOnVif->ptz_GetStatus( m_pProfile->profiletoken, &tVal ) && TO ) {
if( tVal.hasMoveStatus ) {
//LOG("CHK CAM IDLE");
if( tVal.PanTiltIdle && tVal.ZoomIdle ) break;
} else {
if( ( fabs(tVal.pan - dPan) < 0.0005 ) && ( fabs( tVal.tilt - dTilt) < 0.0005 ) ) break;//&& ( fabs( tVal.zoom - dZoom ) < 0.05 ) ) break;
};
SLEEP(10);
TO --;
SLEEP( 333 );
TO--;
};
if( TO ) {
#ifdef DEBUG
//LOG("Finished Move!");
#ifdef DEBUG_EXTRA
LOG("Finished Move!");
#endif
return true;
} else LOG_ERROR("Error Fetching PTZ Status!");

2
lib/rgoose/rgooseCamera.cpp

@ -800,7 +800,7 @@ bool ARGUS_Camera::connectToStream( uint32_t id ){
free( tDATA );
};
} else {
#ifdef DEBUG_EXTRA
#ifdef DEBUG
LOG("No Video Module!");
#endif
//return true;

208
lib/rgoose/rgooseDBConnector.cpp

@ -1224,7 +1224,7 @@ DBC_INT_LIST *argusDBC::listFilters( uint32_t ServerID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -1259,8 +1259,8 @@ DBC_INT_LIST *argusDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaS
case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=0 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break;
default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
};
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -1299,8 +1299,8 @@ DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
default:
sprintf(tQBuf, "SELECT id FROM media_streams WHERE `site_id`=%d", SiteId );
};
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -1330,7 +1330,7 @@ DBC_INT_LIST *argusDBC::listDetectionProfileIDs( uint32_t nodeID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -1361,7 +1361,7 @@ DBC_INT_LIST *argusDBC::listDetectionProfiles( uint32_t nodeID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -1429,7 +1429,7 @@ DBC_INT_LIST *argusDBC::listResources( uint32_t NodeID ){
} else {
sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `site_id`=%d AND `active`=1", m_nSiteID );
};
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -1471,8 +1471,8 @@ DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_id
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -1501,7 +1501,7 @@ uint32_t argusDBC::getCamId( CSTR UUID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
#ifdef DEBUG_EXTRA
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -1527,8 +1527,8 @@ DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -1694,8 +1694,8 @@ DBC_PUSHED_CMD *argusDBC::getCamPushedCMD( uint32_t ID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `cameras` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -1730,7 +1730,7 @@ DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
#ifdef DEBUG_EXTRA
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -1813,8 +1813,8 @@ DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -1879,7 +1879,7 @@ DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -1934,8 +1934,8 @@ DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -1976,8 +1976,8 @@ DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -2012,47 +2012,47 @@ DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
return tVal;
};
void argusDBC::registerServer(uint32_t SiteID, CSTR identity ){
void argusDBC::registerServer(uint32_t SiteID, CSTR identity, int PID ){
if(m_bIsConnected){
m_nSiteID = SiteID;
char tQBuf[CTEXT];
sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()) ON DUPLICATE KEY UPDATE `ts`=UNIX_TIMESTAMP(now()), `online`=1", SiteID, identity );
#ifdef DEBUG
//LOG(tQBuf);
sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d", SiteID, identity, PID, PID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
// Clenup Nodes and services ...
sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
uint32_t sid = getServerID( identity );
if( sid ) {
sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", m_nSiteID, sid );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
cleanResources( m_nSiteID, sid );
@ -2064,7 +2064,7 @@ void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
if( setNodeOffline( NodeID ) ){
char tQBuf[CTEXT];
sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", ServerID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2076,12 +2076,12 @@ bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
char tQBuf[CTEXT];
if( NodeID ) {
sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2096,12 +2096,12 @@ bool argusDBC::setNodeOffline( uint32_t NodeID ){
char tQBuf[CTEXT];
if( NodeID ) {
sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2116,8 +2116,8 @@ DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -2158,6 +2158,9 @@ uint32_t argusDBC::getResourceID( uint32_t SiteID, uint32_t NodeID, uint8_t type
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `site_id`=%d AND `node_id`=%d AND `type`=%d AND `aux_id`=%d", SiteID, NodeID, type, auxID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
AAssoc *result;
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -2181,7 +2184,7 @@ uint32_t argusDBC::getServerID( CSTR identity ){
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
AAssoc *result;
@ -2207,7 +2210,7 @@ uint32_t argusDBC::getServerNode( uint32_t SID ){
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
AAssoc *result;
@ -2240,8 +2243,8 @@ uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t wid
free( tMD5 );
sprintf( tQBuf, "INSERT INTO media_streams SET `site_id`=%d, `source_id`=0, source_type='A', `valid`=1, `name`='Local Frame Grabber', `token`='%s', `img_width`=%d, `img_height`=%d, `mrl_proto`='v4l2', `mrl_port`='', `picture_proto`='', mrl='%s' ON DUPLICATE KEY UPDATE id=id, `valid`=1, img_width=%d, img_height=%d",
SiteID, tM5, width, height, path, width, height );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
};
@ -2280,7 +2283,7 @@ bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_I
if(m_bIsConnected){
char tQBuf[2048];
sprintf(tQBuf,"INSERT INTO `notifications` SET `site_id`=%d, `ts`=NOW(), `lvl`=%d, `type`=%d, `obj_id`=%d ON DUPLICATE KEY UPDATE `status`='A', `ts`=NOW()", m_nSiteID, DIS_LVL, MSG_ID, OBJ_ID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2297,8 +2300,8 @@ uint32_t argusDBC::addResource( uint32_t SiteID, uint32_t NodeID, uint8_t type,
if( tMD5 ) {
sprintf( tQBuf, "INSERT INTO `resources` SET `site_id`=%d, `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", SiteID, NodeID, type, tMD5, auxID, devName, auxID, devName );
free( tMD5 );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
if( RetVal == 0 ) {
@ -2353,7 +2356,7 @@ CSTR argusDBC::getResourceDevice( uint32_t NodeID, uint32_t Type ){
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf( tQBuf, "SELECT `device` FROM `resources` WHERE `node_id`=%d AND `type`=%d LIMIT 1", NodeID, Type );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
AAssoc *result;
@ -2408,7 +2411,7 @@ KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -2441,7 +2444,7 @@ KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t
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
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
@ -2479,8 +2482,8 @@ DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -2523,6 +2526,9 @@ uint32_t argusDBC::getUartID( uint32_t RessourceID ){
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `resource_id`=%d", RessourceID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
AAssoc *result;
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -2544,9 +2550,6 @@ uint32_t argusDBC::getUartID( uint32_t RessourceID ){
bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
#ifdef DEBUG
LOG("Stream Update");
#endif
if( key == NULL ) {
if( mrl == NULL ) {
sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
@ -2560,7 +2563,7 @@ bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
id
);
};
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2599,7 +2602,7 @@ bool argusDBC::updateServerUtilisation( uint32_t ServerID, uint32_t nCores, floa
mcsize,
ServerID
);
#ifdef DEBUG_EXTRA
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2620,8 +2623,8 @@ uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t
status,
CNT
);
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
uint64_t cid = m_pDatabase->QueryID( tQBuf );
if( cid == 0 ) {
@ -2630,8 +2633,8 @@ uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t
SiteID,
SERIAL
);
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
@ -2660,8 +2663,8 @@ uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t
idx
);
}
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
};
@ -2685,8 +2688,8 @@ uint32_t argusDBC::addLocalUART( uint32_t ResID, uint8_t utype, uint32_t speed,
port,
PATH
);
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
RetVal = m_pDatabase->QueryID( tQBuf );
if( RetVal == 0 ) {
@ -2711,8 +2714,8 @@ uint32_t argusDBC::addLocalNetInterface( CSTR address, CSTR mask, CSTR gateway,
mask,
broadcast
);
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
RetVal = m_pDatabase->QueryID( tQBuf );
if( RetVal == 0 ) {
@ -2734,8 +2737,8 @@ bool argusDBC::addDraw( uint32_t DBID, uint16_t SIZE, CSTR ID ){
ID,
SIZE
);
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
return true;
@ -2780,8 +2783,8 @@ uint32_t argusDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsm
RefUUID
);
};
#ifdef DEBUG
// LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
};
@ -2792,6 +2795,9 @@ bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `events_video_records` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
return true;
};
@ -2803,6 +2809,9 @@ uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `video_records` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
}
return tID;
@ -2814,6 +2823,9 @@ DBC_KRNL_CMD *argusDBC::getActiveCommand( uint32_t SiteID ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM `cmd_queue` WHERE `status`=0 AND `site_id`=%d", SiteID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result != NULL ) {
if( result->size() > 0 ) {
@ -2851,6 +2863,9 @@ bool argusDBC::updateCommand( uint32_t CMD_ID, uint8_t STATUS ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "UPDATE `cmd_queue` SET `status`=%d WHERE id=%d", STATUS, CMD_ID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
return true;
};
@ -2888,7 +2903,7 @@ bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, boo
lrfID,
profileID );
};
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2904,7 +2919,7 @@ bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
if( tES ) {
sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
free( tES );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2920,7 +2935,7 @@ bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
if( tES ) {
sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
free( tES );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2934,7 +2949,7 @@ bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2947,7 +2962,7 @@ bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2959,7 +2974,7 @@ bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2971,7 +2986,19 @@ bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
return true;
};
return false;
};
bool argusDBC::setStreamValid( uint32_t streamID ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
@ -2979,7 +3006,6 @@ bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
};
return false;
};
bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
@ -2989,8 +3015,8 @@ bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, floa
x,y,z,
x,y,z
);
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
return true;
@ -3004,20 +3030,15 @@ DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM `module_embed_video_settings` WHERE `id`=%d", ID );
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
LOG("Q is issued");
if( result!= NULL ) {
LOG("Result NN");
if( result->size() > 0 ) {
LOG("Result CNT");
Assoc *cArr;
tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
LOG("Result ALLOC");
if( tPtr!= NULL ) {
LOG("Result ALLOC OK");
Assoc::iterator it;
memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
cArr = result->at(0);
@ -3129,7 +3150,6 @@ DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
};
};
};
LOG("Del Result");
deleteResult( result );
};
return tPtr;
@ -3141,8 +3161,8 @@ DBC_EVT_DATA *argusDBC::getEventByUUID( CSTR UUID ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
#ifdef DEBUG
//LOG(tQBuf);
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {

4
lib/rgoose/rgooseDBConnector.h

@ -104,7 +104,7 @@ class argusDBC{
void registerServer(uint32_t SiteID, CSTR identity );
void registerServer(uint32_t SiteID, CSTR identity, int PID );
void unregisterServer(uint32_t ServerID, uint32_t NodeID );
bool transferEvtToArchive( uint32_t SECONDS = ONE_DAY_HISTORY );
@ -118,7 +118,7 @@ class argusDBC{
bool setLRFDataStatus( uint32_t lrfID, uint8_t ST );
bool setLRFAltSerial( uint32_t lrfID, CSTR Serial );
bool setLRFAltVerison( uint32_t lrfID, CSTR version );
bool setStreamValid( uint32_t streamID );
bool updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z );
bool updateCommand( uint32_t CMD_ID, uint8_t STATUS );
bool updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr );

4
lib/rgoose/rgooseHardwareManager.cpp

@ -40,7 +40,7 @@ argusHardwareManager::argusHardwareManager( bool cold_start ){
m_nServerNodeID = 0;
m_nServerID = 0;
m_nSiteID = 0;
m_nMemoryLimitHeapSize = 52428800; // 50 MB //524288000; //500 MB ~ 1 Hour
m_nMemoryLimitHeapSize = 524288000; // 50 MB //524288000; //500 MB ~ 1 Hour
m_pKernel = argusKernel::getInstance();
if( m_pKernel == NULL ){
LOG_ERROR( "Failure to get Kernel Instance!" );
@ -167,7 +167,7 @@ bool argusHardwareManager::validate( void ){
//Mem Validator
if( m_nMemoryLimitHeapSize ) {
size_t memStat = getCurrentRSS();
#ifdef DEBUG
#ifdef DEBUG_EXTRA
char MEM_MSG[128];
sprintf( MEM_MSG, "MEM: %d TARG: %d", memStat, m_nMemoryLimitHeapSize );
LOG( MEM_MSG );

126
lib/rgoose/rgooseKernel.cpp

@ -65,47 +65,44 @@ argusKernel::argusKernel( bool cold_start, config_setting_t *Settings ):basicTh
};
argusKernel::~argusKernel(){
WaitFinish( true );
#ifdef DEBUG
LOG("Destructor");
LOG(" Deleting Node Factory...");
#endif
WaitFinish(true);
if( m_pNodeFactory != NULL ) delete( m_pNodeFactory );
#ifdef DEBUG
LOG(" Module Factory...");
LOG(" Deleting Module Factory...");
#endif
if( m_pModuleFactory != NULL ) delete( m_pModuleFactory );
#ifdef DEBUG
LOG(" Node Factory...");
#endif
if( m_pNodeFactory != NULL ) delete( m_pNodeFactory );
#ifdef DEBUG
LOG("Deleting Filters");
LOG(" Deleting Target Filters...");
#endif
unloadFilters();
/*
#ifdef DEBUG
LOG("Deleting Resources");
#endif
m_pHardwareManager->unloadResources();
*/
if( m_bExitCause == 0 ) {
#ifdef DEBUG
LOG("Unregister Server");
#endif
m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID );
LOG(" DataBase Connection...");
#ifdef DEBUG
LOG("Close DataBase Connection...");
#endif
if( m_pDBC != NULL ) delete( m_pDBC );
m_pDBC = NULL;
} else {
if( m_bExitCause == 4 ) {
#ifdef DEBUG
LOG("HW PNP Detection Requested...");
#endif
m_pHardwareManager->enumerateHardware();
};
};
_instance = NULL;
#ifdef DEBUG
LOG("Destructor Finished");
LOG("Close DataBase Connection...");
#endif
if( m_pDBC != NULL ) delete( m_pDBC );
m_pDBC = NULL;
};
_instance = NULL;
};
bool argusKernel::create( void ){
@ -114,7 +111,6 @@ bool argusKernel::create( void ){
config_setting_t * pSetting;
int tVal;
const char * tBuf;
//Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
LOG("Getting Settings ...");
if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
char * tVar;
@ -166,7 +162,7 @@ bool argusKernel::create( void ){
#ifdef DEBUG
LOG( "Settings Read Done" );
#endif
m_pDBC->registerServer( m_nSiteID, m_sIdentity );
m_pDBC->registerServer( m_nSiteID, m_sIdentity, getpid() );
m_nServerID = m_pDBC->getServerID( m_sIdentity );
m_nServerNodeID = m_pDBC->getServerNode( m_nServerID );
@ -190,12 +186,23 @@ bool argusKernel::create( void ){
return false;
};
//m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
if( basicSettingsProvider::getInstance()->isCompromised() ) {
basicSettingsProvider::getInstance()->validate();
};
basicSettingsProvider::getInstance()->validate();
m_pEventHeap = basicEventHeap::getInstance();
m_pModuleFactory = argusModuleFactory::getInstance( m_nServerID );
if( !m_pModuleFactory ) {
LOG_ERROR("Failure to get Module Factory Instance!");
return false;
}
#ifdef DEBUG
else {
LOG( "Module Factory Created" );
}
#endif
;
#ifdef DEBUG
LOG( "Load Filters" );
#endif
@ -204,46 +211,19 @@ bool argusKernel::create( void ){
LOG( "Filters Loaded" );
#endif
m_pNodeFactory = argusNodeFactory::getInstance();
if( m_pNodeFactory ) {
#ifdef DEBUG
LOG( "Load Nodes" );
#endif
if( !m_pNodeFactory->loadNodes( m_nSiteID ) ){
LOG_ERROR("Error While Loading Nodes!");
}
#ifdef DEBUG
else {
LOG( "Nodes Loaded" );
}
#endif
;
} else {
LOG_ERROR("Failure to get Node Factory Instance!");
return false;
};
m_pNodeFactory = argusNodeFactory::getInstance( m_nSiteID );
m_pModuleFactory = argusModuleFactory::getInstance();
if( m_pModuleFactory ) {
#ifdef DEBUG
LOG( "Load Modules" );
#endif
if( !m_pModuleFactory->loadModules( m_nServerID ) ){
LOG_ERROR("Error While Loading Modules!");
}
if( !m_pNodeFactory ) {
LOG_ERROR("Failure to get Node Factory Instance!");
return false;
}
#ifdef DEBUG
else {
LOG( "Modules Loaded" );
}
else {
LOG( "Node Factory Created" );
}
#endif
;
} else {
LOG_ERROR("Failure to get Module Factory Instance!");
return false;
};
;
#ifdef DEBUG
LOG( "Kernel Trhead is about to be Created" );
@ -252,6 +232,7 @@ bool argusKernel::create( void ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Kernel Thread Created" );
sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
@ -316,11 +297,15 @@ void argusKernel::unloadFilters(){
};
m_vTargetFilters.clear();
LOG("Unload Filters Done!");
} else {
}
#ifdef DEBUG
else {
LOG("No Filters to Unload!");
#endif
}
#endif
;
};
ARGUS_TARGET_FILTER *argusKernel::getFilter( uint32_t id ){
@ -339,16 +324,14 @@ ARGUS_TARGET_FILTER *argusKernel::getFilter( uint32_t id ){
void argusKernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Thread End Forced" );
LOG( "Forced Exit" );
#endif
} else {
// 3 seconds sleep to settle down processes
SLEEP(3000);
};
waitThreadEnd( Force );
#ifdef DEBUG
if( !Force ) LOG( "Thread is Detached" );
LOG( "Start Waiting for Thread to End (usually at MAIN)." );
#endif
};
waitThreadEnd( Force );
};
/* Main Kernel Thread Procedure */
@ -358,9 +341,8 @@ void argusKernel::m_fThreadProc( void ){
int lastTSS = 0;
int lastTMS = 0;
DBC_EVT_DATA * tEvtPtr;
pid_t pid = gettid();
char pidBuf[16];
sprintf(pidBuf,"KERNEL pid:%d", pid);
char pidBuf[16];
sprintf(pidBuf,"pid: %d tid: %d", getpid(), gettid() );
LOG( pidBuf );
#ifdef SIMULATE_KERNEL_TARGETS
LOG("SIMULATION ENABLED");

3
lib/rgoose/rgooseModule.cpp

@ -3,7 +3,6 @@
argusKernelModule::argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param ): basicEventHandler(), basicObject(){
m_pLog = basicLogCollection::getInstance();
m_pLog->Log( "KMODULE", this, "Constructor Begin" );
m_pDBC = argusDBC::getInstance();
m_pKernel = argusKernel::getInstance();
m_eType = param;
@ -23,10 +22,8 @@ argusKernelModule::argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param ): ba
};
};
for( int i = 0; i < EVT_COUNT; i++ ) m_bEvtFlags[i] = false;
m_pLog->Log( "KMODULE", this, "Constructor End" );
};
argusKernelModule::~argusKernelModule(){
};

289
lib/rgoose/rgooseModuleEmbedVideo.cpp

@ -59,42 +59,36 @@ static const char* kRequestPaths[] = { "/stream", "/sign_in", "/wait", "/sign_ou
//buffer_data bd[1]={0};
argusModuleEmbedVideo::argusModuleEmbedVideo( uint32_t moduleID ): argusKernelModule( moduleID, ARGUS_MODULE_EMBED_VIDEO ), basicMediaDestination(), basicThread(){
LOG( "Begin C" );
m_pEventHeap = basicEventHeap::getInstance();
LOG( "Evt Heap" );
if( m_pDBC ){
LOG( "DB OK!" );
DBC_MODULE_EMBED_VIDEO_DATA *tDATA = m_pDBC->getEmbedVideoData( m_nDBAUXID );
LOG( "Query DB!" );
if( tDATA ) {
LOG( "Data fetched from DB!" );
memcpy( &m_sEmbedVideoData, tDATA, sizeof(DBC_MODULE_EMBED_VIDEO_DATA) );
free( tDATA );
} else {
LOG( "No Data fetched from DB!" );
memset( &m_sEmbedVideoData, 0, sizeof(DBC_MODULE_EMBED_VIDEO_DATA) );
m_sEmbedVideoData.port = 8972;
};
} else {
LOG_ERROR( "DB Error!" );
};
LOG( "DB data" );
n_pNoSignalData = NULL;
m_nNoSignalSize = 0;
#ifdef DEBUG
char tB[64];
sprintf( tB, "Web Streams Port: %d", m_sEmbedVideoData.port );
LOG( tB );
sprintf( tB, "Frame: [%dx%d]", m_sEmbedVideoData.width, m_sEmbedVideoData.height );
LOG( tB );
n_pNoSignalData = NULL;
m_nNoSignalSize = 0;
LOG( tB );
if( m_sEmbedVideoData.show_ts ) LOG("Show TimeStamp");
if( m_sEmbedVideoData.show_label ) LOG("Show Label");
if( m_sEmbedVideoData.show_logo ) LOG("Show Logo");
#endif
if( m_sEmbedVideoData.show_logo ){
LOG("Show Logo");
LOG( m_sEmbedVideoData.logo_md5 );
char tPath[256];
sprintf( tPath, "data/assets/images/%s.png", m_sEmbedVideoData.logo_md5);
if(!fileExist(tPath)){
char tPath[MAX_PATH];
sprintf( tPath, "data/assets/images/%s.png", m_sEmbedVideoData.logo_md5 );
if( !fileExist( tPath ) ){
LOG_ERROR("Logo File Missed!");
m_sEmbedVideoData.show_logo = false;
}
@ -103,43 +97,44 @@ argusModuleEmbedVideo::argusModuleEmbedVideo( uint32_t moduleID ): argusKernelMo
#endif
;
};
LOG( "End C" );
};
argusModuleEmbedVideo::~argusModuleEmbedVideo(){
if( !m_bDetached ) stopService( true );
if( n_pNoSignalData ) free( n_pNoSignalData );
m_bEnabled = false;
stopService();
};
static const char * ht_head = "HTTP/1.1 200 OK\r\n"
"Cache-Control: no-store, no-cache, post-check=0, pre-check=0\r\n"
"Pragma: no-cache\r\n"
"MIME-version: 1.0\r\n"
"Connection: close\r\n"
//"Keep-Alive: timeout=5, max=1\r\n"
//"Connection: Keep-Alive\r\n"
//"Content-Type: video/mp4\r\n"
"Content-Transfer-Encoding: BINARY\r\n"
//"Transfer-Encoding: chunked\r\n"
"Content-type: multipart/x-mixed-replace;boundary=MPFrame\r\n"
"\r\n";
static const char * ht_abort = "HTTP/1.1 404 OK\r\n"
"Cache-Control: no-store, no-cache, post-check=0, pre-check=0\r\n"
"Pragma: no-cache\r\n"
"Connection: close\r\n\r\n";
static const char * ht_no_signal = "HTTP/1.1 200 OK\r\n"
"MIME-version: 1.0\r\n"
"Connection: close\r\n"
"Content-Transfer-Encoding: BINARY\r\n"
//"Content-type: multipart/x-mixed-replace;boundary=MPFrame\r\n\r\n"
"Content-Type: image/jpeg\r\nContent-length: %d\r\n\r\n";
void *argusModuleEmbedVideo::webClientProc( void *ptr ){
static char *head = "HTTP/1.1 200 OK\r\n"
"Cache-Control: no-store, no-cache, post-check=0, pre-check=0\r\n"
"Pragma: no-cache\r\n"
"MIME-version: 1.0\r\n"
"Connection: close\r\n"
//"Keep-Alive: timeout=5, max=1\r\n"
//"Connection: Keep-Alive\r\n"
//"Content-Type: video/mp4\r\n"
"Content-Transfer-Encoding: BINARY\r\n"
//"Transfer-Encoding: chunked\r\n"
"Content-type: multipart/x-mixed-replace;boundary=MPFrame\r\n"
"\r\n";
static char *abort = "HTTP/1.1 404 OK\r\n"
"Cache-Control: no-store, no-cache, post-check=0, pre-check=0\r\n"
"Pragma: no-cache\r\n"
"Connection: close\r\n\r\n";
static char *no_signal ="HTTP/1.1 200 OK\r\n"
"MIME-version: 1.0\r\n"
"Connection: close\r\n"
"Content-Transfer-Encoding: BINARY\r\n"
//"Content-type: multipart/x-mixed-replace;boundary=MPFrame\r\n\r\n"
"Content-Type: image/jpeg\r\nContent-length: %d\r\n\r\n";
WEB_CLIENT_CTX * CTX = (WEB_CLIENT_CTX *) ptr;
argusModuleEmbedVideo * MODULE = CTX->ModulePtr;
uint32_t msgSize;
uint8_t tBuf[FILESTREAMBUFFERSZ];
int retVal;
uint32_t msgSize;
uint8_t tBuf[FILESTREAMBUFFERSZ];
int retVal;
if( CTX ) {
char mesg[1024];
@ -211,100 +206,6 @@ void *argusModuleEmbedVideo::webClientProc( void *ptr ){
TLOG( cGetURI );
#endif
};
// parse rest of request
while( ( reqline[++index] = strtok( NULL, "\n" ) )!= NULL ) {
if( strncmp( reqline[index], "Connection:", 11 ) == 0 ) {
char * pPart;
pPart = strcasestr( reqline[index], "Upgrade" );
if( pPart != NULL ) {
#ifdef DEBUG_EXTRA
TLOG("Upgrade Mode ON");
#endif
//bUpgradeMode = true;
};
};
if( strncmp( reqline[index], "Upgrade:", 8 ) == 0 ) {
/*
if( bUpgradeMode ) {
char * pPart;
pPart = strcasestr( reqline[index], "websocket" );
if( pPart != NULL ) {
TLOG("WebSocket Mode ON");
//bWebSocketMode = true;
};
};
*/
};
if( strncmp( reqline[index], "Sec-WebSocket-Version:", 22 ) == 0 ) {
char * pPart;
pPart = strstr( reqline[index], " " );
if( pPart != NULL ) {
char tBuf[CTEXT];
//nWebSocketVersion = atoi(pPart+1);
#ifdef DEBUG_EXTRA
sprintf( tBuf,"Web Socket Version: %d", 0 );//nWebSocketVersion );
TLOG( tBuf );
#endif
};
};
if( strncmp( reqline[index], "Sec-WebSocket-Key:", 18 ) == 0 ) {
/*char * pPart;
pPart = strstr( reqline[index], " " );
if( pPart != NULL ) {
char tGenStr[256];
unsigned char * tBase64;
size_t nBase64;
int kLen;
unsigned char hash[SHA_DIGEST_LENGTH]; // == 20
pPart++;
kLen = strstr(pPart,"\r") - pPart;
strncpy(cWSKey,pPart,kLen);
cWSKey[kLen]=(char)0;
TLOG( cWSKey );
sprintf( tGenStr, "%s%s", cWSKey, ws_guid );
SHA1( (const unsigned char*)tGenStr, strlen(tGenStr), hash );
tBase64 = base64_encode( hash, SHA_DIGEST_LENGTH, &nBase64 );
strncpy( cWSRep, (const char*)tBase64, nBase64 );
free( tBase64 );
cWSRep[nBase64] = (char)0;
TLOG( cWSRep );
};
*/
};
if( strncmp( reqline[index], "Sec-WebSocket-Protocol:", 23 ) == 0 ) {
char * pPart;
pPart = strstr( reqline[index], " " );
if( pPart != NULL ) {
// Check for protos
};
};
if( strncmp( reqline[index], "Sec-WebSocket-Extensions:", 25 ) == 0 ) {
char * pPart;
pPart = strstr( reqline[index], " " );
if( pPart != NULL ) {
pPart++;
if(strncmp( pPart, "permessage-deflate", 18 ) == 0 ) {
m_bDeflatePerMessage = true;
#ifdef DEBUG_EXTRA
TLOG("Using Deflate");
#endif
};
};
};
if( strncmp( reqline[index],"Accept-Encoding:", 16 ) == 0 ){
char * pPart;
pPart = strstr( reqline[index], " " );
if( pPart != NULL ) {
pPart++;
if(strncmp( pPart, "gzip, deflate", 13 ) == 0 ) {
m_bDeflatePerMessage = true;
#ifdef DEBUG_EXTRA
TLOG("Using Deflate");
#endif
};
};
};
};
if( strncmp( cGetURI, "/stream", 7 ) == 0 ) {
uint32_t tStreamID = 0;
@ -324,7 +225,7 @@ void *argusModuleEmbedVideo::webClientProc( void *ptr ){
#endif
if( CTX->ModulePtr->registerForMediaStream( tStreamID, CTX ) ){
// Send Header
if( send( CTX->m_iSocketFID, head, strlen(head), 0 ) < 0 ){
if( send( CTX->m_iSocketFID, ht_head, strlen(ht_head), 0 ) < 0 ){
sprintf( mesg, "Failed sending file to client: %s", strerror(errno));
TLOG_ERROR(mesg);
CTX->bValid = false;
@ -343,7 +244,8 @@ void *argusModuleEmbedVideo::webClientProc( void *ptr ){
;
};
if( CTX->ModulePtr->n_pNoSignalData ) {
sprintf( mesg, no_signal, CTX->ModulePtr->m_nNoSignalSize );
//Send Dummy Picture
sprintf( mesg, ht_no_signal, CTX->ModulePtr->m_nNoSignalSize );
send( CTX->m_iSocketFID, mesg, strlen(mesg), 0 );
send( CTX->m_iSocketFID, CTX->ModulePtr->n_pNoSignalData, CTX->ModulePtr->m_nNoSignalSize, 0 );
send( CTX->m_iSocketFID, "\r\n\r\n", 4, 0 );
@ -352,7 +254,7 @@ void *argusModuleEmbedVideo::webClientProc( void *ptr ){
#endif
} else {
// Send 404 Header
send( CTX->m_iSocketFID, abort, strlen(abort), 0 );
send( CTX->m_iSocketFID, ht_abort, strlen(ht_abort), 0 );
#ifdef DEBUG_EXTRA
TLOG("Aborted!");
#endif
@ -371,42 +273,43 @@ void *argusModuleEmbedVideo::webClientProc( void *ptr ){
continue;
};
//uint8_t *tBuf = (uint8_t *) malloc(msgSize);
//if( tBuf ){
retVal = read( CTX->m_iEncoderPipe[0], tBuf, msgSize );
if( retVal == -1 ){
//free( tBuf );
if( errno == EAGAIN || errno == EWOULDBLOCK ){
continue;
};
TLOG_ERROR("Pipe Communication Error[2]!");
CTX->bValid = false;
continue;
};
sprintf( mesg, "--MPFrame\r\nContent-type: image/jpeg\r\nContent-length: %d\r\n\r\n", msgSize );
if( send( CTX->m_iSocketFID, mesg, strlen( mesg ), 0 )< 0 ){
sprintf( mesg, "[1]Failed sending file to client: %s", strerror(errno));
TLOG_ERROR(mesg);
CTX->bValid = false;
continue;
};
if( send( CTX->m_iSocketFID, tBuf, msgSize, 0 ) < 0 ){
sprintf( mesg, "[2]Failed sending file to client: %s", strerror(errno));
TLOG_ERROR(mesg);
CTX->bValid = false;
continue;
};
if( send( CTX->m_iSocketFID, "\r\n\r\n", 4, 0 )< 0 ){
sprintf( mesg, "[3]Failed sending file to client: %s", strerror(errno));
TLOG_ERROR(mesg);
CTX->bValid = false;
if( msgSize < FILESTREAMBUFFERSZ ) {
retVal = read( CTX->m_iEncoderPipe[0], tBuf, msgSize );
} else {
//Read Some Data or Abort Whole Thing
//retVal = read( CTX->m_iEncoderPipe[0], tBuf, FILESTREAMBUFFERSZ );
TLOG_ERROR("Data too Big in Pipe Transfer!");
CTX->bValid = false;
continue;
};
if( retVal == -1 ){
//free( tBuf );
if( errno == EAGAIN || errno == EWOULDBLOCK ){
continue;
};
// free( tBuf );
//} else {
// TLOG_ERROR("Mem Alloc Error!");
// CTX->bValid = false;
//};
TLOG_ERROR("Pipe Communication Error[2]!");
CTX->bValid = false;
continue;
};
sprintf( mesg, "--MPFrame\r\nContent-type: image/jpeg\r\nContent-length: %d\r\n\r\n", msgSize );
if( send( CTX->m_iSocketFID, mesg, strlen( mesg ), 0 )< 0 ){
sprintf( mesg, "[1]Failed sending file to client: %s", strerror(errno));
TLOG_ERROR(mesg);
CTX->bValid = false;
continue;
};
if( send( CTX->m_iSocketFID, tBuf, msgSize, 0 ) < 0 ){
sprintf( mesg, "[2]Failed sending file to client: %s", strerror(errno));
TLOG_ERROR(mesg);
CTX->bValid = false;
continue;
};
if( send( CTX->m_iSocketFID, "\r\n\r\n", 4, 0 )< 0 ){
sprintf( mesg, "[3]Failed sending file to client: %s", strerror(errno));
TLOG_ERROR(mesg);
CTX->bValid = false;
continue;
};
};
};
};
@ -546,6 +449,7 @@ void argusModuleEmbedVideo::m_fThreadProc( void ){
bool argusModuleEmbedVideo::startService(){
m_bEnabled = true;
//Create NoSignal Image
cv::Mat tMat( m_sEmbedVideoData.height, m_sEmbedVideoData.width, CV_8UC3 );
cv::rectangle( tMat, cv::Point( 0, 0 ), cv::Point( m_sEmbedVideoData.width, m_sEmbedVideoData.height ), cv::Scalar( 255, 0, 0 ), cv::FILLED );
@ -648,20 +552,33 @@ bool argusModuleEmbedVideo::startService(){
LOG("Listen OK");
};
LOG("Start Thread");
return init();
m_bEnabled = init();
return m_bEnabled;
};
bool argusModuleEmbedVideo::stopService( bool force ){
m_bEnabled = false;
waitThreadEnd( true );
if( m_vThreads.size() ) { // Kill-Wait Started Probes
#ifdef DEBUG
LOG("Have to Wait Client Handlers!");
LOG("Service Thread ended!");
#endif
if( m_vHandlersPool.size() ) { // Kill-Wait Started Probes
#ifdef DEBUG
char tB[200];
sprintf(tB, "Have to Wait Client Handlers[%d]!", m_vHandlersPool.size() );
LOG( tB );
#endif
for( vectorHANDLERS::iterator index = m_vHandlersPool.begin(); index < m_vHandlersPool.end(); index++ ) {
if( force ) {
#ifdef DEBUG
LOG("Force Client Handler to Stop!");
#endif
pthread_cancel( (*index)->m_hThreadHandle );
} else {
#ifdef DEBUG
LOG("Waiting Client Handler to End!");
#endif
pthread_join( (*index)->m_hThreadHandle, NULL );
}
};
@ -670,17 +587,8 @@ bool argusModuleEmbedVideo::stopService( bool force ){
#ifdef DEBUG
LOG("No More Client Handlers!");
#endif
if (m_vResultPool.size()){ // Clear structures
for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
free(*index);
};
m_vResultPool.clear();
};
#ifdef DEBUG
LOG("Data is Cleared!");
#endif
*/
return true;
m_bDetached = true;
return m_bDetached;
};
bool argusModuleEmbedVideo::reloadSettings(){
@ -704,7 +612,8 @@ void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){
if( tMD ) {
float mK, oK;
cv::Rect ROI;
if( !m_mPictureProtector.try_lock() ) return;
//if( !m_mPictureProtector.try_lock() ) return;
m_mPictureProtector.lock();
oK = ((float)m_sEmbedVideoData.height )/ ((float)m_sEmbedVideoData.width);
mK = ((float)Frame.rows )/ ((float)Frame.cols);
//sprintf( tBuffer, "INP: [%dx%d] IK:%0.3f OK:%0.3f", Frame.cols, Frame.rows, mK, oK );

192
lib/rgoose/rgooseModuleFactory.cpp

@ -14,27 +14,30 @@
#define LOG( X ) m_pLog->Log( "MFAC", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "MFAC", this, _LOG_ERROR, X )
argusModuleFactory * argusModuleFactory::_instance = 0;
argusModuleFactory * argusModuleFactory::_instance = NULL;
/**
* Returns the single instance of the object.
*/
argusModuleFactory* argusModuleFactory::getInstance() {
// check if the instance has been created yet
if (0 == _instance) {
// if not, then create it
_instance = new argusModuleFactory;
}
// return the single instance
argusModuleFactory* argusModuleFactory::getInstance( uint32_t ServerID ) {
if( NULL == _instance) {
if( ServerID ) {
_instance = new argusModuleFactory( ServerID );
};
};
return _instance;
};
argusModuleFactory::argusModuleFactory(){
argusModuleFactory::argusModuleFactory( uint32_t ServerID ):basicThread(){
m_nServerID = ServerID;
m_pLog = basicLogCollection::getInstance();
m_pDBC = argusDBC::getInstance();
init();
};
argusModuleFactory::~argusModuleFactory(){
shutdownServices();
waitThreadEnd( true );
shutdownServices( true );
_instance = NULL;
};
@ -42,10 +45,24 @@ void argusModuleFactory::shutdownServices( bool force ){
#ifdef DEBUG
LOG("shutdownServices");
#endif
m_mModulesProtector.lock();
if( m_vKernelModules.size() > 0 ){
for( vectorKernelModules::iterator index = m_vKernelModules.begin(); index < m_vKernelModules.end(); index++ ){
#ifdef DEBUG
LOG("Stop Service of Module");
char tB[128];
switch( (*index)->getType() ){
case ARGUS_MODULE_ZLMEDIA: sprintf( tB, "Stop Service of ZlMedia Module" ); break;
case ARGUS_MODULE_DCBUSB: sprintf( tB, "Stop Service of DCUSB Module" ); break;
case ARGUS_MODULE_KAFKA: sprintf( tB, "Stop Service of KAFKA Module" ); break;
case ARGUS_MODULE_GPS: sprintf( tB, "Stop Service of GPS Module" ); break;
case ARGUS_MODULE_NETWORK: sprintf( tB, "Stop Service of Network Module" ); break;
case ARGUS_MODULE_FLYHUNTER: sprintf( tB, "Stop Service of FlyHunter Module" ); break;
case ARGUS_MODULE_SSDP_ANONCE: sprintf( tB, "Stop Service of SSDP Module" ); break;
case ARGUS_MODULE_ONVIF_OBSERVER: sprintf( tB, "Stop Service of OnVif Observer Module" ); break;
case ARGUS_MODULE_EMBED_VIDEO: sprintf( tB, "Stop Service of EmbedVideo Module" ); break;
default: sprintf( tB, "Stop Service of UNKNOWN[%d] Module", (*index)->getType() ); break;
};
LOG( tB );
#endif
(*index)->stopService( force );
#ifdef DEBUG
@ -58,6 +75,7 @@ void argusModuleFactory::shutdownServices( bool force ){
};
m_vKernelModules.clear();
};
m_mModulesProtector.unlock();
#ifdef DEBUG
LOG("Done shutdownServices");
#endif
@ -150,7 +168,9 @@ argusKernelModule *argusModuleFactory::createModule( int id ){
};
if( tVal != NULL ){
tVal->startService();
m_mModulesProtector.lock();
m_vKernelModules.push_back( tVal );
m_mModulesProtector.unlock();
};
return tVal;
};
@ -170,20 +190,24 @@ void argusModuleFactory::deleteModule( argusKernelModule *M ){
};
void argusModuleFactory::deleteModule( int id ){
m_mModulesProtector.lock();
if( m_vKernelModules.size() > id ) {
deleteModule( m_vKernelModules.at( id ) );
m_vKernelModules.erase( m_vKernelModules.begin() + id );
m_vKernelModules.shrink_to_fit();
};
m_mModulesProtector.unlock();
};
uint32_t argusModuleFactory::getModulesCount( ARGUS_MODULE_TYPE t ){
uint32_t cnt = 0;
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
for( int i=0; i < m_vKernelModules.size(); i++ ) {
if( m_vKernelModules.at(i)->getType() == t ) cnt++;
};
};
m_mModulesProtector.unlock();
return cnt;
};
@ -193,6 +217,7 @@ uint32_t argusModuleFactory::fetchModules( ARGUS_MODULE_TYPE t, argusKernelModul
if( cnt > 0 ) {
RA = ( argusKernelModule** ) calloc( cnt, sizeof( argusKernelModule* ) );
if( RA!= NULL ) {
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
uint32_t idx = 0;
for( int i=0; i < m_vKernelModules.size(); i++ ) {
@ -202,6 +227,7 @@ uint32_t argusModuleFactory::fetchModules( ARGUS_MODULE_TYPE t, argusKernelModul
};
};
};
m_mModulesProtector.unlock();
} else cnt = 0;
};
return cnt;
@ -209,6 +235,7 @@ uint32_t argusModuleFactory::fetchModules( ARGUS_MODULE_TYPE t, argusKernelModul
argusKernelModule *argusModuleFactory::getModule( uint32_t id ){
argusKernelModule *RetVal = NULL;
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){
if( (*idx)->getId() == id ) {
@ -217,11 +244,13 @@ argusKernelModule *argusModuleFactory::getModule( uint32_t id ){
};
};
};
m_mModulesProtector.unlock();
return RetVal;
};
argusKernelModule *argusModuleFactory::getModule( ARGUS_MODULE_TYPE t, uint32_t id ){
argusKernelModule *RetVal = NULL;
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){
if( id ){
@ -237,88 +266,105 @@ argusKernelModule *argusModuleFactory::getModule( ARGUS_MODULE_TYPE t, uint32_t
};
};
};
m_mModulesProtector.unlock();
return RetVal;
};
void argusModuleFactory::validate( void ){
if(m_pDBC == NULL) return;
DBC_INT_LIST *tList = NULL;
bool argusModuleFactory::validate( void ){
return ( m_bThreadStatus < TH_ENDED );
};
void argusModuleFactory::m_fThreadProc( void ){
if( m_pDBC == NULL) {
m_bThreadStatus = TH_ENDED;
} else {
DBC_INT_LIST *tList = NULL;
#ifdef MEM_DEBUG
size_t memStart, memEnd, memDiff;
char MEM_MSG[256];
memStart = getCurrentRSS();
size_t memStart, memEnd, memDiff;
char MEM_MSG[256];
#endif
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( m_nServerID, &tL );
tL.clear();
} else {
tList = m_pDBC->listNewModules( m_nServerID, NULL );
};
if( tList != NULL ) {
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( m_nServerID, &tL );
tL.clear();
} else {
tList = m_pDBC->listNewModules( m_nServerID, NULL );
};
m_mModulesProtector.unlock();
if( tList != NULL ) {
#ifdef DEBUG
LOG("New Modules Exists!");
LOG("New Modules Exists!");
#endif
for( int index=0; index< tList->size(); index++) createModule(tList->at(index));
tList->clear();
delete( tList );
};
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 );
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
if( m_vKernelModules.size() ) {
//Get Full List
//tList = NULL;
tList = m_pDBC->listModules( m_nServerID );
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;
m_mModulesProtector.lock();
if( m_vKernelModules.size() ) {
//Get Full List
//tList = NULL;
tList = m_pDBC->listModules( m_nServerID );
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 );
};
};
};
if( !tRemoved ) {
// validate module
m_vKernelModules.at( cm )->validate();
cm++;
tList->clear();
delete( tList );
} else {
#ifdef DEBUG
LOG("Delete Module!");
LOG("All Modules Must be Deleted!");
#endif
deleteModule( cm );
while( m_vKernelModules.size() ) deleteModule( 0 );
};
};
tList->clear();
delete( tList );
} else {
#ifdef DEBUG
LOG("All Modules Must be Deleted!");
#endif
while( m_vKernelModules.size() ) deleteModule( 0 );
};
} else {
} else {
#ifdef DEBUG
LOG("No Modules to Validate!");
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 );
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
for( int i = ( 5000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
};
};
//--enable-gpl --enable-libx264 --enable-nonfree --extra-ldflags=-latomic --enable-omx --enable-omx-rpi
//-rtsp_transport tcp
#undef LOG
#undef LOG_ERROR

16
lib/rgoose/rgooseModuleFactory.h

@ -3,30 +3,34 @@
#include <vector>
#include "rgooseModule.h"
#include "../components/base/basicThread.h"
#include "../components/base/basicMutex.h"
typedef std::vector<argusKernelModule*> vectorKernelModules;
class argusModuleFactory{
class argusModuleFactory: public basicThread{
private:
basicLogCollection * m_pLog;
argusDBC * m_pDBC;
uint32_t m_nServerID;
vectorKernelModules m_vKernelModules;
basicMutex m_mModulesProtector;
void deleteModule( argusKernelModule * );
public:
static argusModuleFactory * getInstance();
static argusModuleFactory * getInstance( uint32_t ServerID = 0 );
virtual ~argusModuleFactory();
argusKernelModule * createModule( int id );
void deleteModule( argusKernelModule * );
argusKernelModule * createModule( int id );
void deleteModule( int id );
argusKernelModule * getModule( uint32_t id );
argusKernelModule * getModule( ARGUS_MODULE_TYPE t, uint32_t id = 0 );
uint32_t getModulesCount( ARGUS_MODULE_TYPE t );
uint32_t fetchModules( ARGUS_MODULE_TYPE, argusKernelModule**&RA );
bool loadModules( uint32_t ServerID = 0 );
void validate( void );
bool validate( void );
void shutdownServices( bool force = false );
protected:
argusModuleFactory();
explicit argusModuleFactory( uint32_t ServerID );
virtual void m_fThreadProc( void );
private:
static argusModuleFactory * _instance;
};

67
lib/rgoose/rgooseModuleOnvifObserver.cpp

@ -70,7 +70,7 @@
#define TLOG( X ) basicLogCollection::getInstance()->Log( "MOD_ONVIF_T", me, X )
#define TLOG_ERROR( X ) basicLogCollection::getInstance()->Log( "MOD_ONVIF_T", me, _LOG_ERROR, X )
argusModuleOnvifObserver::argusModuleOnvifObserver( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_FLYHUNTER ), basicThread(){
argusModuleOnvifObserver::argusModuleOnvifObserver( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_ONVIF_OBSERVER ), basicThread(){
m_bEnabled = false;
m_pEventHeap = basicEventHeap::getInstance();
m_pIpAddresses = NULL;
@ -91,32 +91,39 @@ argusModuleOnvifObserver::argusModuleOnvifObserver( uint32_t ModuleID ): argusKe
};
argusModuleOnvifObserver::~argusModuleOnvifObserver(){
m_bEnabled = false;
stopService();
if( !m_bDetached ) stopService( true );
};
bool argusModuleOnvifObserver::startService(){
LOG("Starting Service!");
m_bEnabled = true;
//if( m_bEnabled ) return false;
if( !m_bWSAOK ) return false;
return init();
m_bEnabled = init();
return m_bEnabled;
};
bool argusModuleOnvifObserver::stopService( bool force ){
m_bEnabled = false;
waitThreadEnd( true );
if( m_vThreads.size() ) { // Kill-Wait Started Probes
#ifdef DEBUG
LOG("Have to Wait Probes!");
#ifdef DEBUG
char tB[128];
sprintf( tB, "Have to Wait %d Probe(s)!", m_vThreads.size() );
LOG( tB );
#endif
for( vectorOBSERVER_CTX::iterator index = m_vThreads.begin(); index < m_vThreads.end(); index++ ) {
if( force ){
// force
#ifdef DEBUG
LOG("Force Cancel Probe!");
#endif
pthread_cancel( (*index)->m_hThreadHandle );
} else{
// easy
#ifdef DEBUG
LOG("Wait Probe Exits!");
#endif
pthread_join( (*index)->m_hThreadHandle, NULL );
};
free((*index)->context);
free((*index));
};
m_vThreads.clear();
};
@ -132,7 +139,8 @@ bool argusModuleOnvifObserver::stopService( bool force ){
#ifdef DEBUG
LOG("Data is Cleared!");
#endif
return true;
m_bDetached = true;
return m_bDetached;
};
void argusModuleOnvifObserver::m_fThreadProc(){
@ -207,7 +215,20 @@ void argusModuleOnvifObserver::m_fThreadProc(){
startProbe(HTTPMU_HOST_ADDRESS, id, (int)dStep);
dStatus += dStep;
m_nStatus = (int)dStatus;
SLEEP( 30000 );
// Check Finished Threads;
for( vectorOBSERVER_CTX::iterator index = m_vThreads.begin(); index < m_vThreads.end(); index++ ) {
if( (*index)->context->isFinished ){
#ifdef DEBUG_EXTRA
LOG("Probe Exits!");
#endif
pthread_join( (*index)->m_hThreadHandle, NULL );
};
free((*index)->context);
free((*index));
m_vThreads.erase( index );
};
for( int i=300; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( 100 );
};
};
@ -240,6 +261,7 @@ PROBE_CTX *argusModuleOnvifObserver::init_PROBE_CTX(CSTR ADR, int ID, int stp){
RetVal->iOptLen = sizeof(int);
RetVal->AddressID = ID;
RetVal->step = stp;
RetVal->isFinished = false;
RetVal->observer = this;
return RetVal;
};
@ -248,6 +270,9 @@ void *argusModuleOnvifObserver::probeThreadProc( void *ptr ){
PROBE_CTX *me;
if (ptr == NULL) return NULL;
me = (PROBE_CTX *)ptr;
//Detach Self!
//pthread_detach( pthread_self() );
#ifdef DEBUG
//TLOG("Probe Request Sent");
#endif
@ -263,19 +288,22 @@ void *argusModuleOnvifObserver::probeThreadProc( void *ptr ){
u_long val = 1;
ioctlsocket(me->socketFD, FIONBIO, &val);//none block
#endif
for (me->index = 1; me->index <= 10; me->index++){
for( me->index = 1; me->index <= 10; me->index++ ){
memset(me->buff, 0, sizeof(me->buff));
me->RetVal = recvfrom(me->socketFD, me->buff, MAX_BUFF_SIZE, 0, NULL, NULL);
if( me->RetVal < 0 ){//SOCKET_ERROR){
SLEEP(1000);
continue;
};
if( me->RetVal == 0 ) continue; // No Data
me->recv_buff = me->buff;
XMLResults tParseResults;
XMLNode response = XMLNode::parseString( me->buff, "root", &tParseResults );
#ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
FILE *fd;
fd = fopen("ONVIF_MSGS.txt","a+");
fprintf(fd,"++++++++++++++++++++\r\n");
fprintf(fd,me->buff);
fprintf(fd,"--------------------\r\n");
fclose(fd);
@ -285,11 +313,12 @@ void *argusModuleOnvifObserver::probeThreadProc( void *ptr ){
sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
TLOG_ERROR( tBuffer );
} else {
if(response.isEmpty()){
if( response.isEmpty() ){
TLOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element.");
continue;
} else {
XMLNode Body = response.getChildNode("Body", 0);
TLOG_ERROR("XML PARSED OK");
XMLNode Body = response.getChildNode( "Body", 0 );
if(!Body.isEmpty()){
XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference
if(!ProbeMatches.isEmpty()) {
@ -391,15 +420,15 @@ void *argusModuleOnvifObserver::probeThreadProc( void *ptr ){
};
};
me->observer->m_nStatus += me->step;
#ifdef DEBUG_EXTRA
TLOG("Probe Finished");
#endif
#ifdef __linux__
close(me->socketFD);
#else
closesocket(me->socketFD);
#endif
free( me );
#ifdef DEBUG_EXTRA
TLOG("Probe Finished");
#endif
me->isFinished = true;
return NULL;
};

1
lib/rgoose/rgooseModuleOnvifObserver.h

@ -36,6 +36,7 @@ typedef struct S_PROBE_CTX{
int RetVal;
int index;
int step;
bool isFinished;
argusModuleOnvifObserver *observer;
}PROBE_CTX;

2
lib/rgoose/rgooseModuleSSDP.cpp

@ -13,7 +13,7 @@
#endif
argusModuleSSDPAnnouncer::argusModuleSSDPAnnouncer( uint32_t ModuleID ) : argusKernelModule( ModuleID, ARGUS_MODULE_DCBUSB ){
argusModuleSSDPAnnouncer::argusModuleSSDPAnnouncer( uint32_t ModuleID ) : argusKernelModule( ModuleID, ARGUS_MODULE_SSDP_ANONCE ){
m_pEventHeap = basicEventHeap::getInstance();
};

175
lib/rgoose/rgooseNodeFactory.cpp

@ -12,27 +12,28 @@
#define LOG( X ) m_pLog->Log( "NFAC", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "NFAC", this, _LOG_ERROR, X )
argusNodeFactory * argusNodeFactory::_instance = 0;
argusNodeFactory * argusNodeFactory::_instance = NULL;
/**
* Returns the single instance of the object.
*/
argusNodeFactory* argusNodeFactory::getInstance() {
// check if the instance has been created yet
if (0 == _instance) {
// if not, then create it
_instance = new argusNodeFactory;
}
// return the single instance
argusNodeFactory* argusNodeFactory::getInstance( uint32_t ServerID ) {
if( NULL == _instance) {
if( ServerID ) {
_instance = new argusNodeFactory( ServerID );
};
};
return _instance;
};
argusNodeFactory::argusNodeFactory(){
argusNodeFactory::argusNodeFactory( uint32_t ServerID ): basicThread(){
m_nSiteID = ServerID;
m_pLog = basicLogCollection::getInstance();
m_pDBC = argusDBC::getInstance();
LOG("CONSTRUCTION");
init();
};
argusNodeFactory::~argusNodeFactory(){
waitThreadEnd( true );
unloadNodes();
_instance = NULL;
};
@ -142,11 +143,19 @@ bool argusNodeFactory::reloadNode( uint32_t NodeID ){
argusNetNode *argusNodeFactory::createNode( uint32_t id ){
argusNetNode *tVal = NULL;
LOG("Create Node!");
if( m_pDBC != NULL ){
DBC_NODE_DATA *tData = NULL;
tData = m_pDBC->getNodeData( id );
if( tData!= NULL ) {
#ifdef DEBUG
char tB[256];
sprintf( tB, "Node id: %d AUX id: %d", id, tData->aux_id );
LOG( tB );
sprintf( tB, "Node type: %d", tData->type );
LOG( tB );
sprintf( tB, "Node Name: %s", tData->name );
LOG( tB );
#endif
switch( tData->type ) {
case ARGUS_ANALOG_STATIC_CAMERA:{
#ifdef DEBUG
@ -322,6 +331,11 @@ argusNetNode *argusNodeFactory::createNode( uint32_t id ){
};
};
if( tVal != NULL ){
#ifdef DEBUG
char tB[64];
sprintf( tB, "Node PTR: %p", tVal );
LOG( tB );
#endif
m_vNetNodes.push_back( tVal );
m_mNetNodesIDS[id] = tVal;
};
@ -440,71 +454,92 @@ void argusNodeFactory::deleteNode( uint32_t id ){
deleteNode( tNode );
};
void argusNodeFactory::validate( void ){
if(m_pDBC == NULL) return;
DBC_INT_LIST *tList = NULL;
#ifdef MEM_DEBUG
size_t memStart, memEnd, memDiff;
char MEM_MSG[256];
memStart = getCurrentRSS();
#endif
if( m_vNetNodes.size() ) {
DBC_INT_LIST tL;
for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) tL.push_back( (*idx)->getDbId() );
tList = m_pDBC->listNewNodes( m_nSiteID, &tL );
tL.clear();
bool argusNodeFactory::validate( void ){
return ( m_bThreadStatus < TH_ENDED );
};
void argusNodeFactory::m_fThreadProc( void ){
if( m_pDBC == NULL ){
m_bThreadStatus = TH_ENDED;
} else {
tList = m_pDBC->listNewNodes( m_nSiteID, NULL );
};
if( tList != NULL ) {
LOG("New Nodes Added!");
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode( *idx );
tList->clear();
delete( tList );
}
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) {
DBC_INT_LIST *tList = NULL;
#ifdef DEBUG
#ifdef MEM_DEBUG
size_t memStart, memEnd, memDiff;
char MEM_MSG[256];
memStart = getCurrentRSS();
#endif
#endif
if( m_vNetNodes.size() ) {
DBC_INT_LIST tL;
for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) tL.push_back( (*idx)->getDbId() );
tList = m_pDBC->listNewNodes( m_nSiteID, &tL );
tL.clear();
} else {
tList = m_pDBC->listNewNodes( m_nSiteID, NULL );
};
if( tList != NULL ) {
LOG("New Nodes Added!");
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode( *idx );
tList->clear();
delete( tList );
}
#ifdef DEBUG_EXTRA
else {
LOG( "No New Nodes Added");
}
else {
LOG( "No New Nodes Added");
}
#endif
#ifdef MEM_DEBUG
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
if( m_vNetNodes.size() ) {
//Get Full List
tList = m_pDBC->listNodes( m_nSiteID );
if( tList != NULL ) {
for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ){
bool tRemoved = true;
for( DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++ ) if( (*idz) == (*idx)->getDbId() ) tRemoved = false;
tRemoved = !(*idx)->validate();
if( tRemoved ) {
deleteNode((*idx));
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
if( m_vNetNodes.size() ) {
//Get Full List
tList = m_pDBC->listNodes( m_nSiteID );
if( tList != NULL ) {
for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ){
bool tRemoved = true;
// Check if Removed By changes in DB
for( DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++ ) if( (*idz) == (*idx)->getDbId() ) tRemoved = false;
// If Not - check validation
if( !tRemoved ){
tRemoved = !(*idx)->validate();
};
// If Node is Invalid - Removing
if( tRemoved ) {
deleteNode((*idx));
};
};
tList->clear();
delete( tList );
} else {
LOG("All Modules Must be Deleted!");
for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) deleteNode((*idx));
m_vNetNodes.clear();
m_mNetNodesIDS.clear();
};
};
tList->clear();
delete( tList );
} else {
LOG("All Modules Must be Deleted!");
for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) deleteNode((*idx));
m_vNetNodes.clear();
m_mNetNodesIDS.clear();
}
#ifdef DEBUG
else {
LOG("No Nodes to Validate");
}
#ifdef MEM_DEBUG
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
#endif
for( int i = ( 5000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
}
#ifdef DEBUG
else {
LOG("No Nodes to Validate");
}
#endif
#ifdef MEM_DEBUG
memEnd = getCurrentRSS();
memDiff = memEnd - memStart;
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
LOG( MEM_MSG );
#endif
};
LOG("EXIT FROM CTRL THREAD");
};
uint32_t argusNodeFactory::getNodesCount( ARGUS_NODE_TYPE type ){

44
lib/rgoose/rgooseNodeFactory.h

@ -4,34 +4,36 @@
#include <vector>
#include <map>
#include "rgooseNode.h"
#include "../components/base/basicThread.h"
typedef std::vector<argusNetNode*> vectorNetNodes;
typedef std::map<uint32_t,argusNetNode*> mapNode2Id;
class argusNodeFactory{
class argusNodeFactory: public basicThread{
private:
basicLogCollection * m_pLog;
argusDBC * m_pDBC;
uint32_t m_nSiteID;
vectorNetNodes m_vNetNodes;
mapNode2Id m_mNetNodesIDS;
basicLogCollection * m_pLog;
argusDBC * m_pDBC;
uint32_t m_nSiteID;
vectorNetNodes m_vNetNodes;
mapNode2Id m_mNetNodesIDS;
public:
static argusNodeFactory * getInstance();
virtual ~argusNodeFactory();
argusNetNode * createNode( uint32_t id );
void deleteNode( argusNetNode *ptr );
void deleteNode( uint32_t id );
uint32_t fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA );
argusNetNode * getNode( uint32_t id );
uint32_t getNodesCount( ARGUS_NODE_TYPE type );
bool loadNodes( uint32_t SiteID = 0 );
bool unloadNodes( void );
bool reloadNodes( uint32_t SiteID = 0 );
bool reloadNode( uint32_t NodeID );
void validate( void );
static argusNodeFactory * getInstance( uint32_t ServerID = 0 );
virtual ~argusNodeFactory();
argusNetNode * createNode( uint32_t id );
void deleteNode( argusNetNode *ptr );
void deleteNode( uint32_t id );
uint32_t fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA );
argusNetNode * getNode( uint32_t id );
uint32_t getNodesCount( ARGUS_NODE_TYPE type );
bool loadNodes( uint32_t SiteID = 0 );
bool unloadNodes( void );
bool reloadNodes( uint32_t SiteID = 0 );
bool reloadNode( uint32_t NodeID );
bool validate( void );
protected:
argusNodeFactory();
explicit argusNodeFactory( uint32_t ServerID );
virtual void m_fThreadProc( void );
private:
static argusNodeFactory * _instance;
static argusNodeFactory * _instance;
};
#endif

21
lib/rgoose/rgooseNodeStaticCamControl.cpp

@ -125,7 +125,6 @@ void ARGUS_CAM::dispatchEvent( EVENT_CONTAINER *E ){
};
};
bool ARGUS_CAM::validate(){
//LOG("VALIDATE");
if( m_bThreadStatus == TH_ENDED ) return false;
if( !argusNetNode::m_pDBC ) return false;
//Validate Node Settings
@ -144,7 +143,7 @@ bool ARGUS_CAM::validate(){
};
}
// Validate Camera Settings
/*{
/*{
DBC_CAM_DATA *tDATA = argusNetNode::m_pDBC->getCamData( m_sNodeData.aux_id );
if( tDATA ) {
if( memcmp( &m_sCamData, tDATA, sizeof(DBC_CAM_DATA)) != 0 ){
@ -160,19 +159,13 @@ bool ARGUS_CAM::validate(){
}*/
// Validate Stream
{
if( m_sNodeData.aux_parameter ) { // Has Choosed Stream
DBC_MEDIA_STREAM_DATA *tDATA = argusNetNode::m_pDBC->getMediaStreamData( m_sNodeData.aux_parameter );
if( tDATA ){
if( tDATA->valid ) {
if( !m_bSourceConnected ) {
if(!connectToStream( m_sNodeData.aux_parameter ) ) return false;
};
} else {
if( m_bSourceConnected ) {
if( disconnectFromStream() ) return false;
};
if( !m_bSourceConnected ) {
if( m_sNodeData.aux_parameter ) { // Has Choosed Stream
if( connectToStream( m_sNodeData.aux_parameter ) ){
//DBC_MEDIA_STREAM_DATA *tDATA = argusNetNode::m_pDBC->getMediaStreamData( m_sNodeData.aux_parameter );
m_bSourceConnected = true;
return argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter );
};
free( tDATA );
};
};
}

Loading…
Cancel
Save