1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "distributed_hardware_service.h"
17
18 #include "if_system_ability_manager.h"
19 #include "ipc_skeleton.h"
20 #include "ipc_types.h"
21 #include "iservice_registry.h"
22 #include "string_ex.h"
23 #include "system_ability_definition.h"
24
25 #include "access_manager.h"
26 #include "distributed_hardware_errno.h"
27 #include "distributed_hardware_log.h"
28
29 namespace OHOS {
30 namespace DistributedHardware {
31 REGISTER_SYSTEM_ABILITY_BY_ID(DistributedHardwareService, DISTRIBUTED_HARDWARE_SA_ID, true);
32
DistributedHardwareService(int32_t saId,bool runOnCreate)33 DistributedHardwareService::DistributedHardwareService(int32_t saId, bool runOnCreate)
34 : SystemAbility(saId, runOnCreate)
35 {
36 }
37
OnStart()38 void DistributedHardwareService::OnStart()
39 {
40 DHLOGI("DistributedHardwareService::OnStart start");
41 if (state_ == ServiceRunningState::STATE_RUNNING) {
42 DHLOGI("DistributedHardwareService has already started.");
43 return;
44 }
45 if (!Init()) {
46 DHLOGE("failed to init DistributedHardwareService");
47 return;
48 }
49 state_ = ServiceRunningState::STATE_RUNNING;
50 DHLOGI("DistributedHardwareService::OnStart start service success.");
51 }
52
Init()53 bool DistributedHardwareService::Init()
54 {
55 DHLOGI("DistributedHardwareService::Init ready to init.");
56 if (!registerToService_) {
57 bool ret = Publish(this);
58 if (!ret) {
59 DHLOGE("DistributedHardwareService::Init Publish failed!");
60 return false;
61 }
62 registerToService_ = true;
63 }
64 auto ret = AccessManager::GetInstance()->Init();
65 if (ret != DH_FWK_SUCCESS) {
66 DHLOGI("DistributedHardwareService::Init failed.");
67 return false;
68 }
69 DHLOGI("DistributedHardwareService::Init init success.");
70 return true;
71 }
72
OnStop()73 void DistributedHardwareService::OnStop()
74 {
75 DHLOGI("DistributedHardwareService::OnStop ready to stop service.");
76 state_ = ServiceRunningState::STATE_NOT_START;
77 registerToService_ = false;
78 }
79
QuerySinkVersion(std::unordered_map<DHType,std::string> & versionMap)80 int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map<DHType, std::string> &versionMap)
81 {
82 (void)versionMap;
83 return 0;
84 }
85 }
86 }
87