From 3392c21b55c0b48615bd4eabdabc2db71a939e7b Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Thu, 20 Aug 2020 18:11:37 +0900 Subject: [PATCH 2/9] first commit Change-Id: Iad080728bbb7121d7a5e3b346b5bcc2526c972b3 --- README | 1 + 1 file changed, 1 insertion(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..fb0b1cb --- /dev/null +++ b/README @@ -0,0 +1 @@ +# test-server -- 2.7.4 From b216e762a5e6f1cd68150039c938e4457cab354f Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Mon, 20 Jan 2020 16:51:23 +0900 Subject: [PATCH 3/9] Make empty files for wobject Change-Id: Ia7328412edd3753b6373636763934add5b48f3c2 --- src/WObject.cpp | 0 src/WObject.h | 0 src/WObjectPrivate.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/WObject.cpp create mode 100644 src/WObject.h create mode 100644 src/WObjectPrivate.h diff --git a/src/WObject.cpp b/src/WObject.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/WObject.h b/src/WObject.h new file mode 100644 index 0000000..e69de29 diff --git a/src/WObjectPrivate.h b/src/WObjectPrivate.h new file mode 100644 index 0000000..e69de29 -- 2.7.4 From 4b1f96d6328adbb989aa1c46f366abca44d9e8c1 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Mon, 20 Jan 2020 16:54:17 +0900 Subject: [PATCH 4/9] wobject: move files to core dir Change-Id: I2e463177c38efde9d97ad4f866ee4ef944dea83b Signed-off-by: MinJeong Kim --- src/{ => core}/WObject.cpp | 0 src/{ => core}/WObject.h | 0 src/{ => core}/WObjectPrivate.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{ => core}/WObject.cpp (100%) rename src/{ => core}/WObject.h (100%) rename src/{ => core}/WObjectPrivate.h (100%) diff --git a/src/WObject.cpp b/src/core/WObject.cpp similarity index 100% rename from src/WObject.cpp rename to src/core/WObject.cpp diff --git a/src/WObject.h b/src/core/WObject.h similarity index 100% rename from src/WObject.h rename to src/core/WObject.h diff --git a/src/WObjectPrivate.h b/src/core/WObjectPrivate.h similarity index 100% rename from src/WObjectPrivate.h rename to src/core/WObjectPrivate.h -- 2.7.4 From 98ec23321c7cecc2fb4dc8dec48a7c6fbd375a9b Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Mon, 10 Feb 2020 17:27:45 +0900 Subject: [PATCH 5/9] implement signal-slot system with return value Change-Id: I00b31fd43eaa56a30ff706101059e093a5cf72aa Signed-off-by: MinJeong Kim --- src/bin/main.cpp | 58 +++++++++++++++++++++++++ src/core/WCallbackIface.h | 12 ++++++ src/core/WObject.cpp | 26 +++++++++++ src/core/WObject.h | 45 +++++++++++++++++++ src/core/WObjectPrivate.h | 42 ++++++++++++++++++ src/core/WProperty.cpp | 0 src/core/WProperty.h | 12 ++++++ src/core/WPropertyPrivate.h | 0 src/core/WRefBase.cpp | 0 src/core/WRefBase.h | 19 +++++++++ src/core/WRefBasePrivate.h | 0 src/core/WSignal.cpp | 16 +++++++ src/core/WSignal.h | 102 ++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 332 insertions(+) create mode 100644 src/bin/main.cpp create mode 100644 src/core/WCallbackIface.h create mode 100644 src/core/WProperty.cpp create mode 100644 src/core/WProperty.h create mode 100644 src/core/WPropertyPrivate.h create mode 100644 src/core/WRefBase.cpp create mode 100644 src/core/WRefBase.h create mode 100644 src/core/WRefBasePrivate.h create mode 100644 src/core/WSignal.cpp create mode 100644 src/core/WSignal.h diff --git a/src/bin/main.cpp b/src/bin/main.cpp new file mode 100644 index 0000000..c0c004f --- /dev/null +++ b/src/bin/main.cpp @@ -0,0 +1,58 @@ + +#include "../core/WObject.h" +#include "../core/WSignal.h" +#include + +using namespace TizenDisplayServer; + +using SignalAType = WSignal; +using SignalBType = WSignal; + +class MJ : public WObject +{ + public: + MJ() : WObject("MJ"){ std::cout << "construct MJ" << std::endl;} + MJ(std::string name) : WObject(name) {std::cout << "construct MJ" << name << std::endl;} + ~MJ(){ std::cout << "destruct MJ" << std::endl;} + + struct SignalA : public SignalAType { + int emit(int val) { return SignalAType::emit(val); } + } signalA; + + struct SignalB : public SignalBType { + double emit(int val) { return SignalBType::emit(val); } + } signalB; +}; + +class Holder : public WObject { + public: + Holder() : WObject("Holder") {std::cout << "construct Holder" << std::endl;} + Holder(std::string name) : WObject(name) {std::cout << "construct Holder" << std::endl;} + ~Holder() {std::cout << "destruct Holder" << std::endl;} + + static int slotA(int a) { std::cout << "slotA invoked! a:" << a << std::endl; return 1; }; + static double slotB(int a) { std::cout << "slotB invoked! a:" << a << std::endl; return 123.456; }; + static int slotA2(int a) {std::cout << "slotA2 invoked! a:" << a << std::endl; return 2;} +}; + +int main (void) +{ + MJ mj("mj"); + MJ mj2("mj2"); + Holder holder("h1"); + Holder holder2("h2"); + + std::cout << "<<<<<<<< slotA connect to signala >>>>>>>>" << std::endl; + mj.signalA.connect(&holder, Holder::slotA); + std::cout << "<<<<<<<< slotA2 connect to signala >>>>>>>>" << std::endl; + mj.signalA.connect(&holder, Holder::slotA2); + + std::cout << "<<<<<<<< slotB connect to signalB >>>>>>>>" << std::endl; + mj.signalB.connect(&holder, Holder::slotB); + + + int a = mj.signalA.emit(1234); + double b = mj.signalB.emit(5678); + + return 0; +} \ No newline at end of file diff --git a/src/core/WCallbackIface.h b/src/core/WCallbackIface.h new file mode 100644 index 0000000..e9c4e87 --- /dev/null +++ b/src/core/WCallbackIface.h @@ -0,0 +1,12 @@ +#ifndef WCALLBACKIFACE_H +# define WCALLBACKIFACE_H +namespace TizenDisplayServer{ + struct WCallbackIface{ + WCallbackIface(){} + WCallbackIface(const WCallbackIface& cp){ + } + }; + +} +#else +#endif \ No newline at end of file diff --git a/src/core/WObject.cpp b/src/core/WObject.cpp index e69de29..d46b329 100644 --- a/src/core/WObject.cpp +++ b/src/core/WObject.cpp @@ -0,0 +1,26 @@ +#include "WObjectPrivate.h" +#include "WObject.h" + +namespace TizenDisplayServer{ + WObjectPrivate::WObjectPrivate(WObject *p_ptr, std::string name) : p_ptr(p_ptr) + { + type_info.name = name; + std::cout << "construct WObjectPrivate" << std::endl; + } + + WObjectPrivate::~WObjectPrivate() + { + std::cout << "destruct WObjectPrivate" << std::endl; + } + + WObject::WObject(std::string name) + { + std::cout << "construct WOBject " << name < ptr(new WObjectPrivate(this, name)); + d_ptr = std::move(ptr); + } + + WObject::~WObject(){ + destroyNotify(); + } +} diff --git a/src/core/WObject.h b/src/core/WObject.h index e69de29..46e52f3 100644 --- a/src/core/WObject.h +++ b/src/core/WObject.h @@ -0,0 +1,45 @@ +#ifndef WOBJECT_H +# define WOBJECT_H + +#include "WObjectPrivate.h" +#include "WProperty.h" +#include +#include +#include +#include +#include + +namespace TizenDisplayServer{ +class WObjectPrivate; +class WObjectObserverIface; +class WProperty; + +class WObject { + std::unique_ptr d_ptr; + + inline WObjectPrivate* d_func() { return d_ptr.get(); } + inline const WObjectPrivate* d_func() const { return d_ptr.get(); } + friend class WObjectPrivate; + + public: + WObject(std::string name = "default"); + virtual ~WObject(); + + void attachObserver(WObjectObserverIface *ob){} + void detachObserver(WObjectObserverIface *ob){} + void destroyNotify(void){} + bool setProperty(std::string key, WProperty property){} + WProperty& getProperty(std::string key){} + +}; + +class WObjectObserverIface { + public: + WObjectObserverIface() {} + virtual ~WObjectObserverIface() {} + virtual void destroyed(WObject *obj) = 0; +}; + +} +#else +#endif \ No newline at end of file diff --git a/src/core/WObjectPrivate.h b/src/core/WObjectPrivate.h index e69de29..a0ca476 100644 --- a/src/core/WObjectPrivate.h +++ b/src/core/WObjectPrivate.h @@ -0,0 +1,42 @@ +#ifndef WOBJECTPRIVATE_H +# define WOBJECTPRIVATE_H + +#include "WObject.h" +#include "WProperty.h" +#include +#include +#include +#include + +namespace TizenDisplayServer{ + +class WObject; +class WObjectObserverIface; + +class WObjectPrivate { + + struct { + std::string name; + + }type_info; + + WObject *p_ptr; + + std::list observers; + std::unordered_map properties; + + public: + WObjectPrivate() = delete; + WObjectPrivate(WObject *p_ptr, std::string name = "default"); + ~WObjectPrivate(); + + inline const WObject *p_func() const{ return p_ptr;} + + void attachObserver(WObjectObserverIface *ob); + void detachObserver(WObjectObserverIface *ob); + bool setProperty(std::string key, WProperty property); + WProperty& getProperty(std::string key); +}; +} +#else +#endif \ No newline at end of file diff --git a/src/core/WProperty.cpp b/src/core/WProperty.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/core/WProperty.h b/src/core/WProperty.h new file mode 100644 index 0000000..c811603 --- /dev/null +++ b/src/core/WProperty.h @@ -0,0 +1,12 @@ +#ifndef WPROPERTY_H +# define WPROPERTY_H +namespace TizenDisplayServer{ + class WProperty { + public: + WProperty(){} + virtual ~WProperty() {} + }; +} + +#else +#endif \ No newline at end of file diff --git a/src/core/WPropertyPrivate.h b/src/core/WPropertyPrivate.h new file mode 100644 index 0000000..e69de29 diff --git a/src/core/WRefBase.cpp b/src/core/WRefBase.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/core/WRefBase.h b/src/core/WRefBase.h new file mode 100644 index 0000000..970c91b --- /dev/null +++ b/src/core/WRefBase.h @@ -0,0 +1,19 @@ +#ifndef WREFBASE_H +# define WREFBASE_H +namespace TizenDisplayServer{ + +class WRefBase { + int mCount; + + public: + WRefBase() : mCount(0) {}; + virtual ~WRefBase(); + + void ref() {++mCount;} + void unref() {if (--mCount == 0) delete this;} + int getref() { return mCount; } +}; + +} +#else +#endif \ No newline at end of file diff --git a/src/core/WRefBasePrivate.h b/src/core/WRefBasePrivate.h new file mode 100644 index 0000000..e69de29 diff --git a/src/core/WSignal.cpp b/src/core/WSignal.cpp new file mode 100644 index 0000000..418065b --- /dev/null +++ b/src/core/WSignal.cpp @@ -0,0 +1,16 @@ +#include "WSignal.h" +#include + +namespace TizenDisplayServer { + void WSlotsObserver::addSlot(WObject *slot) + { + slots.push_back(slot); + } + void WSlotsObserver::destroyed(WObject *slot) + { + slots.remove(slot); + if (slots.empty()) + delete this; + } + +} \ No newline at end of file diff --git a/src/core/WSignal.h b/src/core/WSignal.h new file mode 100644 index 0000000..741c0da --- /dev/null +++ b/src/core/WSignal.h @@ -0,0 +1,102 @@ +#ifndef WSIGNAL_H +# define WSIGNAL_H +#include "WObject.h" +#include +#include +#include +#include + +namespace TizenDisplayServer{ + class WSlotsObserver : public WObjectObserverIface { + protected: + std::list slots; + public: + WSlotsObserver(){} + ~WSlotsObserver(){} + + virtual void destroyed(WObject *obj); + void addSlot(WObject *slot); + }; + + template + class WSlotConnection : public WSlotsObserver{ + //TODO: make callback as callback iface + //std::unique_ptr callback; + R (*callback)(Args...); + template friend class WSignal; + + public: + WSlotConnection() {} + WSlotConnection(WObject *slot, R (*func) (Args...)) : callback(func) { + //TODO: make callback as callback iface + //std::unique_ptr ptr(new WCallbackIface(func)); + //callback = std::move(ptr); + addSlot(slot); + } + virtual ~WSlotConnection() {} + + void addSlot(WObject *slot) + { + slots.push_back(slot); + } + void destroyed(WObject *slot) + { + slots.remove(slot); + if (slots.empty()) + delete this; + } + + R invoke(Args... args) + { + if (!std::is_void::value) + { + R ret = callback(args...); + return ret; + } + } + + }; + + template + class WSignal { + std::list>> connections; + WSlotConnection *findcon(R (*func)(Args...)) { + for (auto&& con : connections) + { + if (con->callback == func) + return con.get(); + } + return nullptr; + } + + public: + WSignal() {} + virtual ~WSignal() {} + + WSignal& operator()(void) { return *this; } // functor + + void connect(WObject *slot, R (*func)(Args...)) + { + if ((!slot) || (!func)) + return; + if (auto con = findcon(func)) + con->addSlot(slot); + else + connections.emplace_back(new WSlotConnection(slot, func)); + } + + R emit(Args... args){ + if (!std::is_void::value) + { + R ret; + for (auto &&con : connections) + { + ret = con->invoke(args...); + } + return ret; + } + } + }; +} +#else +#endif \ No newline at end of file -- 2.7.4 From f5b7c1f9e729a217f4e7981b29712f78c903fe5e Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Mon, 10 Feb 2020 19:40:39 +0900 Subject: [PATCH 6/9] remove return type of slot callback Change-Id: If79805f1a4e88e61efe92574a3e5b0849ef738fd Signed-off-by: MinJeong Kim --- src/bin/main.cpp | 58 --------------------------------------- src/bin/sample1.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++ src/core/WObject.cpp | 65 +++++++++++++++++++++++++++++++++++++++++--- src/core/WObject.h | 15 ++++++----- src/core/WObjectPrivate.h | 13 +++++---- src/core/WRefBase.h | 6 ++--- src/core/WSignal.h | 65 +++++++++++++++++++++++--------------------- 7 files changed, 184 insertions(+), 107 deletions(-) delete mode 100644 src/bin/main.cpp create mode 100644 src/bin/sample1.cpp diff --git a/src/bin/main.cpp b/src/bin/main.cpp deleted file mode 100644 index c0c004f..0000000 --- a/src/bin/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -#include "../core/WObject.h" -#include "../core/WSignal.h" -#include - -using namespace TizenDisplayServer; - -using SignalAType = WSignal; -using SignalBType = WSignal; - -class MJ : public WObject -{ - public: - MJ() : WObject("MJ"){ std::cout << "construct MJ" << std::endl;} - MJ(std::string name) : WObject(name) {std::cout << "construct MJ" << name << std::endl;} - ~MJ(){ std::cout << "destruct MJ" << std::endl;} - - struct SignalA : public SignalAType { - int emit(int val) { return SignalAType::emit(val); } - } signalA; - - struct SignalB : public SignalBType { - double emit(int val) { return SignalBType::emit(val); } - } signalB; -}; - -class Holder : public WObject { - public: - Holder() : WObject("Holder") {std::cout << "construct Holder" << std::endl;} - Holder(std::string name) : WObject(name) {std::cout << "construct Holder" << std::endl;} - ~Holder() {std::cout << "destruct Holder" << std::endl;} - - static int slotA(int a) { std::cout << "slotA invoked! a:" << a << std::endl; return 1; }; - static double slotB(int a) { std::cout << "slotB invoked! a:" << a << std::endl; return 123.456; }; - static int slotA2(int a) {std::cout << "slotA2 invoked! a:" << a << std::endl; return 2;} -}; - -int main (void) -{ - MJ mj("mj"); - MJ mj2("mj2"); - Holder holder("h1"); - Holder holder2("h2"); - - std::cout << "<<<<<<<< slotA connect to signala >>>>>>>>" << std::endl; - mj.signalA.connect(&holder, Holder::slotA); - std::cout << "<<<<<<<< slotA2 connect to signala >>>>>>>>" << std::endl; - mj.signalA.connect(&holder, Holder::slotA2); - - std::cout << "<<<<<<<< slotB connect to signalB >>>>>>>>" << std::endl; - mj.signalB.connect(&holder, Holder::slotB); - - - int a = mj.signalA.emit(1234); - double b = mj.signalB.emit(5678); - - return 0; -} \ No newline at end of file diff --git a/src/bin/sample1.cpp b/src/bin/sample1.cpp new file mode 100644 index 0000000..acb5f61 --- /dev/null +++ b/src/bin/sample1.cpp @@ -0,0 +1,69 @@ +#include "../core/WObject.h" +#include "../core/WSignal.h" +#include "../core/WRefBase.h" +#include + +using namespace TizenDisplayServer; + +using SignalAType = WSignal; +using SignalBType = WSignal; + +class Sender : public WObject +{ + public: + Sender() : WObject("Sender"){ std::cout << "construct Sender" << std::endl;} + Sender(std::string name) : WObject(name) {std::cout << "construct Sender " << name << std::endl;} + ~Sender(){ std::cout << "destruct Sender " << getName() << std::endl;} + + struct SignalA : public SignalAType { + void emit(int val) { SignalAType::emit(val); } + } signalA; + + struct SignalB : public SignalBType { + void emit(double val) { SignalBType::emit(val); } + } signalB; +}; + +class Receiver : public WObject, public WRefBase { + public: + Receiver() : WObject("Receiver"), WRefBase() { std::cout << "construct Receiver" << std::endl;} + Receiver(std::string name) : WObject(name), WRefBase() { std::cout << "construct Receiver " << name << std::endl;} + ~Receiver() { std::cout << "destruct Receiver(ref: " << getref() << ") " << getName() << std::endl; } + + static void slotA(int a) { std::cout << "slotA invoked! a:" << a << std::endl; }; + static void slotA2(int a) {std::cout << "slotA2 invoked! a:" << a << std::endl; } + static void slotB(double a) { std::cout << "slotB invoked! a:" << a << std::endl; }; +}; + +int main (void) +{ + Sender *sender = new Sender("sender"); + Sender *sender2 = new Sender("sender2"); + Receiver *receiver = new Receiver("receiver1"); + Receiver *receiver2 = new Receiver("receiver2"); + + sender->signalA.connect(receiver, Receiver::slotA); + sender->signalA.connect(receiver2, Receiver::slotA2); + sender->signalB.connect(receiver, Receiver::slotB); + sender->signalB.connect(receiver2, [](double val) { + std::cout << "Lambda slot invoked! val: " << val << std::endl; + }); + + sender->signalA.emit(1234); + sender->signalB.emit(45.67); + + if (receiver2->getref() == 1) + { + receiver2->unref(); + receiver2 = nullptr; + } + + sender->signalB.emit(5678); + sender->signalA.emit(90.1); + + delete sender; + delete sender2; + delete receiver; + + return 0; +} \ No newline at end of file diff --git a/src/core/WObject.cpp b/src/core/WObject.cpp index d46b329..53152db 100644 --- a/src/core/WObject.cpp +++ b/src/core/WObject.cpp @@ -5,17 +5,46 @@ namespace TizenDisplayServer{ WObjectPrivate::WObjectPrivate(WObject *p_ptr, std::string name) : p_ptr(p_ptr) { type_info.name = name; - std::cout << "construct WObjectPrivate" << std::endl; } WObjectPrivate::~WObjectPrivate() { - std::cout << "destruct WObjectPrivate" << std::endl; + } + + void WObjectPrivate::attachDestroyObserver(WObjectObserverIface *ob) + { + observers.push_back(ob); + } + + void WObjectPrivate::detachDestroyObserver(WObjectObserverIface *ob) + { + observers.remove(ob); + } + + bool WObjectPrivate::setProperty(std::string key, WProperty property) + { + } + + WProperty& WObjectPrivate::getProperty(std::string key) + { + } + + void WObjectPrivate::destroyNotify(void) + { + for (WObjectObserverIface* ob : observers) + { + ob->destroyed(p_ptr); + } + observers.clear(); + } + + std::string WObjectPrivate::getName(void) + { + return type_info.name; } WObject::WObject(std::string name) { - std::cout << "construct WOBject " << name < ptr(new WObjectPrivate(this, name)); d_ptr = std::move(ptr); } @@ -23,4 +52,34 @@ namespace TizenDisplayServer{ WObject::~WObject(){ destroyNotify(); } + + void WObject::destroyNotify(void) + { + d_func()->destroyNotify(); + } + + void WObject::attachDestroyObserver(WObjectObserverIface *ob) + { + d_func()->attachDestroyObserver(ob); + } + + void WObject::detachDestroyObserver(WObjectObserverIface *ob) + { + d_func()->detachDestroyObserver(ob); + } + + bool WObject::setProperty(std::string key, WProperty property) + { + + } + + WProperty& WObject::getProperty(std::string key) + { + + } + + std::string WObject::getName(void) + { + return d_func()->getName(); + } } diff --git a/src/core/WObject.h b/src/core/WObject.h index 46e52f3..86a4211 100644 --- a/src/core/WObject.h +++ b/src/core/WObject.h @@ -19,18 +19,19 @@ class WObject { inline WObjectPrivate* d_func() { return d_ptr.get(); } inline const WObjectPrivate* d_func() const { return d_ptr.get(); } - friend class WObjectPrivate; public: - WObject(std::string name = "default"); + WObject(std::string name = "WObject"); virtual ~WObject(); - void attachObserver(WObjectObserverIface *ob){} - void detachObserver(WObjectObserverIface *ob){} - void destroyNotify(void){} - bool setProperty(std::string key, WProperty property){} - WProperty& getProperty(std::string key){} + void attachDestroyObserver(WObjectObserverIface *ob); + void detachDestroyObserver(WObjectObserverIface *ob); + void destroyNotify(void); + bool setProperty(std::string key, WProperty property); + WProperty& getProperty(std::string key); + + std::string getName(void); }; class WObjectObserverIface { diff --git a/src/core/WObjectPrivate.h b/src/core/WObjectPrivate.h index a0ca476..8bd9a0d 100644 --- a/src/core/WObjectPrivate.h +++ b/src/core/WObjectPrivate.h @@ -15,15 +15,15 @@ class WObjectObserverIface; class WObjectPrivate { - struct { + struct TypeInfo{ std::string name; - - }type_info; + }; WObject *p_ptr; std::list observers; std::unordered_map properties; + TypeInfo type_info; public: WObjectPrivate() = delete; @@ -32,10 +32,13 @@ class WObjectPrivate { inline const WObject *p_func() const{ return p_ptr;} - void attachObserver(WObjectObserverIface *ob); - void detachObserver(WObjectObserverIface *ob); + void attachDestroyObserver(WObjectObserverIface *ob); + void detachDestroyObserver(WObjectObserverIface *ob); bool setProperty(std::string key, WProperty property); WProperty& getProperty(std::string key); + void destroyNotify(); + + std::string getName(void); }; } #else diff --git a/src/core/WRefBase.h b/src/core/WRefBase.h index 970c91b..00007f8 100644 --- a/src/core/WRefBase.h +++ b/src/core/WRefBase.h @@ -6,10 +6,10 @@ class WRefBase { int mCount; public: - WRefBase() : mCount(0) {}; - virtual ~WRefBase(); + WRefBase() : mCount(1) {} + virtual ~WRefBase() {} - void ref() {++mCount;} + void ref() { ++mCount; } void unref() {if (--mCount == 0) delete this;} int getref() { return mCount; } }; diff --git a/src/core/WSignal.h b/src/core/WSignal.h index 741c0da..578620d 100644 --- a/src/core/WSignal.h +++ b/src/core/WSignal.h @@ -15,52 +15,57 @@ namespace TizenDisplayServer{ ~WSlotsObserver(){} virtual void destroyed(WObject *obj); - void addSlot(WObject *slot); + virtual void addSlot(WObject *slot); }; - template + template class WSlotConnection : public WSlotsObserver{ //TODO: make callback as callback iface //std::unique_ptr callback; - R (*callback)(Args...); - template friend class WSignal; + void (*callback)(Args...); + template friend class WSignal; public: WSlotConnection() {} - WSlotConnection(WObject *slot, R (*func) (Args...)) : callback(func) { + WSlotConnection(WObject *slot, void (*func) (Args...)) : callback(func) { //TODO: make callback as callback iface //std::unique_ptr ptr(new WCallbackIface(func)); //callback = std::move(ptr); addSlot(slot); } - virtual ~WSlotConnection() {} + virtual ~WSlotConnection() + { + for (auto &&slot : slots) + slot->detachDestroyObserver(this); + slots.clear(); + } - void addSlot(WObject *slot) + void addSlot (WObject *slot) override { slots.push_back(slot); + slot->attachDestroyObserver(this); } - void destroyed(WObject *slot) + void destroyed(WObject *slot) override { slots.remove(slot); if (slots.empty()) - delete this; + { + //TODO: detete from WSignal connections list with guarded pointer + } } - R invoke(Args... args) + void invoke(Args... args) { - if (!std::is_void::value) - { - R ret = callback(args...); - return ret; - } + if (!slots.empty()) + callback(args...); } }; - template + template class WSignal { - std::list>> connections; - WSlotConnection *findcon(R (*func)(Args...)) { + std::list>> connections; + WSlotConnection *findcon(void (*func)(Args...)) { for (auto&& con : connections) { if (con->callback == func) @@ -73,29 +78,27 @@ namespace TizenDisplayServer{ WSignal() {} virtual ~WSignal() {} - WSignal& operator()(void) { return *this; } // functor + WSignal& operator()(void) { return *this; } // functor - void connect(WObject *slot, R (*func)(Args...)) + void connect(WObject *slot, void (*func)(Args...)) { if ((!slot) || (!func)) return; if (auto con = findcon(func)) + { con->addSlot(slot); + } else - connections.emplace_back(new WSlotConnection(slot, func)); - } - - R emit(Args... args){ - if (!std::is_void::value) { - R ret; - for (auto &&con : connections) - { - ret = con->invoke(args...); - } - return ret; + connections.emplace_back(new WSlotConnection(slot, func)); } } + + void emit(Args... args) + { + for (auto &&con : connections) + con->invoke(args...); + } }; } #else -- 2.7.4 From 201b2dd1b303c33663ad159a7779170d1016a318 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Tue, 18 Feb 2020 17:04:25 +0900 Subject: [PATCH 7/9] Use prefix to 'DS' Change-Id: Ib78ae073b7e6782c56a3b182c44f80e603b01b8a Signed-off-by: MinJeong Kim --- src/bin/sample1.cpp | 39 ++++++++--- src/core/WCallbackIface.h | 12 ---- src/core/WObject.cpp | 85 ----------------------- src/core/WObject.h | 46 ------------ src/core/WObjectPrivate.h | 45 ------------ src/core/WProperty.cpp | 0 src/core/WProperty.h | 12 ---- src/core/WPropertyPrivate.h | 0 src/core/WRefBase.cpp | 0 src/lib/DSCallbackIface.h | 12 ++++ src/lib/DSObject.cpp | 85 +++++++++++++++++++++++ src/lib/DSObject.h | 46 ++++++++++++ src/lib/DSObjectPrivate.h | 45 ++++++++++++ src/lib/DSProperty.cpp | 26 +++++++ src/lib/DSProperty.h | 36 ++++++++++ src/lib/DSPropertyPrivate.h | 4 ++ src/{core/WRefBasePrivate.h => lib/DSRefBase.cpp} | 0 src/{core/WRefBase.h => lib/DSRefBase.h} | 12 ++-- src/{core/WSignal.cpp => lib/DSSignal.cpp} | 8 +-- src/{core/WSignal.h => lib/DSSignal.h} | 57 +++++++-------- 20 files changed, 321 insertions(+), 249 deletions(-) delete mode 100644 src/core/WCallbackIface.h delete mode 100644 src/core/WObject.cpp delete mode 100644 src/core/WObject.h delete mode 100644 src/core/WObjectPrivate.h delete mode 100644 src/core/WProperty.cpp delete mode 100644 src/core/WProperty.h delete mode 100644 src/core/WPropertyPrivate.h delete mode 100644 src/core/WRefBase.cpp create mode 100644 src/lib/DSCallbackIface.h create mode 100644 src/lib/DSObject.cpp create mode 100644 src/lib/DSObject.h create mode 100644 src/lib/DSObjectPrivate.h create mode 100644 src/lib/DSProperty.cpp create mode 100644 src/lib/DSProperty.h create mode 100644 src/lib/DSPropertyPrivate.h rename src/{core/WRefBasePrivate.h => lib/DSRefBase.cpp} (100%) rename src/{core/WRefBase.h => lib/DSRefBase.h} (57%) rename src/{core/WSignal.cpp => lib/DSSignal.cpp} (60%) rename src/{core/WSignal.h => lib/DSSignal.h} (52%) diff --git a/src/bin/sample1.cpp b/src/bin/sample1.cpp index acb5f61..94bfedc 100644 --- a/src/bin/sample1.cpp +++ b/src/bin/sample1.cpp @@ -1,18 +1,35 @@ -#include "../core/WObject.h" -#include "../core/WSignal.h" -#include "../core/WRefBase.h" +#include "../lib/DSObject.h" +#include "../lib/DSSignal.h" +#include "../lib/DSRefBase.h" #include +/* SAMPLE RESULT +construct Sender sender +construct Sender sender2 +construct Receiver receiver1 +construct Receiver receiver2 +slotA invoked! a:1234 +slotA2 invoked! a:1234 +slotB invoked! a:45.67 +Lambda slot invoked! val: 45.67 +destruct Receiver(ref: 0) receiver2 +slotB invoked! a:5678 +slotA invoked! a:90 +destruct Sender sender +destruct Sender sender2 +destruct Receiver(ref: 1) receiver1 + */ + using namespace TizenDisplayServer; -using SignalAType = WSignal; -using SignalBType = WSignal; +using SignalAType = DSSignal; +using SignalBType = DSSignal; -class Sender : public WObject +class Sender : public DSObject { public: - Sender() : WObject("Sender"){ std::cout << "construct Sender" << std::endl;} - Sender(std::string name) : WObject(name) {std::cout << "construct Sender " << name << std::endl;} + Sender() : DSObject("Sender"){ std::cout << "construct Sender" << std::endl;} + Sender(std::string name) : DSObject(name) {std::cout << "construct Sender " << name << std::endl;} ~Sender(){ std::cout << "destruct Sender " << getName() << std::endl;} struct SignalA : public SignalAType { @@ -24,10 +41,10 @@ class Sender : public WObject } signalB; }; -class Receiver : public WObject, public WRefBase { +class Receiver : public DSObject, public DSRefBase { public: - Receiver() : WObject("Receiver"), WRefBase() { std::cout << "construct Receiver" << std::endl;} - Receiver(std::string name) : WObject(name), WRefBase() { std::cout << "construct Receiver " << name << std::endl;} + Receiver() : DSObject("Receiver"), DSRefBase() { std::cout << "construct Receiver" << std::endl;} + Receiver(std::string name) : DSObject(name), DSRefBase() { std::cout << "construct Receiver " << name << std::endl;} ~Receiver() { std::cout << "destruct Receiver(ref: " << getref() << ") " << getName() << std::endl; } static void slotA(int a) { std::cout << "slotA invoked! a:" << a << std::endl; }; diff --git a/src/core/WCallbackIface.h b/src/core/WCallbackIface.h deleted file mode 100644 index e9c4e87..0000000 --- a/src/core/WCallbackIface.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WCALLBACKIFACE_H -# define WCALLBACKIFACE_H -namespace TizenDisplayServer{ - struct WCallbackIface{ - WCallbackIface(){} - WCallbackIface(const WCallbackIface& cp){ - } - }; - -} -#else -#endif \ No newline at end of file diff --git a/src/core/WObject.cpp b/src/core/WObject.cpp deleted file mode 100644 index 53152db..0000000 --- a/src/core/WObject.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "WObjectPrivate.h" -#include "WObject.h" - -namespace TizenDisplayServer{ - WObjectPrivate::WObjectPrivate(WObject *p_ptr, std::string name) : p_ptr(p_ptr) - { - type_info.name = name; - } - - WObjectPrivate::~WObjectPrivate() - { - } - - void WObjectPrivate::attachDestroyObserver(WObjectObserverIface *ob) - { - observers.push_back(ob); - } - - void WObjectPrivate::detachDestroyObserver(WObjectObserverIface *ob) - { - observers.remove(ob); - } - - bool WObjectPrivate::setProperty(std::string key, WProperty property) - { - } - - WProperty& WObjectPrivate::getProperty(std::string key) - { - } - - void WObjectPrivate::destroyNotify(void) - { - for (WObjectObserverIface* ob : observers) - { - ob->destroyed(p_ptr); - } - observers.clear(); - } - - std::string WObjectPrivate::getName(void) - { - return type_info.name; - } - - WObject::WObject(std::string name) - { - std::unique_ptr ptr(new WObjectPrivate(this, name)); - d_ptr = std::move(ptr); - } - - WObject::~WObject(){ - destroyNotify(); - } - - void WObject::destroyNotify(void) - { - d_func()->destroyNotify(); - } - - void WObject::attachDestroyObserver(WObjectObserverIface *ob) - { - d_func()->attachDestroyObserver(ob); - } - - void WObject::detachDestroyObserver(WObjectObserverIface *ob) - { - d_func()->detachDestroyObserver(ob); - } - - bool WObject::setProperty(std::string key, WProperty property) - { - - } - - WProperty& WObject::getProperty(std::string key) - { - - } - - std::string WObject::getName(void) - { - return d_func()->getName(); - } -} diff --git a/src/core/WObject.h b/src/core/WObject.h deleted file mode 100644 index 86a4211..0000000 --- a/src/core/WObject.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef WOBJECT_H -# define WOBJECT_H - -#include "WObjectPrivate.h" -#include "WProperty.h" -#include -#include -#include -#include -#include - -namespace TizenDisplayServer{ -class WObjectPrivate; -class WObjectObserverIface; -class WProperty; - -class WObject { - std::unique_ptr d_ptr; - - inline WObjectPrivate* d_func() { return d_ptr.get(); } - inline const WObjectPrivate* d_func() const { return d_ptr.get(); } - - public: - WObject(std::string name = "WObject"); - virtual ~WObject(); - - void attachDestroyObserver(WObjectObserverIface *ob); - void detachDestroyObserver(WObjectObserverIface *ob); - void destroyNotify(void); - - bool setProperty(std::string key, WProperty property); - WProperty& getProperty(std::string key); - - std::string getName(void); -}; - -class WObjectObserverIface { - public: - WObjectObserverIface() {} - virtual ~WObjectObserverIface() {} - virtual void destroyed(WObject *obj) = 0; -}; - -} -#else -#endif \ No newline at end of file diff --git a/src/core/WObjectPrivate.h b/src/core/WObjectPrivate.h deleted file mode 100644 index 8bd9a0d..0000000 --- a/src/core/WObjectPrivate.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef WOBJECTPRIVATE_H -# define WOBJECTPRIVATE_H - -#include "WObject.h" -#include "WProperty.h" -#include -#include -#include -#include - -namespace TizenDisplayServer{ - -class WObject; -class WObjectObserverIface; - -class WObjectPrivate { - - struct TypeInfo{ - std::string name; - }; - - WObject *p_ptr; - - std::list observers; - std::unordered_map properties; - TypeInfo type_info; - - public: - WObjectPrivate() = delete; - WObjectPrivate(WObject *p_ptr, std::string name = "default"); - ~WObjectPrivate(); - - inline const WObject *p_func() const{ return p_ptr;} - - void attachDestroyObserver(WObjectObserverIface *ob); - void detachDestroyObserver(WObjectObserverIface *ob); - bool setProperty(std::string key, WProperty property); - WProperty& getProperty(std::string key); - void destroyNotify(); - - std::string getName(void); -}; -} -#else -#endif \ No newline at end of file diff --git a/src/core/WProperty.cpp b/src/core/WProperty.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/core/WProperty.h b/src/core/WProperty.h deleted file mode 100644 index c811603..0000000 --- a/src/core/WProperty.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WPROPERTY_H -# define WPROPERTY_H -namespace TizenDisplayServer{ - class WProperty { - public: - WProperty(){} - virtual ~WProperty() {} - }; -} - -#else -#endif \ No newline at end of file diff --git a/src/core/WPropertyPrivate.h b/src/core/WPropertyPrivate.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/core/WRefBase.cpp b/src/core/WRefBase.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/DSCallbackIface.h b/src/lib/DSCallbackIface.h new file mode 100644 index 0000000..801328c --- /dev/null +++ b/src/lib/DSCallbackIface.h @@ -0,0 +1,12 @@ +#ifndef DSCALLBACKIFACE_H +# define DSCALLBACKIFACE_H +namespace TizenDisplayServer{ + struct DSCallbackIface{ + DSCallbackIface(){} + DSCallbackIface(const DSCallbackIface& cp){ + } + }; + +} +#else +#endif /* DSCALLBACKIFACE_H */ diff --git a/src/lib/DSObject.cpp b/src/lib/DSObject.cpp new file mode 100644 index 0000000..9829b71 --- /dev/null +++ b/src/lib/DSObject.cpp @@ -0,0 +1,85 @@ +#include "DSObjectPrivate.h" +#include "DSObject.h" + +namespace TizenDisplayServer{ + DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr, std::string name) : p_ptr(p_ptr) + { + type_info.name = name; + } + + DSObjectPrivate::~DSObjectPrivate() + { + } + + void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) + { + observers.push_back(ob); + } + + void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) + { + observers.remove(ob); + } + + bool DSObjectPrivate::setProperty(std::string key, DSProperty&& property) + { + + } + + DSProperty& DSObjectPrivate::getProperty(std::string key) + { + } + + void DSObjectPrivate::destroyNotify(void) + { + for (DSObjectObserverIface* ob : observers) + { + ob->destroyed(p_ptr); + } + observers.clear(); + } + + std::string DSObjectPrivate::getName(void) + { + return type_info.name; + } + + DSObject::DSObject(std::string name) + { + std::unique_ptr ptr(new DSObjectPrivate(this, name)); + d_ptr = std::move(ptr); + } + + DSObject::~DSObject(){ + destroyNotify(); + } + + void DSObject::destroyNotify(void) + { + d_func()->destroyNotify(); + } + + void DSObject::attachDestroyObserver(DSObjectObserverIface *ob) + { + d_func()->attachDestroyObserver(ob); + } + + void DSObject::detachDestroyObserver(DSObjectObserverIface *ob) + { + d_func()->detachDestroyObserver(ob); + } + + bool DSObject::setProperty(std::string key, DSPropertyVariant& data, DSPropertyType type) + { + } + + DSPropertyVariant& DSObject::getProperty(std::string key) + { + + } + + std::string DSObject::getName(void) + { + return d_func()->getName(); + } +} diff --git a/src/lib/DSObject.h b/src/lib/DSObject.h new file mode 100644 index 0000000..23dd8f9 --- /dev/null +++ b/src/lib/DSObject.h @@ -0,0 +1,46 @@ +#ifndef DSOBJECT_H +# define DSOBJECT_H + +#include "DSObjectPrivate.h" +#include "DSProperty.h" +#include +#include +#include + +namespace TizenDisplayServer{ +class DSObjectPrivate; +class DSObjectObserverIface; +class DSProperty; + +class DSObject { + std::unique_ptr d_ptr; + + inline DSObjectPrivate* d_func() { return d_ptr.get(); } + inline const DSObjectPrivate* d_func() const { return d_ptr.get(); } + + public: + DSObject(std::string name = "WObject"); + virtual ~DSObject(); + + void attachDestroyObserver(DSObjectObserverIface *ob); + void detachDestroyObserver(DSObjectObserverIface *ob); + void destroyNotify(void); + + bool setProperty(std::string key, DSPropertyVariant& data, DSPropertyType type); + DSPropertyVariant& getProperty(std::string key); + + std::string getName(void); +}; + +class DSObjectObserverIface { + protected: + DSObjectObserverIface() {} + virtual ~DSObjectObserverIface() {} + + public: + virtual void destroyed(DSObject *obj) = 0; +}; + +} +#else +#endif /* DSOBJECT_H */ diff --git a/src/lib/DSObjectPrivate.h b/src/lib/DSObjectPrivate.h new file mode 100644 index 0000000..89e3f16 --- /dev/null +++ b/src/lib/DSObjectPrivate.h @@ -0,0 +1,45 @@ +#ifndef DSOBJECTPRIVATE_H +# define DSOBJECTPRIVATE_H + +#include "DSObject.h" +#include "DSProperty.h" +#include +#include +#include +#include + +namespace TizenDisplayServer{ + +class DSObject; +class DSObjectObserverIface; + +class DSObjectPrivate { + + struct { + std::string name; + }type_info; + + DSObject *p_ptr; + + std::list observers; + std::unordered_map properties; + + public: + DSObjectPrivate() = delete; + DSObjectPrivate(DSObject *p_ptr, std::string name = "default"); + virtual ~DSObjectPrivate(); + + inline const DSObject *p_func() const{ return p_ptr;} + + void attachDestroyObserver(DSObjectObserverIface *ob); + void detachDestroyObserver(DSObjectObserverIface *ob); + void destroyNotify(); + + bool setProperty(std::string key, DSProperty&& property); + DSProperty& getProperty(std::string key); + + std::string getName(void); +}; +} +#else +#endif /* DSOBJECTPRIVATE_H */ diff --git a/src/lib/DSProperty.cpp b/src/lib/DSProperty.cpp new file mode 100644 index 0000000..09251e9 --- /dev/null +++ b/src/lib/DSProperty.cpp @@ -0,0 +1,26 @@ +#include "DSProperty.h" + +namespace TizenDisplayServer{ + DSProperty::DSProperty(std::string _key, DSPropertyVariant& _data, DSPropertyType _type) : key(_key), type(_type) + { + switch(_type) + { + //copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + data = _data; //copy + break; + case DSPropertyType::OBJECT: + data = &_data; //address + break; + default: + break; + } + } + + DSProperty::~DSProperty() + { + } +} diff --git a/src/lib/DSProperty.h b/src/lib/DSProperty.h new file mode 100644 index 0000000..372de21 --- /dev/null +++ b/src/lib/DSProperty.h @@ -0,0 +1,36 @@ +#ifndef DSPROPERTY_H +# define DSPROPERTY_H +#include +#include + +namespace TizenDisplayServer{ + using DSPropertyType = enum type{ + NONE, + INTEGER, + FLOAT, + DOUBLE, + STRING, + OBJECT, + }; + + using DSPropertyVariant = std::variant; + + class DSProperty + { + private: + std::string key; + DSPropertyVariant data; + DSPropertyType type; + + public: + DSProperty(std::string key, DSPropertyVariant& data, DSPropertyType type); + virtual ~DSProperty(); + }; +} + +#else +#endif /* DSPROPERTY_H */ diff --git a/src/lib/DSPropertyPrivate.h b/src/lib/DSPropertyPrivate.h new file mode 100644 index 0000000..d7abaa5 --- /dev/null +++ b/src/lib/DSPropertyPrivate.h @@ -0,0 +1,4 @@ +#ifndef DSPROPERTYPRIVATE_H +# define DSPROPERTYPRIVATE_H +#else +#endif /* DSPROPERTYPRIVATE_H */ diff --git a/src/core/WRefBasePrivate.h b/src/lib/DSRefBase.cpp similarity index 100% rename from src/core/WRefBasePrivate.h rename to src/lib/DSRefBase.cpp diff --git a/src/core/WRefBase.h b/src/lib/DSRefBase.h similarity index 57% rename from src/core/WRefBase.h rename to src/lib/DSRefBase.h index 00007f8..d5ba124 100644 --- a/src/core/WRefBase.h +++ b/src/lib/DSRefBase.h @@ -1,13 +1,13 @@ -#ifndef WREFBASE_H -# define WREFBASE_H +#ifndef DSREFBASE_H +# define DSREFBASE_H namespace TizenDisplayServer{ -class WRefBase { +class DSRefBase { int mCount; public: - WRefBase() : mCount(1) {} - virtual ~WRefBase() {} + DSRefBase() : mCount(1) {} + virtual ~DSRefBase() {} void ref() { ++mCount; } void unref() {if (--mCount == 0) delete this;} @@ -16,4 +16,4 @@ class WRefBase { } #else -#endif \ No newline at end of file +#endif /* DSREFBASE_H */ diff --git a/src/core/WSignal.cpp b/src/lib/DSSignal.cpp similarity index 60% rename from src/core/WSignal.cpp rename to src/lib/DSSignal.cpp index 418065b..ecac107 100644 --- a/src/core/WSignal.cpp +++ b/src/lib/DSSignal.cpp @@ -1,16 +1,16 @@ -#include "WSignal.h" +#include "DSSignal.h" #include namespace TizenDisplayServer { - void WSlotsObserver::addSlot(WObject *slot) + void DSSlotsObserver::addSlot(DSObject *slot) { slots.push_back(slot); } - void WSlotsObserver::destroyed(WObject *slot) + void DSSlotsObserver::destroyed(DSObject *slot) { slots.remove(slot); if (slots.empty()) delete this; } -} \ No newline at end of file +} diff --git a/src/core/WSignal.h b/src/lib/DSSignal.h similarity index 52% rename from src/core/WSignal.h rename to src/lib/DSSignal.h index 578620d..3809174 100644 --- a/src/core/WSignal.h +++ b/src/lib/DSSignal.h @@ -1,56 +1,57 @@ -#ifndef WSIGNAL_H -# define WSIGNAL_H -#include "WObject.h" +#ifndef DSSIGNAL_H +# define DSSIGNAL_H + +#include "DSObject.h" #include #include #include #include namespace TizenDisplayServer{ - class WSlotsObserver : public WObjectObserverIface { + class DSSlotsObserver : public DSObjectObserverIface { protected: - std::list slots; + std::list slots; public: - WSlotsObserver(){} - ~WSlotsObserver(){} + DSSlotsObserver(){} + ~DSSlotsObserver(){} - virtual void destroyed(WObject *obj); - virtual void addSlot(WObject *slot); + virtual void destroyed(DSObject *obj); + virtual void addSlot(DSObject *slot); }; template - class WSlotConnection : public WSlotsObserver{ + class DSSlotConnection : public DSSlotsObserver{ //TODO: make callback as callback iface - //std::unique_ptr callback; + //std::unique_ptr callback; void (*callback)(Args...); - template friend class WSignal; + template friend class DSSignal; public: - WSlotConnection() {} - WSlotConnection(WObject *slot, void (*func) (Args...)) : callback(func) { + DSSlotConnection() {} + DSSlotConnection(DSObject *slot, void (*func) (Args...)) : callback(func) { //TODO: make callback as callback iface - //std::unique_ptr ptr(new WCallbackIface(func)); + //std::unique_ptr ptr(new DSCallbackIface(func)); //callback = std::move(ptr); addSlot(slot); } - virtual ~WSlotConnection() + virtual ~DSSlotConnection() { for (auto &&slot : slots) slot->detachDestroyObserver(this); slots.clear(); } - void addSlot (WObject *slot) override + void addSlot (DSObject *slot) override { slots.push_back(slot); slot->attachDestroyObserver(this); } - void destroyed(WObject *slot) override + void destroyed(DSObject *slot) override { slots.remove(slot); if (slots.empty()) { - //TODO: detete from WSignal connections list with guarded pointer + //TODO: delete from DSSignal connections list with [guard pointer] } } @@ -63,9 +64,9 @@ namespace TizenDisplayServer{ }; template - class WSignal { - std::list>> connections; - WSlotConnection *findcon(void (*func)(Args...)) { + class DSSignal { + std::list>> connections; + DSSlotConnection *findcon(void (*func)(Args...)) { for (auto&& con : connections) { if (con->callback == func) @@ -75,12 +76,12 @@ namespace TizenDisplayServer{ } public: - WSignal() {} - virtual ~WSignal() {} + DSSignal() {} + virtual ~DSSignal() {} - WSignal& operator()(void) { return *this; } // functor + DSSignal& operator()(void) { return *this; } // functor - void connect(WObject *slot, void (*func)(Args...)) + void connect(DSObject *slot, void (*func)(Args...)) { if ((!slot) || (!func)) return; @@ -90,7 +91,7 @@ namespace TizenDisplayServer{ } else { - connections.emplace_back(new WSlotConnection(slot, func)); + connections.emplace_back(new DSSlotConnection(slot, func)); } } @@ -102,4 +103,4 @@ namespace TizenDisplayServer{ }; } #else -#endif \ No newline at end of file +#endif /* DSSIGNAL_H */ -- 2.7.4 From 5f1a83b7c2a68c3f67a2cdbb39786646e112bdcf Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Wed, 19 Feb 2020 20:02:13 +0900 Subject: [PATCH 8/9] follow c++ coding convention Change-Id: I0e4d8094a351ed3df2abc26136ac3c85b7a56d6c Signed-off-by: MinJeong Kim --- src/bin/sample1.cpp | 4 +- src/lib/DSCallback.h | 32 ++++++++ src/lib/DSCallbackIface.h | 12 --- src/lib/DSObject.cpp | 128 ++++++++++++++++---------------- src/lib/DSObject.h | 49 +++++++------ src/lib/DSObjectPrivate.h | 50 ++++++------- src/lib/DSProperty.cpp | 44 +++++------ src/lib/DSProperty.h | 57 +++++++-------- src/lib/DSPropertyPrivate.h | 6 +- src/lib/DSRefBase.h | 32 ++++---- src/lib/DSSignal.cpp | 23 +++--- src/lib/DSSignal.h | 174 ++++++++++++++++++++++---------------------- 12 files changed, 312 insertions(+), 299 deletions(-) create mode 100644 src/lib/DSCallback.h delete mode 100644 src/lib/DSCallbackIface.h diff --git a/src/bin/sample1.cpp b/src/bin/sample1.cpp index 94bfedc..c8035a2 100644 --- a/src/bin/sample1.cpp +++ b/src/bin/sample1.cpp @@ -20,7 +20,7 @@ destruct Sender sender2 destruct Receiver(ref: 1) receiver1 */ -using namespace TizenDisplayServer; +using namespace display_server; using SignalAType = DSSignal; using SignalBType = DSSignal; @@ -83,4 +83,4 @@ int main (void) delete receiver; return 0; -} \ No newline at end of file +} diff --git a/src/lib/DSCallback.h b/src/lib/DSCallback.h new file mode 100644 index 0000000..9fba026 --- /dev/null +++ b/src/lib/DSCallback.h @@ -0,0 +1,32 @@ +#ifndef __DSCALLBACK_H +#define __DSCALLBACK_H +#include + +namespace display_server +{ +template +class DSCallback { +protected: + virtual ~DSCallback() {} + DSCallback(const DSCallback &cb) {} + bool operator==(const DSCallback &cb); +private: + std::function __function; +}; + +template +class DSCallbackUnique : public DSCallback { +public: + DSCallbackUnique((void)(*function)(Args...)); +}; + +template +class DSCallbackMember : public DSCallback { +}; + +template +class DSCallbackSignal : public DSCallback { +}; +} // namespace display_server +#else +#endif /* __DSCALLBACK_H */ diff --git a/src/lib/DSCallbackIface.h b/src/lib/DSCallbackIface.h deleted file mode 100644 index 801328c..0000000 --- a/src/lib/DSCallbackIface.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef DSCALLBACKIFACE_H -# define DSCALLBACKIFACE_H -namespace TizenDisplayServer{ - struct DSCallbackIface{ - DSCallbackIface(){} - DSCallbackIface(const DSCallbackIface& cp){ - } - }; - -} -#else -#endif /* DSCALLBACKIFACE_H */ diff --git a/src/lib/DSObject.cpp b/src/lib/DSObject.cpp index 9829b71..2d13870 100644 --- a/src/lib/DSObject.cpp +++ b/src/lib/DSObject.cpp @@ -1,85 +1,79 @@ #include "DSObjectPrivate.h" #include "DSObject.h" +#include "DSProperty.h" -namespace TizenDisplayServer{ - DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr, std::string name) : p_ptr(p_ptr) - { - type_info.name = name; - } - - DSObjectPrivate::~DSObjectPrivate() - { - } - - void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) - { - observers.push_back(ob); - } - - void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) - { - observers.remove(ob); - } +namespace display_server +{ +DSObjectPrivate::DSObjectPrivate(DSObject *p_ptr, std::string name) : p_ptr(p_ptr) +{ + type_info.name = name; +} - bool DSObjectPrivate::setProperty(std::string key, DSProperty&& property) - { +DSObjectPrivate::~DSObjectPrivate() +{ +} - } +void DSObjectPrivate::attachDestroyObserver(DSObjectObserverIface *ob) +{ + observers.push_back(ob); +} - DSProperty& DSObjectPrivate::getProperty(std::string key) - { - } +void DSObjectPrivate::detachDestroyObserver(DSObjectObserverIface *ob) +{ + observers.remove(ob); +} - void DSObjectPrivate::destroyNotify(void) - { - for (DSObjectObserverIface* ob : observers) - { - ob->destroyed(p_ptr); - } - observers.clear(); - } +bool DSObjectPrivate::setProperty(std::string key, DSProperty &&property) +{ +} - std::string DSObjectPrivate::getName(void) - { - return type_info.name; - } +DSProperty &DSObjectPrivate::getProperty(std::string key) +{ +} - DSObject::DSObject(std::string name) - { - std::unique_ptr ptr(new DSObjectPrivate(this, name)); - d_ptr = std::move(ptr); - } +void DSObjectPrivate::notifyDestroy(void) +{ + for (DSObjectObserverIface *ob : observers) + ob->destroyed(p_ptr); + observers.clear(); +} - DSObject::~DSObject(){ - destroyNotify(); - } +std::string DSObjectPrivate::getName(void) +{ + return type_info.name; +} - void DSObject::destroyNotify(void) - { - d_func()->destroyNotify(); - } +DSObject::DSObject(std::string name) +{ + std::unique_ptr ptr(new DSObjectPrivate(this, name)); + __d_ptr = std::move(ptr); +} - void DSObject::attachDestroyObserver(DSObjectObserverIface *ob) - { - d_func()->attachDestroyObserver(ob); - } +DSObject::~DSObject() +{ + d_func()->notifyDestroy(); +} - void DSObject::detachDestroyObserver(DSObjectObserverIface *ob) - { - d_func()->detachDestroyObserver(ob); - } +void DSObject::attachDestroyObserver(DSObjectObserverIface *ob) +{ + d_func()->attachDestroyObserver(ob); +} - bool DSObject::setProperty(std::string key, DSPropertyVariant& data, DSPropertyType type) - { - } +void DSObject::detachDestroyObserver(DSObjectObserverIface *ob) +{ + d_func()->detachDestroyObserver(ob); +} - DSPropertyVariant& DSObject::getProperty(std::string key) - { +bool DSObject::setProperty(std::string key, const DSPropertyVariant& data, DSPropertyType type) +{ +} - } +DSPropertyVariant &DSObject::getProperty(std::string key) +{ +} - std::string DSObject::getName(void) - { - return d_func()->getName(); - } +std::string DSObject::getName(void) +{ + return d_func()->getName(); } +} // namespace display_server diff --git a/src/lib/DSObject.h b/src/lib/DSObject.h index 23dd8f9..48b2696 100644 --- a/src/lib/DSObject.h +++ b/src/lib/DSObject.h @@ -1,46 +1,47 @@ -#ifndef DSOBJECT_H -# define DSOBJECT_H +#ifndef __DSOBJECT_H +#define __DSOBJECT_H -#include "DSObjectPrivate.h" -#include "DSProperty.h" #include #include #include +#include "DSObjectPrivate.h" +#include "DSProperty.h" -namespace TizenDisplayServer{ +namespace display_server +{ class DSObjectPrivate; class DSObjectObserverIface; class DSProperty; class DSObject { - std::unique_ptr d_ptr; + public: + explicit DSObject(std::string name = "WObject"); + virtual ~DSObject(); - inline DSObjectPrivate* d_func() { return d_ptr.get(); } - inline const DSObjectPrivate* d_func() const { return d_ptr.get(); } + void attachDestroyObserver(DSObjectObserverIface *ob); + void detachDestroyObserver(DSObjectObserverIface *ob); - public: - DSObject(std::string name = "WObject"); - virtual ~DSObject(); + bool setProperty(std::string key, const DSPropertyVariant &data, DSPropertyType type); + DSPropertyVariant &getProperty(std::string key); - void attachDestroyObserver(DSObjectObserverIface *ob); - void detachDestroyObserver(DSObjectObserverIface *ob); - void destroyNotify(void); + std::string getName(void); - bool setProperty(std::string key, DSPropertyVariant& data, DSPropertyType type); - DSPropertyVariant& getProperty(std::string key); + private: + inline DSObjectPrivate* d_func() { return __d_ptr.get(); } + inline const DSObjectPrivate* d_func() const { return __d_ptr.get(); } - std::string getName(void); + std::unique_ptr __d_ptr; }; class DSObjectObserverIface { - protected: - DSObjectObserverIface() {} - virtual ~DSObjectObserverIface() {} +protected: + DSObjectObserverIface() {} + virtual ~DSObjectObserverIface() {} - public: - virtual void destroyed(DSObject *obj) = 0; +public: + virtual void destroyed(DSObject *obj) = 0; }; -} +} // namespace display_server #else -#endif /* DSOBJECT_H */ +#endif /* __DSOBJECT_H */ diff --git a/src/lib/DSObjectPrivate.h b/src/lib/DSObjectPrivate.h index 89e3f16..6af36df 100644 --- a/src/lib/DSObjectPrivate.h +++ b/src/lib/DSObjectPrivate.h @@ -1,45 +1,45 @@ -#ifndef DSOBJECTPRIVATE_H -# define DSOBJECTPRIVATE_H +#ifndef __DSOBJECTPRIVATE_H +#define __DSOBJECTPRIVATE_H #include "DSObject.h" -#include "DSProperty.h" #include #include #include #include +#include "DSProperty.h" -namespace TizenDisplayServer{ - +namespace display_server { class DSObject; class DSObjectObserverIface; class DSObjectPrivate { +public: + DSObjectPrivate() = delete; + DSObjectPrivate(DSObject *p_ptr, std::string name = "default"); + virtual ~DSObjectPrivate(); - struct { - std::string name; - }type_info; - - DSObject *p_ptr; + inline const DSObject *p_func() const { return p_ptr; } - std::list observers; - std::unordered_map properties; + void attachDestroyObserver(DSObjectObserverIface *ob); + void detachDestroyObserver(DSObjectObserverIface *ob); + void notifyDestroy(); - public: - DSObjectPrivate() = delete; - DSObjectPrivate(DSObject *p_ptr, std::string name = "default"); - virtual ~DSObjectPrivate(); + bool setProperty(std::string key, DSProperty &&property); + DSProperty &getProperty(std::string key); - inline const DSObject *p_func() const{ return p_ptr;} + std::string getName(void); - void attachDestroyObserver(DSObjectObserverIface *ob); - void detachDestroyObserver(DSObjectObserverIface *ob); - void destroyNotify(); +private: + struct + { + std::string name; + } type_info; - bool setProperty(std::string key, DSProperty&& property); - DSProperty& getProperty(std::string key); + DSObject *p_ptr; - std::string getName(void); + std::list observers; + std::unordered_map properties; }; -} +} // namespace display_server #else -#endif /* DSOBJECTPRIVATE_H */ +#endif /* __DSOBJECTPRIVATE_H */ diff --git a/src/lib/DSProperty.cpp b/src/lib/DSProperty.cpp index 09251e9..5510add 100644 --- a/src/lib/DSProperty.cpp +++ b/src/lib/DSProperty.cpp @@ -1,26 +1,26 @@ #include "DSProperty.h" -namespace TizenDisplayServer{ - DSProperty::DSProperty(std::string _key, DSPropertyVariant& _data, DSPropertyType _type) : key(_key), type(_type) - { - switch(_type) - { - //copy case - case DSPropertyType::INTEGER: - case DSPropertyType::DOUBLE: - case DSPropertyType::FLOAT: - case DSPropertyType::STRING: - data = _data; //copy - break; - case DSPropertyType::OBJECT: - data = &_data; //address - break; - default: - break; - } - } +namespace display_server { +DSProperty::DSProperty(std::string _key, DSPropertyVariant &_data, DSPropertyType _type) : key(_key), type(_type) +{ + switch (_type) + { + //copy case + case DSPropertyType::INTEGER: + case DSPropertyType::DOUBLE: + case DSPropertyType::FLOAT: + case DSPropertyType::STRING: + data = _data; //copy + break; + case DSPropertyType::OBJECT: + data = (&_data); //address + break; + default: + break; + } +} - DSProperty::~DSProperty() - { - } +DSProperty::~DSProperty() +{ } +} // namespace display_server diff --git a/src/lib/DSProperty.h b/src/lib/DSProperty.h index 372de21..2270c70 100644 --- a/src/lib/DSProperty.h +++ b/src/lib/DSProperty.h @@ -1,36 +1,33 @@ -#ifndef DSPROPERTY_H -# define DSPROPERTY_H +#ifndef __DSPROPERTY_H +#define __DSPROPERTY_H #include #include -namespace TizenDisplayServer{ - using DSPropertyType = enum type{ - NONE, - INTEGER, - FLOAT, - DOUBLE, - STRING, - OBJECT, - }; +namespace display_server { +using DSPropertyType = enum type { + NONE, + INTEGER, + FLOAT, + DOUBLE, + STRING, + OBJECT, +}; - using DSPropertyVariant = std::variant; - - class DSProperty - { - private: - std::string key; - DSPropertyVariant data; - DSPropertyType type; - - public: - DSProperty(std::string key, DSPropertyVariant& data, DSPropertyType type); - virtual ~DSProperty(); - }; -} +using DSPropertyVariant = std::variant; +class DSProperty { +public: + DSProperty(std::string key, DSPropertyVariant& data, DSPropertyType type); + virtual ~DSProperty(); +private: + std::string key; + DSPropertyVariant data; + DSPropertyType type; +}; +} // namespace display_server #else -#endif /* DSPROPERTY_H */ +#endif /* __DSPROPERTY_H */ diff --git a/src/lib/DSPropertyPrivate.h b/src/lib/DSPropertyPrivate.h index d7abaa5..236482d 100644 --- a/src/lib/DSPropertyPrivate.h +++ b/src/lib/DSPropertyPrivate.h @@ -1,4 +1,4 @@ -#ifndef DSPROPERTYPRIVATE_H -# define DSPROPERTYPRIVATE_H +#ifndef __DSPROPERTYPRIVATE_H +# define __DSPROPERTYPRIVATE_H #else -#endif /* DSPROPERTYPRIVATE_H */ +#endif /* __DSPROPERTYPRIVATE_H */ diff --git a/src/lib/DSRefBase.h b/src/lib/DSRefBase.h index d5ba124..bd37b1c 100644 --- a/src/lib/DSRefBase.h +++ b/src/lib/DSRefBase.h @@ -1,19 +1,21 @@ -#ifndef DSREFBASE_H -# define DSREFBASE_H -namespace TizenDisplayServer{ - +#ifndef __DSREFBASE_H +#define __DSREFBASE_H +namespace display_server { class DSRefBase { - int mCount; - - public: - DSRefBase() : mCount(1) {} - virtual ~DSRefBase() {} +public: + DSRefBase() : mCount(1) {} + virtual ~DSRefBase() {} - void ref() { ++mCount; } - void unref() {if (--mCount == 0) delete this;} - int getref() { return mCount; } + void ref() { ++mCount; } + inline void unref() + { + if (--mCount == 0) + delete this; + } + const int getref() const { return mCount; } +private: + int mCount; }; - -} +} // namespace display_server #else -#endif /* DSREFBASE_H */ +#endif /* __DSREFBASE_H */ diff --git a/src/lib/DSSignal.cpp b/src/lib/DSSignal.cpp index ecac107..1b24993 100644 --- a/src/lib/DSSignal.cpp +++ b/src/lib/DSSignal.cpp @@ -1,16 +1,15 @@ #include "DSSignal.h" -#include -namespace TizenDisplayServer { - void DSSlotsObserver::addSlot(DSObject *slot) - { - slots.push_back(slot); - } - void DSSlotsObserver::destroyed(DSObject *slot) - { - slots.remove(slot); - if (slots.empty()) - delete this; - } +namespace display_server { +void DSSlotsObserver::addSlot(DSObject *slot) +{ + slots.push_back(slot); +} +void DSSlotsObserver::destroyed(DSObject *slot) +{ + slots.remove(slot); + if (slots.empty()) + delete this; } +} // namespace display_server diff --git a/src/lib/DSSignal.h b/src/lib/DSSignal.h index 3809174..824cc4d 100644 --- a/src/lib/DSSignal.h +++ b/src/lib/DSSignal.h @@ -1,5 +1,5 @@ -#ifndef DSSIGNAL_H -# define DSSIGNAL_H +#ifndef __DSSIGNAL_H +#define __DSSIGNAL_H #include "DSObject.h" #include @@ -7,100 +7,100 @@ #include #include -namespace TizenDisplayServer{ - class DSSlotsObserver : public DSObjectObserverIface { - protected: - std::list slots; - public: - DSSlotsObserver(){} - ~DSSlotsObserver(){} +namespace display_server { +class DSSlotsObserver : public DSObjectObserverIface { +public: + DSSlotsObserver() {} + ~DSSlotsObserver() {} - virtual void destroyed(DSObject *obj); - virtual void addSlot(DSObject *slot); - }; + virtual void destroyed(DSObject *obj); + virtual void addSlot(DSObject *slot); +protected: + std::list slots; +}; - template - class DSSlotConnection : public DSSlotsObserver{ - //TODO: make callback as callback iface - //std::unique_ptr callback; - void (*callback)(Args...); - template friend class DSSignal; +template +class DSSlotConnection : public DSSlotsObserver { + public: + DSSlotConnection() {} + DSSlotConnection(DSObject *slot, void (*func)(Args...)) : callback(func) + { + //TODO: make callback as callback iface + //std::unique_ptr ptr(new DSCallbackIface(func)); + //callback = std::move(ptr); + addSlot(slot); + } + virtual ~DSSlotConnection() + { + for (auto &&slot : slots) + slot->detachDestroyObserver(this); + slots.clear(); + } - public: - DSSlotConnection() {} - DSSlotConnection(DSObject *slot, void (*func) (Args...)) : callback(func) { - //TODO: make callback as callback iface - //std::unique_ptr ptr(new DSCallbackIface(func)); - //callback = std::move(ptr); - addSlot(slot); - } - virtual ~DSSlotConnection() - { - for (auto &&slot : slots) - slot->detachDestroyObserver(this); - slots.clear(); - } + void addSlot(DSObject *slot) override + { + slots.push_back(slot); + slot->attachDestroyObserver(this); + } + void destroyed(DSObject *slot) override + { + slots.remove(slot); + if (slots.empty()) + ;//TODO: delete from DSSignal connections list with [guard pointer] + } - void addSlot (DSObject *slot) override - { - slots.push_back(slot); - slot->attachDestroyObserver(this); - } - void destroyed(DSObject *slot) override - { - slots.remove(slot); - if (slots.empty()) - { - //TODO: delete from DSSignal connections list with [guard pointer] - } - } + void invoke(Args... args) + { + if (!slots.empty()) + callback(args...); + } - void invoke(Args... args) - { - if (!slots.empty()) - callback(args...); - } +private: + //TODO: make callback as callback iface + //std::unique_ptr callback; + void (*callback)(Args...); + template + friend class DSSignal; +}; - }; +template +class DSSignal { +public: + DSSignal() {} + virtual ~DSSignal() {} - template - class DSSignal { - std::list>> connections; - DSSlotConnection *findcon(void (*func)(Args...)) { - for (auto&& con : connections) - { - if (con->callback == func) - return con.get(); - } - return nullptr; - } + DSSignal &operator()(void) { return *this; } // functor - public: - DSSignal() {} - virtual ~DSSignal() {} + void connect(DSObject *slot, void (*func)(Args...)) + { + if ((!slot) || (!func)) + return; + if (auto con = findcon(func)) { + con->addSlot(slot); + } else { + connections.emplace_back(new DSSlotConnection(slot, func)); + } + } - DSSignal& operator()(void) { return *this; } // functor + void emit(Args... args) + { + for (auto &&con : connections) + con->invoke(args...); + } - void connect(DSObject *slot, void (*func)(Args...)) - { - if ((!slot) || (!func)) - return; - if (auto con = findcon(func)) - { - con->addSlot(slot); - } - else - { - connections.emplace_back(new DSSlotConnection(slot, func)); - } - } +private: + DSSlotConnection *findcon(void (*func)(Args...)) + { + for (auto &&con : connections) + { + if (con->callback == func) + return con.get(); + } + return nullptr; + } - void emit(Args... args) - { - for (auto &&con : connections) - con->invoke(args...); - } - }; -} + std::list>> connections; +}; +} // namespace display_server #else -#endif /* DSSIGNAL_H */ +#endif /* __DSSIGNAL_H */ -- 2.7.4 From 20fc0d4c5ab8c3c8d791dd9916b1d8bce23ffea3 Mon Sep 17 00:00:00 2001 From: jeon Date: Thu, 20 Feb 2020 19:53:13 +0900 Subject: [PATCH 9/9] packaging: version up to 0.0.1 Change-Id: Ibd319dd077327fde53e1041af58a4c077aa99240 --- meson.build | 77 ++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 0 packaging/test-server.manifest | 5 +++ packaging/test-server.spec | 58 +++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 packaging/test-server.manifest create mode 100644 packaging/test-server.spec diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..4eddada --- /dev/null +++ b/meson.build @@ -0,0 +1,77 @@ +project('test-server', 'cpp', + version : '0.0.1', + license : 'MIT', + default_options : ['cpp_std=c++17'] + ) + +libDS_version = meson.project_version().split('.') + +dir_prefix = get_option('prefix') +dir_lib = join_paths(dir_prefix, get_option('libdir')) +dir_bin = join_paths(dir_prefix, get_option('bindir')) + +#subdir('src') + +## libds + +install_headers('src/lib/DSObject.h', + 'src/lib/DSSignal.h', + 'src/lib/DSRefBase.h') + +src_libds = [ + 'src/lib/DSRefBase.cpp', + 'src/lib/DSRefBase.h', + 'src/lib/DSObject.cpp', + 'src/lib/DSObject.h', + 'src/lib/DSObjectPrivate.h', + 'src/lib/DSSignal.cpp', + 'src/lib/DSSignal.h', + 'src/lib/DSCallback.h', + 'src/lib/DSProperty.cpp', + 'src/lib/DSProperty.h', + 'src/lib/DSPropertyPrivate.h' +] + +pkgconfig = import('pkgconfig') +deps_libds = [] + +link_args = '-W' + +lib_libds = shared_library( + 'libds', + src_libds, + dependencies : deps_libds, + version : meson.project_version(), + link_args : link_args, + install : true + ) + +dep_libds = declare_dependency( + link_with : lib_libds, + dependencies : deps_libds, + include_directories : 'src/lib') + +pkgconfig.generate( + filebase : 'libds', + name : 'Libds', + description : 'DS library', + version : meson.project_version(), + libraries : lib_libds +) + +## For test-server + +path_test_server = dir_bin +#deps_test_server = [ dep_libds, dependency('libds') ] +src_test_server = [ + 'src/bin/sample1.cpp' +] + +executable('test-server', + src_test_server, + dependencies : dep_libds, + link_args : link_args, + install_dir : path_test_server, + install : true + ) + diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..e69de29 diff --git a/packaging/test-server.manifest b/packaging/test-server.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/test-server.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/test-server.spec b/packaging/test-server.spec new file mode 100644 index 0000000..0138e57 --- /dev/null +++ b/packaging/test-server.spec @@ -0,0 +1,58 @@ +Name: test-server +Version: 0.0.1 +Release: 0 +Summary: Test DS server +License: MIT +URL: http://www.tizen.org/ +Source: %name-%version.tar.xz +Source1001: %name.manifest + +BuildRequires: meson +BuildRequires: pkgconfig(glib-2.0) + +%description + +Test DS c++ server + +%package devel +Summary: Test DS c++ server +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + + +%description devel + +Test DS c++ server and lib + +%prep +%setup -q +cp %{SOURCE1001} . + +%build +meson setup \ + --prefix /usr \ + --libdir %{_libdir} \ + --bindir %{_bindir} \ + builddir +ninja -C builddir all + +%install +export DESTDIR=%{buildroot} +ninja -C builddir install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest %{name}.manifest +%defattr(-,root,root,-) +%{_libdir}/*.so.* +%{_bindir}/* + +%files devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%{_includedir}/* +%{_libdir}/*.so +%{_libdir}/pkgconfig/* -- 2.7.4