• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef INPUT_DEVICE_COOPERATE_IMPL_H
16 #define INPUT_DEVICE_COOPERATE_IMPL_H
17 
18 #include <functional>
19 #include <list>
20 #include <map>
21 #include <mutex>
22 
23 #include "nocopyable.h"
24 
25 #include "cooperation_message.h"
26 #include "i_input_device_cooperate_listener.h"
27 
28 namespace OHOS {
29 namespace MMI {
30 class InputDeviceCooperateImpl {
31 public:
32     static InputDeviceCooperateImpl &GetInstance();
33     DISALLOW_COPY_AND_MOVE(InputDeviceCooperateImpl);
34     ~InputDeviceCooperateImpl() = default;
35 
36     using FuncCooperationMessage = std::function<void(std::string, CooperationMessage)>;
37     using FuncCooperateionState = std::function<void(bool)>;
38 
39     using DevCooperationMsg = FuncCooperationMessage;
40     using DevCooperateionState = FuncCooperateionState;
41 
42     using InputDevCooperateListenerPtr = std::shared_ptr<IInputDeviceCooperateListener>;
43 
44     struct CooperateEvent {
45         DevCooperationMsg msg;
46         DevCooperateionState state;
47     };
48 
49     int32_t RegisterCooperateListener(InputDevCooperateListenerPtr listener);
50     int32_t UnregisterCooperateListener(InputDevCooperateListenerPtr listener = nullptr);
51     int32_t EnableInputDeviceCooperate(bool enabled, FuncCooperationMessage callback);
52     int32_t StartInputDeviceCooperate(const std::string &sinkDeviceId, int32_t srcInputDeviceId,
53         FuncCooperationMessage callback);
54     int32_t StopDeviceCooperate(FuncCooperationMessage callback);
55     int32_t GetInputDeviceCooperateState(const std::string &deviceId, FuncCooperateionState callback);
56     void OnDevCooperateListener(const std::string deviceId, CooperationMessage msg);
57     void OnCooprationMessage(int32_t userData, const std::string deviceId, CooperationMessage msg);
58     void OnCooperationState(int32_t userData, bool state);
59     int32_t GetUserData();
60 
61 private:
62     const DevCooperationMsg *GetCooprateMessageEvent(int32_t userData) const;
63     const DevCooperateionState *GetCooprateStateEvent(int32_t userData) const;
64 
65 private:
66     InputDeviceCooperateImpl() = default;
67     std::list<InputDevCooperateListenerPtr> devCooperateListener_;
68     std::map<int32_t, CooperateEvent> devCooperateEvent_;
69     std::mutex mtx_;
70     int32_t userData_ { 0 };
71     bool isListeningProcess_ { false };
72 };
73 } // namespace MMI
74 } // namespace OHOS
75 #define InputDevCooperateImpl OHOS::MMI::InputDeviceCooperateImpl::GetInstance()
76 #endif // INPUT_DEVICE_COOPERATE_IMPL_H