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