1 /*
2  * Copyright (c) 2020-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 #ifndef BASE_STARTUP_INITLITE_SERVICEMANAGER_H
16 #define BASE_STARTUP_INITLITE_SERVICEMANAGER_H
17 
18 #include "init_service.h"
19 #include "cJSON.h"
20 #include "init_cmds.h"
21 #include "list.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define UID_STR_IN_CFG "uid"
30 #define GID_STR_IN_CFG "gid"
31 #define ONCE_STR_IN_CFG "once"
32 #define IMPORTANT_STR_IN_CFG "importance"
33 #define BIN_SH_NOT_ALLOWED "/bin/sh"
34 #define CRITICAL_STR_IN_CFG "critical"
35 #define DISABLED_STR_IN_CFG "disabled"
36 #define CONSOLE_STR_IN_CFG "console"
37 #define SANDBOX_STR_IN_CFG "sandbox"
38 #define D_CAPS_STR_IN_CFG "d-caps"
39 #define APL_STR_IN_CFG "apl"
40 #define CPU_CORE_STR_IN_CFG "cpucore"
41 #define MODULE_UPDATE_STR_IN_CFG "module-update"
42 #define PERIOD_STR_IN_CFG "period"
43 
44 #define MAX_SERVICES_CNT_IN_FILE 100
45 
46 typedef struct {
47     char *capStr;
48     unsigned int CapNum;
49 } CapStrCapNum;
50 
51 typedef struct {
52     int serviceCount;
53 } ServiceSpace;
54 
55 cJSON *GetArrayItem(const cJSON *fileRoot, int *arrSize, const char *arrName);
56 int ParseOneService(const cJSON *curItem, Service *service);
57 
58 void StartServiceByName(const char *serviceName);
59 void StopServiceByName(const char *serviceName);
60 void StopAllServices(int flags, const char **exclude, int size,
61     int (*filter)(const Service *service, const char **exclude, int size));
62 void ParseAllServices(const cJSON *fileRoot, const ConfigContext *context);
63 void ReleaseService(Service *service);
64 void LoadAccessTokenId(void);
65 Service *AddService(const char *name);
66 void DumpServiceHookExecute(const char *name, const char *info);
67 void ProcessControlFd(uint16_t type, const char *serviceCmd, const void *context);
68 int GetKillServiceSig(const char *name);
69 int WatchConsoleDevice(Service *service);
70 #ifdef __cplusplus
71 #if __cplusplus
72 }
73 #endif
74 #endif
75 
76 #endif // BASE_STARTUP_INITLITE_SERVICEMANAGER_H
77