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.

77 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "IM_Kernel.h"
  2. #include "IM_ClientHandler.h"
  3. #define LOG( X ) m_pLog->Log( "KRNL", this, X )
  4. #ifdef DEBUG
  5. #define LOG_ERROR( X ) {\
  6. char _tBfrErrMSG234[256];\
  7. sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  8. m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\
  9. }
  10. #else
  11. #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
  12. #endif
  13. IM_Kernel *IM_Kernel::_instance = NULL;
  14. IM_Kernel *IM_Kernel::getInstance(){
  15. if( _instance == NULL ) {
  16. _instance = new IM_Kernel;
  17. };
  18. return _instance;
  19. };
  20. // Constructor implementation
  21. inline IM_Kernel::IM_Kernel( config_setting_t *Settings ) : basicEngine(), basicThread(){
  22. m_pLog = basicLogCollection::getInstance();
  23. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
  24. m_pWorker = NULL;
  25. };
  26. // Destructor implementation
  27. inline IM_Kernel::~IM_Kernel(){
  28. waitThreadEnd( true );
  29. };
  30. bool IM_Kernel::start(){
  31. m_pWorker = new IM_DnnWorker( m_pSettings );
  32. if( m_pWorker ) {
  33. if( m_pWorker->create() ){
  34. return init();
  35. } else LOG_ERROR( "DNN Worker Create Failure!" );
  36. };
  37. return false;
  38. };
  39. bool IM_Kernel::stop( bool Force ){
  40. delete( m_pWorker );
  41. m_pWorker = NULL;
  42. waitThreadEnd( Force );
  43. return true;
  44. };
  45. networkClientHandler *IM_Kernel::attachNewClient( int SocketID ){
  46. IM_ClientHandler *tVal;
  47. tVal = new IM_ClientHandler( SocketID );
  48. if( tVal ) {
  49. tVal->attachEngine( this );
  50. };
  51. return (networkClientHandler *) tVal;
  52. };
  53. bool IM_Kernel::detachClient( networkClientHandler *ptr ){
  54. delete( (IM_ClientHandler *) ptr );
  55. return true;
  56. };
  57. void IM_Kernel::m_fThreadProc( void ){
  58. m_bThreadStatus = TH_WORKING;
  59. while( m_bThreadStatus < TH_ENDED ) {
  60. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  61. };
  62. };
  63. #undef LOG
  64. #undef LOG_ERROR