• 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_OS_ADAPTER_H
17 #define BASE_STARTUP_PARAM_OS_ADAPTER_H
18 #include <stdint.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <string.h>
23 #if !(defined __LITEOS_A__ || defined __LITEOS_M__)
24 #include <sys/syscall.h>
25 #include "loop_event.h"
26 #else
27 #include <time.h>
28 #endif
29 
30 #ifndef __LITEOS_M__
31 #include <pthread.h>
32 #endif
33 #include "param_utils.h"
34 #include "param_common.h"
35 #ifdef __cplusplus
36 #if __cplusplus
37 extern "C" {
38 #endif
39 #endif
40 
41 #ifndef STATIC_INLINE
42 #ifdef STARTUP_INIT_TEST
43 #define STATIC_INLINE
44 #else
45 #define STATIC_INLINE static inline
46 #endif
47 #endif
48 
49 #define PARAM_WORKSPACE_INVALID ((uint32_t)-1)
50 #define PARAM_WORKSPACE_MIN (1024)
51 /*
52     length for parameter = node size + data size
53     xxxx.xxxx.xxxx.xxxx
54     node size:
55     24 * (count(.) + 1) + strlen(xxxx.xxxx.xxxx.xxxx)
56     data size
57     strlen(xxxx.xxxx.xxxx.xxxx) + 96
58 
59     dac size
60      24 * (count(.) + 1)  + sizeof(ParamSecurityNode)
61 */
62 #define DAC_DEFAULT_GROUP 0
63 #define DAC_DEFAULT_USER 0
64 
65 #ifdef STARTUP_INIT_TEST
66 #define DAC_DEFAULT_MODE 0777
67 #define PARAM_WORKSPACE_DEF (1024 * 80)
68 #define PARAM_WORKSPACE_MAX (1024 * 80)
69 #define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_DEF
70 #else
71 
72 #ifdef __LITEOS_M__
73 #define DAC_DEFAULT_MODE 0777
74 #ifndef PARAM_WORKSPACE_MAX
75 #define PARAM_WORKSPACE_MAX (1024 * 5)
76 #endif
77 #define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX
78 #define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX
79 #else // __LITEOS_M__
80 
81 #ifdef __LITEOS_A__
82 #define DAC_DEFAULT_MODE 0777
83 #define PARAM_WORKSPACE_MAX (1024 * 10)
84 #define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_MAX
85 #define PARAM_WORKSPACE_DEF PARAM_WORKSPACE_MAX
86 #else // __LITEOS_A__
87 #define DAC_DEFAULT_MODE 0774
88 #ifdef PARAM_TEST_PERFORMANCE
89 #define PARAM_WORKSPACE_MAX (1024 * 1024 * 10)
90 #else
91 #define PARAM_WORKSPACE_MAX (80 * 1024)
92 #endif
93 #define PARAM_WORKSPACE_SMALL (1024 * 10)
94 #define PARAM_WORKSPACE_DEF (1024 * 30)
95 #define PARAM_WORKSPACE_DAC (1024 * 20)
96 #endif // __LITEOS_A__
97 #endif // __LITEOS_M__
98 #endif // STARTUP_INIT_TEST
99 
100 #ifndef PARAM_WORKSPACE_DAC
101 #define PARAM_WORKSPACE_DAC PARAM_WORKSPACE_SMALL
102 #endif
103 
104 // support timer
105 #if defined __LITEOS_A__ || defined __LITEOS_M__
106 struct ParamTimer_;
107 typedef void (*ProcessTimer)(const struct ParamTimer_ *taskHandle, void *context);
108 typedef struct ParamTimer_ {
109     timer_t timerId;
110     uint64_t repeat;
111     ProcessTimer timeProcessor;
112     void *context;
113 } ParamTimer;
114 
115 typedef ParamTimer *ParamTaskPtr;
116 #else
117 typedef LoopBase *ParamTaskPtr;
118 typedef void (*ProcessTimer)(const ParamTaskPtr taskHandle, void *context);
119 #endif
120 
121 int ParamTimerCreate(ParamTaskPtr *timer, ProcessTimer process, void *context);
122 int ParamTimerStart(const ParamTaskPtr timer, uint64_t timeout, uint64_t repeat);
123 void ParamTimerClose(ParamTaskPtr timer);
124 
125 INIT_LOCAL_API void  paramMutexEnvInit(void);
126 INIT_LOCAL_API int ParamRWMutexCreate(ParamRWMutex *lock);
127 INIT_LOCAL_API int ParamRWMutexWRLock(ParamRWMutex *lock);
128 INIT_LOCAL_API int ParamRWMutexRDLock(ParamRWMutex *lock);
129 INIT_LOCAL_API int ParamRWMutexUnlock(ParamRWMutex *lock);
130 INIT_LOCAL_API int ParamRWMutexDelete(ParamRWMutex *lock);
131 
132 INIT_LOCAL_API int ParamMutexCreate(ParamMutex *mutex);
133 INIT_LOCAL_API int ParamMutexPend(ParamMutex *mutex);
134 INIT_LOCAL_API int ParamMutexPost(ParamMutex *mutex);
135 INIT_LOCAL_API int ParamMutexDelete(ParamMutex *mutex);
136 
137 #ifdef WORKSPACE_AREA_NEED_MUTEX
138 #define PARAMSPACE_AREA_INIT_LOCK(workspace) ParamRWMutexCreate(&workspace->rwlock)
139 #define PARAMSPACE_AREA_RW_LOCK(workspace) ParamRWMutexWRLock(&workspace->rwlock)
140 #define PARAMSPACE_AREA_RD_LOCK(workspace) ParamRWMutexRDLock(&workspace->rwlock)
141 #define PARAMSPACE_AREA_RW_UNLOCK(workspace) ParamRWMutexUnlock(&workspace->rwlock)
142 #else
143 #define PARAMSPACE_AREA_INIT_LOCK(rwlock) (void)(rwlock)
144 #define PARAMSPACE_AREA_RW_LOCK(rwlock) (void)(rwlock)
145 #define PARAMSPACE_AREA_RD_LOCK(rwlock) (void)(rwlock)
146 #define PARAMSPACE_AREA_RW_UNLOCK(rwlock) (void)(rwlock)
147 #endif
148 
149 INIT_LOCAL_API void *GetSharedMem(const char *fileName, MemHandle *handle, uint32_t spaceSize, int readOnly);
150 INIT_LOCAL_API void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize);
151 
152 #ifdef __cplusplus
153 #if __cplusplus
154 }
155 #endif
156 #endif
157 
158 #endif // BASE_STARTUP_PARAM_OS_ADAPTER_H