Redo Context class to use overridable virtual functions instead of
C-style callbacks. Note that this requires the memory callbacks to have a userdata pointer (so that we can pass the class instance). Also, the Context class has to be passed into the constructors for Connection and Stanza.
This commit is contained in:
24
strophepp.h
24
strophepp.h
@@ -4,11 +4,6 @@
|
|||||||
#include "strophe.h"
|
#include "strophe.h"
|
||||||
|
|
||||||
namespace XMPP {
|
namespace XMPP {
|
||||||
|
|
||||||
typedef void (*alloc_handler)(const size_t size);
|
|
||||||
typedef void (*free_handler)(void *p);
|
|
||||||
typedef void (*realloc_handler)(void *p const size_t size);
|
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
private:
|
private:
|
||||||
xmpp_ctx_t *ctx;
|
xmpp_ctx_t *ctx;
|
||||||
@@ -17,10 +12,15 @@ namespace XMPP {
|
|||||||
Context();
|
Context();
|
||||||
virtual ~Context();
|
virtual ~Context();
|
||||||
|
|
||||||
void setAlloc(alloc_handler handler);
|
virtual void *alloc(const size_t size) = 0;
|
||||||
void setRealloc(realloc_handler handler);
|
virtual void *realloc(void *p, const size_t size) = 0;
|
||||||
void setFree(free_handler handler);
|
virtual void free(void *p) = 0;
|
||||||
void setLogger(xmpp_log_handler handler, void * const userdata);
|
virtual void log(xmpp_log_handler handler, void * const userdata) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void *callAlloc(const size_t size, void *userdata);
|
||||||
|
static void *callRealloc(void *p, const size_t size, void *userdata);
|
||||||
|
static void *callFree(void *p, void *userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Connection {
|
class Connection {
|
||||||
@@ -28,9 +28,10 @@ namespace XMPP {
|
|||||||
xmpp_conn_t *conn;
|
xmpp_conn_t *conn;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Connection();
|
Connection(Context *ctx);
|
||||||
virtual ~Connection();
|
virtual ~Connection();
|
||||||
Connection *clone();
|
Connection *clone();
|
||||||
|
void operator delete(void *p);
|
||||||
|
|
||||||
const char *getJID();
|
const char *getJID();
|
||||||
void setJID(const char * const jid);
|
void setJID(const char * const jid);
|
||||||
@@ -63,8 +64,9 @@ namespace XMPP {
|
|||||||
xmpp_stanza_t *stanza;
|
xmpp_stanza_t *stanza;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Stanza();
|
Stanza(Context *ctx);
|
||||||
virtual ~Stanza();
|
virtual ~Stanza();
|
||||||
|
void operator delete(void *p);
|
||||||
Stanza *clone();
|
Stanza *clone();
|
||||||
Stanza *copy();
|
Stanza *copy();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user