summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components/chat
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-11-03 16:40:19 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-11-03 16:40:19 +0000
commitf46949c28997efe81d30555b8864fdd8235ed22f (patch)
treeab01ed514a85ad5b44c1a37f70400dff3ffde5aa /sca-cpp/trunk/components/chat
parent11894ea5ef3c72c072bbe4c3e24f5678002ba8df (diff)
Add .componentType files describing the utility components. Refactor chat component in two separate components for sending and receiving messages.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1030527 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/components/chat')
-rw-r--r--sca-cpp/trunk/components/chat/Makefile.am22
-rw-r--r--sca-cpp/trunk/components/chat/chat-sender.componentType29
-rw-r--r--sca-cpp/trunk/components/chat/chat-sender.cpp150
-rw-r--r--sca-cpp/trunk/components/chat/chat-sendreceiver.componentType30
-rw-r--r--sca-cpp/trunk/components/chat/chat-sendreceiver.cpp (renamed from sca-cpp/trunk/components/chat/chatter.cpp)22
-rw-r--r--sca-cpp/trunk/components/chat/chat.composite4
6 files changed, 237 insertions, 20 deletions
diff --git a/sca-cpp/trunk/components/chat/Makefile.am b/sca-cpp/trunk/components/chat/Makefile.am
index 64b1e070d3..35fb57daf3 100644
--- a/sca-cpp/trunk/components/chat/Makefile.am
+++ b/sca-cpp/trunk/components/chat/Makefile.am
@@ -31,14 +31,20 @@ comp_DATA = vysper.prefix
vysper.prefix: $(top_builddir)/config.status
echo ${VYSPER_PREFIX} >vysper.prefix
-EXTRA_DIST = chat.composite *.scm
-
-comp_LTLIBRARIES = libchatter.la
-libchatter_la_SOURCES = chatter.cpp
-libchatter_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
-noinst_DATA = libchatter.so
-libchatter.so:
- ln -s .libs/libchatter.so
+EXTRA_DIST = chat.composite chat-sendreceiver.componentType chat-sender.componentType *.scm
+
+comp_LTLIBRARIES = libchat-sendreceiver.la libchat-sender.la
+noinst_DATA = libchat-sendreceiver.so libchat-sender.so
+
+libchat_sendreceiver_la_SOURCES = chat-sendreceiver.cpp
+libchat_sendreceiver_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
+libchat-sendreceiver.so:
+ ln -s .libs/libchat-sendreceiver.so
+
+libchat_sender_la_SOURCES = chat-sender.cpp
+libchat_sender_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
+libchat-sender.so:
+ ln -s .libs/libchat-sender.so
xmpp_test_SOURCES = xmpp-test.cpp
xmpp_test_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
diff --git a/sca-cpp/trunk/components/chat/chat-sender.componentType b/sca-cpp/trunk/components/chat/chat-sender.componentType
new file mode 100644
index 0000000000..01838f0260
--- /dev/null
+++ b/sca-cpp/trunk/components/chat/chat-sender.componentType
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <service name="send"/>
+ <property name="jid" type="xsd:string"/>
+ <property name="password" type="xsd:string"/>
+
+</composite>
diff --git a/sca-cpp/trunk/components/chat/chat-sender.cpp b/sca-cpp/trunk/components/chat/chat-sender.cpp
new file mode 100644
index 0000000000..d3726a4e1c
--- /dev/null
+++ b/sca-cpp/trunk/components/chat/chat-sender.cpp
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * XMPP chat sender component implementation.
+ */
+
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "parallel.hpp"
+#include "xmpp.hpp"
+
+namespace tuscany {
+namespace chat {
+namespace sender {
+
+/**
+ * Post an item to an XMPP JID.
+ */
+const failable<value> post(const list<value>& params, XMPPClient& xc) {
+ const value to = car<value>(car(params));
+ const value val = cadr(params);
+ debug(to, "chat::post::jid");
+ debug(val, "chat::post::value");
+ const failable<bool> r = post(to, val, xc);
+ if (!hasContent(r))
+ return mkfailure<value>(reason(r));
+ return value(mklist<value>(to));
+}
+
+/**
+ * Subscribe and listen to an XMPP session.
+ */
+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;
+ debug("chat::subscribe::listen");
+ 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) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ const tuscany::value func(car(params));
+ if (func == "post")
+ return post(cdr(params), const_cast<XMPPClient&>(xc));
+
+ // Stop the chat sender component
+ if (func != "stop")
+ return tuscany::mkfailure<tuscany::value>();
+ debug("chat::sender::stop");
+
+ // Disconnect and shutdown the worker thread
+ disconnect(const_cast<XMPPClient&>(xc));
+ 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(list<value>)>)car(props))(list<value>());
+ const value pass = ((lambda<value(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>(reason(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)));
+}
+
+}
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::chat::sender::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}
diff --git a/sca-cpp/trunk/components/chat/chat-sendreceiver.componentType b/sca-cpp/trunk/components/chat/chat-sendreceiver.componentType
new file mode 100644
index 0000000000..0367c38f55
--- /dev/null
+++ b/sca-cpp/trunk/components/chat/chat-sendreceiver.componentType
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <service name="send"/>
+ <reference name="relay"/>
+ <property name="jid" type="xsd:string"/>
+ <property name="password" type="xsd:string"/>
+
+</composite>
diff --git a/sca-cpp/trunk/components/chat/chatter.cpp b/sca-cpp/trunk/components/chat/chat-sendreceiver.cpp
index 95f2d40077..610f3cc9cc 100644
--- a/sca-cpp/trunk/components/chat/chatter.cpp
+++ b/sca-cpp/trunk/components/chat/chat-sendreceiver.cpp
@@ -20,7 +20,7 @@
/* $Rev$ $Date$ */
/**
- * XMPP chatter component implementation.
+ * XMPP chat sender/receiver component implementation.
*/
#include "string.hpp"
@@ -33,6 +33,7 @@
namespace tuscany {
namespace chat {
+namespace sendreceiver {
/**
* Post an item to an XMPP JID.
@@ -91,11 +92,11 @@ private:
};
/**
- * Chatter component lambda function
+ * Chat sender/receiver component lambda function
*/
-class chatter {
+class chatSenderReceiver {
public:
- chatter(XMPPClient& xc, worker& w) : xc(xc), w(w) {
+ chatSenderReceiver(XMPPClient& xc, worker& w) : xc(xc), w(w) {
}
const value operator()(const list<value>& params) const {
@@ -103,15 +104,15 @@ public:
if (func == "post")
return post(cdr(params), const_cast<XMPPClient&>(xc));
- // Stop the chatter component
+ // Stop the chat sender/receiver component
if (func != "stop")
return tuscany::mkfailure<tuscany::value>();
- debug("chat::chatter::stop");
+ debug("chat::sendreceiver::stop");
// Disconnect and shutdown the worker thread
disconnect(const_cast<XMPPClient&>(xc));
cancel(const_cast<worker&>(w));
- debug("chat::chatter::stopped");
+ debug("chat::sendreceiver::stopped");
return failable<value>(value(lambda<value(const list<value>&)>()));
}
@@ -143,19 +144,20 @@ const failable<value> start(const list<value>& params) {
const lambda<failable<bool>(const value&, const value&, XMPPClient&)> rl = relay(rel);
submit<failable<bool> >(w, lambda<failable<bool>()>(subscribe(rl, xc)));
- // Return the chatter component lambda function
- return value(lambda<value(const list<value>&)>(chatter(xc, w)));
+ // Return the chat sender/receiver component lambda function
+ return value(lambda<value(const list<value>&)>(chatSenderReceiver(xc, w)));
}
}
}
+}
extern "C" {
const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
const tuscany::value func(car(params));
if (func == "start")
- return tuscany::chat::start(cdr(params));
+ return tuscany::chat::sendreceiver::start(cdr(params));
return tuscany::mkfailure<tuscany::value>();
}
diff --git a/sca-cpp/trunk/components/chat/chat.composite b/sca-cpp/trunk/components/chat/chat.composite
index 15901b51da..9eada5c372 100644
--- a/sca-cpp/trunk/components/chat/chat.composite
+++ b/sca-cpp/trunk/components/chat/chat.composite
@@ -23,7 +23,7 @@
name="chat">
<component name="print-sender">
- <implementation.cpp path="." library="libchatter"/>
+ <implementation.cpp path="." library="libchat-sender"/>
<property name="jid">sca1@localhost</property>
<property name="password">sca1</property>
<service name="print-sender">
@@ -32,7 +32,7 @@
</component>
<component name="print-chatter">
- <implementation.cpp path="." library="libchatter"/>
+ <implementation.cpp path="." library="libchat-sendreceiver"/>
<property name="jid">sca2@localhost</property>
<property name="password">sca2</property>
<service name="print-chatter">