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 OHOS_ABILITY_RUNTIME_APP_SPAWN_SOCKET_H 17 #define OHOS_ABILITY_RUNTIME_APP_SPAWN_SOCKET_H 18 19 #include <string> 20 21 #include "nocopyable.h" 22 #include "client_socket.h" 23 #include "appexecfwk_errors.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 class AppSpawnSocket { 28 public: 29 /** 30 * Constructor. 31 */ 32 explicit AppSpawnSocket(bool isNWebSpawn = false); 33 34 /** 35 * Destructor 36 */ 37 virtual ~AppSpawnSocket(); 38 39 /** 40 * Disable copy. 41 */ 42 DISALLOW_COPY_AND_MOVE(AppSpawnSocket); 43 44 /** 45 * Create client socket and connect the socket. 46 */ 47 virtual ErrCode OpenAppSpawnConnection(); 48 49 /** 50 * Close the client socket. 51 */ 52 virtual void CloseAppSpawnConnection(); 53 54 /** 55 * Write message to the socket. 56 * 57 * @param buf, message pointer. 58 * @param len, message size. 59 */ 60 virtual ErrCode WriteMessage(const void *buf, const int32_t len); 61 62 /** 63 * Read message from the socket. 64 * 65 * @param buf, message pointer. 66 * @param len, message size. 67 */ 68 virtual ErrCode ReadMessage(void *buf, const int32_t len); 69 70 /** 71 * Set function, unit test also use it. 72 * 73 * @param clientSocket, client socket. 74 */ 75 void SetClientSocket(const std::shared_ptr<OHOS::AppSpawn::ClientSocket> clientSocket); 76 77 private: 78 std::shared_ptr<AppSpawn::ClientSocket> clientSocket_; 79 }; 80 } // namespace AppExecFwk 81 } // namespace OHOS 82 #endif // OHOS_ABILITY_RUNTIME_APP_SPAWN_SOCKET_H 83