• 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 } ParamMsgType;
40 
41 typedef enum ContentType {
42     PARAM_NAME,
43     PARAM_VALUE,
44     PARAM_LABEL,
45     PARAM_WAIT_TIMEOUT,
46     PARAM_NAME_VALUE,
47 } ContentType;
48 
49 typedef struct {
50     uint8_t type;
51     uint8_t rev;
52     uint16_t contentSize;
53     char content[0];
54 } ParamMsgContent;
55 
56 typedef struct {
57     uint32_t type;
58     uint32_t msgSize;
59     union {
60         uint32_t msgId;
61         uint32_t watcherId;
62         uint32_t waitId;
63     } id;
64     char key[PARAM_NAME_LEN_MAX + 4];
65     char data[0];
66 } ParamMessage;
67 
68 typedef struct {
69     ParamMessage msg;
70     int32_t result;
71 } ParamResponseMessage;
72 
73 typedef int (*RecvMessage)(const ParamTaskPtr stream, const ParamMessage *msg);
74 
75 typedef struct {
76     uint32_t flags;
77     char *server;
78     LE_IncommingConnect incomingConnect;
79     RecvMessage recvMessage;
80     LE_Close close;
81 } ParamStreamInfo;
82 
83 int ParamServiceStop(void);
84 int ParamServiceStart(void);
85 
86 int ParamTaskClose(const ParamTaskPtr stream);
87 int ParamServerCreate(ParamTaskPtr *stream, const ParamStreamInfo *streamInfo);
88 int ParamStreamCreate(ParamTaskPtr *stream, ParamTaskPtr server,
89                       const ParamStreamInfo *streamInfo, uint16_t userDataSize);
90 int ParamTaskSendMsg(const ParamTaskPtr stream, const ParamMessage *msg);
91 
92 int ParamEventTaskCreate(ParamTaskPtr *stream, LE_ProcessAsyncEvent eventProcess);
93 int ParamEventSend(const ParamTaskPtr stream, uint64_t eventId, const char *content, uint32_t size);
94 
95 void *ParamGetTaskUserData(const ParamTaskPtr stream);
96 
97 int FillParamMsgContent(const ParamMessage *request, uint32_t *start, int type, const char *value, uint32_t length);
98 ParamMsgContent *GetNextContent(const ParamMessage *request, uint32_t *offset);
99 ParamMessage *CreateParamMessage(int type, const char *name, uint32_t msgSize);
100 
101 int ConnectServer(int fd, const char *servername);
102 
103 #ifdef STARTUP_INIT_TEST
104 int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *msg);
105 int OnIncomingConnect(LoopHandle loop, TaskHandle server);
106 #endif
107 #ifdef __cplusplus
108 #if __cplusplus
109 }
110 #endif
111 #endif
112 #endif // BASE_STARTUP_PARAM_MESSAGE_H