lib/dgr.c
/** Set a variable if we are a DGR master (so that we can send it to
 * slaves) and get a variable if we are a DGR slave. The variable is
 * stored in 'buffer' and is 'bufferSize' bytes long.
 *
 * If we are a slave, get the variable from the master and store it in
 * 'buffer' which is 'bufferSize' bytes large. If anything goes wrong
 * (your buffer is the wrong size, the record name that you requested
 * wasn't sent by the server, etc) an error message will be printed
 * and your buffer variable will be unchanged.
 *
 * Once you add a variable with a name, you cannot (currently) remove
 * it from DGR. However, you can overwrite an existing variable with a
 * new value. If you set a variable once and never set it again, DGR
 * will keep sending that variable.
 *
 * @param name A string representing the name of the variable. Both the DGR master and DGR slaves must use the same string for the same variable.
 * @param buffer A pointer to the data (an int, float, array, struct, etc.)
 * @param bufferSize The size of the data in the buffer in bytes.
 */
Set a variable if we are a DGR master (so that we can send it to
slaves) and get a variable if we are a DGR slave. The variable is
stored in 'buffer' and is 'bufferSize' bytes long.

If we are a slave, get the variable from the master and store it in
'buffer' which is 'bufferSize' bytes large. If anything goes wrong
(your buffer is the wrong size, the record name that you requested
wasn't sent by the server, etc) an error message will be printed
and your buffer variable will be unchanged.

Once you add a variable with a name, you cannot (currently) remove
it from DGR. However, you can overwrite an existing variable with a
new value. If you set a variable once and never set it again, DGR
will keep sending that variable.

@param name A string representing the name of the variable. Both the DGR master and DGR slaves must use the same string for the same variable.
@param buffer A pointer to the data (an int, float, array, struct, etc.)
@param bufferSize The size of the data in the buffer in bytes.
Set a variable if we are a DGR master ( so that we can send it to slaves ) and get a variable if we are a DGR slave . The variable is stored in ' buffer ' and is ' bufferSize ' bytes long . If we are a slave get the variable from the master and store it in ' buffer ' which is ' bufferSize ' bytes large . If anything goes wrong ( your buffer is the wrong size the record name that you requested wasn ' t sent by the server etc ) an error message will be printed and your buffer variable will be unchanged . Once you add a variable with a name you cannot ( currently ) remove it from DGR . However you can overwrite an existing variable with a new value . If you set a variable once and never set it again DGR will keep sending that variable . @param name A string representing the name of the variable . Both the DGR master and DGR slaves must use the same string for the same variable . @param buffer A pointer to the data ( an int float array struct etc . ) @param bufferSize The size of the data in the buffer in bytes .
void dgr_setget(const char *name, void* buffer, int bufferSize)
{
	if(dgr_disabled)
		return;
	if(dgr_mode)
		dgr_set(name, buffer, bufferSize);
	else
	{
		int ret = dgr_get(name, buffer, bufferSize);
		if(ret == -1)
			msg(MSG_ERROR, "DGR Slave: Tried to get '%s' from DGR, but DGR didn't have it\n", name);
		else if(ret == -2)
			msg(MSG_ERROR, "DGR Slave: Tried to get '%s' from DGR, but you didn't provide a large enough buffer.\n", name);
		else if(ret != bufferSize)
			msg(MSG_WARNING, "DGR Slave: Successfully retrieved '%s' from DGR but you provided a buffer that didn't match the size of the data you are retrieving. Your buffer is %d bytes but the '%s' record is %d bytes.\n", name, bufferSize, name, ret);
	}
}
void dgr_setget ( const char * name , void * buffer , int bufferSize ) { if ( dgr_disabled ) return ; if ( dgr_mode ) dgr_set ( name , buffer , bufferSize ) ; else { int ret = dgr_get ( name , buffer , bufferSize ) ; if ( ret == -1 ) msg ( MSG_ERROR , " \n " , name ) ; else if ( ret == -2 ) msg ( MSG_ERROR , " \n " , name ) ; else if ( ret != bufferSize ) msg ( MSG_WARNING , " \n " , name , bufferSize , name , ret ) ; } }
Set a variable if we are a DGR master (so that we can send it to
 slaves) and get a variable if we are a DGR slave.
Set a variable if we are a DGR master ( so that we can send it to slaves ) and get a variable if we are a DGR slave .