28 #define PIDFILE "mcs.pid" 56 cout <<
"\nYYYYMMDD HHMMSS thr MESSAGE" << endl;
58 "-------- ------ --- " <<
59 "------------------------------------------------------------" <<
82 Log(
MCS_OK( MSG_THREAD_DESTROY,
"Server" ));
94 Log(
MCS_OK( MSG_THREAD_CREATE,
"Server" ));
99 throw MCS_FATAL(MSG_ERROR,
"max_users <= 0");
125 ofstream of(PIDFILE, ios::out);
126 pid_t pid = getpid();
172 if (ref ==
env->local) {
219 if (i>=0 && i<env->max_users)
void(* cb_newClient)(int i)
Pointer to a void callback function, called by hk_newClient().
void(* cbwa_log)()
Pointer to a void callback function without arguments, called by hk_log().
void newClient(int newsock)
Search for a free identifier and creates a new UserThread object.
void killClient(int i)
Kill client with specified identifier.
RetValue Log(Event e)
Logging facility.
void(* cb_log)(UserThread *p, Event e)
Pointer to a callback function, called by hk_log().
int id()
Returns the Thread object identificator.
void killAllClients()
Kills all UserThread and the LocalThread objects.
Base class for MCS threaded objects.
Data & lastCommand()
Last command executed.
virtual void notify(int id, Thread *ref)
A method called from child threads to notify their termination.
void(* cbwa_postexec)()
Pointer to a void callback function without arguments, called by hk_postexec().
int port
Server port number.
void start()
Start a new thread in the joinable state.
void stop()
Stop thread execution.
The server side client thread.
UserThread ** pClient
Array of pointers to UserThread objects.
void(* cbwa_exec)()
Pointer to a void callback function without arguments, called by hk_exec().
Hold informations about an event.
virtual void hk_newClient(int i)
Virtual method called when a new user connects to the server.
static Env * env
Pointer to the actual Env object, this can be seen in all threaded object.
A dynamic array of Data objects.
int find_free_id()
Search for a free client identifier when a new client tries to connect. See Env.max_users.
Data & timeLastCommand()
Time at which the last command was executed.
string path
Main server path (APPD).
bool acceptConnection(int &newsock, unsigned int millisec)
Wait for an incoming connection.
The base class that implement the data abstraction layer.
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
int max_users
How many clients can be connected at the same time.
Data & operator[](string name)
Data & timeConnetcted()
Time at which the client connected.
Data & commandExecuted()
Number of commands executed.
void * ssl_ctx
Pointer to the global SSL context object, used if cl_use_ssl is true.
Data & hostname()
Hostname of client.
bool cl_restartlocal
Resart local thread when it dies.
RetValue type()
Return the event type.
bool cl_createlocal
Create local thread.
Server(const Server &)
Declared to avoid using of default copy constructor.
RecordSet * getAll_ClientInfo()
Return a RecordSet object containing informations about all clients connections.
void run()
Server thread body.
virtual LocalThread * newLocalThread()
Wrapper around LocalThread constructors.
string ipaddress(int index=-1)
Return the IP address of an interface.
Data & logged()
True if the client has logged in.
RetValue(* cb_auth)(int &, bool &)
Pointer to a callback function, called by hk_auth().
bool cl_local_kills_mcs
When the local thread dies the server will be stopped.
void notify(int id, Thread *ref)
Called when a child thread terminate, used to free resources.
void insert(Record *rec)
Insert a new record in the set.
Server side administrative thread.
string interface
Server interface name.
Main include file for all MCS based applications.
bool cl_logstdout
Copy log on stdout.
void addField(Data *d)
Wrapper around Dynamic_Array.push.
Data & username()
User name.
A general purpose data type.
void set_cancel_state(bool cancel)
Set cancellation state for current thread.
RetValue(* cb_connect)()
Pointer to a callback function, called by hk_connect().
#define MCS_OK(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
Hold all environment variables.
Data & id()
Client ID, the same as the one returned with the MCS_CMD_CID command.
A class to create separate threads.
bool cl_use_ssl
Use secure connections.
string sslpriv
Path to the SSL private key file, used if cl_use_ssl = 1.
#define MCS_BANNER
MCS banner.
virtual UserThread * newUserThread(int lID, int newsock)
Wrapper around UserThread constructors.
#define MCS_FATAL(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
RetValue(* cb_exec)(CommandParser *, bool &_executed)
Pointer to a callback function, called by hk_exec().
void(* cbwa_auth)()
Pointer to a void callback function without arguments, called by hk_auth().
string sslcert
Path to the SSL certificate file, used if cl_use_ssl = 1.
void(* cb_disconnect)()
Pointer to a callback function, called by hk_disconnect().
void(* cb_postexec)(CommandParser *, RetValue)
Pointer to a callback function, called by hk_postexec().
Manage TCP server sockets.
Data & ipaddress()
IP address of client.
Namespace for MCS library.
void(* cbwa_connect)()
Pointer to a void callback function without arguments, called by hk_connect().