1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_DRM_EVENT_LISTENER_H_
18 #define ANDROID_DRM_EVENT_LISTENER_H_
19 
20 #include "autofd.h"
21 #include "worker.h"
22 
23 #include <sys/epoll.h>
24 
25 namespace android {
26 
27 class DrmDevice;
28 
29 class DrmEventHandler {
30  public:
DrmEventHandler()31   DrmEventHandler() {
32   }
~DrmEventHandler()33   virtual ~DrmEventHandler() {
34   }
35 
36   virtual void HandleEvent(uint64_t timestamp_us) = 0;
37 };
38 
39 class DrmTUIEventHandler {
40  public:
DrmTUIEventHandler()41   DrmTUIEventHandler() {
42   }
~DrmTUIEventHandler()43   virtual ~DrmTUIEventHandler() {
44   }
45 
46   virtual void HandleTUIEvent() = 0;
47 };
48 
49 class DrmEventListener : public Worker {
50  static constexpr const char kTUIStatusPath[] = "/sys/devices/platform/exynos-drm/tui_status";
51  static const uint32_t maxFds = 3;
52  public:
53   DrmEventListener(DrmDevice *drm);
54   virtual ~DrmEventListener();
55 
56   int Init();
57 
58   void RegisterHotplugHandler(DrmEventHandler *handler);
59   void UnRegisterHotplugHandler(DrmEventHandler *handler);
60   void RegisterTUIHandler(DrmTUIEventHandler *handler);
61   void UnRegisterTUIHandler(DrmTUIEventHandler *handler);
62 
63   bool IsDrmInTUI();
64 
65   static void FlipHandler(int fd, unsigned int sequence, unsigned int tv_sec,
66                           unsigned int tv_usec, void *user_data);
67 
68  protected:
69   virtual void Routine();
70 
71  private:
72   void UEventHandler();
73   void TUIEventHandler();
74 
75   UniqueFd epoll_fd_;
76   UniqueFd uevent_fd_;
77   UniqueFd tuievent_fd_;
78 
79   DrmDevice *drm_;
80   std::unique_ptr<DrmEventHandler> hotplug_handler_;
81   std::unique_ptr<DrmTUIEventHandler> tui_handler_;
82 };
83 }  // namespace android
84 
85 #endif
86