⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cc_command.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  ACE_ENDTRY;

  return 1; // CC_SUCCESS
}

CC_ChangeMode_Cmd::
    CC_ChangeMode_Cmd (const char *lock_set_name,
                       CosConcurrencyControl::lock_mode held_mode,
                       CosConcurrencyControl::lock_mode new_mode)
  : name_(ACE_OS::strdup (lock_set_name)),
    held_mode_ (held_mode),
    new_mode_ (new_mode)
{
  //  printf("CC_ChangeMode_Cmd::CC_ChangeMode_Cmd: lock set: %s, held mode: %s, new mode: %s\n",
  //         lock_set_name,
  //         CC_TestUtils::get_lock_mode_name(held_mode),
  //         CC_TestUtils::get_lock_mode_name(new_mode));
}

CC_ChangeMode_Cmd::~CC_ChangeMode_Cmd()
{
  ACE_OS::strdup (this->name_);
}

int CC_ChangeMode_Cmd::execute(void)
{
  if(excep_)
    {
      printf("Exception: %s\n", excep_->_rep_id ());
      delete excep_;
      excep_ = 0;
      return 0; // CC_FAIL
    }

  printf("Executing change_mode command (lock set: %s, held_mode: %s, new_mode: %s)\n",
         name_, CC_TestUtils::get_lock_mode_name(held_mode_),
         CC_TestUtils::get_lock_mode_name(new_mode_));

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      CosConcurrencyControl::LockSet_var ccls = GetLockSet(name_ ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ccls->change_mode (held_mode_, new_mode_
                    ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "CC_ChangeMode_Cmd::execute(void)");
    }
  ACE_ENDTRY;
  return 1; // CC_SUCCESS
}

CC_Sleep_Cmd::CC_Sleep_Cmd(int seconds)
  : time_ (seconds)
{
}

CC_Sleep_Cmd::~CC_Sleep_Cmd()
{
}

int CC_Sleep_Cmd::execute(void)
{
  if(excep_)
    {
      printf("Exception: %s\n", excep_->_rep_id ());
      delete excep_;
      excep_ = 0;
      return 0; // CC_FAIL
    }

  printf("Executing sleep command (time: %i)\n", time_);

  ACE_OS::sleep(time_);
  return 1; // CC_SUCCESS
}

CC_Repeat_Cmd::CC_Repeat_Cmd(int times)
  : times_ (times)
{
}

CC_Repeat_Cmd::~CC_Repeat_Cmd()
{
}

int CC_Repeat_Cmd::execute(void)
{
  if(excep_)
    {
      printf("Exception: %s\n", excep_->_rep_id ());
      delete excep_;
      excep_ = 0;
      return 0; // CC_FAIL
    }

  printf("Executing repeat command (times: %i)\n", times_);

  return 1; // CC_SUCCESS
}

CC_Wait_Cmd::CC_Wait_Cmd (const char *prompt)
  : prompt_ (ACE_OS::strdup (prompt))
{
}

CC_Wait_Cmd::~CC_Wait_Cmd()
{
  ACE_OS::free (this->prompt_);
}

int CC_Wait_Cmd::execute(void)
{
  if(excep_)
    {
      printf("Exception: %s\n", excep_->_rep_id ());
      delete excep_;
      excep_ = 0;
      return 0; // CC_FAIL
    }

  printf("Executing wait command\n");

  char s[1];
  printf("%s", prompt_);
  ACE_OS::gets(&s[0]);
  return 1; // CC_SUCCESS
}

CC_Excep_Cmd::CC_Excep_Cmd (const char *excep)
  : ex_ (ACE_OS::strdup (excep))
{
  //  printf("CC_Excep_Cmd::CC_Excep_Cmd: excep: %s\n", excep);
}

CC_Excep_Cmd::~CC_Excep_Cmd(void)
{
  ACE_OS::free (this->ex_);
}

