00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019
00020 #include <string.h>
00021 #include <stdarg.h>
00022
00023 #include <iostream>
00024
00025 #include <assert_pp.h>
00026 #include <HeyParser.hh>
00027 #include <factory_library.h>
00028
00029 #include "AllupImpl.hh"
00030 #include "FactoryLibrary_ltdl.hh"
00031
00032
00033
00034
00035
00036
00037
00038
00039 static int afAllupHey(CORBA::ORB_ptr orb, HeyParser &hp)
00040 {
00041 static HeyPropertyInfo suites[] = {
00042 HeyPropertyInfo("library",
00043 (1L << HeyParser::CREATE_PROPERTY),
00044 "",
00045 "name:string - The library name/path.\n"
00046 "\n"
00047 "Create a FactoryLibrary object for a particular "
00048 "shared library.\n"
00049 "If the library is already loaded, return its IOR.\n"),
00050 HeyPropertyInfo("libraries",
00051 (1L << HeyParser::LIST_PROPERTIES),
00052 "",
00053 "List the names of the libraries currently open in "
00054 "the server.\n"),
00055 HeyPropertyInfo::HPI_NULL
00056 };
00057
00058 const char *prop_name, *prop_value;
00059 edu::utah::pces::Allup_var allup;
00060 int retval = EXIT_FAILURE;
00061 CORBA::Object_var obj;
00062
00063 require(!CORBA::is_nil(orb));
00064
00065 obj = orb->string_to_object(hp.who());
00066 allup = edu::utah::pces::Allup::_narrow(obj.in());
00067 if( CORBA::is_nil(allup.in()) )
00068 {
00069 throw CORBA::BAD_PARAM();
00070 }
00071
00072 switch( hp.what() )
00073 {
00074 case HeyParser::LIST_PROPERTIES:
00075 try
00076 {
00077 hp.popProperty(prop_name, prop_value);
00078 if( strcasecmp(prop_name, "libraries") == 0 )
00079 {
00080 edu::utah::pces::FactoryLibraryList_var fll;
00081 unsigned int lpc;
00082
00083 fll = allup->Libraries();
00084 for( lpc = 0; lpc < fll->length(); lpc++ )
00085 {
00086 CORBA::String_var name;
00087
00088 name = fll[lpc]->Name();
00089 cout << name << endl;
00090 }
00091 }
00092 else
00093 {
00094 cerr << "Unknown property: " << prop_name << endl;
00095 }
00096 }
00097 catch(const HeyParserException &e)
00098 {
00099 cout << "library" << endl;
00100 cout << "libraries" << endl;
00101 retval = EXIT_SUCCESS;
00102 }
00103 break;
00104 case HeyParser::CREATE_PROPERTY:
00105 hp.popProperty(prop_name, prop_value);
00106 if( strcasecmp(prop_name, "library") == 0 )
00107 {
00108 try
00109 {
00110 edu::utah::pces::FactoryLibrary_var fl;
00111
00112 fl = allup->OpenLibrary(hp.withValue("name"));
00113 if( !CORBA::is_nil(fl.in()) )
00114 {
00115 cout << orb->object_to_string(fl.in()) << endl;
00116 retval = EXIT_SUCCESS;
00117 }
00118 else
00119 {
00120 cerr << "Unknown error..." << endl;
00121 }
00122 }
00123 catch(const edu::utah::pces::NoSuchLibrary &e)
00124 {
00125 cerr << "Error: No such library '"
00126 << e.name
00127 << "': "
00128 << e.message
00129 << endl;
00130 }
00131 catch(const HeyParserException &e)
00132 {
00133 cerr << "Name not specified!\n";
00134 }
00135 }
00136 else
00137 {
00138 cerr << "Unknown property: " << prop_name << endl;
00139 }
00140 break;
00141 case HeyParser::SHUTDOWN:
00142 try
00143 {
00144 allup->Shutdown();
00145 }
00146 catch(const CORBA::COMM_FAILURE &e)
00147 {
00148
00149 }
00150 cout << "ok" << endl;
00151 retval = EXIT_SUCCESS;
00152 break;
00153 case HeyParser::GET_SUITES:
00154 try
00155 {
00156 hp.popProperty(prop_name, prop_value);
00157 }
00158 catch(const HeyParserException &e)
00159 {
00160 cout << suites;
00161 retval = EXIT_SUCCESS;
00162 }
00163 break;
00164 default:
00165 cerr << "Unknown verb..." << endl;
00166 break;
00167 }
00168 return( retval );
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178 static int afFactoryLibraryHey(CORBA::ORB_ptr orb, HeyParser &hp)
00179 {
00180 edu::utah::pces::FactoryLibrary_var fl;
00181 CORBA::String_var out, err;
00182 int retval = EXIT_FAILURE;
00183 CORBA::Object_var obj;
00184
00185 require(!CORBA::is_nil(orb));
00186
00187 obj = orb->string_to_object(hp.who());
00188 fl = edu::utah::pces::FactoryLibrary::_narrow(obj.in());
00189 if( CORBA::is_nil(fl.in()) )
00190 {
00191 throw CORBA::BAD_PARAM();
00192 }
00193
00194 retval = fl->Hey(edu::utah::pces::ArgV(hp.getArgCount(),
00195 hp.getArgCount(),
00196 (char **)hp.getArgValues()),
00197 out.out(),
00198 err.out());
00199
00200 cout << out;
00201 cerr << err;
00202
00203 return( retval );
00204 }
00205
00206 int FACTORY_METHOD_SYMBOL(factory_library_op_t op, int tag, va_list args)
00207 {
00208 int retval = ENOSYS;
00209
00210 struct {
00211 const char *hey_server_hint;
00212 HeyParser *hey_parser;
00213 CORBA::ORB_ptr orb;
00214 PortableServer::POA_ptr poa;
00215 } attr = {
00216 NULL,
00217 NULL,
00218 NULL,
00219 PortableServer::POA::_nil(),
00220 };
00221
00222 while( tag != FMA_TAG_DONE )
00223 {
00224 switch( tag )
00225 {
00226 case FMA_ORB:
00227 attr.orb = va_arg(args, CORBA::ORB_ptr);
00228 break;
00229 case FMA_POA:
00230 attr.poa = va_arg(args, PortableServer::POA_ptr);
00231 break;
00232 case FMA_HeyParser:
00233 attr.hey_parser = va_arg(args, HeyParser *);
00234 break;
00235 case FMA_HeyServerHint:
00236 attr.hey_server_hint = va_arg(args, const char *);
00237 break;
00238 default:
00239 break;
00240 }
00241 tag = va_arg(args, int);
00242 }
00243
00244 switch( op )
00245 {
00246 case FLO_QUERY:
00247 if( attr.hey_server_hint != NULL )
00248 {
00249 if( (strcmp(attr.hey_server_hint,
00250 "IDL:edu/utah/pces/Allup:1.0") == 0) ||
00251 (strcmp(attr.hey_server_hint,
00252 "IDL:edu/utah/pces/FactoryLibrary:1.0") == 0) )
00253 {
00254 retval = EXIT_SUCCESS;
00255 }
00256 else
00257 {
00258 }
00259 }
00260 else
00261 {
00262 cout << "\tIDL:edu/utah/pces/Allup:1.0" << endl
00263 << "\tIDL:edu/utah/pces/FactoryLibrary:1.0" << endl;
00264 }
00265 break;
00266 case FLO_HEY:
00267 if( attr.hey_server_hint != NULL )
00268 {
00269 try
00270 {
00271 if( strcmp(attr.hey_server_hint,
00272 "IDL:edu/utah/pces/Allup:1.0") == 0 )
00273 {
00274 retval = afAllupHey(attr.orb, *attr.hey_parser);
00275 }
00276 else if( strcmp(attr.hey_server_hint,
00277 "IDL:edu/utah/pces/FactoryLibrary:1.0") == 0 )
00278 {
00279 retval = afFactoryLibraryHey(attr.orb, *attr.hey_parser);
00280 }
00281 else
00282 {
00283 }
00284 }
00285 catch(const HeyParserException &he)
00286 {
00287 cerr << "Parse error: " << he << endl;
00288 }
00289 catch(const CORBA::SystemException &e)
00290 {
00291 cerr << "Caught Exception: " << e << endl;
00292 }
00293 catch(...)
00294 {
00295 cerr << "Caught an unhandled exception" << endl;
00296 }
00297 }
00298 else
00299 {
00300 }
00301 break;
00302 default:
00303 break;
00304 }
00305
00306 return( retval );
00307 }