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