sys_param.h 2.8 KB
Newer Older
Z
zhong_ning 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Z
zhong_ning 已提交
16 17
#ifndef BASE_STARTUP_SYS_PARAM_H
#define BASE_STARTUP_SYS_PARAM_H
Z
zhong_ning 已提交
18
#include <pthread.h>
S
sun_fan 已提交
19
#include <stdint.h>
Z
zhong_ning 已提交
20 21
#include <sys/types.h>

S
sun_fan 已提交
22
#include "param.h"
Z
zhong_ning 已提交
23 24 25 26 27 28
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

S
sun_fan 已提交
29 30
#define DEFAULT_PARAM_WAIT_TIMEOUT 30 // 30s
#define DEFAULT_PARAM_SET_TIMEOUT 10 // 10s
Z
zhong_ning 已提交
31 32 33

/**
 * 对外接口
Z
zhong_ning 已提交
34
 * 设置参数,主要用于其他进程使用,通过管道修改参数。
Z
zhong_ning 已提交
35 36 37 38 39 40
 *
 */
int SystemSetParameter(const char *name, const char *value);

/**
 * 对外接口
Z
zhong_ning 已提交
41
 * 查询参数,主要用于其他进程使用,需要给定足够的内存保存参数。
Z
zhong_ning 已提交
42 43 44 45 46 47
 * 如果 value == null,获取value的长度
 * 否则value的大小认为是len
 *
 */
int SystemGetParameter(const char *name, char *value, unsigned int *len);

S
sun_fan 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/**
 * 对外接口
 * 查询参数,主要用于其他进程使用,找到对应属性的handle。
 *
 */
int SystemFindParameter(const char *name, ParamHandle *handle);

/**
 * 对外接口
 * 根据handle获取对应数据的修改标识。
 * commitId 获取计数变化
 *
 */
int SystemGetParameterCommitId(ParamHandle handle, uint32_t *commitId);

Z
zhong_ning 已提交
63
/**
Z
zhong_ning 已提交
64 65
 * 外部接口
 * 遍历参数。
Z
zhong_ning 已提交
66 67
 *
 */
4
411148299@qq.com 已提交
68 69
int SystemTraversalParameter(
    void (*traversalParameter)(ParamHandle handle, ParamContextPtr cookie), ParamContextPtr cookie);
Z
zhong_ning 已提交
70 71

/**
Z
zhong_ning 已提交
72 73 74 75
 * 外部接口
 * 查询参数,主要用于其他进程使用,需要给定足够的内存保存参数。
 * 如果 value == null,获取value的长度
 * 否则value的大小认为是len
Z
zhong_ning 已提交
76 77
 *
 */
Z
zhong_ning 已提交
78
int SystemGetParameterName(ParamHandle handle, char *name, unsigned int len);
Z
zhong_ning 已提交
79 80

/**
Z
zhong_ning 已提交
81 82
 * 外部接口
 * 获取参数值。
Z
zhong_ning 已提交
83 84
 *
 */
Z
zhong_ning 已提交
85
int SystemGetParameterValue(ParamHandle handle, char *value, unsigned int *len);
S
sun_fan 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98

/**
 * 外部接口
 * 等待某个参数值被修改,阻塞直到参数值被修改或超时
 *
 */
int SystemWaitParameter(const char *name, const char *value, int32_t timeout);

typedef void (*ParameterChangePtr)(const char *key, const char *value, void *context);
int SystemWatchParameter(const char *keyprefix, ParameterChangePtr change, void *context);

void SystemDumpParameters(int verbose);

Z
zhong_ning 已提交
99 100 101 102 103 104
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif