we do not want to ship .svn directories
[libt2n] / doc / index.doc
index 874f67d..d3bbadc 100644 (file)
@@ -20,6 +20,9 @@
  The code generator is used to create the client and server stubs for the marked procedures. The procedures can be grouped and each group maps to two classes (cmd_group_... and cmd_group_..._client). The cmd_group_..._client class provides the interface to call remote procedures. Each remote procedure maps to a method of this class and the constructor takes a connection object establishing the binding to the remote side. For each group the code generator is called and generates 6 output files: group_common.hxx, group_common.cpp, group_client.hxx, group_client.cpp, group_server.hxx, group_server.cpp. The _common files are used by client and server whereas the _client files contain the client stub code (the cmd_group_..._client class) and the _server files the server stub code. 
  \par
  To simplify the build process a Makefile snippet is provided that allows to create a server program and a client library (including a corresponding .pc file) using the autotools easily.
+ \section License
+ The libt2n libaray is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. The code generator (libt2n-codegen) is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+
  \section install_sec Installation
 
  \subsection requirements Requirements
@@ -39,7 +42,7 @@
  \endverbatim
 
  \subsection Usage
- Take a look at the example file:../../../libt2n-examples/doc/html/index.html
+ Take a look at the \ref example.
 
  \subsection References
  - \anchor notes1
  - \anchor notes6
  [6] boost serialization, http://www.boost.org/libs/serialization/doc/
 */
+
+/*! \page example Usage example
+
+ In this example we create two packages using the autotools:
+ - server program and client library to connect to the server. The server exports a simple procedure using one group: "t2nexample"
+ - client program using the library
+
+ \section server Example server program and client library
+
+ \par The procedure to export (input for the code generator - libt2n-codegen): t2nexample.cpp:
+ First the procedure to export is defined. In this example the procedure throws an exception if the input string is "throw". The exception is passed back to the client transparently. Otherwise some text is appended and returned.
+ \include example1/t2nexample.cpp
+
+ \par Required includes go into the group header file: t2nexample.hxx:
+ All includes required to get the declarations of the types used by the procedures to export go into the group header file. libt2n uses boost for serialization. This means all types involved in a remote procedure call must be boost serializable. In this example we only use std::string provided by <string> and boost already provides serialization for std::string in the boost/serialization/string.hpp header file.
+ \include example1/t2nexample.hxx
+
+ \par The server program: server.cpp:
+ We have to provide the main entry point for the server program. In this example we use a local socket and the server program simply waits until a request.is received which then is handled by the generated code directly.
+ \include example1/server.cpp
+
+ \par Using autoconf and automake to build a example server program and a client library.
+ In the configure.in(.ac) we check for libt2n using the LIBT2N_CHECK m4 macro provided by libt2n.
+ \verbinclude example1/configure.in
+ Writing the Makefile.am isn't difficult either. We have to list the command groups used. For each command group we have to list the C++ source files with the procedures to export. For each group we build a client library by listing the generated client code (group_client.cpp) in a corresponding libtool library target. The .pc file for the library is generated automatically. The sources of the server program must include the generated server code (group_server.cpp), the file with the main entry point and of course the procedure definition.
+ \verbinclude example1/Makefile.am
+
+ \par Build and install the package
+ To build and install the package we first have to create the configure script and the other help scripts of the autotools by running autoreconf.
+ \verbatim
+ autoreconf -f -i && ./configure && make install
+ \endverbatim
+
+ \section client Client using the library
+ Using the library is as simple as using any other library using pkg-config (the pkg-config .pc file is created automatically by the included Makefile snippet)
+ \par We only have to check that the library is installed
+ \verbinclude example1-client/configure.in
+ \par The Makefile.am needs nothing special
+ \verbinclude example1-client/Makefile.am
+ \par The client program: client.cpp:
+ The example client first connects to the local socket. The connection is passed to the constructor of the generated class. To call the remote procedure the "testfunc" method is called. The example first passes "throw" to the remote procedure which will result in a exception to be thrown which is passed back to the client and thrown on the client side again. In the example the exception is caught and it is checked whether the string returned by what() is correct. If so a second remote procedure call is made and its return value is checked. Only if both tests succeed the program will exit with a status value indicating success.
+ \include example1-client/client.cpp
+
+ \par Build and install the package
+ \verbatim
+ autoreconf -f -i && ./configure && make install
+ \endverbatim
+
+ \par Test
+ To test whether it works we first start the server that creates a socket 'socket' in the current working directory. Then we run the client and print "ok" if it exited with a status value indicating success.
+ \verbatim
+$ cd /tmp
+$ file socket
+socket: cannot open `socket' (No such file or directory)
+$ libt2n-example1-server &
+[1] 7711
+$ file socket
+socket: socket
+$ libt2n-example1-client && echo ok
+ok
+$ kill %1
+$ rm socket
+ \endverbatim
+*/