DSInput: control device add/remove events from libinput 94/241594/1
authorjeon <jhyuni.kang@samsung.com>
Thu, 9 Jul 2020 02:38:09 +0000 (11:38 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 09:46:11 +0000 (18:46 +0900)
Change-Id: I62aeff2ca4a28699b59d2fb32555fe4ac799f191

src/DSInput/DSInput.cpp
src/DSInput/DSInput.h
src/DSInput/DSInputPrivate.h
src/DSInput/DSLibinput.cpp
src/DSInput/DSLibinput.h

index 8fe740a..63838dd 100644 (file)
@@ -12,17 +12,73 @@ DSInputPrivate::DSInputPrivate(DSInput * p_ptr)
 
 DSInputPrivate::~DSInputPrivate()
 {
+       if (__dsLibinput) delete __dsLibinput;
+}
+
+void DSInputPrivate::Init()
+{
+       __dsLibinput = new DSLibinput(this);
+}
+
+void DSInputPrivate::PostDeviceAddEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass)
+{
+       DS_GET_PUB(DSInput);
+
+       pub->deviceAdd(name, identifier, devClass, DSInput::NoneSubclass);
+}
+
+void DSInputPrivate::PostDeviceRemoveEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass)
+{
+       DS_GET_PUB(DSInput);
+
+       pub->deviceRemove(name, identifier, devClass, DSInput::NoneSubclass);
 }
 
 DSInput::DSInput()
        : DS_INIT_PRIVATE_PTR(DSInput)
 {
+       DS_GET_PRIV(DSInput);
+
+       priv->Init();
 }
 
 DSInput::~DSInput()
 {
 }
 
+void DSInput::deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass)
+{
+       DSInputDevice *device = new DSInputDevice(name, identifier, devClass, devSubclass);
+
+       for (auto dev : devList)
+       {
+               if (*dev == *device)
+               {
+                       delete device;
+                       return;
+               }
+       }
+
+       devList.push_back(device);
+}
+
+void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass)
+{
+       DSInputDevice *device = new DSInputDevice(name, identifier, devClass, devSubclass);
+
+       for (auto dev : devList)
+       {
+               if (*dev == *device)
+               {
+                       devList.remove(dev);
+                       delete dev;
+                       break;
+               }
+       }
+
+       delete device;
+}
+
 DSInputDevice::DSInputDevice()
        : __deviceName(""),
          __deviceIdentifier(""),
@@ -43,6 +99,23 @@ DSInputDevice::~DSInputDevice()
 {
 }
 
+void DSInputDevice::print()
+{
+       std::cout << "DeviceInfo: " << "name: " << getName() << ", identifier: " << getIdentifier() << ", class: " << getClass()  << ", subclass: " << getSubclass() << std::endl;
+}
+
+bool DSInputDevice::operator==(DSInputDevice& device)
+{
+       if ((getName().compare(device.getName()) == 0) &&
+           (getIdentifier().compare(device.getIdentifier()) == 0) &&
+           (getClass() == device.getClass()))
+       {
+               return true;
+       }
+
+       return false;
+}
+
 std::string DSInputDevice::getName() const
 {
        return __deviceName;
index fa63afb..1cde6bf 100644 (file)
@@ -11,6 +11,7 @@ namespace display_server
 {
 
 class DSInputPrivate;
+class DSInputDevice;
 
 class DSInput : public DSObject
 {
@@ -28,6 +29,12 @@ public:
 public:
        DSInput();
        ~DSInput() override;
+
+       void deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass);
+       void deviceRemove(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass);
+
+private:
+       std::list<DSInputDevice*> devList;
 };
 
 class DSInputDevice
@@ -37,6 +44,9 @@ public:
        DSInputDevice(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass);
        ~DSInputDevice();
 
+       void print();
+       bool operator==(DSInputDevice& device);
+
        std::string getName() const;
        void setName(std::string name);
 
index bfd7d16..8d566eb 100644 (file)
@@ -2,10 +2,13 @@
 #define _DSINPUTPRIVATE_H_
 
 #include "DSInput.h"
+#include "DSLibinput.h"
 
 namespace display_server
 {
 
+class DSLibinput;
+
 class DSInputPrivate : public DSObjectPrivate
 {
 DS_PIMPL_USE_PUBLIC(DSInput);
@@ -14,8 +17,13 @@ public:
        DSInputPrivate(DSInput *p_ptr);
        ~DSInputPrivate() override;
 
+       void Init();
+
+       void PostDeviceAddEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass);
+       void PostDeviceRemoveEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass);
+
 private:
-       /* data */
+       DSLibinput *__dsLibinput;
 };
 
 }
