1 /* 2 * Copyright (c) 2023-2025 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 STOP_ABOUT_VIRTUALTRACKPAD 84 }; 85 86 struct Rectangle { 87 int32_t width; 88 int32_t height; 89 int32_t x; 90 int32_t y; 91 }; 92 93 struct AddObserverEvent { 94 std::shared_ptr<ICooperateObserver> observer; 95 }; 96 using RemoveObserverEvent = AddObserverEvent; 97 98 struct RegisterListenerEvent { 99 int32_t pid; 100 int32_t userData; 101 }; 102 103 using UnregisterListenerEvent = RegisterListenerEvent; 104 using RegisterHotareaListenerEvent = RegisterListenerEvent; 105 using UnregisterHotareaListenerEvent = RegisterListenerEvent; 106 using DisableCooperateEvent = RegisterListenerEvent; 107 108 struct StartCooperateEvent { 109 int32_t pid; 110 int32_t userData; 111 std::string remoteNetworkId; 112 int32_t startDeviceId; 113 std::shared_ptr<std::promise<int32_t>> errCode; 114 int32_t uid { 0 }; 115 }; 116 117 struct EnableCooperateEvent { 118 int32_t tokenId; 119 int32_t pid; 120 int32_t userData; 121 }; 122 123 struct ClientDiedEvent { 124 int32_t pid; 125 }; 126 127 struct StopCooperateEvent { 128 int32_t pid; 129 int32_t userData; 130 bool isUnchained; 131 std::string networkId; 132 }; 133 134 struct GetCooperateStateEvent { 135 int32_t pid; 136 int32_t userData; 137 std::string networkId; 138 }; 139 140 struct RegisterEventListenerEvent { 141 int32_t pid; 142 std::string networkId; 143 }; 144 using UnregisterEventListenerEvent = RegisterEventListenerEvent; 145 146 struct DumpEvent { 147 int32_t fd; 148 }; 149 150 struct DDMBoardOnlineEvent { 151 std::string networkId; 152 bool normal; 153 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 154 }; 155 156 struct StatusChangeEvent { 157 std::string networkId; 158 CoordinationMessage msg { CoordinationMessage::UNKNOW }; 159 }; 160 161 using DDMBoardOfflineEvent = DDMBoardOnlineEvent; 162 using DDPCooperateSwitchChanged = DDMBoardOnlineEvent; 163 164 enum class InputHotplugType { 165 PLUG, 166 UNPLUG, 167 }; 168 169 struct InputHotplugEvent { 170 int32_t deviceId; 171 InputHotplugType type; 172 bool isKeyboard { false }; 173 }; 174 175 struct InputPointerEvent { 176 int32_t deviceId; 177 int32_t pointerAction; 178 int32_t sourceType; 179 Coordinate position; 180 int32_t currentDisplayId { 0 }; 181 }; 182 183 using DSoftbusSessionOpened = DDMBoardOnlineEvent; 184 using DSoftbusSessionClosed = DDMBoardOnlineEvent; 185 186 struct DSoftbusStartCooperate { 187 std::string networkId; 188 std::string originNetworkId; 189 bool success; 190 NormalizedCoordinate cursorPos; 191 StartCooperateData extra; 192 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 193 int32_t pointerSpeed { -1 }; 194 int32_t touchPadSpeed { -1 }; 195 int32_t uid { 0 }; 196 }; 197 198 struct DSoftbusCooperateOptions { 199 std::string networkId; 200 std::string originNetworkId; 201 bool success; 202 NormalizedCooperateOptions cooperateOptions; 203 StartCooperateData extra; 204 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 205 int32_t pointerSpeed { -1 }; 206 int32_t touchPadSpeed { -1 }; 207 }; 208 209 using DSoftbusStartCooperateFinished = DSoftbusStartCooperate; 210 using DSoftbusComeBack = DSoftbusStartCooperate; 211 using DSoftbusStopCooperate = DDMBoardOnlineEvent; 212 using DSoftbusStopCooperateFinished = DDMBoardOnlineEvent; 213 using DSoftbusCooperateWithOptionsFinished = DSoftbusCooperateOptions; 214 using DSoftbusComeBackWithOptions = DSoftbusCooperateOptions; 215 216 struct DSoftbusRelayCooperate { 217 std::string networkId; 218 std::string targetNetworkId; 219 bool normal; 220 int32_t pointerSpeed { -1 }; 221 int32_t touchPadSpeed { -1 }; 222 int32_t uid { 0 }; 223 }; 224 225 struct DSoftbusSubscribeMouseLocation { 226 std::string networkId; 227 std::string remoteNetworkId; 228 }; 229 230 struct DSoftbusReplySubscribeMouseLocation { 231 std::string networkId; 232 std::string remoteNetworkId; 233 bool result { false }; 234 }; 235 236 struct LocationInfo { 237 int32_t displayX; 238 int32_t displayY; 239 int32_t displayWidth; 240 int32_t displayHeight; 241 }; 242 struct DSoftbusSyncMouseLocation { 243 std::string networkId; 244 std::string remoteNetworkId; 245 LocationInfo mouseLocation; 246 }; 247 248 struct DSoftbusSyncInputDevice { 249 std::string networkId; 250 std::vector<std::shared_ptr<IDevice>> devices; 251 }; 252 253 struct DSoftbusHotPlugEvent { 254 std::string networkId; 255 InputHotplugType type; 256 std::shared_ptr<IDevice> device; 257 }; 258 259 struct NotAollowCooperateWhenMotionDragging { 260 int32_t pid; 261 int32_t userData; 262 std::string networkId; 263 bool success; 264 int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) }; 265 }; 266 267 using DSoftbusReplyUnSubscribeMouseLocation = DSoftbusReplySubscribeMouseLocation; 268 using DSoftbusUnSubscribeMouseLocation = DSoftbusSubscribeMouseLocation; 269 270 using DSoftbusRelayCooperateFinished = DSoftbusRelayCooperate; 271 272 struct UpdateCooperateFlagEvent { 273 uint32_t mask; 274 uint32_t flag; 275 }; 276 277 struct SetDamplingCoefficientEvent { 278 uint32_t direction; 279 double coefficient; 280 }; 281 282 struct UpdateVirtualDeviceIdMapEvent { 283 std::unordered_map<int32_t, int32_t> remote2VirtualIds; 284 }; 285 286 struct StartWithOptionsEvent { 287 int32_t pid { -1 }; 288 int32_t userData { 0 }; 289 std::string remoteNetworkId; 290 int32_t startDeviceId { -1 }; 291 int32_t displayX { -1 }; 292 int32_t displayY { -1 }; 293 int32_t displayId { -1 }; 294 std::shared_ptr<std::promise<int32_t>> errCode; 295 }; 296 297 struct CooperateEvent { CooperateEventCooperateEvent298 CooperateEvent() : type(CooperateEventType::QUIT) {} 299 CooperateEventCooperateEvent300 explicit CooperateEvent(CooperateEventType ty) : type(ty) {} 301 302 template<typename Event> CooperateEventCooperateEvent303 CooperateEvent(CooperateEventType ty, Event ev) : type(ty), event(ev) {} 304 305 CooperateEventType type; 306 std::variant< 307 AddObserverEvent, 308 RegisterListenerEvent, 309 StartCooperateEvent, 310 StopCooperateEvent, 311 EnableCooperateEvent, 312 GetCooperateStateEvent, 313 RegisterEventListenerEvent, 314 DSoftbusSubscribeMouseLocation, 315 DSoftbusReplySubscribeMouseLocation, 316 DSoftbusSyncMouseLocation, 317 DumpEvent, 318 DDMBoardOnlineEvent, 319 InputHotplugEvent, 320 InputPointerEvent, 321 DSoftbusStartCooperate, 322 DSoftbusRelayCooperate, 323 ClientDiedEvent, 324 UpdateCooperateFlagEvent, 325 SetDamplingCoefficientEvent, 326 DSoftbusSyncInputDevice, 327 DSoftbusHotPlugEvent, 328 UpdateVirtualDeviceIdMapEvent, 329 StartWithOptionsEvent, 330 DSoftbusCooperateOptions, 331 NotAollowCooperateWhenMotionDragging 332 > event; 333 }; 334 335 inline constexpr int32_t DEFAULT_TIMEOUT { 5000 }; 336 inline constexpr int32_t REPEAT_ONCE { 1 }; 337 inline constexpr int32_t DEFAULT_COOLING_TIME { 10 }; 338 inline constexpr int32_t POINTER_EVENT_TIMEOUT { 10000 }; 339 inline constexpr int32_t SCREEN_LOCKED_TIMEOUT { 600000 }; 340 } // namespace Cooperate 341 } // namespace DeviceStatus 342 } // namespace Msdp 343 } // namespace OHOS 344 #endif // COOPERATE_EVENTS_H 345