FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
Memory-mapped Arrays of Variables

Creates memory-mapped arrays of variables. More...

Classes

struct  MappedVarRecord
 Data structure to reference a variable record within a memory-mapped segment. More...
 

Macros

#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); }
 

Functions

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...
 

Detailed Description

Creates memory-mapped arrays of variables.

Macro Definition Documentation

◆ 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
namepoints 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
namepoints to the variable name
fmtpoints to the desired output format
lenspecifies the length of the variable data.

◆ MAPPED_INT_VAR

#define MAPPED_INT_VAR (   tbl,
  id 
)    MAPPED_TYPE_VAR(int32_t, tbl,id)

Get the address of a MappedVarRecords value representing an integer.

Parameters
tblspecifies the MappedVarRecords array of interest
idspecifies 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
tspecifies the type of the data
tblspecifies the MappedVarRecords array of interest
idspecifies 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
tspecifies the type of the data
tblspecifies the MappedVarRecord array of interest
idspecifies 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
tspecifies the type of the data
tblspecifies the MappedVarRecord array of interest
idspecifies the subscript within the tbl.

Function Documentation

◆ 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
numVarsindicates the number of elements in the vars array.
varsis an prepared array of MappedVarRecords (discussed below) and will be filled in with additional attributes upon successful completion.
segmentis the address of a pointer to the shared memory segment. Normally set to null before entry and filled in with the value upon return.
segmentLenPtrpoints 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.
doInitis a flag from createMappedFile().
fileNamespecifies the file name to be created or mapped into memory.
Return values
-1indicates the call was unsuccessful.
0indicates 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.
1indicates 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.

Generated: Fri Jul 31 2020 18:19:16
Support Information