DSDisplayDeviceOutput: implement the output callback of the OutputTDM implements 42/241542/1
authorSooChan Lim <sc1.lim@samsung.com>
Tue, 23 Jun 2020 06:45:57 +0000 (15:45 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 09:44:59 +0000 (18:44 +0900)
There are five callback functions for the DeviceOuput.

IDSDisplayDevice class has OutputAdded and OutputRemoved callbacks.
  virtual void registerCallbackOutputAdded(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
  virtual void registerCallbackOutputRemoved(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;

IDSDisplayDeviceOutput class has OutputConnected, OutputDisconnected and OutputResolutionSet callbacks.
  virtual void registerCallbackOutputConnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
  virtual void registerCallbackOutputDisconnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
  virtual void registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;

DSDisplayDeviceTDMImpl and DSDisplayDeviceOutputTDMImpl override these functions and implement them.

Change-Id: If76a02aa5348d5e1b5827960e86c2de55729792f

src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp
src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h
src/DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp
src/DSDisplayDevice/DSDisplayDeviceTDMImpl.h
src/DSDisplayDevice/IDSDisplayDevice.h
src/DSDisplayDevice/IDSDisplayDeviceOutput.h
tests/DSDisplayDeviceTDMImpl-test.cpp

index 6032cc5..9941820 100644 (file)
@@ -5,6 +5,21 @@
 
 namespace display_server
 {
+
+DSDisplayDeviceOutputTDMImpl::DSDisplayDeviceOutputTDMImpl()
+       : __toutput(nullptr),
+         __resolutionWidth(0),
+         __resolutionHeight(0),
+         __physicalMMWidth(0),
+         __physicalMMHeight(0),
+         __mode(nullptr),
+         __dpmsMode(IDSDisplayDeviceOutput::DPMS_OFF),
+         __displayDeviceHWC(nullptr)
+{
+       __initializeConnectorType();
+       __updateConnectState();
+}
+
 DSDisplayDeviceOutputTDMImpl::DSDisplayDeviceOutputTDMImpl(tdm_output *toutput)
        : __toutput(toutput),
          __resolutionWidth(0),
@@ -234,4 +249,34 @@ void DSDisplayDeviceOutputTDMImpl::__updateAvailableModeList()
        }
 }
 
+void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputConnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+{
+       this->__connectedSignal.connect(slot, func);
+}
+
+void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputDisconnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+{
+       this->__disconnectedSignal.connect(slot, func);
+}
+
+void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+{
+       this->__resolutionSetSignal.connect(slot, func);
+}
+
+void DSDisplayDeviceOutputTDMImpl::callCallbackOutputConnected()
+{
+       this->__connectedSignal.emit(this);
+}
+
+void DSDisplayDeviceOutputTDMImpl::callCallbackOutputDisconnected()
+{
+       this->__disconnectedSignal.emit(this);
+}
+
+void DSDisplayDeviceOutputTDMImpl::callCallbackOutputResolutionSet()
+{
+       this->__resolutionSetSignal.emit(this);
+}
+
 } // namespace display_server
index ba3041a..82dba0d 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "IDSDisplayDeviceOutput.h"
 #include "IDSDisplayDeviceHWC.h"
+#include "DSSignal.h"
 #include <tdm.h>
 
 namespace display_server
@@ -10,6 +11,7 @@ namespace display_server
 class DSDisplayDeviceOutputTDMImpl : public IDSDisplayDeviceOutput
 {
 public:
+       DSDisplayDeviceOutputTDMImpl();
        DSDisplayDeviceOutputTDMImpl(tdm_output *toutput);
        ~DSDisplayDeviceOutputTDMImpl();
 
@@ -26,12 +28,16 @@ public:
        DPMSMode getDPMSMode() override;
        IDSDisplayDeviceHWC *getHWC() override;
 
-       //TODO: int CallbackOutputAdded() override;
-       //TODO: int CallbackOutputRemoved() override;
-       //TODO: int CallbackOutputConnected() override;
-       //TODO: int CallbackOutputDisconnected() override;
-       //TODO: int CallbackOutputResolutionSet() override;
-       //TODO: int CallbackOutputVBlankTriggered() override;
+       // register callback functions
+       void registerCallbackOutputConnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) override;
+       void registerCallbackOutputDisconnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) override;
+       void registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) override;
+
+       // emit functions
+       void callCallbackOutputConnected();
+       void callCallbackOutputDisconnected();
+       void callCallbackOutputResolutionSet();
+
 private:
        void __initializeConnectorType();
        void __updateConnectState();
@@ -50,6 +56,11 @@ private:
        IDSDisplayDeviceOutput::DPMSMode __dpmsMode;
 
        IDSDisplayDeviceHWC *__displayDeviceHWC;
+
+       // signals
+       DSSignal<IDSDisplayDeviceOutput *> __connectedSignal;
+       DSSignal<IDSDisplayDeviceOutput *> __disconnectedSignal;
+       DSSignal<IDSDisplayDeviceOutput *> __resolutionSetSignal;
 };
 }
 
