1 /*
2  * Copyright (c) 2020 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 "dmslite.h"
17 
18 #include "dmsfwk_interface.h"
19 #include "dmslite_log.h"
20 
21 #include "ohos_init.h"
22 #include "samgr_lite.h"
23 
24 #define STACK_SIZE 0x1000
25 #define QUEUE_SIZE 20
26 #define EMPTY_SERVICE_NAME ""
27 
28 static const char *GetName(Service *service);
29 static BOOL Initialize(Service *service, Identity identity);
30 static BOOL MessageHandle(Service *service, Request *request);
31 static TaskConfig GetTaskConfig(Service *service);
32 
33 static DistributedService g_distributedService = {
34     .GetName = GetName,
35     .Initialize = Initialize,
36     .MessageHandle = MessageHandle,
37     .GetTaskConfig = GetTaskConfig
38 };
39 
GetName(Service * service)40 static const char *GetName(Service *service)
41 {
42     if (service == NULL) {
43         return EMPTY_SERVICE_NAME;
44     }
45     return DISTRIBUTED_SCHEDULE_SERVICE;
46 }
47 
Initialize(Service * service,Identity identity)48 static BOOL Initialize(Service *service, Identity identity)
49 {
50     if (service == NULL) {
51         return FALSE;
52     }
53 
54     ((DistributedService*) service)->identity = identity;
55     return TRUE;
56 }
57 
MessageHandle(Service * service,Request * request)58 static BOOL MessageHandle(Service *service, Request *request)
59 {
60     if (request == NULL || service == NULL) {
61         return FALSE;
62     }
63 
64     /* process for a specific service-level msgId can be added below */
65     HILOGW("[Unknown msgId = %d]", request->msgId);
66     return TRUE;
67 }
68 
GetTaskConfig(Service * service)69 static TaskConfig GetTaskConfig(Service *service)
70 {
71     TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, STACK_SIZE, QUEUE_SIZE, SINGLE_TASK};
72     return config;
73 }
74 
Init(void)75 static void Init(void)
76 {
77     BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_distributedService);
78     HILOGI("[dms service start %s]", result ? "success" : "failed");
79 }
80 SYS_SERVICE_INIT(Init);
81