Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

TaskFactory.cc

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

Generated on Mon Dec 1 16:29:07 2003 for CPU Broker by doxygen 1.3.4