MCS  0.3.3-alpha7
mcs::BaseThread Class Reference

Base class for MCS threaded objects. More...

#include <mcs.hh>

+ Inheritance diagram for mcs::BaseThread:

Public Member Functions

 BaseThread (const BaseThread &)
 Declared to avoid using of default copy constructor. More...
 
 BaseThread (Thread *parent, int lID)
 Constructor invoked from ClienThread objects. More...
 
 BaseThread (Thread *parent, const char *ltID)
 Constructor invoked from other objects. More...
 
int chkExt (string &s)
 Check if an external program or script is registered in the configuration file. More...
 
BaseThreadoperator= (const BaseThread &)
 Declared to avoid using of default assignment operator. More...
 
const char * tid ()
 Return the thread identifier. More...
 
 ~BaseThread ()
 Destructor. More...
 
- Public Member Functions inherited from mcs::Thread
Eventerror ()
 Return last error message. More...
 
int id ()
 Returns the Thread object identificator. More...
 
Threadparent ()
 Returns the address of the parent. More...
 
void start ()
 Start a new thread in the joinable state. More...
 
void startDetached (bool selfDelete=false)
 Start a new thread in the detached state. More...
 
int state ()
 Return the state of the thread. More...
 
void stop ()
 Stop thread execution. More...
 
 Thread (int id=0, Thread *parent=NULL)
 Declared to avoid using of default copy constructor. More...
 
virtual ~Thread ()
 Destructor. More...
 

Static Public Member Functions

static int fileType (string fn)
 Determine the file type of an external program or script. More...
 
static int spawn (string fn, string pars, string wpath=".", string thrID="x", string user="x", string pass="x", string dbname="x", string fout="out", string ferr="err")
 Execute an external program or script in a dedicated environment. More...
 

Protected Member Functions

RetValue Log (Event e)
 Logging facility. More...
 
- Protected Member Functions inherited from mcs::Thread
virtual void final ()
 Finalization method. More...
 
virtual void initial ()
 Initialization method. More...
 
virtual void notify (int id, Thread *ref)
 A method called from child threads to notify their termination. More...
 
virtual void run ()
 Body of the thread execution. More...
 
void set_cancel_state (bool cancel)
 Set cancellation state for current thread. More...
 
void test_cancel ()
 Test if a cancellation request is pending. More...
 

Static Protected Attributes

static Envenv
 Pointer to the actual Env object, this can be seen in all threaded object. More...
 

Private Attributes

 MCS_DEBUG_ALLOC
 
char tID [4]
 Thread identifier stored as a null terminated string. More...
 

Additional Inherited Members

- Protected Attributes inherited from mcs::Thread
Eventlerror
 Last error. More...
 

Detailed Description

Base class for MCS threaded objects.

This is the basic class for all threaded objects inside MCS. It offers a log facility as well as a static access to a Env object.

Definition at line 6098 of file mcs.hh.

Constructor & Destructor Documentation

◆ BaseThread() [1/3]

mcs::BaseThread::BaseThread ( const BaseThread )

Declared to avoid using of default copy constructor.

Warning
This constructor is declared but not implemented. If you try to use it you will get a compilation error.

◆ BaseThread() [2/3]

mcs::BaseThread::BaseThread ( Thread parent,
int  lID 
)

Constructor invoked from ClienThread objects.

ClienThread objects are identified by a numeric identifier.

Parameters
parentParent thread;
lIDNumeric identifier.

Definition at line 75 of file BaseThread.cc.

◆ BaseThread() [3/3]

mcs::BaseThread::BaseThread ( Thread parent,
const char *  ltID 
)

Constructor invoked from other objects.

The other objects are identified by a mnemonic string identifier.

Parameters
parentParent thread;
ltIDString identifier.

Definition at line 81 of file BaseThread.cc.

◆ ~BaseThread()

mcs::BaseThread::~BaseThread ( )

Destructor.

Definition at line 87 of file BaseThread.cc.

Member Function Documentation

◆ chkExt()

int mcs::BaseThread::chkExt ( string &  s)

Check if an external program or script is registered in the configuration file.

The name (as registered in the configuration file) must be given as parameter. Upon return the parameter will contain the complete path to the real file.

An exception will be thrown if the external program or script is not registered in the configuration file or if the file type (as returned by ()) is fileType MCS_FT_UNKNOWN.

Returns
The value returned by fileType().

Definition at line 140 of file BaseThread.cc.

◆ fileType()

int mcs::BaseThread::fileType ( string  fn)
static

Determine the file type of an external program or script.

This method is used when a user issue a MCS_CMD_EXEC command, to execute an external program or script, to determine the file type. Return value can be one of the following:

  • MCS_FT_UNKNOWN;
  • MCS_FT_BATCH;
  • MCS_FT_SQL;
  • MCS_FT_SCRIPT;
  • MCS_FT_BIN.
Parameters
fnPath to file.
Returns
file type.
Exceptions
ERRORMSG_CANT_OPEN_FILE.

Definition at line 112 of file BaseThread.cc.

◆ Log()

RetValue mcs::BaseThread::Log ( Event  e)
protected

Logging facility.

Parameters
eEvent object containing information about an event.
Returns
The event type (Event.type()).

Definition at line 29 of file BaseThread.cc.

◆ operator=()

BaseThread& mcs::BaseThread::operator= ( const BaseThread )

Declared to avoid using of default assignment operator.

Warning
This operator is declared but not implemented. If you try to use it you will get a compilation error.

◆ spawn()

int mcs::BaseThread::spawn ( string  fn,
string  pars,
string  wpath = ".",
string  thrID = "x",
string  user = "x",
string  pass = "x",
string  dbname = "x",
string  fout = "out",
string  ferr = "err" 
)
static

Execute an external program or script in a dedicated environment.

This routine will create an environment with the following variables, the content of which can be specified via this method's parameters:

  • PWD
  • MCS_CID
  • MCS_USER
  • MCS_PASS
  • MCS_DBNAME

Then the external program or script will be executed in the directory specified in the "wpath" parameter, and its standard output and error will be captured in the files specified in the "fout" and "ferr" parameters.

Scripts will be executed under the "sh" shell. The "wpath", "fout", "ferr" parameters can be either absolute paths or path relative to the current working dir, that is what is returned by mcs::Pwd().

Parameters
fnComplete path to the program or script;
parsArguments to the program or script;
wpathDirectory where the program or script will be executed, also content of the PWD environment variable;
thrIDContent of the MCS_CID environment variable;
userContent of the MCS_USER environment variable;
passContent of the MCS_PASS environment variable;
dbnameContent of the MCS_DBNAME environment variable;
foutPath to the file that will contain the standard output result;
ferrPath to the file that will contain the standard error result;
Returns
The exit code of the program or script;

Definition at line 159 of file BaseThread.cc.

◆ tid()

const char * mcs::BaseThread::tid ( )

Return the thread identifier.

Definition at line 90 of file BaseThread.cc.

Member Data Documentation

◆ env

Env * mcs::BaseThread::env
staticprotected

Pointer to the actual Env object, this can be seen in all threaded object.

Definition at line 6116 of file mcs.hh.

◆ tID

char mcs::BaseThread::tID[4]
private

Thread identifier stored as a null terminated string.

Definition at line 6103 of file mcs.hh.


The documentation for this class was generated from the following files:

mcslogo

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