00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <OB/CORBA.h>
00024 #include <OB/CosNaming.h>
00025 #include <ServerTime.h>
00026 #include "BridgeStub.h"
00027 #include "SoapBridge.h"
00028 #include "SoapBridge_skel.h"
00029
00030 CORBA::ORB_var orb;
00031 ServerTime::Time_var tv;
00032 bool running = true;
00033
00034 class Overhead : public JTCMonitor
00035 {
00036 public:
00037 double mn, mx, sm, cn;
00038
00039 Overhead ()
00040 {
00041 mn = 100000;
00042 mx = -100000;
00043 cn = sm = 0;
00044 };
00045 void Stats (double ov)
00046 {
00047 JTCSynchronized sync (*this);
00048 if (ov < mn) mn = ov;
00049 if (ov > mx) mx = ov;
00050 sm += ov;
00051 cn ++;
00052 printf ("%8.3lf %8.3lf/%5.0lf=%8.3lf %8.3lf\r", mn, sm, cn, sm / cn, mx);
00053 fflush (stdout);
00054 };
00055 } *OV;
00056
00057 class Torture : public JTCThread
00058 {
00059 public:
00060 int wt;
00061
00062 virtual void run ()
00063 {
00064 JTCThread::sleep (500 + wt);
00065 while (running) {
00066 int w4 = 1;
00067 double start = -sec_u ();
00068 try {
00069 tv->WaitThisLong (w4);
00070 }
00071 catch (...) {
00072 printf ("\n\n**** test failed ****\n\n");
00073 return;
00074 }
00075 start += sec_u ();
00076 OV->Stats (start - (double) w4);
00077 }
00078 }
00079 };
00080
00081 class CORBACallback_impl : virtual public POA_SOAPBridge::CORBACallback
00082 {
00083 public:
00084 CORBACallback_impl ()
00085 {
00086 };
00087 ~CORBACallback_impl ()
00088 {
00089 };
00090 void tellMe (const char *sa, const char *ifn, const char *mtn, const char *ctx, const char *err)
00091 throw (CORBA::SystemException)
00092 {
00093 running = false;
00094 printf ("\n\nInvocation failure!\n");
00095 printf ("\tSOAP address was: %s\n", sa);
00096 printf ("\tInterface name : %s\n", ifn);
00097 printf ("\tInterface method: %s\n", mtn);
00098 printf ("\tContext key : %s\n", ctx);
00099 printf ("\tFailure reason : %s\n", err);
00100 };
00101 };
00102
00103 int main (int argc, char *argv [])
00104 {
00105 JTCInitialize initialize;
00106 OV = new Overhead;
00107 int ntr = (argc == 2) ? atoi (argv [1]) : 5;
00108 try {
00109 CosNaming::Name name;
00110 CosNaming::NamingContext_var inc;
00111 CosNaming::NamingContext_var myinc;
00112 orb = CORBA::ORB_init(argc, argv);
00113 try {
00114 CORBA::Object_var poaObj = orb->resolve_initial_references ("RootPOA");
00115 PortableServer::POA_var poa = PortableServer::POA::_narrow (poaObj);
00116 PortableServer::POAManager_var mgr = poa->the_POAManager ();
00117 mgr->activate ();
00118 CORBA::Object_var obj = orb->resolve_initial_references ("NameService");
00119 inc = CosNaming::NamingContext::_narrow (obj);
00120 assert (!CORBA::is_nil (inc));
00121 name.length (2);
00122 printf ("Resolving 'SOAPBridge/CORBACall'\n");
00123 name [0].id = CORBA::string_dup ("SOAPBridge");
00124 name [0].kind = CORBA::string_dup ("");
00125 name [1].id = CORBA::string_dup ("CORBACall");
00126 name [1].kind = CORBA::string_dup ("");
00127 try {
00128 CORBA::Object_var ccObj = inc->resolve (name);
00129 SOAPBridge::CORBACall_var cc = SOAPBridge::CORBACall::_narrow (ccObj);
00130 CORBACallback_impl cb;
00131 obj = cc->CreateSession ("http://soap2corba/cgi-bin/SBCGI.xml", "ServerTime/Time", 1,
00132 cb._this ());
00133 {
00134 CORBA::String_var whatCtx = cc->contextKey ();
00135 printf ("We've been assigned context: %s\n", (char *) whatCtx);
00136 }
00137 tv = ServerTime::Time::_narrow (obj);
00138
00139 tv->WaitThisLong (1);
00140 int i;
00141 for (i = 0; running && i < ntr; i ++) {
00142 JTCHandleT<Torture> t = new Torture;
00143 t->wt = i * 20;
00144 t->start ();
00145 }
00146 }
00147 catch (...) {
00148 printf ("Failed\n");
00149 return 1;
00150 }
00151 printf ("Test initialization done.\n");
00152 orb->run ();
00153 }
00154 catch (...) {
00155 printf ("NameService down?\n");
00156 return 1;
00157 }
00158 }
00159 catch (...) {
00160 printf ("Oops!\n");
00161 return 1;
00162 }
00163 return 0;
00164 }
00165