- Fixed new AMOR settings module - Initial implementation of the new SICS hierarchical parameter database SKIPPED: psi/amorset.c psi/libpsi.a psi/sps.c
176 lines
7.2 KiB
C
176 lines
7.2 KiB
C
/**
|
|
* 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>
|
|
/*======================== 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 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);
|
|
/*======================== 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);
|
|
/*============= 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();
|
|
|
|
#endif /*SICSHIPADABA_H_*/
|