tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r1094212 - in /tuscany/sca-cpp/trunk: ./ components/chat/ components/http/
Date Sun, 17 Apr 2011 22:14:29 GMT
Author: jsdelfino
Date: Sun Apr 17 22:14:29 2011
New Revision: 1094212

URL: http://svn.apache.org/viewvc?rev=1094212&view=rev
Log:
Add an XMPP message sender component that only connects to an XMPP server as needed just before
sending a message to avoid unnecessary connects / disconnects in a dynamic virtual host environment.
Add another component that does an HTTP delete.

Added:
    tuscany/sca-cpp/trunk/components/chat/chat-send.cpp
    tuscany/sca-cpp/trunk/components/chat/chat-sender2.componentType
    tuscany/sca-cpp/trunk/components/chat/chat-sender2.cpp
    tuscany/sca-cpp/trunk/components/http/httpdelete.componentType
    tuscany/sca-cpp/trunk/components/http/httpdelete.cpp
Modified:
    tuscany/sca-cpp/trunk/.gitignore
    tuscany/sca-cpp/trunk/components/chat/Makefile.am
    tuscany/sca-cpp/trunk/components/chat/server-test
    tuscany/sca-cpp/trunk/components/http/Makefile.am

Modified: tuscany/sca-cpp/trunk/.gitignore
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/.gitignore?rev=1094212&r1=1094211&r2=1094212&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/.gitignore (original)
+++ tuscany/sca-cpp/trunk/.gitignore Sun Apr 17 22:14:29 2011
@@ -136,4 +136,5 @@ value-element
 modules/edit/apps/*/htdocs
 modules/edit/apps/*/nuvem
 modules/edit/apps/*/lib
+chat-send
 

Modified: tuscany/sca-cpp/trunk/components/chat/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/chat/Makefile.am?rev=1094212&r1=1094211&r2=1094212&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/chat/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/components/chat/Makefile.am Sun Apr 17 22:14:29 2011
@@ -31,10 +31,10 @@ comp_DATA = vysper.prefix
 vysper.prefix: $(top_builddir)/config.status
 	echo ${VYSPER_PREFIX} >vysper.prefix
 
-EXTRA_DIST = chat.composite chat-sendreceiver.componentType chat-sender.componentType *.scm
+EXTRA_DIST = chat.composite chat-sendreceiver.componentType chat-sender.componentType chat-sender2.componentType
*.scm
 
-comp_LTLIBRARIES = libchat-sendreceiver.la libchat-sender.la
-noinst_DATA = libchat-sendreceiver.so libchat-sender.so
+comp_LTLIBRARIES = libchat-sendreceiver.la libchat-sender.la libchat-sender2.la
+noinst_DATA = libchat-sendreceiver.so libchat-sender.so libchat-sender2.so
 
 libchat_sendreceiver_la_SOURCES = chat-sendreceiver.cpp
 libchat_sendreceiver_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl
-lresolv
@@ -46,12 +46,22 @@ libchat_sender_la_LDFLAGS = -L${LIBSTROP
 libchat-sender.so:
 	ln -s .libs/libchat-sender.so
 
+libchat_sender2_la_SOURCES = chat-sender2.cpp
+libchat_sender2_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
+libchat-sender2.so:
+	ln -s .libs/libchat-sender2.so
+
+chat_send_SOURCES = chat-send.cpp
+chat_send_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
+
 xmpp_test_SOURCES = xmpp-test.cpp
 xmpp_test_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
 
 client_test_SOURCES = client-test.cpp
 client_test_LDFLAGS = -lxml2 -lcurl -lmozjs -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe
-lssl -lresolv
 
+comp_PROGRAMS = chat-send
+
 noinst_PROGRAMS = xmpp-test client-test
 dist_noinst_SCRIPTS = server-test
 
@@ -62,7 +72,7 @@ dist_noinst_JAVA = test/*.java
 CLEANFILES = test/*.class
 
 dist_noinst_SCRIPTS += echo-test
-TESTS = echo-test 
+TESTS = echo-test server-test
 endif
 
 endif

Added: tuscany/sca-cpp/trunk/components/chat/chat-send.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/chat/chat-send.cpp?rev=1094212&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/chat/chat-send.cpp (added)
+++ tuscany/sca-cpp/trunk/components/chat/chat-send.cpp Sun Apr 17 22:14:29 2011
@@ -0,0 +1,55 @@
+/*
+ * 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$ */
+
+/**
+ * Test sending a message to an XMPP id.
+ */
+
+#include <assert.h>
+#include "stream.hpp"
+#include "string.hpp"
+#include "list.hpp"
+#include "element.hpp"
+#include "monad.hpp"
+#include "value.hpp"
+#include "perf.hpp"
+#include "parallel.hpp"
+#include "xmpp.hpp"
+
+namespace tuscany {
+namespace chat {
+
+bool sendmsg(const string& jid, const string& pass, const string& to, const string&
msg) {
+    XMPPClient xc(jid, pass);
+    const failable<bool> c = connect(xc);
+    assert(hasContent(c));
+    const failable<bool> p = post(to, msg, xc);
+    assert(hasContent(p));
+    return true;
+}
+
+}
+}
+
+int main(unused const int argc, const char** argv) {
+    tuscany::chat::sendmsg(argv[1], argv[2], argv[3], argv[4]);
+    return 0;
+}

