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

TaskFactory.cc

Go to the documentation of this file.
00001 /*
00002  * TaskFactory.cc
00003  *
00004  * Copyright (c) 2003, 2004 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 #include "MinMaxTaskAdvocate.hh"
00038 
00039 #if defined(HAVE_LIBRK)
00040 #include "RKObserverAdvocate.hh"
00041 #endif
00042 
00043 using namespace std;
00044 
00045 /**
00046  * Handle 'hey's directed at the library.
00047  *
00048  * @param orb Pointer to the ORB.
00049  * @param poa The POA to use when instantiating objects.
00050  * @param hp The HeyParser that describes the action to take.
00051  * @param out Standard out.
00052  * @param err Standard error.
00053  * @return Zero on success, an errno value otherwise.
00054  */
00055 static int tfHey(CORBA::ORB_ptr orb,
00056                  PortableServer::POA_ptr poa,
00057                  HeyParser &hp,
00058                  ostream &out,
00059                  ostream &err)
00060 {
00061     static HeyPropertyInfo suites[] = {
00062         HeyPropertyInfo("logging-advocate",
00063                         (1L << HeyParser::CREATE_PROPERTY),
00064                         "",
00065                         "Create a LoggingAdvocate object.  This is a "
00066                         "decorator that you can use to log\n"
00067                         "advocate activity at different points in the chain."
00068                         "\n"),
00069         HeyPropertyInfo("max-decay-task-advocate",
00070                         (1L << HeyParser::CREATE_PROPERTY),
00071                         "",
00072                         "Create a MaxDecayTaskAdvocate object.  This advocate "
00073                         "sends an advice that\n"
00074                         "reflects the highest value seen in the last N "
00075                         "periods.\n"),
00076         HeyPropertyInfo("min-max-task-advocate",
00077                         (1L << HeyParser::CREATE_PROPERTY),
00078                         "",
00079                         "Create a MinMaxTaskAdvocate object.  This advocate "
00080                         "bounds an advice to a\n"
00081                         "user specified minimum and maximum.\n"),
00082         HeyPropertyInfo("glacial-task-advocate",
00083                         (1L << HeyParser::CREATE_PROPERTY),
00084                         "",
00085                         "Create a GlacialTaskAdvocate object.  This advocate "
00086                         "is slow to react to changes\n"
00087                         "in the observed CPU usage.\n"),
00088 #if defined(HAVE_LIBRK)
00089         HeyPropertyInfo("rk-observer-advocate",
00090                         (1L << HeyParser::CREATE_PROPERTY),
00091                         "",
00092                         "Create a RKObserverAdvocate object.  This advocate "
00093                         "will observe a resource set\n"
00094                         "and automatically make reports on behalf of the "
00095                         "task.\n"),
00096 #endif
00097 #if defined(HAVE_QUO)
00098         HeyPropertyInfo("quo-advocate",
00099                         (1L << HeyParser::CREATE_PROPERTY),
00100                         "",
00101                         "Create a QuoAdvocate object.  This is a decorator "
00102                         "that sends updates to QuO\n"
00103                         "system condition objects.\n"),
00104 #endif
00105         HeyPropertyInfo::HPI_NULL
00106     };
00107 
00108     const char *prop_name, *prop_value;
00109     int retval = EXIT_FAILURE;
00110 
00111     require(!CORBA::is_nil(orb));
00112     require(!CORBA::is_nil(poa));
00113 
00114     switch( hp.what() )
00115     {
00116     case HeyParser::LIST_PROPERTIES:
00117         try
00118         {
00119             hp.popProperty(prop_name, prop_value);
00120         }
00121         catch(const HeyParserException &e)
00122         {
00123             out << "logging-advocate" << endl;
00124             out << "max-decay-task-advocate" << endl;
00125             out << "min-max-task-advocate" << endl;
00126             out << "glacial-task-advocate" << endl;
00127             out << "rk-observer-advocate" << endl;
00128 #if defined(HAVE_QUO)
00129             out << "quo-advocate" << endl;
00130 #endif
00131         }
00132         break;
00133     case HeyParser::CREATE_PROPERTY:
00134         hp.popProperty(prop_name, prop_value);
00135         if( strcasecmp(prop_name, "logging-advocate") == 0 )
00136         {
00137             BrokerDelegates::RealTimeTaskDelegate_var rttd;
00138             LoggingAdvocate *la = new LoggingAdvocate();
00139             PortableServer::ObjectId_var oid;
00140             
00141             oid = poa->activate_object(la);
00142             rttd = BrokerDelegates::RealTimeTaskDelegate::
00143                 _narrow(poa->id_to_reference(oid.in()));
00144             out << orb->object_to_string(rttd._retn()) << endl;
00145             retval = EXIT_SUCCESS;
00146         }
00147         else if( strcasecmp(prop_name, "max-decay-task-advocate") == 0 )
00148         {
00149             MaxDecayTaskAdvocate *mdta = new MaxDecayTaskAdvocate();
00150             BrokerDelegates::RealTimeTaskDelegate_var rttd;
00151             PortableServer::ObjectId_var oid;
00152             
00153             oid = poa->activate_object(mdta);
00154             rttd = BrokerDelegates::RealTimeTaskDelegate::
00155                 _narrow(poa->id_to_reference(oid.in()));
00156             out << orb->object_to_string(rttd._retn()) << endl;
00157             retval = EXIT_SUCCESS;
00158         }
00159         else if( strcasecmp(prop_name, "min-max-task-advocate") == 0 )
00160         {
00161             MinMaxTaskAdvocate *mmta = new MinMaxTaskAdvocate();
00162             BrokerDelegates::RealTimeTaskDelegate_var rttd;
00163             PortableServer::ObjectId_var oid;
00164             
00165             oid = poa->activate_object(mmta);
00166             rttd = BrokerDelegates::RealTimeTaskDelegate::
00167                 _narrow(poa->id_to_reference(oid.in()));
00168             out << orb->object_to_string(rttd._retn()) << endl;
00169             retval = EXIT_SUCCESS;
00170         }
00171         else if( strcasecmp(prop_name, "glacial-task-advocate") == 0 )
00172         {
00173             GlacialTaskAdvocate *gta = new GlacialTaskAdvocate();
00174             BrokerDelegates::RealTimeTaskDelegate_var rttd;
00175             PortableServer::ObjectId_var oid;
00176             
00177             oid = poa->activate_object(gta);
00178             rttd = BrokerDelegates::RealTimeTaskDelegate::
00179                 _narrow(poa->id_to_reference(oid.in()));
00180             out << orb->object_to_string(rttd._retn()) << endl;
00181             retval = EXIT_SUCCESS;
00182         }
00183 #if defined(HAVE_LIBRK)
00184         else if( strcasecmp(prop_name, "rk-observer-advocate") == 0 )
00185         {
00186             RKObserverAdvocate *rkoa = new RKObserverAdvocate();
00187             BrokerDelegates::RealTimeTaskDelegate_var rttd;
00188             PortableServer::ObjectId_var oid;
00189             
00190             oid = poa->activate_object(rkoa);
00191             rttd = BrokerDelegates::RealTimeTaskDelegate::
00192                 _narrow(poa->id_to_reference(oid.in()));
00193             out << orb->object_to_string(rttd._retn()) << endl;
00194             retval = EXIT_SUCCESS;
00195         }
00196 #endif
00197 #if defined(HAVE_QUO)
00198         else if( strcasecmp(prop_name, "quo-advocate") == 0 )
00199         {
00200             BrokerDelegates::RealTimeTaskDelegate_var rttd;
00201             QuoAdvocate *qa = new QuoAdvocate();
00202             PortableServer::ObjectId_var oid;
00203             
00204             oid = poa->activate_object(qa);
00205             rttd = BrokerDelegates::RealTimeTaskDelegate::
00206                 _narrow(poa->id_to_reference(oid.in()));
00207             out << orb->object_to_string(rttd._retn()) << endl;
00208             retval = EXIT_SUCCESS;
00209         }
00210 #endif
00211         else
00212         {
00213             err << "Unknown property: " << prop_name << endl;
00214         }
00215         break;
00216     case HeyParser::GET_SUITES:
00217         try
00218         {
00219             hp.popProperty(prop_name, prop_value);
00220             err << "Unknown property: " << prop_name << endl;
00221         }
00222         catch(const HeyParserException &e)
00223         {
00224             out << suites;
00225             retval = EXIT_SUCCESS;
00226         }
00227         break;
00228     default:
00229         err << "Unknown verb" << endl;
00230         break;
00231     }
00232     return( retval );
00233 }
00234 
00235 #if defined(HAVE_QUO)
00236 /**
00237  * Handle 'hey's directed at an IMP:QuoAdvocate:1.0 object.
00238  *
00239  * @param orb Pointer to the ORB.
00240  * @param hp The HeyParser that describes the action to take.
00241  * @return Zero on success, an errno value otherwise.
00242  */
00243 static int tfQuoAdvocateHey(CORBA::ORB_ptr orb, HeyParser &hp)
00244 {
00245     static HeyPropertyInfo suites[] = {
00246         HeyPropertyInfo("status-sc",
00247                         (1L << HeyParser::GET_PROPERTY) |
00248                         (1L << HeyParser::SET_PROPERTY),
00249                         "",
00250                         "Get or set the QuO system condition that records the status given to ReportCPU.\n"),
00251         HeyPropertyInfo("advice-sc",
00252                         (1L << HeyParser::GET_PROPERTY) |
00253                         (1L << HeyParser::SET_PROPERTY),
00254                         "",
00255                         "Get or set the QuO system condition that records the advice given to ReportCPU.\n"),
00256         HeyPropertyInfo::HPI_NULL
00257     };
00258     
00259     BrokerDelegates::Delegate_var delegate;
00260     const char *prop_name, *prop_value;
00261     int retval = EXIT_FAILURE;
00262     CORBA::Object_var obj;
00263     
00264     obj = orb->string_to_object(hp.who());
00265     delegate = BrokerDelegates::Delegate::_narrow(obj.in());
00266     if( CORBA::is_nil(delegate.in()) )
00267     {
00268         throw CORBA::BAD_PARAM();
00269     }
00270     
00271     switch( hp.what() )
00272     {
00273     case HeyParser::LIST_PROPERTIES:
00274         try
00275         {
00276             hp.popProperty(prop_name, prop_value);
00277         }
00278         catch(const HeyParserException &e)
00279         {
00280             cout << "status-sc" << endl;
00281             cout << "advice-sc" << endl;
00282             retval = EXIT_SUCCESS;
00283         }
00284         break;
00285     case HeyParser::GET_PROPERTY:
00286         hp.popProperty(prop_name, prop_value);
00287         if( (strcasecmp(prop_name, "status-sc") == 0) ||
00288             (strcasecmp(prop_name, "advice-sc") == 0) )
00289         {
00290             quo::ValueSC_ptr scp;
00291             CORBA::Any_ptr any;
00292 
00293             any = delegate->GetDelegateAttribute(prop_name);
00294             if( (*any) >>= scp )
00295             {
00296                 cout << orb->object_to_string(scp) << endl;
00297                 retval = EXIT_SUCCESS;
00298             }
00299             else
00300             {
00301                 cerr << "Unknown error..." << endl;
00302             }
00303         }
00304         else
00305         {
00306             cerr << "Unknown property: " << prop_name;
00307         }
00308         break;
00309     case HeyParser::SET_PROPERTY:
00310         hp.popProperty(prop_name, prop_value);
00311         if( (strcasecmp(prop_name, "status-sc") == 0) ||
00312             (strcasecmp(prop_name, "advice-sc") == 0) )
00313         {
00314             quo::ValueSC_var sc;
00315             CORBA::Any any;
00316 
00317             obj = orb->string_to_object(hp.to());
00318             sc = quo::ValueSC::_narrow(obj.in());
00319             if( CORBA::is_nil(sc.in()) )
00320             {
00321                 cerr << "Error: IOR is not a system condition" << endl;
00322             }
00323             else
00324             {
00325                 any <<= sc.in();
00326                 delegate->SetDelegateAttributeObject(prop_name, obj.in());
00327                 cout << "ok" << endl;
00328                 retval = EXIT_SUCCESS;
00329             }
00330         }
00331         else
00332         {
00333             cerr << "Unknown property: " << prop_name;
00334         }
00335         break;
00336     case HeyParser::GET_SUITES:
00337         cout << suites;
00338         retval = EXIT_SUCCESS;
00339         break;
00340     default:
00341         cerr << "Unknown verb..." << endl;
00342         break;
00343     }
00344     return( retval );
00345 }
00346 #endif
00347 
00348 int FACTORY_METHOD_SYMBOL(factory_library_op_t op, int tag, va_list args)
00349 {
00350     int retval = EXIT_FAILURE;
00351 
00352     struct {
00353         const char *hey_server_hint;
00354         HeyParser *hey_parser;
00355         CORBA::ORB_ptr orb;
00356         PortableServer::POA_ptr poa;
00357         ostream *out;
00358         ostream *err;
00359     } attr = {
00360         NULL,
00361         NULL,
00362         NULL,
00363         NULL,
00364         NULL,
00365         NULL,
00366     };
00367     
00368     while( tag != FMA_TAG_DONE )
00369     {
00370         switch( tag )
00371         {
00372         case FMA_ORB:
00373             attr.orb = va_arg(args, CORBA::ORB_ptr);
00374             break;
00375         case FMA_POA:
00376             attr.poa = va_arg(args, PortableServer::POA_ptr);
00377             break;
00378         case FMA_HeyParser:
00379             attr.hey_parser = va_arg(args, HeyParser *);
00380             break;
00381         case FMA_HeyServerHint:
00382             attr.hey_server_hint = va_arg(args, const char *);
00383             break;
00384         case FMA_StandardOut:
00385             attr.out = va_arg(args, ostream *);
00386             break;
00387         case FMA_StandardError:
00388             attr.err = va_arg(args, ostream *);
00389             break;
00390         default:
00391             break;
00392         }
00393         tag = va_arg(args, int);
00394     }
00395 
00396     switch( op )
00397     {
00398     case FLO_QUERY:
00399 #if defined(HAVE_QUO)
00400         if( attr.hey_server_hint != NULL )
00401         {
00402             if( strcmp(attr.hey_server_hint, "IMP:QuoAdvocate:1.0") == 0 )
00403             {
00404                 retval = EXIT_SUCCESS;
00405             }
00406             else
00407             {
00408             }
00409         }
00410         else
00411         {
00412             cout << "\tIMP:QuoAdvocate:1.0" << endl;
00413         }
00414 #endif
00415         break;
00416     case FLO_HEY:
00417         if( attr.hey_server_hint != NULL )
00418         {
00419 #if defined(HAVE_QUO)
00420             try
00421             {
00422                 if( strcmp(attr.hey_server_hint,
00423                            "IMP:QuoAdvocate:1.0") == 0 )
00424                 {
00425                     retval = tfQuoAdvocateHey(attr.orb, *attr.hey_parser);
00426                 }
00427                 else
00428                 {
00429                 }
00430             }
00431             catch(const HeyParserException &he)
00432             {
00433                 cerr << "Parse error: " << he << endl;
00434             }
00435             catch(const CORBA::SystemException &e)
00436             {
00437                 cerr << "Caught Exception: " << e << endl;
00438             }
00439             catch(...)
00440             {
00441                 cerr << "Caught an unhandled exception" << endl;
00442             }
00443 #endif
00444         }
00445         else
00446         {
00447             retval = tfHey(attr.orb,
00448                            attr.poa,
00449                            *attr.hey_parser,
00450                            *attr.out,
00451                            *attr.err);
00452         }
00453         break;
00454     default:
00455         break;
00456     }
00457     
00458     return( retval );
00459 }

Generated on Fri Oct 22 07:50:25 2004 for CPU Broker by  doxygen 1.3.9.1