169570cc8Sopenharmony_ci/* 269570cc8Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 369570cc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 469570cc8Sopenharmony_ci * you may not use this file except in compliance with the License. 569570cc8Sopenharmony_ci * You may obtain a copy of the License at 669570cc8Sopenharmony_ci * 769570cc8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 869570cc8Sopenharmony_ci * 969570cc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1069570cc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1169570cc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1269570cc8Sopenharmony_ci * See the License for the specific language governing permissions and 1369570cc8Sopenharmony_ci * limitations under the License. 1469570cc8Sopenharmony_ci */ 1569570cc8Sopenharmony_ci 1669570cc8Sopenharmony_ci#ifndef APPSPAWN_CLIENT_H 1769570cc8Sopenharmony_ci#define APPSPAWN_CLIENT_H 1869570cc8Sopenharmony_ci#include <pthread.h> 1969570cc8Sopenharmony_ci#include <stdint.h> 2069570cc8Sopenharmony_ci#include <stdlib.h> 2169570cc8Sopenharmony_ci 2269570cc8Sopenharmony_ci#include "appspawn_msg.h" 2369570cc8Sopenharmony_ci#include "list.h" 2469570cc8Sopenharmony_ci 2569570cc8Sopenharmony_ci#ifdef __cplusplus 2669570cc8Sopenharmony_ciextern "C" { 2769570cc8Sopenharmony_ci#endif 2869570cc8Sopenharmony_ci 2969570cc8Sopenharmony_ci#ifdef ASAN_DETECTOR 3069570cc8Sopenharmony_ci#define TIMEOUT_DEF 60 3169570cc8Sopenharmony_ci#define ASAN_TIMEOUT 60 3269570cc8Sopenharmony_ci#else 3369570cc8Sopenharmony_ci#define TIMEOUT_DEF 2 3469570cc8Sopenharmony_ci#define ASAN_TIMEOUT 5 3569570cc8Sopenharmony_ci#endif 3669570cc8Sopenharmony_ci 3769570cc8Sopenharmony_ci#define RETRY_TIME (200 * 1000) // 200 * 1000 wait 200ms CONNECT_RETRY_DELAY = 200 * 1000 3869570cc8Sopenharmony_ci#define MAX_RETRY_SEND_COUNT 2 // 2 max retry count CONNECT_RETRY_MAX_TIMES = 2; 3969570cc8Sopenharmony_ci 4069570cc8Sopenharmony_ci// only used for ExternalFileManager.hap 4169570cc8Sopenharmony_ci#define GID_FILE_ACCESS 1006 4269570cc8Sopenharmony_ci#define GID_USER_DATA_RW 1008 4369570cc8Sopenharmony_ci 4469570cc8Sopenharmony_ci#define MAX_DATA_IN_TLV 2 4569570cc8Sopenharmony_ci 4669570cc8Sopenharmony_cistruct TagAppSpawnReqMsgNode; 4769570cc8Sopenharmony_citypedef enum { 4869570cc8Sopenharmony_ci CLIENT_FOR_APPSPAWN, 4969570cc8Sopenharmony_ci CLIENT_FOR_NWEBSPAWN, 5069570cc8Sopenharmony_ci CLIENT_FOR_CJAPPSPAWN, 5169570cc8Sopenharmony_ci CLIENT_FOR_NATIVESPAWN, 5269570cc8Sopenharmony_ci CLIENT_MAX 5369570cc8Sopenharmony_ci} AppSpawnClientType; 5469570cc8Sopenharmony_ci 5569570cc8Sopenharmony_citypedef struct { 5669570cc8Sopenharmony_ci struct ListNode node; 5769570cc8Sopenharmony_ci uint32_t blockSize; // block 的大小 5869570cc8Sopenharmony_ci uint32_t currentIndex; // 当前已经填充的位置 5969570cc8Sopenharmony_ci uint8_t buffer[0]; 6069570cc8Sopenharmony_ci} AppSpawnMsgBlock; 6169570cc8Sopenharmony_ci 6269570cc8Sopenharmony_citypedef struct TagAppSpawnReqMsgMgr { 6369570cc8Sopenharmony_ci AppSpawnClientType type; 6469570cc8Sopenharmony_ci uint32_t maxRetryCount; 6569570cc8Sopenharmony_ci uint32_t timeout; 6669570cc8Sopenharmony_ci uint32_t msgNextId; 6769570cc8Sopenharmony_ci int socketId; 6869570cc8Sopenharmony_ci pthread_mutex_t mutex; 6969570cc8Sopenharmony_ci AppSpawnMsgBlock recvBlock; // 消息接收缓存 7069570cc8Sopenharmony_ci} AppSpawnReqMsgMgr; 7169570cc8Sopenharmony_ci 7269570cc8Sopenharmony_citypedef struct TagAppSpawnReqMsgNode { 7369570cc8Sopenharmony_ci struct ListNode node; 7469570cc8Sopenharmony_ci uint32_t reqId; 7569570cc8Sopenharmony_ci uint32_t retryCount; 7669570cc8Sopenharmony_ci int fdCount; 7769570cc8Sopenharmony_ci int fds[APP_MAX_FD_COUNT]; 7869570cc8Sopenharmony_ci int isAsan; 7969570cc8Sopenharmony_ci AppSpawnMsgFlags *msgFlags; 8069570cc8Sopenharmony_ci AppSpawnMsgFlags *permissionFlags; 8169570cc8Sopenharmony_ci AppSpawnMsg *msg; 8269570cc8Sopenharmony_ci struct ListNode msgBlocks; // 保存实际的消息数据 8369570cc8Sopenharmony_ci} AppSpawnReqMsgNode; 8469570cc8Sopenharmony_ci 8569570cc8Sopenharmony_citypedef struct { 8669570cc8Sopenharmony_ci uint8_t *data; 8769570cc8Sopenharmony_ci uint16_t dataLen; 8869570cc8Sopenharmony_ci uint16_t dataType; 8969570cc8Sopenharmony_ci} AppSpawnAppData; 9069570cc8Sopenharmony_ci 9169570cc8Sopenharmony_ciint32_t GetPermissionMaxCount(); 9269570cc8Sopenharmony_ci 9369570cc8Sopenharmony_ci#ifdef __cplusplus 9469570cc8Sopenharmony_ci} 9569570cc8Sopenharmony_ci#endif 9669570cc8Sopenharmony_ci#endif 97