MCS  0.3.3-alpha7
mcs Namespace Reference

Namespace for MCS library. More...

Classes

class  B64_Codec
 A Base 64 encoder/decoder. More...
 
class  BaseThread
 Base class for MCS threaded objects. More...
 
class  Buffer
 High level buffer. More...
 
class  Client
 Connect to a MCS server as a client. More...
 
class  ClientInfo
 Class holding information about a client connection. More...
 
class  CommandParser
 Parse command lines. More...
 
class  Conf
 Read and write configuration files. More...
 
class  Data
 A general purpose data type. More...
 
class  DateTime
 A class to hold date time information. More...
 
class  DBConn
 Handle database connection. More...
 
class  Dynamic_Array
 A thread safe, template class to handle an array of objects. More...
 
class  Env
 Hold all environment variables. More...
 
class  Event
 Hold informations about an event. More...
 
class  FITSReader
 Read a FITS file. More...
 
class  FITSWriter
 Write a fits file. More...
 
class  HostInfo
 Retrieve informations about a network host. More...
 
class  LocalThread
 Server side administrative thread. More...
 
class  NetInterface
 Retrieve informations about network interfaces. More...
 
class  Pipe
 A high level class to use system pipes. More...
 
class  Query
 Execute queries on the database. More...
 
class  Record
 A dynamic array of Data objects. More...
 
class  RecordSet
 The base class that implement the data abstraction layer. More...
 
class  Serializable
 Serialize memory buffers or files into chunks. More...
 
class  Server
 Main server class for a MCS-based application. More...
 
class  ServerSocket
 Manage TCP server sockets. More...
 
class  Socket
 Manage TCP sockets. More...
 
class  Synchro
 A simple class to implement "critical sections". More...
 
class  Table
 A class to directly set and retrieve value from a database table. More...
 
class  Thread
 A class to create separate threads. More...
 
class  ThreadFunc
 
class  ThreadSpecificData
 
class  UserThread
 The server side client thread. More...
 

Typedefs

typedef enum Types Types
 

Enumerations

enum  BufferFreeOnDestroy { AUTO_FREE, DONT_FREE }
 Values to be used in Buffer class constructor. More...
 
enum  RetValue { OK, WARN, ERROR, FATAL }
 Return value for MCS routines. More...
 
enum  ThrowExceptions { DONT_THROW, THROW }
 Values to be used with throwexc parameters. More...
 
enum  TimeMode { UTC, LOCAL }
 Enumerate operational mode for a DateTime object. More...
 
enum  Types {
  TINY, SMALL, MEDIUM, INT,
  BIGINT, FLOAT, DOUBLE, STRING,
  TIME, TINY_BLOB, BLOB, POINTER
}
 Enumeration of base type for Data. More...
 

Functions

string btos (bool b)
 Convert a boolean to a string containing "true" or "false". More...
 
string chomp (string s)
 Remove any trailing newlines. More...
 
int copy (char *OLDNAME, char *NEWNAME)
 Copy a file from OLDNAME to NEWNAME. More...
 
string dtos (double f)
 Convert an floating point number to a string. More...
 
int extractCode (const char *msg)
 Extract the numeric code from a server reply. More...
 
bool File_Dir_Exist (string fn, unsigned int &size)
 Check if a file or directory exists. More...
 
bool FITS2Types (int fits, Types &dbt, bool &isunsigned)
 Convert a FITSIO type into a MCS type. More...
 
string fitsError (int status)
 Return a description of a FITS error. More...
 
bool FloatType (Types type)
 Tell if "type" is a float type. More...
 
string hexDump (const void *buf, unsigned int size)
 Return a string with an hex dump of the buffer pointed by "buf", with a length of "size". More...
 
bool IntType (Types type)
 Tell if "type" is an integer type. More...
 
string itos (int i)
 Convert an integer to a string. More...
 
void ls2Record (string fn, Record &v)
 Fill a vector with a list of file. More...
 
EnvmcsStart (string appname, string inipath="", Server *(*cb_newServer)(Env *)=NULL)
 Start a MCS server. More...
 
bool mkDir (string path, mode_t perm=0, enum ThrowExceptions throwexc=THROW)
 Create a directory. More...
 
int move (char *OLDNAME, char *NEWNAME)
 Move a file from OLDNAME to NEWNAME. More...
 
time_t my_timelocal (struct tm *tm)
 
string MYSQL2Str (enum_field_types type)
 Return the name of the MySQL type given in "type". More...
 
bool MYSQL2Types (enum_field_types mtype, Types &type)
 Convert a MySQL type into a MCS type. More...
 
string Pwd ()
 Return the current working dir. More...
 
mode_t read_umask ()
 Read the file creation mask of the current process. More...
 
