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
21extern "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
32static 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 */
52int 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 */
69int 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 */
90int 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 */
106typedef void (*ParameterChgPtr)(const char *key, const char *value, void *context);
107int 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 */
123int RemoveParameterWatcher(const char *keyPrefix, ParameterChgPtr callback, void *context);
124
125/**
126 * @brief Synchronize saving persistent parameters.
127 *
128 * You can use this function to save system parameter in shared memory immediately.\n
129 *
130 * @return Returns <b>0</b> if the operation is successful;
131 * returns <b>-1</b> in other scenarios.
132 * @since 4.1
133 * @version 4.1
134*/
135int SaveParameters(void);
136const char *GetSecurityPatchTag(void);
137const char *GetOSFullName(void);
138const char *GetVersionId(void);
139const char *GetBuildRootHash(void);
140const char *GetOsReleaseType(void);
141int GetSdkApiVersion(void);
142
143const char *GetDeviceType(void);
144const char *GetProductModel(void);
145const char *GetManufacture(void);
146const char *GetBrand(void);
147const char *GetMarketName(void);
148const char *GetProductSeries(void);
149const char *GetSoftwareModel(void);
150const char *GetHardwareModel(void);
151const char *GetHardwareProfile(void);
152const char *GetSerial(void);
153const char *GetAbiList(void);
154const char *GetDisplayVersion(void);
155const char *GetIncrementalVersion(void);
156const char *GetBootloaderVersion(void);
157const char *GetBuildType(void);
158const char *GetBuildUser(void);
159const char *GetBuildHost(void);
160const char *GetBuildTime(void);
161int GetFirstApiVersion(void);
162int GetDevUdid(char *udid, int size);
163
164const char *AclGetSerial(void);
165int AclGetDevUdid(char *udid, int size);
166
167/**
168 * @brief Obtains a system parameter matching the specified <b>key</b>.
169 *
170 * If no system parameter is found, return -1.\n
171 *
172 * @param key Indicates the key for the system parameter to find.
173 * @return Returns the index for parameter;
174 * returns <b>handle</b> if a parameter is correct; returns <b>-1</b> in other scenarios.
175 * @since 1
176 * @version 1
177 */
178uint32_t FindParameter(const char *key);
179uint32_t GetParameterCommitId(uint32_t handle);
180int GetParameterName(uint32_t handle, char *key, uint32_t len);
181int GetParameterValue(uint32_t handle, char *value, uint32_t len);
182long long GetSystemCommitId(void);
183
184int32_t GetIntParameter(const char *key, int32_t def);
185uint32_t GetUintParameter(const char *key, uint32_t def);
186
187const char *GetDistributionOSName(void);
188const char *GetDistributionOSVersion(void);
189int GetDistributionOSApiVersion(void);
190const char *GetDistributionOSApiName(void);
191const char *GetDistributionOSReleaseType(void);
192
193#ifdef __cplusplus
194#if __cplusplus
195}
196#endif
197#endif /* __cplusplus */
198
199#endif // STARTUP_SYSPARAM_PARAMETER_API_H
200