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

QosketFactory.cc

Go to the documentation of this file.
00001 /*
00002  * QosketFactory.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 QosketFactory.cc
00014  *
00015  * The shared library interface for libqosket.
00016  */
00017 
00018 #include "config.h"
00019 
00020 #include <string.h>
00021 #include <stdarg.h>
00022 #include <assert_pp.h>
00023 
00024 #include <iostream>
00025 
00026 #include "time_util.h"
00027 #include "HeyParser.hh"
00028 #include "factory_library.h"
00029 
00030 #include "quoC.h"
00031 
00032 using namespace std;
00033 
00034 /**
00035  * Handle 'hey's directed at a quo::QuoKernel object.
00036  *
00037  * @param orb Pointer to the ORB.
00038  * @param hp The HeyParser that describes the action to take.
00039  * @return Zero on success, an errno value otherwise.
00040  */
00041 static int qfKernelHey(CORBA::ORB_ptr orb, HeyParser &hp)
00042 {
00043     static HeyPropertyInfo suites[] = {
00044         HeyPropertyInfo("sys-cond",
00045                         (1L << HeyParser::CREATE_PROPERTY),
00046                         "",
00047                         "app-id:string - system condition name.\n"
00048                         "idl-type:string - fully qualified name of the syscond IDL type.\n"
00049                         "impl-type:string - fully qualified name of the implementation class.\n"
00050                         "\n"
00051                         "Create a system condition.\n"),
00052         HeyPropertyInfo::HPI_NULL
00053     };
00054     
00055     const char *prop_name, *prop_value;
00056     int retval = EXIT_FAILURE;
00057     CORBA::Object_var obj;
00058     quo::QuoKernel_var qk;
00059     
00060     obj = orb->string_to_object(hp.who());
00061     qk = quo::QuoKernel::_narrow(obj.in());
00062     if( CORBA::is_nil(qk.in()) )
00063     {
00064         throw CORBA::BAD_PARAM();
00065     }
00066     
00067     switch( hp.what() )
00068     {
00069     case HeyParser::LIST_PROPERTIES:
00070         try
00071         {
00072             hp.popProperty(prop_name, prop_value);
00073         }
00074         catch(const HeyParserException &e)
00075         {
00076             cout << "sys-cond" << endl;
00077             retval = EXIT_SUCCESS;
00078         }
00079         break;
00080     case HeyParser::CREATE_PROPERTY:
00081         hp.popProperty(prop_name, prop_value);
00082         if( strcasecmp(prop_name, "sys-cond") == 0 )
00083         {
00084             quo::SysCond_var sc;
00085 
00086             sc = qk->bindSysCond(hp.withValue("app-id"),
00087                                  hp.withValue("idl-type"),
00088                                  hp.withValue("impl-type"));
00089             cout << orb->object_to_string(sc.in()) << endl;
00090             retval = EXIT_SUCCESS;
00091         }
00092         else
00093         {
00094             cerr << "Unknown property: " << prop_name;
00095         }
00096         break;
00097     case HeyParser::GET_SUITES:
00098         cout << suites;
00099         retval = EXIT_SUCCESS;
00100         break;
00101     default:
00102         cerr << "Unknown verb..." << endl;
00103         break;
00104     }
00105     return( retval );
00106 }
00107 
00108 /**
00109  * Handle 'hey's directed at a quo::ValueSC object.
00110  *
00111  * @param orb Pointer to the ORB.
00112  * @param hp The HeyParser that describes the action to take.
00113  * @return Zero on success, an errno value otherwise.
00114  */
00115 static int qfValueSCHey(CORBA::ORB_ptr orb, HeyParser &hp)
00116 {
00117     static HeyPropertyInfo suites[] = {
00118         HeyPropertyInfo("long-value",
00119                         (1L << HeyParser::GET_PROPERTY) |
00120                         (1L << HeyParser::SET_PROPERTY),
00121                         "",
00122                         "Get or set the long value of a ValueSC object.\n"),
00123         HeyPropertyInfo::HPI_NULL
00124     };
00125     
00126     const char *prop_name, *prop_value;
00127     int retval = EXIT_FAILURE;
00128     CORBA::Object_var obj;
00129     quo::ValueSC_var sc;
00130     
00131     obj = orb->string_to_object(hp.who());
00132     sc = quo::ValueSC::_narrow(obj.in());
00133     if( CORBA::is_nil(sc.in()) )
00134     {
00135         throw CORBA::BAD_PARAM();
00136     }
00137     
00138     switch( hp.what() )
00139     {
00140     case HeyParser::LIST_PROPERTIES:
00141         try
00142         {
00143             hp.popProperty(prop_name, prop_value);
00144         }
00145         catch(const HeyParserException &e)
00146         {
00147             cout << "long-value" << endl;
00148             retval = EXIT_SUCCESS;
00149         }
00150         break;
00151     case HeyParser::GET_PROPERTY:
00152         hp.popProperty(prop_name, prop_value);
00153         if( strcasecmp(prop_name, "long-value") == 0 )
00154         {
00155             cout << sc->longValue() << endl;
00156             retval = EXIT_SUCCESS;
00157         }
00158         else
00159         {
00160             cerr << "Unknown property: " << prop_name;
00161         }
00162         break;
00163     case HeyParser::SET_PROPERTY:
00164         hp.popProperty(prop_name, prop_value);
00165         if( strcasecmp(prop_name, "long-value") == 0 )
00166         {
00167             CORBA::Long l;
00168 
00169             if( sscanf(hp.to(), "%ld", (long *)&l) == 1 )
00170             {
00171                 sc->longValue(l);
00172                 cout << "ok" << endl;
00173                 retval = EXIT_SUCCESS;
00174             }
00175             else
00176             {
00177                 cerr << "Error: not a number" << endl;
00178             }
00179         }
00180         else
00181         {
00182             cerr << "Unknown property: " << prop_name;
00183         }
00184         break;
00185     case HeyParser::GET_SUITES:
00186         cout << suites;
00187         retval = EXIT_SUCCESS;
00188         break;
00189     default:
00190         cerr << "Unknown verb..." << endl;
00191         break;
00192     }
00193     return( retval );
00194 }
00195 
00196 int FACTORY_METHOD_SYMBOL(factory_library_op_t op, int tag, va_list args)
00197 {
00198     int retval = ENOSYS;
00199 
00200     struct {
00201         const char *hey_server_hint;
00202         HeyParser *hey_parser;
00203         CORBA::ORB_ptr orb;
00204         ostream *out;
00205         ostream *err;
00206     } attr = {
00207         NULL,
00208         NULL,
00209         NULL,
00210         NULL,
00211         NULL,
00212     };
00213 
00214     while( tag != FMA_TAG_DONE )
00215     {
00216         switch( tag )
00217         {
00218         case FMA_ORB:
00219             attr.orb = va_arg(args, CORBA::ORB_ptr);
00220             break;
00221         case FMA_HeyParser:
00222             attr.hey_parser = va_arg(args, HeyParser *);
00223             break;
00224         case FMA_HeyServerHint:
00225             attr.hey_server_hint = va_arg(args, const char *);
00226             break;
00227         case FMA_StandardOut:
00228             attr.out = va_arg(args, ostream *);
00229             break;
00230         case FMA_StandardError:
00231             attr.err = va_arg(args, ostream *);
00232             break;
00233         default:
00234             break;
00235         }
00236         tag = va_arg(args, int);
00237     }
00238 
00239     switch( op )
00240     {
00241     case FLO_QUERY:
00242         if( attr.hey_server_hint != NULL )
00243         {
00244             if( strcmp(attr.hey_server_hint, "IDL:quo/QuoKernel:1.0") == 0 )
00245             {
00246                 retval = EXIT_SUCCESS;
00247             }
00248             else if( strcmp(attr.hey_server_hint, "IDL:quo/ValueSC:1.0") == 0 )
00249             {
00250                 retval = EXIT_SUCCESS;
00251             }
00252             else
00253             {
00254             }
00255         }
00256         else
00257         {
00258             cout << "\tIDL:quo/QuoKernel:1.0" << endl
00259                  << "\tIDL:quo/ValueSC:1.0" << endl;
00260         }
00261         break;
00262     case FLO_HEY:
00263         if( attr.hey_server_hint != NULL )
00264         {
00265             try
00266             {
00267                 if( strcmp(attr.hey_server_hint,
00268                            "IDL:quo/QuoKernel:1.0") == 0 )
00269                 {
00270                     retval = qfKernelHey(attr.orb, *attr.hey_parser);
00271                 }
00272                 else if( strcmp(attr.hey_server_hint,
00273                                 "IDL:quo/ValueSC:1.0") == 0 )
00274                 {
00275                     retval = qfValueSCHey(attr.orb, *attr.hey_parser);
00276                 }
00277                 else
00278                 {
00279                 }
00280             }
00281             catch(const HeyParserException &he)
00282             {
00283                 cerr << "Parse error: " << he << endl;
00284             }
00285             catch(const CORBA::SystemException &e)
00286             {
00287                 cerr << "Caught Exception: " << e << endl;
00288             }
00289             catch(...)
00290             {
00291                 cerr << "Caught an unhandled exception" << endl;
00292             }
00293         }
00294         else
00295         {
00296         }
00297         break;
00298     default:
00299         break;
00300     }
00301     
00302     return( retval );
00303 }

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