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