Creates memory-mapped arrays of variables.
More...
|
#define | INIT_MAPPED_VAR(name, fmt, len) { 0, 0, name, fmt, len, 0} |
| Convenience macro to define an initialization record for a MappedVarRecord structure. More...
|
|
#define | INIT_MAPPED_INT_VAR(name) INIT_MAPPED_VAR(name, "=%d", sizeof(int)) |
| Convenience macro to define an initialization record for a MappedVarRecord representing an integer variable using text output. The output format used is "=%d", yielding output lines like "varName=NNNN". More...
|
|
#define | MAPPED_TYPE_VAR(t, tbl, id) ((t *)(tbl[id].address)) |
| Get the address of a MappedVarRecords value. More...
|
|
#define | MAPPED_INT_VAR(tbl, id) MAPPED_TYPE_VAR(int32_t, tbl,id) |
| Get the address of a MappedVarRecords value representing an integer. More...
|
|
#define | UPDATE_MAPPED_TYPE_VAR(t, tbl, id) { int _l = sprintf((char *) tbl[id].outputAddress, tbl[id].formatPattern, *MAPPED_TYPE_VAR(t, tbl, id)); tbl[id].outputAddress[_l] = ' '; } |
| Update (format) the output value of a MappedVarRecord element. More...
|
|
#define | RELOAD_MAPPED_TYPE_VAR(t, tbl, id) { int _l = sscanf((char *) tbl[id].outputAddress, tbl[id].formatPattern, MAPPED_TYPE_VAR(t, tbl, id)); } |
| Reload the value represented by the formatted text into the native format held by a MappedVarRecord. More...
|
|
#define | UPDATE_MAPPED_INT_VAR(tbl, id) { uint32_t workBfr[6]; uint32_t _l; uint64_t _v = *MAPPED_INT_VAR(tbl, id); char *_r = int_to_ascii(workBfr, sizeof(workBfr), _v, &_l); int _i = 0; while (tbl[id].formatPattern[_i] != '%') { tbl[id].outputAddress[_i] = tbl[id].formatPattern[_i]; _i+=1; } memcpy(tbl[id].outputAddress+_i, _r, _l); } |
|
|
int | createMappedVars (const uint_fast32_t numVars, struct MappedVarRecord vars[], unsigned char **segment, size_t *segmentLenPtr, const uint_fast32_t doInit, const char *fileName) |
| Create/reload an array of MappedVarRecords that is mapped by a memory mapped file. More...
|
|
Creates memory-mapped arrays of variables.
◆ INIT_MAPPED_INT_VAR
#define INIT_MAPPED_INT_VAR |
( |
|
name | ) |
INIT_MAPPED_VAR(name, "=%d", sizeof(int)) |
Convenience macro to define an initialization record for a MappedVarRecord representing an integer variable using text output. The output format used is "=%d", yielding output lines like "varName=NNNN".
- Parameters
-
name | points to the variable name |
◆ INIT_MAPPED_VAR
#define INIT_MAPPED_VAR |
( |
|
name, |
|
|
|
fmt, |
|
|
|
len |
|
) |
| { 0, 0, name, fmt, len, 0} |
Convenience macro to define an initialization record for a MappedVarRecord structure.
- Parameters
-
name | points to the variable name |
fmt | points to the desired output format |
len | specifies the length of the variable data. |
◆ MAPPED_INT_VAR
Get the address of a MappedVarRecords value representing an integer.
- Parameters
-
tbl | specifies the MappedVarRecords array of interest |
id | specifies the subscript within the tbl . |
◆ MAPPED_TYPE_VAR
#define MAPPED_TYPE_VAR |
( |
|
t, |
|
|
|
tbl, |
|
|
|
id |
|
) |
| ((t *)(tbl[id].address)) |
Get the address of a MappedVarRecords value.
- Parameters
-
t | specifies the type of the data |
tbl | specifies the MappedVarRecords array of interest |
id | specifies the subscript within the tbl . |
◆ RELOAD_MAPPED_TYPE_VAR
#define RELOAD_MAPPED_TYPE_VAR |
( |
|
t, |
|
|
|
tbl, |
|
|
|
id |
|
) |
| { int _l = sscanf((char *) tbl[id].outputAddress, tbl[id].formatPattern, MAPPED_TYPE_VAR(t, tbl, id)); } |
Reload the value represented by the formatted text into the native format held by a MappedVarRecord.
- Parameters
-
t | specifies the type of the data |
tbl | specifies the MappedVarRecord array of interest |
id | specifies the subscript within the tbl . |
◆ UPDATE_MAPPED_INT_VAR
#define UPDATE_MAPPED_INT_VAR |
( |
|
tbl, |
|
|
|
id |
|
) |
| { uint32_t workBfr[6]; uint32_t _l; uint64_t _v = *MAPPED_INT_VAR(tbl, id); char *_r = int_to_ascii(workBfr, sizeof(workBfr), _v, &_l); int _i = 0; while (tbl[id].formatPattern[_i] != '%') { tbl[id].outputAddress[_i] = tbl[id].formatPattern[_i]; _i+=1; } memcpy(tbl[id].outputAddress+_i, _r, _l); } |
◆ UPDATE_MAPPED_TYPE_VAR
#define UPDATE_MAPPED_TYPE_VAR |
( |
|
t, |
|
|
|
tbl, |
|
|
|
id |
|
) |
| { int _l = sprintf((char *) tbl[id].outputAddress, tbl[id].formatPattern, *MAPPED_TYPE_VAR(t, tbl, id)); tbl[id].outputAddress[_l] = ' '; } |
Update (format) the output value of a MappedVarRecord element.
- Parameters
-
t | specifies the type of the data |
tbl | specifies the MappedVarRecord array of interest |
id | specifies the subscript within the tbl . |
◆ createMappedVars()
int createMappedVars |
( |
const uint_fast32_t |
numVars, |
|
|
struct MappedVarRecord |
vars[], |
|
|
unsigned char ** |
segment, |
|
|
size_t * |
segmentLenPtr, |
|
|
const uint_fast32_t |
doInit, |
|
|
const char * |
fileName |
|
) |
| |
Create/reload an array of MappedVarRecords that is mapped by a memory mapped file.
- Parameters
-
numVars | indicates the number of elements in the vars array. |
vars | is an prepared array of MappedVarRecords (discussed below) and will be filled in with additional attributes upon successful completion. |
segment | is the address of a pointer to the shared memory segment. Normally set to null before entry and filled in with the value upon return. |
segmentLenPtr | points to the length of the segment. Normally the value pointed to specifies the desired segment length. Filled in with the actual segment length upon return. |
doInit | is a flag from createMappedFile() . |
fileName | specifies the file name to be created or mapped into memory. |
- Return values
-
-1 | indicates the call was unsuccessful. |
0 | indicates the call was successful, but the existing variables in the mapped segment may not have matched those defined in the vars array. This will always be the case when using unlabeled variables. |
1 | indicates the call was successful and the variables in the vars array matched the contents of the segment. |
Usage Notes: There are two basic choices to be made: whether a pure binary format is to be used or if a plain text format is to be used. If plain text is used, a second choice is made regarding whether variable names will be used in an attribute/value format or just values.
Under normal usage patterns, the address and outputAddress members will be null upon entry. If formatPattern is null, raw binary format will be used. If varName is null, no variable name will be provided in text mode.
References MappedVarRecord::address, createMappedFile(), MappedVarRecord::formatPattern, MAP_FILE_INIT, MappedVarRecord::outputAddress, stderr, and MappedVarRecord::val.