int
CC_Excep_Cmd::execute(void)
{
  printf("Executing excep command (expected: %s)\n", ex_);
  // First we check to see if an exception has occured. If not we fail
  // because we expected to see one
  if(excep_==0)
    return 0; // CC_FAIL

  // If there is an exception check that it's the expected one
  if(ACE_OS::strcmp(excep_->_rep_id (), ex_)==0)
    {
      delete excep_;
      excep_ = 0;
      return 1; // CC_SUCCESS
    }
  else
    {
      printf("Exception: %s\n", excep_->_rep_id ());
      delete excep_;
      excep_ = 0;
      return 0; // CC_FAIL
    }
}

CC_Dummy_Cmd::CC_Dummy_Cmd(void)
{
}

CC_Dummy_Cmd::~CC_Dummy_Cmd(void)
{
}

int
CC_Dummy_Cmd::execute(void)
{
  return 1; // CC_SUCCESS
}

CC_Print_Cmd::CC_Print_Cmd (const char * message)
  : msg_ (ACE_OS::strdup (message))
{
}

CC_Print_Cmd::~CC_Print_Cmd(void)
{
  ACE_OS::free(msg_);
}

int
CC_Print_Cmd::execute(void)
{
  printf("%s\n", msg_);
  return 1; // CC_SUCCESS
}

CC_Lookup_Cmd::CC_Lookup_Cmd (const char *lock_set_name)
  : name_ (ACE_OS::strdup (lock_set_name))
{
}

CC_Lookup_Cmd::~CC_Lookup_Cmd()
{
  if(name_)
    {
      ACE_OS::free(name_);
      name_ = 0;
    }
}

int
CC_Lookup_Cmd::execute(void)
{
  if(excep_)
    {
      printf("Exception: %s\n", excep_->_rep_id ());
      delete excep_;
      excep_ = 0;
      return 0; // CC_FAIL
    }

  printf("Executing lookup command (lock set: %s)\n", name_);

  // Do the lookup if we haven't done it before
  if(cc_lockset_.in() == 0)
    {
      ACE_DECLARE_NEW_CORBA_ENV;
      ACE_TRY
        {
          CORBA::Object_var ccls_obj =
            CC_naming_service::Instance()->get_obj_from_name ("",
                                                              name_
                                                              ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          CosConcurrencyControl::LockSet_var ccls =
            CosConcurrencyControl::LockSet::_narrow (ccls_obj.in ()
                                                     ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          cc_lockset_ = ccls;
          ACE_TRY_CHECK;

        }
      ACE_CATCHANY
        {
          ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                               "CC_UnLock_Cmd::execute(void)");
        }
      ACE_ENDTRY;
    }
  return 1; // CC_SUCCESS
}

CC_CommandElem::CC_CommandElem(CC_Command *cmd, CC_CommandElem *next)
  : next_ (next), cmd_ (cmd)
{
}

CC_CommandElem::~CC_CommandElem(void)
{
}

CC_Command *CC_CommandElem::GetCommand(void)
{
  return cmd_;
}

CC_CommandElem *
CC_CommandElem::GetNext(void)
{
  return next_;
}

void
CC_CommandElem::SetNext(CC_CommandElem *next)
{
  next_ = next;
}

CC_CommandList::CC_CommandList(void)
  : head_ (0), last_ (0), times_ (1)
{
  printf("CC_CommandList::CC_CommandList\n");
}

CC_CommandList::~CC_CommandList(void)
{
}

int
CC_CommandList::add(CC_Command *cmd)
{
  if(head_==0)
    {
      head_ = new CC_CommandElem(cmd, 0);
      last_ = head_;
    }
  else
    {
      CC_CommandElem *tmp = new CC_CommandElem(cmd, 0);
      last_->SetNext(tmp);
      last_ = tmp;
    }
  return 0;
}

int
CC_CommandList::execute(void)
{
  CC_CommandElem *current = head_;

  for(int i=0; i<times_; i++)
    {
      current = head_;
      while(current!=0)
        {
          if(current->GetCommand()->execute()==0) // == CC_FAIL
            {
              return 0; // CC_FAIL
            }
          current = current->GetNext();
        }
    }
  return 1; // CC_SUCCESS
}

void
CC_CommandList::setrepeat(int times)
{
  times_ = times;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -