1 /*
2  * Copyright (c) 2020-2021 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 GRAPHIC_LITE_INPUT_EVENT_PROXY_H
17 #define GRAPHIC_LITE_INPUT_EVENT_PROXY_H
18 
19 #include "input_event_distributer.h"
20 #include "gfx_utils/input_event_info.h"
21 #include "input_manager_service.h"
22 #include "ipc_skeleton.h"
23 #include "serializer.h"
24 #include <pthread.h>
25 #include <map>
26 
27 namespace OHOS {
28 constexpr uint8_t MAX_CLIENT_SIZE = 1;
29 class InputEventClientProxy : public InputEventDistributer::RawEventListener {
30 public:
31     static InputEventClientProxy* GetInstance();
32 
33     static void ClientRequestHandle(int funcId, void* origin, IpcIo* req, IpcIo* reply);
34 
35 private:
InputEventClientProxy()36     InputEventClientProxy()
37     {
38         InputManagerService::GetInstance()->GetDistributer()->AddRawEventListener(this);
39         pthread_mutex_init(&lock_, nullptr);
40     }
41 
~InputEventClientProxy()42     ~InputEventClientProxy()
43     {
44         pthread_mutex_destroy(&lock_);
45     }
46 
47     struct ClientInfo {
48         SvcIdentity svc;
49         uint32_t cdId;
50         bool alwaysInvoke;
51     };
52 
53     std::map<pid_t, ClientInfo> clientInfoMap_;
54     static pthread_mutex_t lock_;
55     int16_t lastState_ = 0;
56 
57     InputEventClientProxy(const InputEventClientProxy&) = delete;
58     InputEventClientProxy& operator=(const InputEventClientProxy&) = delete;
59     InputEventClientProxy(InputEventClientProxy&&) = delete;
60     InputEventClientProxy& operator=(InputEventClientProxy&&) = delete;
61 
62     void OnRawEvent(const RawEvent& event) override;
63     void AddListener(const void* origin, IpcIo* req, IpcIo* reply);
64     void RemoveListener(const void* origin, IpcIo* req, IpcIo* reply);
65     static void DeathCallback(void* origin);
66 };
67 }
68 #endif