Update from PSI
r1040 | ffr | 2006-08-03 10:05:34 +1000 (Thu, 03 Aug 2006) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
074f1cb3cd
commit
dbc07ee639
242
sicshipadaba.h
Normal file
242
sicshipadaba.h
Normal file
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* This is a set of helper functions for SICS to work with the hierarchical parameter
|
||||
* database hipadaba. In SICS, the calldata associated with any callback will always
|
||||
* be the connection object.
|
||||
*
|
||||
* copyright: GPL
|
||||
*
|
||||
* Mark Koennecke, June 2006
|
||||
*/
|
||||
#ifndef SICSHIPADABA_H_
|
||||
#define SICSHIPADABA_H_
|
||||
#include <hipadaba.h>
|
||||
#include <sics.h>
|
||||
#include <dynstring.h>
|
||||
/*======================== callback error codes ===============================*/
|
||||
#define SICSCBRO -607
|
||||
#define SICSCBPERM -608
|
||||
#define SICSCBRANGE -609
|
||||
#define SICSCBBADFIXED -610
|
||||
#define SICSNOPAR -611
|
||||
/*======================== data structure for automatic parameter update =======*/
|
||||
typedef struct {
|
||||
SConnection *pCon;
|
||||
int updateList;
|
||||
int iEnd;
|
||||
}hdbUpdateTask, *pHdbUpdateTask;
|
||||
/*======================== common callbacks =====================================*/
|
||||
/**
|
||||
* make a callback which checks permissions. To be used on write
|
||||
* @param priv The privilege to check against
|
||||
* @return a suitably initialized callback structure for
|
||||
* checking permissions.
|
||||
*/
|
||||
pHdbCallback MakeCheckPermissionCallback(int priv);
|
||||
/**
|
||||
* make a callback which directly updates a
|
||||
* paramter after setting. Usefule for program parameters.
|
||||
* @return a suitably initialized callback structure setting
|
||||
* program parameters
|
||||
*/
|
||||
pHdbCallback MakeSetUpdateCallback();
|
||||
/**
|
||||
* make a callback which starts a parameter driving.
|
||||
* @param sicsObject The SICS object to drive.
|
||||
* @return a suitably initialized callback structure for
|
||||
* starting a parameter driving.
|
||||
*/
|
||||
pHdbCallback MakeSICSDriveCallback(void *sicsObject);
|
||||
/**
|
||||
* make a callback which reads a SICS drivable object
|
||||
* @param sicsObject The SICS drivable object to read.
|
||||
* @return a suitably initialized callback structure for
|
||||
* reading a drivable parameter
|
||||
*/
|
||||
pHdbCallback MakeSICSReadDriveCallback(void *sicsObject);
|
||||
/**
|
||||
* make a callback which enables automatically
|
||||
* notification of pCon on parameter updates.
|
||||
* @param pCon The connection to notify. The notification
|
||||
* is issued in the context of this connection.
|
||||
* @param id An integer id which can later on be used to remove the
|
||||
* callback.
|
||||
* @return a suitably initialized callback structure for
|
||||
* automatic notification.
|
||||
*/
|
||||
pHdbCallback MakeNotifyCallback(SConnection *pCon, int id);
|
||||
/**
|
||||
* make a callback for checking if a parameter is within a given
|
||||
* range of integers
|
||||
* @param min The minimum value of the range
|
||||
* @param max The maximum value of the range
|
||||
* @return a suitably configured callback or NULL
|
||||
* when out of memory
|
||||
*/
|
||||
pHdbCallback MakeIntRangeCallback(int min, int max);
|
||||
/**
|
||||
* make a callback for checking if a parameter is one out
|
||||
* of a series of permitted integers
|
||||
* @param data An array of permitted integers
|
||||
* @param length The length of the data array.
|
||||
* @return a suitably configured callback or NULL
|
||||
* when out of memory
|
||||
*/
|
||||
pHdbCallback MakeIntFixedCallback(long *data, int length);
|
||||
/**
|
||||
* make a callback for checking if a parameter is within a given
|
||||
* range of floats
|
||||
* @param min The minimum value of the range
|
||||
* @param max The maximum value of the range
|
||||
* @return a suitably configured callback or NULL
|
||||
* when out of memory
|
||||
*/
|
||||
pHdbCallback MakeFloatRangeCallback(double min, double max);
|
||||
/*======================== parameter creation ===================================*/
|
||||
/**
|
||||
* make a simple SICS hdb parameter. Setting it will call update immediately. Use
|
||||
* this for program parameters.
|
||||
* @param name The name of the parameter
|
||||
* @param priv The privilege required to change that parameter
|
||||
* @param v The initial value and datatype of this parameter
|
||||
* @return A new suitably configured Hdb parameter or NULL when out of memory.
|
||||
*/
|
||||
pHdb MakeSICSHdbPar(char *name, int priv, hdbValue v);
|
||||
/**
|
||||
* make a SICS hdb drivable parameter. Setting it will start the motor,
|
||||
* virtual motor or environment parameter. This will call StartDevice
|
||||
* eventually
|
||||
* @param name The name of the parameter
|
||||
* @param priv The privilege required to change that parameter
|
||||
* @param sicsObject The object corresponding to this parameter.
|
||||
* @param dataType The datatype of this variable
|
||||
* @return A new suitably configured Hdb parameter or NULL when out of memory.
|
||||
*/
|
||||
|
||||
pHdb MakeSICSHdbDriv(char *name, int priv,void *sicsObject, int datatype);
|
||||
/**
|
||||
* makes a SICS Hdb read only parameter. Setting such a parameter causes an error.
|
||||
* @param name The name of the parameter
|
||||
* @param v The initial value and datatype of this parameter
|
||||
* @return A new suitably configured Hdb parameter or NULL when out of memory.
|
||||
*/
|
||||
pHdb MakeSICSROPar(char *name, hdbValue v);
|
||||
/**
|
||||
* make a SICS scriptable parameter. I.e. when this parameter is set or read,
|
||||
* appropriate scripts are invoked.
|
||||
* @param name The name of the parameter
|
||||
* @param setScript The script to call when this parameter is being set
|
||||
* @param readScript The script to call when this parameter is being read.
|
||||
* @param v The initial value and datatype of this parameter
|
||||
* @return A new suitably configured Hdb parameter or NULL when out of memory.
|
||||
*/
|
||||
pHdb MakeSICSScriptPar(char *name, char *setScript, char *readScript, hdbValue v);
|
||||
/**
|
||||
* remove a SICS paramameter node and its children. In contrast to the
|
||||
* normal DeletHipadabaNode, this function also takes care of
|
||||
* clearing scipted nodes out of the update tasks watch list.
|
||||
* @param node The node to delete
|
||||
*/
|
||||
void RemoveSICSPar(pHdb node);
|
||||
/*============== access support functions =================================*/
|
||||
/**
|
||||
* SICSHdbGetFloat returns the float value of a parameter. Integers are
|
||||
* automatically converted.
|
||||
* @param parent The parent node where to start searching for the parameter
|
||||
* @param pCon The optional connection object to use for reporting errors.
|
||||
* @param path The path to the parameter.
|
||||
* @param value The value of the parameter
|
||||
* @return 1 on success, a negative error code else.
|
||||
*/
|
||||
int SICSHdbGetFloat(pHdb parent, SConnection *pCon,
|
||||
char *path, float *value);
|
||||
/**
|
||||
* SICSHdbSetFloat sets the value of a parameter. Integers are
|
||||
* automatically converted.
|
||||
* @param parent The parent node where to start searching for the parameter
|
||||
* @param pCon The optional connection object to use for reporting errors.
|
||||
* @param path The path to the parameter.
|
||||
* @param value The new value of the parameter
|
||||
* @return 1 on success, a negative error code else.
|
||||
*/
|
||||
int SICSHdbSetFloat(pHdb parent, SConnection *pCon,
|
||||
char *path, float value);
|
||||
/*============= common SICS Interactions ===================================*/
|
||||
/**
|
||||
* Install a SICS automatic notification callback on the node. This is
|
||||
* a default callback using the current connection with its current
|
||||
* context for notification.
|
||||
* @param node The parameter on which to install the callback
|
||||
* @param pCon The connection to which this callback is linked.
|
||||
* @param id An int associated with this notification callback. A
|
||||
* precaution for later removal.
|
||||
* @param recurse a flag 0 or 1 which determines if callbacks are
|
||||
* installed to all nodes recursively.
|
||||
* @return 1 on success, 0 when out of memory.
|
||||
*/
|
||||
int InstallSICSNotify(pHdb node, SConnection *pCon, int id, int recurse);
|
||||
/**
|
||||
* handles the common task of checking for, and processing a SICS parameter.
|
||||
* @param root The node at which to search for parameters
|
||||
* @param pCon The connection in whichs context the parameter is processed.
|
||||
* @param printPrefix A prefix to prepend before printing this parameter.
|
||||
* Will be ignored if NULL.
|
||||
* @param argc number of arguments to process.
|
||||
* @param argv The arguments to process. argv[0] should be the parameter
|
||||
* name.
|
||||
* @return -1 when argv[0] is no parameter, 0 on failure, 1 on success.
|
||||
*/
|
||||
int ProcessSICSHdbPar(pHdb root, SConnection *pCon, char *printPrefix,
|
||||
int argc, char *argv[]);
|
||||
/**
|
||||
* A SICS task which scans a Hipadaba and reads and updates all parameters,
|
||||
* one per invocation. TODO: how to distinguish between automatic pars which
|
||||
* do not need this and pars which need this? Idea 1: make a root point at an
|
||||
* artificial tree of parameters which need to be checked like this.
|
||||
* @param pData The root to start scanning at.
|
||||
* @return 0 when ends, 1 else
|
||||
*/
|
||||
int SICSHipadabaTask(void *pData);
|
||||
void SICSHipadabaSignal(void *pData, int iSignal, void *pSigData);
|
||||
/*================== value helpers ========================================*/
|
||||
/**
|
||||
* format a Hdb Value into a string using SICS defaults.
|
||||
* @param v The Hdb value to format
|
||||
* @return a dynamic string holding the formatted data. NULL when
|
||||
* out of memory
|
||||
*/
|
||||
pDynString formatValue(hdbValue v);
|
||||
/**
|
||||
* read values for a Hdb value from a string.
|
||||
* @param v The hdbValue to read data into. Datatype and arraylength must
|
||||
* already have been initialised before this call in order to allow for
|
||||
* checks. Arrays should also have been allocated in the right size.
|
||||
* @param data The string to parse and convert.
|
||||
* @param error A string to copy failure reasons too
|
||||
* @param errlen The length of the error string
|
||||
* @return 0 on failure, 1 on success
|
||||
*/
|
||||
int readHdbValue(hdbValue *v, char *data, char *error, int errlen);
|
||||
/*================= SICS Interpreter Interface ===========================*/
|
||||
/**
|
||||
* InstallHipadaba installs the Hipadaba commands into the SICS interpreter.
|
||||
* The actual command implementation is in sicshipadaba.c.
|
||||
* @param pCon The connection object
|
||||
* @param pSics The SICS interpreter
|
||||
* @param pData The object data structure
|
||||
* @param argc The number of arguments
|
||||
* @param argv[] The text arguments
|
||||
* @return 0 on filaure, 1 on success
|
||||
*/
|
||||
int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]);
|
||||
/**
|
||||
* get the root of the SICS Hipadaba tree
|
||||
* @return The root node of the hipdaba
|
||||
*/
|
||||
pHdb GetHipadabaRoot();
|
||||
/**
|
||||
* kill the SICS hierarchical database
|
||||
* Only to be called when shutting down the SICServer
|
||||
*/
|
||||
void killSICSHipadaba(void);
|
||||
#endif /*SICSHIPADABA_H_*/
|
||||
Reference in New Issue
Block a user