1 /* 2 * Copyright (c) 2021 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_MSG_PEER_H 17 #define APPSPAWN_MSG_PEER_H 18 19 #include <string> 20 21 #include "client_socket.h" 22 #include "server_socket.h" 23 #include "nocopyable.h" 24 25 namespace OHOS { 26 namespace AppSpawn { 27 class AppSpawnMsgPeer { 28 public: 29 /** 30 * Constructor used to delete the default constructor. 31 */ 32 AppSpawnMsgPeer() = delete; 33 34 /** 35 * Constructor used to create a AppSpawnMsgPeer. 36 */ 37 AppSpawnMsgPeer(const std::shared_ptr<ServerSocket> &socket, int connectFd); 38 39 /** 40 * Destructor used to destory a AppSpawnMsgPeer 41 */ 42 ~AppSpawnMsgPeer(); 43 44 /** 45 * Disables copy and moving of AppSpawnMsgPeer. 46 */ 47 DISALLOW_COPY_AND_MOVE(AppSpawnMsgPeer); 48 49 /** 50 * Gets the message about the app property. 51 */ 52 ClientSocket::AppProperty *GetMsg() const; 53 54 /** 55 * Returns the PID of the application process in the response sent to the ability manager service 56 * after AppSpawn forks the application process. 57 * 58 * @param pid Indicates the PID of the application process. 59 */ 60 int Response(pid_t pid); 61 62 /** 63 * Reads the message from MsgPeer over the socket. 64 */ 65 int MsgPeer(); 66 67 /** 68 * Gets the connection file description used by the ability manager service to connect to AppSpawn. 69 */ 70 int GetConnectFd() const; 71 72 private: 73 int connectFd_ = -1; 74 std::shared_ptr<ServerSocket> socket_ = nullptr; 75 std::unique_ptr<int8_t[]> buf_ = nullptr; 76 }; 77 } // namespace AppSpawn 78 } // namespace OHOS 79 #endif 80