Home2L - C/C++ API  v1.2-2-ga4fe (2023-04-15)
Smart Tools for a Private Home
Macros
env.H File Reference
#include "base.H"
#include <stdio.h>
Include dependency graph for env.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HOME2L_USER   "home2l"
 User and group name of the Home2L user (for background processes).
 
Variables with standard types ...
#define ENV_PARA_STRING(key, varName, varDefault)   const char *varName = varDefault; CEnvPara varName##PreInit (key, eptString, &varName); const char *varName##Key = key;
 
#define ENV_PARA_PATH(key, varName, varDefault)   const char *varName = varDefault; CEnvPara varName##PreInit (key, eptPath, &varName); const char *varName##Key = key;
 Path can be made absolute before first use by calling EnvGetPath (<varName>Key, &<varName>, [<base path>] ) afterwards.
 
#define ENV_PARA_INT(key, varName, varDefault)   int varName = varDefault; CEnvPara varName##PreInit (key, eptInt, &varName); const char *varName##Key = key;
 
#define ENV_PARA_FLOAT(key, varName, varDefault)   float varName = varDefault; CEnvPara varName##PreInit (key, eptFloat, &varName); const char *varName##Key = key;
 
#define ENV_PARA_BOOL(key, varName, varDefault)   bool varName = varDefault; CEnvPara varName##PreInit (key, eptBool, &varName); const char *varName##Key = key;
 
Variables for special cases ...

such as free types, manual initialization or read-only variables.

#define ENV_PARA_VAR(key, varType, varName, varDefault)   varType varName = varDefault; const char *varName##Key = key;
 
Keys without a variable ...

The macro just defines a key name as a constant variable.

#define ENV_PARA_NOVAR(key, varType, varName, varDefault)   const char *varName##Key = key;
 Argument 'varType' is used for automatic documentation.
 
Groups of variables ...

such as patterned variables like doorman.<PHONE>.register.

#define ENV_PARA_SPECIAL(keyPattern, varType, varDefault)
 Arguments 'varType' and 'varDefault' are used for automatic documentation.
 

Functions

Environment ...
const char * EnvBuildOS ()
 Operating software ("Debian", "Android", ...).
 
const char * EnvBuildArch ()
 Operating architecture (e.g. "i386", "armhf", ...).
 
const char * EnvMachineName ()
 Machine name (network host name).
 
const char * EnvExecPathName ()
 Full path name of the executable (== argv[0]). More...
 
const char * EnvExecName ()
 File name of the executable without path.
 
const char * EnvInstanceName ()
 Instance name - the identifier for the running process. More...
 
const char * EnvDroidId ()
 Droid ID.
 
int EnvPid ()
 Operating system's process identifier (PID).
 
bool EnvHaveTerminal ()
 'true', if the application has been started from an interactive terminal.
 
void EnvReadIniFile (const char *fileName, CDictCompact< CString > *map)
 Read a .ini file. 'fileName' must be an absolute path name.
 
Directories ...
const char * EnvHome2lRoot ()
 Root installation path: all static data (blob + etc).
 
const char * EnvHome2lEtc ()
 'etc' root path: configuration data.
 
const char * EnvHome2lVar ()
 'var' root path: dynamic data (saved over reboots).
 
const char * EnvHome2lTmp ()
 'tmp' root path: dynamic data (not need to save over reboots).
 
const char * EnvGetHome2lRootPath (CString *ret, const char *relOrAbsPath)
 Return an absolute path name in the root domain. A path starting with '/' is considered already absolute and is returned unchanged, but normalized.
 
const char * EnvGetHome2lEtcPath (CString *ret, const char *relOrAbsPath)
 Return an absolute path name in the 'etc' domain.
 
const char * EnvGetHome2lVarPath (CString *ret, const char *relOrAbsPath)
 Return an absolute path name in the 'var' domain.
 
const char * EnvGetHome2lTmpPath (CString *ret, const char *relOrAbsPath)
 Return an absolute path name in the 'tmp' domain.
 
bool EnvMkVarDir (const char *relOrAbsPath)
 Prepare (create) a directory in the 'var' domain. More...
 
bool EnvMkTmpDir (const char *relOrAbsPath)
 Prepare (create) a directory in the 'tmp' domain.
 
Network ...
bool EnvNetResolve (const char *hostAndPort, CString *retHost, int *retPort=NULL, int defaultPort=0, bool warn=true)
 Get a resolved host + port combination. More...
 
Location ...
float EnvLocationLatitudeN ()
 Get the WGS84 latitude north coordinate of the home (the 'location.latitudeN' setting).
 
