--- /dev/null
+/*
+* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#include <DSSignalBroker.h>
+
+namespace display_server
+{
+
+std::mutex DSSignalBroker::__mutex;
+DSSignalBroker* DSSignalBroker::__signalBroker { nullptr };
+
+DSSignalBroker::DSSignalBroker(DSObject *parent)
+{
+}
+
+DSSignalBroker::~DSSignalBroker()
+{
+}
+
+DSSignalBroker *DSSignalBroker::getInstance()
+{
+ std::lock_guard<std::mutex> tLock(__mutex);
+
+ if (!__signalBroker)
+ {
+ __signalBroker = new DSSignalBroker(new DSObject);
+ DSLOG_INF("DSSignalBroker", "DSSignalBroker instance has been created !");
+ }
+
+ return __signalBroker;
+}
+
+void DSSignalBroker::releaseInstance()
+{
+ std::lock_guard<std::mutex> tLock(__mutex);
+
+ if (__signalBroker && __signalBroker->__signalHash.empty())
+ {
+ delete __signalBroker;
+ __signalBroker = nullptr;
+ DSLOG_INF("DSSignalBroker", "DSSignalBroker instance has been removed !");
+ }
+}
+
+bool DSSignalBroker::registerCallback(std::string signalStr, DSObject *slot, std::function<void(void *)> func)
+{
+ if (!__signalBroker) return false;
+
+ if (__signalBroker->__signalHash.find(signalStr) == __signalBroker->__signalHash.end())
+ {
+ DSLOG_INF("DSSignalBroker","registerCallback:: cannot find signal, add new one %s", signalStr.c_str());
+
+ __signalBroker->__signalHash[signalStr] = new DSSignal<void *>();
+ }
+
+ __signalBroker->__signalHash[signalStr]->connect(slot, func);
+
+ return true;
+}
+
+bool DSSignalBroker::deregisterCallback(std::string signalStr, DSObject *slot, std::function<void(void *)> func)
+{
+ if (!__signalBroker) return false;
+
+ if (__signalBroker->__signalHash.find(signalStr) == __signalBroker->__signalHash.end())
+ return false;
+
+ // TODO: have to impl disconnect method in DSSignal
+ //__signalBroker->__signalHash[signalStr]->disconnect(slot, func);
+
+ return true;
+}
+
+bool DSSignalBroker::emitSignal(std::string signalStr, void *arg)
+{
+ if (!__signalBroker) return false;
+
+ if (__signalBroker->__signalHash.find(signalStr) == __signalBroker->__signalHash.end())
+ {
+ DSLOG_INF("DSSignalBroker","emitSignal:: cannot find signal, add new one %s", signalStr.c_str());
+
+ __signalBroker->__signalHash[signalStr] = new DSSignal<void *>();
+ }
+
+ __signalBroker->__signalHash[signalStr]->emit(arg);
+
+ return true;
+}
+
+} // end of namespace display_server
\ No newline at end of file
--- /dev/null
+/*
+* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef __DS_SIGNAL_BROKER_H__
+#define __DS_SIGNAL_BROKER_H__
+
+#include <DSCore.h>
+#include <DSObject.h>
+#include <DSSignal.h>
+
+namespace display_server
+{
+
+class DSSignalBroker : public DSObject
+{
+public:
+ static DSSignalBroker *getInstance();
+ static void releaseInstance();
+
+ // TODO: needs arguments using signal (now only supports void*)
+ bool registerCallback(std::string signalStr, DSObject *slot, std::function<void(void *)> func);
+ bool deregisterCallback(std::string signalStr, DSObject *slot, std::function<void(void *)> func);
+ bool emitSignal(std::string signalStr, void *arg);
+
+private:
+ static std::mutex __mutex;
+ static DSSignalBroker *__signalBroker;
+
+ std::unordered_map<std::string, DSSignal<void *> *> __signalHash;
+
+ DSSignalBroker() = delete;
+ ~DSSignalBroker();
+ DSSignalBroker(DSObject *parent);
+};
+
+} // end of namespace display_server
+
+#endif // end of __DS_SIGNAL_BROKER_H__
'DSSeat/DSTouch.h',
'DSSignal/DSSignal.cpp',
'DSSignal/DSSignal.h',
+ 'DSSignal/DSSignalBroker.cpp',
+ 'DSSignal/DSSignalBroker.h',
'DSCore/DSStruct.h',
'DSCore/DSCore.h',
'DSWaylandExtension/DSWaylandExtension.cpp',
--- /dev/null
+/*
+* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#include <iostream>
+#include "libds-tests.h"
+#include "DSSignal.h"
+#include "DSSignalBroker.h"
+#include "DSDebugLog.h"
+
+using namespace display_server;
+
+class DSSignalBrokerTest : public ::testing::Test
+{
+public:
+ void SetUp(void) override
+ {
+ res_lambda = false;
+ }
+ void TearDown(void) override
+ {}
+
+ bool res_lambda;
+};
+
+TEST_F(DSSignalBrokerTest, getInstance)
+{
+ DSSignalBroker *sigbro = DSSignalBroker::getInstance();
+ EXPECT_TRUE(sigbro != nullptr);
+
+ if (sigbro)
+ sigbro->releaseInstance();
+}
+
+TEST_F(DSSignalBrokerTest, registerCallback)
+{
+ bool res = false;
+ DSSignalBroker *sigbro = DSSignalBroker::getInstance();
+ std::string testSignal = "TestSignalBroker";
+ EXPECT_TRUE(sigbro != nullptr);
+
+ res = sigbro->registerCallback(testSignal, new DSObject, [&](void * arg) {
+ DSLOG_INF("DSTEST", "%s is invoked!, input: %p", __func__, arg);
+ res_lambda = true;
+ });
+ EXPECT_TRUE(res);
+
+ if (sigbro)
+ sigbro->releaseInstance();
+}
+
+TEST_F(DSSignalBrokerTest, emitSignal)
+{
+ bool res = false;
+ DSSignalBroker *sigbro = DSSignalBroker::getInstance();
+ std::string testSignal = "TestSignalBroker";
+ EXPECT_TRUE(sigbro != nullptr);
+
+ // NOTICE: If registerCallback test didn't called, this test will fail.
+ res = sigbro->emitSignal(testSignal, nullptr);
+ EXPECT_TRUE(res);
+ EXPECT_TRUE(res_lambda);
+
+ if (sigbro)
+ sigbro->releaseInstance();
+}
'DSDebugLog-test.cpp',
'DSDisplayDeviceTDMImpl-test.cpp',
'DSSignal-test.cpp',
+ 'DSSignalBroker-test.cpp',
'DSWindowManager-test.cpp',
'DSWindow-test.cpp',
'DSWindowShell-test.cpp',