1/* 2 * Copyright (c) 2021-2023 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 APPSPAWN_SERVICE_H 17#define APPSPAWN_SERVICE_H 18 19#include <limits.h> 20#include <stdbool.h> 21#include <unistd.h> 22 23#include "appspawn.h" 24#include "appspawn_hook.h" 25#include "appspawn_msg.h" 26#include "appspawn_server.h" 27#include "appspawn_utils.h" 28#include "list.h" 29#include "loop_event.h" 30 31#ifdef __cplusplus 32extern "C" { 33#endif 34 35#ifdef APPSPAWN_TEST 36#define MAX_WAIT_MSG_COMPLETE (5 * 100) // 500ms 37#define COLD_CHILD_RESPONSE_TIMEOUT 5 38#define WAIT_CHILD_RESPONSE_TIMEOUT 3 //3s 39#else 40#define MAX_WAIT_MSG_COMPLETE (5 * 1000) // 5s 41#define COLD_CHILD_RESPONSE_TIMEOUT 5 42#define WAIT_CHILD_RESPONSE_TIMEOUT 3 //3s 43#endif 44 45typedef struct TagAppSpawnMsgNode AppSpawnMsgNode; 46typedef struct TagAppSpawnMsgReceiverCtx { 47 uint32_t nextMsgId; // 校验消息id 48 uint32_t msgRecvLen; // 已经接收的长度 49 TimerHandle timer; // 测试消息完整 50 int fdCount; 51 int fds[APP_MAX_FD_COUNT]; 52 AppSpawnMsgNode *incompleteMsg; // 保存不完整的消息,额外保存消息头信息 53} AppSpawnMsgReceiverCtx; 54 55typedef struct TagAppSpawnConnection { 56 uint32_t connectionId; 57 TaskHandle stream; 58 AppSpawnMsgReceiverCtx receiverCtx; 59} AppSpawnConnection; 60 61typedef struct TagAppSpawnStartArg { 62 RunMode mode; 63 uint32_t moduleType; 64 const char *socketName; 65 const char *serviceName; 66 uint32_t initArg : 1; 67} AppSpawnStartArg; 68 69typedef struct { 70 char *serverName; 71 AppSpawnStartArg arg; 72} AppSpawnStartArgTemplate; 73 74pid_t NWebSpawnLaunch(void); 75void NWebSpawnInit(void); 76AppSpawnContent *StartSpawnService(const AppSpawnStartArg *arg, uint32_t argvSize, int argc, char *const argv[]); 77void AppSpawnDestroyContent(AppSpawnContent *content); 78 79#ifdef __cplusplus 80} 81#endif 82#endif // APPSPAWN_SERVICE_H 83