string remLeading (string &s, const char *p)
 Remove any leading character "p". More...
 
string remTabs (string s)
 Remove any tab. More...
 
string remTrailing (string &s, const char *p)
 Remove any trailing character "p". More...
 
bool rmDir (string path, enum ThrowExceptions throwexc=THROW)
 Removes a directory. More...
 
int Select (int fd, unsigned int sec_timeout, unsigned int usec_timeout, int op)
 
int Select (int fd[], int nfd, unsigned int sec_timeout, unsigned int usec_timeout, int op)
 
void sleep_ms (unsigned int millisec)
 A millisecond resolution sleep function. More...
 
vector< string > split (string s, string sep=" ")
 Split a string into tokens. More...
 
int stoi (string s)
 Convert a string to an integer. More...
 
int stoi (string s, int errval)
 Convert a string to an integer. More...
 
string subst (string s, string what, string with, int op=0)
 Perform substitutions on a string. More...
 
string trim (string s)
 Remove any leading or trailing blanks. More...
 
bool Types2FITS (Types dbt, bool isunsigned, int &fits)
 Convert a MCS type into a FITSIO type. More...
 
bool Types2MYSQL (Types &type, enum_field_types &mtype)
 Convert a MCS type into a MySQL type. More...
 
string Types2MYSQLStr (Types &type, bool isunsigned)
 Convert a MCS type into a MySQL type. More...
 
bool Types2S_FITS (Types dbt, int len, bool isunsigned, string &fits)
 Convert a MCS type into a FITSIO type code. More...
 
string Types2Str (Types type, bool isunsigned)
 Return the name of the type given in "type" and "isunsigned". More...
 
bool VarLenType (Types type)
 Tell if "type" is a variable length type. More...
 
string vtos (vector< string > vec)
 Join a vector of strings in a single string using newlines. More...
 

Detailed Description

Namespace for MCS library.

The namespace "mcs" contains all classes, functions and type declarations provided by the mcs library. Those names that cannot be protected inside namespaces, like symbols and macros, has the "MCS_" prefix.

Enumeration Type Documentation

◆ BufferFreeOnDestroy

Values to be used in Buffer class constructor.

Enumerator
AUTO_FREE 

Automatically free allocated buffer.

DONT_FREE 

Don't free allocated buffer.

Definition at line 246 of file mcs.hh.

◆ RetValue

Return value for MCS routines.

This enumeration is often used as a return value for a function or method. It says if the function executed correctly (value OK) or not (values WARN, ERROR, FATAL). This enumeration is also used to specify an event type (see the Event class), which are also used to throw exceptions.

The three values for errors should be used following this rule:

  • WARN a warning, should be used when the error is just an unexpected condition, and the function can do its task as if the error wasn't caught. If such an error occurr during the execution of a batch list of commands, the execution will continue until the end.
  • ERROR an application error, should be used when the function cannot do its task, but the error is due to a wrong call made by the user, or a wrong use of the software. In this case a message should be displayed at the user and the execution of the task should be terminated. This is what happened if the server is executing a list of batch commands.
  • FATAL a system error, should be used hen the function caught an error after a call to a system routine, or if something very wrong happened such a file that was expected to be available and it isn't. In this case the thread who caught the error should terminate.
Enumerator
OK 

No error.

WARN 

Warning.

ERROR 

Application error.

FATAL 

Fatal error.

Definition at line 471 of file mcs.hh.

◆ ThrowExceptions

Values to be used with throwexc parameters.

Enumerator
DONT_THROW 

Don't throw exception.

THROW 

Throw an exception.

Definition at line 257 of file mcs.hh.

◆ TimeMode

Enumerate operational mode for a DateTime object.

Specify if datetime values being read/written into a DateTime object are expressed in UTC or in local time zone.

Definition at line 2833 of file mcs.hh.

◆ Types

enum mcs::Types

Enumeration of base type for Data.

Enumerator
TINY 

1 byte integer

SMALL 

2 bytes integer

MEDIUM 

3 bytes integer

INT 

4 bytes integer

BIGINT 

8 bytes integer

FLOAT 

4 bytes floating point

DOUBLE 

8 bytes floating point

STRING 

Variable length string

TIME 

Date and time information, with second resolution

TINY_BLOB 

Binary data with length < 256

BLOB 

Binary data with length < 65536

Definition at line 54 of file mcs.hh.

Function Documentation

◆ btos()

string mcs::btos ( bool  b)

Convert a boolean to a string containing "true" or "false".

Definition at line 113 of file Utils.cc.

◆ chomp()

string mcs::chomp ( string  s)

Remove any trailing newlines.

Definition at line 166 of file Utils.cc.

◆ copy()

int mcs::copy ( char *  OLDNAME,
char *  NEWNAME 
)

