Question

I have a simple CORBA interface with a simple operation as shown in this IDL extract:

interface MtInterface
{
    void myOperation(in string id);
}

I need to add a boolean argument to myOperation. So all I do is change my IDL to:

interface MtInterface
{
    void myOperation(in string id, in boolean flag);
}

Now this is all well and good, except that this interface is used in quite a lot of places and I would like to avoid having to modify all the calls by giving a default value of false to flag, so my first try looks like:

interface MtInterface
{
    void myOperation(in string id, in boolean flag = false);
}

but this makes omniORB bark with Syntax error in operation parameters.

So to repeat the question in the title: Is there a way to specify a default value for an operation argument in general in my IDL? And in this particular case, how would I specify a default value of false for flag?

Thanks for your help!

Was it helpful?

Solution

No. IDL doesn't support default arguments, probably because some of the target languages don't support that feature.

OTHER TIPS

What could work for you is a union as your argument. One variant has two parameters, one only a single one. You would still need to manually code the default value though, e.g. by having the single parameter version call the two parameter version with the second parameter set to what you want as the default. With this IDL:

interface MtInterface
{
   struct myShortArg
   {
      string    id;
   };

   struct myLongArg
   {
      string    id;
      boolean   flag;
   }

   union myArgument switch (unsigned short)
   {
      case 1: myShortArg   shortArg;
      case 2: myLongArg    longArg;
   }

   void myOperation(in myArgument);
}

In your implementation you would need to examine what the actual contents of the union are (details will depend on the language binding). Which you might do along the lines of:

switch(typeof(myArgument))
{
    case class(myLongArg):    myOperationImpl(myArgument.id, myArgument.flag);
                              break;

    case class(myShortArg):   myOperationImpl(myArgument.id, false);
                              break;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top