smax-clib v0.9
A C/C++ client library for SMA-X
|
A set of functions for simplified access to SMA-X for specific variable types. More...
Functions | |
XField * | smaxCreate1DField (const char *name, XType type, int size, const void *value) |
XField * | smaxCreateBooleanField (const char *name, boolean value) |
XField * | smaxCreateDoubleField (const char *name, double value) |
XField * | smaxCreateIntField (const char *name, int value) |
XField * | smaxCreateLongField (const char *name, long long value) |
XField * | smaxCreateScalarField (const char *name, XType type, const void *value) |
XField * | smaxCreateStringField (const char *name, const char *value) |
int | smaxGetArrayField (const XStructure *s, const char *name, void *dst, XType type, int count) |
boolean | smaxGetBooleanField (const XStructure *s, const char *name, boolean defaultValue) |
double | smaxGetDoubleField (const XStructure *s, const char *name, double defaultValue) |
long long | smaxGetLongField (const XStructure *s, const char *name, long long defaultValue) |
char * | smaxGetRawField (const XStructure *s, const char *name, char *defaultValue) |
double | smaxPullDouble (const char *table, const char *key) |
double | smaxPullDoubleDefault (const char *table, const char *key, double defaultValue) |
double * | smaxPullDoubles (const char *table, const char *key, XMeta *meta, int *n) |
int | smaxPullInt (const char *table, const char *key, int defaultValue) |
int * | smaxPullInts (const char *table, const char *key, XMeta *meta, int *n) |
long long | smaxPullLong (const char *table, const char *key, long long defaultValue) |
long long * | smaxPullLongs (const char *table, const char *key, XMeta *meta, int *n) |
char * | smaxPullRaw (const char *table, const char *key, XMeta *meta, int *status) |
char * | smaxPullString (const char *table, const char *key) |
char ** | smaxPullStrings (const char *table, const char *key, XMeta *meta, int *n) |
XStructure * | smaxPullStruct (const char *id, XMeta *meta, int *status) |
int | smaxShareBoolean (const char *table, const char *key, boolean value) |
int | smaxShareBooleans (const char *table, const char *key, const boolean *values, int n) |
int | smaxShareBytes (const char *table, const char *key, const char *values, int n) |
int | smaxShareDouble (const char *table, const char *key, double value) |
int | smaxShareDoubles (const char *table, const char *key, const double *values, int n) |
int | smaxShareFloats (const char *table, const char *key, const float *values, int n) |
int | smaxShareHex (const char *table, const char *key, long long value) |
int | smaxShareInt (const char *table, const char *key, long long value) |
int | smaxShareInts (const char *table, const char *key, const int *values, int n) |
int | smaxShareLongs (const char *table, const char *key, const long long *values, int n) |
int | smaxShareShorts (const char *table, const char *key, const short *values, int n) |
int | smaxShareString (const char *table, const char *key, const char *sValue) |
int | smaxShareStrings (const char *table, const char *key, const char **sValues, int n) |
int | smaxWaitOnSubscribed (const char *table, const char *key, int timeout) |
int | smaxWaitOnSubscribedGroup (const char *matchTable, char **changedKey, int timeout) |
int | smaxWaitOnSubscribedVar (const char *matchKey, char **changedTable, int timeout) |
A set of functions for simplified access to SMA-X for specific variable types.
Creates a field for 1-D array of a given name and type using specified native values. It is like xCreate1DField()
except that the field is created in serialized form.
name | Field name |
type | Storage type, e.g. X_INT. |
size | Array size. |
value | Pointer to the native array in memory. |
References smaxCreateField(), and x_trace_null().
Creates a field holding a single boolean value. It is like xCreateBooleanField()
except that the field is created in serialized form.
name | Field name |
value | Associated value |
References smaxCreateScalarField(), X_BOOLEAN, and x_trace_null().
XField * smaxCreateDoubleField | ( | const char * | name, |
double | value | ||
) |
Creates a field holding a single double-precision value. It is like xCreateDoubleField()
except that the field is created in serialized form.
name | Field name |
value | Associated value |
References smaxCreateScalarField(), X_DOUBLE, and x_trace_null().
XField * smaxCreateIntField | ( | const char * | name, |
int | value | ||
) |
Creates a field holding a single integer value. It is like xCreateIntField()
except that the field is created in serialized form.
name | Field name |
value | Associated value |
References smaxCreateScalarField(), X_INT, and x_trace_null().
XField * smaxCreateLongField | ( | const char * | name, |
long long | value | ||
) |
Creates a field holding a single wide (64-bit) integer value. It is like xCreateLongField()
except that the field is created in serialized form.
name | Field name |
value | Associated value |
References smaxCreateScalarField(), X_LONG, and x_trace_null().
Creates a scalar field of a given name and type using the specified native value. It is like xCreateScalarField()
except that the field is created in serialized form.
name | Field name |
type | Storage type, e.g. X_INT. |
value | Pointer to the native data location in memory. |
References smaxCreate1DField(), and x_trace_null().
XField * smaxCreateStringField | ( | const char * | name, |
const char * | value | ||
) |
Creates a field holding a single string value. It is like xCreateStringField()
except that the field is created in serialized form.
name | Field name |
value | Associated value |
References smaxCreateScalarField(), X_STRING, and x_trace_null().
int smaxGetArrayField | ( | const XStructure * | s, |
const char * | name, | ||
void * | dst, | ||
XType | type, | ||
int | count | ||
) |
Gets the data of an SMA-X structure field as an array of values of the specified type and element count. The field's data will be truncated or padded with zeroes to provide the requested element count always.
s | Pointer to SMA-X structure | |
name | Field name | |
[out] | dst | Array to return values in. |
type | Type of data. | |
count | Number of elements in return array. The field data will be truncated or padded as necessary. |
References smaxStringToValues(), XField::value, x_error(), X_NAME_INVALID, X_NULL, X_SIZE_INVALID, X_STRUCT_INVALID, X_SUCCESS, and xGetField().
boolean smaxGetBooleanField | ( | const XStructure * | s, |
const char * | name, | ||
boolean | defaultValue | ||
) |
Returns the first value in a structure's field as an integer, or the specified default value if there is no such field in the structure, or the content cannot be parse into an integer.
s | Pointer to the XStructure. |
name | Field name |
defaultValue | Value to return if no corresponding integer field value. |
References XField::value, xGetField(), and xParseBoolean().
double smaxGetDoubleField | ( | const XStructure * | s, |
const char * | name, | ||
double | defaultValue | ||
) |
Returns the first value in a structure's field as a double precision float, or the specified default value if there is no such field in the structure, or the content cannot be parse into an double.
s | Pointer to the XStructure. |
name | Field name |
defaultValue | Value to return if no corresponding integer field value. |
References XField::value, and xGetField().
long long smaxGetLongField | ( | const XStructure * | s, |
const char * | name, | ||
long long | defaultValue | ||
) |
Returns the first value in a structure's field as an integer, or the specified default value if there is no such field in the structure, or the content cannot be parse into an integer.
s | Pointer to the XStructure. |
name | Field name |
defaultValue | Value to return if no corresponding integer field value. |
References XField::value, and xGetField().
char * smaxGetRawField | ( | const XStructure * | s, |
const char * | name, | ||
char * | defaultValue | ||
) |
Returns the string value in a structure's field, or the specified default value if there is no such field in the structure.
s | Pointer to the XStructure. |
name | Field name |
defaultValue | Value to return if no corresponding integer field value. |
References XField::value, and xGetField().
double smaxPullDouble | ( | const char * | table, |
const char * | key | ||
) |
Returns a single floating-point value for a given SMA-X variable, or a NAN if the value could not be retrieved.
table | Hash table name. |
key | Variable name under which the data is stored. |
References NAN, and smaxPullDoubleDefault().
double smaxPullDoubleDefault | ( | const char * | table, |
const char * | key, | ||
double | defaultValue | ||
) |
Returns a single floating-point value for a given SMA-X variable, or a specified default value if the SMA-X value could not be retrieved.
table | Hash table name. |
key | Variable name under which the data is stored. |
defaultValue | The value to return in case of an error. |
References smaxPull(), and X_DOUBLE.
double * smaxPullDoubles | ( | const char * | table, |
const char * | key, | ||
XMeta * | meta, | ||
int * | n | ||
) |
Returns a dynamically allocated array of doubles stored in an SMA-X variable.
[in] | table | The hash table name. |
[in] | key | The variable name under which the data is stored. |
[out] | meta | (optional) Pointer to metadata to be filled or NULL if not required. |
[out] | n | Pointer to which the number of double is returned (if *n > 0) or else an error code. |
References X_DOUBLE, and x_trace_null().
int smaxPullInt | ( | const char * | table, |
const char * | key, | ||
int | defaultValue | ||
) |
Returns a single integer value for a given SMA-X variable, or a default value if the value could not be retrieved.
table | The hash table name. |
key | The variable name under which the data is stored. |
defaultValue | The value to return in case of an error. |
References smaxPull(), and X_INT.
int * smaxPullInts | ( | const char * | table, |
const char * | key, | ||
XMeta * | meta, | ||
int * | n | ||
) |
Returns a dynamically allocated array of integers stored in an SMA-X variable.
[in] | table | The hash table name. |
[in] | key | The variable name under which the data is stored. |
[out] | meta | (optional) Pointer to metadata to be filled or NULL if not required. |
[out] | n | Pointer to which the number of integers is returned (if *n > 0) or else an error code. |
References X_INT, and x_trace_null().
long long smaxPullLong | ( | const char * | table, |
const char * | key, | ||
long long | defaultValue | ||
) |
Returns a single integer value for a given SMA-X variable, or a default value if the value could not be retrieved.
table | The hash table name. |
key | The variable name under which the data is stored. |
defaultValue | The value to return in case of an error. |
References smaxPull(), and X_LONG.
long long * smaxPullLongs | ( | const char * | table, |
const char * | key, | ||
XMeta * | meta, | ||
int * | n | ||
) |
Returns a dynamically allocated array of long long (int64) integers stored in an SMA-X variable.
[in] | table | The hash table name. |
[in] | key | The variable name under which the data is stored. |
[out] | meta | (optional) Pointer to metadata to be filled or NULL if not required. |
[out] | n | Pointer to which the number of integers is returned (if *n > 0) or else an error code. |
References X_INT, and x_trace_null().
char * smaxPullRaw | ( | const char * | table, |
const char * | key, | ||
XMeta * | meta, | ||
int * | status | ||
) |
Returns a dynamically allocated buffer with the raw string value stored in SMA-X. This call can also be used to get single string values from SMA-X, since for single string the stored raw value is simply the string itself. However, to properly retrieve string arrays, you want to use smaxPullStrings() instead.
[in] | table | The hash table name. |
[in] | key | The variable name under which the data is stored. |
[out] | meta | (optional) Pointer to metadata to be filled or NULL if not required. |
[out] | status | Pointer int which an error status is returned. |
References smaxPull(), x_error(), X_RAW, and x_trace_null().
char * smaxPullString | ( | const char * | table, |
const char * | key | ||
) |
Returns a single string value for a given SMA-X variable, or a NULL if the value could not be retrieved.
table | Hash table name. |
key | Variable name under which the data is stored. |
References smaxPull(), X_STRING, and x_trace_null().
char ** smaxPullStrings | ( | const char * | table, |
const char * | key, | ||
XMeta * | meta, | ||
int * | n | ||
) |
Returns an array of pointers to individuals strings inside the retrieved contiguous data buffer. Thus, to discard the returned data after use, you must first discard the underlying buffer (as pointed by the first element) before discarding the array of pointers themselves. E.g.:
char **array = smaxPullStrings("mygroup", "myfield", &meta); ... if(array != NULL) { free(array[0]); // discards the underlying contiguous buffer free(array); // discards the array of pointers. }
[in] | table | The hash table name. |
[in] | key | The variable name under which the data is stored. |
[out] | meta | (optional) Pointer to metadata to be filled or NULL if not required. |
[out] | n | Pointer to which the number of double is returned (if *n > 0) or else an error code. |
References smaxGetMetaCount(), smaxPullRaw(), XMeta::storeBytes, x_error(), X_META_INIT, and x_trace_null().
XStructure * smaxPullStruct | ( | const char * | id, |
XMeta * | meta, | ||
int * | status | ||
) |
Returns a dynamically allocated XStrucure for the specified hashtable in SMA-X.
[in] | id | Aggregated structure ID. |
[out] | meta | (optional) Pointer to metadata to be filled or NULL if not required. |
[out] | status | Pointer int which an error status is returned. |
References smaxPull(), x_error(), X_STRUCT, and x_trace_null().
int smaxShareBoolean | ( | const char * | table, |
const char * | key, | ||
boolean | value | ||
) |
Shares a single boolean value to SMA-X. All non-zero values are mapped to "1".
table | The hash table name. |
key | The variable name under which the data is stored. |
value | A boolean value. |
References smaxShareBooleans(), and X_SUCCESS.
int smaxShareBooleans | ( | const char * | table, |
const char * | key, | ||
const boolean * | values, | ||
int | n | ||
) |
Shares an array of boolean values to SMA-X. All non-zero values are mapped to "1".
table | Hash table name. |
key | Variable name under which the data is stored. |
values | Pointer to boolean[] array. |
n | Number of elements in array to share. |
References smaxShare(), X_BOOLEAN, and X_SUCCESS.
int smaxShareBytes | ( | const char * | table, |
const char * | key, | ||
const char * | values, | ||
int | n | ||
) |
Shares a binary sequence to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
values | pointer to the byte buffer. |
n | Number of bytes in buffer to share. |
References smaxShare(), X_BYTE, and X_SUCCESS.
int smaxShareDouble | ( | const char * | table, |
const char * | key, | ||
double | value | ||
) |
Shares a single floating point value to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
value | floating-point value. |
References smaxShareDoubles(), and X_SUCCESS.
int smaxShareDoubles | ( | const char * | table, |
const char * | key, | ||
const double * | values, | ||
int | n | ||
) |
Shares an array of doubles to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
values | Pointer to double[] array. |
n | Number of elements in array to share. |
References smaxShare(), X_DOUBLE, and X_SUCCESS.
int smaxShareFloats | ( | const char * | table, |
const char * | key, | ||
const float * | values, | ||
int | n | ||
) |
Shares an array of floats to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
values | Pointer to float[] array. |
n | Number of elements in array to share. |
References smaxShare(), X_FLOAT, and X_SUCCESS.
int smaxShareHex | ( | const char * | table, |
const char * | key, | ||
long long | value | ||
) |
Shares a single integer value to SMA-X in a hexadecimal representatin.
table | The hash table name. |
key | The variable name under which the data is stored. |
value | Integer value. |
References smaxShare(), X_LONG_HEX, and X_SUCCESS.
int smaxShareInt | ( | const char * | table, |
const char * | key, | ||
long long | value | ||
) |
Shares a single integer value to SMA-X.
table | Hash table name. |
key | Variable name under which the data is stored. |
value | Integer value. |
References smaxShareLongs(), and X_SUCCESS.
int smaxShareInts | ( | const char * | table, |
const char * | key, | ||
const int * | values, | ||
int | n | ||
) |
Shares an array of long integers to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
values | Pointer to int[] array. |
n | Number of elements in array to share. |
References smaxShare(), X_INT, and X_SUCCESS.
int smaxShareLongs | ( | const char * | table, |
const char * | key, | ||
const long long * | values, | ||
int | n | ||
) |
Shares an array of wide integers to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
values | Pointer to long long[] array. |
n | Number of elements in array to share. |
References smaxShare(), X_LONG, and X_SUCCESS.
int smaxShareShorts | ( | const char * | table, |
const char * | key, | ||
const short * | values, | ||
int | n | ||
) |
Shares an array of shorts to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
values | Pointer to short[] array. |
n | Number of elements in array to share. |
References smaxShare(), X_SHORT, and X_SUCCESS.
int smaxShareString | ( | const char * | table, |
const char * | key, | ||
const char * | sValue | ||
) |
Shares a single string value to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
sValue | Pointer to string. |
References smaxShare(), X_RAW, and X_SUCCESS.
int smaxShareStrings | ( | const char * | table, |
const char * | key, | ||
const char ** | sValues, | ||
int | n | ||
) |
Shares an array of strings to SMA-X.
table | The hash table name. |
key | The variable name under which the data is stored. |
sValues | Pointer to array of string pointers. |
n | Number of elements in array to share. |
References smaxShare(), x_error(), X_NULL, X_RAW, and X_SUCCESS.
int smaxWaitOnSubscribed | ( | const char * | table, |
const char * | key, | ||
int | timeout | ||
) |
Waits for a specific pushed entry. There must be an active subscription that includes the specified group & variable, or else the call will block indefinitely.
table | Hash table name |
key | Variable name to wait on. |
timeout | (s) Timeout value. 0 or negative values result in an indefinite wait. |
References x_error(), X_GROUP_INVALID, X_NAME_INVALID, and X_SUCCESS.
int smaxWaitOnSubscribedGroup | ( | const char * | matchTable, |
char ** | changedKey, | ||
int | timeout | ||
) |
Waits for changes on a specific group. The must be an active subscription including that group, or else the call will block indefinitely.
[in] | matchTable | Hash table name (e.g. owner ID) to wait on. |
[out] | changedKey | Pointer to the string that holds the name of the variable which unblocked the wait or which is set to NULL. The lease of the buffer is for the call only. The caller should copy its content if persistent storage is required. |
[in] | timeout | (s) Timeout value. 0 or negative values result in an indefinite wait. |
References x_error(), X_GROUP_INVALID, and X_SUCCESS.
int smaxWaitOnSubscribedVar | ( | const char * | matchKey, |
char ** | changedTable, | ||
int | timeout | ||
) |
Waits for a specific pushed variable from any group/table. There must be an active subscription that includes the specified variable in one or more groups/tables, or else the call will block indefinitely.
[in] | matchKey | Variable name to wait on. |
[out] | changedTable | Pointer to the string that holds the name of the table which unblocked the wait or which is set to NULL. The lease of the buffer is for the call only. The caller should copy its content if persistent storage is required. |
[in] | timeout | (s) Timeout value. 0 or negative values result in an indefinite wait. |
References x_error(), X_NAME_INVALID, and X_SUCCESS.