• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_APP_SPAWN_CLIENT_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_APP_SPAWN_CLIENT_H
18 
19 #include "nocopyable.h"
20 #include "app_spawn_msg_wrapper.h"
21 #include "app_spawn_socket.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 enum class SpawnConnectionState { STATE_NOT_CONNECT, STATE_CONNECTED, STATE_CONNECT_FAILED };
26 
27 class AppSpawnClient {
28 public:
29     /**
30      * Constructor.
31      */
32     explicit AppSpawnClient(bool isNWebSpawn = false);
33 
34     /**
35      * Destructor
36      */
37     virtual ~AppSpawnClient() = default;
38 
39     /**
40      * Disable copy.
41      */
42     DISALLOW_COPY_AND_MOVE(AppSpawnClient);
43 
44     /**
45      * Try connect to appspawn.
46      */
47     ErrCode OpenConnection();
48 
49     /**
50      * Close the connect of appspawn.
51      */
52     void CloseConnection();
53 
54     /**
55      * AppSpawnClient core function, Start request to appspawn.
56      *
57      * @param startMsg, request message.
58      * @param pid, pid of app process, get from appspawn.
59      */
60     virtual ErrCode StartProcess(const AppSpawnStartMsg &startMsg, pid_t &pid);
61 
62     /**
63      * Get render process termination status.
64      *
65      * @param startMsg, request message.
66      * @param status, termination status of render process, get from appspawn.
67      */
68     virtual ErrCode GetRenderProcessTerminationStatus(const AppSpawnStartMsg &startMsg, int &status);
69 
70     /**
71      * Return the connect state.
72      */
73     SpawnConnectionState QueryConnectionState() const;
74 
75     /**
76      * Set function, unit test also use it.
77      */
78     void SetSocket(const std::shared_ptr<AppSpawnSocket> socket);
79 
80 private:
81     /**
82      * AppSpawnClient core function,
83      *
84      * @param startMsg, request message.
85      * @param pid, pid of app process, get it from appspawn.
86      */
87     ErrCode StartProcessImpl(const AppSpawnStartMsg &startMsg, pid_t &pid);
88 
89 private:
90     std::shared_ptr<AppSpawnSocket> socket_;
91     SpawnConnectionState state_ = SpawnConnectionState::STATE_NOT_CONNECT;
92 };
93 }  // namespace AppExecFwk
94 }  // namespace OHOS
95 #endif  // FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_APP_SPAWN_CLIENT_H
96