[omniORB] cannot marshal a null fixed

Duncan Grisby duncan@grisby.org
Tue Mar 11 13:07:02 2003


------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <14325.1047387896.1@grisby.org>

On Monday 10 March, "Renzo Tomaselli" wrote:

> this sounds strange. All of:
> 
> CORBA::Fixed f;
> CORBA::Fixed f(0);
> CORBA::Fixed f("0");
> 
> etc. yield the same null fixed, thus they are invalid.

There is nothing invalid (or null) about them. However, fixed point
values can only be sent through an IDL interface if either the IDL
declares a specific fixed point type, with specific limits, or if you
put it in an any.

To put it in an any, you need a typecode; it is illegal to have a
typecode specifying a fixed with zero digits, just as it is illegal to
write IDL that says typedef fixed<0,0> MyFixed. If you are generating
a typecode, either explicitly or implicitly with
CORBA::Any::from_fixed, it is up to you to make sure it is legal.

I've attached a simple client and server that demonstrate that it is
fine to send zero as a fixed point value.

Cheers,

Duncan.


------- =_aaaaaaaaaa0
Content-Type: text/plain; name="adder.idl"; charset="us-ascii"
Content-ID: <14325.1047387896.2@grisby.org>

typedef fixed<5,2> MyFixed;

interface Adder {
  MyFixed add(in MyFixed a, in MyFixed b);
};

------- =_aaaaaaaaaa0
Content-Type: text/plain; name="adderServer.cc"; charset="us-ascii"
Content-ID: <14325.1047387896.3@grisby.org>

#include <iostream.h>
#include <adder.hh>

class Adder_i : public POA_Adder,
		public PortableServer::RefCountServantBase
{
public:
  Adder_i() {}

  MyFixed add(const MyFixed &a, const MyFixed &b) {
    return a + b;
  }
};

int main(int argc, char** argv)
{
  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
  CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
  PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);

  Adder_i* adderServant = new Adder_i();
  Adder_var adderObjref = adderServant->_this();
  adderServant->_remove_ref();

  PortableServer::POAManager_var pm = poa->the_POAManager();
  pm->activate();

  CORBA::String_var ior = orb->object_to_string(adderObjref);
  cout << ior << endl;

  orb->run();
  return 0;
}

------- =_aaaaaaaaaa0
Content-Type: text/plain; name="adderClient.cc"; charset="us-ascii"
Content-ID: <14325.1047387896.4@grisby.org>

#include <iostream.h>
#include <adder.hh>

int main(int argc, char** argv)
{
  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
  CORBA::Object_var obj = orb->string_to_object(argv[1]);

  Adder_var adder = Adder::_narrow(obj);
    
  CORBA::Fixed a, b, r;
  CORBA::String_var s;

  a = 123;
  b = 456;

  r = adder->add(a, b);
  s = r.to_string();

  cout << s << endl;

  a = 0;
  r = adder->add(a, b);
  s = r.to_string();

  cout << s << endl;

  try {
    a = 1234;
    r = adder->add(a, b);
    s = r.to_string();

    cout << s << endl;
  }
  catch (CORBA::DATA_CONVERSION& ex) {
    // DATA_CONVERSION is thrown because a exceeds the fixed digits.
  }
  
  orb->destroy();
  return 0;
}

------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <14325.1047387896.5@grisby.org>

-- 
 -- Duncan Grisby         --
  -- duncan@grisby.org     --
   -- http://www.grisby.org --

------- =_aaaaaaaaaa0--