You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
6.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*******************************************************************
  2. *
  3. * DESCRIPTION: ARGUS Kernel source
  4. *
  5. * AUTHOR: gagua
  6. *
  7. * HISTORY:
  8. *
  9. * DATE:5/29/2019
  10. *
  11. *******************************************************************/
  12. #include "RGoose_Kernel.h"
  13. #include <sys/types.h>
  14. #define LOG( X ) m_pLog->Log( "KRNL", this, X )
  15. #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X )
  16. ARGUS_Kernel::ARGUS_Kernel( config_setting_t *Settings ):basicThread(){
  17. m_bExitCause = 0;
  18. m_nSiteID = 0;
  19. m_tTimeTSeconds = time( NULL );
  20. m_pLog = basicLogCollection::getInstance();
  21. m_pEventHeap = basicEventHeap::getInstance();
  22. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
  23. if( basicSettingsProvider::getInstance()->isCompromised() ) {
  24. basicSettingsProvider::getInstance()->validate();
  25. };
  26. };
  27. ARGUS_Kernel::~ARGUS_Kernel(){
  28. #ifdef DEBUG
  29. LOG("Destructor");
  30. #endif
  31. WaitFinish(true);
  32. #ifdef DEBUG
  33. LOG("Deleting Components");
  34. #endif
  35. #ifdef DEBUG
  36. LOG("Destructor Finished");
  37. #endif
  38. };
  39. bool ARGUS_Kernel::create( void ){
  40. char tBuffer[256];
  41. if( m_pSettings != NULL ) {
  42. config_setting_t * pSetting;
  43. int tVal;
  44. const char * tBuf;
  45. //Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
  46. LOG("Getting Settings ...");
  47. if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
  48. char * tVar;
  49. char * tTS;
  50. tTS = getTStr(NULL);
  51. tVar = MD5String(tTS);
  52. free(tTS);
  53. sprintf( m_sIdentity, tVar );
  54. pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
  55. config_setting_set_string( pSetting, tVar );
  56. free( tVar );
  57. basicSettingsProvider::getInstance()->compromise();
  58. LOG("Server Identity not defined - generating new!");
  59. } else {
  60. sprintf( m_sIdentity, tBuf );
  61. sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
  62. LOG( tBuffer );
  63. };
  64. if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
  65. tVal = m_nSiteID = 1;
  66. pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
  67. config_setting_set_int( pSetting, tVal );
  68. basicSettingsProvider::getInstance()->compromise();
  69. LOG("Site ID not defined - using [1] as number!");
  70. } else {
  71. m_nSiteID = tVal;
  72. sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
  73. LOG( tBuffer );
  74. };
  75. /*
  76. #ifdef __EU_PROJECT__
  77. if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_SAFE_SHORE, &tVal ) ){
  78. tVal = m_bSafeShoreSupport = true;
  79. pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_SAFE_SHORE, CONFIG_TYPE_BOOL );
  80. config_setting_set_bool( pSetting, tVal );
  81. m_pSettingsProvider->compromise();
  82. LOG("Safe-Shore support not defined");
  83. } else {
  84. m_bSafeShoreSupport = (bool)tVal;
  85. sprintf( tBuffer, "Safe-Shore support Read From Settings: %d", tVal );
  86. LOG( tBuffer );
  87. };
  88. #endif
  89. if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DEFENDER, &tVal ) ){
  90. tVal = m_bDefenderSupport = true;
  91. pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DEFENDER, CONFIG_TYPE_BOOL );
  92. config_setting_set_bool( pSetting, tVal );
  93. m_pSettingsProvider->compromise();
  94. LOG("Defender support not defined");
  95. } else {
  96. m_bDefenderSupport = (bool)tVal;
  97. sprintf( tBuffer, "Defender support Read From Settings: %d", tVal );
  98. LOG( tBuffer );
  99. };
  100. if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){
  101. tVal = m_nWidth = 1000;
  102. pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT);
  103. config_setting_set_int(pSetting, tVal );
  104. m_pSettingsProvider->compromise();
  105. LOG("No Detector Width");
  106. } else {
  107. m_nWidth = tVal;
  108. sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal );
  109. LOG( tBuffer );
  110. };
  111. if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){
  112. tVal = m_nKernelFilter = 0x000000ff;
  113. pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT);
  114. config_setting_set_int(pSetting, tVal );
  115. m_pSettingsProvider->compromise();
  116. LOG("No Fltered Kernels Defined - All LRF Will Work");
  117. } else {
  118. m_nKernelFilter = tVal;
  119. sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal );
  120. LOG( tBuffer );
  121. };
  122. if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){
  123. tVal = m_nSST = 0;
  124. pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT);
  125. config_setting_set_int(pSetting, tVal );
  126. m_pSettingsProvider->compromise();
  127. LOG("No Detector SST");
  128. } else {
  129. m_nSST = tVal;
  130. sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal );
  131. LOG( tBuffer );
  132. };
  133. if( m_pSettingsProvider->isCompromised() ) {
  134. LOG("Save Settings");
  135. m_pSettingsProvider->validate();
  136. };
  137. */
  138. } else {
  139. LOG_ERROR("Failed Read Config Settings!");
  140. return false;
  141. };
  142. #ifdef DEBUG
  143. LOG( "Settings Read Done" );
  144. #endif
  145. #ifdef DEBUG
  146. LOG( "Kernel Trhead is about to be Created" );
  147. #endif
  148. if( init() == false ){
  149. LOG_ERROR("Error in starting Kernel Thread!");
  150. return false;
  151. };
  152. #ifdef DEBUG
  153. LOG( "Kernel Thread Created" );
  154. #endif
  155. return true;
  156. };
  157. void ARGUS_Kernel::WaitFinish( bool Force ){
  158. if( Force ){
  159. #ifdef DEBUG
  160. LOG( "Thread End Forced" );
  161. #endif
  162. } else {
  163. // 3 seconds sleep to settle down processes
  164. SLEEP(3000);
  165. };
  166. waitThreadEnd( Force );
  167. #ifdef DEBUG
  168. LOG( "Thread is Detached" );
  169. #endif
  170. };
  171. /* Main Kernel Thread Procedure */
  172. void ARGUS_Kernel::m_fThreadProc( void ){
  173. char Buffer[CTEXT];
  174. time_t tTimeTSeconds;
  175. int lastTSS = 0;
  176. int lastTMS = 0;
  177. #ifdef DEBUG
  178. pid_t pid = gettid();
  179. char pidBuf[16];
  180. sprintf(pidBuf,"pid:%d", pid);
  181. LOG(pidBuf);
  182. #endif
  183. m_bThreadStatus = TH_WORKING;
  184. while( m_bThreadStatus < TH_ENDED ){
  185. m_tTimeTSeconds = time( NULL );
  186. if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process
  187. tTimeTSeconds = m_tTimeTSeconds;
  188. };
  189. SLEEP( SLEEP_KERNEL_INTERVAL );
  190. };
  191. };
  192. bool ARGUS_Kernel::setStatus( int A ){
  193. m_bThreadStatus = (thredStatus)A;
  194. };
  195. #undef LOG
  196. #undef LOG_ERROR