📄 ft_client.cpp
字号:
}
case '<':
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->counter();" << std::endl;
}
long attribute = this->replica_->counter(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
std::cout << "FT Client: Attribute: " << attribute << std::endl;
echo = 0;
break;
}
case '!':
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->is_alive();" << std::endl;
}
int alive = this->replica_->is_alive(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
std::cout << "FT Client: Is alive? " << alive << std::endl;
break;
}
case 'd':
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->die(" << operand << ");" << std::endl;
}
this->replica_->die(ACE_static_cast (FT_TEST::TestReplica::Bane, operand) ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
echo = 0;
break;
}
case 's':
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->get_state();" << std::endl;
}
state = this->replica_->get_state(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
stateValue = counter;
break;
}
case 'S':
{
if (state.in() != 0)
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->set_state(saved_state);" << std::endl;
}
this->replica_->set_state(state ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
counter = stateValue;
}
else
{
std::cout << "FT Client: Error: no saved state." << std::endl;
}
break;
}
case 'u':
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->get_update();" << std::endl;
}
update = this->replica_->get_update(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
updateValue = counter;
break;
}
case 'U':
{
if (update.in() != 0)
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->set_update(saved_update);" << std::endl;
}
this->replica_->set_update(update ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
counter = updateValue;
}
else
{
std::cout << "FT Client: ERROR: No saved update information." << std::endl;
}
break;
}
case 'v':
{
this->verbose_ = ACE_static_cast(Verbosity, operand);
break;
}
case 'z':
{
if (operand == 0)
{
operand = 1;
}
ACE_Time_Value tv (operand,0);
ACE_OS::sleep(tv);
break;
}
case 'q':
{
if (operand != 0)
{
ACE_TRY_NEW_ENV
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->shutdown();" << std::endl;
}
this->replica_->shutdown( ACE_ENV_SINGLE_ARG_PARAMETER);
// @@ Note: this is here because the corba event loop seems to go to sleep
// if there's nothing for it to do.
// not quite sure why, yet. Dale
this->replica_->is_alive(ACE_ENV_SINGLE_ARG_PARAMETER);
}
ACE_CATCHANY
{
std::cout << "FT Client: Ignoring expected exception during shutdown." << std::endl;
; // ignore exception during shutdown
}
ACE_ENDTRY;
}
echo = 0;
more = 0;
break;
}
default:
{
if (op != '?')
{
std::cout << "FT Client: Unknown: " << command << std::endl;
}
commandUsage(std::cerr);
break;
}
}
if (echo && this->verbose_ >= QUIET)
{
if (this->verbose_ >= LOUD)
{
std::cout << "FT Client: ->get();" << std::endl;
}
long value = this->replica_->get(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
if (value == counter)
{
if (this->verbose_ >= NORMAL)
{
std::cout << "FT Client: " << counter << std::endl;;
}
}
else
{
std::cout << "FT Client: Error: read " << value << " expecting " << counter << std::endl;
result = -1;
}
}
}
}
return result;
}
int FTClientMain::next_replica (ACE_ENV_SINGLE_ARG_DECL)
{
int result = 0;
if (this->replica_pos_ < this->replica_iors_.size())
{
this->replica_name_ = this->replica_iors_[this->replica_pos_].c_str();
this->replica_pos_ += 1;
CORBA::Object_var rep_obj = this->orb_->string_to_object (this->replica_name_ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0)
replica_ = FT_TEST::TestReplica::_narrow (rep_obj.in ());
if (! CORBA::is_nil (replica_.in ()))
{
result = 1;
}
else
{
std::cerr << "FT Client: Can't resolve IOR: " << this->replica_name_ << std::endl;
}
}
else
{
std::cerr << "***OUT_OF_REPLICAS*** " << this->replica_pos_ << std::endl;
}
return result;
}
int FTClientMain::run ()
{
int result = 0;
this->orb_ = CORBA::ORB_init(this->argc_, this->argv_ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1)
if (next_replica ())
{
// retry information
ACE_CString command;
int retry = 0;
long counter = this->replica_->get(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
if (this->verbose_ >= NORMAL)
{
std::cout << "FT Client: Initial counter " << counter << std::endl;
}
if (ACE_OS::isatty(fileno(stdin)))
{
std::cout << "FT Client: Commands(? for help):" << std::endl;
}
int more = 1;
while (more && result == 0 && ! this->commandIn_->eof())
{
ACE_TRY_NEW_ENV
{
result = pass (counter, more, command, retry);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::SystemException, sysex)
{
std::cout << "FT Client: Caught system exception: " << std::endl;
ACE_PRINT_EXCEPTION (sysex, "FT Client");
retry = 0;
int handled = 0;
handled = next_replica();
if (handled)
{
std::cout << "FT Client: Recovering from fault." << std::endl;
std::cout << "FT Client: Activate " << this->replica_name_ << std::endl;
if (command.length () == 0)
{
std::cout << "FT Client: No command to retry." << std::endl;
}
else if (command[0] == 'd')
{
std::cout << "FT Client: Not retrying \"die\" command." << std::endl;
}
else if (sysex.completed () == CORBA::COMPLETED_YES)
{
std::cout << "FT Client: Last command completed. No retry needed." << std::endl;
}
else
{
if (sysex.completed () == CORBA::COMPLETED_MAYBE)
{
std::cout << "FT Client: Last command may have completed. Retrying anyway." << std::endl;
}
retry = 1;
std::cout << "FT Client: Retrying command: " << command << std::endl;
}
}
if (! handled)
{
std::cout << "FT Client: Exception not handled. Rethrow. " << std::endl;
ACE_RE_THROW;
}
}
ACE_ENDTRY;
}
}
else
{
std::cerr << "FT Client: Can't connect to replica." << std::endl;
}
return result;
}
int
main (int argc, char *argv[])
{
FTClientMain app;
int result = app.parse_args(argc, argv);
if (result == 0)
{
ACE_TRY_NEW_ENV
{
result = app.run ();
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"FT_Client::main\t\n");
result = -1;
}
ACE_ENDTRY;
}
return result;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Vector<ACE_CString>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
# pragma ACE_Vector<ACE_CString>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -