started example using code generator
authorJens Thiele <jens.thiele@intra2net.com>
Mon, 20 Nov 2006 16:44:36 +0000 (16:44 +0000)
committerJens Thiele <jens.thiele@intra2net.com>
Mon, 20 Nov 2006 16:44:36 +0000 (16:44 +0000)
example-codegen/Makefile.am [new file with mode: 0644]
example-codegen/client.cpp [new file with mode: 0644]
example-codegen/server.cpp [new file with mode: 0644]
example-codegen/server.hxx [new file with mode: 0644]

diff --git a/example-codegen/Makefile.am b/example-codegen/Makefile.am
new file mode 100644 (file)
index 0000000..3531289
--- /dev/null
@@ -0,0 +1,23 @@
+INCLUDES = -I$(top_srcdir)/src @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@ -I$(top_srcdir)/codegen
+
+LDADD = $(top_builddir)/src/libt2n.la @BOOST_SERIALIZATION_LIB@ @BOOST_LDFLAGS@
+
+libclient_la_SOURCES = codegen_client.cpp
+noinst_LTLIBRARIES = libclient.la
+
+client_SOURCES = client.cpp
+client_LDADD = $(LDADD) libclient.la
+
+server_SOURCES = server.cpp codegen_server.cpp
+
+noinst_PROGRAMS = client server
+
+all-local: server.xml
+
+client.cpp codegen_common.hxx codegen_common.cpp codegen_client.hxx codegen_client.cpp codegen_server.cpp: server.xml
+
+server.xml: server.cpp $(top_builddir)/codegen/codegen
+       cp $(top_srcdir)/codegen/codegen-stubhead.hxx codegen_common.hxx
+       gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) server.hxx -fxml=tmpserver.xml
+       $(top_builddir)/codegen/codegen tmpserver.xml codegen_
+       mv tmpserver.xml server.xml
diff --git a/example-codegen/client.cpp b/example-codegen/client.cpp
new file mode 100644 (file)
index 0000000..f3f1176
--- /dev/null
@@ -0,0 +1,18 @@
+/***************************************************************************
+ *   Copyright (C) 2004 by Intra2net AG                                    *
+ *   info@intra2net.com                                                    *
+ *                                                                         *
+ ***************************************************************************/
+
+#include <socket_client.hxx>
+
+// include library header
+#include "codegen_client.hxx"
+
+int main(int argc, char** argv)
+{
+  libt2n::socket_client_connection sc("./socket");
+  cmd_group_example_client cc(sc);
+
+  return (cc.testfunc("hello")=="hello, testfunc() was here") ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/example-codegen/server.cpp b/example-codegen/server.cpp
new file mode 100644 (file)
index 0000000..aa8af26
--- /dev/null
@@ -0,0 +1,17 @@
+#include <socket_server.hxx>
+#include <command_server.hxx>
+
+#include "server.hxx"
+
+using namespace libt2n;
+
+int main(int argc, char** argv) {
+  socket_server ss("./socket");
+  group_command_server<cmd_group_default> cs(ss);
+
+  // handle requests (without timeout)
+  while(true)
+    cs.handle();
+
+  return 0;
+}
diff --git a/example-codegen/server.hxx b/example-codegen/server.hxx
new file mode 100644 (file)
index 0000000..027e313
--- /dev/null
@@ -0,0 +1,18 @@
+#include <string>
+#include "codegen_common.hxx"
+
+using namespace std;
+
+LIBT2N_SET_DEFAULTGROUP(example);
+
+LIBT2N_EXPORT std::string testfunc(std::string str) 
+{
+    string ret;
+    if (str=="throw")
+        throw libt2n::t2n_runtime_error("throw me around");
+    if (str=="big")
+        ret.insert(0,100*1024,'x');
+    else
+        ret=str+", testfunc() was here";
+    return ret;
+}