#include <command.h>
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) |
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.
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.
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
s | | string to be parsed to build the command |
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
Definition at line 26 of file command.cpp.
References file_name, INT_AS_STRING_BYTES, max_clients, and port.
Referenced by send_command().
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
sock | | socket from which to receive the command | |
com | | command object to be filled for the caller |
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
the response data will be one of the following, depending on the command:
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 |
Definition at line 112 of file command.cpp.
string command::file_name |
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().
int command::id |
identifies the command type
values are defined here:
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().
int command::port |
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().