Devices > 
Device operation
 
 
 

Depending on the requested operation, FBDevice::DeviceOperation calls the corresponding device function and propagates the call to the parent class and returns the result.

Once your device plug-in is loaded, MotionBuilder calls the function FBDevice::DeviceOperation() with a flag of type kDeviceOperations to request behaviors as follows:

MotionBuilder takes special care when starting, resetting, or stopping a device when several threads are accessing a device at once.

To control initialization and shutdown sequences from the layout, it must communicate with the device with DeviceOperation. Any other method of operating the device may cause MotionBuilder to crash due to the complex nature of the thread interaction.

DeviceOperation returns true if it is online after the command is completed and false if it is offline. DeviceOperation maps the requested operation of the device (kOp* commands) to the actual functions that are associated with the operation.

The kOpDone command is called when a device is destroyed. You should insert all final once-only shutdown code here.

These functions should generally be mapped to device functions as demonstrated in the following code. Note that Init() and so on are defined as member functions of the device class and must return a boolean value.

bool MyDevice::DeviceOperation(
kDeviceOperations pOperation )
{
 switch(pOperation)
 {
 case kOpInit:   return Init();
 case kOpStart:  return Start();
 case kOpReset:  return Reset();
 case kOpStop:  return Stop();
 case kOpDone:  return Done();
 }
 return FBDevice::DeviceOperation
(pOperation);
}