mcs::Client Class Reference

#include <mcs.hh>

Inheritance diagram for mcs::Client:

Inheritance graph
[legend]

List of all members.


Detailed Description

Connect to a MCS server as a client.

This class let you connect to a MCS server as a client, execute command on it, upload and download files and binary data. A typical usage is as follow:

  #include <mcs.hh>
  using namespace mcs;

  ...

  try {
    //Connect to the server.
    Client cli = new Client("", "Host_running_a_MCS_server");

    //Login
    cli->login(user, pass, dbna);

    //Retrieve the Client Identifier
    cli->exec("cid");
    int cid = cli->recv.pop().ival();

    //Query a table in the database
    if (! cli->exec(MCS_CMD_QUERY + string(" SELECT * FROM MyTable")))
    {
      //The server reported an error
      while (cli->msg.ready())
        cout << cli->msg.pop().sval()  << endl;
      exit(1);
    }

    //Retrieve the first record
    cli->exec(MCS_CMD_RECORD + string (" 0"));

    //Use values in field...
    cli->record()[0].ival();
    cli->record().field("MyField").sval();
    //...

    //Create an INTEGER Data object to send to server.
    Data aa(12);
    cli->exec(MCS_CMD_PUTDATA, &aa);

    //Retrieve a Data object from the server.
    cli->exec(MCS_CMD_GETDATA);
    Data bb = cli->recv.pop();

    //Upload a file
    cli->exec(MCS_CMD_PUT + string(" FileToUpload");

    //Download a file
    cli->exec(MCS_CMD_GET + string(" FileToDownload");

    //Close connection
    cli->exec(MSG_BYE);
  }
  catch (Event e) {
    cout << e.msg() << endl;
  }

Definition at line 7562 of file mcs.hh.


Public Member Functions

int chunksize ()
 Return the server side chunk size used to send data across network.
int cid ()
 Return the server side client identificator.
 Client (string path, string server, int port=6523, bool synchro=false, bool SSL=false, unsigned int timeout=10 *60 *1000)
 Constructor.
 Client (const Client &)
 Declared to avoid using of default copy constructor.
virtual void event (int op, Data d, int code=0)
bool exec (string cmd, Data *data=NULL)
 Execute commands on the server.
bool isConnected ()
 Tell if the object is connected to the MCS server.
bool login (string user, string pass, string db="")
 Log in to a MCS server.
Clientoperator= (const Client &)
 Declared to avoid using of default assignment operator.
void writeToFile (int des)
virtual ~Client ()
 Destructor.

Public Attributes

Record aux
 Record containing all auxiliary fields sent by the server.
Record code
 Record containing all reply's numeric codes sent by the server while executing the last command.
Record msg
 Record containing all reply's messages sent by the server while executing the last command.
Record out
 Record containing all output lines (code: MSG_OUT) sent by the server while executing the last command.
Record recv
 Record containing all Data objects sent by the server.

Protected Member Functions

void clearRecords ()
 Clear all records.
bool fetch (unsigned int newpos, bool random)

Protected Attributes

bool connected
 Flag telling if the client is connected or not.
int fileDescriptor
int lchunksize
int lcid
string lpath
 Local path to read/write files.
Recordlrecord
bool writetofile

Constructor & Destructor Documentation

mcs::Client::Client ( const Client  ) 

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.

mcs::Client::Client ( string  path,
string  server,
int  port = 6523,
bool  synchro = false,
bool  SSL = false,
unsigned int  timeout = 10 * 60 * 1000 
)

Constructor.

Parameters:
path Local directory;
server Address of a host running a MCS server;
port Port in which the MCS service is listening;
synchro If all Record objects must be synchronized (useful in multithreading application);
SSL If the TCP connection should be protected with SSL;
timeout Time to wait for server response (in milliseconds).

Definition at line 29 of file Client.cc.

mcs::Client::~Client (  )  [virtual]

Destructor.

Definition at line 63 of file Client.cc.


Member Function Documentation

int mcs::Client::chunksize (  ) 

Return the server side chunk size used to send data across network.

Definition at line 332 of file Client.cc.

int mcs::Client::cid (  ) 

Return the server side client identificator.

Definition at line 329 of file Client.cc.

void mcs::Client::clearRecords (  )  [protected]

Clear all records.

Definition at line 101 of file Client.cc.

bool mcs::Client::exec ( string  cmd,
Data data = NULL 
)

Execute commands on the server.

Parameters:
cmd The command to execute;
Data If the command is MCS_CMD_PUTDATA you should supply an address to a valid Data object;

Definition at line 124 of file Client.cc.

bool mcs::Client::isConnected (  ) 

Tell if the object is connected to the MCS server.

Definition at line 322 of file Client.cc.

bool mcs::Client::login ( string  user,
string  pass,
string  db = "" 
)

Log in to a MCS server.

You must already been connected (see the constructor) to the host before executing this method.

Parameters:
user User name;
pass Password;
db Database name, default is the application name.
Returns:
True if logged in, false otherwise.

Definition at line 76 of file Client.cc.

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

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.


Member Data Documentation

Record mcs::Client::aux

Record containing all auxiliary fields sent by the server.

Definition at line 7628 of file mcs.hh.

Record mcs::Client::code

Record containing all reply's numeric codes sent by the server while executing the last command.

Reimplemented from mcs::RecordSet.

Definition at line 7603 of file mcs.hh.

bool mcs::Client::connected [protected]

Flag telling if the client is connected or not.

Definition at line 7569 of file mcs.hh.

string mcs::Client::lpath [protected]

Local path to read/write files.

Definition at line 7566 of file mcs.hh.

Record mcs::Client::msg

Record containing all reply's messages sent by the server while executing the last command.

Definition at line 7616 of file mcs.hh.

Record mcs::Client::out

Record containing all output lines (code: MSG_OUT) sent by the server while executing the last command.

Definition at line 7622 of file mcs.hh.

Record mcs::Client::recv

Record containing all Data objects sent by the server.

Definition at line 7625 of file mcs.hh.


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

MCS (My Customizable Server) ver. 0.3.3-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012