include/command.h File Reference

#include <string>

Include dependency graph for command.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  command
 common structure of a generic command More...

Defines

#define register_file   1
 Declarations for command related structures.
#define unregister_file   2
 from FS to DFR: server asking for file removal
#define start_file_transfer   3
 from CL to DFR: client asking for file transfer approval
#define end_file_transfer   4
 from CL to DFR: client signaling for file transfer completion
#define reg_notification   5
 from CL to DFR: client asking for notification
#define notify   6
 from DFR to CL: DFR signaling a notification on a file
#define get_file   7
 from CL to FS: client askinf for file transfer
#define OK   11
 command was served correctly
#define ERR_FILE_NOT_REGISTERED   12
 unregister_file command failed due to unregistered file
#define ERR_TOO_MANY_CLIENTS   13
 cannot start the trasfer, too many clients on specified file
#define ERR_FILE_NOT_EXISTS   14
 cannot start file transfer, requested file does not exists
#define ERR_NO_TRANSFER   15
 cannot stop file transfer, no file transfer was previusly requested
#define ERR_NO_NOTIFICATION   16
 no notification was requested
#define ERR_UNKNOWN   17
 unknown error occourred
#define INT_AS_STRING_BYTES   11
 maximum number of characters in a string containing an integer expression (including \0)

Functions

int send_command (int sock, command com, int *rep_data_size, char **rep_data)
 sends a synchronized command
int receive_command (int sock, command *com)
 receives a synchronized command
int reply_command (int sock, int status, int add_bytes, const char *add_data)
 sends a response message to a previously received command
int receive_sft_reply (int sock, int *rep_data_size, char **rep_data)
 receives a response message


Define Documentation

#define end_file_transfer   4

from CL to DFR: client signaling for file transfer completion

Definition at line 29 of file command.h.

Referenced by CL_req_s_body(), and send_end_command().

#define ERR_FILE_NOT_EXISTS   14

cannot start file transfer, requested file does not exists

Definition at line 46 of file command.h.

Referenced by mode_1(), mode_2(), req_server(), serve_start_file_transfer(), and transfer_file().

#define ERR_FILE_NOT_REGISTERED   12

unregister_file command failed due to unregistered file

Definition at line 42 of file command.h.

Referenced by FS_req_s_body().

#define ERR_NO_NOTIFICATION   16

no notification was requested

Definition at line 50 of file command.h.

Referenced by mode_2(), and serve_reg_notification().

#define ERR_NO_TRANSFER   15

cannot stop file transfer, no file transfer was previusly requested

Definition at line 48 of file command.h.

Referenced by send_end_command(), and serve_end_file_transfer().

#define ERR_TOO_MANY_CLIENTS   13

cannot start the trasfer, too many clients on specified file

Definition at line 44 of file command.h.

Referenced by mode_1(), mode_2(), req_server(), serve_start_file_transfer(), and transfer_file().

#define ERR_UNKNOWN   17

unknown error occourred

Definition at line 52 of file command.h.

Referenced by receive_sft_reply(), req_server(), and send_command().

#define get_file   7

from CL to FS: client askinf for file transfer

Definition at line 35 of file command.h.

Referenced by req_server(), and transfer_file().

#define INT_AS_STRING_BYTES   11

maximum number of characters in a string containing an integer expression (including \0)

Definition at line 55 of file command.h.

Referenced by CL_req_s_body(), FS_req_s_body(), main(), mode_1(), mode_2(), reply_command(), req_server(), serve_start_file_transfer(), and command::to_string().

#define notify   6

from DFR to CL: DFR signaling a notification on a file

Definition at line 33 of file command.h.

Referenced by mode_2(), and serve_reg_notification().

#define OK   11

#define reg_notification   5

from CL to DFR: client asking for notification

Definition at line 31 of file command.h.

Referenced by CL_req_s_body(), and mode_2().

#define register_file   1

Declarations for command related structures.

This file contains most of the structures related to commands server and clients can send to the DFR, and the errors that can be sent back to command originator.

notation:

  • FS = File server
  • DFR = Distributed File Repository
  • CL = Client from FS to DFR: server asking for file registration

Definition at line 23 of file command.h.

Referenced by FS_req_s_body(), and main().

#define start_file_transfer   3

from CL to DFR: client asking for file transfer approval

Definition at line 27 of file command.h.

Referenced by CL_req_s_body(), and mode_1().

#define unregister_file   2

from FS to DFR: server asking for file removal

Definition at line 25 of file command.h.

Referenced by FS_req_s_body().


Function Documentation

int receive_command ( int  sock,
command com 
)

receives a synchronized command

friend function (forward declaration)

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
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.

References command::fill_from_string().

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

int receive_sft_reply ( int  sock,
int *  rep_data_size,
char **  rep_data 
)

receives a response message

this function SHOULD be used only by the CLs, when they ask a notification and the DFR finally signals the disponibility of the file to the client, the server sends a notify command to the client. If the client replies to this message with an OK status, the server assumes that a start_file_transfer command has been initiated by the client, this means that the DFR will reply with a start_file_transfer response message. the CL can use this function to catch that response message.

Parameters:
sock | socket on which the CL wants to wait for the response
rep_data | pointer to data to be returned to the client (allocated dynamically)
rep_data_size | pointer to an integer to return the size of the rep_data
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 213 of file command.cpp.

References ERR_UNKNOWN.

Referenced by mode_2().

int reply_command ( int  sock,
int  status,
int  add_bytes,
const char *  add_data 
)

sends a response message to a previously received command

each command needs a response message, allowing the corresponding send_command() call to return to the caller. the reply message is built as follows:

<status_integer|size_of_additional_data|additional_data>

status_integer is one of the following values:

  • OK
  • ERR_FILE_NOT_REGISTERED
  • ERR_TOO_MANY_CLIENTS
  • ERR_FILE_NOT_EXISTS
  • ERR_NO_TRANSFER
  • ERR_NO_NOTIFICATION
  • ERR_UNKNOWN

size_of_additional_data is an integer-as-string field which is the number of bytes in the following field.

additional_data is the data the responder is sending to the commander which has previously sent a command.

Parameters:
sock | socket to send the response message
status | status of the request, as described above
add_bytes | number of bytes to be sent as additional data (0 if no additional data)
add_data | pointer to additional data to be sent (NULL if no additional data)
Returns:
0 if everything is ok, -1 otherwise

Definition at line 178 of file command.cpp.

References INT_AS_STRING_BYTES.

Referenced by FS_req_s_body(), mode_2(), req_server(), serve_end_file_transfer(), serve_reg_notification(), and serve_start_file_transfer().

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

sends a synchronized command

friend function (forward declaration)

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

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.

References ERR_UNKNOWN, and command::to_string().

Referenced by main(), mode_1(), mode_2(), send_end_command(), serve_reg_notification(), and transfer_file().


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