Commit 53eaca81 authored by Nicolas Michon's avatar Nicolas Michon

bellesip::Object marshalling now uses virtual toString() for easier debug and leaks analysis

parent d55bac08
...@@ -43,11 +43,8 @@ class BELLESIP_EXPORT Object { ...@@ -43,11 +43,8 @@ class BELLESIP_EXPORT Object {
Object(); Object();
Object *ref(); Object *ref();
void unref(); void unref();
virtual belle_sip_error_code marshal(char* buff, size_t buff_size, size_t *offset); //Overrides should keep the size of toString() lower than BELLE_SIP_MAX_TO_STRING_SIZE
std::string toString()const{ virtual std::string toString() const;
std::string ret(belle_sip_object_to_string(&mObject));
return ret;
}
virtual Object *clone()const; virtual Object *clone()const;
belle_sip_cpp_object_t *getCObject(); belle_sip_cpp_object_t *getCObject();
const belle_sip_cpp_object_t *getCObject()const; const belle_sip_cpp_object_t *getCObject()const;
...@@ -66,8 +63,7 @@ class BELLESIP_EXPORT Object { ...@@ -66,8 +63,7 @@ class BELLESIP_EXPORT Object {
private: private:
void init(); void init();
belle_sip_cpp_object_t mObject; belle_sip_cpp_object_t mObject;
static belle_sip_cpp_object_t *sClone(belle_sip_cpp_object_t *); belle_sip_error_code marshal(char* buff, size_t buff_size, size_t *offset);
static belle_sip_error_code sMarshal(belle_sip_cpp_object_t* obj, char* buff, size_t buff_size, size_t *offset);
}; };
/** /**
......
...@@ -69,11 +69,25 @@ void Object::unref(){ ...@@ -69,11 +69,25 @@ void Object::unref(){
belle_sip_object_unref(&mObject); belle_sip_object_unref(&mObject);
} }
std::string Object::toString() const {
std::ostringstream ss;
ss << "bellesip::Object. cObject(";
ss << static_cast<const void *>(&mObject);
ss << ")";
return ss.str();
}
belle_sip_error_code Object::marshal(char* buff, size_t buff_size, size_t *offset){ belle_sip_error_code Object::marshal(char* buff, size_t buff_size, size_t *offset){
return mObject.vptr->get_parent()->marshal(&mObject, buff, buff_size, offset); /*default to belle_sip_object_t's implementation*/ std::string tmp = toString();
if (tmp.size() >= buff_size) {
return BELLE_SIP_BUFFER_OVERFLOW;
}
strncpy(buff, tmp.c_str(), buff_size);
*offset += tmp.size();
return BELLE_SIP_OK;
} }
Object *Object::clone()const{ Object *Object::clone() const {
return new Object(*this); return new Object(*this);
} }
......
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