upsdev.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "upsimpl.h"
  2. #include "log4vendor.h"
  3. UpsClassImpl* g_pUpsDevice = NULL;
  4. void __attribute__((destructor)) uninit()
  5. {
  6. if (g_pUpsDevice)
  7. {
  8. delete g_pUpsDevice;
  9. g_pUpsDevice = NULL;
  10. }
  11. }
  12. void __attribute__((constructor)) init()
  13. {
  14. }
  15. DEVICEBASE_API ErrorCodeEnum CreateDevComponent(DeviceBaseClass *&baseObj)
  16. {
  17. ErrorCodeEnum eRt = Error_Succeed;
  18. if(NULL == g_pUpsDevice)
  19. {
  20. g_pUpsDevice = new UpsClassImpl();
  21. baseObj = (DeviceBaseClass *)g_pUpsDevice;
  22. cmb::log_init_config config;
  23. config.log_level=CMB_LOG_LEVEL_ALL;
  24. config.dev_name = "UPS";
  25. #if defined(_MSC_VER)
  26. config.log_dir = ("C:\\rvc\\dbg\\");
  27. #else
  28. config.log_dir = ("/opt/rvc/dbg/");
  29. #endif //_MSC_VER
  30. std::string str;
  31. cmb::log4vendor::init(config, str);
  32. printf("init after: %s\n", str.c_str());
  33. }
  34. else
  35. {
  36. eRt = Error_AlreadyExist;
  37. }
  38. return eRt;
  39. }
  40. DEVICEBASE_API ErrorCodeEnum ReleaseDevComponent(DeviceBaseClass *&pBaseObj)
  41. {
  42. ErrorCodeEnum eRt = Error_Succeed;
  43. if(pBaseObj == (DeviceBaseClass*)g_pUpsDevice)
  44. {
  45. delete g_pUpsDevice;
  46. g_pUpsDevice = NULL;
  47. return Error_Succeed;
  48. }
  49. return Error_Param;
  50. }