DSInput: Add device add/remove signals 05/241605/1
authorjeon <jhyuni.kang@samsung.com>
Fri, 10 Jul 2020 04:33:01 +0000 (13:33 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 09:46:24 +0000 (18:46 +0900)
Change-Id: I39a13760d26abb5283cfa8cfcc3990915bbcf684

src/DSInput/DSInput.cpp
src/DSInput/DSInput.h

index 63838dd..b59361f 100644 (file)
@@ -37,15 +37,19 @@ void DSInputPrivate::PostDeviceRemoveEvent(std::string seat, std::string name, s
 DSInput::DSInput()
        : DS_INIT_PRIVATE_PTR(DSInput)
 {
-       DS_GET_PRIV(DSInput);
-
-       priv->Init();
 }
 
 DSInput::~DSInput()
 {
 }
 
+void DSInput::Init()
+{
+       DS_GET_PRIV(DSInput);
+
+       priv->Init();
+}
+
 void DSInput::deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass)
 {
        DSInputDevice *device = new DSInputDevice(name, identifier, devClass, devSubclass);
@@ -59,6 +63,8 @@ void DSInput::deviceAdd(std::string name, std::string identifier, DSInput::Devic
                }
        }
 
+       this->__deviceAddSignal.emit(std::make_shared<DSInputDevice>(*device));
+
        devList.push_back(device);
 }
 
@@ -70,6 +76,8 @@ void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::De
        {
                if (*dev == *device)
                {
+                       this->__deviceRemoveSignal.emit(std::make_shared<DSInputDevice>(*dev));
+
                        devList.remove(dev);
                        delete dev;
                        break;
@@ -79,6 +87,17 @@ void DSInput::deviceRemove(std::string name, std::string identifier, DSInput::De
        delete device;
 }
 
+void DSInput::registerCallbackDeviceAdd(DSObject *slot, std::function<void(std::shared_ptr<DSInputDevice>)> func)
+{
+       this->__deviceAddSignal.connect(slot, func);
+}
+
+void DSInput::registerCallbackDeviceRemove(DSObject *slot, std::function<void(std::shared_ptr<DSInputDevice>)> func)
+{
+       this->__deviceRemoveSignal.connect(slot, func);
+}
+
+
 DSInputDevice::DSInputDevice()
        : __deviceName(""),
          __deviceIdentifier(""),
index 1cde6bf..86931e3 100644 (file)
@@ -6,6 +6,8 @@
 #include <iostream>
 #include <string>
 #include <memory>
+#include <DSSignal.h>
+#include <functional>
 
 namespace display_server
 {
@@ -30,11 +32,19 @@ public:
        DSInput();
        ~DSInput() override;
 
+       void Init();
+
        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);
 
+       void registerCallbackDeviceAdd(DSObject *slot, std::function<void(std::shared_ptr<DSInputDevice>)> func);
+       void registerCallbackDeviceRemove(DSObject *slot, std::function<void(std::shared_ptr<DSInputDevice>)> func);
+
 private:
        std::list<DSInputDevice*> devList;
+
+       DSSignal<std::shared_ptr<DSInputDevice>> __deviceAddSignal;
+       DSSignal<std::shared_ptr<DSInputDevice>> __deviceRemoveSignal;
 };
 
 class DSInputDevice