DSDisplayDevice: make the pointers related to IDSDisplayDeviceOutput into the smart... 68/241568/1
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 2 Jul 2020 23:17:13 +0000 (08:17 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 09:45:48 +0000 (18:45 +0900)
Change-Id: I3462edb81c090c6d8f951083948ed705caf04a5e

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 0cfde74..97d46d3 100644 (file)
@@ -248,34 +248,34 @@ void DSDisplayDeviceOutputTDMImpl::__updateAvailableModeList()
        }
 }
 
-void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputConnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputConnected(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func)
 {
        this->__connectedSignal.connect(slot, func);
 }
 
-void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputDisconnected(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputDisconnected(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func)
 {
        this->__disconnectedSignal.connect(slot, func);
 }
 
-void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func)
 {
        this->__resolutionSetSignal.connect(slot, func);
 }
 
 void DSDisplayDeviceOutputTDMImpl::callCallbackOutputConnected()
 {
-       this->__connectedSignal.emit(this);
+       this->__connectedSignal.emit(shared_from_this());
 }
 
 void DSDisplayDeviceOutputTDMImpl::callCallbackOutputDisconnected()
 {
-       this->__disconnectedSignal.emit(this);
+       this->__disconnectedSignal.emit(shared_from_this());
 }
 
 void DSDisplayDeviceOutputTDMImpl::callCallbackOutputResolutionSet()
 {
-       this->__resolutionSetSignal.emit(this);
+       this->__resolutionSetSignal.emit(shared_from_this());
 }
 
 } // namespace display_server
index 82dba0d..042cc23 100644 (file)
@@ -8,7 +8,7 @@
 
 namespace display_server
 {
-class DSDisplayDeviceOutputTDMImpl : public IDSDisplayDeviceOutput
+class DSDisplayDeviceOutputTDMImpl : public IDSDisplayDeviceOutput, public std::enable_shared_from_this<DSDisplayDeviceOutputTDMImpl>
 {
 public:
        DSDisplayDeviceOutputTDMImpl();
@@ -29,9 +29,9 @@ public:
        IDSDisplayDeviceHWC *getHWC() 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;
+       void registerCallbackOutputConnected(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) override;
+       void registerCallbackOutputDisconnected(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) override;
+       void registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) override;
 
        // emit functions
        void callCallbackOutputConnected();
@@ -58,9 +58,9 @@ private:
        IDSDisplayDeviceHWC *__displayDeviceHWC;
 
        // signals
-       DSSignal<IDSDisplayDeviceOutput *> __connectedSignal;
-       DSSignal<IDSDisplayDeviceOutput *> __disconnectedSignal;
-       DSSignal<IDSDisplayDeviceOutput *> __resolutionSetSignal;
+       DSSignal<std::shared_ptr<IDSDisplayDeviceOutput>> __connectedSignal;
+       DSSignal<std::shared_ptr<IDSDisplayDeviceOutput>> __disconnectedSignal;
+       DSSignal<std::shared_ptr<IDSDisplayDeviceOutput>> __resolutionSetSignal;
 };
 }
 
index 2255542..7dccce7 100644 (file)
@@ -10,7 +10,6 @@ DSDisplayDeviceTDMImpl::DSDisplayDeviceTDMImpl()
 {
        tdm_error terror;
        tdm_output *toutput;
-       IDSDisplayDeviceOutput *deviceOutput;
 
        __tdisplay = tdm_display_init(&terror);
        if (terror != TDM_ERROR_NONE) {
@@ -29,8 +28,8 @@ DSDisplayDeviceTDMImpl::DSDisplayDeviceTDMImpl()
                        DSLOG_ERR("TDM DEVICE", "tdm_display_get_output fails.(output num: %d)\n", i);
                        return;
                }
-               deviceOutput = new DSDisplayDeviceOutputTDMImpl(toutput);
-               __outputList.emplace_back(deviceOutput);
+
+               __outputList.emplace_back(std::make_shared<DSDisplayDeviceOutputTDMImpl>(toutput));
        }
 }
 
