Lets say I have a simple piece of code like this:
if(!hardware.produceMeSomeData())
somehowHandleFailure();
Now I want to have my HW run on a separate computer which I want to communicate with remotely with CORBA. So the CORBA layer on both sides would look similar to this:
HardwareData* HardwareClient::produceMeSomeData()
{
IDL::HardwareData_var hwDataIdl;
_hardwareRef->produceMeSomeData(hwDataIdl.out());
HardwareData* hwData = nullptr;
// here I'd like to do sth like this:
if(!CORBA::is_nil(hwDataIdl))
HardwareDataFromIdl(hwDataIdl.in(), hwData);
return hwData;
}
HardwareServant::produceMeSomeData(IDL::HardwareData_out hwDataOut)
{
HardwareData* hwData = _hardware->produceMeSomeData();
if(hwData)
HardwareDataToIdl(hwData, hwDataOut.ptr());
else
// ???
}
The problem is, CORBA doesn't seem to allow returning nullpointers in any way. If I directly assign nullptr to the _out type, the call will throw a BAD_PARAM exception as also stated in the docs, same if I don't assign anything to it. So it basically forces me to create an object and with that it's kind of hard to design the logic I need here. Concretely I'd have to abuse a valid object to represent a nullpointer just so I can differentiate both results on the client side. Another idea of mine would be to wrap the return type into a struct with a boolean that tells me whether the object is valid or not.
The quick hack I'm using right now is just to catch the BAD_PARAM exception on the client side and return nullptr in this case but this doesn't look like good and stable design either.
Is there a better and simpler solution for this?