From 36adc76235fb0a38e7042bc751f988b71627e2a0 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 11 Dec 2012 06:13:02 +0000 Subject: Changes to get successful C++11 based build. Code cleanup, dependency upgrades, and const + inline optimizations in components, samples, and app hosting server. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1420007 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/components/chat/xmpp.hpp | 73 +++++++++++++++------------------- 1 file changed, 31 insertions(+), 42 deletions(-) (limited to 'sca-cpp/trunk/components/chat/xmpp.hpp') diff --git a/sca-cpp/trunk/components/chat/xmpp.hpp b/sca-cpp/trunk/components/chat/xmpp.hpp index aa006029fa..88174613a0 100644 --- a/sca-cpp/trunk/components/chat/xmpp.hpp +++ b/sca-cpp/trunk/components/chat/xmpp.hpp @@ -66,8 +66,8 @@ private: */ class XMPPClient { public: - XMPPClient(const string& jid, const string& pass, bool owner = true) : owner(owner), ctx(xmpp_ctx_new(NULL, xmppRuntime.log)), conn(xmpp_conn_new(ctx)), connecting(false), connected(false), disconnecting(false) { - xmpp_conn_set_jid(conn, c_str(jid + "/" + mkuuid())); + XMPPClient(const string& jid, const string& pass, const bool owner = true) : owner(owner), ctx(xmpp_ctx_new(NULL, xmppRuntime.log)), conn(xmpp_conn_new(ctx)), connecting(false), connected(false), disconnecting(false) { + xmpp_conn_set_jid(conn, c_str(jid + "/" + (string)mkuuid())); xmpp_conn_set_pass(conn, c_str(pass)); debug(jid, "chat::xmppclient::jid"); } @@ -76,19 +76,7 @@ public: debug("chat::xmppclient::copy"); } - const XMPPClient& operator=(const XMPPClient& xc) { - debug("chat::xmppclient::operator="); - if(this == &xc) - return *this; - owner = false; - ctx = xc.ctx; - conn = xc.conn; - listener = xc.listener; - connecting = xc.connecting; - connected = xc.connected; - disconnecting = xc.disconnecting; - return *this; - } + XMPPClient& operator=(const XMPPClient& xc) = delete; ~XMPPClient() { debug("chat::~xmppclient"); @@ -110,12 +98,12 @@ private: friend const failable send(xmpp_stanza_t* const stanza, XMPPClient& xc); friend const failable post(const value& to, const value& val, XMPPClient& xc); friend const failable disconnect(XMPPClient& xc); - friend const failable listen(const lambda(const value&, const value&, XMPPClient&)>& listener, XMPPClient& xc); + friend const failable listen(const lambda(const value&, const value&, XMPPClient&)>& listener, XMPPClient& xc); - bool owner; + const bool owner; xmpp_ctx_t* ctx; xmpp_conn_t* conn; - lambda(const value&, const value&, XMPPClient&)> listener; + gc_mutable_ref(const value&, const value&, XMPPClient&)> > listener; bool connecting; bool connected; bool disconnecting; @@ -124,8 +112,8 @@ private: /** * Make a text stanza. */ -xmpp_stanza_t* textStanza(const char* text, xmpp_ctx_t* ctx) { - xmpp_stanza_t* stanza = xmpp_stanza_new(ctx); +xmpp_stanza_t* const textStanza(const char* const text, xmpp_ctx_t* const ctx) { + xmpp_stanza_t* const stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_text(stanza, text); return stanza; } @@ -133,8 +121,8 @@ xmpp_stanza_t* textStanza(const char* text, xmpp_ctx_t* ctx) { /** * Make a named stanza. */ -xmpp_stanza_t* namedStanza(const char* ns, const char* name, xmpp_ctx_t* ctx) { - xmpp_stanza_t* stanza = xmpp_stanza_new(ctx); +xmpp_stanza_t* const namedStanza(const char* const ns, const char* const name, xmpp_ctx_t* const ctx) { + xmpp_stanza_t* const stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(stanza, name); if (ns != NULL) xmpp_stanza_set_ns(stanza, ns); @@ -144,8 +132,8 @@ xmpp_stanza_t* namedStanza(const char* ns, const char* name, xmpp_ctx_t* ctx) { /** * Make a named stanza using a qualified name. */ -xmpp_stanza_t* namedStanza(const char* name, xmpp_ctx_t* ctx) { - xmpp_stanza_t* stanza = xmpp_stanza_new(ctx); +xmpp_stanza_t* const namedStanza(const char* const name, xmpp_ctx_t* const ctx) { + xmpp_stanza_t* const stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(stanza, name); return stanza; } @@ -157,16 +145,16 @@ int versionHandler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* c XMPPClient& xc = *(XMPPClient*)udata; // Build version reply stanza - xmpp_stanza_t* reply = namedStanza("iq", xc.ctx); + xmpp_stanza_t* const reply = namedStanza("iq", xc.ctx); xmpp_stanza_set_type(reply, "result"); xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza)); xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from")); - xmpp_stanza_t* query = namedStanza(xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza)), "query", xc.ctx); + xmpp_stanza_t* const query = namedStanza(xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza)), "query", xc.ctx); xmpp_stanza_add_child(reply, query); - xmpp_stanza_t* name = namedStanza("name", xc.ctx); + xmpp_stanza_t* const name = namedStanza("name", xc.ctx); xmpp_stanza_add_child(query, name); xmpp_stanza_add_child(name, textStanza("Apache Tuscany", xc.ctx)); - xmpp_stanza_t* version = namedStanza("version", xc.ctx); + xmpp_stanza_t* const version = namedStanza("version", xc.ctx); xmpp_stanza_add_child(query, version); xmpp_stanza_add_child(version, textStanza("1.0", xc.ctx)); @@ -188,17 +176,18 @@ int messageHandler(unused xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, // Call the client listener function XMPPClient& xc = *(XMPPClient*)udata; - const char* from = xmpp_stanza_get_attribute(stanza, "from"); - const char* text = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); - if (isNil(xc.listener)) + const char* const from = xmpp_stanza_get_attribute(stanza, "from"); + const char* const text = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); + if (isNil((lambda(const value&, const value&, XMPPClient&)>)xc.listener)) return 1; - const value val(scheme::readValue(text)); + const value val(content(scheme::readValue(text))); debug(from, "chat::messageHandler::from"); debug(val, "chat::messageHandler::body"); - const failable r = xc.listener(value(string(from)), val, xc); + const lambda(const value&, const value&, XMPPClient&)> listener = xc.listener; + const failable r = listener(value(string(from)), val, xc); if (!hasContent(r) || !content(r)) { // Stop listening - xc.listener = lambda(const value&, const value&, XMPPClient&)>(); + xc.listener = lambda(const value&, const value&, XMPPClient&)>(); return 0; } return 1; @@ -216,7 +205,7 @@ void connHandler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, unuse xmpp_handler_add(conn, versionHandler, "jabber:iq:version", "iq", NULL, &xc); // Send a stanza so that we appear online to contacts - xmpp_stanza_t* pres = xmpp_stanza_new(xc.ctx); + xmpp_stanza_t* const pres = xmpp_stanza_new(xc.ctx); xmpp_stanza_set_name(pres, "presence"); xmpp_send(conn, pres); xmpp_stanza_release(pres); @@ -246,7 +235,7 @@ const failable connect(XMPPClient& xc) { /** * Send a buffer on an XMPP session. */ -const failable send(const char* data, const size_t len, XMPPClient& xc) { +const failable send(const char* const data, const size_t len, XMPPClient& xc) { if (len == 0) return 0; const size_t written = xc.conn->tls? tls_write(xc.conn->tls, data, len) : sock_write(xc.conn->sock, data, len); @@ -268,7 +257,7 @@ const failable send(const string& data, XMPPClient& xc) { * Send a stanza on an XMPP session. */ const failable send(xmpp_stanza_t* const stanza, XMPPClient& xc) { - char *buf; + char* buf; size_t len; const int rc = xmpp_stanza_to_text(stanza, &buf, &len); if (rc != 0) @@ -291,13 +280,13 @@ const failable post(const value& to, const value& val, XMPPClient& xc) { debug(val, "chat::post::body"); // Convert the value to a string - const string vs(scheme::writeValue(val)); + const string vs(write(content(scheme::writeValue(val)))); // Build message stanza - xmpp_stanza_t* stanza = namedStanza("message", xc.ctx); + xmpp_stanza_t* const stanza = namedStanza("message", xc.ctx); xmpp_stanza_set_type(stanza, "chat"); xmpp_stanza_set_attribute(stanza, "to", c_str(string(to))); - xmpp_stanza_t* body = namedStanza("body", xc.ctx); + xmpp_stanza_t* const body = namedStanza("body", xc.ctx); xmpp_stanza_add_child(stanza, body); xmpp_stanza_add_child(body, textStanza(c_str(vs), xc.ctx)); @@ -323,12 +312,12 @@ const failable disconnect(XMPPClient& xc) { /** * Listen to messages received by an XMPP client. */ -const failable listen(const lambda(const value&, const value&, XMPPClient&)>& listener, XMPPClient& xc) { +const failable listen(const lambda(const value&, const value&, XMPPClient&)>& listener, XMPPClient& xc) { debug("chat::listen"); xc.listener = listener; xmpp_handler_add(xc.conn, messageHandler, NULL, "message", NULL, &xc); xc.ctx->loop_status = XMPP_LOOP_RUNNING; - while(xc.connected && !isNil(xc.listener) && xc.ctx->loop_status == XMPP_LOOP_RUNNING) + while(xc.connected && !isNil((lambda(const value&, const value&, XMPPClient&)>)xc.listener) && xc.ctx->loop_status == XMPP_LOOP_RUNNING) xmpp_run_once(xc.ctx, 1000L); return true; } -- cgit v1.2.3