X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=examples-codegen%2Fexample1-client-wrapper%2Fclient.cpp;fp=examples-codegen%2Fexample1-client-wrapper%2Fclient.cpp;h=86a2802cb8742dad8a861b80412a333f665955c2;hp=0000000000000000000000000000000000000000;hb=393e7b700efffc748e593661b365ead414a341c1;hpb=c99918d6ed784eec9576d8641c62dd3153089414 diff --git a/examples-codegen/example1-client-wrapper/client.cpp b/examples-codegen/example1-client-wrapper/client.cpp new file mode 100644 index 0000000..86a2802 --- /dev/null +++ b/examples-codegen/example1-client-wrapper/client.cpp @@ -0,0 +1,32 @@ +// for a wrapped socket connection +#include + +// include generated library header +#include "t2nexample_client.hxx" + +// define a type for more conveniant access +typedef libt2n::T2nSingletonWrapper wraptype; + +// static object which keeps the wrapper-singleton +template<> +std::auto_ptr wraptype::SingletonObject = std::auto_ptr(); + +// static object which keeps the connection +template<> +std::auto_ptr wraptype::WrappedConnection = + std::auto_ptr(); + +int main(int argc, char** argv) +{ + // tell the client-wrapper how to contact the server if a connection is requested + wraptype::set_connection(std::auto_ptr + (new libt2n::ReconnectSocketWrapper("./socket"))); + + std::string result; + + // execute a function via t2n. The wrapper will open a connection to the server if none + // exists or try to reconnect if the existing one doesn't answer + std::cout << t2n_exec(&cmd_group_t2nexample_client::testfunc)("hello") << endl; + + return EXIT_SUCCESS; +}