From: MinJeong Kim Date: Tue, 18 Feb 2020 08:04:25 +0000 (+0900) Subject: Use prefix to 'DS' X-Git-Tag: accepted/tizen/unified/20200820.213435~400 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=201b2dd1b303c33663ad159a7779170d1016a318;p=platform%2Fcore%2Fuifw%2Flibds.git Use prefix to 'DS' Change-Id: Ib78ae073b7e6782c56a3b182c44f80e603b01b8a Signed-off-by: MinJeong Kim --- 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 */