#include "it3256_service.h" #include "it3256_log.h" #include "iservice_registry.h" namespace OHOS { namespace It3256 { REGISTER_SYSTEM_ABILITY_BY_ID(It3256IOService, It3256IO_SERVICE_ID, true); It3256IOService::It3256IOService(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) { It3256_LOGI("It3256IOService constructor"); } It3256IOService::~It3256IOService() { It3256_LOGI("It3256IOService destructor"); } void It3256IOService::OnStart() { It3256_LOGI("It3256IOService::OnStart start"); if (ready_) { It3256_LOGI("It3256IOService has already started"); return; } if (!Initialize()) { It3256_LOGE("Failed to initialize"); return; } // 发布服务 if (!Publish(this)) { It3256_LOGE("Failed to publish service"); return; } ready_ = true; It3256_LOGI("It3256IOService start success"); } void It3256IOService::OnStop() { It3256_LOGI("It3256IOService::OnStop start"); if (!ready_) { return; } ready_ = false; control_ = nullptr; It3256_LOGI("It3256IOService stop success"); } bool It3256IOService::Initialize() { control_ = std::make_shared(); if (!control_) { It3256_LOGE("Failed to create It3256IOControl"); return false; } return true; } bool It3256IOService::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) { if (!ready_) { It3256_LOGE("Service not ready"); return false; } return control_->SetAIRangeCode(startch, stopch, poutbuf); } bool It3256IOService::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) { if (!ready_) { It3256_LOGE("Service not ready"); return false; } return control_->GetAIRangeCode(startch, stopch, poutbuf); } } // namespace It3256 } // namespace OHOS