Copy a file from OLDNAME to NEWNAME.

OLDNAME must be an absolute or relative path with a filename.

NEWNAME can be an absolute or relative path with or without a filename (the file will be copied with its original name).

Return 0 if successfull, otherwise return -1. In case of error a message will be printed in stderr.

Definition at line 353 of file Utils.cc.

◆ dtos()

string mcs::dtos ( double  f)

Convert an floating point number to a string.

Definition at line 105 of file Utils.cc.

◆ extractCode()

int mcs::extractCode ( const char *  msg)

Extract the numeric code from a server reply.

Definition at line 26 of file Utils.cc.

◆ File_Dir_Exist()

bool mcs::File_Dir_Exist ( string  fn,
unsigned int &  size 
)

Check if a file or directory exists.

Parameters
fnPath to the filename or directory;
sizeUpon return will contain the size (if "fn" referred to a file);
Returns
True if the file or directory exists, false otherwise.

Definition at line 39 of file Utils.cc.

◆ FITS2Types()

bool mcs::FITS2Types ( int  fits,
Types dbt,
bool &  isunsigned 
)

Convert a FITSIO type into a MCS type.

Convert the FITSIO type "fits" into a MCS type and put the result in the "dbt" and "isunsigned" parameters (which are references). If the conversion is possible will return true, false otherwise.

Definition at line 526 of file Data.cc.

◆ fitsError()

string mcs::fitsError ( int  status)

Return a description of a FITS error.

Definition at line 438 of file Readers.cc.

◆ FloatType()

bool mcs::FloatType ( Types  type)

Tell if "type" is a float type.

Definition at line 379 of file Data.cc.

◆ hexDump()

string mcs::hexDump ( const void *  buf,
unsigned int  size 
)

Return a string with an hex dump of the buffer pointed by "buf", with a length of "size".

Definition at line 211 of file Utils.cc.

◆ IntType()

bool mcs::IntType ( Types  type)

Tell if "type" is an integer type.

Definition at line 364 of file Data.cc.

◆ itos()

string mcs::itos ( int  i)

Convert an integer to a string.

Definition at line 77 of file Utils.cc.

◆ ls2Record()

void mcs::ls2Record ( string  fn,
Record v 
)

Fill a vector with a list of file.

Definition at line 290 of file Utils.cc.

◆ mcsStart()

Env * mcs::mcsStart ( string  appname,
string  inipath = "",
Server *(*)(Env *)  cb_newServer = NULL 
)

Start a MCS server.

This function start a MCS Server (or a derived object) creating the necessary Env object, and eventually catching exceptions. If an exception is raised the message will be written on standard error.

This funtion return the address of an Env object, or NULL if an error occurred. The Env object needs to be destroyed when the program exit.

A typical use of this function is in the main program, you can start a MCS server without derived classses with the following code:

#include <mcs.hh>
using namespace mcs;
Env* env = mcsStart("myApp");

Instead, if you implemented some derived classes, you should change the code as follows:

#include <mcs.hh>
using namespace mcs;
//...derived class implementation.
//Derive the Server class, see relative documentation.
MCS_CUSTOM_SERVER(MyServer, MyClient, MyLocal);
int main(int argc, char* argv[])
{
Env* env = mcsCustomStart("myApp");
}

The mcsCustomStart() function has been implemented by the call to the MCS_CUSTOM_SERVER macro.

Parameters
appnameApplication name, will be passed to the Env constructor.
inipathConfiguration file path, will be passed to the Env constructor.
Returns
Address of the newCustomServer function if defined, users should not use this argument.

Definition at line 113 of file Main.cc.

◆ mkDir()

bool mcs::mkDir ( string  path,
mode_t  perm = 0,
enum ThrowExceptions  throwexc = THROW 
)

Create a directory.

Definition at line 259 of file Utils.cc.

◆ move()

int mcs::move ( char *  OLDNAME,
char *  NEWNAME 
)

Move a file from OLDNAME to NEWNAME.

OLDNAME must be an absolute or relative path with a filename.

NEWNAME can be an absolute or relative path with or without a filename (the file will be copied with its original name). If a relative path wich uses only the "." or ".." paths and without a filename is used then it MUST terminates with a slash "/".

Return 0 if successfull, otherwise return -1. In case of error a message will be printed in stderr.

Definition at line 395 of file Utils.cc.

◆ MYSQL2Str()

string mcs::MYSQL2Str ( enum_field_types  type)

Return the name of the MySQL type given in "type".

Definition at line 393 of file Data.cc.

◆ MYSQL2Types()

bool mcs::MYSQL2Types ( enum_field_types  mtype,
Types type 
)

Convert a MySQL type into a MCS type.

