huray.txt= code associated with "Interoperable Objects for Distributed Real-Time Systems," Lazlo Huray, March 1997 Listing 1: IDL interface definition file // File: sensor.ifc (written by the sensor implementation) interface Sensor { getValue(in IOCM::Word channel, out IOCM::Dword value); }; Listing 2: Interface type definition include file generated by C++ IDL compiler // File: sensor_ifc.hpp (generated by the client side IDL compiler) # include Òiocm_obj.hppÓ // see later class Sensor_ifc : public virtual IOCM::Object { public: Sensor_ifc(long sensorIdent, long ifcIdent=0); int getValue(short channel, long* valueP); int getValue(short channel, long* valueP, short invokeIdent); // ... }; Listing 3: The C++ clients instantiate the object interface, and use it normally. // File: client.hpp (written by the client implementation) #include Òsensor_ifc.hppÓ const long mySensorIdent= 0x12345678; // object ident: well known constant class Client { public: Client() : mySensor(mySensorIdent) {} void processSensorValue_synchronously(); void processSensorValue_asynchronously(); private: Sensor_ifc mySensor; // instantiate the interface class long sensorValue; }; // File: client.cpp (written by the client implementation) #include Òclient.hppÓ void Client::processSensorValue_synchronously() { mySensor.getValue(25, &sensorValue); // synchronous call for channel #25 // process the ÔsensorValueÕ ... } void Client::processSensorValue_asynchronously() { const short myInvokeIdent= 0x1234; // used for asynchronous method call const long myTimeOut = 100; // 100 ms timeout mySensor.getValue(25, &sensorValue, myInvokeIdent); // asynchronous call // do something else... (Note: the ÕsensorValueÕ is not available yet!) switch(IOCM::checkInvocation(myInvokeIdent, myTimeOut)) { case IOCM::Status_OK: // process the ÔsensorValueÕ ... break; case IOCM::Status_Timeout: // handle the time out situation break; default: // handle the error situation } } Listing 4 : Code for example of the usage of the IOCM-MB by IDL compiler at client side. // File: sensor_ifc.cpp (generated by the client side IDL compiler) #include Òsensor_ifc.hppÓ Sensor_ifc::Sensor_ifc(long sensorIdent, long ifcIdent) :IOCM::Object(ifcIdent), ident(sensorIdent) {} // ident is a member int Sensor_ifc::getValue(short channel, long* valueP) { messageBox.createMessage(8); // Data Buffer size= 8 bytes messageBox.setMessageIdents(IOCM::Default_MessageIdent); // order&reply ids // Fill the Data Buffer from offset 0: messageBox.putWord(1, 0); // offset 0= methodIdent= 1st method messageBox.putWord(channel, 2); // offset 2= input parameter messageBox.sendOrder(ident, Object::getIdent()); // send(dst,src) message messageBox.receiveReply(); // wait for the reply messageBox.getDword(valueP, 4); // output parameter= offset 4 messageBox.deleteMessage(); // delete the message return IOCM::Status_OK; // simplified example: no error checking } int Sensor_ifc::getValue(short channel, long* valueP, short invokeIdent) { messageBox.createMessage(8+4); // + 4 bytes for the ÔvaluePÕ mb.setMessageIdent(IOCM::Default_MessageIdent); mb.setReplyMessageIdent(invokeIdent); messageBox.putWord(1, 0); // offset 0= methodIdent= 1st method messageBox.putWord(channel, 2); // offset 2= input parameter messageBox.putPointer(valueP, 8); // offset 8= pointer to the output value messageBox.sendOrder(ident, Object::getIdent()); // send the message return IOCM::Status_OK; // simplified example: no error checking } int Sensor_ifc::receiveMessage(IOCM::MessageBox& messageBox) { // called by ÔIOCM::checkInvocationÕ through IOCM::Object short methodIdent; messageBox.getWord(&methodIdent, 0); // methodIdent= offset 0 switch (methodIdent) { case 1: return getValue_reply(messageBox);// return to checkInvocation // ... } } int Sensor_ifc::getValue_reply(IOCM::MessageBox& messageBox) { long *valueP; messageBox.getPointer(&valueP, 8); // output parameter ptr= offset 8 messageBox.getDword(valueP, 4); // output parameter= offset 4 return IOCM::Status_OK; // simplified example: no error checking } Listing 5: Usage of IOCM-MB by IDL compiler at object implementation side. // File: sensor_ske.cpp (generated by the // sensor impl side IDL compiler) #include Òsensor_ske.hppÓ Sensor_ske::Sensor_ske(long sensorIdent) : IOCM::Object(sensorIdent) {} int Sensor_ske::receiveMessage(IOCM::MessageBox& messageBox) { short methodIdent; switch (messageBox.getMessageIdent()) { case IOCM::Default_MessageIdent: messageBox.getWord(&methodIdent, 0); // methodIdent= offset 0 switch (methodIdent) { case 1: return getValue_order(messageBox); // 1st method // ... } // ... } } int Sensor_ske::getValue_order(IOCM::MessageBox& messageBox) { short channel; long value; messageBox.getWord(&channel, 2); // input parameter= offset 2 getValue(channel, &value); // call the ÔgetValueÕ implementation messageBox.putDword(value, 4); // offset 4= output parameter messageBox.sendReply(); // send the message back as reply message return IOCM::Status_OK; // simplified example: no error checking }