00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019
00020 #include <stdlib.h>
00021 #include <signal.h>
00022
00023 #include <sys/time.h>
00024
00025 #include <assert.h>
00026 #include <assert_pp.h>
00027
00028 #if defined(HAVE_LIBRK)
00029 #include <rk/rk.h>
00030 #include <rk/rk_error.h>
00031 #endif
00032
00033 #include <iostream>
00034
00035 #include <AllupImpl.hh>
00036
00037 using namespace std;
00038
00039
00040
00041
00042
00043
00044 static struct {
00045 const char *ba_IORFileName;
00046 #if defined(HAVE_LIBRK)
00047 rk_resource_set_t ba_ResourceSet;
00048 #endif
00049 } ba_data;
00050
00051
00052
00053
00054
00055
00056 static void sig_exit_handler(int sig)
00057 {
00058 #if defined(HAVE_LIBRK)
00059 if( ba_data.ba_ResourceSet != NULL_RESOURCE_SET )
00060 {
00061 rk_resource_set_destroy(ba_data.ba_ResourceSet);
00062 }
00063 #endif
00064 exit(EXIT_SUCCESS);
00065 }
00066
00067
00068
00069
00070
00071
00072 static void baUsage(const char *prog_name)
00073 {
00074 require(prog_name != NULL);
00075
00076 cerr << "Server for CPU broker objects." << endl
00077 << "Usage: "
00078 << prog_name
00079 << " [options]\n"
00080 << endl
00081 << "Options:\n"
00082 << " -h\t\tThis help message.\n"
00083 << " -V\t\tShow the version number.\n"
00084
00085 << " -o\t\tThe IOR file name. (Default: "
00086 << ba_data.ba_IORFileName << ")" << endl
00087
00088 << endl
00089
00090 << "Package: " << PACKAGE_STRING << endl
00091 << "Contact: " << PACKAGE_BUGREPORT << endl
00092
00093 ;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 static int baProcessOptions(int &argc_inout, char **&argv_inout)
00107 {
00108 int ch, retval = 0;
00109 char *prog_name;
00110 char **argv;
00111 int argc;
00112
00113 argc = argc_inout;
00114 argv = argv_inout;
00115 prog_name = argv[0];
00116 while( ((ch = getopt(argc, argv, "hVo:")) != -1) && (retval == 0) )
00117 {
00118 switch( ch )
00119 {
00120 case 'o':
00121 if( strlen(optarg) == 0 )
00122 {
00123 cerr << "Empty IOR file name" << endl;
00124 retval = 1;
00125 }
00126 else
00127 {
00128 ba_data.ba_IORFileName = optarg;
00129 }
00130 break;
00131 case 'V':
00132 cerr << PACKAGE_VERSION << endl;
00133 retval = -1;
00134 break;
00135 case 'h':
00136 case '?':
00137 default:
00138 retval = 1;
00139 break;
00140 }
00141 }
00142 argc_inout -= optind;
00143 argv_inout += optind;
00144 return( retval );
00145 }
00146
00147 int main(int argc, char *argv[])
00148 {
00149 const char *prog_name = argv[0];
00150 int retval = EXIT_FAILURE;
00151
00152
00153 ba_data.ba_IORFileName = "allup.ior";
00154
00155 signal(SIGINT, sig_exit_handler);
00156 signal(SIGTERM, sig_exit_handler);
00157
00158 #if defined(HAVE_ACE)
00159
00160 ACE_Log_Msg::instance()->priority_mask(0, ACE_Log_Msg::PROCESS);
00161 #endif
00162
00163 #if defined(HAVE_LIBRK)
00164 {
00165 char set_name[RK_NAME_LEN];
00166 rk_resource_set_t rs;
00167
00168 snprintf(set_name, sizeof(set_name),
00169 "allup.%d",
00170 getpid());
00171 if( rk_proc_get_rset(getpid()) != NULL_RESOURCE_SET )
00172 {
00173
00174 }
00175 else if( (rs = rk_resource_set_create(set_name)) != NULL )
00176 {
00177 struct cpu_reserve_attr cra;
00178 rk_reserve_t cr;
00179
00180 memset(&cra, 0, sizeof(cra));
00181 cra.compute_time.tv_sec = 0;
00182 cra.compute_time.tv_nsec = 100000;
00183 cra.period.tv_sec = 0;
00184 cra.period.tv_nsec = 500000000;
00185 cra.deadline = cra.period;
00186 cra.reserve_type.sch_mode = RSV_SOFT;
00187 cra.reserve_type.enf_mode = RSV_SOFT;
00188 cra.reserve_type.rep_mode = RSV_SOFT;
00189 cra.processor = RK_ANY_CPU;
00190 if( (rk_cpu_reserve_create(rs, &cr, &cra) == RK_SUCCESS) &&
00191 (rk_resource_set_attach_process(rs, getpid()) == RK_SUCCESS) )
00192 {
00193 ba_data.ba_ResourceSet = rs;
00194 }
00195 else
00196 {
00197 rk_resource_set_destroy(rs);
00198 }
00199 }
00200 else
00201 {
00202 perror("rk_resource_set_create");
00203 }
00204 }
00205 #endif
00206
00207 try
00208 {
00209 int rc;
00210
00211
00212 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00213 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00214
00215 PortableServer::POA_var root_poa =
00216 PortableServer::POA::_narrow(obj.in());
00217 PortableServer::POAManager_var mgr = root_poa->the_POAManager();
00218 mgr->activate();
00219
00220 PortableServer::ThreadPolicy_var thread = root_poa->
00221 create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
00222
00223 CORBA::PolicyList policy_list;
00224 policy_list.length(1);
00225 policy_list[0] = PortableServer::ThreadPolicy::_duplicate(thread.in());
00226
00227 PortableServer::POA_var st_poa = root_poa->
00228 create_POA("SingleThread",
00229 PortableServer::POAManager::_nil(),
00230 policy_list);
00231
00232 thread->destroy();
00233
00234 rc = baProcessOptions(argc, argv);
00235 if( rc == 0 )
00236 {
00237 edu::utah::pces::Allup_var allup;
00238 AllupImpl *ai;
00239
00240 ai = new AllupImpl();
00241 allup = ai->_this();
00242
00243 {
00244 ofstream ostr(ba_data.ba_IORFileName);
00245
00246 ostr << orb->object_to_string(allup.in()) << endl;
00247 ostr.close();
00248 }
00249
00250 orb->run();
00251 }
00252 else
00253 {
00254 if( rc >= 0 )
00255 {
00256 baUsage(prog_name);
00257 }
00258 }
00259
00260 orb->shutdown();
00261 }
00262 catch(const CORBA::SystemException &e)
00263 {
00264 cerr << "Caught CORBA exception: " << e << endl;
00265 }
00266 catch(...)
00267 {
00268 cerr << "Caught unknown exception..." << endl;
00269 }
00270
00271 #if defined(HAVE_LIBRK)
00272 sig_exit_handler(0);
00273 #endif
00274
00275 return( retval );
00276 }