index d67150e..e6c2683 100644 (file)
@@ -11,8 +11,9 @@ const struct ::libinput_interface DSLibinput::__input_interface = {
        .close_restricted = DSLibinput::__handleCloseRestricted
 };
 
-DSLibinput::DSLibinput()
+DSLibinput::DSLibinput(DSInputPrivate *p_ptr)
 {
+       inputPrivate = p_ptr;
        __udev = udev_new();
        __libinput = libinput_udev_create_context(&__input_interface, this, __udev);
 
@@ -24,6 +25,8 @@ DSLibinput::DSLibinput()
 
        __fd = libinput_get_fd(__libinput);
        __libinput_handler = ecore_main_fd_handler_add(__fd, ECORE_FD_READ, __handleEvents, this, NULL, NULL);
+
+       this->__handleEvents(this, __libinput_handler);
 }
 
 DSLibinput::~DSLibinput()
@@ -111,12 +114,60 @@ Eina_Bool DSLibinput::__handleEvents(void *data, Ecore_Fd_Handler *hdlr)
 
 void DSLibinput::__processDeviceAddEvent(struct ::libinput_event *event)
 {
-       ;
+       struct ::libinput *libinput;
+       struct ::libinput_seat *libinput_seat;
+       struct ::libinput_device *device;
+       std::string seatName, devName, identifier;
+
+       libinput = libinput_event_get_context(event);
+       device = libinput_event_get_device(event);
+       libinput_seat = libinput_device_get_seat(device);
+
+       seatName = libinput_seat_get_logical_name(libinput_seat);
+       devName = libinput_device_get_name(device);
+       identifier= (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
+       {
+               inputPrivate->PostDeviceAddEvent(seatName, devName, identifier, DSInput::KeyboardClass);
+       }
+       else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
+       {
+               inputPrivate->PostDeviceAddEvent(seatName, devName, identifier, DSInput::PointerClass);
+       }
+       else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
+       {
+               inputPrivate->PostDeviceAddEvent(seatName, devName, identifier, DSInput::TouchClass);
+       }
 }
 
 void DSLibinput::__processDeviceRemoveEvent(struct ::libinput_event *event)
 {
-       ;
+       struct ::libinput *libinput;
+       struct ::libinput_seat *libinput_seat;
+       struct ::libinput_device *device;
+       std::string seatName, devName, identifier;
+
+       libinput = libinput_event_get_context(event);
+       device = libinput_event_get_device(event);
+       libinput_seat = libinput_device_get_seat(device);
+
+       seatName = libinput_seat_get_logical_name(libinput_seat);
+       devName = libinput_device_get_name(device);
+       identifier= (std::string)"/dev/input/" + (std::string)libinput_device_get_sysname(device);
+
+       if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
+       {
+               inputPrivate->PostDeviceRemoveEvent(seatName, devName, identifier, DSInput::KeyboardClass);
+       }
+       else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
+       {
+               inputPrivate->PostDeviceRemoveEvent(seatName, devName, identifier, DSInput::PointerClass);
+       }
+       else if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
+       {
+               inputPrivate->PostDeviceRemoveEvent(seatName, devName, identifier, DSInput::TouchClass);
+       }
 }
 
 void DSLibinput::__processKeyboardKeyEvent(struct ::libinput_event *event)
index adcb43b..b934bd7 100644 (file)
@@ -9,6 +9,7 @@
 #include <libinput.h>
 #include <libudev.h>
 #include <Ecore.h>
+#include "DSInputPrivate.h"
 
 namespace display_server
 {
@@ -16,10 +17,12 @@ namespace display_server
 class DSLibinput
 {
 public:
-       DSLibinput();
+       DSLibinput() = delete;
+       DSLibinput(DSInputPrivate *p_ptr);
        ~DSLibinput();
 
 private:
+       DSInputPrivate *inputPrivate;
        struct ::libinput *__libinput;
        udev *__udev;
        int __fd;