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
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),
}
}
+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
#include "IDSDisplayDeviceOutput.h"
#include "IDSDisplayDeviceHWC.h"
+#include "DSSignal.h"
#include <tdm.h>
namespace display_server
class DSDisplayDeviceOutputTDMImpl : public IDSDisplayDeviceOutput
{
public:
+ DSDisplayDeviceOutputTDMImpl();
DSDisplayDeviceOutputTDMImpl(tdm_output *toutput);
~DSDisplayDeviceOutputTDMImpl();
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();
IDSDisplayDeviceOutput::DPMSMode __dpmsMode;
IDSDisplayDeviceHWC *__displayDeviceHWC;
+
+ // signals
+ DSSignal<IDSDisplayDeviceOutput *> __connectedSignal;
+ DSSignal<IDSDisplayDeviceOutput *> __disconnectedSignal;
+ DSSignal<IDSDisplayDeviceOutput *> __resolutionSetSignal;
};
}
}
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
#define _DS_DISPLAY_DEVICE_TDM_IMPL_H_
#include "IDSDisplayDevice.h"
+#include "DSSignal.h"
#include <tdm.h>
namespace display_server
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;
};
}
#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;
};
}
#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
const void *private_mode;
} DSDisplayDeviceOutputMode;
-class IDSDisplayDeviceOutput
+class IDSDisplayDeviceOutput : public DSObject
{
public:
enum ConnectState {
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;
};
}
#include "libds-tests.h"
#include "DSDisplayDeviceTDMImpl.h"
+#include "DSDisplayDeviceOutputTDMImpl.h"
using namespace display_server;
};
// 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)
{
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)
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)