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