Member Function Documentation
[Field][Field]common::CCircularBuffer::CCircularBuffer (unsigned int uiCirBufsize, unsigned int uiCirBufRecSize, ToOutput fptr)
Constructor.
Parameters:
in |
uiCirBufsize |
size of circular buffer |
in |
uiCirBufRecSize |
size of each record/row of circular buffer |
in |
fptr |
function pointer points to function of third party for circular buffer record processing/formatting |
[Field][Field]bool common::CCircularBuffer::AddRecord (uint64_t uiCurTimeStamp, char * data, uint32_t data_size, bool bWriteIfBufferFull = false)[virtual]
This function adds record in circular buffer one at a time.
Parameters:
in |
uiCurTimeStamp |
time stamp of record generation |
in |
data |
pointer to buffer which contains record data |
in |
data_size |
length of the record pointed by data buffer |
in |
bWriteIfBufferFull |
defines if buffer is full or not (default is false) |
Returns:
true if record is successfully added to circular buffer else false
[Field][Field]void common::CCircularBuffer::GetCircularBufferValue (std::vector< std::string > & vecStrCirBuf)[virtual]
This function returns the data in circular buffer.
Parameters:
in |
vecStrCirBuf |
circular buffer value as vector of strings |
[Field][Field]bool common::CCircularBuffer::IsWritingToFile ()[virtual]
This function tells whether any file operation is in progress.
Returns:
true if file operation is in progress else false
[Field][Field]bool common::CCircularBuffer::WriteToFile (std::string filepath, std::string header, int startTimeSec, int endTimeSec, eOperationType eOperType)[virtual]
This function writes record from circular buffer to a file based on requested operation.
Parameters:
in |
filepath |
size of circular buffer |
in |
header |
header header of the outpul file |
in |
startTimeSec |
integer value in seconds relative to current time from where record is written to file |
in |
endTimeSec |
integer value in seconds relative to current time up to which record is written to file |
in |
eOperType |
type of operation : ENEW, EAPPEND as defined in eOperationType enum |
Returns:
true if request is valid else false
File Handling
The common library provides the framework to perform operations on binary files. These files are needed to store the persistent data. It includes the agent output files as well as cout log files. The files are implemented in a circular manner, so the last data is removed once its full. The persistent files are stored in flash folder /tmp/container/50593792/rootfs/usr/share/flash/<overlayId-Dec>/<AgentId-Dec>.
Member Function Documentation
[Field][Field]virtual eResult common::AgentBinFile::Append (const void * i_Buffer)[virtual]
This function appends to the file.
Parameters:
in |
i_Buffer |
input buffer |
Returns:
-
eSuccess, if success
-
eFailure, if failure
Implements common::IAgentFile.
[Field][Field]virtual eResult common::AgentBinFile::Delete (const char * i_cFileName)[virtual]
This function deletes the file.
Parameters:
in |
i_cFileName |
name of the file |
Returns:
-
eSuccess , if success
-
eFailure , f failure
Implements common::IAgentFile.
[Field][Field]virtual char* common::AgentBinFile::GetLatestErrorMessage ()[virtual]
This function gets the latest error occurred during the file operations.
Returns:
-
pointer to char array where the error message is stored
Implements common::IAgentFile.
[Field][Field]virtual eResult common::AgentBinFile::GetNumberOfRows (uint16_t & o_usCurrentRows, uint16_t & o_usBuffTail)[virtual]
This function gets the number of rows and tail of buffer.
Parameters:
out |
o_usCurrentRows |
number of rows in file |
out |
o_usBuffTail |
row number which row pointer is pointing to or tail of buffer |
Returns:
-
eSuccess , f success
-
eFailure , if failure
Implements common::IAgentFile.
[Field][Field]virtual eResult common::AgentBinFile::Open (const char * i_cFileName, const uint16_t i_usRowLength)[virtual]
This function opens an existing file else creates the file.
Parameters:
in |
i_cFileName |
name of the file |
in |
i_usRowLength |
Length of one row |
Returns:
-
eSuccess , if success
-
eFailure, if failure
Implements common::IAgentFile.
[Field][Field]virtual eResult common::AgentBinFile::OpenToRead (const char * i_cFileName, const uint16_t i_usRowLength)[virtual]
This function opens an existing file in read mode.
Parameters:
in |
i_cFileName |
name of the file |
in |
i_usRowLength |
Length of one row |
Returns:
-
eSuccess , if success
-
eFailure, if failure
Implements common::IAgentFile.
[Field][Field]virtual eResult common::AgentBinFile::Read (const uint16_t i_usFromRow, const uint16_t i_usToRow, void * o_Buffer)[virtual]
This function reads the content of the file.
Parameters:
in |
i_usFromRow |
starts from row number i_usFromRow |
in |
i_usToRow |
reads till row number i_usToRow |
out |
o_Buffer |
outputs the content read to o_Buffer |
Returns:
-
eSuccess, if success
-
eFailure , if failure
Implements common::IAgentFile.
[Field][Field]IAgentFile::eResult common::AgentBinFile::Update (const void * i_Buffer, uint16_t i_uRowPosition)
This function updates row based on given position.
Parameters:
in |
i_Buffer |
input buffer string |
in |
i_uRowPosition |
input row position in file |
Returns:
-
eSuccess, if success
-
eFailure, if failure
[Field][Field]virtual eResult common::AgentBinFile::Write (const void * i_Buffer)[virtual]
This function writes at or replaces the next row to the file.
Parameters:
in |
i_Buffer |
input buffer string |
Returns:
-
eSuccess, if success
-
eFailure, if failure
Configuration Handing
The common library provides the framework to specify the configuration description in an XML file. The common library automatically validates the incoming configuration XML using the description. The common library also takes care of sending notifications back to the server to indicate success or failure of the configuration. The agent can register callback functions to be called when there is a change of any configuration value. This is implemented using CConfigParser class. This class requires description file for each configuration to work. The methods implemented by this class are-
Static Public Member Functions
static CConfigParser & GetConfigParserInstance ()
This function gets instance of the CConfigParser.
Member Function Documentation
bool common::CConfigParser::InitFeature (const uint32_t & i_featureId, string & o_errorMsg)
This function initializes the passed feature in CParseConfig class.
Parameters:
in |
i_featureId |
Feature Id |
out |
o_errorMsg |
Error message if any |
Returns:
-
true, if success
-
false, if failure
[Field][Field]bool common::CConfigParser::ManageConfigXMLString (const uint32_t i_uiFeatureId, const uint32_t i_configId, const uint32_t i_featureVersion, const uint32_t i_uiConfigLen, const char * i_configurationBlobStream, XmlReturnVal & i_eRetval)
Manages configuration xml parameters.
Parameters:
in |
i_uiFeatureId |
Feature Id under which updated config parameter lies |
in |
i_configId |
Configuration id |
in |
i_featureVersion |
feature version |
in |
i_uiConfigLen |
config length for the feature |
in |
i_configurationBlobStream |
string containing XML content |
in |
i_eRetval |
XML return values, useful incase of error |
Returns:
-
true, if success
-
false, if failure
[Field][Field]AgentApiReturnType common::CConfigParser::ProcessConfigurationList (void * featureConfigurationList)
This function parses the configuration list received.
Parameters:
in |
featureConfigurationList |
Configuration feature handle |
Returns:
AgentApiReturnType return API error
[Field][Field]bool common::CConfigParser::RegisterConfigParamCallback (const uint32_t & i_featureId, const string & i_folder, const string & i_paramter, ConfigValSetCallback i_configValSetCallback, string & o_errorMsg)
Register callback functions to update parameters available in configuration xml file.
Parameters:
in |
i_featureId |
Feature Id |
in |
i_folder |
input parameter for folder name |
in |
i_paramter |
input name of the parameter which belong to specified folder |
in |
i_configValSetCallback |
callback function to update related parameter used by caller |
out |
o_errorMsg |
Error message if any |
Returns:
-
true, if success
-
false, if failure
[Field][Field]bool common::CConfigParser::RegisterConfigurationUpdateCallback (ConfigUpdateCallback i_ConfigUpdateCallback, string & o_errorMsg)
This function is getting used to register callback by the agent to update all the configuration params after processing the xml file.
Parameters:
in |
i_ConfigUpdateCallback |
callback function to update configuration params by caller |
out |
o_errorMsg |
error message if any |
Returns:
-
true, if success
-
false, if failure
[Field][Field]void common::CConfigParser::setAgentId (const uint32_t i_agentId)
This function sets the agent id.
Parameters:
in |
i_agentId |
Agent Id |
[Field][Field]bool common::CConfigParser::UpdateAPIServiceForFeature (const uint32_t & i_featureId, string & o_errorMsg)
This function is used by agent indicating the config module to subscribe API services for configuration management.
Parameters:
in |
i_featureId |
feature Id |
out |
o_errorMsg |
error message if any |
Returns:
-
true, if success
-
false, if failure
Command Handling
The common library provides a framework to allow the server to send commands to the agent using the configuration framework. The agent can register callback functions for each command. The new commands can be added as per requirement of an agent. To process the commands sent by agent, CCommand class is implemented. The methods implemented by this class are –
Static Public Member Functions
static CCommand & GetCommandInstance ()
This function gets the instance of CCommand.
Member Function Documentation
[Field][Field]static CCommand& common::CCommand::GetCommandInstance ()[static]
This function gets the instance of CCommand.
Returns:
instance of CCommand
[Field][Field]bool common::CCommand::InitCommand (CConfigParser & i_configParser, string & o_errorMsg)
This function initializes command configurations.
Parameters:
in |
i_configParser |
configuration parser object |
out |
o_errorMsg |
error message to be returned |
Returns:
-
TRUE, if success
-
FALSE, if failure
[Field][Field]void common::CCommand::ProcessCommandConfigurationCallback (string i_folderName, string i_paramName, stConfigVal i_stConfigVal)
This function processes callback method which will be called when config module get any update for command parameters via xml.
Parameters:
in |
i_folderName |
folder name of the configuration parameter |
in |
i_paramName |
parameter name of the configuration value |
in |
i_stConfigVal |
parameter value and type |
[Field][Field]bool common::CCommand::RegisterCommand (CConfigParser & i_configParser, const string i_commandName, CommandCallback i_funPtr, string & o_errorMsg)
This function registers the commands with function callback pointer.
Parameters:
in |
i_configParser |
configuration parser object |
in |
i_commandName |
name of the command |
in |
i_funPtr |
callback function pointer to be invoked |
out |
o_errorMsg |
error message to be returned |
Returns:
-
TRUE, if success
-
FALSE, if failure
[Field][Field]void common::CCommand::SetCommandCallbackFlag (bool i_bValue)
This function sets the value of m_bIgnoreInitialCommandCallback flag( this flag is used to ignore first call to command callback functions when agent starts)
Parameters:
in |
i_bValue |
is the value to be assigned to m_bIgnoreInitialCommandCallback flag |
[Field][Field]bool common::CCommand::UpdateAPIServiceForCommand (CConfigParser & i_configParser, string & o_errorMsg)
This function updates service API for commands.
Parameters:
in |
i_configParser |
configuration parser object |
in |
o_errorMsg |
error message to be returned |
Returns:
-
TRUE, if success
-
FALSE, if failure
COUT Logging
The common library redirects all logs written to cout into a file /tmp/container/587464704/rootfs/tmp/agent/<agentid_hex>/<agentid_hex>_log (on host build, the file would be /tmp/agent/<agentid_hex>/<agentid_hex>_log). When the file reaches a specified limit, it is compressed and timestamped. Logging continues on a new file. If there are a greater number of compressed files than what is specified, the oldest files are removed. The parameters can be configured from the server. This logging can be enabled and disabled from the server through configuration. In order to use this feature, add the values to be printed using “cout<< ”. This will write the values in log file at specified path . This feature is implemented using CoutLogger class.This class implement functions to write cout logs into log file using circular buffer.
Member Function Documentation
[Field][Field]static CoutLogger& CoutLogger::GetCoutLoggerInstance ()[static]
This static function gets CoutLogger instance.
Returns:
instance of CoutLogger
[Field][Field]char* CoutLogger::getDirPath ()[inline]
This function gets path of the directory.
Returns:
directory path
Logging to Server
The common library provides functions to log messages to server. Various log levels are defined. The level above which the logs have to be sent to the server can be configured from the server. The log messages have standard information like timestamp sent automatically. This functionality is implemented using CDataToServer. This class implements function to write data and event messages into database using circular buffer.
Static Public Member Functions
[Field][Field]static CDataToServer* common::CDataToServer::GetDataToServerInstance ()[static]
This static function gets CDataToServer instance.
Returns:
instance of CDataToServer
static void ReleaseDataToServerInstance ()
This function releases DataToServerInstance.
Member Function Documentation
[Field][Field]void common::CDataToServer::SendDataToServer (const char * i_file, uint32_t i_line, const uint32_t & i_featureId, const char * i_Data, const uint32_t & i_DataLength, const uint32_t & i_eventId = 0, const bool & i_sendAsAlarm = 0, const uint64_t & i_TimeStampSec = 0)
This function sends data to store into buffer, which is picked to be send to server.
Parameters:
in |
i_file |
name of the file calling this function |
in |
i_line |
line number of caller |
in |
i_featureId |
feature if |
in |
i_Data |
data to be send to server |
in |
i_DataLength |
length of the data string |
in |
i_eventId |
event id |
in |
i_sendAsAlarm |
send the event as alarm or not? |
in |
i_TimeStampSec |
timestamp needed, if ApiWithTimestamp is used |
Agent Features Start and Stop
Every agent implements a number of features. A set of features from a number of agents together form an Application. When an Application is licensed on the App Store, the required agents are installed on the meter and the required features in them are started. The common library provides the scripts for the DI Agent Monitor to control the features. Also, the reference agent has the stubs for the developers to add code to be executed at the start and stop of the features. It is implemented as common.h class.
Member Function Documentation
[Field][Field]void common::CurrentFeatureList (const uint8_t i_byAllowedNumberOfFeatures, bool o_abPresentStatus[], uint8_t o_abyOrderOfFeature[], const uint32_t i_auiAllowedFeatures[], const string i_astrFeatureName[], const string i_strCmdFilePath, const string i_strStatusFilePath)
This function stores the list which has the information of currently running, started or stopped features with their order of execution.
Parameters:
in |
i_byAllowedNumberOfFeatures |
this is the number of features which are allowed by the daemon |
in |
o_abPresentStatus |
this has the present status of the features, if it has started or stopped |
in |
o_abyOrderOfFeature |
this has the order of features in which they were started |
in |
i_auiAllowedFeatures |
this has the features which are only allowed in this daemon |
in |
i_astrFeatureName |
this has the feature names of the allowed features |
in |
i_strCmdFilePath |
command file path |
in |
i_strStatusFilePath |
status file path |
SDK API Wrappers
The common library provides wrappers to the SDK APIs. These ensure that the multi-threading nuances are taken care of. This is implemented in apiWrapper file. It implements following functions-
Function Documentation
[Field][Field]AgentApiReturnType common::apiAgentLidListGetNext (void * i_LidListHandle, uint32_t * i_lidNumber, ApiVariableType * i_lidValue)
This function gets the next lid value pair in a previously created lid list
Parameters:
i_LidListHandle |
Pointer to a previously created lid list. |
i_lidNumber* |
Pointer to memory that will be filled by the next lid number in the list. |
i_lidValue* |
Pointer to memory that will be filled by the next value in the list. |
Returns:
returns API success or failure accordingly
[Field][Field]AgentApiReturnType common::apiGetData (const uint32_t & i_lidNumber, ApiVariableType * i_lidValue)
This function is api wrapper to retrieve non-periodic LIDs.
Parameters:
in |
i_lidNumber |
lid number whose value to be retrieved |
out |
i_lidValue |
lid value returned |
Returns:
returns API success or failure accordingly
[Field][Field]AgentApiReturnType common::apiLidListResetIteration (void * i_LidListHandle)
This function resets iteration on a lid list. MUST BE USED after lid list is used for other purposes.
Parameters:
i_LidListHandle* |
Pointer to a previously created lid list. |
Returns:
returns API success or failure accordingly
[Field][Field]AgentApiReturnType common::apiLogHistEvt (const uint32_t & i_eventId, const char * i_eventData, const uint32_t & i_eventDataLength, const uint32_t & i_featureId, const bool & i_sendAsAlarm)
This function is api wrapper used by agent to log an event.
Parameters:
in |
i_eventId |
event id |
in |
i_eventData |
Data string to be added |
in |
i_eventDataLength |
length of the data string |
in |
i_featureId |
feature if |
in |
i_sendAsAlarm |
Send the event as alarm or not? |
Returns:
returns API success or failure accordingly
[Field][Field]AgentApiReturnType common::apiLogHistEvtWithTimeStamp (const uint32_t & i_eventId, const char * i_eventData, const uint32_t & i_eventDataLength, const uint32_t & i_featureId, const bool & i_sendAsAlarm, const uint64_t & i_timestamp)
This function is api wrapper used by agent to log an event with timestamp.
Parameters:
in |
i_eventId |
event id |
in |
i_eventData |
Data string to be added |
in |
i_eventDataLength |
length of the data string |
in |
i_featureId |
feature if |
in |
i_sendAsAlarm |
Send the event as alarm or not? |
in |
i_timestamp |
current time stamp to be logged |
Returns:
returns API success or failure accordingly
[Field][Field]AgentApiReturnType common::apiUpstreamForAgentData (const uint32_t & i_featureId, const char * i_data, const uint32_t & i_length)
This function is api wrapper function to write contents into agentdata.
Parameters:
in |
i_featureId |
feature id |
in |
i_data |
Data string to be added |
in |
i_length |
length of the data string |
Returns:
returns API success or failure accordingly
[Field][Field]AgentApiReturnType common::apiWriteAgentDataForUpstreamSystemWithTimestamp (const uint32_t & i_featureId, const char * i_data, const uint32_t & i_length, const uint64_t & i_timestamp)
This function is api wrapper function to write contents into agentdata using timestamp.
Parameters:
in |
i_featureId |
feature id |
in |
i_data |
Data string to be added |
in |
i_length |
length of the data string |
in |
i_timestamp |
current time stamp to be logged |
Returns:
returns API success or failure accordingly
[Field][Field]bool common::CheckAPIErrorStatus (AgentApiReturnType i_APIRetVal)
This function checks API return type error status.
Parameters:
i_APIRetVal |
Return value of an API call |
Returns:
returns false if API success or false if failure accordingly