• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 STARTUP_SYSPARAM_PARAMETER_API_H
17 #define STARTUP_SYSPARAM_PARAMETER_API_H
18 #include <stdint.h>
19 #ifdef __cplusplus
20 #if __cplusplus
21 extern "C" {
22 #endif
23 #endif /* __cplusplus */
24 
25 #define PARAM_CONST_VALUE_LEN_MAX 4096
26 #define PARAM_VALUE_LEN_MAX  96
27 #define PARAM_NAME_LEN_MAX  96
28 #define OS_FULL_NAME_LEN 128
29 #define VERSION_ID_MAX_LEN 256
30 #define PARAM_BUFFER_MAX (0x01 << 16)
31 
32 static const char EMPTY_STR[] = { "" };
33 
34 /**
35  * @brief Obtains a system parameter matching the specified <b>key</b>.
36  *
37  * If no system parameter is found, the <b>def</b> parameter will be returned.\n
38  *
39  * @param key Indicates the key for the system parameter to query.
40  * The value can contain lowercase letters, digits, underscores (_), and dots (.).
41  * Its length cannot exceed 32 bytes (including the end-of-text character in the string).
42  * @param def Indicates the default value to return when no query result is found.
43  * This parameter is specified by the caller.
44  * @param value Indicates the data buffer that stores the query result.
45  * This parameter is applied for and released by the caller and can be used as an output parameter.
46  * @param len Indicates the length of the data in the buffer.
47  * @return Returns the number of bytes of the system parameter if the operation is successful;
48  * returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios.
49  * @since 1
50  * @version 1
51  */
52 int GetParameter(const char *key, const char *def, char *value, uint32_t len);
53 
54 /**
55  * @brief Sets or updates a system parameter.
56  *
57  * You can use this function to set a system parameter that matches <b>key</b> as <b>value</b>.\n
58  *
59  * @param key Indicates the key for the parameter to set or update.
60  * The value can contain lowercase letters, digits, underscores (_), and dots (.).
61  * Its length cannot exceed 32 bytes (including the end-of-text character in the string).
62  * @param value Indicates the system parameter value.
63  * Its length cannot exceed 128 bytes (including the end-of-text character in the string).
64  * @return Returns <b>0</b> if the operation is successful;
65  * returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios.
66  * @since 1
67  * @version 1
68  */
69 int SetParameter(const char *key, const char *value);
70 
71 /**
72  * @brief Wait for a system parameter with specified value.
73  *
74  * You can use this function to wait a system parameter that matches <b>key</b> as <b>value</b>.\n
75  *
76  * @param key Indicates the key for the parameter to wait.
77  * The value can contain lowercase letters, digits, underscores (_), and dots (.).
78  * Its length cannot exceed 96 bytes (including the end-of-text character in the string).
79  * @param value Indicates the system parameter value.
80  * Its length cannot exceed 96 bytes (including the end-of-text character in the string).
81  * value can use "*" to do arbitrary match.
82  * @param timeout Indicates the timeout value, in seconds.
83  * <=0 means wait for ever.
84  * >0 means wait for specified seconds
85  * @return Returns <b>0</b> if the operation is successful;
86  * returns <b>-10</b> if timeout; returns <b>-1</b> in other scenarios.
87  * @since 1.1
88  * @version 1.1
89  */
90 int WaitParameter(const char *key, const char *value, int timeout);
91 
92 /**
93  * @brief Watch for system parameter values.
94  *
95  * You can use this function to watch system parameter values.\n
96  *
97  * @param keyPrefix Indicates the key prefix for the parameter to be watched.
98  * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.".
99  * @param callback Indicates value change callback.
100  * If callback is NULL, it means to cancel the watch.
101  * @return Returns <b>0</b> if the operation is successful;
102  * returns <b>-1</b> in other scenarios.
103  * @since 1.1
104  * @version 1.1
105  */
106 typedef void (*ParameterChgPtr)(const char *key, const char *value, void *context);
107 int WatchParameter(const char *keyPrefix, ParameterChgPtr callback, void *context);
108 
109 /**
110  * @brief Remove parameter watcher.
111  *
112  * You can use this function to remove system parameter watcher.\n
113  *
114  * @param keyPrefix Indicates the key prefix for the parameter to be watched.
115  * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.".
116  * @param callback Indicates value change callback.
117  * If callback is NULL, it means to cancel the watch.
118  * @return Returns <b>0</b> if the operation is successful;
119  * returns <b>-1</b> in other scenarios.
120  * @since 1.1
121  * @version 1.1
122  */
123 int RemoveParameterWatcher(const char *keyPrefix, ParameterChgPtr callback, void *context);
124 
125 const char *GetSecurityPatchTag(void);
126 const char *GetOSFullName(void);
127 const char *GetVersionId(void);
128 const char *GetBuildRootHash(void);
129 const char *GetOsReleaseType(void);
130 int GetSdkApiVersion(void);
131 
132 const char *GetDeviceType(void);
133 const char *GetProductModel(void);
134 const char *GetManufacture(void);
135 const char *GetBrand(void);
136 const char *GetMarketName(void);
137 const char *GetProductSeries(void);
138 const char *GetSoftwareModel(void);
139 const char *GetHardwareModel(void);
140 const char *GetHardwareProfile(void);
141 const char *GetSerial(void);
142 const char *GetAbiList(void);
143 const char *GetDisplayVersion(void);
144 const char *GetIncrementalVersion(void);
145 const char *GetBootloaderVersion(void);
146 const char *GetBuildType(void);
147 const char *GetBuildUser(void);
148 const char *GetBuildHost(void);
149 const char *GetBuildTime(void);
150 int GetFirstApiVersion(void);
151 int GetDevUdid(char *udid, int size);
152 
153 const char *AclGetSerial(void);
154 int AclGetDevUdid(char *udid, int size);
155 
156 /**
157  * @brief Obtains a system parameter matching the specified <b>key</b>.
158  *
159  * If no system parameter is found, return -1.\n
160  *
161  * @param key Indicates the key for the system parameter to find.
162  * @return Returns the index for parameter;
163  * returns <b>handle</b> if a parameter is correct; returns <b>-1</b> in other scenarios.
164  * @since 1
165  * @version 1
166  */
167 uint32_t FindParameter(const char *key);
168 uint32_t GetParameterCommitId(uint32_t handle);
169 int GetParameterName(uint32_t handle, char *key, uint32_t len);
170 int GetParameterValue(uint32_t handle, char *value, uint32_t len);
171 long long GetSystemCommitId(void);
172 
173 int32_t GetIntParameter(const char *key, int32_t def);
174 uint32_t GetUintParameter(const char *key, uint32_t def);
175 
176 const char *GetDistributionOSName(void);
177 const char *GetDistributionOSVersion(void);
178 int GetDistributionOSApiVersion(void);
179 const char *GetDistributionOSReleaseType(void);
180 
181 #ifdef __cplusplus
182 #if __cplusplus
183 }
184 #endif
185 #endif /* __cplusplus */
186 
187 #endif // STARTUP_SYSPARAM_PARAMETER_API_H
188