Added: tuscany/sca-cpp/trunk/components/chat/chat-sender2.componentType
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/chat/chat-sender2.componentType?rev=1094212&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/chat/chat-sender2.componentType (added)
+++ tuscany/sca-cpp/trunk/components/chat/chat-sender2.componentType Sun Apr 17 22:14:29 2011
@@ -0,0 +1,31 @@
+<?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="jid"/>
+    <reference name="pass"/>
+    <reference name="to"/>
+    <reference name="msg"/>
+
+</composite>

Added: tuscany/sca-cpp/trunk/components/chat/chat-sender2.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/chat/chat-sender2.cpp?rev=1094212&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/chat/chat-sender2.cpp (added)
+++ tuscany/sca-cpp/trunk/components/chat/chat-sender2.cpp Sun Apr 17 22:14:29 2011
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ * This sender gets its configuration from a single property and its
+ * input data from component references instead of function parameters.
+ */
+
+#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 lambda<value(const list<value>&)>
jid, const lambda<value(const list<value>&)> pass, const lambda<value(const
list<value>&)> to, const lambda<value(const list<value>&)> msg,
const list<value>& params) {
+
+    const value vjid = jid(mklist<value>("get", params));
+    const value vpass = pass(mklist<value>("get", params));
+    const value vto = to(mklist<value>("get", params));
+    const value vmsg = msg(mklist<value>("get", params));
+    debug(vjid, "chat::post::from");
+    debug(vto, "chat::post::to");
+    debug(vmsg, "chat::post::value");
+
+    // Create an XMPP client session
+    XMPPClient xc(vjid, vpass);
+    const failable<bool> c = connect(xc);
+    if (!hasContent(c))
+        return mkfailure<value>(reason(c));
+
+    // Post the message
+    const failable<bool> r = post(vto, vmsg, xc);
+    if (!hasContent(r))
+        return mkfailure<value>(reason(r));
+    return value(mklist<value>(vto));
+}
+
+/**
+ * Chat sender component lambda function
+ */
+class chatSender {
+public:
+    chatSender(const lambda<value(const list<value>&)> jid, const lambda<value(const
list<value>&)> pass, const lambda<value(const list<value>&)>
to, const lambda<value(const list<value>&)> msg) : jid(jid), pass(pass), to(to),
msg(msg) {
+    }
+
+    const value operator()(const list<value>& params) const {
+        const tuscany::value func(car(params));
+        if (func == "get")
+            return post(jid, pass, to, msg, cdr(params));
+
+        // Stop the chat sender component
+        if (func != "stop")
+            return tuscany::mkfailure<tuscany::value>();
+        debug("chat::sender::stop");
+        return failable<value>(value(lambda<value(const list<value>&)>()));
+    }
+
+private:
+    const lambda<value(const list<value>&)> jid;
+    const lambda<value(const list<value>&)> pass;
+    const lambda<value(const list<value>&)> to;
+    const lambda<value(const list<value>&)> msg;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+
+    // Return the chat sender component lambda function
+    return value(lambda<value(const list<value>&)>(chatSender(car(params),
cadr(params), caddr(params), cadddr(params))));
+}
+
+}
+}
+}
+
+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>();
+}
+
+}

