command Class Reference

common structure of a generic command More...

#include <command.h>

List of all members.

Public Member Functions

 command ()
 null constructor
 command (int id, const char *file_name, int max_clients=0, int port=0)
 initialization constructor
char * to_string ()
 translates the command in a string
int fill_from_string (const char *s)
 fills the class members using a string

Public Attributes

int id
 identifies the command type
string file_name
 file on which the command needs to be executed
int max_clients
 max number of clients on a particular file
int port
 port on which the file is reachable

Friends

int send_command (int sock, command com, int *rep_data_size, char **rep_data)
 friend function (forward declaration)
int receive_command (int sock, command *com)
 friend function (forward declaration)


Detailed Description

common structure of a generic command

i have built a single class for any command type, possible commands are the following:

to each of them has been associated an int value through a macro as shown in this file.

Definition at line 72 of file command.h.


Constructor & Destructor Documentation

command::command (  ) 

null constructor

it makes yust some null initialization

Definition at line 10 of file command.cpp.

References file_name, max_clients, and port.

command::command ( int  id,
const char *  file_name,
int  max_clients = 0,
int  port = 0 
)

initialization constructor

using this type of constructor the user can set the 4 memer fields of the command object

Definition at line 17 of file command.cpp.


Member Function Documentation

int command::fill_from_string ( const char *  s  ) 

fills the class members using a string

parsing the string s, this function assigns values to each member of the command class, we assume that the string passed as parameter s is a string built using the to_string() function, as previously described. if this is not the case, the fill_from_string() method will recognise the unvalid string and return an error value

Parameters:
s | string to be parsed to build the command
Returns:
-1 on error, 0 if everything is ok

Definition at line 51 of file command.cpp.

References file_name, max_clients, and port.

Referenced by receive_command().

char * command::to_string (  ) 

translates the command in a string

commands need to be transmitted on the network, this functions builds a string containing the information to reconstruct the command structure again at delivery. the built string has the following structure:

<id|max_clients|port|file_name>

if no max_clients or port need to be defined the values will be 0, those are integers presented as strings

Returns:
string result of convertion (dynamically allocated)

Definition at line 26 of file command.cpp.

References file_name, INT_AS_STRING_BYTES, max_clients, and port.

Referenced by send_command().


Friends And Related Function Documentation

int receive_command ( int  sock,
command com 
) [friend]

friend function (forward declaration)

receive_command() is declared friend to allow use of fill_from_string() private member function

See also:
receive_command()
this function receives a singular command from a channel which must have been previously initialized. It will not return until a command is received, or an error occours. received parameters are saved in the command object pointed by com.

Parameters:
sock | socket from which to receive the command
com | command object to be filled for the caller
Returns:
0 if everything is ok, -1 otherwise

Definition at line 161 of file command.cpp.

int send_command ( int  sock,
command  com,
int *  rep_data_size,
char **  rep_data 
) [friend]

friend function (forward declaration)

send_command() is declared friend to allow use of to_string() private member function

See also:
send_command()
this function sends a command to a remote server or client, the connection must be previously established. It will not return until some data are received in response on the socket, this means a state message and eventually some data.

the response data will be one of the following, depending on the command:

  • register_file -> no data (NULL)
  • unregister_file -> no data (NULL)
  • start_file_transfer -> information on how to contact the associated FS
  • end_file_transfer -> no data (NULL)
  • reg_notification -> no data (NULL)
  • notify -> no data (NULL)
  • get_file -> transferred file

Parameters:
sock | socket to contact the opposite end of the channel
com | command to be sent
rep_data | pointer to data to be returned to the caller (allocated dynamically)
rep_data_size | pointer to an integer to return the size of the rep_data, if any
Returns:
a state code from the following list
See also:
OK

ERR_FILE_NOT_REGISTERED

ERR_TOO_MANY_CLIENTS

ERR_FILE_NOT_EXISTS

ERR_NO_TRANSFER

ERR_NO_NOTIFICATION

ERR_UNKNOWN

Definition at line 112 of file command.cpp.


Member Data Documentation

file on which the command needs to be executed

each command has a file_name parameter, this field will be set in any valid command

Definition at line 90 of file command.h.

Referenced by CL_req_s_body(), command(), fill_from_string(), FS_req_s_body(), req_server(), and to_string().

identifies the command type

values are defined here:

See also:
register_file

unregister_file

start_file_transfer

end_file_transfer

reg_notification

notify

get_file

Definition at line 84 of file command.h.

Referenced by CL_req_s_body(), FS_req_s_body(), and req_server().

max number of clients on a particular file

this field will be set only in case of register_file command

Definition at line 95 of file command.h.

Referenced by command(), fill_from_string(), FS_req_s_body(), and to_string().

port on which the file is reachable

this field will be set only in case of register_file command

Definition at line 100 of file command.h.

Referenced by command(), fill_from_string(), FS_req_s_body(), and to_string().


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

Generated on Sat Jun 13 21:06:30 2009 for DistributedFileRepository by  doxygen 1.5.8