#include <repository.h>
Classes | |
struct | file |
a particular file More... | |
struct | location |
location of a file More... | |
struct | ltstr |
comparison operator for standard template library map More... | |
struct | section |
a section in the repository More... | |
Public Member Functions | |
repository_class () | |
constructor | |
void | add_file (string file_name, int sock, string ip_address, int port, int max_clients) |
member function to add a file | |
int | remove_file (string file_name, int sock) |
member function to remove a file | |
int | obtain_file (string file_name, string *ip_address, int *port, int cli_sock) |
member function to obtain location info on a file | |
int | release_file (string file_name, int cli_sock) |
member function to release a previously obtained file | |
void | wait_file (string file_name) |
member function to wait for a particular file to become available | |
Private Member Functions | |
int | section_number (char c) |
produce the index in the archive | |
Private Attributes | |
section | archive [SEC_NUM] |
the real repository is this archive |
this class describes the structure and methods of a repository the repository has the following structure:
Definition at line 26 of file repository.h.
repository_class::repository_class | ( | ) |
void repository_class::add_file | ( | string | file_name, | |
int | sock, | |||
string | ip_address, | |||
int | port, | |||
int | max_clients | |||
) |
member function to add a file
it adds a file to the repository, working as follows:
file_name | | name of the file to add | |
sock | | socket associated to the FS on the DFR | |
ip_address | | ip_address of a FS that holds the file | |
port | | port on which the FS wants to be contacted | |
max_clients | | maximum number of clients for this file on the FS |
Definition at line 20 of file repository.cpp.
References archive, repository_class::repository_class::location::cur_clients, DEB, repository_class::repository_class::section::files, repository_class::repository_class::file::free, repository_class::repository_class::file::locations, repository_class::repository_class::location::max_clients, repository_class::repository_class::location::port, section_number(), repository_class::repository_class::location::serv_ip_address, repository_class::repository_class::location::serv_sock, and repository_class::repository_class::file::waiting_clients.
Referenced by FS_req_s_body().
int repository_class::obtain_file | ( | string | file_name, | |
string * | ip_address, | |||
int * | port, | |||
int | cli_sock | |||
) |
member function to obtain location info on a file
it works as follows:
file_name | | name of the file the CL needs to get | |
ip_address | | pointer to return the ip_address of the FS | |
port | | pointer to return the port on the FS | |
cli_sock | | socket identifying the client on the DFR |
Definition at line 101 of file repository.cpp.
References archive, DEB, repository_class::repository_class::section::files, repository_class::repository_class::file::locations, and section_number().
Referenced by serve_start_file_transfer().
int repository_class::release_file | ( | string | file_name, | |
int | cli_sock | |||
) |
member function to release a previously obtained file
it works as follows:
the condition may be signaled, but we have to signal ALL the threads currently waiting for that condition variable, the reason to do that can be explained with an example:
note that this function returns an error if the client needs to free a file but the File Server has unregistered that file... this is no problem... but the client needs to be prepared to receive an error.
file_name | | name of the file to be released | |
cli_sock | | socket of the client on the DFR |
Definition at line 130 of file repository.cpp.
References archive, DEB, repository_class::repository_class::section::files, repository_class::repository_class::file::free, repository_class::repository_class::file::locations, and section_number().
Referenced by CL_req_s_body(), and serve_end_file_transfer().
int repository_class::remove_file | ( | string | file_name, | |
int | sock | |||
) |
member function to remove a file
it removes a specified file location, as follows:
file_name | | name of the file to remove | |
sock | | socket on the DFR of the FS that holds the file |
Definition at line 68 of file repository.cpp.
References archive, DEB, repository_class::repository_class::section::files, repository_class::repository_class::file::locations, section_number(), and repository_class::repository_class::file::waiting_clients.
Referenced by FS_req_s_body().
int repository_class::section_number | ( | char | c | ) | [private] |
produce the index in the archive
using the first character of the filename, this function produces the index (in the archive array) of the appropriate section
c | | first character of the filename |
Definition at line 12 of file repository.cpp.
References SEC_NUM.
Referenced by add_file(), obtain_file(), release_file(), remove_file(), and wait_file().
void repository_class::wait_file | ( | string | file_name | ) |
member function to wait for a particular file to become available
if a file does not exist yet or if there is no FS slots left for a client, the client can use the wait_file() function to wait for a particular file to become available, FS creating files, or clients releasing files can signal the waiting clients, the awaken clients must test again the condition and block again if necessary
file_name | | name of the file the client wants to be notified about |
Definition at line 161 of file repository.cpp.
References archive, DEB, repository_class::repository_class::section::files, repository_class::repository_class::file::free, repository_class::repository_class::file::locations, repository_class::repository_class::section::mutex, section_number(), and repository_class::repository_class::file::waiting_clients.
Referenced by serve_reg_notification().
section repository_class::archive[SEC_NUM] [private] |
the real repository is this archive
Definition at line 84 of file repository.h.
Referenced by add_file(), obtain_file(), release_file(), remove_file(), repository_class(), and wait_file().