1/* 2 * Copyright (c) 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 BASE_STARTUP_PARAM_PERSIST_H 17#define BASE_STARTUP_PARAM_PERSIST_H 18#include <stdint.h> 19#include <sys/types.h> 20 21#include "param_osadp.h" 22#define PUBLIC_PERSIST_FILE 0 23#define PRIVATE_PERSIST_FILE 1 24 25#ifdef __cplusplus 26#if __cplusplus 27extern "C" { 28#endif 29#endif 30 31typedef int (*PersistParamGetPtr)(const char *name, const char *value, void *context); 32typedef void *PERSIST_SAVE_HANDLE; 33typedef struct { 34 void *context; 35 PersistParamGetPtr persistParamGet; 36} PersistAdpContext; 37 38typedef struct { 39#if defined(__LITEOS_M__) || defined(__LITEOS_A__) || defined(__LINUX__) 40 int (*load)(void); 41 int (*batchSaveBegin)(PERSIST_SAVE_HANDLE *handle); 42 int (*batchSave)(PERSIST_SAVE_HANDLE handle, const char *name, const char *value); 43 void (*batchSaveEnd)(PERSIST_SAVE_HANDLE handle); 44#else 45 int (*load)(int fileType); 46 int (*batchSaveBegin)(PERSIST_SAVE_HANDLE *handle); 47 int (*batchSave)(PERSIST_SAVE_HANDLE handle[], const char *name, const char *value); 48 void (*batchSaveEnd)(PERSIST_SAVE_HANDLE handle[]); 49#endif 50 int (*save)(const char *name, const char *value); 51} PersistParamOps; 52 53int RegisterPersistParamOps(PersistParamOps *ops); 54 55#ifndef STARTUP_INIT_TEST 56#define PARAM_MUST_SAVE_PARAM_DIFF 1 // 1s 57#else 58#define PARAM_MUST_SAVE_PARAM_DIFF 1 59void TimerCallbackForSave(ParamTaskPtr timer, void *context); 60#endif 61 62void CheckAndSavePersistParam(void); 63 64#ifdef __cplusplus 65#if __cplusplus 66} 67#endif 68#endif 69#endif