Example #1
0
static VALUE _r2tao_set_request_exceptions(CORBA::Request_ptr _req, VALUE exc_list)
{
  long exc_len = 0;
  CORBA::ORB_var _orb = _req->target ()->_get_orb ();

  // clear all current excepts
  CORBA::ULong x_num = _req->exceptions ()->count ();
  while (x_num > 0)
    _req->exceptions ()->remove (--x_num);

  if (exc_list != Qnil)
  {
    exc_len = RARRAY (exc_list)->len;
    for (long x=0; x<exc_len ;++x)
    {
      VALUE exctc = rb_ary_entry (exc_list, x);
      CORBA::TypeCode_var _xtc = r2tao_Typecode_r2t (exctc, _orb.in ());
      _req->exceptions ()->add (_xtc.in ());
    }
  }
  return LONG2NUM (exc_len);
}
Example #2
0
static VALUE _r2tao_invoke_request(CORBA::Request_ptr _req, bool& _raise)
{
  CORBA::ULong ret_num = 0;
  // get the ORB we're using for the request
  CORBA::ORB_var _orb  = _req->target ()->_get_orb ();

  CORBA::TypeCode_var _ret_tc = _req->return_value ().type ();
  // invoke twoway if resulttype specified (could be void!)
  if (_ret_tc->kind () != CORBA::tk_null)
  {
    if (_ret_tc->kind () != CORBA::tk_void)
      ++ret_num;

    CORBA::ULong arg_num = _req->arguments ()->count ();
    for (CORBA::ULong a=0; a<arg_num ;++a)
    {
      CORBA::NamedValue_ptr _arg = _req->arguments ()->item (a);
      if (ACE_BIT_DISABLED (_arg->flags (), CORBA::ARG_IN))
        ++ret_num;
    }

    // invoke request
    try
    {
      _req->invoke ();
    }
    catch (CORBA::UnknownUserException& user_ex)
    {
      CORBA::Any& _excany = user_ex.exception ();

      CORBA::ULong exc_len = _req->exceptions ()->count ();
      for (CORBA::ULong x=0; x<exc_len ;++x)
      {
        CORBA::TypeCode_var _xtc = _req->exceptions ()->item (x);
        if (ACE_OS::strcmp (_xtc->id (),
                            _excany._tao_get_typecode ()->id ()) == 0)
        {
          VALUE x_rtc = r2tao_Typecode_t2r(_xtc.in (), _orb.in ());
          VALUE rexc = r2tao_Typecode_Any2Ruby (_excany,
                                                _xtc.in (),
                                                x_rtc, x_rtc,
                                                _orb.in ());
          _raise = true;
          return rexc;
        }
      }

      // rethrow if we were not able to identify the exception
      // will be caught and handled in outer exception handler
      throw;
    }

    // handle result and OUT arguments
    VALUE result = (ret_num>1 ? rb_ary_new () : Qnil);

    if (_ret_tc->kind () != CORBA::tk_void)
    {
      CORBA::Any& retval = _req->return_value ();
      VALUE result_type = r2tao_Typecode_t2r(_ret_tc.in (), _orb.in ());
      // return value
      if (ret_num>1)
        rb_ary_push (result, r2tao_Typecode_Any2Ruby (retval, _ret_tc.in (), result_type, result_type, _orb.in ()));
      else
        result = r2tao_Typecode_Any2Ruby (retval, _ret_tc.in (), result_type, result_type, _orb.in ());

      --ret_num; // return value handled
    }

    // (in)out args
    if (ret_num > 0)
    {
      for (CORBA::ULong a=0; a<arg_num ;++a)
      {
        CORBA::NamedValue_ptr _arg = _req->arguments ()->item (a);
        if (ACE_BIT_DISABLED (_arg->flags (), CORBA::ARG_IN))
        {
          CORBA::TypeCode_var _arg_tc = _arg->value ()->type ();
          VALUE arg_rtc = r2tao_Typecode_t2r(_arg_tc.in (), _orb.in ());
          if (result != Qnil)
            rb_ary_push (result, r2tao_Typecode_Any2Ruby (*_arg->value (), _arg_tc.in (), arg_rtc, arg_rtc, _orb.in ()));
          else
            result = r2tao_Typecode_Any2Ruby (*_arg->value (), _arg_tc.in (), arg_rtc, arg_rtc, _orb.in ());
        }
      }
    }

    return result;
  }
  else  // invoke oneway
  {
    // oneway
    _req->send_oneway ();

    return Qtrue;
  }
}