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