devices/device_syncreference/ordevice_syncreference_device.cxx

devices/device_syncreference/ordevice_syncreference_device.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declaration
#include "ordevice_syncreference_device.h"
//--- Registration defines
#define ORDEVICETEMPLATE__CLASS ORDEVICETEMPLATE__CLASSNAME
#define ORDEVICETEMPLATE__NAME ORDEVICETEMPLATE__CLASSSTR
#define ORDEVICETEMPLATE__LABEL "OR - Device SyncReference"
#define ORDEVICETEMPLATE__DESC "OR - Device SyncReference Description"
#define ORDEVICETEMPLATE__PREFIX "SyncReference"
//--- FiLMBOX implementation and registration
FBDeviceImplementation ( ORDEVICETEMPLATE__CLASS );
FBRegisterDevice ( ORDEVICETEMPLATE__NAME,
ORDEVICETEMPLATE__CLASS,
ORDEVICETEMPLATE__LABEL,
ORDEVICETEMPLATE__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
static void SamplingRateSet( HIObject pObject, double pValue )
{
ORDevice_SyncReference* lDevice = FBCast<ORDevice_SyncReference>(pObject);
lDevice->SamplingRate.SetPropertyValue(pValue);
FBTime lPeriod; lPeriod.SetSecondDouble(1.0/pValue);
lDevice->SamplingPeriod = lPeriod;
}
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORDevice_SyncReference::FBCreate()
{
// Set sampling rate to 60 Hz
FBTime lPeriod;
lPeriod.SetSecondDouble(1.0/60.0);
SamplingPeriod = lPeriod;
FBPropertyPublish( this, SamplingRate, "SamplingRate", NULL,SamplingRateSet );
SamplingRate.SetPropertyValue(60);
mSyncReference = new FBSyncReference("MyDeviceSync");
mSyncId = -1;
return true;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORDevice_SyncReference::FBDestroy()
{
delete mSyncReference;
}
/************************************************
* Device operation.
************************************************/
bool ORDevice_SyncReference::DeviceOperation( kDeviceOperations pOperation )
{
switch (pOperation)
{
case kOpInit: return Init();
case kOpStart: return Start();
case kOpStop: return Stop();
case kOpReset: return Reset();
case kOpDone: return Done();
}
return FBDevice::DeviceOperation( pOperation );
}
/************************************************
* Initialization of device.
************************************************/
bool ORDevice_SyncReference::Init()
{
FBProgress lProgress;
lProgress.Caption = "Device SyncReference";
lProgress.Text = "Initializing device...";
return true;
}
/************************************************
* Device is put online.
************************************************/
bool ORDevice_SyncReference::Start()
{
FBProgress lProgress;
lProgress.Caption = "Starting up device";
mSyncId = mSyncReference->GetSyncCount();
mSyncReference->Active = true;
Status = "Ok";
return true;
}
/************************************************
* Device is stopped (offline).
************************************************/
bool ORDevice_SyncReference::Stop()
{
FBProgress lProgress;
lProgress.Caption = "Shutting down device";
mSyncReference->Active = false;
Status = "?";
return false;
}
/************************************************
* Removal of device.
************************************************/
bool ORDevice_SyncReference::Done()
{
return false;
}
/************************************************
* Reset of device.
************************************************/
bool ORDevice_SyncReference::Reset()
{
Stop();
return Start();
}
/************************************************
* Real-Time Engine Evaluation.
************************************************/
bool ORDevice_SyncReference::AnimationNodeNotify(FBAnimationNode* pAnimationNode ,FBEvaluateInfo* pEvaluateInfo)
{
return true;
}
/************************************************
* Device Evaluation Notify.
************************************************/
bool ORDevice_SyncReference::DeviceEvaluationNotify( kTransportMode pMode, FBEvaluateInfo* pEvaluateInfo )
{
AckOneSampleReceived();
mSyncReference->Sync(++mSyncId);
return true;
}
/************************************************
* Real-Time Synchronous Device IO.
************************************************/
void ORDevice_SyncReference::DeviceIONotify( kDeviceIOs pAction,FBDeviceNotifyInfo &pDeviceNotifyInfo)
{
switch (pAction)
{
// Output devices
case kIOPlayModeWrite:
case kIOStopModeWrite:
{
}break;
// Input devices
case kIOStopModeRead:
case kIOPlayModeRead:
{
}break;
}
}
/************************************************
* Record a frame of the device (recording).
************************************************/
void ORDevice_SyncReference::DeviceRecordFrame( FBDeviceNotifyInfo &pDeviceNotifyInfo )
{
}
/************************************************
* Store data in FBX.
************************************************/
bool ORDevice_SyncReference::FbxStore(FBFbxObject* pFbxObject,kFbxObjectStore pStoreWhat)
{
return true;
}
/************************************************
* Retrieve data from FBX.
************************************************/
bool ORDevice_SyncReference::FbxRetrieve(FBFbxObject* pFbxObject,kFbxObjectStore pStoreWhat)
{
return true;
}