#ifndef fsubagentRow_H #define fsubagentRow_H #include #ifdef __cplusplus extern "C" { #endif /* First two bytes (in big endian order) written by fsubagentRow_toBuf() */ #define fsubagentRow_MAGIC 0x5352 /* SR */ /* Values that can be present in fsubagentRowConstraints.format[] */ enum fsubagentItemType { fsubagentItem_UNDEF='.', fsubagentItem_INT='i', fsubagentItem_STRING='s' }; /**------------------------------------------------------------------------- Constraints on a row of monitoring variables. Shared among all rows in the same array. --------------------------------------------------------------------------*/ struct fsubagentRowConstraints_s { /** format[i] gives the type of the variable at oid[i+1] in the row. 'i' means int, 's' means string, '.' means gap (no variable at that index) */ const char *format; /** max oid in row; equals strlen(format); stored for convenience */ int maxoid; }; typedef struct fsubagentRowConstraints_s fsubagentRowConstraints; /** Given a transient pointer to the row's format, create a constraints object. */ fsubagentRowConstraints *fsubagentRowConstraints_new(const char *format); /**------------------------------------------------------------------------- A row of monitoring variables. Threadsafe. Contains a mixture of int32 and string variables as defined by the constraints passed in during creation. In the SNMP variables simpleVariable.0 fooTable.fooEntry.fooMember.index1 barTable.barEntry.barMember.index2.index1 the numerical value of the last OID component before the indices (e.g. simpleVariable, fooMember, or barMember) is what you pass to fsubagentRow_{get,set}{Int,String}() to select the desired variable from the designated row. The only methods for use by the app programmer are {Set,Get}Int(), AddInt(), and {Set,Get}String(). The rest of its methods are not meant to be called directly by the programmer; see fsubagent.h. The module is implemented in C using an object-oriented idiom which provides good encapsualation. Since all data members of fsubagentRow are private, the structure is only named here; the full definition is private to fsubagentRow.c. --------------------------------------------------------------------------*/ struct fsubagentRow_s; typedef struct fsubagentRow_s fsubagentRow; /* class fsubagentRow { */ /**---------------------------------------------------------------------- Create a fsubagentRow. @param constraints = stable pointer to row constraints @return initialized fsubagentRow * on success, NULL on failure -----------------------------------------------------------------------*/ fsubagentRow *fsubagentRow_new(const fsubagentRowConstraints *constraints); /**---------------------------------------------------------------------- Delete a fsubagentRow and release any resources it has allocated. -----------------------------------------------------------------------*/ void fsubagentRow_delete(fsubagentRow *); /**---------------------------------------------------------------------- Load new current row contents from buffer. Must obey constraints this row was created with. @param buf Buffer to load from. @param buflen Number of bytes of data in buffer. @return 0 on success, Unix error code on failure -----------------------------------------------------------------------*/ int fsubagentRow_fromBuf(fsubagentRow *, const char *buf, int buflen); /**---------------------------------------------------------------------- Save new current row contents to buffer. @param buf Buffer to save to. @param bufsize Size of buffer in bytes. @param bufused Pointer to where to store number of buffer bytes used. @return 0 on success, Unix error code on failure -----------------------------------------------------------------------*/ int fsubagentRow_toBuf(fsubagentRow *, char *buf, int bufsize, int *bufused); /**---------------------------------------------------------------------- Set an integer variable in the row. @param index which variable in row to set (1 or higher) @param val value to set it to @return 0 on success, Unix error code on failure -----------------------------------------------------------------------*/ int fsubagentRow_setInt(fsubagentRow *, int index, int val); /**---------------------------------------------------------------------- Retrieve an integer variable in the row. @param index which variable in row to get (1 or higher) @param pval pointer to where to store value @return 0 on success, Unix error code on failure -----------------------------------------------------------------------*/ int fsubagentRow_getInt(fsubagentRow *, int index, int *pval); /**---------------------------------------------------------------------- Add the given signed increment to an integer variable in the row. @param index which variable in row to set (1 or higher) @param val value to add to it @return 0 on success, Unix error code on failure -----------------------------------------------------------------------*/ int fsubagentRow_addInt(fsubagentRow *, int index, int val); /**---------------------------------------------------------------------- Set a string variable in the row. Can only be done once. @param index which variable in row to set (1 or higher) @param val pointer to where to copy string value from @return 0 on success, Unix error code on failure -----------------------------------------------------------------------*/ int fsubagentRow_setString(fsubagentRow *, int index, const char *val); /**---------------------------------------------------------------------- Retrieve a string variable in the row. @param index which variable in row to set (1 or higher) @param pp where to save pointer to const string inside row @return 0 on success, Unix error code on failure -----------------------------------------------------------------------*/ int fsubagentRow_getString(fsubagentRow *, int index, const char **p); /**---------------------------------------------------------------------- Lock the row against access by other threads. -----------------------------------------------------------------------*/ void fsubagentRow_lock(fsubagentRow *); /**---------------------------------------------------------------------- Unlock the row. -----------------------------------------------------------------------*/ void fsubagentRow_unlock(fsubagentRow *); /* } */ #ifdef __cplusplus } #endif #endif