// // parse_args // int AnalogTemperatureProbe_Impl::parse_args (const char * args) { // Conver the command string into a vector of commands. ACE_ARGV_T <char> argv (args); const char * optargs = "d"; // Parse the command-line options. ACE_Get_Opt get_opt (argv.argc (), argv.argv (), optargs, 0); get_opt.long_option ("debug", ACE_Get_Opt::NO_ARG); int opt = 0; while (EOF != (opt = get_opt ())) { switch (opt) { case 0: if (0 == ACE_OS::strcmp ("debug", get_opt.long_option ())) this->debug_ = true; break; case 'd': this->debug_ = true; break; } } return 0; }
// // parse_args // int Tron_Deployment_Handler::parse_args (char * args[]) { // Convert the command string into a vector of commands. ACE_ARGV_T <char> argv (args); const char * optargs = ""; // Parse the command-line options. ACE_Get_Opt get_opt (argv.argc (), argv.argv (), optargs, 0); get_opt.long_option ("TimeUnit", ACE_Get_Opt::ARG_REQUIRED); get_opt.long_option ("Timeout", ACE_Get_Opt::ARG_REQUIRED); int opt = 0; while (EOF != (opt = get_opt ())) { switch (opt) { case 0: if (0 == ACE_OS::strcmp ("TimeUnit", get_opt.long_option ())) { size_t timeunit; std::istringstream istr (get_opt.opt_arg ()); istr >> timeunit; if (istr.fail ()) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%T (%t) - %M - failed to parse TimeUnit value\n")), -1); this->timeunit_ = timeunit; } if (0 == ACE_OS::strcmp ("Timeout", get_opt.long_option ())) { size_t timeout; std::istringstream istr (get_opt.opt_arg ()); istr >> timeout; if (istr.fail ()) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%T (%t) - %M - failed to parse Timeout value\n")), -1); this->timeout_ = timeout; } break; }
// // test_load_configuration_command_line // int test_load_configuration_command_line (void) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%T (%t) - %M - executing test_load_configuration_command_line ()\n"))); OASIS::Standard_EINode einode; ACE_ARGV_T <char> args; args.add ("test_load_configuration_command_line -c test.einode"); einode.init (args.argc (), args.argv ()); if (!validate_einode_configuration (einode.configuration ())) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%T (%t) - %M - invalid configuration\n")), -1); return 0; }
int ACE_TMAIN (int, ACE_TCHAR *[]) { CPMDAppLayer app_layer; bool exception(false); try { int connection_timeout_ms; int request_timeout_ms; if (!get_timeout_params(connection_timeout_ms, request_timeout_ms)) { throw 0; } std::string node = CPMUtils_ns::CPMUtils::get_local_addr(); std::string cpmd_port; if (!CPMUtils_ns::CPMUtils::get_cpmd_port(cpmd_port)) { EVENT_HANDLER_SYSTEMLOG->handle_event( _SRC, CPMDEvents::ev_cpmd_port_env_var_not_defined, LM_ERROR); throw 0; } std::string iiop = std::string("iiop://") + node + ":" + cpmd_port; //ACE_DEBUG((LM_DEBUG, "CPMD::IIOP = %s\n", iiop.c_str())); ACE_ARGV_T<ACE_TCHAR> args; args.add(ACE_TEXT("-ORBListenEndPoints")); args.add(ACE_TEXT(iiop.c_str())); app_layer.cpmo_id("CPMD"); CPMTAOLayer tao_layer; if (tao_layer.init(args.argc(), args.argv())) { tao_layer.set_request_timeout_orb(request_timeout_ms); // limit time for request to request_timeout_ms msec tao_layer.set_connection_timeout_orb(connection_timeout_ms); // limit time for connection to connection_timeout_ms msec app_layer.tao_layer(&tao_layer); try { if (!app_layer.run()) { throw 0; } } catch(...) { EVENT_HANDLER_SYSTEMLOG->handle_event( _SRC, CPMDEvents::ev_cpmd_app_layer_failure, LM_ERROR); throw 0; } } else { EVENT_HANDLER_SYSTEMLOG->handle_event( _SRC, CPMDEvents::ev_cpmd_tao_layer_init_failure, LM_ERROR); throw 0; } EVENT_HANDLER_SYSTEMLOG->handle_event( _SRC, CPMDEvents::ev_server_stopped, LM_INFO, "CPMD"); } catch(...) { EVENT_HANDLER_SYSTEMLOG->handle_event( _SRC, CPMDEvents::ev_main_exception, LM_ERROR, "CPMD"); EVENT_HANDLER_SYSTEMLOG->handle_event( _SRC, CPMDEvents::ev_server_stopped, LM_ERROR, "CPMD"); exception = true; } if (exception) { return -1; } return 0; }
int main (int argc, char* argv[]) { char parent_process_path_buf[128]; sprintf(parent_process_path_buf, "/proc/%d/cmdline", getppid()); std::ifstream parent_cmdline; parent_cmdline.open(parent_process_path_buf); std::string parent_cmdline_str; std::getline(parent_cmdline, parent_cmdline_str); parent_cmdline.close(); std::cout <<(char *)getauxval(AT_EXECFN) << " pid " << getpid() << " Parent PID is " << getppid() << " " <<parent_cmdline_str << " " <<currentDateTime() << std::endl; usleep(1000000* (rand()%10+1)); std::cout <<get_process_name(getpid()) << " pid " << getpid() << " Parent PID is " << getppid() << " " <<parent_cmdline_str << " " <<currentDateTime() << std::endl; std::cout << "Resource size is " << (size_t)&_binary_main_cpp_size<<std::endl; std::string src(&_binary_main_cpp_start,(size_t)( &_binary_main_cpp_end-&_binary_main_cpp_start)); ACE_Argv_Type_Converter to_tchar (argc, argv); ACE_Get_Opt get_opt (argc, to_tchar.get_TCHAR_argv (), ACE_TEXT ("msad:"), 1, 0); //ACE_Get_Opt get_opt (argc,argv, ACE_TEXT ("P"), 1, 0); for (int c; (c = get_opt ()) != -1; ) switch (c) { case 's': // print source code std::cout <<src << std::endl; break; case 'm': // print free memory information { std::cout << "Parent process is " << get_process_name(getppid()) << std::endl; std::string ss=runcmd("free -m"); std::cout << ss <<std::endl; } break; case 'a': // test ACE_Argv_Type_Converter { ACE_ARGV_T<char> argslist; argslist.add("abc def ghi"); argslist.add("4th"); argslist.add("5th"); int newargc=argslist.argc(); ACE_Argv_Type_Converter cmdline(newargc, argslist.argv()); char** newargs=cmdline.get_ASCII_argv(); std::cout << "arg count " << argslist.argc()<<std::endl; for(int i=0; i<newargc;i++) std::cout<< "argv["<<i<<"] " << newargs[i]<<std::endl; } break; case 'd': // compare performance of itoa and sprintf { int cnt = ACE_OS::atoi(get_opt.opt_arg ()); uint64_t perf1start= getCurrentMillis(); char buf[16]; for(int i=0; i<cnt; i++) itoa(i, buf, 10); uint64_t perf2start= getCurrentMillis(); for(int i=0; i<cnt; i++) sprintf(buf, "%d", i); uint64_t perf2stop= getCurrentMillis(); std::cout << "convert "<<cnt<<" int to string by itoa in " << (perf2start-perf1start) << " milliseconds, sprintf in " << (perf2stop-perf2start) << " milliseconds\n"; } break; default: break; } return 0; }