int main(int argc, char* argv[]) { cout << "processing configuration options ..." << endl; // pointers to options we will create for the grid server program option_t* opt_server_host = 0; option_t* opt_connect_port = 0; const option_level_cnt = 3; option_group_t options(option_level_cnt); W_COERCE(options.add_option("connect_port", "1024 < integer < 65535", "1234", "port for connecting to grid server", false, option_t::set_value_long, opt_connect_port)); W_COERCE(options.add_option("server_host", "host address", "localhost", "address of host running server", false, option_t::set_value_charstr, opt_server_host)); if (init_config_options(options, "client", argc, argv)) { usage(options); exit(1); } // there should not be any other command line arguments if (argc > 1) { usage(options); exit(1); } int port = strtol(opt_connect_port->value(), 0, 0); cout << "trying to connect to server at port " << port<< endl; if (!connect_to_server(opt_server_host->value(), port)) { cerr << "Shutting down due to connection failure" << endl; exit(1); } process_user_commands(); disconnect_from_server(); cout << "Finished!" << endl; return 0; }
void smthread_main_t::run() { rc_t rc; // pointers to options we will create for the grid server program option_t* opt_device_name = 0; option_t* opt_device_quota = 0; option_t* opt_num_rec = 0; option_t* opt_rec_size = 0; if(debug) { outstream << "processing configuration options ..." << " argc " << argc << endl; for(int i=0; i < argc; i++) { outstream << " -------- argv["<<i<<"]=" << argv[i] << endl; } sendout(); } const int option_level_cnt = 3; option_group_t options(option_level_cnt); W_COERCE(options.add_option("device_name", "device/file name", NULL, "device containg volume holding file to scan", true, option_t::set_value_charstr, opt_device_name)); W_COERCE(options.add_option("device_quota", "# > 1000", "2000", "quota for device", false, option_t::set_value_long, opt_device_quota)); W_COERCE(options.add_option("num_rec", "# > 0", NULL, "number of records in file", true, option_t::set_value_long, opt_num_rec)); W_COERCE(options.add_option("rec_size", "# > 0", "7800", "size for records", false, option_t::set_value_long, opt_rec_size)); // have the SSM add its options to the group W_COERCE(ss_m::setup_options(&options)); rc = init_config_options(options, "server", argc, argv); if (rc.is_error()) { usage(options); retval = 1; return; } int cmdline_nrecords(-1); // trumps config options if set int nrecords(0); // set by config options // process command line: looking for the "-i" flag bool init_device = false; int option; int nthreads(1); while ((option = getopt(argc, argv, "Adn:hit:")) != -1) { if(debug) { outstream << "option " << option << endl; sendout(); } switch (option) { case 'A' : append_only = true; if(debug) { outstream << "append only " << endl; sendout(); } break; case 'd' : debug = true; break; case 'n' : cmdline_nrecords = strtol(optarg, 0, 0); break; case 'h' : usage(options); retval = 1; return; break; case 'i' : { if (init_device) { cerr << "Error only one -i parameter allowed" << endl; usage(options); retval = 1; return; } init_device = true; } break; case 't' : nthreads = strtol(optarg, 0, 0); break; default: usage(options); retval = 1; return; break; } } outstream << "Starting SSM and performing recovery ..." << endl; sendout(); ssm = new ss_m(); if (!ssm) { cerr << "Error: Out of memory for ss_m" << endl; retval = 1; return; } smksize_t quota = strtol(opt_device_quota->value(), 0, 0); nrecords = strtol(opt_num_rec->value(), 0, 0); smsize_t rec_size = strtol(opt_rec_size->value(), 0, 0); rid_t start_rid; stid_t fid; if(cmdline_nrecords > 0) { outstream << " num rec of " << cmdline_nrecords << " overrides config option num rec of " << nrecords << endl; sendout(); nrecords = cmdline_nrecords; } rc = setup_device_and_volume(opt_device_name->value(), init_device, quota); if (rc.is_error()) { cerr << "could not set up device/volume due to: " << endl; cerr << rc << endl; delete ssm; rc = RCOK; // force deletion of w_error_t info hanging off rc // otherwise a leak for w_error_t will be reported retval = 1; if(rc.is_error()) W_COERCE(rc); // avoid error not checked. return; } outstream << "************ vid " << vid << endl; sendout(); outstream << "************ NTHREADS " << nthreads << endl; sendout(); /* fork off the correct number of threads */ threadptr * subthreads = new threadptr [nthreads]; if(init_device) { for(int i=0; i<nthreads; i ++) { int nrecs = nrecords/(i?i:1) +1; subthreads[i] = new smthread_creator_t(vid, i, nrecs, rec_size, append_only); #if defined(DEBUG_DESPERATE) && defined(USING_VALGRIND) if(RUNNING_ON_VALGRIND) { check_definedness(subthreads[i], sizeof(smthread_creator_t)); check_valgrind_errors(__LINE__, __FILE__); } #endif } } else { for(int i=0; i<nthreads; i ++) { int nrecs = nrecords/(i?i:1) +1; subthreads[i] = new smthread_scanner_t(vid, i, nrecs, rec_size); } } for(int i=0; i<nthreads; i ++) { subthreads[i]->fork(); } for(int i=0; i<nthreads; i ++) { subthreads[i]->join(); } for(int i=0; i<nthreads; i ++) { delete subthreads[i]; } delete[] subthreads; outstream << "\nShutting down SSM ..." << endl; sendout(); delete ssm; outstream << "*******************************************" << endl; outstream << "Finished! return value=" << retval << endl; outstream << "*******************************************" << endl; sendout(); }
/**\defgroup EGOPTIONS Example of setting up options. * This method creates configuration options, starts up * the storage manager, */ w_rc_t smthread_main_t::handle_options() { option_t* opt_device_name = 0; option_t* opt_device_quota = 0; option_t* opt_num_rec = 0; cout << "Processing configuration options ..." << endl; // Create an option group for my options. // I use a 3-level naming scheme: // executable-name.server.option-name // Thus, the file will contain lines like this: // create_rec.server.device_name : /tmp/example/device // *.server.device_name : /tmp/example/device // create_rec.*.device_name : /tmp/example/device // const int option_level_cnt = 3; _options = new option_group_t (option_level_cnt); if(!_options) { cerr << "Out of memory: could not allocate from heap." << endl; retval = 1; return RC(fcINTERNAL); } option_group_t &options(*_options); W_COERCE(options.add_option("device_name", "device/file name", NULL, "device containg volume holding file to scan", true, option_t::set_value_charstr, opt_device_name)); W_COERCE(options.add_option("device_quota", "# > 1000", "2000", "quota for device", false, option_t::set_value_long, opt_device_quota)); // Default number of records to create is 1. W_COERCE(options.add_option("num_rec", "# > 0", "1", "number of records in file", true, option_t::set_value_long, opt_num_rec)); // Have the SSM add its options to my group. W_COERCE(ss_m::setup_options(&options)); cout << "Finding configuration option settings." << endl; w_rc_t rc = init_config_options(options, "server", _argc, _argv); if (rc.is_error()) { usage(options); retval = 1; return rc; } cout << "Processing command line." << endl; // Process the command line int option; while ((option = getopt(_argc, _argv, "hit:n:s:r:dpo:")) != -1) { switch (option) { case 'i' : _initialize_device = true; break; case 's' : // how many iterations for scan _scan_file = atoi(optarg); break; case 'h' : usage(options); break; case 't': // which test to run _test_no = atoi(optarg); break; case 'n': _num_parts = atoi(optarg); break; case 'r': _rec_size = atoi(optarg); break; case 'd': // dora _bIgnoreLocks = true; break; case 'p': // plp _bIgnoreLatches = true; break; case 'o': // which mrbt design _design_no = atoi(optarg);; break; default: usage(options); retval = 1; return RC(fcNOTIMPLEMENTED); break; } } { cout << "Checking for required options..."; /* check that all required options have been set */ w_ostrstream err_stream; w_rc_t rc = options.check_required(&err_stream); if (rc.is_error()) { cerr << "These required options are not set:" << endl; cerr << err_stream.c_str() << endl; return rc; } cout << "Options OK; values are: { " << endl; options.print_values(false, cout); cout << "} end list of options values. " << endl; } // Grab the options values for later use by run() _device_name = opt_device_name->value(); _quota = strtol(opt_device_quota->value(), 0, 0); _num_rec = strtol(opt_num_rec->value(), 0, 0); // print the options cout << "DESIGN: " << _design_no << endl << "TEST: " << _test_no << endl << "_num_rec: " << _num_rec << endl << "_rec_size: " << _rec_size << endl << " _initialize_device: " << _initialize_device << endl << "_num_parts: " << _num_parts << endl << "_scan_file: " << _scan_file << endl << "_bIgnoreLocks: " << _bIgnoreLocks << endl << "_bIgnoreLatches: " << _bIgnoreLatches << endl; return RCOK; }