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 <ohos_init.h>
17 #include <samgr_lite.h>
18 #include <service.h>
19
20 #include <unistd.h>
21 #include <pthread.h>
22
23 #include "hilog_wrapper.h"
24 #include "power_mgr.h"
25
26 #define STACK_SIZE 0x800
27 #define QUEUE_SIZE 20
28
29 typedef struct {
30 INHERIT_SERVICE;
31 Identity identity;
32 } PowerMgrService;
33
34 static const char *GetName(Service *service);
35 static BOOL Initialize(Service *service, Identity identity);
36 static BOOL MessageHandle(Service *service, Request *request);
37 static TaskConfig GetTaskConfig(Service *service);
38
39 static PowerMgrService g_service = {
40 .GetName = GetName,
41 .Initialize = Initialize,
42 .MessageHandle = MessageHandle,
43 .GetTaskConfig = GetTaskConfig,
44 .identity = { -1, -1, NULL }
45 };
46
GetName(Service * service)47 static const char *GetName(Service *service)
48 {
49 (void)service;
50 return POWER_MANAGE_SERVICE;
51 }
52
Initialize(Service * service,Identity identity)53 static BOOL Initialize(Service *service, Identity identity)
54 {
55 if (service == NULL) {
56 POWER_HILOGE("Invalid service");
57 return FALSE;
58 }
59 PowerMgrService *pms = (PowerMgrService *)(service);
60 pms->identity = identity;
61 return TRUE;
62 }
63
MessageHandle(Service * service,Request * request)64 static BOOL MessageHandle(Service *service, Request *request)
65 {
66 (void)service;
67 return request != NULL;
68 }
69
GetTaskConfig(Service * service)70 static TaskConfig GetTaskConfig(Service *service)
71 {
72 (void)service;
73 TaskConfig config = { LEVEL_HIGH, PRI_NORMAL, STACK_SIZE, QUEUE_SIZE, SINGLE_TASK };
74 return config;
75 }
76
Init(void)77 static void Init(void)
78 {
79 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
80 POWER_HILOGI("Succeed to init power manager service");
81 }
82 SYS_SERVICE_INIT(Init);
83