1 /*
2  * Copyright (c) 2023 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_ROSEN_WINDOW_SCENE_DISTRIBUTED_CLIENT_H
17 #define OHOS_ROSEN_WINDOW_SCENE_DISTRIBUTED_CLIENT_H
18 
19 #include <string>
20 
21 #include "mission_info.h"
22 #include "mission_snapshot.h"
23 #include "iremote_broker.h"
24 #include "wm_single_instance.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 class DistributedClient {
29 WM_DECLARE_SINGLE_INSTANCE(DistributedClient);
30 
31 public:
32     int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions,
33                             std::vector<AAFwk::MissionInfo>& missionInfos);
34     int32_t GetRemoteMissionSnapshotInfo(const std::string& deviceId, int32_t missionId,
35                                          AAFwk::MissionSnapshot& missionSnapshot);
36     int32_t SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState& state);
37     void ClearDmsProxy();
38     enum {
39         START_REMOTE_ABILITY = 1,
40         CONNECT_REMOTE_ABILITY = 6,
41         DISCONNECT_REMOTE_ABILITY = 7,
42         START_CONTINUATION = 11,
43         NOTIFY_COMPLETE_CONTINUATION = 12,
44         CONTINUE_MISSION = 36,
45         CONTINUE_MISSION_OF_BUNDLENAME = 37,
46         GET_MISSION_INFOS = 80,
47         REGISTER_MISSION_LISTENER = 84,
48         UNREGISTER_MISSION_LISTENER = 85,
49         START_SYNC_MISSIONS = 92,
50         STOP_SYNC_MISSIONS = 98,
51         GET_REMOTE_MISSION_SNAPSHOT_INFO = 99,
52         START_REMOTE_ABILITY_BY_CALL = 150,
53         RELEASE_REMOTE_ABILITY = 151,
54         START_REMOTE_FREE_INSTALL = 200,
55         STOP_REMOTE_EXTERNSION_ABILITY = 225,
56         REGISTER_ON_LISTENER = 260,
57         REGISTER_OFF_LISTENER = 261,
58         SET_MISSION_CONTINUE_STATE = 300
59     };
60 private:
61     class DmsDeathRecipient : public IRemoteObject::DeathRecipient {
62     public:
63         void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
64     };
65     void ConnectDistributedSchedLocked();
66     sptr<IRemoteObject> GetDmsProxy();
67     bool ReadMissionInfosFromParcel(Parcel& parcel, std::vector<AAFwk::MissionInfo>& missionInfos);
68 
69     std::mutex mutex_;
70     sptr<DmsDeathRecipient> dmsDeath_ = nullptr;
71     sptr<IRemoteObject> dmsProxy_ = nullptr;
72 };
73 } // namespace Rosen
74 } // namespace OHOS
75 #endif // OHOS_ROSEN_WINDOW_SCENE_DISTRIBUTED_CLIENT_H
76