Convert the MySQL type "mtype" into a MCS type and put the result in the "type" parameter (which is a reference). If the conversion is possible will return true, false otherwise.

Definition at line 436 of file Data.cc.

◆ Pwd()

string mcs::Pwd ( )

Return the current working dir.

Definition at line 66 of file Utils.cc.

◆ read_umask()

mode_t mcs::read_umask ( )

Read the file creation mask of the current process.

Definition at line 250 of file Utils.cc.

◆ remLeading()

string mcs::remLeading ( string &  s,
const char *  p 
)

Remove any leading character "p".

Definition at line 178 of file Utils.cc.

◆ remTabs()

string mcs::remTabs ( string  s)

Remove any tab.

Definition at line 172 of file Utils.cc.

◆ remTrailing()

string mcs::remTrailing ( string &  s,
const char *  p 
)

Remove any trailing character "p".

Definition at line 185 of file Utils.cc.

◆ rmDir()

bool mcs::rmDir ( string  path,
enum ThrowExceptions  throwexc = THROW 
)

Removes a directory.

Definition at line 274 of file Utils.cc.

◆ sleep_ms()

void mcs::sleep_ms ( unsigned int  millisec)

A millisecond resolution sleep function.

The libc provides a second and a nanosecond resolution sleep function. This one provides a millisecond resolution, and is probably the most useful.

Definition at line 603 of file Thread.cc.

◆ split()

std::vector< std::string > mcs::split ( string  s,
string  sep = " " 
)

Split a string into tokens.

Return a vector of tokens starting from the string "s" and using "sep" as delimiter. Delimiters won't be included in any token. The "sep" parameter is intended as a regular expression.

Definition at line 192 of file Utils.cc.

◆ stoi() [1/2]

int mcs::stoi ( string  s)

Convert a string to an integer.

Parameters
sThe string containing the number;

If the conversion cannot be performed an exception will be thrown.

Returns
The result of conversion.

Definition at line 85 of file Utils.cc.

◆ stoi() [2/2]

int mcs::stoi ( string  s,
int  errval 
)

Convert a string to an integer.

Parameters
sThe string containing the number;
errvalIf the conversion cannot be performed this parameter will be used as return value.
Returns
The result of conversion or "errval".

Definition at line 95 of file Utils.cc.

◆ subst()

string mcs::subst ( string  s,
string  what,
string  with,
int  op = 0 
)

Perform substitutions on a string.

Substitutes "what" with "with" in the string "s" and return the result. The "what" parameter is intended as a regular expression. The parameter "op" can be one or more of MCS_SUBST_QUOTE_WITH, MCS_SUBST_LEADING, MCS_SUBST_TRAILING.

Definition at line 135 of file Utils.cc.

◆ trim()

string mcs::trim ( string  s)

Remove any leading or trailing blanks.

Definition at line 160 of file Utils.cc.

◆ Types2FITS()

bool mcs::Types2FITS ( Types  dbt,
bool  isunsigned,
int &  fits 
)

Convert a MCS type into a FITSIO type.

Convert the MCS type into a FITSIO type and put the result in the "fits" parameter (which is a reference). If the conversion is possible will return true, false otherwise.

Definition at line 564 of file Data.cc.

◆ Types2MYSQL()

bool mcs::Types2MYSQL ( Types type,
enum_field_types &  mtype 
)

Convert a MCS type into a MySQL type.

Convert the MCS type into a MySQL type and put the result in the "mtype" parameter (which is a reference). If the conversion is possible will return true, false otherwise.

Definition at line 477 of file Data.cc.

◆ Types2MYSQLStr()

string mcs::Types2MYSQLStr ( Types type,
bool  isunsigned 
)

Convert a MCS type into a MySQL type.

Return the name of the full MySQL type given the MCS type (reference) and the "isunsigned" parameters. If the conversion is not possible an empty string will be returned.

Definition at line 509 of file Data.cc.

◆ Types2S_FITS()

bool mcs::Types2S_FITS ( Types  dbt,
int  len,
bool  isunsigned,
string &  fits 
)

Convert a MCS type into a FITSIO type code.

Convert the MCS type into a FITSIO type code and put the result in the "fits" parameter (which is a reference). If the conversion is possible will return true, false otherwise.

Definition at line 603 of file Data.cc.

◆ Types2Str()

string mcs::Types2Str ( Types  type,
bool  isunsigned 
)

Return the name of the type given in "type" and "isunsigned".

Definition at line 313 of file Data.cc.

◆ VarLenType()

bool mcs::VarLenType ( Types  type)

Tell if "type" is a variable length type.

Definition at line 349 of file Data.cc.

◆ vtos()

string mcs::vtos ( vector< string >  vec)

Join a vector of strings in a single string using newlines.

Definition at line 122 of file Utils.cc.


mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018