@@ -39,17 +38,17 @@ DSDisplayDeviceTDMImpl::~DSDisplayDeviceTDMImpl()
        tdm_display_deinit(__tdisplay);
 }
 
-std::list<IDSDisplayDeviceOutput *> DSDisplayDeviceTDMImpl::getOutputList()
+std::list<std::shared_ptr<IDSDisplayDeviceOutput>> DSDisplayDeviceTDMImpl::getOutputList()
 {
        return __outputList;
 }
 
-void DSDisplayDeviceTDMImpl::registerCallbackOutputAdded(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+void DSDisplayDeviceTDMImpl::registerCallbackOutputAdded(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func)
 {
        this->__outputAddedSignal.connect(slot, func);
 }
 
-void DSDisplayDeviceTDMImpl::registerCallbackOutputRemoved(DSObject *slot, std::function<void(IDSDisplayDeviceOutput *)> func)
+void DSDisplayDeviceTDMImpl::registerCallbackOutputRemoved(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func)
 {
        this->__outputRemovedSignal.connect(slot, func);
 }
index 3bf9a16..df4bc05 100644 (file)
@@ -14,11 +14,11 @@ public:
        DSDisplayDeviceTDMImpl();
        ~DSDisplayDeviceTDMImpl();
 
-       std::list<IDSDisplayDeviceOutput *> getOutputList() override;
+       std::list<std::shared_ptr<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;
+       void registerCallbackOutputAdded(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) override;
+       void registerCallbackOutputRemoved(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) override;
 
        // emit functions
        void callCallbackOutputAdded();
@@ -27,11 +27,11 @@ public:
 private:
        tdm_display *__tdisplay;
        int __numOutputs;
-       std::list<IDSDisplayDeviceOutput *> __outputList;
+       std::list<std::shared_ptr<IDSDisplayDeviceOutput>> __outputList;
 
        // signals
-       DSSignal<IDSDisplayDeviceOutput *> __outputAddedSignal;
-       DSSignal<IDSDisplayDeviceOutput *> __outputRemovedSignal;
+       DSSignal<std::shared_ptr<IDSDisplayDeviceOutput>> __outputAddedSignal;
+       DSSignal<std::shared_ptr<IDSDisplayDeviceOutput>> __outputRemovedSignal;
 };
 
 }
index ea03a3e..1d4257f 100644 (file)
@@ -12,9 +12,9 @@ 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;
+       virtual std::list<std::shared_ptr<IDSDisplayDeviceOutput>> getOutputList() = 0;
+       virtual void registerCallbackOutputAdded(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) = 0;
+       virtual void registerCallbackOutputRemoved(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) = 0;
 };
 }
 
index 8c4ce70..84e1a7a 100644 (file)
@@ -75,9 +75,9 @@ public:
        virtual IDSDisplayDeviceHWC                     *getHWC() = 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;
+       virtual void registerCallbackOutputConnected(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) = 0;
+       virtual void registerCallbackOutputDisconnected(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) = 0;
+       virtual void registerCallbackOutputResolutionSet(DSObject *slot, std::function<void(std::shared_ptr<IDSDisplayDeviceOutput>)> func) = 0;
 };
 
 }
index ec75a9e..d7166ce 100644 (file)
@@ -29,11 +29,11 @@ public:
        ~MockDisplayDevice()
        {}
 
