From f4dfa6457b4b4f0f37b4aa55384c03ebd530385f Mon Sep 17 00:00:00 2001 From: Jens Thiele Date: Mon, 11 Dec 2006 12:19:43 +0000 Subject: [PATCH] moved examples out of libt2n into libt2n-example --- codegen/TODO | 1 + example-codegen/Makefile.am | 62 ------------------------------------- example-codegen/README | 18 ----------- example-codegen/TODO | 67 ----------------------------------------- example-codegen/client.cpp | 39 ------------------------ example-codegen/codegen.make | 65 --------------------------------------- example-codegen/configure.in | 11 ------- example-codegen/default.cpp | 33 -------------------- example-codegen/default.hxx | 9 ----- example-codegen/foo.hxx | 21 ------------- example-codegen/other-1.cpp | 21 ------------- example-codegen/other-2.cpp | 7 ---- example-codegen/other.hxx | 11 ------- example-codegen/server.cpp | 23 -------------- example-codegen/test | 17 ---------- example-libusage/Makefile.am | 10 ------ example-libusage/README | 1 - example-libusage/client.cpp | 30 ------------------ example-libusage/configure.in | 11 ------- 19 files changed, 1 insertions(+), 456 deletions(-) delete mode 100644 example-codegen/Makefile.am delete mode 100644 example-codegen/README delete mode 100644 example-codegen/TODO delete mode 100644 example-codegen/client.cpp delete mode 100644 example-codegen/codegen.make delete mode 100644 example-codegen/configure.in delete mode 100644 example-codegen/default.cpp delete mode 100644 example-codegen/default.hxx delete mode 100644 example-codegen/foo.hxx delete mode 100644 example-codegen/other-1.cpp delete mode 100644 example-codegen/other-2.cpp delete mode 100644 example-codegen/other.hxx delete mode 100644 example-codegen/server.cpp delete mode 100755 example-codegen/test delete mode 100644 example-libusage/Makefile.am delete mode 100644 example-libusage/README delete mode 100644 example-libusage/client.cpp delete mode 100644 example-libusage/configure.in diff --git a/codegen/TODO b/codegen/TODO index 13f3f64..3a10806 100644 --- a/codegen/TODO +++ b/codegen/TODO @@ -18,3 +18,4 @@ open questions: => we do not provide this for now - naming scheme?! perhaps generated group class should not be prefixed by cmd_group_ + diff --git a/example-codegen/Makefile.am b/example-codegen/Makefile.am deleted file mode 100644 index 00aaac7..0000000 --- a/example-codegen/Makefile.am +++ /dev/null @@ -1,62 +0,0 @@ -# not a GNU package. You can remove this line, if -# you have all needed files, that a GNU package needs -AUTOMAKE_OPTIONS = foreign - -INCLUDES = @LIBT2N_CFLAGS@ -LDADD = @LIBT2N_LIBS@ - -# list your command groups -CMDGROUPS = default other - -# for each command group list the files to parse for LIBT2N_EXPORT -default_GROUP = default.cpp -# example of a command group using multiple cpp files -other_GROUP = other-1.cpp other-2.cpp - -# headers declaring data types used as rpc arguments must be listed manually -# (in this example the class Foo) -include_HEADERS = foo.hxx - -# unfortunately we can't set those from variables -# because they are parsed by automake - -# we would like to use nodist_ here but our automake is to old -# nodist_libdefault_la_SOURCES = default_client.cpp -# nodist_libother_la_SOURCES = other_client.cpp - -# using objects as workaround -libdefault_la_OBJECTS += default_client.lo -#libdefault_la_SOURCES = default_client.cpp -libother_la_OBJECTS += other_client.lo -#libother_la_SOURCES = other_client.cpp -lib_LTLIBRARIES = libdefault.la libother.la - -# build an example server and client -client_SOURCES = client.cpp -client_LDADD = $(LDADD) libdefault.la libother.la - -noinst_PROGRAMS = client server - -# we would like to use nodist_ here but our automake is to old -# nodist_server_SOURCES = other_server.cpp default_server.cpp - -server_LDADD = $(LDADD) other_server.$(OBJEXT) default_server.$(OBJEXT) - -server_SOURCES = \ - server.cpp $(other_GROUP) $(default_GROUP) -# other_server.cpp default_server.cpp - - -# test script - -TESTS = test - -EXTRA_DIST = $(TESTS) configure.in - -# if you use libt2n-codegen you should add this -# (i did not find a nice way to let libt2n install this makefile snippet -# and let projects using libt2n use the installed version. -# the core of the problem is: -# the makefile snippet is already needed when automake is run -# => no way to let configure locate the snippet) -include codegen.make diff --git a/example-codegen/README b/example-codegen/README deleted file mode 100644 index ca3ab46..0000000 --- a/example-codegen/README +++ /dev/null @@ -1,18 +0,0 @@ -Example how to use the code generator libt2n-codegen. -This example may be build during the build of libt2n or it may be build seperately using a -installed version of libt2n. - -To build it seperately using a installed version of libt2n: -autoreconf && ./configure && make && make distcheck - -if it does not work you may have to move the example-codegen out of the libt2n directory and -pass some options to autoreconf -I use something like: -tar xzvf libt2n-0.1.tar.gz -mv libt2n-0.1/example-codegen . -cd example-codegen -# get configure script created and missing autotools helper files installed -# if you installed libt2n in some non-standard directory you might have to pass -# -M pathtolibt2n.m4 -autoreconf -f -i -./configure && make && make distcheck diff --git a/example-codegen/TODO b/example-codegen/TODO deleted file mode 100644 index 7386630..0000000 --- a/example-codegen/TODO +++ /dev/null @@ -1,67 +0,0 @@ -multiple command groups test: howto multiplex multiple commands on one stream? -don't multiplex but a select on multiple groups would be nice - -include problem: -- i don't see a solution using gccxml -- a simple solution would be to have a special include file containing the neccessary includes (or 2: one for the type definitions and one for the serialization) -- another solution would be to extract the includes from the file and add them to the generated code -both solutions only work if the include paths used during compilation of a program using the library are correct[tm] -now we use the first solution - -- test using valgrind -- would be nice to reduce amount of changed files - (codegen output is often the same as the existing files - something similar to ccache - for codegen - but not overwriting output files if they are the same) -- howto include the part after "# always the same:" in all makefiles (using the codegenerator) - (we now use make's include) -- lib name should be group name + suffix/prefix ?! - user should have complete control => no default suffix/perfix - headers should be installed in pkgincludedir? maybe yes on the other hand - the user can pass the directory to configure via --includedir -- the example should not get installed (but still it should show how to build a lib that gets installed :-( - (overwriting install: doesn't work) - => perhaps split libt2n package into 3 packages? - libt2n - libt2n-example-codegen - libt2n-example-libusage -- at the moment make dist from within a clean source will not work - (this is related to the nodist problem / old automake version) - this is caused by BUILT_SOURCES not working for make dist(check?) - and the dependency generation - - distcheck -> dist -> distdir -> DISTFILES - - all -> all-redirect -> all-am -> Makefile -> BUILT_SOURCES => bene - - => how to add dependency on BUILT_SOURCES for dist? - the real problem is that make dist should not depend on BUILT_SOURCES - unfortunately we can't fix this as long as we use a old automake version - (DISTFILES includes generated files we would like to mark as noinst) -- make clean / make distclean?! make clean geht beim zweiten mal nicht - now it works?! why?! - das ganze ist abhängig davon in welchem verzeichnis man ist?! - das problem ist: - BUILT_SOURCES -> generierte files -> codegen ! - (make clean in toplevel src dir -> codegen does not exist) - - => how to get rid off BUILT_SOURCES - or how to get rid off dependency off clean and dist on BUILT_SOURCES files ? - (the nodist problem) - - getting rid off BUILT_SOURCES would not suffice - (explicit dependencies still would depend upon the files) - => the real problem is the missing nodist - - => workaround for old automake version? - a workaround would require us not to use _SOURCES but still be able to add object files - to the libs/bins created - looking at the generated Makefile this perhaps could be done via _OBJECTS - - nodist wurde mit automake 1.5 eingeführt (2001-08-23) - - what doesn't work: - - make dist and make clean only work if you did a make all - - hmm Makefile should not depend on BUILT_SOURCES - http://sources.redhat.com/ml/bug-automake/2000/msg00040.html - \ No newline at end of file diff --git a/example-codegen/client.cpp b/example-codegen/client.cpp deleted file mode 100644 index 1029abe..0000000 --- a/example-codegen/client.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004 by Intra2net AG * - * info@intra2net.com * - * * - ***************************************************************************/ - -#include - -// include generated library headers -#include "default_client.hxx" -#include "other_client.hxx" - -int main(int argc, char** argv) -{ - libt2n::socket_client_connection sc("./socket"); - libt2n::socket_client_connection sc_other("./socket_other"); - cmd_group_default_client cc(sc); - cmd_group_other_client cc_other(sc_other); - - bool throwok=false; - try - { - cc.testfunc("throw"); - }catch(libt2n::t2n_runtime_error &e){ - throwok=(std::string(e.what())=="throw me around"); - } - - Foo foo={10,10}; - - return ( throwok - && ( cc.testfunc("hello") == "hello, testfunc() was here" ) - && ( cc.testfunc_ref("hello") == "hello, testfunc() was here" ) - && ( cc.t2(10) == 10 ) - && ( cc_other.t3(10, 20, "hello", std::pair(10,20)) ) - && ( cc_other.t3(10) == 10 ) - && ( cc_other.t3(std::vector(1,10)) ) - && ( cc_other.t3(foo) ) ) - ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/example-codegen/codegen.make b/example-codegen/codegen.make deleted file mode 100644 index f9de2b7..0000000 --- a/example-codegen/codegen.make +++ /dev/null @@ -1,65 +0,0 @@ -# Makefile snippet included by projects using libt2n-codegen - -# Asumptions: -# gnu make (functions for transforming text) -# sed is available - -include_HEADERS += $(foreach i, $(CMDGROUPS), $(i)_client.hxx $(i).hxx) - -# not needed but nice to have -# IFILES=$(foreach i, $(CMDGROUPS), $(foreach j, $($(i)_GROUP), $(j))) - --include $(foreach i, $(CMDGROUPS), libt2ngroup_$(i).P) - -libt2ngroup_%.P : Makefile.am - echo $@ : $($*_GROUP) > libt2ngroup_$*.P - -%.libt2nstamp : libt2ngroup_%.P -# assuming we have some unix like shell (maybe even bash) -# echo BUILT_SOURCES: $(BUILT_SOURCES) -# temporarily create _common.hxx file (will be overwritten by codegen below) - echo '#include "codegen-stubhead.hxx"' > $*_common.hxx; - echo '#include "$*.hxx"' >> $*_common.hxx; -# todo use tmp file for xml file - for i in $($*_GROUP); do \ - gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(srcdir)/$${i} -fxml=$${i%*.cpp}.xml; \ - done; \ - $(LIBT2N_CODEGEN) $* $($*_GROUP:.cpp=.xml) && touch $@ - -LIBT2N_CODEGEN_BUILT = $(foreach i, $(CMDGROUPS), $(foreach j, _common.hxx _common.cpp _client.hxx _client.cpp _server.hxx _server.cpp, $(i)$(j)) ) - -# using BUILT_SOURCES is a bit problematic (see also automake manual) -BUILT_SOURCES += $(LIBT2N_CODEGEN_BUILT) - -LIBT2N_STAMPS=$(CMDGROUPS:=.libt2nstamp) -$(BUILT_SOURCES) : $(LIBT2N_STAMPS) - -# Install the pkg-config files: (todo: perhaps use +=) -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = $(CMDGROUPS:=.pc) - -# .pc files (one pc file for each command group) -%.pc : $(LIBT2N_CLIENT_PCTEMPLATE) Makefile - sed \ - -e 's,\@CMDGROUP\@,$*,g' \ - -e 's,\@prefix\@,$(prefix),g' \ - -e 's,\@exec_prefix\@,$(exec_prefix),g' \ - -e 's,\@libdir\@,$(libdir),g' \ - -e 's,\@includedir\@,$(includedir),g' \ - -e 's,\@VERSION\@,$(VERSION),g' \ - $< >$*.pc - -CLEANFILES += $(LIBT2N_CODEGEN_BUILT) $(LIBT2N_STAMPS) $(pkgconfig_DATA) - -# didn't work (same problem as with _LTLIBRARIES [parsing by automake], -# this time _OBJECTS was not correct) -# server_SOURCES = server.cpp \ -# $(foreach i, $(CMDGROUPS), $(foreach j, $($(i)_GROUP), $(j))) \ -# $(foreach i, $(CMDGROUPS), $(i)_server.cpp) - -# we have got an old automake version (1.4-p5) which doesn't support nodist_ -# => we use this hack using the dist-hook -dist-hook: $(LIBT2N_CODEGEN_BUILT) - rm -vf $(foreach i, $(LIBT2N_CODEGEN_BUILT), $(distdir)/$(i)) - -EXTRA_DIST += codegen.make diff --git a/example-codegen/configure.in b/example-codegen/configure.in deleted file mode 100644 index 4afd1be..0000000 --- a/example-codegen/configure.in +++ /dev/null @@ -1,11 +0,0 @@ -AC_INIT(configure.in) - -AM_INIT_AUTOMAKE(libt2n-example, 0.1) - -AC_LANG_CPLUSPLUS -AC_PROG_CXX -AM_PROG_LIBTOOL - -LIBT2N_CHECK(libt2n = 0.1) - -AC_OUTPUT(Makefile) diff --git a/example-codegen/default.cpp b/example-codegen/default.cpp deleted file mode 100644 index 460b130..0000000 --- a/example-codegen/default.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "default_common.hxx" - -//! test pass by copy -LIBT2N_EXPORT std::string testfunc(std::string str) -{ - std::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; -} - -//! test pass by const reference -LIBT2N_EXPORT std::string testfunc_ref(const std::string &str) -{ - std::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; -} - -//! test builtin type -LIBT2N_EXPORT int t2(int i) -{ - return i; -} diff --git a/example-codegen/default.hxx b/example-codegen/default.hxx deleted file mode 100644 index 9a8d548..0000000 --- a/example-codegen/default.hxx +++ /dev/null @@ -1,9 +0,0 @@ -#include -// serialization of string -#include -// serialization of pair -#include - -// std::vector -#include -#include diff --git a/example-codegen/foo.hxx b/example-codegen/foo.hxx deleted file mode 100644 index 49d0197..0000000 --- a/example-codegen/foo.hxx +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FOO_HXX -#define FOO_HXX - -#include - -struct Foo -{ - int i,j; - - friend class boost::serialization::access; - template - void serialize(Archive & ar, const unsigned int /* version */) - { - ar & BOOST_SERIALIZATION_NVP(i); - ar & BOOST_SERIALIZATION_NVP(j); - } -}; - -BOOST_CLASS_VERSION(Foo, 1) - -#endif diff --git a/example-codegen/other-1.cpp b/example-codegen/other-1.cpp deleted file mode 100644 index b0898be..0000000 --- a/example-codegen/other-1.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "other_common.hxx" - -using namespace std; - -//! test function overload -LIBT2N_EXPORT int t3(int i) -{ - return i; -} - -//! test pair, multiple arguments and namespace -LIBT2N_EXPORT bool t3(int i, float f, const string &s, const pair &p) -{ - return (i==p.first) && (f==p.second) && (s=="hello"); -} - -//! test std::vector -LIBT2N_EXPORT bool t3(const std::vector &i) -{ - return (i.size()==1) && (i[0]==10); -} diff --git a/example-codegen/other-2.cpp b/example-codegen/other-2.cpp deleted file mode 100644 index 51a444a..0000000 --- a/example-codegen/other-2.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "other_common.hxx" - -//! test own type -LIBT2N_EXPORT bool t3(const Foo &foo) -{ - return (foo.i==foo.j); -} diff --git a/example-codegen/other.hxx b/example-codegen/other.hxx deleted file mode 100644 index dd931b5..0000000 --- a/example-codegen/other.hxx +++ /dev/null @@ -1,11 +0,0 @@ -#include -// serialization of string -#include -// serialization of pair -#include - -// std::vector -#include -#include - -#include "foo.hxx" diff --git a/example-codegen/server.cpp b/example-codegen/server.cpp deleted file mode 100644 index 4c96d97..0000000 --- a/example-codegen/server.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -#include "default_server.hxx" -#include "other_server.hxx" - -using namespace libt2n; - - -int main(int argc, char** argv) { - socket_server ss("./socket"); - socket_server ss_other("./socket_other"); - group_command_server cs(ss); - group_command_server cs_other(ss_other); - - // handle requests - while(true) { - cs.handle(1000); - cs_other.handle(1000); - } - - return 0; -} diff --git a/example-codegen/test b/example-codegen/test deleted file mode 100755 index 19fb9c3..0000000 --- a/example-codegen/test +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -o nounset -set -o errexit - -# todo handle separate build dir -./server & -SPID="$!" -# ugly -sleep 1 -if ./client; then - RET="0" -else - RET="1" -fi -kill "$SPID" -exit "$RET" diff --git a/example-libusage/Makefile.am b/example-libusage/Makefile.am deleted file mode 100644 index 5adf4a5..0000000 --- a/example-libusage/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -# not a GNU package. You can remove this line, if -# you have all needed files, that a GNU package needs -AUTOMAKE_OPTIONS = foreign - -INCLUDES = @DEFAULT_CFLAGS@ -LDADD = @DEFAULT_LIBS@ - -client_SOURCES = client.cpp - -bin_PROGRAMS = client diff --git a/example-libusage/README b/example-libusage/README deleted file mode 100644 index 1f39f2b..0000000 --- a/example-libusage/README +++ /dev/null @@ -1 +0,0 @@ -example how to use a installed library generated using libt2n-codegen diff --git a/example-libusage/client.cpp b/example-libusage/client.cpp deleted file mode 100644 index 7a98309..0000000 --- a/example-libusage/client.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004 by Intra2net AG * - * info@intra2net.com * - * * - ***************************************************************************/ - -#include - -// include generated library header -#include "default_client.hxx" - -int main(int argc, char** argv) -{ - libt2n::socket_client_connection sc("./socket"); - cmd_group_default_client cc(sc); - - bool throwok=false; - try - { - cc.testfunc("throw"); - }catch(libt2n::t2n_runtime_error &e){ - throwok=(std::string(e.what())=="throw me around"); - } - - return ( throwok - && ( cc.testfunc("hello") == "hello, testfunc() was here" ) - && ( cc.testfunc_ref("hello") == "hello, testfunc() was here" ) - && ( cc.t2(10) == 10 ) ) - ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/example-libusage/configure.in b/example-libusage/configure.in deleted file mode 100644 index 59a0210..0000000 --- a/example-libusage/configure.in +++ /dev/null @@ -1,11 +0,0 @@ -AC_INIT(configure.in) - -AM_INIT_AUTOMAKE(libt2n-clientexample, 0.1) - -AC_LANG_CPLUSPLUS -AC_PROG_CXX -AM_PROG_LIBTOOL - -PKG_CHECK_MODULES(DEFAULT, default = 0.1) - -AC_OUTPUT(Makefile) -- 1.7.1