GlobalBpiLib  1.0
GlobalBpiLib.hpp File Reference
#include "include/json.hpp"
#include <string>
#include <sstream>
#include <vector>
#include <csignal>
#include <chrono>
Include dependency graph for GlobalBpiLib.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  BpiOutStream
 Custom bpi printer class. More...
 
class  DebugOutStream
 Custom debug printer class. More...
 
class  Configuration
 Interface between the application and a local stored json file. More...
 
class  Timer
 Simple timer with µs precision. More...
 

Macros

#define STAMPLENGTH   6
 
#define GEN_BUFFERSIZE   4096
 
#define DLE   "\x10"
 
#define ST_UDP   1
 
#define ST_RAW   0
 
#define SOCKETTYPE   ST_RAW
 

Functions

void bpiSetName (std::string name)
 
std::string bpiGetName ()
 
bool registerChild (int pid)
 
bool deregisterChild (int pid)
 
std::vector< int > getAllChilds ()
 
void sigtermHandler (int signum)
 
void bpiSystemCall (std::string cmd, int(*printFct)(std::string)=nullptr, int(*printErrFct)(std::string)=nullptr)
 
void bpiSystemCall2 (std::string cmd, int(*printFct)(std::string)=nullptr, int(*printErrFct)(std::string)=nullptr, std::string cmdId="")
 
std::string bpiTimestamp ()
 
std::vector< std::string > bpiSplitIntoItems (std::string str, char delimiter)
 
std::string bpiGetNamestamp (std::string name)
 
std::string bpiGetNamestampErr (std::string name)
 
std::string bpiConfirm (std::string command, std::string optional)
 
bool readInputFromStdin (std::string *s, int bufsize=BUFSIZ)
 
int readFromFileDescriptor (int fileDescriptor, std::string &data, int buffersize)
 
int writeToFileDescriptor (int fileDescriptor, std::string data)
 
std::string createCtrlMessage (int argc,...)
 
std::string createStatCtrlMessage (int argc,...)
 
std::string macToString (int len, char *mac)
 
double getCurrentCpuUsage ()
 

Detailed Description

Provides a number of general functions and classes for different use cases, which should be needed in all implementations relating the BananaNetworkTower Project. This class needs obligatory the counterpart header LocalBpiLib.h, containing the following definitions

  • NAMESTAMP

Macro Definition Documentation

◆ STAMPLENGTH

#define STAMPLENGTH   6

Length of Namestamps.

Function Documentation

◆ bpiConfirm()

std::string bpiConfirm ( std::string  command,
std::string  optional 
)

Creates a confirmation for the specified command.

◆ bpiGetNamestamp()

std::string bpiGetNamestamp ( std::string  name)

Creates a namestamp depending on the specified parameter.

◆ bpiGetNamestampErr()

std::string bpiGetNamestampErr ( std::string  name)

Creates a namestamp depending on the specified parameter.

◆ bpiSetName()

void bpiSetName ( std::string  name)

Overwrites the name placeholder string bpiName.

◆ bpiSplitIntoItems()

std::vector<std::string> bpiSplitIntoItems ( std::string  str,
char  delimiter 
)

Splits string into a vector of items.

◆ bpiSystemCall()

void bpiSystemCall ( std::string  cmd,
int(*)(std::string)  printFct,
int(*)(std::string)  printErrFct 
)

Performs a sequential system call. Optional pointer to printer functions may be specified as parameter.

Invokes a system call. The programm waits until the system call is finished and prints to stdout and stderr.

Parameters
cmdCommand to be executed by the system
printFctPointer to a printer function
printErrFctPointer to an error printer function

◆ bpiSystemCall2()

void bpiSystemCall2 ( std::string  cmd,
int(*)(std::string)  printFct,
int(*)(std::string)  printErrFct,
std::string  cmdId 
)

Performs a concurrent system call. Optional pointer to printer functions may be specified as parameter.

Invokes a system call. The call runs concurrently to the application and prints to stdout and stderr.

Parameters
cmdCommand to be executed by the system
printFctPointer to a printer function
printErrFctPointer to an error printer function
Here is the call graph for this function:

◆ bpiTimestamp()

std::string bpiTimestamp ( )

Creates a timestamp.

Here is the call graph for this function:

◆ createCtrlMessage()

std::string createCtrlMessage ( int  argc,
  ... 
)

Creates a control message.

Creates a control message, consisting of argc many char* strings , separated each by a semicolon. The result is enclosed by the control character DLE. A control message may not contain any line breaks.

Parameters
argcNumber of arguments in the argumentvector
Returns
Control message

◆ createStatCtrlMessage()

std::string createStatCtrlMessage ( int  argc,
  ... 
)

Creates a control message.

Creates a control message, consisting of argc many char* strings , separated each by a semicolon. The result is enclosed by the control character DLE. A control message may not contain any line breaks.

Parameters
argcNumber of arguments in the argumentvector
Returns
Control message

◆ deregisterChild()

bool deregisterChild ( int  pid)

Deregisters a forked child by removing its pid from the vector childs.

◆ getAllChilds()

std::vector<int> getAllChilds ( )

Returns the complete vector of all forked child processes.

◆ readFromFileDescriptor()

int readFromFileDescriptor ( int  fileDescriptor,
std::string &  data,
int  buffersize 
)

Reads data from a file descriptor.

◆ registerChild()

bool registerChild ( int  pid)

Registers a new forked child by appending its pid to the vector childs.

◆ sigtermHandler()

void sigtermHandler ( int  signum)

A handler for the signal SIGTERM. All forked processes in childs will be killed first by sending SIGTERM to them.

◆ writeToFileDescriptor()

int writeToFileDescriptor ( int  fileDescriptor,
std::string  data 
)

Writes data to a file descriptor.