-       void outputAdded(IDSDisplayDeviceOutput *output) {
+       void outputAdded(std::shared_ptr<IDSDisplayDeviceOutput> output) {
                flagOutputAdded = true;
        }
 
-       void outputRemoved(IDSDisplayDeviceOutput *output) {
+       void outputRemoved(std::shared_ptr<IDSDisplayDeviceOutput> output) {
                flagOutputRemoved = true;
        }
 
@@ -51,7 +51,7 @@ TEST_F(DSDisplayDeviceTDMImplTest, Device_getOutputList)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
        EXPECT_TRUE(displayDevice != nullptr);
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
+       std::list<std::shared_ptr<IDSDisplayDeviceOutput>> outputList = displayDevice->getOutputList();
        EXPECT_TRUE(outputList.size() != 0);
 }
 
@@ -82,13 +82,13 @@ TEST_F(DSDisplayDeviceTDMImplTest, Device_OutputRemoved)
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_getInitialValues)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
+       std::list<std::shared_ptr<IDSDisplayDeviceOutput>> outputList = displayDevice->getOutputList();
        EXPECT_TRUE(outputList.size() != 0);
 
        IDSDisplayDeviceOutput::ConnectorType connType;
        IDSDisplayDeviceOutput::ConnectState connState;
 
-       for (IDSDisplayDeviceOutput *output : outputList) {
+       for (std::shared_ptr<IDSDisplayDeviceOutput> output : outputList) {
                connType = output->getConnectType();
                EXPECT_TRUE(connType <= IDSDisplayDeviceOutput::TYPE_DSI);
                connState = output->getConnectState();
@@ -118,14 +118,14 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_getInitialValues)
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_setModeBestResolution)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
+       std::list<std::shared_ptr<IDSDisplayDeviceOutput>> outputList = displayDevice->getOutputList();
        EXPECT_TRUE(outputList.size() != 0);
 
        IDSDisplayDeviceOutput::ConnectorType connType;
        IDSDisplayDeviceOutput::ConnectState connState;
        DSDisplayDeviceOutputMode *bestMode;
 
-       for (IDSDisplayDeviceOutput *output : outputList) {
+       for (std::shared_ptr<IDSDisplayDeviceOutput> output : outputList) {
                connType = output->getConnectType();
                EXPECT_TRUE(connType <= IDSDisplayDeviceOutput::TYPE_DSI);
                connState = output->getConnectState();
@@ -162,15 +162,15 @@ public:
        {}
        ~MockDisplayDeviceOutput() = default;
 
-       void outputConnected(IDSDisplayDeviceOutput *deviceOuptut) {
+       void outputConnected(std::shared_ptr<IDSDisplayDeviceOutput> displayDeviceOuptut) {
                flagOutputConnected = true;
        }
 
-       void outputDisconnected(IDSDisplayDeviceOutput *deviceOuptut) {
+       void outputDisconnected(std::shared_ptr<IDSDisplayDeviceOutput> displayDeviceOuptut) {
                flagOutputDisconnected = true;
        }
 
-       void outputResolutionSet(IDSDisplayDeviceOutput *deviceOuptut) {
+       void outputResolutionSet(std::shared_ptr<IDSDisplayDeviceOutput> displayDeviceOuptut) {
                flagOutputResolutionSet = true;
        }
 
@@ -182,12 +182,13 @@ public:
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputConnected)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
-       for (IDSDisplayDeviceOutput *output : outputList) {
-               std::shared_ptr<MockDisplayDeviceOutput> mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
-               DSDisplayDeviceOutputTDMImpl *displayDeviceOutput = static_cast<DSDisplayDeviceOutputTDMImpl *>(output);
+       auto outputList = displayDevice->getOutputList();
+       for (auto displayDeviceOutput : outputList) {
+               auto mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
                displayDeviceOutput->registerCallbackOutputConnected(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputConnected, mockDisplayDeviceOutput, std::placeholders::_1));
-               displayDeviceOutput->callCallbackOutputConnected();
+
+               auto displayDeviceOutputTDM = std::dynamic_pointer_cast<DSDisplayDeviceOutputTDMImpl>(displayDeviceOutput); // down-casting of std::shared_ptr
+               displayDeviceOutputTDM->callCallbackOutputConnected();
                EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputConnected);
        }
 }
@@ -195,12 +196,13 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputConnected)
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputDisconnected)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
-       for (IDSDisplayDeviceOutput *output : outputList) {
-               std::shared_ptr<MockDisplayDeviceOutput> mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
-               DSDisplayDeviceOutputTDMImpl *displayDeviceOutput = static_cast<DSDisplayDeviceOutputTDMImpl *>(output);
+       auto outputList = displayDevice->getOutputList();
+       for (auto displayDeviceOutput : outputList) {
+               auto mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
                displayDeviceOutput->registerCallbackOutputDisconnected(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputDisconnected, mockDisplayDeviceOutput, std::placeholders::_1));
-               displayDeviceOutput->callCallbackOutputDisconnected();
+
+               auto displayDeviceOutputTDM = std::dynamic_pointer_cast<DSDisplayDeviceOutputTDMImpl>(displayDeviceOutput); // down-casting of std::shared_ptr
+               displayDeviceOutputTDM->callCallbackOutputDisconnected();
                EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputDisconnected);
        }
 }
