[DEV] correction of virtual and refcounter of objects

This commit is contained in:
Edouard DUPIN 2014-05-27 21:26:40 +02:00
parent c2eb3c1467
commit 3237d26474
35 changed files with 154 additions and 102 deletions

2
external/airtaudio vendored

@ -1 +1 @@
Subproject commit bb547a72d99802ac5d9a99c843549f175c856826
Subproject commit b0eb151df0802a1d63a5cb6b6812a4460ddd09a1

2
external/egami vendored

@ -1 +1 @@
Subproject commit bb58a8c06e30cf141a59f8a09a544919c1f695ed
Subproject commit 34eac48f5114151bab137e9cb177513c7cf42d96

View File

@ -65,7 +65,7 @@ namespace ewol {
/**
* @brief Destructor
*/
~Dimension();
virtual ~Dimension();
/**
* @brief string cast :

View File

@ -47,7 +47,7 @@ namespace ewol {
/**
* @brief generic destructor
*/
~Area();
virtual ~Area();
public:
/**
* @brief draw All the refistered text in the current element on openGL

View File

@ -43,7 +43,7 @@ namespace ewol {
/**
* @brief Basic destructor
*/
~Drawing();
virtual ~Drawing();
private:
/**
* @brief load the openGL program and get all the ID needed

View File

@ -101,7 +101,7 @@ namespace ewol {
/**
* @brief generic destructor
*/
~Shaper();
virtual ~Shaper();
public:
/**
* @brief draw All the refistered text in the current element on openGL

View File

@ -19,7 +19,7 @@ namespace ewol {
* Constructor / destructor
*/
ConfigFont();
~ConfigFont();
virtual ~ConfigFont();
private:
std::string m_folder;
public:

View File

@ -17,7 +17,6 @@
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/
@interface OpenglView : UIView {
@private
CAEAGLLayer* _eaglLayer;

View File

@ -112,6 +112,7 @@ void ewol::object::Manager::remove(const ewol::object::Shared<ewol::Object>& _ob
EWOL_ERROR("Try to Auto-Remove (nullptr) Object");
return;
}
int32_t count = 0;
auto it(m_eObjectListActive.begin());
while (it != m_eObjectListActive.end()) {
if (*it == _object) {
@ -120,13 +121,19 @@ void ewol::object::Manager::remove(const ewol::object::Shared<ewol::Object>& _ob
EWOL_DEBUG("Auto-Remove Object : [" << _object->getId() << "] type='" << _object->getObjectType() << "' name=" << _object->getName());
informOneObjectIsRemoved(_object);
ewol::getContext().forceRedrawAll();
EWOL_DEBUG("Auto-Remove Object ... done (have " << _object->getRefCount() << " references)");
EWOL_VERBOSE("Auto-Remove Object ... done (have " << _object->getRefCount() << " references)");
it = m_eObjectListActive.begin();
count++;
} else {
++it;
}
}
if (count == 0) {
EWOL_ERROR("Try to Auto-Remove Object that is not referenced ...");
} else if ( count>1
|| count<0) {
EWOL_ERROR("Remove more than one object in the system list ==> this is a real problem ...");
}
}
// clean all Object that request an autoRemove ...

View File

@ -25,7 +25,7 @@ namespace ewol {
Context& m_context;
public:
Manager(Context& _context);
~Manager();
virtual ~Manager();
/**
* @brief remove all resources (un-init) out of the destructor (due to the system implementation)
*/

View File

@ -32,7 +32,7 @@ namespace ewol {
std::vector<MessageList> m_messageList; //!< List of all message ...
public:
MultiCast();
~MultiCast();
virtual ~MultiCast();
void clear();
void anonymousSend(const char* const _messageId, const std::string& _data) {
send(nullptr, _messageId, _data);

View File

@ -59,18 +59,40 @@ void ewol::Object::operator delete[](void* _ptr, std::size_t _sz) {
EWOL_CRITICAL("custom delete for size ==> not implemented ..." << _sz);
::operator delete(_ptr);
}
#ifdef DEBUG
void ewol::Object::incOwnerCount() {
std::unique_lock<std::mutex> lock(m_lockRefCount);
m_ownerCount++;
if (m_ownerCount>1) {
EWOL_CRITICAL("Multiple Owner on one Object ==> very bad ... " << m_ownerCount);
}
}
void ewol::Object::decOwnerCount() {
std::unique_lock<std::mutex> lock(m_lockRefCount);
m_ownerCount--;
if (m_ownerCount<0) {
EWOL_CRITICAL("Owner remove the owner counter under 1 ==> very bad ... " << m_ownerCount);
}
}
#endif
void ewol::Object::autoDestroy() {
EWOL_VERBOSE("Destroy object : [" << getId() << "] type:" << getObjectType());
bool needRemove = false;
{
std::unique_lock<std::mutex> lock(m_lockRefCount);
if (m_isDestroyed == true) {
EWOL_WARNING("Request remove of a removed object");
return;
}
} else {
m_isDestroyed = true;
needRemove = true;
}
}
if (needRemove == true) {
getObjectManager().remove(this);
}
}
void ewol::Object::removeObject() {
@ -89,6 +111,9 @@ void ewol::Object::respownObject() {
ewol::Object::Object() :
m_objRefCount(1),
#ifdef DEBUG
m_ownerCount(0),
#endif
m_isDestroyed(false),
m_static(false),
m_isResource(false) {
@ -100,6 +125,9 @@ ewol::Object::Object() :
}
ewol::Object::Object(const std::string& _name) :
m_objRefCount(1),
#ifdef DEBUG
m_ownerCount(0),
#endif
m_isDestroyed(false),
m_static(false),
m_name(_name),
@ -114,12 +142,6 @@ ewol::Object::Object(const std::string& _name) :
ewol::Object::~Object() {
EWOL_DEBUG("delete Object : [" << m_uniqueId << "] : " << getTypeDescription() << " refcount=" << m_objRefCount);
getMultiCast().rm(this);
for (size_t iii=0; iii<m_externEvent.size(); ++iii) {
if (m_externEvent[iii] != nullptr) {
delete(m_externEvent[iii]);
m_externEvent[iii] = nullptr;
}
}
m_externEvent.clear();
m_availlableEventId.clear();
m_uniqueId = -1;
@ -161,7 +183,13 @@ bool ewol::Object::isTypeCompatible(const std::string& _type) {
}
void ewol::Object::addEventId(const char * _generateEventId) {
if (nullptr != _generateEventId) {
for (auto &it : m_availlableEventId) {
if (std::string(it) == _generateEventId) {
EWOL_WARNING("Event already existed : '" << it << "' == '" << _generateEventId << "'");
return;
}
}
if (_generateEventId != nullptr) {
m_availlableEventId.push_back(_generateEventId);
}
}
@ -170,29 +198,25 @@ void ewol::Object::generateEventId(const char * _generateEventId, const std::str
int32_t nbObject = getObjectManager().getNumberObject();
EWOL_VERBOSE("try send message '" << _generateEventId << "'");
// for every element registered ...
for (size_t iii=0; iii<m_externEvent.size(); ++iii) {
if (nullptr==m_externEvent[iii]) {
EWOL_VERBOSE(" Null pointer");
continue;
}
for (auto &it : m_externEvent) {
// if we find the event ...
if (m_externEvent[iii]->localEventId != _generateEventId) {
EWOL_VERBOSE(" wrong event '" << m_externEvent[iii]->localEventId << "' != '" << _generateEventId << "'");
if (it.localEventId != _generateEventId) {
EWOL_VERBOSE(" wrong event '" << it.localEventId << "' != '" << _generateEventId << "'");
continue;
}
if (m_externEvent[iii]->destObject == nullptr) {
if (it.destObject == nullptr) {
EWOL_VERBOSE(" nullptr dest");
continue;
}
if (m_externEvent[iii]->overloadData.size() <= 0){
ewol::object::Message tmpMsg(this, m_externEvent[iii]->destEventId, _data);
if (it.overloadData.size() <= 0){
ewol::object::Message tmpMsg(this, it.destEventId, _data);
EWOL_VERBOSE("send message " << tmpMsg);
m_externEvent[iii]->destObject->onReceiveMessage(tmpMsg);
it.destObject->onReceiveMessage(tmpMsg);
} else {
// set the user requested data ...
ewol::object::Message tmpMsg(this, m_externEvent[iii]->destEventId, m_externEvent[iii]->overloadData);
ewol::object::Message tmpMsg(this, it.destEventId, it.overloadData);
EWOL_VERBOSE("send message " << tmpMsg);
m_externEvent[iii]->destObject->onReceiveMessage(tmpMsg);
it.destObject->onReceiveMessage(tmpMsg);
}
}
if (nbObject > getObjectManager().getNumberObject()) {
@ -227,19 +251,15 @@ void ewol::Object::registerOnEvent(const ewol::object::Shared<ewol::Object>& _de
if ( _eventId[0] == '*'
&& _eventId[1] == '\0') {
EWOL_VERBOSE("Register on all event ...");
for(size_t iii=0; iii<m_availlableEventId.size(); iii++) {
ewol::object::EventExtGen * tmpEvent = new ewol::object::EventExtGen();
if (nullptr == tmpEvent) {
EWOL_ERROR("Allocation error in Register Event...");
continue;
}
tmpEvent->localEventId = m_availlableEventId[iii];
tmpEvent->destObject = _destinationObject;
tmpEvent->overloadData = _overloadData;
for(auto &it : m_availlableEventId) {
ewol::object::EventExtGen tmpEvent;
tmpEvent.localEventId = it;
tmpEvent.destObject = _destinationObject;
tmpEvent.overloadData = _overloadData;
if (nullptr != _eventIdgenerated) {
tmpEvent->destEventId = _eventIdgenerated;
tmpEvent.destEventId = _eventIdgenerated;
} else {
tmpEvent->destEventId = m_availlableEventId[iii];
tmpEvent.destEventId = it;
}
m_externEvent.push_back(tmpEvent);
}
@ -247,18 +267,18 @@ void ewol::Object::registerOnEvent(const ewol::object::Shared<ewol::Object>& _de
}
// check if event existed :
bool findIt = false;
for(size_t iii=0; iii<m_availlableEventId.size(); iii++) {
if (m_availlableEventId[iii] == _eventId) {
for(auto &it : m_availlableEventId) {
if (it == _eventId) {
findIt = true;
break;
}
}
if (false == findIt) {
EWOL_VERBOSE("Try to register with a NON direct string name");
for(size_t iii=0; iii<m_availlableEventId.size(); iii++) {
if (0 == strncmp(m_availlableEventId[iii], _eventId, 1024)) {
for(auto &it : m_availlableEventId) {
if (0 == strncmp(it, _eventId, 1024)) {
findIt = true;
_eventId = m_availlableEventId[iii];
_eventId = it;
EWOL_VERBOSE("find event ID : '" << _eventId << "' ==> '" << _eventIdgenerated << "'");
break;
}
@ -268,50 +288,54 @@ void ewol::Object::registerOnEvent(const ewol::object::Shared<ewol::Object>& _de
EWOL_ERROR("Can not register event on this Type=" << getObjectType() << " event=\"" << _eventId << "\" == > unknow event");
return;
}
ewol::object::EventExtGen * tmpEvent = new ewol::object::EventExtGen();
if (nullptr == tmpEvent) {
EWOL_ERROR("Allocation error in Register Event...");
return;
}
tmpEvent->localEventId = _eventId;
tmpEvent->destObject = _destinationObject;
tmpEvent->overloadData = _overloadData;
ewol::object::EventExtGen tmpEvent;
tmpEvent.localEventId = _eventId;
tmpEvent.destObject = _destinationObject;
tmpEvent.overloadData = _overloadData;
if (nullptr != _eventIdgenerated) {
tmpEvent->destEventId = _eventIdgenerated;
tmpEvent.destEventId = _eventIdgenerated;
} else {
tmpEvent->destEventId = _eventId;
tmpEvent.destEventId = _eventId;
}
m_externEvent.push_back(tmpEvent);
}
void ewol::Object::unRegisterOnEvent(const ewol::object::Shared<ewol::Object>& _destinationObject,
const char * _eventId) {
if (nullptr == _destinationObject) {
if (_destinationObject == nullptr) {
EWOL_ERROR("Input ERROR nullptr pointer Object ...");
return;
}
// check if event existed :
for(int64_t iii = m_externEvent.size()-1; iii >= 0; --iii) {
if (m_externEvent[iii] == nullptr) {
continue;
}
if (m_externEvent[iii]->destObject != _destinationObject) {
continue;
}
if (_eventId == nullptr) {
m_externEvent.erase(m_externEvent.begin()+iii);
} else if (m_externEvent[iii]->localEventId == _eventId) {
m_externEvent.erase(m_externEvent.begin()+iii);
auto it(m_externEvent.begin());
while(it != m_externEvent.end()) {
if (it->destObject == nullptr) {
m_externEvent.erase(it);
it = m_externEvent.begin();
} else if ( it->destObject == _destinationObject
&& it->localEventId == _eventId) {
m_externEvent.erase(it);
it = m_externEvent.begin();
EWOL_INFO("[" << getId() << "] Remove extern event : to object id=" << _destinationObject->getId() << " event=" << _eventId);
} else {
++it;
}
}
}
void ewol::Object::onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) {
EWOL_VERBOSE("[" << getId() << "] onObjectRemove(" << _object->getId() << ")");
for(int32_t iii=m_externEvent.size()-1; iii >= 0; iii--) {
if (m_externEvent[iii] != nullptr) {
m_externEvent.erase(m_externEvent.begin()+iii);
EWOL_VERBOSE("[" << getId() << "] Remove extern event : to object id=" << _object->getId());
auto it(m_externEvent.begin());
while(it != m_externEvent.end()) {
if (it->destObject == nullptr) {
m_externEvent.erase(it);
it = m_externEvent.begin();
} else if (it->destObject == _object) {
m_externEvent.erase(it);
it = m_externEvent.begin();
EWOL_INFO("[" << getId() << "] Remove extern event : to object id=" << _object->getId());
} else {
++it;
}
}
}

View File

@ -69,6 +69,12 @@ namespace ewol {
static void operator delete(void* _ptr, std::size_t _sz);
//! @not-in-doc
static void operator delete[](void* _ptr, std::size_t _sz);
#ifdef DEBUG
public:
int32_t m_ownerCount;
void incOwnerCount();
void decOwnerCount();
#endif
private:
static size_t m_valUID; //!< stic used for the unique ID definition
public:
@ -157,7 +163,7 @@ namespace ewol {
return m_uniqueId;
};
private:
std::vector<object::EventExtGen*> m_externEvent; //!< Generic list of event generation for output link
std::vector<object::EventExtGen> m_externEvent; //!< Generic list of event generation for output link
std::vector<const char*> m_availlableEventId; //!< List of all event availlable for this widget
protected:
/**

View File

@ -54,6 +54,9 @@ namespace ewol {
return;
}
m_pointer->objRefCountIncrement();
#ifdef DEBUG
m_pointer->incOwnerCount();
#endif
}
template<typename T2, typename = typename
std::enable_if<std::is_convertible<T*, T2*>::value>::type>
@ -65,6 +68,9 @@ namespace ewol {
m_pointer = _obj.get();
if (m_pointer != nullptr) {
m_pointer->objRefCountIncrement();
#ifdef DEBUG
m_pointer->incOwnerCount();
#endif
}
return *this;
}
@ -75,6 +81,9 @@ namespace ewol {
m_pointer = _obj.get();
if (m_pointer != nullptr) {
m_pointer->objRefCountIncrement();
#ifdef DEBUG
m_pointer->incOwnerCount();
#endif
}
return *this;
}
@ -95,6 +104,9 @@ namespace ewol {
delete tmp;
} else {
tmp->objRefCountDecrement();
#ifdef DEBUG
tmp->decOwnerCount();
#endif
}
}
void resetShared() {
@ -111,6 +123,9 @@ namespace ewol {
delete tmp;
} else {
tmp->objRefCountDecrement();
#ifdef DEBUG
tmp->decOwnerCount();
#endif
}
}
T* get() noexcept {

View File

@ -19,7 +19,7 @@ namespace ewol {
virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _object) = 0;
public:
RemoveEvent();
~RemoveEvent();
virtual ~RemoveEvent();
};
}
};

View File

@ -48,7 +48,7 @@ void ewol::resource::ColorFile::reload() {
EWOL_ERROR("Can not get basic array : 'color'");
return;
}
for (int32_t iii = 0; iii < baseArray->size(); ++iii) {
for (size_t iii = 0; iii < baseArray->size(); ++iii) {
ejson::Object* tmpObj = baseArray->getObject(iii);
if (tmpObj == nullptr) {
EWOL_DEBUG(" can not get object in 'color' id=" << iii);

View File

@ -29,7 +29,7 @@ ewol::resource::ConfigFile::ConfigFile(const std::string& _filename) :
ewol::resource::ConfigFile::~ConfigFile() {
// remove all element
for (size_t iii=0; iii<m_list.size(); iii++){
for (int32_t iii=0; iii<m_list.size(); iii++){
if (nullptr != m_list[iii]) {
delete(m_list[iii]);
m_list[iii] = nullptr;
@ -40,7 +40,7 @@ ewol::resource::ConfigFile::~ConfigFile() {
void ewol::resource::ConfigFile::reload() {
// reset all parameters
for (size_t iii=0; iii<m_list.size(); iii++){
for (int32_t iii=0; iii<m_list.size(); iii++){
if (nullptr != m_list[iii]) {
m_list[iii] = nullptr;
}

View File

@ -33,7 +33,7 @@ namespace ewol {
protected:
DistanceFieldFont(const std::string& _fontName);
public:
~DistanceFieldFont();
virtual ~DistanceFieldFont();
public:
float getDisplayRatio(float _size);
/**

View File

@ -31,7 +31,7 @@ namespace ewol {
protected:
FontFreeType(const std::string& _fontName);
public:
~FontFreeType();
virtual ~FontFreeType();
public:
bool getGlyphProperty(int32_t _fontSize,

View File

@ -186,6 +186,7 @@ bool ewol::resource::Manager::checkResourceToRemove() {
if ((*it)->getRefCount() > 3) {
continue;
}
EWOL_DEBUG("Request remove of an resource (refcount in Low : " << (*it)->getRefCount() << ")");
m_resourceList.erase(it);
it = m_resourceList.begin();
return true;

View File

@ -32,7 +32,7 @@ namespace ewol {
* @brief Uninitiamize the resource manager, free all resources previously requested
* @note when not free == > generate warning, because the segfault can appear after...
*/
~Manager();
virtual ~Manager();
/**
* @brief remove all resources (un-init) out of the destructor (due to the system implementation)
*/

View File

@ -48,7 +48,7 @@ namespace ewol {
Texture(const std::string& _filename);
Texture();
public:
~Texture();
virtual ~Texture();
public:
// you must set the size here, because it will be set in multiple of pow(2)
void setImageSize(ivec2 newSize);

View File

@ -47,7 +47,7 @@ namespace ewol {
protected:
TexturedFont(const std::string& _fontName);
public:
~TexturedFont();
virtual ~TexturedFont();
public:
/**
* @brief get the display height of this font

View File

@ -40,7 +40,7 @@ namespace ewol {
/**
* @brief Destructor
*/
~Composer();
virtual ~Composer();
/**
* @brief load a composition with a file
* @param[in] _fileName Name of the file

View File

@ -30,7 +30,7 @@ namespace ewol {
/**
* @brief Destructor
*/
~Container();
virtual ~Container();
public:
/**
* @brief get the main node widget

View File

@ -34,7 +34,7 @@ namespace ewol {
/**
* @brief Destructor
*/
~Container2();
virtual ~Container2();
private:
/**
* @brief Specify the current widget

View File

@ -31,7 +31,7 @@ namespace ewol {
/**
* @brief Destructor
*/
~ContainerN();
virtual ~ContainerN();
protected:
bvec2 m_lockExpand; //!< Lock the expend of the sub widget to this one == > this permit to limit bigger subWidget
bvec2 m_subExpend; //!< reference of the sub element expention requested.

View File

@ -37,7 +37,7 @@ namespace ewol {
// TODO : Add a standalone configuration ..
public:
ListFileSystem();
~ListFileSystem();
virtual ~ListFileSystem();
protected:
ewol::object::Shared<ewol::resource::ColorFile> m_colorProperty; //!< theme color property.
int32_t m_colorIdText; //!< Color of the text.

View File

@ -33,7 +33,7 @@ namespace ewol {
int64_t m_lastPeriodicCallTime; //!< last call time ...
public:
Manager();
~Manager();
virtual ~Manager();
void focusKeep(const ewol::object::Shared<ewol::Widget>& _newWidget); // set the focus at the specific widget
void focusSetDefault(const ewol::object::Shared<ewol::Widget>& _newWidget); // select the default focus getter

View File

@ -106,7 +106,7 @@ namespace ewol {
unicodeValue = 0;
keyboardMoveValue = ewol::key::keyboardUnknow;
};
~EventShortCut() { };
virtual ~EventShortCut() { };
};
/**
* @brief Widget class is the main widget interface, it hase some generic properties:

View File

@ -30,7 +30,7 @@ namespace ewol {
static const char * const eventChange;
public:
ColorChooser();
~ColorChooser();
virtual ~ColorChooser();
public: // Derived function
virtual void onReceiveMessage(const ewol::object::Message& _msg);
virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject);

View File

@ -32,7 +32,7 @@ namespace ewol {
static const char * const eventClose;
public:
Parameter();
~Parameter();
virtual ~Parameter();
public: // Derived function
virtual void onReceiveMessage(const ewol::object::Message& _msg);
virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject);

View File

@ -30,7 +30,7 @@ namespace ewol {
m_image(_image) {
};
~elementPL() {};
virtual ~elementPL() {};
};
/**

View File

@ -48,7 +48,7 @@ namespace ewol {
/**
* @brief std-pop-up destructor.
*/
~StdPopUp();
virtual ~StdPopUp();
protected:
ewol::object::Shared<ewol::widget::Label> m_title; //!< Title Label widget
public:

View File

@ -17,7 +17,7 @@ def create(target):
myModule = module.Module(__file__, 'ewol', 'LIBRARY')
# add extra compilation flags :
#myModule.add_extra_compile_flags()
myModule.add_extra_compile_flags()
# add the file to compile:
myModule.add_src_file([
'ewol/ewol.cpp',