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 28extern "C" { 29#endif 30#endif 31 32#define PARAM_TEST_FLAGS 0x01 33typedef 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 42typedef enum ContentType { 43 PARAM_NAME, 44 PARAM_VALUE, 45 PARAM_LABEL, 46 PARAM_WAIT_TIMEOUT, 47 PARAM_NAME_VALUE, 48} ContentType; 49 50typedef struct { 51 uint8_t type; 52 uint8_t rev; 53 uint16_t contentSize; 54 char content[0]; 55} ParamMsgContent; 56 57typedef 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 69typedef struct { 70 ParamMessage msg; 71 int32_t result; 72} ParamResponseMessage; 73 74typedef int (*RecvMessage)(const ParamTaskPtr stream, const ParamMessage *msg); 75 76typedef struct { 77 uint32_t flags; 78 char *server; 79 LE_IncommingConnect incomingConnect; 80 RecvMessage recvMessage; 81 LE_Close close; 82} ParamStreamInfo; 83 84int ParamServiceStop(void); 85int ParamServiceStart(void); 86 87int ParamTaskClose(const ParamTaskPtr stream); 88int ParamServerCreate(ParamTaskPtr *stream, const ParamStreamInfo *streamInfo); 89int ParamStreamCreate(ParamTaskPtr *stream, ParamTaskPtr server, 90 const ParamStreamInfo *streamInfo, uint16_t userDataSize); 91int ParamTaskSendMsg(const ParamTaskPtr stream, const ParamMessage *msg); 92 93int ParamEventTaskCreate(ParamTaskPtr *stream, LE_ProcessAsyncEvent eventProcess); 94int ParamEventSend(const ParamTaskPtr stream, uint64_t eventId, const char *content, uint32_t size); 95 96void *ParamGetTaskUserData(const ParamTaskPtr stream); 97 98int FillParamMsgContent(const ParamMessage *request, uint32_t *start, int type, const char *value, uint32_t length); 99ParamMsgContent *GetNextContent(const ParamMessage *request, uint32_t *offset); 100ParamMessage *CreateParamMessage(int type, const char *name, uint32_t msgSize); 101 102int ConnectServer(int fd, const char *servername); 103 104#ifdef STARTUP_INIT_TEST 105int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *msg); 106int 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