index f79af90..66e35e5 100644 (file)
@@ -41,9 +41,34 @@ std::list<IDSDisplayDeviceOutput *> DSDisplayDeviceTDMImpl::getOutputList()
                }
                deviceOutput = new DSDisplayDeviceOutputTDMImpl(toutput);
                __outputList.emplace_back(deviceOutput);
+
+               // emit the output added signal
+               this->__outputAddedSignal.emit(deviceOutput);
        }
 
        return __outputList;
 }
 
+void DSDisplayDeviceTDMImpl::registerCallbackOutputAdded(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+{
+       this->__outputAddedSignal.connect(slot, func);
+}
+
+void DSDisplayDeviceTDMImpl::registerCallbackOutputRemoved(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+{
+       this->__outputRemovedSignal.connect(slot, func);
+}
+
+void DSDisplayDeviceTDMImpl::callCallbackOutputAdded()
+{
+       //TODO: create the new IDSDisplayDeviceOutput instance and put the parameter of the emit function.
+       this->__outputAddedSignal.emit(nullptr);
+}
+
+void DSDisplayDeviceTDMImpl::callCallbackOutputRemoved()
+{
+       //TODO: create the new IDSDisplayDeviceOutput instance and put the parameter of the emit function.
+       this->__outputRemovedSignal.emit(nullptr);
+}
+
 } // namespace display_server
index 8585152..013d1e4 100644 (file)
@@ -2,6 +2,7 @@
 #define _DS_DISPLAY_DEVICE_TDM_IMPL_H_
 
 #include "IDSDisplayDevice.h"
+#include "DSSignal.h"
 #include <tdm.h>
 
 namespace display_server
@@ -14,10 +15,22 @@ public:
 
        std::list<IDSDisplayDeviceOutput *> getOutputList() override;
 
+       // register callback functions
+       void registerCallbackOutputAdded(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) override;
+       void registerCallbackOutputRemoved(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) override;
+
+       // emit functions
+       void callCallbackOutputAdded();
+       void callCallbackOutputRemoved();
+
 private:
        tdm_display *__tdisplay;
        int __numOutputs;
        std::list<IDSDisplayDeviceOutput *> __outputList;
+
+       // signals
+       DSSignal<IDSDisplayDeviceOutput *> __outputAddedSignal;
+       DSSignal<IDSDisplayDeviceOutput *> __outputRemovedSignal;
 };
 }
 
index cccc9f0..ea03a3e 100644 (file)
@@ -1,17 +1,20 @@
 #ifndef _I_DS_DISPLAY_DEVICE_H_
 #define _I_DS_DISPLAY_DEVICE_H_
 
+#include "DSObject.h"
+#include "IDSDisplayDeviceOutput.h"
 #include <list>
-#include <IDSDisplayDeviceOutput.h>
 
 namespace display_server
 {
-class IDSDisplayDevice
+class IDSDisplayDevice : public DSObject
 {
 public:
        virtual ~IDSDisplayDevice() = default;
 
        virtual std::list<IDSDisplayDeviceOutput *> getOutputList() = 0;
+       virtual void registerCallbackOutputAdded(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
+       virtual void registerCallbackOutputRemoved(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
 };
 }
 
index 4492c1a..9f0df9f 100644 (file)
@@ -1,9 +1,11 @@
 #ifndef _I_DS_DISPLAY_DEVICE_OUTPUT_H_
 #define _I_DS_DISPLAY_DEVICE_OUTPUT_H_
 
+#include "DSObject.h"
+#include "IDSDisplayDeviceHWC.h"
 #include <list>
 #include <string>
-#include "IDSDisplayDeviceHWC.h"
+#include <functional>
 
 #define NAME_LEN 64
 
@@ -21,7 +23,7 @@ typedef struct _DSDisplayDeviceOutputMode {
        const void *private_mode;
 } DSDisplayDeviceOutputMode;
 
-class IDSDisplayDeviceOutput
+class IDSDisplayDeviceOutput : public DSObject
 {
 public:
        enum ConnectState {
@@ -73,12 +75,10 @@ public:
        virtual DPMSMode                                                                getDPMSMode() = 0;
        virtual IDSDisplayDeviceHWC                                             *getHWC() = 0;
 
-       //TODO: virtual int CallbackOutputAdded() = 0;
-       //TODO: virtual int CallbackOutputRemoved() = 0;
-       //TODO: virtual int CallbackOutputConnected() = 0;
-       //TODO: virtual int CallbackOutputDisconnected() = 0;
-       //TODO: virtual int CallbackOutputResolutionSet() = 0;
-       //TODO: virtual int CallbackOutputVBlankTriggered() = 0;
+       // Callback methods
+       virtual void registerCallbackOutputConnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
+       virtual void registerCallbackOutputDisconnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
+       virtual void registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func) = 0;
 };
 }
 
index 286282a..4255d9d 100644 (file)
@@ -1,5 +1,6 @@
 #include "libds-tests.h"
 #include "DSDisplayDeviceTDMImpl.h"
+#include "DSDisplayDeviceOutputTDMImpl.h"
 
 using namespace display_server;
 
@@ -18,6 +19,27 @@ public:
 };
 
 // DSDisplayDeviceTDMImpl
