1 /* 2 * Copyright (c) 2024 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_CLIENT_H 17 #define APPSPAWN_CLIENT_H 18 #include <pthread.h> 19 #include <stdint.h> 20 #include <stdlib.h> 21 22 #include "appspawn_msg.h" 23 #include "list.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #ifdef ASAN_DETECTOR 30 #define TIMEOUT_DEF 60 31 #else 32 #define TIMEOUT_DEF 2 33 #endif 34 35 #define RETRY_TIME (200 * 1000) // 200 * 1000 wait 200ms CONNECT_RETRY_DELAY = 200 * 1000 36 #define MAX_RETRY_SEND_COUNT 2 // 2 max retry count CONNECT_RETRY_MAX_TIMES = 2; 37 38 // only used for ExternalFileManager.hap 39 #define GID_FILE_ACCESS 1006 40 #define GID_USER_DATA_RW 1008 41 42 #define MAX_DATA_IN_TLV 2 43 44 struct TagAppSpawnReqMsgNode; 45 typedef enum { 46 CLIENT_FOR_APPSPAWN, 47 CLIENT_FOR_NWEBSPAWN, 48 CLIENT_MAX 49 } AppSpawnClientType; 50 51 typedef struct { 52 struct ListNode node; 53 uint32_t blockSize; // block 的大小 54 uint32_t currentIndex; // 当前已经填充的位置 55 uint8_t buffer[0]; 56 } AppSpawnMsgBlock; 57 58 typedef struct TagAppSpawnReqMsgMgr { 59 AppSpawnClientType type; 60 uint32_t maxRetryCount; 61 uint32_t timeout; 62 uint32_t msgNextId; 63 int socketId; 64 pthread_mutex_t mutex; 65 AppSpawnMsgBlock recvBlock; // 消息接收缓存 66 } AppSpawnReqMsgMgr; 67 68 typedef struct TagAppSpawnReqMsgNode { 69 struct ListNode node; 70 uint32_t reqId; 71 uint32_t retryCount; 72 AppSpawnMsgFlags *msgFlags; 73 AppSpawnMsgFlags *permissionFlags; 74 AppSpawnMsg *msg; 75 struct ListNode msgBlocks; // 保存实际的消息数据 76 } AppSpawnReqMsgNode; 77 78 typedef struct { 79 uint8_t *data; 80 uint16_t dataLen; 81 uint16_t dataType; 82 } AppSpawnAppData; 83 84 int32_t GetPermissionMaxCount(); 85 86 #ifdef __cplusplus 87 } 88 #endif 89 #endif 90