TEcho.cxx

Go to the documentation of this file.
00001 // @(#)root/clarens:$Id: TEcho.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Maarten Ballintijn   25/10/2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TEcho                                                                //
00015 //                                                                      //
00016 //                                                                      //
00017 //////////////////////////////////////////////////////////////////////////
00018 
00019 #include "TEcho.h"
00020 
00021 
00022 #include "xmlrpc.h"
00023 #include "xmlrpc_client.h"
00024 
00025 
00026 #include "TString.h"
00027 #include "TXmlRpc.h"
00028 #include "TStopwatch.h"
00029 #include "Riostream.h"
00030 
00031 
00032 ClassImp(TEcho)
00033 
00034 
00035 //______________________________________________________________________________
00036 TEcho::TEcho(TXmlRpc *rpc)
00037    : TClProxy("echo", rpc)
00038 {
00039 }
00040 
00041 
00042 //______________________________________________________________________________
00043 Bool_t TEcho::Echo(const Char_t *in, TString &out)
00044 {
00045    xmlrpc_env *env = fRpc->GetEnv();
00046 
00047    xmlrpc_value *arg = xmlrpc_build_value(env, "(s)", in);
00048    if (RpcFailed("Echo", "encode argument")) return kFALSE;
00049 
00050    xmlrpc_value *retval = fRpc->Call("echo", arg);
00051    if (RpcFailed("Echo", "call")) return kFALSE;
00052 
00053    if (gDebug>1) fRpc->PrintValue(retval);
00054 
00055    char *o;
00056    xmlrpc_parse_value(env, retval, "(s)", &o);
00057    if (RpcFailed("Echo", "decode")) return kFALSE;
00058 
00059    out = o;
00060 
00061    xmlrpc_DECREF (arg);
00062    xmlrpc_DECREF (retval);
00063 
00064       return kTRUE;
00065 }
00066 
00067 
00068 //______________________________________________________________________________
00069 Bool_t TEcho::Hostname(TString &name, TString &ip)
00070 {
00071    xmlrpc_env *env = fRpc->GetEnv();
00072 
00073    xmlrpc_value *retval = fRpc->Call("hostname", 0);
00074    if (RpcFailed("Hostname", "call")) return kFALSE;
00075 
00076    if (gDebug>1) fRpc->PrintValue(retval);
00077 
00078    char *n, *i;
00079    xmlrpc_parse_value(env, retval, "(ss)", &n, &i);
00080    if (RpcFailed("Hostname", "decode")) return kFALSE;
00081 
00082    name = n;
00083    ip = i;
00084 
00085    xmlrpc_DECREF (retval);
00086 
00087    return kTRUE;
00088 }
00089 
00090 
00091 //______________________________________________________________________________
00092 void TEcho::Benchmark(Int_t iterations)
00093 {
00094    TStopwatch timer;
00095    TString out;
00096 
00097    for(Int_t i = 0; i < iterations ; i++) {
00098       Echo("Dummy test string", out);
00099    }
00100 
00101    timer.Stop();
00102 
00103    cout <<
00104       "Elapsed time is " << timer.RealTime() << " s, " <<
00105       iterations / timer.RealTime() << " calls/s for " <<
00106       iterations << " calls" << endl;
00107 }
00108 

Generated on Tue Jul 5 14:50:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1