float EnvLocationLongitudeE ()
 Get the WGS84 longitude east coordinate of the home (the 'location.longitudeE' setting).
 
Init/Done ...
void EnvInit (int argc, char **argv, const char *specOptionsUsage=NULL, const char *instanceName=NULL, bool noBanner=false)
 Initialize the environment module. More...
 
void EnvPrintBanner ()
 Print the tool banner (only useful if banner was suppressed in the EnvInit() call).
 
void EnvDone ()
 Shutdown the environment module.
 
Persistence ...
void EnvEnablePersistence (bool writeThrough=true, const char *_varFileName=NULL)
 Enable the persistence of all environment variables starting with "var.*". More...
 
void EnvFlush ()
 Write back any persistent variables now.
 
Primitive Get/Put ...
const char * EnvGet (const char *key)
 Generically read a setting; Returns 'NULL' on non-existence and never prints warnings. More...
 
const char * EnvPut (const char *key, const char *value)
 Generically put a string into the dictionary; Passing 'value == NULL' removes the entry. More...
 
const char * EnvPut (const char *key, int value)
 Put an integer or boolean variable into the dictionary. More...
 
static void EnvDel (const char *key)
 Remove an entry from the environment dictionary.
 
Get with type ...

These functions get an environment parameter and convert them to a given type. For each type, there are two variants:

  1. An advanced function returning the success status and - only on success - writing the result back via a pointer.
  2. A simple function returning that type; On error, the type's default value is returned. In all variants, a warning is emitted in case of a syntax error. If a parameter does not existence, 'false' is returned as a success code, and a warning is emitted if 'warnIfMissing' is set. Most parameters have reasonable defaults, so that 'warnIfMissing' is set to 'false' by default. To help with the discovery of typos in parameter keys, all accesses to non-existent parameters are logged as debug messages of level 1 in EnvGet().

Note: The functions with implicit translation capabilities ('EnvGetPath*' and 'EnvGetHost*') convert their strings in place. This means:

  1. Later retrievals by EnvGet() will return the absolute path, not the original string, e.g. from the configuration file.
  2. These functions may only be called from the main thread.
bool EnvGetString (const char *key, const char **ret, bool warnIfMissing=false)
 Read a string (advanced variant).
 
const char * EnvGetString (const char *key, const char *defaultVal, bool warnIfMissing=false)
 Read a string (simple variant).
 
static const char * EnvGetString (const char *key, bool warnIfMissing)
 Read a string (simple variant) without default.
 
static const char * EnvGetString (const char *key)
 Accelerator for 'EnvGetString (key, warnIfMissing = false)'.
 
bool EnvGetPath (const char *key, const char **ret, const char *path=NULL, bool warnIfMissing=false)
 Read a path, eventually convert value to an absolute path before (advanced). The returned path is always absolute. Relative paths are interpreted as relative to 'path' or HOME2L_ROOT and made absolute.
 
const char * EnvGetPath (const char *key, const char *path=NULL, bool warnIfMissing=false)
 Read a path, eventually convert value to an absolute path before (simple).
 
bool EnvGetHostAndPort (const char *key, CString *retHost, int *retPort=NULL, int defaultPort=0, bool warnIfMissing=false)
 Get a host + port combination; host names are translated using the 'net.resolve.<name>' settings.
 
static bool EnvGetHost (const char *key, CString *retHost, bool warnIfMissing=false)
 Get a host name; host names are translated using the 'net.resolve.<name>' settings.
 
bool EnvGetInt (const char *key, int *ret, bool warnIfMissing=false)
 Read an integer (advanced).
 
int EnvGetInt (const char *key, int defaultVal=0, bool warnIfMissing=false)
 Read an integer (simple).
 
bool EnvGetFloat (const char *key, float *ret, bool warnIfMissing=false)
 Read a float value (advanced).
 
float EnvGetFloat (const char *key, float defaultVal=0.0, bool warnIfMissing=false)
 Read a float value (simple).
 
bool EnvGetBool (const char *key, bool *ret, bool warnIfMissing=false)
 Read a boolean value (advanced).
 
bool EnvGetBool (const char *key, bool defaultVal=false, bool warnIfMissing=false)
 Read a boolean value (simple).
 
Advanced access to the dictionary ...
void EnvGetPrefixInterval (const char *prefix, int *retIdx0, int *retIdx1)
 
const char * EnvGetKey (int idx)
 
const char * EnvGetVal (int idx)
 
const CDictRawEnvGetKeySet ()
 Get the complete key set for direct key listing. More...