This short example is meant to be self-explanatory.
#include <apps/Common/exampleHelper_C.h>
#include <mvDeviceManager/Include/mvDeviceManager.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
# include <conio.h>
#endif
typedef struct TMatchbox
{
int matches_;
} Matchbox;
typedef struct TWallet
{
double euros_;
} Wallet;
typedef struct THandbag
{
Matchbox matchbox_;
Wallet wallet_;
} Handbag;
void DMR_CALL callbackFunction( HOBJ hObj, void* pUserData )
{
static unsigned int hitCount = 0;
Wallet* pWallet = 0;
Matchbox* pMatchbox = 0;
printf( "Hit-count: %d, hObj causing the callback: 0x%08x\n", ++hitCount, hObj );
pWallet = &( ( Handbag* )pUserData )->wallet_;
pMatchbox = &( ( Handbag* )pUserData )->matchbox_;
printf( "There are %d matches in my box and %.2f Euros in my wallet.\n", pMatchbox->matches_, pWallet->euros_ );
if( pMatchbox->matches_ > 0 )
{
--pMatchbox->matches_;
printf( "I lit a match.\n" );
}
else if( pWallet->euros_ > 0.5 )
{
pWallet->euros_ -= 0.5;
printf( "I bought a new box of matches.\n" );
pMatchbox->matches_ = 5;
}
else
{
printf( "I got no more matches and don't have enough money to buy new ones...\n" );
}
}
void checkCallbackCreation( HDRV hDrv )
{
Handbag handbag;
HOBJ hPropImageRequestTimeout_ms = getSettingProp( hDrv, "Base", "ImageRequestTimeout_ms" );
int i = 0;
{
printf( "Failed to locate 'ImageRequestTimeout_ms' property.\n" );
return;
}
handbag.matchbox_.matches_ = 5;
handbag.wallet_.euros_ = 2.14;
{
return;
}
{
for( i = 0; i < 30; i++ )
{
printf( "Provoking callback %d.\n", i + 1 );
setPropI( hPropImageRequestTimeout_ms, i, 12345 );
}
{
}
}
else
{
}
{
}
hCallback = 0;
if( handbag.wallet_.euros_ < 2.14 )
{
printf( "The callback spent some of my money. I got %.2f left.\n", handbag.wallet_.euros_ );
}
}
int main( int argc, char* argv[] )
{
unsigned int deviceCount = 0;
unsigned int i = 0;
char* pStringBuffer = NULL;
unsigned int deviceNumber = 0;
( void )argc;
( void )argv;
{
printf( "DMR_Init failed (code: %d)\n", result );
END_APPLICATION;
}
{
END_APPLICATION;
}
if( deviceCount == 0 )
{
printf( "No %s compliant device detected.\n", PRODUCT_NAME );
END_APPLICATION;
}
printf( "%d %s compliant devices detected.\n", deviceCount, PRODUCT_NAME );
for( i = 0; i < deviceCount; i++ )
{
{
END_APPLICATION;
}
if( ( hPropSerial = getDeviceProp( hDev,
"Serial" ) ) ==
INVALID_ID )
{
printf( "Failed to obtain device serial property for device %d.\n", i );
continue;
}
getStringValue( hPropSerial, &pStringBuffer, 0 );
printf( "[%d]: %s.\n", i, pStringBuffer );
free( pStringBuffer );
}
printf( "Please enter the number in front of the listed device followed by [ENTER] to open it: " );
deviceNumber = getIntValFromSTDIn();
{
printf(
"DMR_GetDevice(%d) failed (code: %d(%s))\n", deviceNumber, result,
DMR_ErrorCodeToString( result ) );
END_APPLICATION;
}
{
printf( "DMR_OpenDevice failed (code: %d)\n", result );
END_APPLICATION;
}
checkCallbackCreation( hDrv );
END_APPLICATION;
}
TDMR_ERROR
Errors reported by the device manager.
Definition mvDriverBaseEnums.h:2601
@ DMR_NO_ERROR
The function call was executed successfully.
Definition mvDriverBaseEnums.h:2603
@ dmdsmSerial
Searches for a device with a certain serial number.
Definition mvDeviceManager.h:528
MVDMR_API TDMR_ERROR DMR_CALL DMR_GetDeviceCount(unsigned int *pDevCnt)
Receives the number of devices recognized by this interface.
Definition mvDeviceManager.cpp:1466
MVDMR_API TDMR_ERROR DMR_CALL DMR_Close(void)
Frees internal data structures and decreases the usage counter for this library.
Definition mvDeviceManager.cpp:1265
MVDMR_API TDMR_ERROR DMR_CALL DMR_CloseDevice(HDRV hDrv, HDEV hDev)
Closes a device.
Definition mvDeviceManager.cpp:1585
MVDMR_API TDMR_ERROR DMR_CALL DMR_Init(HDMR *pHDmr)
Initialises the library.
Definition mvDeviceManager.cpp:1137
MVDMR_API const char *DMR_CALL DMR_ErrorCodeToString(int errorCode)
Returns a string representation of a given error code.
Definition mvDeviceManager.cpp:5383
MVDMR_API TDMR_ERROR DMR_CALL DMR_OpenDevice(HDEV hDev, HDRV *pHDrv)
Initialises a device.
Definition mvDeviceManager.cpp:1516
MVDMR_API TDMR_ERROR DMR_CALL DMR_GetDevice(HDEV *pHDev, TDMR_DeviceSearchMode searchMode, const char *pSearchString, unsigned int devNr, char wildcard)
Tries to locate a certain device in the system which matches the input criteria.
Definition mvDeviceManager.cpp:1379
void * CallbackHandle
A type to create a unique identifier for a callback.
Definition mvPropHandlingDatatypes.h:894
const int INVALID_ID
A constant to check for an invalid ID returned from the property handling module.
Definition mvPropHandlingDatatypes.h:62
TPROPHANDLING_ERROR
Error codes of the module handling everything related to properties.
Definition mvPropHandlingDatatypes.h:382
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_CreateCallback(TCallbackType type, CBOBJChanged pMeth, void *pUserData, CallbackHandle *phCallback)
Creates a new callback object that can be bound to one or multiple features.
Definition ObjectHandling.cpp:541
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_AttachCallback(HOBJ hObj, CallbackHandle hCallback)
Attaches a previously created callback to a feature.
Definition ObjectHandling.cpp:612
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_DeleteCallback(CallbackHandle hCallback)
Deletes a callback object.
Definition ObjectHandling.cpp:586
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_DetachCallback(HOBJ hObj, CallbackHandle hCallback)
Detaches a previously created callback to a feature.
Definition ObjectHandling.cpp:640
@ PROPHANDLING_NO_ERROR
The operation has been executed successfully.
Definition mvPropHandlingDatatypes.h:384
@ ctOnChanged
Execute callback whenever this component has been modified.
Definition mvPropHandlingDatatypes.h:133