it3256_service.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "it3256_service.h"
  2. #include "it3256_log.h"
  3. #include "iservice_registry.h"
  4. namespace OHOS {
  5. namespace It3256 {
  6. REGISTER_SYSTEM_ABILITY_BY_ID(It3256IOService, It3256IO_SERVICE_ID, true);
  7. It3256IOService::It3256IOService(int32_t systemAbilityId, bool runOnCreate)
  8. : SystemAbility(systemAbilityId, runOnCreate)
  9. {
  10. It3256_LOGI("It3256IOService constructor");
  11. }
  12. It3256IOService::~It3256IOService()
  13. {
  14. It3256_LOGI("It3256IOService destructor");
  15. }
  16. void It3256IOService::OnStart()
  17. {
  18. It3256_LOGI("It3256IOService::OnStart start");
  19. if (ready_) {
  20. It3256_LOGI("It3256IOService has already started");
  21. return;
  22. }
  23. if (!Initialize()) {
  24. It3256_LOGE("Failed to initialize");
  25. return;
  26. }
  27. // 发布服务
  28. if (!Publish(this)) {
  29. It3256_LOGE("Failed to publish service");
  30. return;
  31. }
  32. ready_ = true;
  33. It3256_LOGI("It3256IOService start success");
  34. }
  35. void It3256IOService::OnStop()
  36. {
  37. It3256_LOGI("It3256IOService::OnStop start");
  38. if (!ready_) {
  39. return;
  40. }
  41. ready_ = false;
  42. control_ = nullptr;
  43. It3256_LOGI("It3256IOService stop success");
  44. }
  45. bool It3256IOService::Initialize()
  46. {
  47. control_ = std::make_shared<It3256IOControl>();
  48. if (!control_) {
  49. It3256_LOGE("Failed to create It3256IOControl");
  50. return false;
  51. }
  52. return true;
  53. }
  54. bool It3256IOService::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
  55. {
  56. if (!ready_) {
  57. It3256_LOGE("Service not ready");
  58. return false;
  59. }
  60. return control_->SetAIRangeCode(startch, stopch, poutbuf);
  61. }
  62. bool It3256IOService::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
  63. {
  64. if (!ready_) {
  65. It3256_LOGE("Service not ready");
  66. return false;
  67. }
  68. return control_->GetAIRangeCode(startch, stopch, poutbuf);
  69. }
  70. } // namespace It3256
  71. } // namespace OHOS