• 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_cmdexecutor.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 
33 #define GROUP_DEFAULT_PATH STARTUP_INIT_UT_PATH"/system/etc"
34 #define BOOT_GROUP_NAME "bootgroup"
35 #define BOOT_GROUP_DEFAULT "device.boot.group"
36 
37 typedef enum {
38     GROUP_BOOT,
39     GROUP_CHARGE,
40     GROUP_UNKNOW
41 } InitGroupType;
42 
43 typedef enum {
44     NODE_TYPE_JOBS,
45     NODE_TYPE_SERVICES,
46     NODE_TYPE_PLUGINS,
47     NODE_TYPE_CMDS,
48     NODE_TYPE_GROUPS,
49     NODE_TYPE_MAX
50 } InitNodeType;
51 
52 typedef struct InitGroupNode_ {
53     struct InitGroupNode_ *next;
54     HashNode hashNode;
55     unsigned char type;
56     union {
57         Service *service;
58         PluginCmd *cmd;
59     } data;
60     char name[0];
61 } InitGroupNode;
62 
63 typedef struct {
64     uint8_t initFlags;
65     InitGroupType groupMode;
66     InitGroupNode *groupNodes[NODE_TYPE_MAX];
67     HashMapHandle hashMap[NODE_TYPE_GROUPS];
68     char groupModeStr[GROUP_NAME_MAX_LENGTH];
69 } InitWorkspace;
70 
71 void InitServiceSpace(void);
72 void CloseServiceSpace(void);
73 int InitParseGroupCfg(void);
74 
75 int GenerateHashCode(const char *key);
76 InitGroupNode *AddGroupNode(int type, const char *name);
77 InitGroupNode *GetGroupNode(int type, const char *name);
78 InitGroupNode *GetNextGroupNode(int type, const InitGroupNode *curr);
79 void DelGroupNode(int type, const char *name);
80 int CheckNodeValid(int type, const char *name);
81 HashMapHandle GetGroupHashMap(int type);
82 #ifdef STARTUP_INIT_TEST
83 InitWorkspace *GetInitWorkspace(void);
84 #endif
85 int GetBootModeFromMisc(void);
86 void clearMisc(void);
87 void ReleaseCmd(PluginCmd *cmd);
88 #ifdef __cplusplus
89 #if __cplusplus
90 }
91 #endif
92 #endif
93 
94 #endif // STARTUP_INIT_GROUP_MANAGER_H
95