• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "server_stub.h"
17 #include "securec.h"
18 #include "ohos_init.h"
19 #include "samgr_lite.h"
20 #include "iproxy_server.h"
21 #include "dm_log.h"
22 #include "dm_subscribe_info.h"
23 #include "ipc_def.h"
24 #include "device_manager_service.h"
25 
26 namespace {
27     const int32_t WAIT_FOR_SERVER = 2;
28     const int32_t STACK_SIZE = 0x1000;
29     const int32_t QUEUE_SIZE = 32;
30 }
31 
32 using namespace OHOS::DistributedHardware;
33 
34 struct DefaultFeatureApi {
35     INHERIT_SERVER_IPROXY;
36 };
37 
38 struct DeviceManagerSamgrService {
39     INHERIT_SERVICE;
40     INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
41     Identity identity;
42 };
43 
44 
GetName(Service * service)45 static const char *GetName(Service *service)
46 {
47     (void)service;
48     return DEVICE_MANAGER_SERVICE_NAME;
49 }
50 
Initialize(Service * service,Identity identity)51 static BOOL Initialize(Service *service, Identity identity)
52 {
53     if (service == NULL) {
54         LOGW("Initialize invalid param");
55         return FALSE;
56     }
57 
58     const int32_t DM_SERVICE_INIT_DELAY = 2;
59     sleep(DM_SERVICE_INIT_DELAY);
60     SAMGR_Bootstrap();
61 
62     DeviceManagerService::GetInstance().Init();
63 
64     DeviceManagerSamgrService *mgrService = static_cast<DeviceManagerSamgrService *>(service);
65     mgrService->identity = identity;
66     return TRUE;
67 }
68 
MessageHandle(const Service * service,const Request * request)69 static BOOL MessageHandle(const Service *service, const Request *request)
70 {
71     if ((service == NULL) || (request == NULL)) {
72         LOGW("MessageHandle invalid param");
73         return FALSE;
74     }
75     return TRUE;
76 }
77 
GetTaskConfig(Service * service)78 static TaskConfig GetTaskConfig(Service *service)
79 {
80     (void)service;
81     TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, STACK_SIZE, QUEUE_SIZE, SHARED_TASK};
82     return config;
83 }
84 
DevMgrSvcInit(void)85 static void DevMgrSvcInit(void)
86 {
87     sleep(WAIT_FOR_SERVER);
88     static DeviceManagerSamgrService service = {
89         .GetName = GetName,
90         .Initialize = Initialize,
91         .MessageHandle = MessageHandle,
92         .GetTaskConfig = GetTaskConfig,
93         SERVER_IPROXY_IMPL_BEGIN,
94         .Invoke = NULL,
95         IPROXY_END,
96     };
97 
98     if (!SAMGR_GetInstance()->RegisterService((Service *)&service)) {
99         LOGE("%s, RegisterService failed", DEVICE_MANAGER_SERVICE_NAME);
100         return;
101     }
102     if (!SAMGR_GetInstance()->RegisterDefaultFeatureApi(DEVICE_MANAGER_SERVICE_NAME, GET_IUNKNOWN(service))) {
103         LOGE("%s, RegisterDefaultFeatureApi failed", DEVICE_MANAGER_SERVICE_NAME);
104         return;
105     }
106     LOGI("%s, init success", DEVICE_MANAGER_SERVICE_NAME);
107 }
108 
109 SYSEX_SERVICE_INIT(DevMgrSvcInit);
110