+class MockDisplayDevice : public DSObject
+{
+public:
+       MockDisplayDevice()
+               : flagOutputAdded(false),
+                 flagOutputRemoved(false)
+       {}
+       ~MockDisplayDevice()
+       {}
+
+       void outputAdded(IDSDisplayDeviceOutput *output) {
+               flagOutputAdded = true;
+       }
+
+       void outputRemoved(IDSDisplayDeviceOutput *output) {
+               flagOutputRemoved = true;
+       }
+
+       bool flagOutputAdded;
+       bool flagOutputRemoved;
+};
 
 TEST_F(DSDisplayDeviceTDMImplTest, Device_New)
 {
@@ -36,6 +58,29 @@ TEST_F(DSDisplayDeviceTDMImplTest, Device_getOutputList)
        delete dispayDevice;
 }
 
+TEST_F(DSDisplayDeviceTDMImplTest, Device_OutputAdded)
+{
+       std::shared_ptr<MockDisplayDevice> mockDisplayDevice = std::make_shared<MockDisplayDevice>();
+       std::unique_ptr<DSDisplayDeviceTDMImpl> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
+
+       displayDevice->registerCallbackOutputAdded(mockDisplayDevice.get(), std::bind(&MockDisplayDevice::outputAdded, mockDisplayDevice, std::placeholders::_1));
+       displayDevice->callCallbackOutputAdded();
+
+       EXPECT_TRUE(mockDisplayDevice->flagOutputAdded);
+}
+
+TEST_F(DSDisplayDeviceTDMImplTest, Device_OutputRemoved)
+{
+       //MockDisplayDevice *mockDisplayDevice = new MockDisplayDevice;
+       std::shared_ptr<MockDisplayDevice> mockDisplayDevice = std::make_shared<MockDisplayDevice>();
+       std::unique_ptr<DSDisplayDeviceTDMImpl> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
+
+       displayDevice->registerCallbackOutputRemoved(mockDisplayDevice.get(), std::bind(&MockDisplayDevice::outputRemoved, mockDisplayDevice, std::placeholders::_1));
+       displayDevice->callCallbackOutputRemoved();
+
+       EXPECT_TRUE(mockDisplayDevice->flagOutputRemoved);
+}
+
 // DSDisplayDeviceTDMOutputImpl
 
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_getInitialValues)
@@ -115,6 +160,66 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_setModeBestResolution)
        delete dispayDevice;
 }
 
+class MockDisplayDeviceOutput : public DSObject
+{
+public:
+       MockDisplayDeviceOutput()
+               : flagOutputConnected(false),
+                 flagOutputDisconnected(false),
+                 flagOutputResolutionSet(false)
+       {}
+       ~MockDisplayDeviceOutput() = default;
+
+       void outputConnected(IDSDisplayDeviceOutput *deviceOuptut) {
+               flagOutputConnected = true;
+       }
+
+       void outputDisconnected(IDSDisplayDeviceOutput *deviceOuptut) {
+               flagOutputDisconnected = true;
+       }
+
+       void outputResolutionSet(IDSDisplayDeviceOutput *deviceOuptut) {
+               flagOutputResolutionSet = true;
+       }
+
+       bool flagOutputConnected;
+       bool flagOutputDisconnected;
+       bool flagOutputResolutionSet;
+};
+
+TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputConnected)
+{
+       std::shared_ptr<MockDisplayDeviceOutput> mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
+       std::unique_ptr<DSDisplayDeviceOutputTDMImpl> displayDeviceOutput = std::make_unique<DSDisplayDeviceOutputTDMImpl>();
+
+       displayDeviceOutput->registerCallbackOutputConnected(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputConnected, mockDisplayDeviceOutput, std::placeholders::_1));
+       displayDeviceOutput->callCallbackOutputConnected();
+
+       EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputConnected);
+}
+
+TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputDisconnected)
+{
+       std::shared_ptr<MockDisplayDeviceOutput> mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
+       std::unique_ptr<DSDisplayDeviceOutputTDMImpl> displayDeviceOutput = std::make_unique<DSDisplayDeviceOutputTDMImpl>();
+
+       displayDeviceOutput->registerCallbackOutputDisconnected(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputDisconnected, mockDisplayDeviceOutput, std::placeholders::_1));
+       displayDeviceOutput->callCallbackOutputDisconnected();
+
+       EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputDisconnected);
+}
+
+TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputResolutionSet)
+{
+       std::shared_ptr<MockDisplayDeviceOutput> mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
+       std::unique_ptr<DSDisplayDeviceOutputTDMImpl> displayDeviceOutput = std::make_unique<DSDisplayDeviceOutputTDMImpl>();
+
+       displayDeviceOutput->registerCallbackOutputResolutionSet(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputResolutionSet, mockDisplayDeviceOutput, std::placeholders::_1));
+       displayDeviceOutput->callCallbackOutputResolutionSet();
+
+       EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputResolutionSet);
+}
+
 // DSDisplayDeviceTDMHWC
 
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_createHWCWindow)