diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-12-11 06:13:02 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-12-11 06:13:02 +0000 |
commit | 36adc76235fb0a38e7042bc751f988b71627e2a0 (patch) | |
tree | fc83b3f4e0afeb3932c8d200f5493f0a8d6c4619 /sca-cpp/trunk/components/chat/chat-sender.cpp | |
parent | 86b1de85536e93c59a25702a5a2d3e384202ffd2 (diff) |
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
Diffstat (limited to 'sca-cpp/trunk/components/chat/chat-sender.cpp')
-rw-r--r-- | sca-cpp/trunk/components/chat/chat-sender.cpp | 91 |
1 files changed, 29 insertions, 62 deletions
diff --git a/sca-cpp/trunk/components/chat/chat-sender.cpp b/sca-cpp/trunk/components/chat/chat-sender.cpp index a4cabef8de..64d0271d43 100644 --- a/sca-cpp/trunk/components/chat/chat-sender.cpp +++ b/sca-cpp/trunk/components/chat/chat-sender.cpp @@ -51,45 +51,38 @@ const failable<value> post(const list<value>& params, XMPPClient& xc) { } /** - * Subscribe and listen to an XMPP session. + * Start the component. */ -class noop { -public: - noop() { - } - - const failable<bool> operator()(unused const value& jid, unused const value& val, unused XMPPClient& xc) const { - return true; - } -}; - -class subscribe { -public: - subscribe(XMPPClient& xc) : xc(xc) { - } - - const failable<bool> operator()() const { - gc_pool pool; +const failable<value> start(const list<value>& params) { + // Extract the the XMPP JID and password + const list<value> props = params; + const value jid = ((lvvlambda)car(props))(nilListValue); + const value pass = ((lvvlambda)cadr(props))(nilListValue); + + // Create an XMPP client session + XMPPClient xc(jid, pass, false); + const failable<bool> r = connect(xc); + if (!hasContent(r)) + return mkfailure<value>(r); + + // Subscribe and listen to XMPP session + const lambda<const failable<bool>()> subscribe = [xc]() -> const failable<bool> { + const gc_pool pool; debug("chat::subscribe::listen"); - const failable<bool> r = listen(noop(), const_cast<XMPPClient&>(xc)); + const lambda<const failable<bool>(const value&, const value&, XMPPClient&)> noop = [](unused const value& jid, unused const value& val, unused XMPPClient& xc) -> const failable<bool> { + return true; + }; + const failable<bool> r = listen(noop, const_cast<XMPPClient&>(xc)); debug("chat::subscribe::stopped"); return r; - } - -private: - const lambda<failable<bool>(const value&, const value&, XMPPClient&)> l; - XMPPClient xc; -}; + }; -/** - * Chatter component lambda function - */ -class chatSender { -public: - chatSender(XMPPClient& xc, worker& w) : xc(xc), w(w) { - } + // Listen and relay messages in a worker thread + worker w(3); + submit<failable<bool> >(w, subscribe); - const value operator()(const list<value>& params) const { + // Return the chat sender component lambda function + const lvvlambda chatSender = [xc, w](const list<value>& params) -> const value { const tuscany::value func(car(params)); if (func == "post") return post(cdr(params), const_cast<XMPPClient&>(xc)); @@ -104,35 +97,9 @@ public: cancel(const_cast<worker&>(w)); debug("chat::sender::stopped"); - return failable<value>(value(lambda<value(const list<value>&)>())); - } - -private: - const XMPPClient xc; - worker w; -}; - -/** - * Start the component. - */ -const failable<value> start(const list<value>& params) { - // Extract the the XMPP JID and password - const list<value> props = params; - const value jid = ((lambda<value(const list<value>&)>)car(props))(list<value>()); - const value pass = ((lambda<value(const list<value>&)>)cadr(props))(list<value>()); - - // Create an XMPP client session - XMPPClient xc(jid, pass, false); - const failable<bool> r = connect(xc); - if (!hasContent(r)) - return mkfailure<value>(r); - - // Listen and relay messages in a worker thread - worker w(3); - submit<failable<bool> >(w, lambda<failable<bool>()>(subscribe(xc))); - - // Return the chat sender component lambda function - return value(lambda<value(const list<value>&)>(chatSender(xc, w))); + return failable<value>(value(lvvlambda())); + }; + return value(chatSender); } } |