1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 OHOS_SHARING_INTERACTION_MANAGER_H 17 #define OHOS_SHARING_INTERACTION_MANAGER_H 18 19 #include <unordered_map> 20 #include "event/event_base.h" 21 #include "event/handle_event_base.h" 22 #include "interaction.h" 23 #include "interaction/interprocess/ipc_msg_adapter.h" 24 #include "singleton.h" 25 #include "domain/domain_manager.h" 26 27 namespace OHOS { 28 namespace Sharing { 29 30 class InteractionEventListener : public EventListener { 31 public: InteractionEventListener()32 InteractionEventListener() 33 { 34 SHARING_LOGD("trace."); 35 classType_ = CLASS_TYPE_INTERACTION; 36 } 37 38 virtual ~InteractionEventListener() = default; 39 40 int32_t OnEvent(SharingEvent &event) final; 41 }; 42 43 class InteractionManager final : public Singleton<InteractionManager>, 44 public HandleEventBase, 45 public DomainManagerListener, 46 public EventEmitter { 47 friend class Singleton<InteractionManager>; 48 49 public: 50 InteractionManager(); 51 ~InteractionManager() override; 52 53 void Init(); 54 void RemoveInteraction(uint32_t interactionId); 55 void DestroyInteraction(uint32_t interactionId); 56 int32_t HandleEvent(SharingEvent &event) final; 57 Interaction::Ptr CreateInteraction(const std::string &className); 58 59 void DelInteractionKey(const std::string &key); 60 void AddInteractionKey(const std::string &key, uint32_t interactionId); 61 int32_t GetInteractionId(const std::string &key); 62 63 int32_t SendDomainMsg(std::shared_ptr<BaseDomainMsg> msg); 64 int32_t OnDomainMsg(std::shared_ptr<BaseDomainMsg> msg) override; 65 66 Interaction::Ptr GetInteraction(const std::string &key); 67 Interaction::Ptr GetInteraction(uint32_t interactionId); 68 69 private: 70 std::mutex mutex_; 71 std::unordered_map<std::string, uint32_t> interactionKeys_; 72 std::unordered_map<uint32_t, Interaction::Ptr> interactions_; 73 }; 74 75 } // namespace Sharing 76 } // namespace OHOS 77 #endif