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 STATE_CHANGE_NOTIFY_H 17 #define STATE_CHANGE_NOTIFY_H 18 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 23 #include "drag_data.h" 24 #include "stream_session.h" 25 26 namespace OHOS { 27 namespace Msdp { 28 namespace DeviceStatus { 29 class StateChangeNotify final { 30 public: 31 StateChangeNotify() = default; 32 ~StateChangeNotify() = default; 33 34 struct MessageInfo { 35 MessageId msgId { MessageId::INVALID }; 36 SessionPtr session { nullptr }; 37 DragState state { DragState::ERROR }; 38 bool operator==(std::shared_ptr<MessageInfo> info) 39 { 40 if (info == nullptr || info->session == nullptr) { 41 return false; 42 } 43 return session->GetPid() == info->session->GetPid(); 44 } 45 }; 46 47 void AddNotifyMsg(std::shared_ptr<MessageInfo> info); 48 void RemoveNotifyMsg(std::shared_ptr<MessageInfo> info); 49 int32_t StateChangedNotify(DragState state); 50 51 private: 52 void OnStateChangedNotify(SessionPtr session, MessageId msId, DragState state); 53 54 private: 55 std::list<std::shared_ptr<MessageInfo>> msgInfos_; 56 }; 57 } // namespace DeviceStatus 58 } // namespace Msdp 59 } // namespace OHOS 60 #endif // STATE_CHANGE_NOTIFY_H 61