smax-clib v0.9
A C/C++ client library for SMA-X
Loading...
Searching...
No Matches
smax-meta.c File Reference

A set of utility functions for manipulating optional static metadata. More...

Functions

XCoordinateSystemsmaxCreateCoordinateSystem (int nAxis)
 
void smaxDestroyCoordinateSystem (XCoordinateSystem *coords)
 
XCoordinateAxissmaxGetCoordinateAxis (const char *id, int n)
 
XCoordinateSystemsmaxGetCoordinateSystem (const char *table, const char *key)
 
char * smaxGetDescription (const char *table, const char *key)
 
char * smaxGetUnits (const char *table, const char *key)
 
char * smaxPullMeta (const char *meta, const char *table, const char *key, int *status)
 
double smaxPullTime (const char *table, const char *key)
 
XType smaxPullTypeDimension (const char *table, const char *key, int *ndim, int *sizes)
 
int smaxPushMeta (const char *meta, const char *table, const char *key, const char *value)
 
int smaxSetCoordinateAxis (const char *id, int n, const XCoordinateAxis *axis)
 
int smaxSetCoordinateSystem (const char *table, const char *key, const XCoordinateSystem *coords)
 
int smaxSetDescription (const char *table, const char *key, const char *description)
 
int smaxSetUnits (const char *table, const char *key, const char *unit)
 

Detailed Description

A set of utility functions for manipulating optional static metadata.

Date
Mar 24, 2020
Author
Attila Kovacs

Function Documentation

◆ smaxCreateCoordinateSystem()

XCoordinateSystem * smaxCreateCoordinateSystem ( int  nAxis)

Creates a coordinate system with the desired dimension, and standard Cartesian coordinates with no labels, or units specified (NULL).

Parameters
nAxisDimension of the coordiante system, i.e. number of axes.
Returns
Pointer to the new coordinate system structure, or NULL if the coordiate system could not be created as specified.
See also
smaxDestroyCoordinateSystem()

References XCoordinateSystem::axis, XCoordinateSystem::nAxis, XCoordinateAxis::step, x_error(), and X_MAX_DIMS.

◆ smaxDestroyCoordinateSystem()

void smaxDestroyCoordinateSystem ( XCoordinateSystem coords)

Deallocates a coordinate system structure.

Parameters
coordsPointer to the coordinate system to discard.
See also
smaxCreateCoordinateSystem()

References XCoordinateSystem::axis.

◆ smaxGetCoordinateAxis()

XCoordinateAxis * smaxGetCoordinateAxis ( const char *  id,
int  n 
)

Returns the n'th coordinate axis for a given SMA-X coordinate system table id.

Parameters
idFully qualified SMA-X coordinate system ID.
nThe (0-based) index of the coordinate axis
Returns
Pointer to a newly allocated XCoordinateAxis structure or NULL if the axis is undefined, or could not be retrieved from the database.
See also
smaxSetCoordinateAxis()

References RedisEntry::key, XCoordinateAxis::name, redisxGetTable(), XCoordinateAxis::refIndex, XCoordinateAxis::refValue, smaxGetRedis(), XCoordinateAxis::step, XCoordinateAxis::unit, RedisEntry::value, x_error(), x_trace_null(), and xGetAggregateID().

◆ smaxGetCoordinateSystem()

XCoordinateSystem * smaxGetCoordinateSystem ( const char *  table,
const char *  key 
)

Returns the coordinate system, if any, associated to a given SMA-X variable.

Parameters
tableHash table name.
keyVariable / field name in table.
Returns
A newly allocated coordinate system structure, or NULL.
See also
smaxSetCoordinateSystem()
smaxGetCoordinateAxis()

References XCoordinateSystem::axis, META_COORDS, XCoordinateSystem::nAxis, smaxGetCoordinateAxis(), X_MAX_DIMS, x_trace_null(), and xGetAggregateID().

◆ smaxGetDescription()

char * smaxGetDescription ( const char *  table,
const char *  key 
)

Returns a concise description of a variable.

Parameters
tableHash table name.
keyVariable / field name in table.
Returns
Variable description or NULL or empty string if the variable has no description assiciated with it.
See also
smaxSetDescription()

References META_DESCRIPTION, smaxPullMeta(), X_SUCCESS, and x_trace_null().

◆ smaxGetUnits()

char * smaxGetUnits ( const char *  table,
const char *  key 
)

Returns the physical unit name, if any, for the given variable.

Parameters
tableHash table name.
keyVariable / field name in table.
Returns
Unit name (e.g. "W / Hz"), or NULL or empty string if the variable has no designated physical unit.
See also
smaxSetUnits()

References META_UNIT, smaxPullMeta(), X_SUCCESS, and x_trace_null().

◆ smaxPullMeta()

char * smaxPullMeta ( const char *  meta,
const char *  table,
const char *  key,
int *  status 
)

Retrieves a metadata string value for a given variable from the database

Parameters
metaRoot meta table name, usually something like "<metaname>".
tableHash table name.
keyVariable / field name in table.
statusPointer to int in which to return a X_SUCCESS or an error code.
Returns
The string metadata value or NULL.
See also
setPushMeta()