@@ -208,12 +210,13 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputDisconnect
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputResolutionSet)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
-       for (IDSDisplayDeviceOutput *output : outputList) {
-               std::shared_ptr<MockDisplayDeviceOutput> mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
-               DSDisplayDeviceOutputTDMImpl *displayDeviceOutput = static_cast<DSDisplayDeviceOutputTDMImpl *>(output);
+       auto outputList = displayDevice->getOutputList();
+       for (auto displayDeviceOutput : outputList) {
+               auto mockDisplayDeviceOutput = std::make_shared<MockDisplayDeviceOutput>();
                displayDeviceOutput->registerCallbackOutputResolutionSet(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputResolutionSet, mockDisplayDeviceOutput, std::placeholders::_1));
-               displayDeviceOutput->callCallbackOutputResolutionSet();
+
+               auto displayDeviceOutputTDM = std::dynamic_pointer_cast<DSDisplayDeviceOutputTDMImpl>(displayDeviceOutput); // down-casting of std::shared_ptr
+               displayDeviceOutputTDM->callCallbackOutputResolutionSet();
                EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputResolutionSet);
        }
 }
@@ -223,7 +226,7 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputResolution
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_createHWCWindow)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
+       std::list<std::shared_ptr<IDSDisplayDeviceOutput>> outputList = displayDevice->getOutputList();
        EXPECT_TRUE(outputList.size() != 0);
 
        IDSDisplayDeviceOutput::ConnectorType connType;
@@ -231,7 +234,7 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_createHWCWindow)
        IDSDisplayDeviceHWC *deviceHWC;
        IDSDisplayDeviceHWCWindow *deviceHWCWindow;
 
-       for (IDSDisplayDeviceOutput *output : outputList) {
+       for (std::shared_ptr<IDSDisplayDeviceOutput> output : outputList) {
                connType = output->getConnectType();
                EXPECT_TRUE(connType <= IDSDisplayDeviceOutput::TYPE_DSI);
                connState = output->getConnectState();
@@ -251,7 +254,7 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_createHWCWindow)
 TEST_F(DSDisplayDeviceTDMImplTest, DeviceHWC_commit)
 {
        std::unique_ptr<IDSDisplayDevice> displayDevice = std::make_unique<DSDisplayDeviceTDMImpl>();
-       std::list<IDSDisplayDeviceOutput *> outputList = displayDevice->getOutputList();
+       std::list<std::shared_ptr<IDSDisplayDeviceOutput>> outputList = displayDevice->getOutputList();
        EXPECT_TRUE(outputList.size() != 0);
 
        IDSDisplayDeviceOutput::ConnectorType connType;
@@ -259,7 +262,7 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceHWC_commit)
        IDSDisplayDeviceHWC *deviceHWC;
        IDSDisplayDeviceHWCWindow *deviceHWCWindow;
 
-       for (IDSDisplayDeviceOutput *output : outputList) {
+       for (std::shared_ptr<IDSDisplayDeviceOutput> output : outputList) {
                connType = output->getConnectType();
                EXPECT_TRUE(connType <= IDSDisplayDeviceOutput::TYPE_DSI);
                connState = output->getConnectState();