1 /* 2 * Copyright (c) 2021-2022 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_SOCKET_CLIENT_H 17 #define APPSPAWN_SOCKET_CLIENT_H 18 19 #include "appspawn_socket.h" 20 #include "appspawn_msg.h" 21 #include "nocopyable.h" 22 23 namespace OHOS { 24 namespace AppSpawn { 25 class ClientSocket : public AppSpawnSocket { 26 public: 27 /** 28 * Constructor used to create a ClientSocket 29 */ 30 explicit ClientSocket(const std::string &client); 31 32 /** 33 * Destructor used to destroy a ClientSocket 34 */ 35 virtual ~ClientSocket() = default; 36 37 /** 38 * Disables copying and moving for the ClientSocket. 39 */ 40 DISALLOW_COPY_AND_MOVE(ClientSocket); 41 42 /** 43 * Creates a local client socket. 44 */ 45 virtual int CreateClient(); 46 47 /** 48 * Closes a client socket. 49 */ 50 virtual void CloseClient(); 51 52 /** 53 * Connects a client socket. 54 */ 55 virtual int ConnectSocket(); 56 57 /** 58 * Writes messages to a client socket. 59 * 60 * @param buf Indicates the pointer to the message buffer. 61 * @param len Indicates the message length. 62 */ 63 virtual int WriteSocketMessage(const void *buf, int len); 64 65 /** 66 * Reads messages from a client socket. 67 * 68 * @param buf Indicates the pointer to the message buffer. 69 * @param len Indicates the message length. 70 */ 71 virtual int ReadSocketMessage(void *buf, int len); 72 73 /** 74 * Uses functions of the parent class. 75 */ 76 using AppSpawnSocket::CloseSocket; 77 using AppSpawnSocket::CreateSocket; 78 using AppSpawnSocket::GetSocketFd; 79 using AppSpawnSocket::ReadSocketMessage; 80 using AppSpawnSocket::WriteSocketMessage; 81 82 enum AppType { 83 APP_TYPE_DEFAULT = 0, // JavaScript app 84 APP_TYPE_NATIVE // Native C++ app 85 }; 86 87 static constexpr int APPSPAWN_MSG_MAX_SIZE = APP_MSG_MAX_SIZE; // appspawn message max size 88 static constexpr int LEN_PROC_NAME = APP_LEN_PROC_NAME; // process name length 89 static constexpr int LEN_BUNDLE_NAME = APP_LEN_BUNDLE_NAME; // bundle name length 90 static constexpr int LEN_SO_PATH = APP_LEN_SO_PATH; // load so lib 91 static constexpr int MAX_GIDS = APP_MAX_GIDS; 92 static constexpr int APL_MAX_LEN = APP_APL_MAX_LEN; 93 static constexpr int RENDER_CMD_MAX_LEN = APP_RENDER_CMD_MAX_LEN; 94 static constexpr int APPSPAWN_COLD_BOOT = APP_COLD_BOOT; 95 96 using AppProperty = AppParameter; 97 using AppOperateCode = AppOperateType; 98 private: 99 /** 100 * Connects a client socket. 101 * 102 * @param connectFd Indicates the connection's FD. 103 */ 104 int ConnectSocket(int connectFd); 105 }; 106 } // namespace AppSpawn 107 } // namespace OHOS 108 #endif 109