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 27 namespace OHOS { 28 namespace Msdp { 29 namespace DeviceStatus { 30 namespace Cooperate { 31 enum CooperateState : size_t { 32 COOPERATE_STATE_FREE = 0, 33 COOPERATE_STATE_OUT, 34 COOPERATE_STATE_IN, 35 N_COOPERATE_STATES, 36 }; 37 38 enum 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 WITH_OPTIONS_START, 51 STOP, 52 GET_COOPERATE_STATE, 53 REGISTER_EVENT_LISTENER, 54 UNREGISTER_EVENT_LISTENER, 55 UPDATE_COOPERATE_FLAG, 56 SET_DAMPLING_COEFFICIENT, 57 DUMP, 58 APP_CLOSED, 59 DDM_BOARD_ONLINE, 60 DDM_BOARD_OFFLINE, 61 DDP_COOPERATE_SWITCH_CHANGED, 62 INPUT_HOTPLUG_EVENT, 63 INPUT_POINTER_EVENT, 64 DSOFTBUS_SESSION_OPENED, 65 DSOFTBUS_SESSION_CLOSED, 66 DSOFTBUS_START_COOPERATE, 67 DSOFTBUS_COME_BACK, 68 DSOFTBUS_STOP_COOPERATE, 69 DSOFTBUS_RELAY_COOPERATE, 70 DSOFTBUS_RELAY_COOPERATE_FINISHED, 71 DSOFTBUS_SUBSCRIBE_MOUSE_LOCATION, 72 DSOFTBUS_UNSUBSCRIBE_MOUSE_LOCATION, 73 DSOFTBUS_REPLY_SUBSCRIBE_MOUSE_LOCATION, 74 DSOFTBUS_REPLY_UNSUBSCRIBE_MOUSE_LOCATION, 75 DSOFTBUS_MOUSE_LOCATION, 76 DSOFTBUS_INPUT_DEV_SYNC, 77 DSOFTBUS_INPUT_DEV_HOT_PLUG, 78 UPDATE_VIRTUAL_DEV_ID_MAP, 79 DSOFTBUS_COME_BACK_WITH_OPTIONS, 80 DSOFTBUS_COOPERATE_WITH_OPTIONS, 81 DSOFTBUS_RELAY_COOPERATE_WITHOPTIONS, 82 DSOFTBUS_RELAY_COOPERATE_WITHOPTIONS_FINISHED 83 }; 84 85 struct Rectangle { 86 int32_t width; 87 int32_t height; 88 int32_t x; 89 int32_t y; 90 }; 91 92 struct AddObserverEvent { 93 std::shared_ptr<ICooperateObserver> observer; 94 }; 95 using RemoveObserverEvent = AddObserverEvent; 96 97 struct RegisterListenerEvent { 98 int32_t pid; 99 int32_t userData; 100 }; 101 102 using UnregisterListenerEvent = RegisterListenerEvent; 103 using RegisterHotareaListenerEvent = RegisterListenerEvent; 104 using UnregisterHotareaListenerEvent = RegisterListenerEvent; 105 using DisableCooperateEvent = RegisterListenerEvent; 106 107 struct StartCooperateEvent { 108 int32_t pid; 109 int32_t userData; 110 std::string remoteNetworkId; 111 int32_t startDeviceId; 112 std::shared_ptr<std::promise<int32_t>> errCode; 113 }; 114 115 struct EnableCooperateEvent { 116 int32_t tokenId; 117 int32_t pid; 118 int32_t userData; 119 }; 120 121 struct ClientDiedEvent { 122 int32_t pid; 123 }; 124 125 struct StopCooperateEvent { 126 int32_t pid; 127 int32_t userData; 128 bool isUnchained; 129 std::string networkId; 130 }; 131 132 struct GetCooperateStateEvent { 133 int32_t pid; 134 int32_t userData; 135 std::string networkId; 136 }; 137 138 struct RegisterEventListenerEvent { 139 int32_t pid; 140 std::string networkId; 141 }; 142 using UnregisterEventListenerEvent = RegisterEventListenerEvent; 143 144 struct DumpEvent { 145 int32_t fd; 146 }; 147 148 struct DDMBoardOnlineEvent { 149 std::string networkId; 150 bool normal; 151 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 152 }; 153 154 struct StatusChangeEvent { 155 std::string networkId; 156 CoordinationMessage msg { CoordinationMessage::UNKNOW }; 157 }; 158 159 using DDMBoardOfflineEvent = DDMBoardOnlineEvent; 160 using DDPCooperateSwitchChanged = DDMBoardOnlineEvent; 161 162 enum class InputHotplugType { 163 PLUG, 164 UNPLUG, 165 }; 166 167 struct InputHotplugEvent { 168 int32_t deviceId; 169 InputHotplugType type; 170 bool isKeyboard { false }; 171 }; 172 173 struct InputPointerEvent { 174 int32_t deviceId; 175 int32_t pointerAction; 176 int32_t sourceType; 177 Coordinate position; 178 int32_t currentDisplayId { 0 }; 179 }; 180 181 using DSoftbusSessionOpened = DDMBoardOnlineEvent; 182 using DSoftbusSessionClosed = DDMBoardOnlineEvent; 183 184 struct DSoftbusStartCooperate { 185 std::string networkId; 186 std::string originNetworkId; 187 bool success; 188 NormalizedCoordinate cursorPos; 189 StartCooperateData extra; 190 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 191 int32_t pointerSpeed { -1 }; 192 int32_t touchPadSpeed { -1 }; 193 }; 194 195 struct DSoftbusCooperateOptions { 196 std::string networkId; 197 std::string originNetworkId; 198 bool success; 199 NormalizedCooperateOptions cooperateOptions; 200 StartCooperateData extra; 201 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 202 }; 203 204 using DSoftbusStartCooperateFinished = DSoftbusStartCooperate; 205 using DSoftbusComeBack = DSoftbusStartCooperate; 206 using DSoftbusStopCooperate = DDMBoardOnlineEvent; 207 using DSoftbusStopCooperateFinished = DDMBoardOnlineEvent; 208 using DSoftbusCooperateWithOptionsFinished = DSoftbusCooperateOptions; 209 using DSoftbusComeBackWithOptions = DSoftbusCooperateOptions; 210 211 struct DSoftbusRelayCooperate { 212 std::string networkId; 213 std::string targetNetworkId; 214 bool normal; 215 int32_t pointerSpeed { -1 }; 216 int32_t touchPadSpeed { -1 }; 217 }; 218 219 struct DSoftbusSubscribeMouseLocation { 220 std::string networkId; 221 std::string remoteNetworkId; 222 }; 223 224 struct DSoftbusReplySubscribeMouseLocation { 225 std::string networkId; 226 std::string remoteNetworkId; 227 bool result { false }; 228 }; 229 230 struct LocationInfo { 231 int32_t displayX; 232 int32_t displayY; 233 int32_t displayWidth; 234 int32_t displayHeight; 235 }; 236 struct DSoftbusSyncMouseLocation { 237 std::string networkId; 238 std::string remoteNetworkId; 239 LocationInfo mouseLocation; 240 }; 241 242 struct DSoftbusSyncInputDevice { 243 std::string networkId; 244 std::vector<std::shared_ptr<IDevice>> devices; 245 }; 246 247 struct DSoftbusHotPlugEvent { 248 std::string networkId; 249 InputHotplugType type; 250 std::shared_ptr<IDevice> device; 251 }; 252 253 struct NotAollowCooperateWhenMotionDragging { 254 int32_t pid; 255 int32_t userData; 256 std::string networkId; 257 bool success; 258 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 259 }; 260 261 using DSoftbusReplyUnSubscribeMouseLocation = DSoftbusReplySubscribeMouseLocation; 262 using DSoftbusUnSubscribeMouseLocation = DSoftbusSubscribeMouseLocation; 263 264 using DSoftbusRelayCooperateFinished = DSoftbusRelayCooperate; 265 266 struct UpdateCooperateFlagEvent { 267 uint32_t mask; 268 uint32_t flag; 269 }; 270 271 struct SetDamplingCoefficientEvent { 272 uint32_t direction; 273 double coefficient; 274 }; 275 276 struct UpdateVirtualDeviceIdMapEvent { 277 std::unordered_map<int32_t, int32_t> remote2VirtualIds; 278 }; 279 280 struct StartWithOptionsEvent { 281 int32_t pid { -1 }; 282 int32_t userData { 0 }; 283 std::string remoteNetworkId; 284 int32_t startDeviceId { -1 }; 285 int32_t displayX { -1 }; 286 int32_t displayY { -1 }; 287 int32_t displayId { -1 }; 288 std::shared_ptr<std::promise<int32_t>> errCode; 289 }; 290 291 struct CooperateEvent { CooperateEventCooperateEvent292 CooperateEvent() : type(CooperateEventType::QUIT) {} 293 CooperateEventCooperateEvent294 explicit CooperateEvent(CooperateEventType ty) : type(ty) {} 295 296 template<typename Event> CooperateEventCooperateEvent297 CooperateEvent(CooperateEventType ty, Event ev) : type(ty), event(ev) {} 298 299 CooperateEventType type; 300 std::variant< 301 AddObserverEvent, 302 RegisterListenerEvent, 303 StartCooperateEvent, 304 StopCooperateEvent, 305 EnableCooperateEvent, 306 GetCooperateStateEvent, 307 RegisterEventListenerEvent, 308 DSoftbusSubscribeMouseLocation, 309 DSoftbusReplySubscribeMouseLocation, 310 DSoftbusSyncMouseLocation, 311 DumpEvent, 312 DDMBoardOnlineEvent, 313 InputHotplugEvent, 314 InputPointerEvent, 315 DSoftbusStartCooperate, 316 DSoftbusRelayCooperate, 317 ClientDiedEvent, 318 UpdateCooperateFlagEvent, 319 SetDamplingCoefficientEvent, 320 DSoftbusSyncInputDevice, 321 DSoftbusHotPlugEvent, 322 UpdateVirtualDeviceIdMapEvent, 323 StartWithOptionsEvent, 324 DSoftbusCooperateOptions, 325 NotAollowCooperateWhenMotionDragging 326 > event; 327 }; 328 329 inline constexpr int32_t DEFAULT_TIMEOUT { 5000 }; 330 inline constexpr int32_t REPEAT_ONCE { 1 }; 331 inline constexpr int32_t DEFAULT_COOLING_TIME { 10 }; 332 inline constexpr int32_t POINTER_EVENT_TIMEOUT { 10000 }; 333 inline constexpr int32_t SCREEN_LOCKED_TIMEOUT { 600000 }; 334 } // namespace Cooperate 335 } // namespace DeviceStatus 336 } // namespace Msdp 337 } // namespace OHOS 338 #endif // COOPERATE_EVENTS_H 339