1cb69b360Sopenharmony_ci/*
2cb69b360Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3cb69b360Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cb69b360Sopenharmony_ci * you may not use this file except in compliance with the License.
5cb69b360Sopenharmony_ci * You may obtain a copy of the License at
6cb69b360Sopenharmony_ci *
7cb69b360Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cb69b360Sopenharmony_ci *
9cb69b360Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cb69b360Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cb69b360Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb69b360Sopenharmony_ci * See the License for the specific language governing permissions and
13cb69b360Sopenharmony_ci * limitations under the License.
14cb69b360Sopenharmony_ci */
15cb69b360Sopenharmony_ci
16cb69b360Sopenharmony_ci#include <ohos_init.h>
17cb69b360Sopenharmony_ci#include <samgr_lite.h>
18cb69b360Sopenharmony_ci#include <service.h>
19cb69b360Sopenharmony_ci
20cb69b360Sopenharmony_ci#include <unistd.h>
21cb69b360Sopenharmony_ci#include <pthread.h>
22cb69b360Sopenharmony_ci
23cb69b360Sopenharmony_ci#include "hilog_wrapper.h"
24cb69b360Sopenharmony_ci#include "power_mgr.h"
25cb69b360Sopenharmony_ci
26cb69b360Sopenharmony_ci#define STACK_SIZE      0x800
27cb69b360Sopenharmony_ci#define QUEUE_SIZE      20
28cb69b360Sopenharmony_ci
29cb69b360Sopenharmony_citypedef struct {
30cb69b360Sopenharmony_ci    INHERIT_SERVICE;
31cb69b360Sopenharmony_ci    Identity identity;
32cb69b360Sopenharmony_ci} PowerMgrService;
33cb69b360Sopenharmony_ci
34cb69b360Sopenharmony_cistatic const char *GetName(Service *service);
35cb69b360Sopenharmony_cistatic BOOL Initialize(Service *service, Identity identity);
36cb69b360Sopenharmony_cistatic BOOL MessageHandle(Service *service, Request *request);
37cb69b360Sopenharmony_cistatic TaskConfig GetTaskConfig(Service *service);
38cb69b360Sopenharmony_ci
39cb69b360Sopenharmony_cistatic PowerMgrService g_service = {
40cb69b360Sopenharmony_ci    .GetName = GetName,
41cb69b360Sopenharmony_ci    .Initialize = Initialize,
42cb69b360Sopenharmony_ci    .MessageHandle = MessageHandle,
43cb69b360Sopenharmony_ci    .GetTaskConfig = GetTaskConfig,
44cb69b360Sopenharmony_ci    .identity = { -1, -1, NULL }
45cb69b360Sopenharmony_ci};
46cb69b360Sopenharmony_ci
47cb69b360Sopenharmony_cistatic const char *GetName(Service *service)
48cb69b360Sopenharmony_ci{
49cb69b360Sopenharmony_ci    (void)service;
50cb69b360Sopenharmony_ci    return POWER_MANAGE_SERVICE;
51cb69b360Sopenharmony_ci}
52cb69b360Sopenharmony_ci
53cb69b360Sopenharmony_cistatic BOOL Initialize(Service *service, Identity identity)
54cb69b360Sopenharmony_ci{
55cb69b360Sopenharmony_ci    if (service == NULL) {
56cb69b360Sopenharmony_ci        POWER_HILOGE("Invalid service");
57cb69b360Sopenharmony_ci        return FALSE;
58cb69b360Sopenharmony_ci    }
59cb69b360Sopenharmony_ci    PowerMgrService *pms = (PowerMgrService *)(service);
60cb69b360Sopenharmony_ci    pms->identity = identity;
61cb69b360Sopenharmony_ci    return TRUE;
62cb69b360Sopenharmony_ci}
63cb69b360Sopenharmony_ci
64cb69b360Sopenharmony_cistatic BOOL MessageHandle(Service *service, Request *request)
65cb69b360Sopenharmony_ci{
66cb69b360Sopenharmony_ci    (void)service;
67cb69b360Sopenharmony_ci    return request != NULL;
68cb69b360Sopenharmony_ci}
69cb69b360Sopenharmony_ci
70cb69b360Sopenharmony_cistatic TaskConfig GetTaskConfig(Service *service)
71cb69b360Sopenharmony_ci{
72cb69b360Sopenharmony_ci    (void)service;
73cb69b360Sopenharmony_ci    TaskConfig config = { LEVEL_HIGH, PRI_NORMAL, STACK_SIZE, QUEUE_SIZE, SINGLE_TASK };
74cb69b360Sopenharmony_ci    return config;
75cb69b360Sopenharmony_ci}
76cb69b360Sopenharmony_ci
77cb69b360Sopenharmony_cistatic void Init(void)
78cb69b360Sopenharmony_ci{
79cb69b360Sopenharmony_ci    SAMGR_GetInstance()->RegisterService((Service *)&g_service);
80cb69b360Sopenharmony_ci    POWER_HILOGI("Succeed to init power manager service");
81cb69b360Sopenharmony_ci}
82cb69b360Sopenharmony_ciSYS_SERVICE_INIT(Init);
83