• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 STARTUP_INIT_GROUP_MANAGER_H
16 #define STARTUP_INIT_GROUP_MANAGER_H
17 #include <stdlib.h>
18 #include <string.h>
19 #include "init_service.h"
20 #include "init_hashmap.h"
21 #include "init_plugin_manager.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define GROUP_IMPORT_MAX_LEVEL 5
30 #define GROUP_NAME_MAX_LENGTH 64
31 #define GROUP_HASHMAP_BUCKET 32
32 #ifdef STARTUP_INIT_TEST
33 #define GROUP_DEFAULT_PATH "/data/init_ut"
34 #define BOOT_CMD_LINE "/data/init_ut/cmdline"
35 #else
36 #define GROUP_DEFAULT_PATH "/system/etc"
37 #define BOOT_CMD_LINE "/proc/cmdline"
38 #endif
39 #define BOOT_GROUP_NAME "bootgroup"
40 #define BOOT_GROUP_DEFAULT "device.boot.group"
41 
42 typedef enum {
43     GROUP_BOOT,
44     GROUP_CHARING,
45     GROUP_UNKNOW
46 } InitGroupType;
47 
48 typedef enum {
49     NODE_TYPE_JOBS,
50     NODE_TYPE_SERVICES,
51     NODE_TYPE_PLUGINS,
52     NODE_TYPE_CMDS,
53     NODE_TYPE_GROUPS,
54     NODE_TYPE_MAX
55 } InitNodeType;
56 
57 typedef struct InitGroupNode_ {
58     struct InitGroupNode_ *next;
59     HashNode hashNode;
60     unsigned char type;
61     union {
62         Service *service;
63         PluginInfo *pluginInfo;
64         PluginCmd *cmd;
65     } data;
66     char name[0];
67 } InitGroupNode;
68 
69 typedef struct {
70     uint8_t initFlags;
71     InitGroupType groupMode;
72     InitGroupNode *groupNodes[NODE_TYPE_MAX];
73     HashMapHandle hashMap[NODE_TYPE_GROUPS];
74     char groupModeStr[GROUP_NAME_MAX_LENGTH];
75 } InitWorkspace;
76 
77 void InitServiceSpace(void);
78 int InitParseGroupCfg(void);
79 
80 int GenerateHashCode(const char *key);
81 InitGroupNode *AddGroupNode(int type, const char *name);
82 InitGroupNode *GetGroupNode(int type, const char *name);
83 InitGroupNode *GetNextGroupNode(int type, const InitGroupNode *curr);
84 void DelGroupNode(int type, const char *name);
85 int CheckNodeValid(int type, const char *name);
86 HashMapHandle GetGroupHashMap(int type);
87 #ifdef STARTUP_INIT_TEST
88 InitWorkspace *GetInitWorkspace(void);
89 #endif
90 int GetBootModeFromMisc(void);
91 #ifdef __cplusplus
92 #if __cplusplus
93 }
94 #endif
95 #endif
96 
97 #endif // STARTUP_INIT_GROUP_MANAGER_H
98