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 COOPERATE_EVENTS_H
17#define COOPERATE_EVENTS_H
18
19#include <future>
20#include <string>
21#include <variant>
22
23#include "coordination_message.h"
24#include "i_cooperate.h"
25#include "i_device.h"
26
27namespace OHOS {
28namespace Msdp {
29namespace DeviceStatus {
30namespace Cooperate {
31enum CooperateState : size_t {
32    COOPERATE_STATE_FREE = 0,
33    COOPERATE_STATE_OUT,
34    COOPERATE_STATE_IN,
35    N_COOPERATE_STATES,
36};
37
38enum class CooperateEventType {
39    NOOP,
40    QUIT,
41    ADD_OBSERVER,
42    REMOVE_OBSERVER,
43    REGISTER_LISTENER,
44    UNREGISTER_LISTENER,
45    REGISTER_HOTAREA_LISTENER,
46    UNREGISTER_HOTAREA_LISTENER,
47    ENABLE,
48    DISABLE,
49    START,
50    STOP,
51    GET_COOPERATE_STATE,
52    REGISTER_EVENT_LISTENER,
53    UNREGISTER_EVENT_LISTENER,
54    UPDATE_COOPERATE_FLAG,
55    SET_DAMPLING_COEFFICIENT,
56    DUMP,
57    APP_CLOSED,
58    DDM_BOARD_ONLINE,
59    DDM_BOARD_OFFLINE,
60    DDP_COOPERATE_SWITCH_CHANGED,
61    INPUT_HOTPLUG_EVENT,
62    INPUT_POINTER_EVENT,
63    DSOFTBUS_SESSION_OPENED,
64    DSOFTBUS_SESSION_CLOSED,
65    DSOFTBUS_START_COOPERATE,
66    DSOFTBUS_COME_BACK,
67    DSOFTBUS_STOP_COOPERATE,
68    DSOFTBUS_RELAY_COOPERATE,
69    DSOFTBUS_RELAY_COOPERATE_FINISHED,
70    DSOFTBUS_SUBSCRIBE_MOUSE_LOCATION,
71    DSOFTBUS_UNSUBSCRIBE_MOUSE_LOCATION,
72    DSOFTBUS_REPLY_SUBSCRIBE_MOUSE_LOCATION,
73    DSOFTBUS_REPLY_UNSUBSCRIBE_MOUSE_LOCATION,
74    DSOFTBUS_MOUSE_LOCATION,
75    DSOFTBUS_INPUT_DEV_SYNC,
76    DSOFTBUS_INPUT_DEV_HOT_PLUG,
77};
78
79struct Rectangle {
80    int32_t width;
81    int32_t height;
82    int32_t x;
83    int32_t y;
84};
85
86struct AddObserverEvent {
87    std::shared_ptr<ICooperateObserver> observer;
88};
89using RemoveObserverEvent = AddObserverEvent;
90
91struct RegisterListenerEvent {
92    int32_t pid;
93    int32_t userData;
94};
95
96using UnregisterListenerEvent = RegisterListenerEvent;
97using RegisterHotareaListenerEvent = RegisterListenerEvent;
98using UnregisterHotareaListenerEvent = RegisterListenerEvent;
99using DisableCooperateEvent = RegisterListenerEvent;
100
101struct StartCooperateEvent {
102    int32_t pid;
103    int32_t userData;
104    std::string remoteNetworkId;
105    int32_t startDeviceId;
106    std::shared_ptr<std::promise<int32_t>> errCode;
107};
108
109struct EnableCooperateEvent {
110    int32_t tokenId;
111    int32_t pid;
112    int32_t userData;
113};
114
115struct ClientDiedEvent {
116    int32_t pid;
117};
118
119struct StopCooperateEvent {
120    int32_t pid;
121    int32_t userData;
122    bool isUnchained;
123    std::string networkId;
124};
125
126struct GetCooperateStateEvent {
127    int32_t pid;
128    int32_t userData;
129    std::string networkId;
130};
131
132struct RegisterEventListenerEvent {
133    int32_t pid;
134    std::string networkId;
135};
136using UnregisterEventListenerEvent = RegisterEventListenerEvent;
137
138struct DumpEvent {
139    int32_t fd;
140};
141
142struct DDMBoardOnlineEvent {
143    std::string networkId;
144    bool normal;
145    int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) };
146};
147
148using DDMBoardOfflineEvent = DDMBoardOnlineEvent;
149using DDPCooperateSwitchChanged = DDMBoardOnlineEvent;
150
151enum class InputHotplugType {
152    PLUG,
153    UNPLUG,
154};
155
156struct InputHotplugEvent {
157    int32_t deviceId;
158    InputHotplugType type;
159    bool isKeyboard { false };
160};
161
162struct InputPointerEvent {
163    int32_t deviceId;
164    int32_t pointerAction;
165    int32_t sourceType;
166    Coordinate position;
167};
168
169using DSoftbusSessionOpened = DDMBoardOnlineEvent;
170using DSoftbusSessionClosed = DDMBoardOnlineEvent;
171
172struct DSoftbusStartCooperate {
173    std::string networkId;
174    std::string originNetworkId;
175    bool success;
176    NormalizedCoordinate cursorPos;
177    StartCooperateData extra;
178    int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) };
179};
180
181using DSoftbusStartCooperateFinished = DSoftbusStartCooperate;
182using DSoftbusComeBack = DSoftbusStartCooperate;
183using DSoftbusStopCooperate = DDMBoardOnlineEvent;
184using DSoftbusStopCooperateFinished = DDMBoardOnlineEvent;
185
186struct DSoftbusRelayCooperate {
187    std::string networkId;
188    std::string targetNetworkId;
189    bool normal;
190};
191
192struct DSoftbusSubscribeMouseLocation {
193    std::string networkId;
194    std::string remoteNetworkId;
195};
196
197struct DSoftbusReplySubscribeMouseLocation {
198    std::string networkId;
199    std::string remoteNetworkId;
200    bool result { false };
201};
202
203struct LocationInfo {
204    int32_t displayX;
205    int32_t displayY;
206    int32_t displayWidth;
207    int32_t displayHeight;
208};
209struct DSoftbusSyncMouseLocation {
210    std::string networkId;
211    std::string remoteNetworkId;
212    LocationInfo mouseLocation;
213};
214
215struct DSoftbusSyncInputDevice {
216    std::string networkId;
217    std::vector<std::shared_ptr<IDevice>> devices;
218};
219
220struct DSoftbusHotPlugEvent {
221    std::string networkId;
222    InputHotplugType type;
223    std::shared_ptr<IDevice> device;
224};
225
226using DSoftbusReplyUnSubscribeMouseLocation = DSoftbusReplySubscribeMouseLocation;
227using DSoftbusUnSubscribeMouseLocation = DSoftbusSubscribeMouseLocation;
228
229using DSoftbusRelayCooperateFinished = DSoftbusRelayCooperate;
230
231struct UpdateCooperateFlagEvent {
232    uint32_t mask;
233    uint32_t flag;
234};
235
236struct SetDamplingCoefficientEvent {
237    uint32_t direction;
238    double coefficient;
239};
240
241struct CooperateEvent {
242    CooperateEvent() : type(CooperateEventType::QUIT) {}
243
244    explicit CooperateEvent(CooperateEventType ty) : type(ty) {}
245
246    template<typename Event>
247    CooperateEvent(CooperateEventType ty, Event ev) : type(ty), event(ev) {}
248
249    CooperateEventType type;
250    std::variant<
251        AddObserverEvent,
252        RegisterListenerEvent,
253        StartCooperateEvent,
254        StopCooperateEvent,
255        EnableCooperateEvent,
256        GetCooperateStateEvent,
257        RegisterEventListenerEvent,
258        DSoftbusSubscribeMouseLocation,
259        DSoftbusReplySubscribeMouseLocation,
260        DSoftbusSyncMouseLocation,
261        DumpEvent,
262        DDMBoardOnlineEvent,
263        InputHotplugEvent,
264        InputPointerEvent,
265        DSoftbusStartCooperate,
266        DSoftbusRelayCooperate,
267        ClientDiedEvent,
268        UpdateCooperateFlagEvent,
269        SetDamplingCoefficientEvent,
270        DSoftbusSyncInputDevice,
271        DSoftbusHotPlugEvent
272    > event;
273};
274
275inline constexpr int32_t DEFAULT_TIMEOUT { 3000 };
276inline constexpr int32_t REPEAT_ONCE { 1 };
277inline constexpr int32_t DEFAULT_COOLING_TIME { 10 };
278inline constexpr int32_t POINTER_EVENT_TIMEOUT { 10000 };
279inline constexpr int32_t SCREEN_LOCKED_TIMEOUT { 600000 };
280} // namespace Cooperate
281} // namespace DeviceStatus
282} // namespace Msdp
283} // namespace OHOS
284#endif // COOPERATE_EVENTS_H
285