• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef BASE_STARTUP_PARAM_MANAGER_H
17 #define BASE_STARTUP_PARAM_MANAGER_H
18 #include <stdio.h>
19 #include <string.h>
20 
21 #include "param_message.h"
22 #include "param_persist.h"
23 #include "param_security.h"
24 #include "param_trie.h"
25 #include "param_utils.h"
26 #include "sys_param.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif
32 #endif
33 
34 #define futex(addr1, op, val, rel, addr2, val3) syscall(SYS_futex, addr1, op, val, rel, addr2, val3)
35 #define futex_wait_always(addr1) syscall(SYS_futex, addr1, FUTEX_WAIT, *(int *)(addr1), 0, 0, 0)
36 #define futex_wake_single(addr1) syscall(SYS_futex, addr1, FUTEX_WAKE, 1, 0, 0, 0)
37 
38 typedef struct {
39     uint32_t flags;
40     WorkSpace paramSpace;
41     ParamSecurityLabel *securityLabel;
42     ParamSecurityOps paramSecurityOps;
43     ParamTaskPtr serverTask;
44     ParamTaskPtr timer;
45     ParamTaskPtr watcherTask;
46     char buffer[PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX];
47 } ParamWorkSpace;
48 
49 typedef struct {
50     uint32_t flags;
51     ParamTaskPtr saveTimer;
52     time_t lastSaveTimer;
53     PersistParamOps persistParamOps;
54 } ParamPersistWorkSpace;
55 
56 int InitParamWorkSpace(ParamWorkSpace *workSpace, int onlyRead);
57 void CloseParamWorkSpace(ParamWorkSpace *workSpace);
58 
59 int ReadParamWithCheck(const ParamWorkSpace *workSpace, const char *name, uint32_t op, ParamHandle *handle);
60 int ReadParamValue(const ParamWorkSpace *workSpace, ParamHandle handle, char *value, uint32_t *len);
61 int ReadParamName(const ParamWorkSpace *workSpace, ParamHandle handle, char *name, uint32_t len);
62 int ReadParamCommitId(const ParamWorkSpace *workSpace, ParamHandle handle, uint32_t *commitId);
63 
64 int CheckParamName(const char *name, int paramInfo);
65 int CheckParamPermission(const ParamWorkSpace *workSpace,
66     const ParamSecurityLabel *srcLabel, const char *name, uint32_t mode);
67 
68 typedef void (*TraversalParamPtr)(ParamHandle handle, void *context);
69 typedef struct {
70     TraversalParamPtr traversalParamPtr;
71     void *context;
72     const char *prefix;
73 } ParamTraversalContext;
74 int TraversalParam(const ParamWorkSpace *workSpace,
75     const char *prefix, TraversalParamPtr walkFunc, void *cookie);
76 
77 ParamWorkSpace *GetParamWorkSpace(void);
78 ParamWorkSpace *GetClientParamWorkSpace(void);
79 void DumpParameters(const ParamWorkSpace *workSpace, int verbose);
80 #ifdef __cplusplus
81 #if __cplusplus
82 }
83 #endif
84 #endif
85 #endif