未验证 提交 be6255b2 编写于 作者: O openharmony_ci 提交者: Gitee

!1504 系统优化:commit相关接口移到base

Merge pull request !1504 from cheng_jinsong/init-1110
......@@ -36,8 +36,6 @@ extern "C" {
#define PARAM_NAME_LEN_MAX 96
#endif
typedef uint32_t ParamHandle;
typedef enum {
PARAM_CODE_ERROR = -1,
PARAM_CODE_SUCCESS = 0,
......@@ -166,21 +164,6 @@ int SystemSetParameter(const char *name, const char *value);
*/
#define SystemGetParameter SystemReadParam
/**
* 对外接口
* 查询参数,主要用于其他进程使用,找到对应属性的handle。
*
*/
int SystemFindParameter(const char *name, ParamHandle *handle);
/**
* 对外接口
* 根据handle获取对应数据的修改标识。
* commitId 获取计数变化
*
*/
int SystemGetParameterCommitId(ParamHandle handle, uint32_t *commitId);
/**
* 外部接口
* 遍历参数。
......@@ -198,13 +181,6 @@ int SystemTraversalParameter(const char *prefix,
*/
int SystemGetParameterName(ParamHandle handle, char *name, unsigned int len);
/**
* 外部接口
* 获取参数值。
*
*/
int SystemGetParameterValue(ParamHandle handle, char *value, unsigned int *len);
/**
* 外部接口
* 等待某个参数值被修改,阻塞直到参数值被修改或超时
......@@ -216,7 +192,6 @@ typedef void (*ParameterChangePtr)(const char *key, const char *value, void *con
int SystemWatchParameter(const char *keyprefix, ParameterChangePtr change, void *context);
int SystemCheckParamExist(const char *name);
long long GetSystemCommitId(void);
void SystemDumpParameters(int verbose, int (*dump)(const char *fmt, ...));
......
......@@ -23,6 +23,8 @@ extern "C" {
#endif
#endif
typedef uint32_t ParamHandle;
typedef struct {
uint8_t updaterMode;
void (*logFunc)(int logLevel, uint32_t domain, const char *tag, const char *fmt, va_list vargs);
......@@ -45,6 +47,31 @@ int SystemReadParam(const char *name, char *value, uint32_t *len);
* parameter client初始化接口 供服务调用
*/
void InitParameterClient(void);
/**
* 对外接口
* 查询参数,主要用于其他进程使用,找到对应属性的handle。
*
*/
int SystemFindParameter(const char *name, ParamHandle *handle);
/**
* 对外接口
* 根据handle获取对应数据的修改标识。
* commitId 获取计数变化
*
*/
int SystemGetParameterCommitId(ParamHandle handle, uint32_t *commitId);
/**
* 外部接口
* 获取参数值。
*
*/
int SystemGetParameterValue(ParamHandle handle, char *value, unsigned int *len);
long long GetSystemCommitId(void);
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -12,7 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <unistd.h>
#include <linux/reboot.h>
#include <sys/reboot.h>
#include <sys/syscall.h>
#include "reboot_adp.h"
#include "init_cmdexecutor.h"
......@@ -103,11 +107,23 @@ static int DoRebootSuspend(int id, const char *name, int argc, const char **argv
return DoRoot_("suspend", RB_AUTOBOOT);
}
static int DoRebootOther(int id, const char *name, int argc, const char **argv)
{
UNUSED(id);
UNUSED(name);
PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter argc %d", argc);
const char *cmd = strstr(argv[0], "reboot,");
PLUGIN_CHECK(cmd != NULL, return -1, "Invalid parameter argc %s", argv[0]);
PLUGIN_LOGI("DoRebootOther argv %s", argv[0]);
return syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, cmd + strlen("reboot,"));
}
static void RebootAdpInit(void)
{
// sample {"reboot,shutdown", "reboot.shutdown", "reboot.shutdown"},
// add default reboot cmd
(void)AddCmdExecutor("reboot", DoReboot);
(void)AddCmdExecutor("reboot.other", DoRebootOther);
AddRebootCmdExecutor("shutdown", DoRebootShutdown);
AddRebootCmdExecutor("flashd", DoRebootFlashed);
AddRebootCmdExecutor("updater", DoRebootUpdater);
......
......@@ -286,3 +286,40 @@ INIT_LOCAL_API int AddWorkSpace(const char *name, int onlyRead, uint32_t spaceSi
PARAM_LOGV("AddWorkSpace %s %s", name, ret == 0 ? "success" : "fail");
return ret;
}
int SystemFindParameter(const char *name, ParamHandle *handle)
{
PARAM_CHECK(name != NULL && handle != NULL, return -1, "The name or handle is null");
int ret = ReadParamWithCheck(name, DAC_READ, handle);
if (ret != PARAM_CODE_NOT_FOUND && ret != 0 && ret != PARAM_CODE_NODE_EXIST) {
PARAM_CHECK(ret == 0, return ret, "Forbid to access parameter %s", name);
}
return ret;
}
int SystemGetParameterCommitId(ParamHandle handle, uint32_t *commitId)
{
PARAM_CHECK(handle != 0 && commitId != NULL, return -1, "The handle is null");
ParamNode *entry = (ParamNode *)GetTrieNodeByHandle(handle);
if (entry == NULL) {
return PARAM_CODE_NOT_FOUND;
}
*commitId = ReadCommitId(entry);
return 0;
}
long long GetSystemCommitId(void)
{
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC);
if (space == NULL || space->area == NULL) {
return 0;
}
return ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_acquire);
}
int SystemGetParameterValue(ParamHandle handle, char *value, unsigned int *len)
{
PARAM_CHECK(len != NULL && handle != 0, return -1, "The value is null");
return ReadParamValue(handle, value, len);
}
\ No newline at end of file
......@@ -246,16 +246,6 @@ int SystemCheckParamExist(const char *name)
return SysCheckParamExist(name);
}
int SystemFindParameter(const char *name, ParamHandle *handle)
{
PARAM_CHECK(name != NULL && handle != NULL, return -1, "The name or handle is null");
int ret = ReadParamWithCheck(name, DAC_READ, handle);
if (ret != PARAM_CODE_NOT_FOUND && ret != 0 && ret != PARAM_CODE_NODE_EXIST) {
PARAM_CHECK(ret == 0, return ret, "Forbid to access parameter %s", name);
}
return ret;
}
int WatchParamCheck(const char *keyprefix)
{
PARAM_CHECK(keyprefix != NULL, return PARAM_CODE_INVALID_PARAM, "Invalid keyprefix");
......
......@@ -113,13 +113,3 @@ int SystemCheckParamExist(const char *name)
{
return SysCheckParamExist(name);
}
int SystemFindParameter(const char *name, ParamHandle *handle)
{
PARAM_CHECK(name != NULL && handle != NULL, return -1, "The name or handle is null");
int ret = ReadParamWithCheck(name, DAC_READ, handle);
if (ret != PARAM_CODE_NOT_FOUND && ret != 0 && ret != PARAM_CODE_NODE_EXIST) {
PARAM_CHECK(ret == 0, return ret, "Forbid to access parameter %s", name);
}
return ret;
}
......@@ -299,7 +299,7 @@ static int GetServiceCtrlInfoForPowerCtrl(const char *name, const char *value, S
}
// not found reboot, so reboot by normal
valueOffset = strlen(OHOS_SERVICE_CTRL_PREFIX) + strlen("reboot") + 1;
return CreateCtrlInfo(ctrlInfo, "reboot", valueOffset, 1, "%s%s.%s", OHOS_SERVICE_CTRL_PREFIX, "reboot", value);
return CreateCtrlInfo(ctrlInfo, "reboot.other", valueOffset, 1, "%s%s.%s", OHOS_SERVICE_CTRL_PREFIX, "reboot", value);
}
INIT_LOCAL_API int GetServiceCtrlInfo(const char *name, const char *value, ServiceCtrlInfo **ctrlInfo)
......@@ -376,35 +376,8 @@ INIT_LOCAL_API int CheckParameterSet(const char *name,
return ret;
}
int SystemGetParameterCommitId(ParamHandle handle, uint32_t *commitId)
{
PARAM_CHECK(handle != 0 && commitId != NULL, return -1, "The handle is null");
ParamNode *entry = (ParamNode *)GetTrieNodeByHandle(handle);
if (entry == NULL) {
return PARAM_CODE_NOT_FOUND;
}
*commitId = ReadCommitId(entry);
return 0;
}
long long GetSystemCommitId(void)
{
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC);
if (space == NULL || space->area == NULL) {
return 0;
}
return ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_acquire);
}
int SystemGetParameterName(ParamHandle handle, char *name, unsigned int len)
{
PARAM_CHECK(name != NULL && handle != 0, return -1, "The name is null");
return ReadParamName(handle, name, len);
}
int SystemGetParameterValue(ParamHandle handle, char *value, unsigned int *len)
{
PARAM_CHECK(len != NULL && handle != 0, return -1, "The value is null");
return ReadParamValue(handle, value, len);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册