00001
00002
00003 #ifndef REPOSITORY_
00004 #define REPOSITORY_
00005
00006 #include <list>
00007 #include <map>
00008 #include <string>
00009 #include <pthread.h>
00010 using namespace std;
00011
00013
00014 #define SEC_NUM 27
00015
00016
00018
00026 class repository_class {
00027
00029
00030 struct ltstr {
00031 bool operator()(const string s1, const string s2) const {
00032 return (s1<s2);
00033 }
00034 };
00035
00037
00046 struct location {
00047 int serv_sock;
00048 string serv_ip_address;
00049 int port;
00050 int max_clients;
00051 int cur_clients;
00052 list<int> active_clients;
00053 };
00054
00056
00062 struct file {
00063 list<location*> locations;
00064 int waiting_clients;
00065 pthread_cond_t free;
00066 };
00067
00069
00078 struct section {
00079 map<const string, file*, ltstr> files;
00080 pthread_mutex_t mutex;
00081 };
00082
00084 section archive[SEC_NUM];
00085
00087
00093 int section_number(char c);
00094
00095 public:
00097
00098 repository_class();
00099
00101
00124 void add_file(string file_name, int sock, string ip_address, int port, int max_clients);
00125
00127
00143 int remove_file(string file_name, int sock);
00144
00146
00158 int obtain_file(string file_name, string* ip_address, int* port, int cli_sock);
00159
00161
00191 int release_file(string file_name, int cli_sock);
00192
00194
00201 void wait_file(string file_name);
00202 };
00203
00204 #endif