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

PolicyFactory.cc

Go to the documentation of this file.
00001 /*
00002  * PolicyFactory.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 PolicyFactory.cc
00014  *
00015  * The shared library interface for libpolicies.
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 #include "ManagerImpl.hh"
00031 #include "PartitionPolicyImpl.hh"
00032 #include "StrictPolicyImpl.hh"
00033 #include "WeightedPolicyImpl.hh"
00034 
00035 using namespace std;
00036 
00037 /**
00038  * Handle 'hey's directed at the library.
00039  *
00040  * @param orb Pointer to the ORB.
00041  * @param poa The POA to use when activating objects.
00042  * @param hp The HeyParser that describes the action to take.
00043  * @param out Standard out.
00044  * @param err Standard error.
00045  * @return Zero on success, an errno value otherwise.
00046  */
00047 static int pfHey(CORBA::ORB_ptr orb,
00048                  PortableServer::POA_ptr poa,
00049                  HeyParser &hp,
00050                  ostream &out,
00051                  ostream &err)
00052 {
00053     static HeyPropertyInfo suites[] = {
00054         HeyPropertyInfo("strict-policy",
00055                         (1L << HeyParser::CREATE_PROPERTY),
00056                         "",
00057                         "name:string - The name of the StrictPolicy.\n"
00058                         "\n"
00059                         "Create a StrictPolicy object.  This policy resolves "
00060                         "contention by completely\n"
00061                         "satisfying task requests in order of priority until "
00062                         "there is no more CPU\n"
00063                         "available.\n"),
00064         HeyPropertyInfo("weighted-policy",
00065                         (1L << HeyParser::CREATE_PROPERTY),
00066                         "",
00067                         "name:string - The name of the WeightedPolicy.\n"
00068                         "\n"
00069                         "Create a WeightedPolicy object.  This policy "
00070                         "resolves contention using a\n"
00071                         "proportional share scheme.  For example, a task with "
00072                         "a weight of 20 will get\n"
00073                         "twice as much CPU as one with 10.\n"),
00074         HeyPropertyInfo("partition-policy",
00075                         (1L << HeyParser::CREATE_PROPERTY),
00076                         "",
00077                         "name:string - The name of the PartitionPolicy.\n"
00078                         "\n"
00079                         "Create a PartitionPolicy object.  This policy acts "
00080                         "as a meta-policy that\n"
00081                         "partitions tasks into separate sub-policies, which "
00082                         "can of any type.\n"),
00083         HeyPropertyInfo::HPI_NULL
00084     };
00085 
00086     const char *prop_name, *prop_value;
00087     int retval = EXIT_FAILURE;
00088 
00089     require(!CORBA::is_nil(orb));
00090     require(!CORBA::is_nil(poa));
00091 
00092     switch( hp.what() )
00093     {
00094     case HeyParser::LIST_PROPERTIES:
00095         try
00096         {
00097             hp.popProperty(prop_name, prop_value);
00098         }
00099         catch(const HeyParserException &e)
00100         {
00101             out << "strict-policy" << endl
00102                 << "weighted-policy" << endl
00103                 << "partition-policy" << endl;
00104         }
00105         break;
00106     case HeyParser::CREATE_PROPERTY:
00107         hp.popProperty(prop_name, prop_value);
00108         if( strcasecmp(prop_name, "strict-policy") == 0 )
00109         {
00110             StrictPolicyImpl *spi = new StrictPolicyImpl(hp.withValue("name"));
00111             BrokerPolicies::StrictPolicy_var sp;
00112             PortableServer::ObjectId_var oid;
00113             
00114             oid = poa->activate_object(spi);
00115             sp = BrokerPolicies::StrictPolicy::
00116                 _narrow(poa->id_to_reference(oid.in()));
00117             out << orb->object_to_string(sp._retn()) << endl;
00118             retval = EXIT_SUCCESS;
00119         }
00120         else if( strcasecmp(prop_name, "weighted-policy") == 0 )
00121         {
00122             BrokerPolicies::WeightedPolicy_var wp;
00123             PortableServer::ObjectId_var oid;
00124             WeightedPolicyImpl *wpi;
00125 
00126             wpi = new WeightedPolicyImpl(hp.withValue("name"));
00127             oid = poa->activate_object(wpi);
00128             wp = BrokerPolicies::WeightedPolicy::
00129                 _narrow(poa->id_to_reference(oid.in()));
00130             out << orb->object_to_string(wp._retn()) << endl;
00131             retval = EXIT_SUCCESS;
00132         }
00133         else if( strcasecmp(prop_name, "partition-policy") == 0 )
00134         {
00135             BrokerPolicies::PartitionPolicy_var pp;
00136             PortableServer::ObjectId_var oid;
00137             PartitionPolicyImpl *ppi;
00138 
00139             ppi = new PartitionPolicyImpl(hp.withValue("name"));
00140             oid = poa->activate_object(ppi);
00141             pp = BrokerPolicies::PartitionPolicy::
00142                 _narrow(poa->id_to_reference(oid.in()));
00143             out << orb->object_to_string(pp._retn()) << endl;
00144             retval = EXIT_SUCCESS;
00145         }
00146         else
00147         {
00148             err << "Unknown property: " << prop_name << endl;
00149         }
00150         break;
00151     case HeyParser::GET_SUITES:
00152         try
00153         {
00154             hp.popProperty(prop_name, prop_value);
00155             err << "Unknown property: " << prop_name << endl;
00156         }
00157         catch(const HeyParserException &e)
00158         {
00159             out << suites;
00160             retval = EXIT_SUCCESS;
00161         }
00162         break;
00163     default:
00164         err << "Unknown verb" << endl;
00165         break;
00166     }
00167     return( retval );
00168 }
00169 
00170 /**
00171  * Handle 'hey's directed at a StrictPolicy object.
00172  *
00173  * @param orb Pointer to the ORB.
00174  * @param hp The HeyParser that describes the action to take.
00175  * @return Zero on success, an errno value otherwise.
00176  */
00177 static int pfStrictPolicyHey(CORBA::ORB_ptr orb, HeyParser &hp)
00178 {
00179     static HeyPropertyInfo suites[] = {
00180         HeyPropertyInfo("tasks",
00181                         (1L << HeyParser::LIST_PROPERTIES),
00182                         "",
00183                         "List tasks currently being managed.\n"),
00184         HeyPropertyInfo("tasks",
00185                         (1L << HeyParser::GET_SUITES),
00186                         "",
00187                         "Get a description of the sub-properties of task.\n"),
00188         HeyPropertyInfo("task",
00189                         (1L << HeyParser::GET_PROPERTY),
00190                         "name:string - The task name.",
00191                         "Get the IOR for the task matching the given name.\n"),
00192         HeyPropertyInfo("max-cpu",
00193                         (1L << HeyParser::SET_PROPERTY) |
00194                         (1L << HeyParser::GET_PROPERTY),
00195                         "",
00196                         "Get or set the maximum CPU allocation.  The value is "
00197                         "a floating point number\n"
00198                         "between 0.0 and 1.0 that represents the percentage "
00199                         "of CPU that the policy\n"
00200                         "will allocate to the tasks it manages.\n"),
00201         HeyPropertyInfo::HPI_NULL
00202     };
00203     
00204     static HeyPropertyInfo task_suites[] = {
00205         HeyPropertyInfo("priority",
00206                         (1L << HeyParser::SET_PROPERTY) |
00207                         (1L << HeyParser::GET_PROPERTY),
00208                         "",
00209                         "Set or get the priority of the given task in this "
00210                         "policy.\n"),
00211         HeyPropertyInfo::HPI_NULL
00212     };
00213     
00214     const char *prop_name, *prop_value, *to_value;
00215     BrokerPolicies::StrictPolicy_var sp;
00216     int retval = EXIT_FAILURE;
00217     Broker::TaskList_var tl;
00218     CORBA::Object_var obj;
00219     Broker::Task_var task;
00220     
00221     obj = orb->string_to_object(hp.who());
00222     sp = BrokerPolicies::StrictPolicy::_narrow(obj.in());
00223     if( CORBA::is_nil(sp.in()) )
00224     {
00225         throw CORBA::BAD_PARAM();
00226     }
00227     
00228     tl = sp->GetTaskList();
00229     switch( hp.what() )
00230     {
00231     case HeyParser::LIST_PROPERTIES:
00232         try
00233         {
00234             hp.popProperty(prop_name, prop_value);
00235             if( strcasecmp(prop_name, "tasks") == 0 )
00236             {
00237                 unsigned int lpc;
00238                 
00239                 for( lpc = 0; lpc < tl->length(); lpc++ )
00240                 {
00241                     cout << tl[lpc]->Name() << endl;
00242                 }
00243                 retval = EXIT_SUCCESS;
00244             }
00245             else if( strcasecmp(prop_name, "task") == 0 )
00246             {
00247                 cout << "priority" << endl;
00248             }
00249             else
00250             {
00251                 cerr << "Unknown property: " << prop_name << endl;
00252             }
00253         }
00254         catch(const HeyParserException &e)
00255         {
00256             cout << "max-cpu" << endl;
00257             cout << "tasks" << endl;
00258             cout << "task" << endl;
00259             retval = EXIT_SUCCESS;
00260         }
00261         break;
00262     case HeyParser::GET_PROPERTY:
00263         hp.popProperty(prop_name, prop_value);
00264         if( strcasecmp(prop_name, "task") == 0 )
00265         {
00266             task = ManagerImpl::ResolveTask(orb, tl, prop_value);
00267             hp.popProperty(prop_name, prop_value);
00268             if( strcasecmp(prop_name, "priority") == 0 )
00269             {
00270                 cout << sp->GetTaskPriority(task.in()) << endl;
00271                 retval = EXIT_SUCCESS;
00272             }
00273             else
00274             {
00275                 cout << orb->object_to_string(task.in()) << endl;
00276                 retval = EXIT_SUCCESS;
00277             }
00278         }
00279         else if( strcasecmp(prop_name, "max-cpu") == 0 )
00280         {
00281             cout << sp->GetMaxCPUAllocation() << endl;
00282             retval = EXIT_SUCCESS;
00283         }
00284         else
00285         {
00286             cerr << "Unknown property: " << prop_name << endl;
00287         }
00288         break;
00289     case HeyParser::SET_PROPERTY:
00290         hp.popProperty(prop_name, prop_value);
00291         if( strcasecmp(prop_name, "task") == 0 )
00292         {
00293             task = ManagerImpl::ResolveTask(orb, tl, prop_value);
00294             hp.popProperty(prop_name, prop_value);
00295             if( strcasecmp(prop_name, "priority") == 0 )
00296             {
00297                 CORBA::Short pri;
00298                 
00299                 to_value = hp.to();
00300                 if( sscanf(to_value, "%hd", &pri) == 1 )
00301                 {
00302                     sp->SetTaskPriority(task.in(), pri);
00303                     cout << "ok" << endl;
00304                     retval = EXIT_SUCCESS;
00305                 }
00306                 else
00307                 {
00308                     cerr << "Priority not a number: "
00309                          << to_value
00310                          << endl;
00311                 }
00312             }
00313             else
00314             {
00315                 cerr << "Unknown property: " << prop_name << endl;
00316             }
00317         }
00318         else if( strcasecmp(prop_name, "max-cpu") == 0 )
00319         {
00320             CORBA::Float pct;
00321             
00322             to_value = hp.to();
00323             if( sscanf(to_value, "%f", &pct) == 1 )
00324             {
00325                 if( (pct < BrokerPolicies::StrictPolicy::CPU_ALLOCATION_MIN) ||
00326                     (pct > BrokerPolicies::StrictPolicy::CPU_ALLOCATION_MAX) )
00327                 {
00328                     cerr << "Invalid percentage, expecting a "
00329                          << "value greater than "
00330                          << BrokerPolicies::StrictPolicy::CPU_ALLOCATION_MIN
00331                          << " and less than "
00332                          << BrokerPolicies::StrictPolicy::CPU_ALLOCATION_MAX
00333                          << endl;
00334                 }
00335                 else
00336                 {
00337                     sp->SetMaxCPUAllocation(pct);
00338                     cout << "ok" << endl;
00339                     retval = EXIT_SUCCESS;
00340                 }
00341             }
00342             else
00343             {
00344                 cerr << "max-cpu value not a percentage: "
00345                      << to_value
00346                      << endl;
00347             }
00348         }
00349         else
00350         {
00351             cerr << "Unknown property: " << prop_name << endl;
00352         }
00353         break;
00354     case HeyParser::GET_SUITES:
00355         try
00356         {
00357             hp.popProperty(prop_name, prop_value);
00358             if( strcasecmp(prop_name, "task") == 0 )
00359             {
00360                 cout << task_suites;
00361                 retval = EXIT_SUCCESS;
00362             }
00363             else
00364             {
00365                 cerr << "Unknown property: " << prop_name << endl;
00366             }
00367         }
00368         catch(const HeyParserException &e)
00369         {
00370             cout << suites;
00371             retval = EXIT_SUCCESS;
00372         }
00373         break;
00374     default:
00375         cerr << "Unknown verb..." << endl;
00376         break;
00377     }
00378     return( retval );
00379 }
00380 
00381 /**
00382  * Handle 'hey's directed at a WeightedPolicy object.
00383  *
00384  * @param orb Pointer to the ORB.
00385  * @param hp The HeyParser that describes the action to take.
00386  * @return Zero on success, an errno value otherwise.
00387  */
00388 static int pfWeightedPolicyHey(CORBA::ORB_ptr orb, HeyParser &hp)
00389 {
00390     static HeyPropertyInfo suites[] = {
00391         HeyPropertyInfo("tasks",
00392                         (1L << HeyParser::LIST_PROPERTIES),
00393                         "",
00394                         "List tasks currently being managed.\n"),
00395         HeyPropertyInfo("tasks",
00396                         (1L << HeyParser::GET_SUITES),
00397                         "",
00398                         "Get a description of the sub-properties of task.\n"),
00399         HeyPropertyInfo("task",
00400                         (1L << HeyParser::GET_PROPERTY),
00401                         "name:string - The task name.",
00402                         "Get the IOR for the task matching the given name.\n"),
00403         HeyPropertyInfo("max-cpu",
00404                         (1L << HeyParser::SET_PROPERTY) |
00405                         (1L << HeyParser::GET_PROPERTY),
00406                         "",
00407                         "Get or set the maximum CPU allocation.  The value is "
00408                         "a floating point number\n"
00409                         "between 0.0 and 1.0 that represents the percentage "
00410                         "of CPU that the policy\n"
00411                         "will allocate to the tasks it manages.\n"),
00412         HeyPropertyInfo::HPI_NULL
00413     };
00414     
00415     static HeyPropertyInfo task_suites[] = {
00416         HeyPropertyInfo("weight",
00417                         (1L << HeyParser::SET_PROPERTY) |
00418                         (1L << HeyParser::GET_PROPERTY),
00419                         "",
00420                         "Set or get the weight of the given task in this "
00421                         "policy.\n"),
00422         HeyPropertyInfo::HPI_NULL
00423     };
00424     
00425     const char *prop_name, *prop_value, *to_value;
00426     BrokerPolicies::WeightedPolicy_var sp;
00427     int retval = EXIT_FAILURE;
00428     Broker::TaskList_var tl;
00429     CORBA::Object_var obj;
00430     Broker::Task_var task;
00431     
00432     obj = orb->string_to_object(hp.who());
00433     sp = BrokerPolicies::WeightedPolicy::_narrow(obj.in());
00434     if( CORBA::is_nil(sp.in()) )
00435     {
00436         throw CORBA::BAD_PARAM();
00437     }
00438     
00439     tl = sp->GetTaskList();
00440     switch( hp.what() )
00441     {
00442     case HeyParser::LIST_PROPERTIES:
00443         try
00444         {
00445             hp.popProperty(prop_name, prop_value);
00446             if( strcasecmp(prop_name, "tasks") == 0 )
00447             {
00448                 unsigned int lpc;
00449                 
00450                 for( lpc = 0; lpc < tl->length(); lpc++ )
00451                 {
00452                     cout << tl[lpc]->Name() << endl;
00453                 }
00454                 retval = EXIT_SUCCESS;
00455             }
00456             else if( strcasecmp(prop_name, "task") == 0 )
00457             {
00458                 cout << "weight" << endl;
00459             }
00460             else
00461             {
00462                 cerr << "Unknown property: " << prop_name << endl;
00463             }
00464         }
00465         catch(const HeyParserException &e)
00466         {
00467             cout << "max-cpu" << endl;
00468             cout << "tasks" << endl;
00469             cout << "task" << endl;
00470             retval = EXIT_SUCCESS;
00471         }
00472         break;
00473     case HeyParser::GET_PROPERTY:
00474         hp.popProperty(prop_name, prop_value);
00475         if( strcasecmp(prop_name, "task") == 0 )
00476         {
00477             task = ManagerImpl::ResolveTask(orb, tl, prop_value);
00478             hp.popProperty(prop_name, prop_value);
00479             if( strcasecmp(prop_name, "weight") == 0 )
00480             {
00481                 cout << sp->GetTaskWeight(task.in()) << endl;
00482                 retval = EXIT_SUCCESS;
00483             }
00484             else
00485             {
00486                 cout << orb->object_to_string(task.in()) << endl;
00487                 retval = EXIT_SUCCESS;
00488             }
00489         }
00490         else if( strcasecmp(prop_name, "max-cpu") == 0 )
00491         {
00492             cout << sp->GetMaxCPUAllocation() << endl;
00493             retval = EXIT_SUCCESS;
00494         }
00495         else
00496         {
00497             cerr << "Unknown property: " << prop_name << endl;
00498         }
00499         break;
00500     case HeyParser::SET_PROPERTY:
00501         hp.popProperty(prop_name, prop_value);
00502         if( strcasecmp(prop_name, "task") == 0 )
00503         {
00504             task = ManagerImpl::ResolveTask(orb, tl, prop_value);
00505             hp.popProperty(prop_name, prop_value);
00506             if( strcasecmp(prop_name, "weight") == 0 )
00507             {
00508                 CORBA::Short pri;
00509                 
00510                 to_value = hp.to();
00511                 if( sscanf(to_value, "%hd", &pri) == 1 )
00512                 {
00513                     sp->SetTaskWeight(task.in(), pri);
00514                     cout << "ok" << endl;
00515                     retval = EXIT_SUCCESS;
00516                 }
00517                 else
00518                 {
00519                     cerr << "Weight not a number: "
00520                          << to_value
00521                          << endl;
00522                 }
00523             }
00524             else
00525             {
00526                 cerr << "Unknown property: " << prop_name << endl;
00527             }
00528         }
00529         else if( strcasecmp(prop_name, "max-cpu") == 0 )
00530         {
00531             CORBA::Float pct;
00532             
00533             to_value = hp.to();
00534             if( sscanf(to_value, "%f", &pct) == 1 )
00535             {
00536                 if( (pct < BrokerPolicies::WeightedPolicy::CPU_ALLOCATION_MIN) ||
00537                     (pct > BrokerPolicies::WeightedPolicy::CPU_ALLOCATION_MAX) )
00538                 {
00539                     cerr << "Invalid percentage, expecting a "
00540                          << "value greater than "
00541                          << BrokerPolicies::WeightedPolicy::CPU_ALLOCATION_MIN
00542                          << " and less than "
00543                          << BrokerPolicies::WeightedPolicy::CPU_ALLOCATION_MAX
00544                          << endl;
00545                 }
00546                 else
00547                 {
00548                     sp->SetMaxCPUAllocation(pct);
00549                     cout << "ok" << endl;
00550                     retval = EXIT_SUCCESS;
00551                 }
00552             }
00553             else
00554             {
00555                 cerr << "max-cpu value not a percentage: "
00556                      << to_value
00557                      << endl;
00558             }
00559         }
00560         else
00561         {
00562             cerr << "Unknown property: " << prop_name << endl;
00563         }
00564         break;
00565     case HeyParser::GET_SUITES:
00566         try
00567         {
00568             hp.popProperty(prop_name, prop_value);
00569             if( strcasecmp(prop_name, "task") == 0 )
00570             {
00571                 cout << task_suites;
00572                 retval = EXIT_SUCCESS;
00573             }
00574             else
00575             {
00576                 cerr << "Unknown property: " << prop_name << endl;
00577             }
00578         }
00579         catch(const HeyParserException &e)
00580         {
00581             cout << suites;
00582             retval = EXIT_SUCCESS;
00583         }
00584         break;
00585     default:
00586         cerr << "Unknown verb..." << endl;
00587         break;
00588     }
00589     return( retval );
00590 }
00591 
00592 /**
00593  * Handle 'hey's directed at a PartitionPolicy object.
00594  *
00595  * @param orb Pointer to the ORB.
00596  * @param hp The HeyParser that describes the action to take.
00597  * @return Zero on success, an errno value otherwise.
00598  */
00599 static int pfPartitionPolicyHey(CORBA::ORB_ptr orb, HeyParser &hp)
00600 {
00601     static HeyPropertyInfo suites[] = {
00602         HeyPropertyInfo("tasks",
00603                         (1L << HeyParser::LIST_PROPERTIES),
00604                         "",
00605                         "List tasks currently being managed.\n"),
00606         HeyPropertyInfo("tasks",
00607                         (1L << HeyParser::GET_SUITES),
00608                         "",
00609                         "Get a description of the sub-properties of task.\n"),
00610         HeyPropertyInfo("task",
00611                         (1L << HeyParser::GET_PROPERTY),
00612                         "name:string - The task name.",
00613                         "Get the IOR for the task matching the given name.\n"),
00614         HeyPropertyInfo("max-cpu",
00615                         (1L << HeyParser::SET_PROPERTY) |
00616                         (1L << HeyParser::GET_PROPERTY),
00617                         "",
00618                         "Get or set the maximum CPU allocation.  The value is "
00619                         "a floating point number\n"
00620                         "between 0.0 and 1.0 that represents the percentage "
00621                         "of CPU that the policy\n"
00622                         "will allocate to the tasks it manages.\n"),
00623         HeyPropertyInfo::HPI_NULL
00624     };
00625     
00626     static HeyPropertyInfo task_suites[] = {
00627         HeyPropertyInfo("policy",
00628                         (1L << HeyParser::SET_PROPERTY) |
00629                         (1L << HeyParser::GET_PROPERTY),
00630                         "",
00631                         "Set or get the policy for the given task.\n"),
00632         HeyPropertyInfo::HPI_NULL
00633     };
00634     
00635     const char *prop_name, *prop_value, *to_value;
00636     BrokerPolicies::PartitionPolicy_var sp;
00637     int retval = EXIT_FAILURE;
00638     Broker::TaskList_var tl;
00639     CORBA::Object_var obj;
00640     Broker::Task_var task;
00641     
00642     obj = orb->string_to_object(hp.who());
00643     sp = BrokerPolicies::PartitionPolicy::_narrow(obj.in());
00644     if( CORBA::is_nil(sp.in()) )
00645     {
00646         throw CORBA::BAD_PARAM();
00647     }
00648     
00649     tl = sp->GetTaskList();
00650     switch( hp.what() )
00651     {
00652     case HeyParser::LIST_PROPERTIES:
00653         try
00654         {
00655             hp.popProperty(prop_name, prop_value);
00656             if( strcasecmp(prop_name, "tasks") == 0 )
00657             {
00658                 unsigned int lpc;
00659                 
00660                 for( lpc = 0; lpc < tl->length(); lpc++ )
00661                 {
00662                     cout << tl[lpc]->Name() << endl;
00663                 }
00664                 retval = EXIT_SUCCESS;
00665             }
00666             else if( strcasecmp(prop_name, "task") == 0 )
00667             {
00668                 cout << "weight" << endl;
00669             }
00670             else
00671             {
00672                 cerr << "Unknown property: " << prop_name << endl;
00673             }
00674         }
00675         catch(const HeyParserException &e)
00676         {
00677             cout << "max-cpu" << endl;
00678             cout << "tasks" << endl;
00679             cout << "task" << endl;
00680             retval = EXIT_SUCCESS;
00681         }
00682         break;
00683     case HeyParser::GET_PROPERTY:
00684         hp.popProperty(prop_name, prop_value);
00685         if( strcasecmp(prop_name, "task") == 0 )
00686         {
00687             task = ManagerImpl::ResolveTask(orb, tl, prop_value);
00688             hp.popProperty(prop_name, prop_value);
00689             if( strcasecmp(prop_name, "policy") == 0 )
00690             {
00691                 Broker::Policy_var policy;
00692 
00693                 policy = sp->GetTaskPolicy(task.in());
00694                 cout << orb->object_to_string(policy.in()) << endl;
00695                 retval = EXIT_SUCCESS;
00696             }
00697             else
00698             {
00699                 cout << orb->object_to_string(task.in()) << endl;
00700                 retval = EXIT_SUCCESS;
00701             }
00702         }
00703         else if( strcasecmp(prop_name, "default-policy") == 0 )
00704         {
00705             Broker::Policy_var policy;
00706 
00707             policy = sp->DefaultPolicy();
00708             cout << orb->object_to_string(policy.in()) << endl;
00709         }
00710         else if( strcasecmp(prop_name, "max-cpu") == 0 )
00711         {
00712             cout << sp->GetMaxCPUAllocation() << endl;
00713             retval = EXIT_SUCCESS;
00714         }
00715         else
00716         {
00717             cerr << "Unknown property: " << prop_name << endl;
00718         }
00719         break;
00720     case HeyParser::SET_PROPERTY:
00721         hp.popProperty(prop_name, prop_value);
00722         if( strcasecmp(prop_name, "task") == 0 )
00723         {
00724             task = ManagerImpl::ResolveTask(orb, tl, prop_value);
00725             hp.popProperty(prop_name, prop_value);
00726             if( strcasecmp(prop_name, "policy") == 0 )
00727             {
00728                 Broker::Policy_var policy;
00729                 CORBA::Object_var obj;
00730 
00731                 obj = orb->string_to_object(hp.to());
00732                 if( !CORBA::is_nil(obj.in()) )
00733                 {
00734                     policy = Broker::Policy::_narrow(obj.in());
00735                     if( CORBA::is_nil(policy.in()) )
00736                     {
00737                         cerr << "Error: Policy is not an object." << endl;
00738                         throw CORBA::BAD_PARAM();
00739                     }
00740                 }
00741                 
00742                 sp->SetTaskPolicy(task.in(), policy.in());
00743                 cout << "ok" << endl;
00744             }
00745             else
00746             {
00747                 cerr << "Unknown property: " << prop_name << endl;
00748             }
00749         }
00750         else if( strcasecmp(prop_name, "default-policy") == 0 )
00751         {
00752             Broker::Policy_var policy;
00753             CORBA::Object_var obj;
00754             
00755             obj = orb->string_to_object(hp.to());
00756             if( !CORBA::is_nil(obj.in()) )
00757             {
00758                 policy = Broker::Policy::_narrow(obj.in());
00759                 if( CORBA::is_nil(policy.in()) )
00760                 {
00761                     cerr << "Error: Policy is not an object." << endl;
00762                     throw CORBA::BAD_PARAM();
00763                 }
00764             }
00765             
00766             sp->DefaultPolicy(policy.in());
00767             cout << "ok" << endl;
00768         }
00769         else if( strcasecmp(prop_name, "max-cpu") == 0 )
00770         {
00771             CORBA::Float pct;
00772             
00773             to_value = hp.to();
00774             if( sscanf(to_value, "%f", &pct) == 1 )
00775             {
00776                 if( (pct < BrokerPolicies::PartitionPolicy::CPU_ALLOCATION_MIN) ||
00777                     (pct > BrokerPolicies::PartitionPolicy::CPU_ALLOCATION_MAX) )
00778                 {
00779                     cerr << "Invalid percentage, expecting a "
00780                          << "value greater than "
00781                          << BrokerPolicies::PartitionPolicy::CPU_ALLOCATION_MIN
00782                          << " and less than "
00783                          << BrokerPolicies::PartitionPolicy::CPU_ALLOCATION_MAX
00784                          << endl;
00785                 }
00786                 else
00787                 {
00788                     sp->SetMaxCPUAllocation(pct);
00789                     cout << "ok" << endl;
00790                     retval = EXIT_SUCCESS;
00791                 }
00792             }
00793             else
00794             {
00795                 cerr << "max-cpu value not a percentage: "
00796                      << to_value
00797                      << endl;
00798             }
00799         }
00800         else
00801         {
00802             cerr << "Unknown property: " << prop_name << endl;
00803         }
00804         break;
00805     case HeyParser::GET_SUITES:
00806         try
00807         {
00808             hp.popProperty(prop_name, prop_value);
00809             if( strcasecmp(prop_name, "task") == 0 )
00810             {
00811                 cout << task_suites;
00812                 retval = EXIT_SUCCESS;
00813             }
00814             else
00815             {
00816                 cerr << "Unknown property: " << prop_name << endl;
00817             }
00818         }
00819         catch(const HeyParserException &e)
00820         {
00821             cout << suites;
00822             retval = EXIT_SUCCESS;
00823         }
00824         break;
00825     default:
00826         cerr << "Unknown verb..." << endl;
00827         break;
00828     }
00829     return( retval );
00830 }
00831 
00832 int FACTORY_METHOD_SYMBOL(factory_library_op_t op, int tag, va_list args)
00833 {
00834     int retval = EXIT_FAILURE;
00835 
00836     struct {
00837         const char *hey_server_hint;
00838         HeyParser *hey_parser;
00839         CORBA::ORB_ptr orb;
00840         PortableServer::POA_ptr poa;
00841         ostream *out;
00842         ostream *err;
00843     } attr = {
00844         NULL,
00845         NULL,
00846         NULL,
00847         NULL,
00848         NULL,
00849         NULL,
00850     };
00851     
00852     while( tag != FMA_TAG_DONE )
00853     {
00854         switch( tag )
00855         {
00856         case FMA_ORB:
00857             attr.orb = va_arg(args, CORBA::ORB_ptr);
00858             break;
00859         case FMA_POA:
00860             attr.poa = va_arg(args, PortableServer::POA_ptr);
00861             break;
00862         case FMA_HeyParser:
00863             attr.hey_parser = va_arg(args, HeyParser *);
00864             break;
00865         case FMA_HeyServerHint:
00866             attr.hey_server_hint = va_arg(args, const char *);
00867             break;
00868         case FMA_StandardOut:
00869             attr.out = va_arg(args, ostream *);
00870             break;
00871         case FMA_StandardError:
00872             attr.err = va_arg(args, ostream *);
00873             break;
00874         default:
00875             break;
00876         }
00877         tag = va_arg(args, int);
00878     }
00879 
00880     switch( op )
00881     {
00882     case FLO_QUERY:
00883         if( attr.hey_server_hint != NULL )
00884         {
00885             if( strcmp(attr.hey_server_hint,
00886                        "IDL:BrokerPolicies/StrictPolicy:1.0") == 0 )
00887             {
00888                 retval = EXIT_SUCCESS;
00889             }
00890             else if( strcmp(attr.hey_server_hint,
00891                             "IDL:BrokerPolicies/WeightedPolicy:1.0") == 0 )
00892             {
00893                 retval = EXIT_SUCCESS;
00894             }
00895             else if( strcmp(attr.hey_server_hint,
00896                             "IDL:BrokerPolicies/PartitionPolicy:1.0") == 0 )
00897             {
00898                 retval = EXIT_SUCCESS;
00899             }
00900             else
00901             {
00902             }
00903         }
00904         else
00905         {
00906             cout << "\tIDL:BrokerPolicies/StrictPolicy:1.0" << endl
00907                  << "\tIDL:BrokerPolicies/WeightedPolicy:1.0" << endl
00908                  << "\tIDL:BrokerPolicies/PartitionPolicy:1.0" << endl;
00909         }
00910         break;
00911     case FLO_HEY:
00912         if( attr.hey_server_hint != NULL )
00913         {
00914             try
00915             {
00916                 if( strcmp(attr.hey_server_hint,
00917                            "IDL:BrokerPolicies/StrictPolicy:1.0") == 0 )
00918                 {
00919                     retval = pfStrictPolicyHey(attr.orb, *attr.hey_parser);
00920                 }
00921                 else if( strcmp(attr.hey_server_hint,
00922                                 "IDL:BrokerPolicies/WeightedPolicy:1.0") == 0 )
00923                 {
00924                     retval = pfWeightedPolicyHey(attr.orb, *attr.hey_parser);
00925                 }
00926                 else if( strcmp(attr.hey_server_hint,
00927                                 "IDL:BrokerPolicies/PartitionPolicy:1.0") == 0 )
00928                 {
00929                     retval = pfPartitionPolicyHey(attr.orb, *attr.hey_parser);
00930                 }
00931                 else
00932                 {
00933                 }
00934             }
00935             catch(const HeyParserException &he)
00936             {
00937                 cerr << "Parse error: " << he << endl;
00938             }
00939             catch(const CORBA::SystemException &e)
00940             {
00941                 cerr << "Caught Exception: " << e << endl;
00942             }
00943             catch(...)
00944             {
00945                 cerr << "Caught an unhandled exception" << endl;
00946             }
00947         }
00948         else
00949         {
00950             retval = pfHey(attr.orb,
00951                            attr.poa,
00952                            *attr.hey_parser,
00953                            *attr.out,
00954                            *attr.err);
00955         }
00956         break;
00957     default:
00958         break;
00959     }
00960     
00961     return( retval );
00962 }

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