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

AllupFactory.cc

Go to the documentation of this file.
00001 /*
00002  * AllupFactory.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 AllupFactory.cc
00014  *
00015  * The shared library interface for libbroker_allup.
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  * Handle 'hey's directed at an edu::utah::pces::Allup object.
00034  *
00035  * @param orb Pointer to the ORB.
00036  * @param hp The HeyParser that describes the action to take.
00037  * @return Zero on success, an errno value otherwise.
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         HeyPropertyInfo("libraries",
00050                         (1L << HeyParser::LIST_PROPERTIES),
00051                         "",
00052                         "List the libraries currently open in the server.\n"),
00053         HeyPropertyInfo::HPI_NULL
00054     };
00055     
00056     const char *prop_name, *prop_value;
00057     edu::utah::pces::Allup_var allup;
00058     int retval = EXIT_FAILURE;
00059     CORBA::Object_var obj;
00060 
00061     require(!CORBA::is_nil(orb));
00062     
00063     obj = orb->string_to_object(hp.who());
00064     allup = edu::utah::pces::Allup::_narrow(obj.in());
00065     if( CORBA::is_nil(allup.in()) )
00066     {
00067         throw CORBA::BAD_PARAM();
00068     }
00069 
00070     switch( hp.what() )
00071     {
00072     case HeyParser::LIST_PROPERTIES:
00073         try
00074         {
00075             hp.popProperty(prop_name, prop_value);
00076             if( strcasecmp(prop_name, "libraries") == 0 )
00077             {
00078                 edu::utah::pces::FactoryLibraryList_var fll;
00079                 unsigned int lpc;
00080                 
00081                 fll = allup->Libraries();
00082                 for( lpc = 0; lpc < fll->length(); lpc++ )
00083                 {
00084                     CORBA::String_var name;
00085 
00086                     name = fll[lpc]->Name();
00087                     cout << name << endl;
00088                 }
00089             }
00090             else
00091             {
00092                 cerr << "Unknown property: " << prop_name << endl;
00093             }
00094         }
00095         catch(const HeyParserException &e)
00096         {
00097             cout << "library" << endl;
00098             cout << "libraries" << endl;
00099             retval = EXIT_SUCCESS;
00100         }
00101         break;
00102     case HeyParser::CREATE_PROPERTY:
00103         hp.popProperty(prop_name, prop_value);
00104         if( strcasecmp(prop_name, "library") == 0 )
00105         {
00106             try
00107             {
00108                 edu::utah::pces::FactoryLibrary_var fl;
00109                 
00110                 fl = allup->OpenLibrary(hp.withValue("name"));
00111                 if( !CORBA::is_nil(fl.in()) )
00112                 {
00113                     cout << orb->object_to_string(fl.in()) << endl;
00114                     retval = EXIT_SUCCESS;
00115                 }
00116                 else
00117                 {
00118                     cerr << "Unknown error..." << endl;
00119                 }
00120             }
00121             catch(const edu::utah::pces::NoSuchLibrary &e)
00122             {
00123                 cerr << "Error: No such library '"
00124                      << e.name
00125                      << "': "
00126                      << e.message
00127                      << endl;
00128             }
00129             catch(const HeyParserException &e)
00130             {
00131                 cerr << "Name not specified!\n";
00132             }
00133         }
00134         else
00135         {
00136             cerr << "Unknown property: " << prop_name << endl;
00137         }
00138         break;
00139     case HeyParser::SHUTDOWN:
00140         try
00141         {
00142             allup->Shutdown();
00143             cerr << "error" << endl;
00144         }
00145         catch(const CORBA::COMM_FAILURE &e)
00146         {
00147             cout << "ok" << endl;
00148             retval = EXIT_SUCCESS;
00149         }
00150         break;
00151     case HeyParser::GET_SUITES:
00152         try
00153         {
00154             hp.popProperty(prop_name, prop_value);
00155         }
00156         catch(const HeyParserException &e)
00157         {
00158             cout << suites;
00159             retval = EXIT_SUCCESS;
00160         }
00161         break;
00162     default:
00163         cerr << "Unknown verb..." << endl;
00164         break;
00165     }
00166     return( retval );
00167 }
00168 
00169 /**
00170  * Handle 'hey's directed at an edu::utah::pces::FactoryLibrary object.
00171  *
00172  * @param orb Pointer to the ORB.
00173  * @param hp The HeyParser that describes the action to take.
00174  * @return Zero on success, an errno value otherwise.
00175  */
00176 static int afFactoryLibraryHey(CORBA::ORB_ptr orb, HeyParser &hp)
00177 {
00178     edu::utah::pces::FactoryLibrary_var fl;
00179     CORBA::String_var out, err;
00180     int retval = EXIT_FAILURE;
00181     CORBA::Object_var obj;
00182 
00183     require(!CORBA::is_nil(orb));
00184     
00185     obj = orb->string_to_object(hp.who());
00186     fl = edu::utah::pces::FactoryLibrary::_narrow(obj.in());
00187     if( CORBA::is_nil(fl.in()) )
00188     {
00189         throw CORBA::BAD_PARAM();
00190     }
00191 
00192     retval = fl->Hey(edu::utah::pces::ArgV(hp.getArgCount(),
00193                                            hp.getArgCount(),
00194                                            (char **)hp.getArgValues()),
00195                      out.out(),
00196                      err.out());
00197 
00198     cout << out;
00199     cerr << err;
00200     
00201     return( retval );
00202 }
00203 
00204 int FACTORY_METHOD_SYMBOL(factory_library_op_t op, int tag, va_list args)
00205 {
00206     int retval = ENOSYS;
00207 
00208     struct {
00209         const char *hey_server_hint;
00210         HeyParser *hey_parser;
00211         CORBA::ORB_ptr orb;
00212     } attr = {
00213         NULL,
00214         NULL,
00215         NULL,
00216     };
00217 
00218     while( tag != FMA_TAG_DONE )
00219     {
00220         switch( tag )
00221         {
00222         case FMA_ORB:
00223             attr.orb = va_arg(args, CORBA::ORB_ptr);
00224             break;
00225         case FMA_HeyParser:
00226             attr.hey_parser = va_arg(args, HeyParser *);
00227             break;
00228         case FMA_HeyServerHint:
00229             attr.hey_server_hint = va_arg(args, const char *);
00230             break;
00231         default:
00232             break;
00233         }
00234         tag = va_arg(args, int);
00235     }
00236 
00237     switch( op )
00238     {
00239     case FLO_QUERY:
00240         if( attr.hey_server_hint != NULL )
00241         {
00242             if( (strcmp(attr.hey_server_hint,
00243                         "IDL:edu/utah/pces/Allup:1.0") == 0) ||
00244                 (strcmp(attr.hey_server_hint,
00245                         "IDL:edu/utah/pces/FactoryLibrary:1.0") == 0) )
00246             {
00247                 retval = EXIT_SUCCESS;
00248             }
00249             else
00250             {
00251             }
00252         }
00253         else
00254         {
00255             cout << "\tIDL:edu/utah/pces/Allup:1.0" << endl
00256                  << "\tIDL:edu/utah/pces/FactoryLibrary:1.0" << endl;
00257         }
00258         break;
00259     case FLO_HEY:
00260         if( attr.hey_server_hint != NULL )
00261         {
00262             try
00263             {
00264                 if( strcmp(attr.hey_server_hint,
00265                            "IDL:edu/utah/pces/Allup:1.0") == 0 )
00266                 {
00267                     retval = afAllupHey(attr.orb, *attr.hey_parser);
00268                 }
00269                 else if( strcmp(attr.hey_server_hint,
00270                                 "IDL:edu/utah/pces/FactoryLibrary:1.0") == 0 )
00271                 {
00272                     retval = afFactoryLibraryHey(attr.orb, *attr.hey_parser);
00273                 }
00274                 else
00275                 {
00276                 }
00277             }
00278             catch(const HeyParserException &he)
00279             {
00280                 cerr << "Parse error: " << he << endl;
00281             }
00282             catch(const CORBA::SystemException &e)
00283             {
00284                 cerr << "Caught Exception: " << e << endl;
00285             }
00286             catch(...)
00287             {
00288                 cerr << "Caught an unhandled exception" << endl;
00289             }
00290         }
00291         else
00292         {
00293         }
00294         break;
00295     default:
00296         break;
00297     }
00298     
00299     return( retval );
00300 }

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