[DEV] add a worker interface
This commit is contained in:
parent
7c4d4ff1dc
commit
942b3a155d
@ -21,6 +21,7 @@ ewol::object::Manager::Manager(ewol::Context& _context) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
ewol::object::Manager::~Manager() {
|
ewol::object::Manager::~Manager() {
|
||||||
|
m_workerList.clear();
|
||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
if (m_eObjectList.size()!=0) {
|
if (m_eObjectList.size()!=0) {
|
||||||
EWOL_ERROR("Must not have anymore eObject !!!");
|
EWOL_ERROR("Must not have anymore eObject !!!");
|
||||||
@ -44,6 +45,10 @@ void ewol::object::Manager::displayListObject() {
|
|||||||
|
|
||||||
void ewol::object::Manager::unInit() {
|
void ewol::object::Manager::unInit() {
|
||||||
EWOL_DEBUG(" == > Un-Init Object-Manager");
|
EWOL_DEBUG(" == > Un-Init Object-Manager");
|
||||||
|
if (m_workerList.size() > 0) {
|
||||||
|
EWOL_DEBUG(" == > Remove all workers");
|
||||||
|
m_workerList.clear();
|
||||||
|
}
|
||||||
for (auto &it : m_eObjectList) {
|
for (auto &it : m_eObjectList) {
|
||||||
std::shared_ptr<ewol::Object> element = it.lock();
|
std::shared_ptr<ewol::Object> element = it.lock();
|
||||||
if (element != nullptr) {
|
if (element != nullptr) {
|
||||||
@ -74,8 +79,7 @@ void ewol::object::Manager::cleanInternalRemoved() {
|
|||||||
auto it(m_eObjectList.begin());
|
auto it(m_eObjectList.begin());
|
||||||
while (it != m_eObjectList.end()) {
|
while (it != m_eObjectList.end()) {
|
||||||
if (it->expired() == true) {
|
if (it->expired() == true) {
|
||||||
m_eObjectList.erase(it);
|
it = m_eObjectList.erase(it);
|
||||||
it = m_eObjectList.begin();
|
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
@ -104,3 +108,18 @@ std::shared_ptr<ewol::Object> ewol::object::Manager::getObjectNamed(const std::s
|
|||||||
return ewol::object::Manager::get(_name);
|
return ewol::object::Manager::get(_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ewol::object::Manager::workerAdd(const std::shared_ptr<ewol::Object>& _worker) {
|
||||||
|
m_workerList.push_back(_worker);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::object::Manager::workerRemove(const std::shared_ptr<ewol::Object>& _worker) {
|
||||||
|
auto it(m_workerList.begin());
|
||||||
|
while (it != m_workerList.end()) {
|
||||||
|
if (*it == _worker) {
|
||||||
|
it = m_workerList.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -52,6 +52,19 @@ namespace ewol {
|
|||||||
* @return the requested object or nullptr
|
* @return the requested object or nullptr
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<ewol::Object> getObjectNamed(const std::string& _name);
|
std::shared_ptr<ewol::Object> getObjectNamed(const std::string& _name);
|
||||||
|
private:
|
||||||
|
std::vector<std::shared_ptr<ewol::Object>> m_workerList;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Add a worker on the system list.
|
||||||
|
* @param[in] _worker Worker to add in the list.
|
||||||
|
*/
|
||||||
|
void workerAdd(const std::shared_ptr<ewol::Object>& _worker);
|
||||||
|
/**
|
||||||
|
* @brief Remove a worker on the system list.
|
||||||
|
* @param[in] _worker Worker to add in the list.
|
||||||
|
*/
|
||||||
|
void workerRemove(const std::shared_ptr<ewol::Object>& _worker);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -85,7 +85,7 @@ namespace ewol {
|
|||||||
*/
|
*/
|
||||||
void autoDestroy();
|
void autoDestroy();
|
||||||
public:
|
public:
|
||||||
void destroy() {
|
virtual void destroy() {
|
||||||
autoDestroy();
|
autoDestroy();
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
@ -72,10 +72,12 @@ namespace ewol {
|
|||||||
* @param[in] _obj shared pointer on the removing object
|
* @param[in] _obj shared pointer on the removing object
|
||||||
*/
|
*/
|
||||||
void release(std::shared_ptr<ewol::Object> _obj) {
|
void release(std::shared_ptr<ewol::Object> _obj) {
|
||||||
for (auto it(m_callerList.begin()) ; it != m_callerList.end(); ++it) {
|
auto it(m_callerList.begin());
|
||||||
|
while(it != m_callerList.end()) {
|
||||||
if (it->first.lock() == _obj) {
|
if (it->first.lock() == _obj) {
|
||||||
m_callerList.erase(it);
|
it = m_callerList.erase(it);
|
||||||
it = m_callerList.begin();
|
} else {
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +86,15 @@ namespace ewol {
|
|||||||
* @param[in] _data data to emit
|
* @param[in] _data data to emit
|
||||||
*/
|
*/
|
||||||
void emit(const T& _data) {
|
void emit(const T& _data) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
int32_t tmpID = m_uidSignal++;
|
||||||
|
ewol::Object* srcObject = dynamic_cast<ewol::Object*>(&m_objectLink);
|
||||||
|
if (srcObject != nullptr) {
|
||||||
|
EWOL_DEBUG("emit signal{" << tmpID << "} : " << srcObject->getObjectType() << " signal='" << m_name << "' data='" << etk::to_string(_data) << "' to:");
|
||||||
|
} else {
|
||||||
|
EWOL_DEBUG("emit signal{" << tmpID << "} : signal='" << m_name << "' data='" << etk::to_string(_data) << "' to:");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
for (auto &it : m_callerList) {
|
for (auto &it : m_callerList) {
|
||||||
std::shared_ptr<ewol::Object> destObject = it.first.lock();
|
std::shared_ptr<ewol::Object> destObject = it.first.lock();
|
||||||
if (destObject == nullptr) {
|
if (destObject == nullptr) {
|
||||||
@ -92,11 +103,10 @@ namespace ewol {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
ewol::Object* srcObject = dynamic_cast<ewol::Object*>(&m_objectLink);
|
|
||||||
if (srcObject != nullptr) {
|
if (srcObject != nullptr) {
|
||||||
EWOL_DEBUG("emit signal : " << srcObject->getObjectType() << " '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " data='" << etk::to_string(_data) << "'");
|
EWOL_DEBUG(" signal{" << tmpID << "} : [" << destObject->getId() << "]" << destObject->getObjectType());
|
||||||
} else {
|
} else {
|
||||||
EWOL_DEBUG("emit signal : '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " data='" << etk::to_string(_data) << "'");
|
EWOL_DEBUG(" signal{" << tmpID << "} : [" << destObject->getId() << "]" << destObject->getObjectType());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
it.second(_data);
|
it.second(_data);
|
||||||
@ -157,14 +167,25 @@ namespace ewol {
|
|||||||
* @param[in] _obj shared pointer on the removing object
|
* @param[in] _obj shared pointer on the removing object
|
||||||
*/
|
*/
|
||||||
void release(std::shared_ptr<ewol::Object> _obj) {
|
void release(std::shared_ptr<ewol::Object> _obj) {
|
||||||
for (auto it(m_callerList.begin()) ; it != m_callerList.end(); ++it) {
|
auto it(m_callerList.begin());
|
||||||
|
while(it != m_callerList.end()) {
|
||||||
if (it->first.lock() == _obj) {
|
if (it->first.lock() == _obj) {
|
||||||
m_callerList.erase(it);
|
it = m_callerList.erase(it);
|
||||||
it = m_callerList.begin();
|
} else {
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void emit() {
|
void emit() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
int32_t tmpID = m_uidSignal++;
|
||||||
|
ewol::Object* srcObject = dynamic_cast<ewol::Object*>(&m_objectLink);
|
||||||
|
if (srcObject != nullptr) {
|
||||||
|
EWOL_DEBUG("emit signal{" << tmpID << "} : " << srcObject->getObjectType() << " signal='" << m_name << "' BANG!!! to:");
|
||||||
|
} else {
|
||||||
|
EWOL_DEBUG("emit signal{" << tmpID << "} : signal='" << m_name << "' to:");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
for (auto &it : m_callerList) {
|
for (auto &it : m_callerList) {
|
||||||
std::shared_ptr<ewol::Object> destObject = it.first.lock();
|
std::shared_ptr<ewol::Object> destObject = it.first.lock();
|
||||||
if (destObject == nullptr) {
|
if (destObject == nullptr) {
|
||||||
@ -173,11 +194,10 @@ namespace ewol {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
ewol::Object* srcObject = dynamic_cast<ewol::Object*>(&m_objectLink);
|
|
||||||
if (srcObject != nullptr) {
|
if (srcObject != nullptr) {
|
||||||
EWOL_DEBUG("emit signal : " << srcObject->getObjectType() << " '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " BANG!!!");
|
EWOL_DEBUG(" signal{" << tmpID << "} : [" << destObject->getId() << "]" << destObject->getObjectType());
|
||||||
} else {
|
} else {
|
||||||
EWOL_DEBUG("emit signal : '" << m_name << "' to [" << destObject->getId() << "]" << destObject->getObjectType() << " BANG!!!");
|
EWOL_DEBUG(" signal{" << tmpID << "} : [" << destObject->getId() << "]" << destObject->getObjectType());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
it.second();
|
it.second();
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <ewol/object/SignalList.h>
|
#include <ewol/object/SignalList.h>
|
||||||
#include <ewol/object/SignalBase.h>
|
#include <ewol/object/SignalBase.h>
|
||||||
|
|
||||||
|
int32_t ewol::object::SignalBase::m_uidSignal = 0;
|
||||||
ewol::object::SignalBase::SignalBase(ewol::object::SignalList& _objectLink,
|
ewol::object::SignalBase::SignalBase(ewol::object::SignalList& _objectLink,
|
||||||
const std::string& _name,
|
const std::string& _name,
|
||||||
const std::string& _description) :
|
const std::string& _description) :
|
||||||
|
@ -21,6 +21,7 @@ namespace ewol {
|
|||||||
ewol::object::SignalList& m_objectLink;
|
ewol::object::SignalList& m_objectLink;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
std::string m_description;
|
std::string m_description;
|
||||||
|
static int32_t m_uidSignal;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Create a parameter with a specific type.
|
* @brief Create a parameter with a specific type.
|
||||||
|
34
sources/ewol/object/Worker.cpp
Normal file
34
sources/ewol/object/Worker.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ewol/debug.h>
|
||||||
|
#include <ewol/object/Worker.h>
|
||||||
|
#include <ewol/object/Manager.h>
|
||||||
|
|
||||||
|
ewol::object::Worker::Worker() {
|
||||||
|
addObjectType("ewol::Worker");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::object::Worker::init() {
|
||||||
|
ewol::Object::init();
|
||||||
|
getObjectManager().workerAdd(shared_from_this());
|
||||||
|
}
|
||||||
|
//! @previous
|
||||||
|
void ewol::object::Worker::init(const std::string& _name) {
|
||||||
|
ewol::Object::init(_name);
|
||||||
|
getObjectManager().workerAdd(shared_from_this());
|
||||||
|
}
|
||||||
|
|
||||||
|
ewol::object::Worker::~Worker() {
|
||||||
|
// nothing to do ...
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::object::Worker::destroy() {
|
||||||
|
ewol::Object::destroy();
|
||||||
|
getObjectManager().workerRemove(shared_from_this());
|
||||||
|
}
|
44
sources/ewol/object/Worker.h
Normal file
44
sources/ewol/object/Worker.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __EWOL_WORKER_H__
|
||||||
|
#define __EWOL_WORKER_H__
|
||||||
|
|
||||||
|
#include <ewol/debug.h>
|
||||||
|
#include <ewol/object/Object.h>
|
||||||
|
|
||||||
|
namespace ewol {
|
||||||
|
namespace object {
|
||||||
|
/**
|
||||||
|
* @brief A worker might not been possesed by someone, then the system might keep a pointer on it.
|
||||||
|
*/
|
||||||
|
class Worker : public ewol::Object {
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Constructor.
|
||||||
|
*/
|
||||||
|
Worker();
|
||||||
|
void init();
|
||||||
|
//! @previous
|
||||||
|
void init(const std::string& _name);
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Factory
|
||||||
|
*/
|
||||||
|
DECLARE_FACTORY(Worker);
|
||||||
|
/**
|
||||||
|
* @brief Destructor
|
||||||
|
*/
|
||||||
|
virtual ~Worker();
|
||||||
|
public:
|
||||||
|
virtual void destroy();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -90,6 +90,7 @@ def create(target):
|
|||||||
myModule.add_src_file([
|
myModule.add_src_file([
|
||||||
'ewol/object/Manager.cpp',
|
'ewol/object/Manager.cpp',
|
||||||
'ewol/object/Object.cpp',
|
'ewol/object/Object.cpp',
|
||||||
|
'ewol/object/Worker.cpp',
|
||||||
'ewol/object/Parameter.cpp',
|
'ewol/object/Parameter.cpp',
|
||||||
'ewol/object/ParameterList.cpp',
|
'ewol/object/ParameterList.cpp',
|
||||||
'ewol/object/ParamList.cpp',
|
'ewol/object/ParamList.cpp',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user