References redisxGetStringValue(), smaxGetRedis(), x_error(), X_GROUP_INVALID, X_NO_INIT, x_trace_null(), and xGetAggregateID().

◆ smaxPullTime()

double smaxPullTime ( const char *  table,
const char *  key 
)

Retrieves the timestamp for a given variable from the database.

Parameters
[in]tableHash table name (or NULL if key is an aggregate ID).
[in]keyVariable / field name in table.
Returns
(s) UNIX timestamp, as fractional seconds since 1 Jan 1970, or NAN if there was an error.
See also
setPushMeta()

References NAN, SMAX_TIMESTAMPS, smaxPullMeta(), and x_trace_null().

◆ smaxPullTypeDimension()

XType smaxPullTypeDimension ( const char *  table,
const char *  key,
int *  ndim,
int *  sizes 
)

Retrieves the timestamp for a given variable from the database.

Parameters
[in]tableHash table name (or NULL if key is an aggregate ID).
[in]keyVariable / field name in table.
[out]ndimPointer to integer in which to return the dimensionality of the variable, or NULL if not requested.
[out]sizesArray to store sizes along each dimension, which should hold X_MAX_DIMS integers, or NULL if dimensions are not requested.
Returns
Type of data stored under the specified table/key ID.
See also
setPushMeta()

References SMAX_DIMS, SMAX_TYPES, smaxPullMeta(), smaxTypeForString(), x_trace(), X_UNKNOWN, and xParseDims().

◆ smaxPushMeta()

int smaxPushMeta ( const char *  meta,
const char *  table,
const char *  key,
const char *  value 
)

Adds/updates metadata associated with an SMA-X variable. The data will be pushed via the Redis pipeline channel.

Parameters
metaRoot meta table name, usually something like "<metaname>".
tableHash table name.
keyVariable / field name in table.
valueMetadata string value.
Returns
X_SUCCESS (0) if the metadata was successfully retrieved X_INCOMPLETE if the meatdata was successfully written but an update notification was not sent or else the return value of redisxSetValue()
See also
smaxPullMeta(), redisxSetValue()

References FALSE, redisxNotify(), redisxSetValue(), smaxGetProgramID(), smaxGetRedis(), x_error(), X_GROUP_INVALID, X_INCOMPLETE, X_NO_INIT, X_NULL, X_SUCCESS, x_trace(), and xGetAggregateID().

◆ smaxSetCoordinateAxis()

int smaxSetCoordinateAxis ( const char *  id,
int  n,
const XCoordinateAxis axis 
)

Defines the n'th coordinate axis for a given SMA-X coordinate system table id.

Parameters
idFully qualified SMA-X coordinate system ID.
nThe (0-based) index of the coordinate axis
axisPointer to the structure describing the coordinate axis.
Returns
X_SUCCESS (0) if the coordinate axis was successfully set in the database. or else the return value of redisxMultiSet().
See also
smaxSetCoordinateAxis(), redisxMultiSet()

References FALSE, RedisEntry::key, XCoordinateAxis::name, redisxMultiSet(), XCoordinateAxis::refIndex, XCoordinateAxis::refValue, smaxGetRedis(), XCoordinateAxis::step, XCoordinateAxis::unit, RedisEntry::value, X_FAILURE, X_SUCCESS, x_trace(), and xGetAggregateID().

◆ smaxSetCoordinateSystem()

int smaxSetCoordinateSystem ( const char *  table,
const char *  key,
const XCoordinateSystem coords 
)

Sets the coordinate system metadata for data in the database.

Parameters
tableHash table name.
keyVariable / field name in table.
coordsPointer to the coordinate system structure associated to this variable.
Returns
X_SUCCESS (0) if the coordinate system was successfully sent to SMA-X or else the first error encountered by xSetCoordinateAxis()
See also
smaxGetCoordinateSystem()
smaxSetCoordinateAxis()

References XCoordinateSystem::axis, META_COORDS, XCoordinateSystem::nAxis, smaxSetCoordinateAxis(), X_NULL, X_SUCCESS, x_trace(), and xGetAggregateID().

◆ smaxSetDescription()

int smaxSetDescription ( const char *  table,
const char *  key,
const char *  description 
)

Sets the static description for a given SMA-X variable.

Parameters
tableHash table name.
keyVariable / field name in table.
descriptionConcise but descriptive summary of the meaning of the variable.
Returns
X_SUCCESS (0) If successful or else the return value of smaxPushMeta()
See also
smaxSetDescription(), smaxPushMeta()

References META_DESCRIPTION, smaxPushMeta(), and X_SUCCESS.

◆ smaxSetUnits()

int smaxSetUnits ( const char *  table,
const char *  key,
const char *  unit 
)

Sets the physical unit name for a given SMA-X variable.

Parameters
tableHash table name.
keyVariable / field name in table.
unitStandard unit specification, e.g. "W / Hz" or "W Hz**{-1}".
Returns
X_SUCCESS (0) If successful or else the return value of smaxPushMeta()
See also
smaxGetUnits(), smaxPushMeta()

References META_UNIT, smaxPushMeta(), and X_SUCCESS.