Examples/ArenaC/C_Callback_OnNodeChange/C_Callback_OnNodeChange.c
AC_ERROR ConfigureAndCauseCallback(acSystem hSystem, acDevice hDevice)
{
	AC_ERROR err = AC_ERR_SUCCESS;

	// get node map
	acNodeMap hNodeMap = NULL;

	err = acDeviceGetNodeMap(hDevice, &hNodeMap);
	if (err != AC_ERR_SUCCESS)
		return err;

	// Register PayloadSize for callbacks
	//    Callbacks are registered with a node and a function. This example
	//    demonstrates callbacks being invoked when the node is invalidated. This
	//    could be when the node value changes, either manually or by the device,
	//    or the node is invalidated manually.
	printf("%sRegister callback on PayloadSize\n", TAB1);

	// get payload size node
	acNode hPayloadSizeNode = NULL;

	err = acNodeMapGetNode(hNodeMap, "PayloadSize", &hPayloadSizeNode);
	if (err != AC_ERR_SUCCESS)
		return err;

	// get device serial number to retrieve during callback. This could be used
	// to identify devices among multiple cameras.
	size_t index = 0;
	char pSerialNumberBuf[MAX_BUF];
	size_t bufLen = MAX_BUF;

	err = acSystemGetDeviceSerial(hSystem, index, pSerialNumberBuf, &bufLen);
	if (err != AC_ERR_SUCCESS)
		return err;

	// register callback
	acCallback hCallback = NULL;

	err = acCallbackRegister(&hCallback, hPayloadSizeNode, PrintNodeValue, &pSerialNumberBuf);
	if (err != AC_ERR_SUCCESS)
		return err;

	// Modify Height to invalidate and invoke callback on PayloadSize
	//    The value of PayloadSize depends on a number of other nodes, including
	//    Height, Width, etc. Therefore, changing the value of Height changes the
	//    value of and invalidates PayloadSize, which then invokes the callback.
	acNode hHeightNode = NULL;

	err = acNodeMapGetNode(hNodeMap, "Height", &hHeightNode);
	if (err != AC_ERR_SUCCESS)
		return err;

	// get initial height node value that will be changed and returned at the end
	// of the example
	int64_t heightValueInitial = 0;

	err = acIntegerGetValue(hHeightNode, &heightValueInitial);
	if (err != AC_ERR_SUCCESS)
		return err;

	// set new height values
	printf("%sChange height once\n", TAB2);

	err = acIntegerSetValue(hHeightNode, HEIGHT_ONE);
	if (err != AC_ERR_SUCCESS)
		return err;

	printf("%sChange height twice\n", TAB2);

	err = acIntegerSetValue(hHeightNode, HEIGHT_TWO);
	if (err != AC_ERR_SUCCESS)
		return err;

	// Manually invalidate PayloadSize for callback
	//    Apart from changing the value of a node, nodes can be invalidated
	//    manually by calling InvalidateNode. This also invokes the callback.
	printf("%sInvalidate PayloadSize\n", TAB2);

	err = acNodeInvalidateNode(hPayloadSizeNode);
	if (err != AC_ERR_SUCCESS)
		return err;

	// Deregister callback
	//    Failing to deregister a callback results in a memory leak. Once a
	//    callback has been registered, it will no longer be invoked when a node
	//    is invalidated.
	printf("%sDeregister callback\n", TAB2);

	err = acCallbackDeregister(hCallback);
	if (err != AC_ERR_SUCCESS)
		return err;

	// return height node to initial value
	err = acIntegerSetValue(hHeightNode, heightValueInitial);
	if (err != AC_ERR_SUCCESS)
		return err;

	return err;
}
// demonstrates callbacks invoked on node changes
// (1) registers callback on node PayloadSize
// (2) changes Height twice to invalidate PayloadSize, invoking callback
// (3) invalidates PayloadSize manually
// (4) deregisters callback
demonstrates callbacks invoked on node changes
(1) registers callback on node PayloadSize
(2) changes Height twice to invalidate PayloadSize, invoking callback
(3) invalidates PayloadSize manually
(4) deregisters callback
demonstrates callbacks invoked on node changes ( 1 ) registers callback on node PayloadSize ( 2 ) changes Height twice to invalidate PayloadSize invoking callback ( 3 ) invalidates PayloadSize manually ( 4 ) deregisters callback
AC_ERROR ConfigureAndCauseCallback(acSystem hSystem, acDevice hDevice)
{
	AC_ERROR err = AC_ERR_SUCCESS;
	acNodeMap hNodeMap = NULL;
	err = acDeviceGetNodeMap(hDevice, &hNodeMap);
	if (err != AC_ERR_SUCCESS)
		return err;
	printf("%sRegister callback on PayloadSize\n", TAB1);
	acNode hPayloadSizeNode = NULL;
	err = acNodeMapGetNode(hNodeMap, "PayloadSize", &hPayloadSizeNode);
	if (err != AC_ERR_SUCCESS)
		return err;
	size_t index = 0;
	char pSerialNumberBuf[MAX_BUF];
	size_t bufLen = MAX_BUF;
	err = acSystemGetDeviceSerial(hSystem, index, pSerialNumberBuf, &bufLen);
	if (err != AC_ERR_SUCCESS)
		return err;
	acCallback hCallback = NULL;
	err = acCallbackRegister(&hCallback, hPayloadSizeNode, PrintNodeValue, &pSerialNumberBuf);
	if (err != AC_ERR_SUCCESS)
		return err;
	acNode hHeightNode = NULL;
	err = acNodeMapGetNode(hNodeMap, "Height", &hHeightNode);
	if (err != AC_ERR_SUCCESS)
		return err;
	int64_t heightValueInitial = 0;
	err = acIntegerGetValue(hHeightNode, &heightValueInitial);
	if (err != AC_ERR_SUCCESS)
		return err;
	printf("%sChange height once\n", TAB2);
	err = acIntegerSetValue(hHeightNode, HEIGHT_ONE);
	if (err != AC_ERR_SUCCESS)
		return err;
	printf("%sChange height twice\n", TAB2);
	err = acIntegerSetValue(hHeightNode, HEIGHT_TWO);
	if (err != AC_ERR_SUCCESS)
		return err;
	printf("%sInvalidate PayloadSize\n", TAB2);
	err = acNodeInvalidateNode(hPayloadSizeNode);
	if (err != AC_ERR_SUCCESS)
		return err;
	printf("%sDeregister callback\n", TAB2);
	err = acCallbackDeregister(hCallback);
	if (err != AC_ERR_SUCCESS)
		return err;
	err = acIntegerSetValue(hHeightNode, heightValueInitial);
	if (err != AC_ERR_SUCCESS)
		return err;
	return err;
}
AC_ERROR ConfigureAndCauseCallback ( acSystem hSystem , acDevice hDevice ) { AC_ERROR err = AC_ERR_SUCCESS ; acNodeMap hNodeMap = NULL ; err = acDeviceGetNodeMap ( hDevice , & hNodeMap ) ; if ( err != AC_ERR_SUCCESS ) return err ; printf ( " \n " , TAB1 ) ; acNode hPayloadSizeNode = NULL ; err = acNodeMapGetNode ( hNodeMap , " " , & hPayloadSizeNode ) ; if ( err != AC_ERR_SUCCESS ) return err ; size_t index = 0 ; char pSerialNumberBuf [ MAX_BUF ] ; size_t bufLen = MAX_BUF ; err = acSystemGetDeviceSerial ( hSystem , index , pSerialNumberBuf , & bufLen ) ; if ( err != AC_ERR_SUCCESS ) return err ; acCallback hCallback = NULL ; err = acCallbackRegister ( & hCallback , hPayloadSizeNode , PrintNodeValue , & pSerialNumberBuf ) ; if ( err != AC_ERR_SUCCESS ) return err ; acNode hHeightNode = NULL ; err = acNodeMapGetNode ( hNodeMap , " " , & hHeightNode ) ; if ( err != AC_ERR_SUCCESS ) return err ; int64_t heightValueInitial = 0 ; err = acIntegerGetValue ( hHeightNode , & heightValueInitial ) ; if ( err != AC_ERR_SUCCESS ) return err ; printf ( " \n " , TAB2 ) ; err = acIntegerSetValue ( hHeightNode , HEIGHT_ONE ) ; if ( err != AC_ERR_SUCCESS ) return err ; printf ( " \n " , TAB2 ) ; err = acIntegerSetValue ( hHeightNode , HEIGHT_TWO ) ; if ( err != AC_ERR_SUCCESS ) return err ; printf ( " \n " , TAB2 ) ; err = acNodeInvalidateNode ( hPayloadSizeNode ) ; if ( err != AC_ERR_SUCCESS ) return err ; printf ( " \n " , TAB2 ) ; err = acCallbackDeregister ( hCallback ) ; if ( err != AC_ERR_SUCCESS ) return err ; err = acIntegerSetValue ( hHeightNode , heightValueInitial ) ; if ( err != AC_ERR_SUCCESS ) return err ; return err ; }
demonstrates callbacks invoked on node changes
(1) registers callback on node PayloadSize
(2) changes Height twice to invalidate PayloadSize, invoking callback
(3) invalidates PayloadSize manually
(4) deregisters callback
demonstrates callbacks invoked on node changes ( 1 ) registers callback on node PayloadSize ( 2 ) changes Height twice to invalidate PayloadSize invoking callback ( 3 ) invalidates PayloadSize manually ( 4 ) deregisters callback
// get node map // Register PayloadSize for callbacks //    Callbacks are registered with a node and a function. This example //    demonstrates callbacks being invoked when the node is invalidated. This //    could be when the node value changes, either manually or by the device, //    or the node is invalidated manually. // get payload size node // get device serial number to retrieve during callback. This could be used // to identify devices among multiple cameras. // register callback // Modify Height to invalidate and invoke callback on PayloadSize //    The value of PayloadSize depends on a number of other nodes, including //    Height, Width, etc. Therefore, changing the value of Height changes the //    value of and invalidates PayloadSize, which then invokes the callback. // get initial height node value that will be changed and returned at the end // of the example // set new height values // Manually invalidate PayloadSize for callback //    Apart from changing the value of a node, nodes can be invalidated //    manually by calling InvalidateNode. This also invokes the callback. // Deregister callback //    Failing to deregister a callback results in a memory leak. Once a //    callback has been registered, it will no longer be invoked when a node //    is invalidated. // return height node to initial value