1d9f0492fSopenharmony_ci/*
2d9f0492fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3d9f0492fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d9f0492fSopenharmony_ci * you may not use this file except in compliance with the License.
5d9f0492fSopenharmony_ci * You may obtain a copy of the License at
6d9f0492fSopenharmony_ci *
7d9f0492fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d9f0492fSopenharmony_ci *
9d9f0492fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d9f0492fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d9f0492fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d9f0492fSopenharmony_ci * See the License for the specific language governing permissions and
13d9f0492fSopenharmony_ci * limitations under the License.
14d9f0492fSopenharmony_ci */
15d9f0492fSopenharmony_ci
16d9f0492fSopenharmony_ci#ifndef STARTUP_SYSPARAM_PARAMETER_API_H
17d9f0492fSopenharmony_ci#define STARTUP_SYSPARAM_PARAMETER_API_H
18d9f0492fSopenharmony_ci#include <stdint.h>
19d9f0492fSopenharmony_ci#ifdef __cplusplus
20d9f0492fSopenharmony_ci#if __cplusplus
21d9f0492fSopenharmony_ciextern "C" {
22d9f0492fSopenharmony_ci#endif
23d9f0492fSopenharmony_ci#endif /* __cplusplus */
24d9f0492fSopenharmony_ci
25d9f0492fSopenharmony_ci#define PARAM_CONST_VALUE_LEN_MAX 4096
26d9f0492fSopenharmony_ci#define PARAM_VALUE_LEN_MAX  96
27d9f0492fSopenharmony_ci#define PARAM_NAME_LEN_MAX  96
28d9f0492fSopenharmony_ci#define OS_FULL_NAME_LEN 128
29d9f0492fSopenharmony_ci#define VERSION_ID_MAX_LEN 256
30d9f0492fSopenharmony_ci#define PARAM_BUFFER_MAX (0x01 << 16)
31d9f0492fSopenharmony_ci
32d9f0492fSopenharmony_cistatic const char EMPTY_STR[] = { "" };
33d9f0492fSopenharmony_ci
34d9f0492fSopenharmony_ci/**
35d9f0492fSopenharmony_ci * @brief Obtains a system parameter matching the specified <b>key</b>.
36d9f0492fSopenharmony_ci *
37d9f0492fSopenharmony_ci * If no system parameter is found, the <b>def</b> parameter will be returned.\n
38d9f0492fSopenharmony_ci *
39d9f0492fSopenharmony_ci * @param key Indicates the key for the system parameter to query.
40d9f0492fSopenharmony_ci * The value can contain lowercase letters, digits, underscores (_), and dots (.).
41d9f0492fSopenharmony_ci * Its length cannot exceed 32 bytes (including the end-of-text character in the string).
42d9f0492fSopenharmony_ci * @param def Indicates the default value to return when no query result is found.
43d9f0492fSopenharmony_ci * This parameter is specified by the caller.
44d9f0492fSopenharmony_ci * @param value Indicates the data buffer that stores the query result.
45d9f0492fSopenharmony_ci * This parameter is applied for and released by the caller and can be used as an output parameter.
46d9f0492fSopenharmony_ci * @param len Indicates the length of the data in the buffer.
47d9f0492fSopenharmony_ci * @return Returns the number of bytes of the system parameter if the operation is successful;
48d9f0492fSopenharmony_ci * returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios.
49d9f0492fSopenharmony_ci * @since 1
50d9f0492fSopenharmony_ci * @version 1
51d9f0492fSopenharmony_ci */
52d9f0492fSopenharmony_ciint GetParameter(const char *key, const char *def, char *value, uint32_t len);
53d9f0492fSopenharmony_ci
54d9f0492fSopenharmony_ci/**
55d9f0492fSopenharmony_ci * @brief Sets or updates a system parameter.
56d9f0492fSopenharmony_ci *
57d9f0492fSopenharmony_ci * You can use this function to set a system parameter that matches <b>key</b> as <b>value</b>.\n
58d9f0492fSopenharmony_ci *
59d9f0492fSopenharmony_ci * @param key Indicates the key for the parameter to set or update.
60d9f0492fSopenharmony_ci * The value can contain lowercase letters, digits, underscores (_), and dots (.).
61d9f0492fSopenharmony_ci * Its length cannot exceed 32 bytes (including the end-of-text character in the string).
62d9f0492fSopenharmony_ci * @param value Indicates the system parameter value.
63d9f0492fSopenharmony_ci * Its length cannot exceed 128 bytes (including the end-of-text character in the string).
64d9f0492fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful;
65d9f0492fSopenharmony_ci * returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios.
66d9f0492fSopenharmony_ci * @since 1
67d9f0492fSopenharmony_ci * @version 1
68d9f0492fSopenharmony_ci */
69d9f0492fSopenharmony_ciint SetParameter(const char *key, const char *value);
70d9f0492fSopenharmony_ci
71d9f0492fSopenharmony_ci/**
72d9f0492fSopenharmony_ci * @brief Wait for a system parameter with specified value.
73d9f0492fSopenharmony_ci *
74d9f0492fSopenharmony_ci * You can use this function to wait a system parameter that matches <b>key</b> as <b>value</b>.\n
75d9f0492fSopenharmony_ci *
76d9f0492fSopenharmony_ci * @param key Indicates the key for the parameter to wait.
77d9f0492fSopenharmony_ci * The value can contain lowercase letters, digits, underscores (_), and dots (.).
78d9f0492fSopenharmony_ci * Its length cannot exceed 96 bytes (including the end-of-text character in the string).
79d9f0492fSopenharmony_ci * @param value Indicates the system parameter value.
80d9f0492fSopenharmony_ci * Its length cannot exceed 96 bytes (including the end-of-text character in the string).
81d9f0492fSopenharmony_ci * value can use "*" to do arbitrary match.
82d9f0492fSopenharmony_ci * @param timeout Indicates the timeout value, in seconds.
83d9f0492fSopenharmony_ci * <=0 means wait for ever.
84d9f0492fSopenharmony_ci * >0 means wait for specified seconds
85d9f0492fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful;
86d9f0492fSopenharmony_ci * returns <b>-10</b> if timeout; returns <b>-1</b> in other scenarios.
87d9f0492fSopenharmony_ci * @since 1.1
88d9f0492fSopenharmony_ci * @version 1.1
89d9f0492fSopenharmony_ci */
90d9f0492fSopenharmony_ciint WaitParameter(const char *key, const char *value, int timeout);
91d9f0492fSopenharmony_ci
92d9f0492fSopenharmony_ci/**
93d9f0492fSopenharmony_ci * @brief Watch for system parameter values.
94d9f0492fSopenharmony_ci *
95d9f0492fSopenharmony_ci * You can use this function to watch system parameter values.\n
96d9f0492fSopenharmony_ci *
97d9f0492fSopenharmony_ci * @param keyPrefix Indicates the key prefix for the parameter to be watched.
98d9f0492fSopenharmony_ci * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.".
99d9f0492fSopenharmony_ci * @param callback Indicates value change callback.
100d9f0492fSopenharmony_ci * If callback is NULL, it means to cancel the watch.
101d9f0492fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful;
102d9f0492fSopenharmony_ci * returns <b>-1</b> in other scenarios.
103d9f0492fSopenharmony_ci * @since 1.1
104d9f0492fSopenharmony_ci * @version 1.1
105d9f0492fSopenharmony_ci */
106d9f0492fSopenharmony_citypedef void (*ParameterChgPtr)(const char *key, const char *value, void *context);
107d9f0492fSopenharmony_ciint WatchParameter(const char *keyPrefix, ParameterChgPtr callback, void *context);
108d9f0492fSopenharmony_ci
109d9f0492fSopenharmony_ci/**
110d9f0492fSopenharmony_ci * @brief Remove parameter watcher.
111d9f0492fSopenharmony_ci *
112d9f0492fSopenharmony_ci * You can use this function to remove system parameter watcher.\n
113d9f0492fSopenharmony_ci *
114d9f0492fSopenharmony_ci * @param keyPrefix Indicates the key prefix for the parameter to be watched.
115d9f0492fSopenharmony_ci * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.".
116d9f0492fSopenharmony_ci * @param callback Indicates value change callback.
117d9f0492fSopenharmony_ci * If callback is NULL, it means to cancel the watch.
118d9f0492fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful;
119d9f0492fSopenharmony_ci * returns <b>-1</b> in other scenarios.
120d9f0492fSopenharmony_ci * @since 1.1
121d9f0492fSopenharmony_ci * @version 1.1
122d9f0492fSopenharmony_ci */
123d9f0492fSopenharmony_ciint RemoveParameterWatcher(const char *keyPrefix, ParameterChgPtr callback, void *context);
124d9f0492fSopenharmony_ci
125d9f0492fSopenharmony_ci/**
126d9f0492fSopenharmony_ci * @brief Synchronize saving persistent parameters.
127d9f0492fSopenharmony_ci *
128d9f0492fSopenharmony_ci * You can use this function to save system parameter in shared memory immediately.\n
129d9f0492fSopenharmony_ci *
130d9f0492fSopenharmony_ci * @return Returns <b>0</b> if the operation is successful;
131d9f0492fSopenharmony_ci * returns <b>-1</b> in other scenarios.
132d9f0492fSopenharmony_ci * @since 4.1
133d9f0492fSopenharmony_ci * @version 4.1
134d9f0492fSopenharmony_ci*/
135d9f0492fSopenharmony_ciint SaveParameters(void);
136d9f0492fSopenharmony_ciconst char *GetSecurityPatchTag(void);
137d9f0492fSopenharmony_ciconst char *GetOSFullName(void);
138d9f0492fSopenharmony_ciconst char *GetVersionId(void);
139d9f0492fSopenharmony_ciconst char *GetBuildRootHash(void);
140d9f0492fSopenharmony_ciconst char *GetOsReleaseType(void);
141d9f0492fSopenharmony_ciint GetSdkApiVersion(void);
142d9f0492fSopenharmony_ci
143d9f0492fSopenharmony_ciconst char *GetDeviceType(void);
144d9f0492fSopenharmony_ciconst char *GetProductModel(void);
145d9f0492fSopenharmony_ciconst char *GetManufacture(void);
146d9f0492fSopenharmony_ciconst char *GetBrand(void);
147d9f0492fSopenharmony_ciconst char *GetMarketName(void);
148d9f0492fSopenharmony_ciconst char *GetProductSeries(void);
149d9f0492fSopenharmony_ciconst char *GetSoftwareModel(void);
150d9f0492fSopenharmony_ciconst char *GetHardwareModel(void);
151d9f0492fSopenharmony_ciconst char *GetHardwareProfile(void);
152d9f0492fSopenharmony_ciconst char *GetSerial(void);
153d9f0492fSopenharmony_ciconst char *GetAbiList(void);
154d9f0492fSopenharmony_ciconst char *GetDisplayVersion(void);
155d9f0492fSopenharmony_ciconst char *GetIncrementalVersion(void);
156d9f0492fSopenharmony_ciconst char *GetBootloaderVersion(void);
157d9f0492fSopenharmony_ciconst char *GetBuildType(void);
158d9f0492fSopenharmony_ciconst char *GetBuildUser(void);
159d9f0492fSopenharmony_ciconst char *GetBuildHost(void);
160d9f0492fSopenharmony_ciconst char *GetBuildTime(void);
161d9f0492fSopenharmony_ciint GetFirstApiVersion(void);
162d9f0492fSopenharmony_ciint GetDevUdid(char *udid, int size);
163d9f0492fSopenharmony_ci
164d9f0492fSopenharmony_ciconst char *AclGetSerial(void);
165d9f0492fSopenharmony_ciint AclGetDevUdid(char *udid, int size);
166d9f0492fSopenharmony_ci
167d9f0492fSopenharmony_ci/**
168d9f0492fSopenharmony_ci * @brief Obtains a system parameter matching the specified <b>key</b>.
169d9f0492fSopenharmony_ci *
170d9f0492fSopenharmony_ci * If no system parameter is found, return -1.\n
171d9f0492fSopenharmony_ci *
172d9f0492fSopenharmony_ci * @param key Indicates the key for the system parameter to find.
173d9f0492fSopenharmony_ci * @return Returns the index for parameter;
174d9f0492fSopenharmony_ci * returns <b>handle</b> if a parameter is correct; returns <b>-1</b> in other scenarios.
175d9f0492fSopenharmony_ci * @since 1
176d9f0492fSopenharmony_ci * @version 1
177d9f0492fSopenharmony_ci */
178d9f0492fSopenharmony_ciuint32_t FindParameter(const char *key);
179d9f0492fSopenharmony_ciuint32_t GetParameterCommitId(uint32_t handle);
180d9f0492fSopenharmony_ciint GetParameterName(uint32_t handle, char *key, uint32_t len);
181d9f0492fSopenharmony_ciint GetParameterValue(uint32_t handle, char *value, uint32_t len);
182d9f0492fSopenharmony_cilong long GetSystemCommitId(void);
183d9f0492fSopenharmony_ci
184d9f0492fSopenharmony_ciint32_t GetIntParameter(const char *key, int32_t def);
185d9f0492fSopenharmony_ciuint32_t GetUintParameter(const char *key, uint32_t def);
186d9f0492fSopenharmony_ci
187d9f0492fSopenharmony_ciconst char *GetDistributionOSName(void);
188d9f0492fSopenharmony_ciconst char *GetDistributionOSVersion(void);
189d9f0492fSopenharmony_ciint GetDistributionOSApiVersion(void);
190d9f0492fSopenharmony_ciconst char *GetDistributionOSApiName(void);
191d9f0492fSopenharmony_ciconst char *GetDistributionOSReleaseType(void);
192d9f0492fSopenharmony_ci
193d9f0492fSopenharmony_ci#ifdef __cplusplus
194d9f0492fSopenharmony_ci#if __cplusplus
195d9f0492fSopenharmony_ci}
196d9f0492fSopenharmony_ci#endif
197d9f0492fSopenharmony_ci#endif /* __cplusplus */
198d9f0492fSopenharmony_ci
199d9f0492fSopenharmony_ci#endif // STARTUP_SYSPARAM_PARAMETER_API_H
200