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