Commit 2784a2f5 authored by Ronan's avatar Ronan

fix(wrappers): cpp Listener is now virtual (avoid memory leak)

parent ba9ecd30
Pipeline #248 failed with stage
in 0 seconds
......@@ -46,12 +46,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#endif
namespace linphone {
class Object: public std::enable_shared_from_this<Object> {
public:
Object(void *ptr, bool takeRef=true);
virtual ~Object();
public:
template <class T>
void setData(const std::string &key, T &data) {
......@@ -70,7 +70,7 @@ namespace linphone {
}
LINPHONECXX_PUBLIC void unsetData(const std::string &key);
LINPHONECXX_PUBLIC bool dataExists(const std::string &key);
public:
template <class T>
static std::shared_ptr<T> cPtrToSharedPtr(void *ptr, bool takeRef=true) {
......@@ -100,58 +100,61 @@ namespace linphone {
}
static void *sharedPtrToCPtr(const std::shared_ptr<const Object> &sharedPtr);
private:
LINPHONECXX_PUBLIC std::map<std::string,void *> &getUserData() const;
static Object *getBackPtrFromCPtr(const void *ptr);
template <class T> static void deleteSharedPtr(std::shared_ptr<T> *ptr) {if (ptr != NULL) delete ptr;}
static void deleteString(std::string *str) {if (str != NULL) delete str;}
protected:
void *mPrivPtr;
private:
static const std::string sUserDataKey;
};
class Listener {};
class Listener {
public:
virtual ~Listener() = 0;
};
class ListenableObject: public Object {
protected:
ListenableObject(void *ptr, bool takeRef=true);
void setListener(const std::shared_ptr<Listener> &listener);
public:
static std::shared_ptr<Listener> & getListenerFromObject(void *object);
private:
static void deleteListenerPtr(std::shared_ptr<Listener> *ptr) {delete ptr;}
private:
static std::string sListenerDataName;
};
class MultiListenableObject: public Object {
friend class Factory;
protected:
MultiListenableObject(void *ptr, bool takeRef=true);
virtual ~MultiListenableObject() {};
protected:
void addListener(const std::shared_ptr<Listener> &listener);
void removeListener(const std::shared_ptr<Listener> &listener);
std::list<std::shared_ptr<Listener> > &getListeners() const;
private:
static void deleteListenerList(std::list<std::shared_ptr<Listener> > *listeners) {delete listeners;}
private:
static std::string sListenerListName;
};
};
#endif // _LINPHONE_OBJECT_HH
......@@ -27,18 +27,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "object.hh"
namespace linphone {
class AbstractBctbxListWrapper {
public:
AbstractBctbxListWrapper(): mCList(NULL) {}
virtual ~AbstractBctbxListWrapper() {}
::bctbx_list_t *c_list() {return mCList;}
protected:
::bctbx_list_t *mCList;
};
template <class T>
class ObjectBctbxListWrapper: public AbstractBctbxListWrapper {
public:
......@@ -72,22 +72,22 @@ namespace linphone {
}
return cList;
}
private:
static void unrefData(void *data) {
if (data != NULL) belle_sip_object_unref(data);
}
};
class StringBctbxListWrapper: public AbstractBctbxListWrapper {
public:
StringBctbxListWrapper(const std::list<std::string> &cppList);
virtual ~StringBctbxListWrapper();
static std::list<std::string> bctbxListToCppList(const ::bctbx_list_t *bctbxList);
};
template <class T, class U>
class StructBctbxListWrapper: public AbstractBctbxListWrapper {
public:
......@@ -111,11 +111,11 @@ namespace linphone {
}
return cList;
}
private:
static void deleteCStruct(U *cStruct) {delete cStruct;}
};
class StringUtilities {
public:
static std::string cStringToCpp(const char *cstr);
......@@ -123,7 +123,7 @@ namespace linphone {
static const char *cppStringToC(const std::string &cppstr);
static std::list<std::string> cStringArrayToCppList(const char **cArray);
};
template <class T>
class StructWrapper {
public:
......@@ -133,7 +133,7 @@ namespace linphone {
const void *ptr() const {
return &mStruct;
}
private:
T mStruct;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment