1d9f0492fSopenharmony_ci/*
2d9f0492fSopenharmony_ci * Copyright (c) 2021 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 BASE_STARTUP_PARAM_MESSAGE_H
17d9f0492fSopenharmony_ci#define BASE_STARTUP_PARAM_MESSAGE_H
18d9f0492fSopenharmony_ci#include <stdint.h>
19d9f0492fSopenharmony_ci#include <string.h>
20d9f0492fSopenharmony_ci#include <unistd.h>
21d9f0492fSopenharmony_ci
22d9f0492fSopenharmony_ci#include "loop_event.h"
23d9f0492fSopenharmony_ci#include "param_osadp.h"
24d9f0492fSopenharmony_ci#include "param_utils.h"
25d9f0492fSopenharmony_ci
26d9f0492fSopenharmony_ci#ifdef __cplusplus
27d9f0492fSopenharmony_ci#if __cplusplus
28d9f0492fSopenharmony_ciextern "C" {
29d9f0492fSopenharmony_ci#endif
30d9f0492fSopenharmony_ci#endif
31d9f0492fSopenharmony_ci
32d9f0492fSopenharmony_ci#define PARAM_TEST_FLAGS 0x01
33d9f0492fSopenharmony_citypedef enum {
34d9f0492fSopenharmony_ci    MSG_SET_PARAM,
35d9f0492fSopenharmony_ci    MSG_WAIT_PARAM,
36d9f0492fSopenharmony_ci    MSG_ADD_WATCHER,
37d9f0492fSopenharmony_ci    MSG_DEL_WATCHER,
38d9f0492fSopenharmony_ci    MSG_NOTIFY_PARAM,
39d9f0492fSopenharmony_ci    MSG_SAVE_PARAM
40d9f0492fSopenharmony_ci} ParamMsgType;
41d9f0492fSopenharmony_ci
42d9f0492fSopenharmony_citypedef enum ContentType {
43d9f0492fSopenharmony_ci    PARAM_NAME,
44d9f0492fSopenharmony_ci    PARAM_VALUE,
45d9f0492fSopenharmony_ci    PARAM_LABEL,
46d9f0492fSopenharmony_ci    PARAM_WAIT_TIMEOUT,
47d9f0492fSopenharmony_ci    PARAM_NAME_VALUE,
48d9f0492fSopenharmony_ci} ContentType;
49d9f0492fSopenharmony_ci
50d9f0492fSopenharmony_citypedef struct {
51d9f0492fSopenharmony_ci    uint8_t type;
52d9f0492fSopenharmony_ci    uint8_t rev;
53d9f0492fSopenharmony_ci    uint16_t contentSize;
54d9f0492fSopenharmony_ci    char content[0];
55d9f0492fSopenharmony_ci} ParamMsgContent;
56d9f0492fSopenharmony_ci
57d9f0492fSopenharmony_citypedef struct {
58d9f0492fSopenharmony_ci    uint32_t type;
59d9f0492fSopenharmony_ci    uint32_t msgSize;
60d9f0492fSopenharmony_ci    union {
61d9f0492fSopenharmony_ci        uint32_t msgId;
62d9f0492fSopenharmony_ci        uint32_t watcherId;
63d9f0492fSopenharmony_ci        uint32_t waitId;
64d9f0492fSopenharmony_ci    } id;
65d9f0492fSopenharmony_ci    char key[PARAM_NAME_LEN_MAX + 4];
66d9f0492fSopenharmony_ci    char data[0];
67d9f0492fSopenharmony_ci} ParamMessage;
68d9f0492fSopenharmony_ci
69d9f0492fSopenharmony_citypedef struct {
70d9f0492fSopenharmony_ci    ParamMessage msg;
71d9f0492fSopenharmony_ci    int32_t result;
72d9f0492fSopenharmony_ci} ParamResponseMessage;
73d9f0492fSopenharmony_ci
74d9f0492fSopenharmony_citypedef int (*RecvMessage)(const ParamTaskPtr stream, const ParamMessage *msg);
75d9f0492fSopenharmony_ci
76d9f0492fSopenharmony_citypedef struct {
77d9f0492fSopenharmony_ci    uint32_t flags;
78d9f0492fSopenharmony_ci    char *server;
79d9f0492fSopenharmony_ci    LE_IncommingConnect incomingConnect;
80d9f0492fSopenharmony_ci    RecvMessage recvMessage;
81d9f0492fSopenharmony_ci    LE_Close close;
82d9f0492fSopenharmony_ci} ParamStreamInfo;
83d9f0492fSopenharmony_ci
84d9f0492fSopenharmony_ciint ParamServiceStop(void);
85d9f0492fSopenharmony_ciint ParamServiceStart(void);
86d9f0492fSopenharmony_ci
87d9f0492fSopenharmony_ciint ParamTaskClose(const ParamTaskPtr stream);
88d9f0492fSopenharmony_ciint ParamServerCreate(ParamTaskPtr *stream, const ParamStreamInfo *streamInfo);
89d9f0492fSopenharmony_ciint ParamStreamCreate(ParamTaskPtr *stream, ParamTaskPtr server,
90d9f0492fSopenharmony_ci                      const ParamStreamInfo *streamInfo, uint16_t userDataSize);
91d9f0492fSopenharmony_ciint ParamTaskSendMsg(const ParamTaskPtr stream, const ParamMessage *msg);
92d9f0492fSopenharmony_ci
93d9f0492fSopenharmony_ciint ParamEventTaskCreate(ParamTaskPtr *stream, LE_ProcessAsyncEvent eventProcess);
94d9f0492fSopenharmony_ciint ParamEventSend(const ParamTaskPtr stream, uint64_t eventId, const char *content, uint32_t size);
95d9f0492fSopenharmony_ci
96d9f0492fSopenharmony_civoid *ParamGetTaskUserData(const ParamTaskPtr stream);
97d9f0492fSopenharmony_ci
98d9f0492fSopenharmony_ciint FillParamMsgContent(const ParamMessage *request, uint32_t *start, int type, const char *value, uint32_t length);
99d9f0492fSopenharmony_ciParamMsgContent *GetNextContent(const ParamMessage *request, uint32_t *offset);
100d9f0492fSopenharmony_ciParamMessage *CreateParamMessage(int type, const char *name, uint32_t msgSize);
101d9f0492fSopenharmony_ci
102d9f0492fSopenharmony_ciint ConnectServer(int fd, const char *servername);
103d9f0492fSopenharmony_ci
104d9f0492fSopenharmony_ci#ifdef STARTUP_INIT_TEST
105d9f0492fSopenharmony_ciint ProcessMessage(const ParamTaskPtr worker, const ParamMessage *msg);
106d9f0492fSopenharmony_ciint OnIncomingConnect(LoopHandle loop, TaskHandle server);
107d9f0492fSopenharmony_ci#endif
108d9f0492fSopenharmony_ci#ifdef __cplusplus
109d9f0492fSopenharmony_ci#if __cplusplus
110d9f0492fSopenharmony_ci}
111d9f0492fSopenharmony_ci#endif
112d9f0492fSopenharmony_ci#endif
113d9f0492fSopenharmony_ci#endif // BASE_STARTUP_PARAM_MESSAGE_H