• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "domain/domain_manager.h"
21 #include "event/event_base.h"
22 #include "event/handle_event_base.h"
23 #include "interaction.h"
24 #include "interaction/interprocess/ipc_msg_adapter.h"
25 #include "singleton.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     using Ptr = std::shared_ptr<InteractionManager>;
51     InteractionManager();
52     ~InteractionManager() override;
53 
54     void Init();
55     void RemoveInteraction(uint32_t interactionId);
56     void DestroyInteraction(uint32_t interactionId);
57     int32_t HandleEvent(SharingEvent &event) final;
58     Interaction::Ptr CreateInteraction(const std::string &className);
59 
60     void DelInteractionKey(const std::string &key);
61     void AddInteractionKey(const std::string &key, uint32_t interactionId);
62     int32_t GetInteractionId(const std::string &key);
63 
64     int32_t SendDomainMsg(std::shared_ptr<BaseDomainMsg> msg);
65     int32_t OnDomainMsg(std::shared_ptr<BaseDomainMsg> msg) override;
66 
67     Interaction::Ptr GetInteraction(const std::string &key);
68     Interaction::Ptr GetInteraction(uint32_t interactionId);
69 
70 private:
71     std::mutex mutex_;
72     Ptr sharedFromThis_ = nullptr;
73     std::unordered_map<std::string, uint32_t> interactionKeys_;
74     std::unordered_map<uint32_t, Interaction::Ptr> interactions_;
75 };
76 
77 } // namespace Sharing
78 } // namespace OHOS
79 #endif