00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019
00020 #include <errno.h>
00021 #include <string.h>
00022 #include <stdarg.h>
00023 #include <stdlib.h>
00024
00025 #include <iostream>
00026
00027 #include <assert_pp.h>
00028 #include <HeyParser.hh>
00029 #include <factory_library.h>
00030
00031 #include "RealTimeTaskDelegateImpl.hh"
00032 #include "StrictPolicyDelegateImpl.hh"
00033
00034 using namespace std;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 static int dfHey(CORBA::ORB_ptr orb, HeyParser &hp, ostream &out, ostream &err)
00046 {
00047 static HeyPropertyInfo suites[] = {
00048 HeyPropertyInfo("real-time-task-delegate",
00049 (1L << HeyParser::CREATE_PROPERTY),
00050 "",
00051 "Create a RealTimeTaskDelegate object.\n"),
00052 HeyPropertyInfo("strict-policy-delegate",
00053 (1L << HeyParser::CREATE_PROPERTY),
00054 "",
00055 "Create a StrictPolicyDelegate object.\n"),
00056 HeyPropertyInfo::HPI_NULL
00057 };
00058
00059 const char *prop_name, *prop_value;
00060 int retval = EXIT_FAILURE;
00061
00062 require(!CORBA::is_nil(orb));
00063
00064 switch( hp.what() )
00065 {
00066 case HeyParser::LIST_PROPERTIES:
00067 try
00068 {
00069 hp.popProperty(prop_name, prop_value);
00070 }
00071 catch(const HeyParserException &e)
00072 {
00073 out << "real-time-task-delegate" << endl;
00074 }
00075 break;
00076 case HeyParser::CREATE_PROPERTY:
00077 hp.popProperty(prop_name, prop_value);
00078 if( strcasecmp(prop_name, "real-time-task-delegate") == 0 )
00079 {
00080 RealTimeTaskDelegateImpl *rttdi;
00081 BrokerDelegates::RealTimeTaskDelegate_var rttd;
00082
00083 rttdi = new RealTimeTaskDelegateImpl();
00084 rttd = rttdi->_this();
00085 out << orb->object_to_string(rttd._retn()) << endl;
00086 retval = EXIT_SUCCESS;
00087 }
00088 else if( strcasecmp(prop_name, "strict-policy-delegate") == 0 )
00089 {
00090 StrictPolicyDelegateImpl *spdi;
00091 BrokerDelegates::StrictPolicyDelegate_var spd;
00092
00093 spdi = new StrictPolicyDelegateImpl();
00094 spd = spdi->_this();
00095 out << orb->object_to_string(spd._retn()) << endl;
00096 retval = EXIT_SUCCESS;
00097 }
00098 else
00099 {
00100 err << "Unknown property: " << prop_name << endl;
00101 }
00102 break;
00103 case HeyParser::GET_SUITES:
00104 out << suites;
00105 retval = EXIT_SUCCESS;
00106 break;
00107 }
00108 return( retval );
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118 static int dfDelegateHey(CORBA::ORB_ptr orb, HeyParser &hp)
00119 {
00120 static HeyPropertyInfo suites[] = {
00121 HeyPropertyInfo("remote-object",
00122 (1L << HeyParser::SET_PROPERTY) |
00123 (1L << HeyParser::GET_PROPERTY),
00124 "",
00125 "Get or set the object to delegate to.\n"),
00126 HeyPropertyInfo("insert",
00127 (1L << HeyParser::EXECUTE_PROPERTY),
00128 "",
00129 "delegate:object - The delegate to insert.\n"
00130 "\n"
00131 "Insert another delegate between this object and the\n"
00132 "remote object.\n"),
00133 HeyPropertyInfo::HPI_NULL
00134 };
00135
00136 const char *prop_name, *prop_value, *to_value;
00137 BrokerDelegates::Delegate_var delegate;
00138 int retval = EXIT_FAILURE;
00139 CORBA::Object_var obj;
00140
00141 obj = orb->string_to_object(hp.who());
00142 delegate = BrokerDelegates::Delegate::_narrow(obj.in());
00143 if( CORBA::is_nil(delegate.in()) )
00144 {
00145 throw CORBA::BAD_PARAM();
00146 }
00147
00148 switch( hp.what() )
00149 {
00150 case HeyParser::LIST_PROPERTIES:
00151 try
00152 {
00153 hp.popProperty(prop_name, prop_value);
00154 }
00155 catch(const HeyParserException &e)
00156 {
00157 cout << "remote-object" << endl;
00158 retval = EXIT_SUCCESS;
00159 }
00160 break;
00161 case HeyParser::GET_PROPERTY:
00162 hp.popProperty(prop_name, prop_value);
00163 if( strcasecmp(prop_name, "remote-object") == 0 )
00164 {
00165 obj = delegate->GetDelegateAttributeObject(prop_name);
00166 cout << orb->object_to_string(obj.in()) << endl;
00167 retval = EXIT_SUCCESS;
00168 }
00169 else
00170 {
00171 try
00172 {
00173 CORBA::Any *any;
00174
00175 any = delegate->GetDelegateAttribute(prop_name);
00176 cout << "ok" << endl;
00177 }
00178 catch(const CORBA::BAD_PARAM &e)
00179 {
00180 cerr << "Unknown property: " << prop_name << endl;
00181 }
00182 }
00183 break;
00184 case HeyParser::SET_PROPERTY:
00185 hp.popProperty(prop_name, prop_value);
00186 if( strcasecmp(prop_name, "remote-object") == 0 )
00187 {
00188 to_value = hp.to();
00189 obj = orb->string_to_object(to_value);
00190 delegate->SetDelegateAttributeObject(prop_name, obj.in());
00191 cout << "ok" << endl;
00192 retval = EXIT_SUCCESS;
00193 }
00194 else
00195 {
00196 try
00197 {
00198 CORBA::Any any;
00199
00200 any <<= hp.to();
00201 delegate->SetDelegateAttribute(prop_name, any);
00202 cout << "ok" << endl;
00203 retval = EXIT_SUCCESS;
00204 }
00205 catch(const CORBA::BAD_PARAM &e)
00206 {
00207 cerr << "Unknown property: " << prop_name << endl;
00208 }
00209 }
00210 break;
00211 case HeyParser::EXECUTE_PROPERTY:
00212 hp.popProperty(prop_name, prop_value);
00213 if( strcasecmp(prop_name, "insert") == 0 )
00214 {
00215 BrokerDelegates::Delegate_var interposer;
00216 CORBA::Object_var remote_object;
00217
00218 obj = orb->string_to_object(hp.withValue("delegate"));
00219 interposer = BrokerDelegates::Delegate::_narrow(obj.in());
00220 if( CORBA::is_nil(interposer.in()) )
00221 {
00222 cerr << "Error: delegate value not a Delegate\n" << endl;
00223 throw CORBA::BAD_PARAM();
00224 }
00225
00226 remote_object = delegate->
00227 GetDelegateAttributeObject("remote-object");
00228 if( CORBA::is_nil(remote_object.in()) )
00229 {
00230 cerr << "Error: no remote object to interpose on.\n" << endl;
00231 throw CORBA::BAD_PARAM();
00232 }
00233
00234 interposer->SetDelegateAttributeObject("remote-object",
00235 remote_object.in());
00236 delegate->SetDelegateAttributeObject("remote-object",
00237 interposer.in());
00238 cout << "ok" << endl;
00239 retval = EXIT_SUCCESS;
00240 }
00241 else
00242 {
00243 cerr << "Unknown property: " << prop_name << endl;
00244 }
00245 break;
00246 case HeyParser::GET_SUITES:
00247 try
00248 {
00249 hp.popProperty(prop_name, prop_value);
00250 cerr << "Unknown property: " << prop_name << endl;
00251 }
00252 catch(const HeyParserException &e)
00253 {
00254 cout << suites;
00255 retval = EXIT_SUCCESS;
00256 }
00257 break;
00258 default:
00259 cerr << "Unknown verb..." << endl;
00260 break;
00261 }
00262 return( retval );
00263 }
00264
00265 int FACTORY_METHOD_SYMBOL(factory_library_op_t op, int tag, va_list args)
00266 {
00267 int retval = EXIT_FAILURE;
00268
00269 struct {
00270 const char *hey_server_hint;
00271 HeyParser *hey_parser;
00272 CORBA::ORB_ptr orb;
00273 ostream *out;
00274 ostream *err;
00275 } attr = {
00276 NULL,
00277 NULL,
00278 NULL,
00279 NULL,
00280 NULL,
00281 };
00282
00283 while( tag != FMA_TAG_DONE )
00284 {
00285 switch( tag )
00286 {
00287 case FMA_ORB:
00288 attr.orb = va_arg(args, CORBA::ORB_ptr);
00289 break;
00290 case FMA_HeyParser:
00291 attr.hey_parser = va_arg(args, HeyParser *);
00292 break;
00293 case FMA_HeyServerHint:
00294 attr.hey_server_hint = va_arg(args, const char *);
00295 break;
00296 case FMA_StandardOut:
00297 attr.out = va_arg(args, ostream *);
00298 break;
00299 case FMA_StandardError:
00300 attr.err = va_arg(args, ostream *);
00301 break;
00302 default:
00303 break;
00304 }
00305 tag = va_arg(args, int);
00306 }
00307
00308 switch( op )
00309 {
00310 case FLO_QUERY:
00311 if( attr.hey_server_hint != NULL )
00312 {
00313 if( strcmp(attr.hey_server_hint,
00314 "IDL:BrokerDelegates/Delegate:1.0") == 0 )
00315 {
00316 retval = EXIT_SUCCESS;
00317 }
00318 else
00319 {
00320 }
00321 }
00322 else
00323 {
00324 cout << "\tIDL:BrokerDelegates/Delegate:1.0" << endl;
00325 }
00326 break;
00327 case FLO_HEY:
00328 if( attr.hey_server_hint != NULL )
00329 {
00330 try
00331 {
00332 if( strcmp(attr.hey_server_hint,
00333 "IDL:BrokerDelegates/Delegate:1.0") == 0 )
00334 {
00335 retval = dfDelegateHey(attr.orb, *attr.hey_parser);
00336 }
00337 else
00338 {
00339 }
00340 }
00341 catch(const HeyParserException &he)
00342 {
00343 cerr << "Parse error: " << he << endl;
00344 }
00345 catch(const CORBA::SystemException &e)
00346 {
00347 cerr << "Caught Exception: " << e << endl;
00348 }
00349 catch(...)
00350 {
00351 cerr << "Caught an unhandled exception" << endl;
00352 }
00353 }
00354 else
00355 {
00356 retval = dfHey(attr.orb, *attr.hey_parser, *attr.out, *attr.err);
00357 }
00358 break;
00359 default:
00360 break;
00361 }
00362
00363 return( retval );
00364 }