mcs Namespace Reference


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.


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


Enumeration Type Documentation

enum mcs::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 218 of file mcs.hh.

enum mcs::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:

Enumerator:
OK  No error.
WARN  Warning.
ERROR  Application error.
FATAL  Fatal error.

Definition at line 443 of file mcs.hh.

enum mcs::ThrowExceptions

Values to be used with throwexc parameters.

Enumerator:
DONT_THROW  Don't throw exception.
THROW  Throw an exception.

Definition at line 229 of file mcs.hh.

enum mcs::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.

Enumerator:
UTC 
LOCAL 

Definition at line 2848 of file mcs.hh.

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
POINTER 

Definition at line 503 of file mcs.hh.


Function Documentation

string mcs::btos ( bool  b  ) 

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

Definition at line 113 of file Utils.cc.

string mcs::chomp ( string  s  ) 

Remove any trailing newlines.

Definition at line 166 of file Utils.cc.

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.

string mcs::dtos ( double  f  ) 

Convert an floating point number to a string.

Definition at line 105 of file Utils.cc.

int mcs::extractCode ( const char *  msg  ) 

Extract the numeric code from a server reply.

Definition at line 26 of file Utils.cc.

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

Check if a file or directory exists.

Parameters:
fn Path to the filename or directory;
size Upon 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.

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.

string mcs::fitsError ( int  status  ) 

Return a description of a FITS error.

Definition at line 434 of file Readers.cc.

bool mcs::FloatType ( Types  type  ) 

Tell if "type" is a float type.

Definition at line 379 of file Data.cc.

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.

bool mcs::IntType ( Types  type  ) 

Tell if "type" is an integer type.

Definition at line 364 of file Data.cc.

string mcs::itos ( int  i  ) 

Convert an integer to a string.

Definition at line 77 of file Utils.cc.

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

Fill a vector with a list of file.

Definition at line 290 of file Utils.cc.

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:
appname Application name, will be passed to the Env constructor.
inipath Configuration 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.

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

Create a directory.

Definition at line 259 of file Utils.cc.

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.

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.

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.

string mcs::Pwd (  ) 

Return the current working dir.

Definition at line 66 of file Utils.cc.

mode_t mcs::read_umask (  ) 

Read the file creation mask of the current process.

Definition at line 250 of file Utils.cc.

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

Remove any leading character "p".

Definition at line 178 of file Utils.cc.

string mcs::remTabs ( string  s  ) 

Remove any tab.

Definition at line 172 of file Utils.cc.

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

Remove any trailing character "p".

Definition at line 185 of file Utils.cc.

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

Removes a directory.

Definition at line 274 of file Utils.cc.

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 468 of file Thread.cc.

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.

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

Convert a string to an integer.

Parameters:
s The string containing the number;
errval If 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.

int mcs::stoi ( string  s  ) 

Convert a string to an integer.

Parameters:
s The 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.

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.

string mcs::trim ( string  s  ) 

Remove any leading or trailing blanks.

Definition at line 160 of file Utils.cc.

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 562 of file Data.cc.

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.

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.

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 601 of file Data.cc.

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.

bool mcs::VarLenType ( Types  type  ) 

Tell if "type" is a variable length type.

Definition at line 349 of file Data.cc.

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-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012