Modified: tuscany/sca-cpp/trunk/components/chat/server-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/chat/server-test?rev=1094212&r1=1094211&r2=1094212&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/chat/server-test (original)
+++ tuscany/sca-cpp/trunk/components/chat/server-test Sun Apr 17 22:14:29 2011
@@ -26,6 +26,8 @@ SCAContribution `pwd`/
 SCAComposite chat.composite
 EOF
 
+./vysper-start
+sleep 3
 ../../modules/http/httpd-start tmp
 sleep 2
 
@@ -36,4 +38,6 @@ rc=$?
 # Cleanup
 ../../modules/http/httpd-stop tmp
 sleep 1
+./vysper-stop
+sleep 1
 return $rc

Modified: tuscany/sca-cpp/trunk/components/http/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/http/Makefile.am?rev=1094212&r1=1094211&r2=1094212&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/http/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/components/http/Makefile.am Sun Apr 17 22:14:29 2011
@@ -17,16 +17,21 @@
 
 compdir=$(prefix)/components/http
 
-EXTRA_DIST = http.composite httpget.componentType *.scm
+EXTRA_DIST = http.composite httpget.componentType httpdelete.componentType *.scm
 
-comp_LTLIBRARIES = libhttpget.la
-noinst_DATA = libhttpget.so
+comp_LTLIBRARIES = libhttpget.la libhttpdelete.la
+noinst_DATA = libhttpget.so libhttpdelete.so
 
 libhttpget_la_SOURCES = httpget.cpp
 libhttpget_la_LDFLAGS = -lxml2 -lmozjs -curl
 libhttpget.so:
 	ln -s .libs/libhttpget.so
 
+libhttpdelete_la_SOURCES = httpdelete.cpp
+libhttpdelete_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttpdelete.so:
+	ln -s .libs/libhttpdelete.so
+
 client_test_SOURCES = client-test.cpp
 client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
 

Added: tuscany/sca-cpp/trunk/components/http/httpdelete.componentType
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/http/httpdelete.componentType?rev=1094212&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/http/httpdelete.componentType (added)
+++ tuscany/sca-cpp/trunk/components/http/httpdelete.componentType Sun Apr 17 22:14:29 2011
@@ -0,0 +1,28 @@
+<?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="http"/>
+    <reference name="url"/>
+
+</composite>

Added: tuscany/sca-cpp/trunk/components/http/httpdelete.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/http/httpdelete.cpp?rev=1094212&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/http/httpdelete.cpp (added)
+++ tuscany/sca-cpp/trunk/components/http/httpdelete.cpp Sun Apr 17 22:14:29 2011
@@ -0,0 +1,90 @@
+/*
+ * 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$ */
+
+/**
+ * HTTP client component implementation.
+ */
+
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace httpdelete {
+
+/**
+ * Evaluate an HTTP delete.
+ */
+const failable<value> get(const lambda<value(const list<value>&)> url,
http::CURLSession& ch) {
+    debug("httpdelete::get");
+    const value u = url(mklist<value>("get", list<value>()));
+    debug(u, "httpdelete::get::url");
+    return http::del(u, ch);
+}
+
+/**
+ * Component implementation lambda function.
+ */
+class applyhttp {
+public:
+    applyhttp(const lambda<value(const list<value>&)> url, http::CURLSession&
ch) : url(url), ch(ch) {
+    }
+
+    const value operator()(const list<value>& params) const {
+        debug(params, "httpdelete::applyhttp::params");
+        const value func(car(params));
+        if (func == "get")
+            return get(url, ch);
+        return tuscany::mkfailure<tuscany::value>();
+    }
+
+private:
+    const lambda<value(const list<value>&)> url;
+    http::CURLSession& ch;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+    // Create a CURL session
+    http::CURLSession& ch = *(new (gc_new<http::CURLSession>()) http::CURLSession("",
"", ""));
+
+    // Return the component implementation lambda function
+    return value(lambda<value(const list<value>&)>(applyhttp(car(params),
ch)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+    const tuscany::value func(car(params));
+    if (func == "start")
+        return tuscany::httpdelete::start(cdr(params));
+    return tuscany::mkfailure<tuscany::value>();
+}
+
+}



Mime
View raw message