summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-10 17:22:53 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-10 17:22:53 +0300
commit7f6664f049ed6b7674d3613f777710490c44c17c (patch)
tree2d84fa7bfdd98a8d5b178093e5d474020ed73043
parentReplace default folders. (diff)
downloadidfetch-7f6664f049ed6b7674d3613f777710490c44c17c.tar.gz
idfetch-7f6664f049ed6b7674d3613f777710490c44c17c.tar.bz2
idfetch-7f6664f049ed6b7674d3613f777710490c44c17c.zip
Replace tuiclient argument: --wait-distfile=df_name by --wait-distfiles=df_name1,df_name2,...,df_nameN
Tuiclient waits until all distfiles are downloaded. If at least one of the specified distfiles is not in the queue tuiclient will exit immediately.
-rw-r--r--segget/str.cpp15
-rw-r--r--segget/str.h1
-rw-r--r--segget/ui_server.cpp83
-rw-r--r--tuiclient/settings.h6
-rw-r--r--tuiclient/str.cpp4
-rw-r--r--tuiclient/tuiclient.cpp70
-rw-r--r--tuiclient/tuidistfile.cpp16
-rw-r--r--tuiclient/tuidistfile.h1
8 files changed, 148 insertions, 48 deletions
diff --git a/segget/str.cpp b/segget/str.cpp
index e7b974e..cc7e813 100644
--- a/segget/str.cpp
+++ b/segget/str.cpp
@@ -56,6 +56,21 @@ string toString(double t){
s << t;
return s.str();
}
+
+vector <string> split_to_vector(string splitter, string str){
+ vector <string> parts;
+ uint splitter_pos=str.find(splitter);
+ while (splitter_pos!=str.npos){
+ parts.push_back(str.substr(0,splitter_pos));
+ str=str.substr(splitter_pos+splitter.length());
+ splitter_pos=str.find(splitter);
+ }
+ if (str.length()>0){
+ parts.push_back(str);
+ }
+ return parts;
+}
+
/*
template<typename T> string toString(T t){
stringstream s;
diff --git a/segget/str.h b/segget/str.h
index a118cea..dcb9b13 100644
--- a/segget/str.h
+++ b/segget/str.h
@@ -39,6 +39,7 @@ string trim(std::string const& source, char const* delims = " \t\r\n");
int lower_char(int c);
string noupper(string s);
bool split(string splitter, string str, string &before, string &after);
+vector <string> split_to_vector(string splitter, string str);
string toString(uint t);
string toString(int t);
string toString(ulong t);
diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp
index ba31a12..eaa0f57 100644
--- a/segget/ui_server.cpp
+++ b/segget/ui_server.cpp
@@ -187,57 +187,84 @@ void Tui_server::serve_tuiclient(uint fd, string msg){
string request_str_before,request_str_after;
split("<d>",msg,request_str_before,request_str_after);
split("<.>",request_str_after,request_str_before,request_str_after);
- string distfile_by_name_lookup_request=request_str_before;
- TDFsearch_rusults distfile_search_result=NOT_FOUND;
- if (distfile_by_name_lookup_request.length()>0){
- for (ulong distfile_num=0; distfile_num<request_server_pkg.distfile_count; distfile_num++){
- if (distfile_by_name_lookup_request==request_server_pkg.Pdistfile_list[distfile_num]->name){
- if (request_server_pkg.Pdistfile_list[distfile_num]->get_status()==DDOWNLOADED){
- distfile_search_result=DOWNLOADED;
- }else{
- distfile_search_result=IN_QUEUE;
- }
- break;
- }
- }
- if (distfile_search_result==NOT_FOUND){
- for (ulong distfile_num=0; distfile_num<proxy_fetcher_pkg.distfile_count; distfile_num++){
- if (distfile_by_name_lookup_request==proxy_fetcher_pkg.Pdistfile_list[distfile_num]->name){
- if (proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_status()==DDOWNLOADED){
+ vector <string> wait_distfiles_vector;
+ wait_distfiles_vector=split_to_vector(",", request_str_before);
+ TDFsearch_rusults ALL_distfiles_search_result;
+ if (wait_distfiles_vector.size()<1){
+ // if no distfile specified just wait for the ones in queue
+ ALL_distfiles_search_result=IN_QUEUE;
+ }else{
+ // Let's start from DONWLOADED, and if we find one IN_QUEUE or even NOT_FOUND we'll change it
+ ALL_distfiles_search_result=DOWNLOADED;
+ }
+ for (ulong cur_tuiwaited_distfile=0;cur_tuiwaited_distfile<wait_distfiles_vector.size();cur_tuiwaited_distfile++){
+ debug("Search distfile:"+wait_distfiles_vector[cur_tuiwaited_distfile]);
+// string distfile_by_name_lookup_request=request_str_before;
+ TDFsearch_rusults distfile_search_result=NOT_FOUND;
+ if (wait_distfiles_vector[cur_tuiwaited_distfile].length()>0){
+ for (ulong distfile_num=0; distfile_num<request_server_pkg.distfile_count; distfile_num++){
+ debug("..Name:"+request_server_pkg.Pdistfile_list[distfile_num]->name);
+ if (wait_distfiles_vector[cur_tuiwaited_distfile]==request_server_pkg.Pdistfile_list[distfile_num]->name){
+ if (request_server_pkg.Pdistfile_list[distfile_num]->get_status()==DDOWNLOADED){
distfile_search_result=DOWNLOADED;
+ debug("....downloaded:"+wait_distfiles_vector[cur_tuiwaited_distfile]);
}else{
+ debug("....in queue:"+wait_distfiles_vector[cur_tuiwaited_distfile]);
distfile_search_result=IN_QUEUE;
+ ALL_distfiles_search_result=IN_QUEUE;
}
break;
}
}
+ if (distfile_search_result==NOT_FOUND){
+ for (ulong distfile_num=0; distfile_num<proxy_fetcher_pkg.distfile_count; distfile_num++){
+ if (wait_distfiles_vector[cur_tuiwaited_distfile]==proxy_fetcher_pkg.Pdistfile_list[distfile_num]->name){
+ if (proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_status()==DDOWNLOADED){
+ debug("2....downloaded:"+wait_distfiles_vector[cur_tuiwaited_distfile]);
+ distfile_search_result=DOWNLOADED;
+ }else{
+ debug("2....in queue:"+wait_distfiles_vector[cur_tuiwaited_distfile]);
+ distfile_search_result=IN_QUEUE;
+ ALL_distfiles_search_result=IN_QUEUE;
+ }
+ break;
+ }
+ }
+ }
+ }else{
+ // if no name for distfile specified -> no need to find distfile
+ // just keep an eye on the ones in queue
+ distfile_search_result=IN_QUEUE;
+ }
+ if (distfile_search_result==NOT_FOUND){
+ ALL_distfiles_search_result=NOT_FOUND;
+ break;
}
- }else{
- // if no name for distfile specified -> no need to find distfile
- // just keep an eye on the ones in queue
- distfile_search_result=IN_QUEUE;
}
- switch (distfile_search_result){
+ switch (ALL_distfiles_search_result){
case NOT_FOUND:
- ui_server.send_to_fd(fd, "<m>n<t><.>"); //distfile is not in the list quit
+ send_to_fd(fd, "<m>n<t><.>"); //distfile is not in the list quit
+ error_log_no_msg("Distfile(s) not found");
break;
case DOWNLOADED:
- ui_server.send_to_fd(fd, "<m>N<t><.>"); //distfile is not in the list quit
+ send_to_fd(fd, "<m>N<t><.>"); //distfile is not in the list quit
+ error_log_no_msg("Distfile(s) downloaded");
break;
case IN_QUEUE:
- ui_server.send_to_fd(fd, "<m>y<t><.>"); //distfile is in the list continue
+ error_log_no_msg("Distfile(s) in queue");
+ send_to_fd(fd, "<m>y<t><.>"); //distfile is in the list continue
// Get this info to catch up!
for (uint line_num=0; line_num<=max_published_screenline_num;line_num++){
- ui_server.send_connection_msg_to_fd(fd, line_num, screenlines[line_num]);
+ send_connection_msg_to_fd(fd, line_num, screenlines[line_num]);
debug("Sending to client line:"+toString(line_num)+" "+screenlines[line_num]);
}
debug("Sending to client distfiles_num:"+toString(request_server_pkg.Pdistfile_list.size()));
for (ulong distfile_num=0; distfile_num<request_server_pkg.Pdistfile_list.size(); distfile_num++){
- ui_server.send_distfile_progress_msg_to_fd(fd, request_server_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str());
+ send_distfile_progress_msg_to_fd(fd, request_server_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str());
debug("Sending to client:"+request_server_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str());
}
for (ulong distfile_num=0; distfile_num<proxy_fetcher_pkg.Pdistfile_list.size(); distfile_num++){
- ui_server.send_distfile_progress_msg_to_fd(fd, proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str());
+ send_distfile_progress_msg_to_fd(fd, proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str());
debug("Sending to client:"+proxy_fetcher_pkg.Pdistfile_list[distfile_num]->get_distfile_progress_str());
}
}
diff --git a/tuiclient/settings.h b/tuiclient/settings.h
index 3b1b938..8395156 100644
--- a/tuiclient/settings.h
+++ b/tuiclient/settings.h
@@ -37,7 +37,8 @@ class Tsettings{
private:
public:
// cli arguments
- string arg_wait_distfile;
+ string arg_wait_distfiles;
+ vector <string> wait_distfiles_vector;
//ui_server
string ui_ip;
ulong ui_port;
@@ -49,7 +50,8 @@ class Tsettings{
Tsettings():
// cli arguments
- arg_wait_distfile(""),
+ arg_wait_distfiles(""),
+ wait_distfiles_vector(),
//ui_server
ui_ip("127.0.0.1"),
ui_port(9999),
diff --git a/tuiclient/str.cpp b/tuiclient/str.cpp
index 26afd36..0436778 100644
--- a/tuiclient/str.cpp
+++ b/tuiclient/str.cpp
@@ -51,7 +51,9 @@ vector <string> split_to_vector(string splitter, string str){
str=str.substr(splitter_pos+splitter.length());
splitter_pos=str.find(splitter);
}
- parts.push_back(str);
+ if (str.length()>0){
+ parts.push_back(str);
+ }
return parts;
}
/*
diff --git a/tuiclient/tuiclient.cpp b/tuiclient/tuiclient.cpp
index 28fc8e8..7331321 100644
--- a/tuiclient/tuiclient.cpp
+++ b/tuiclient/tuiclient.cpp
@@ -213,12 +213,39 @@ void decode_downloaded_distfile_msg(string msg_body){
}
*/
+inline void check_for_quit(ulong cur_distfile){
+ if (tuidistfiles[cur_distfile].is_finished()){
+ for (ulong cur_tuiwaited_distfile=0;cur_tuiwaited_distfile<settings.wait_distfiles_vector.size();cur_tuiwaited_distfile++){
+ if (settings.wait_distfiles_vector[cur_tuiwaited_distfile]==tuidistfiles[cur_distfile].name){
+ if (settings.wait_distfiles_vector.size()>1){
+// debug("cur_wait_distfile"+settings.wait_distfiles_vector[cur_tuiwaited_distfile]);
+// debug("wait distfiles num="+toString(settings.wait_distfiles_vector.size()));
+// debug("d0"+settings.wait_distfiles_vector[0]);
+// debug("d1"+settings.wait_distfiles_vector[1]);
+ settings.wait_distfiles_vector.erase(settings.wait_distfiles_vector.begin()+cur_tuiwaited_distfile,settings.wait_distfiles_vector.begin()+cur_tuiwaited_distfile+1);
+// debug("wait distfiles num="+toString(settings.wait_distfiles_vector.size()));
+// debug("d0"+settings.wait_distfiles_vector[0]);
+ }else{
+ quit(0,"All distfiles have been downloaded");
+ }
+ }
+ }
+ }
+}
void decode_downloaded_distfile_msg(string msg_body){
vector <string> parts;
parts=split_to_vector("<>", msg_body);
if (parts.size()>5){
for (ulong cur_distfile=0;cur_distfile<tuidistfiles.size();cur_distfile++){
if (tuidistfiles[cur_distfile].name==parts[0]){
+ // if status changes
+ if (tuidistfiles[cur_distfile].status!=(Tdistfile_status)atoi(parts[1])){
+ tuidistfiles[cur_distfile].status=(Tdistfile_status)atoi(parts[1]);
+ check_for_quit(cur_distfile);
+ }else{
+ tuidistfiles[cur_distfile].status=(Tdistfile_status)atoi(parts[1]);
+ }
+
tuidistfiles[cur_distfile].status=(Tdistfile_status)atoi(parts[1]);
tuidistfiles[cur_distfile].dld_segments=atol(parts[2]);
tuidistfiles[cur_distfile].segments_count=atol(parts[3]);
@@ -228,13 +255,16 @@ void decode_downloaded_distfile_msg(string msg_body){
}
}
Ttuidistfile a_tuidistfile;
- a_tuidistfile.name=parts[0];
- a_tuidistfile.status=(Tdistfile_status)atoi(parts[1]);
- a_tuidistfile.dld_segments=atol(parts[2]);
- a_tuidistfile.segments_count=atol(parts[3]);
- a_tuidistfile.dld_bytes=atol(parts[4]);
- a_tuidistfile.size=atol(parts[5]);
tuidistfiles.push_back(a_tuidistfile);
+ ulong new_distfile=tuidistfiles.size()-1;
+ tuidistfiles[new_distfile].name=parts[0];
+ tuidistfiles[new_distfile].status=(Tdistfile_status)atoi(parts[1]);
+ check_for_quit(new_distfile);
+ tuidistfiles[new_distfile].dld_segments=atol(parts[2]);
+ tuidistfiles[new_distfile].segments_count=atol(parts[3]);
+ tuidistfiles[new_distfile].dld_bytes=atol(parts[4]);
+ tuidistfiles[new_distfile].size=atol(parts[5]);
+ // wont work here
}
}
@@ -256,8 +286,9 @@ int parse_cli_arguments(int argc, char* argv[]){
posEqual=option.find('=');
name = trim(option.substr(0,posEqual));
value = trim(option.substr(posEqual+1));
- if (name=="--wait-distfile"){
- settings.arg_wait_distfile=value;
+ if (name=="--wait-distfiles"){
+ settings.arg_wait_distfiles=value;
+ settings.wait_distfiles_vector=split_to_vector(",", value);
continue;
};
// //f (name=="--pkglist-file") {settings.pkg_list_file=value; continue;};
@@ -275,7 +306,8 @@ void no_curses_msg(string msg){
void exit_curses_and_show_msg(){
try{
- nocbreak();
+// sleep(1);
+// nocbreak();
endwin();
try{
close(sockfd);
@@ -368,18 +400,16 @@ int main(int argc, char* argv[])
debug("connected");
mainwindow.connected();
- if (settings.arg_wait_distfile.length()>999){
- quit(1,"Error in argument --wait-distfile="+settings.arg_wait_distfile+" : Distfile name is too long");
+ if (settings.arg_wait_distfiles.length()>9999){
+ quit(1,"Error in argument --wait-distfile="+settings.arg_wait_distfiles+" : Distfile name is too long");
};
char send_buffer[10000];
- string send_msg="<d>"+settings.arg_wait_distfile+"<.>";
+ string send_msg="<d>"+settings.arg_wait_distfiles+"<.>";
strcpy(send_buffer,send_msg.c_str());
if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)send_msg.length()){
perror("Error in request.cpp: request(): request msg size and sent data size are different.");
}
-
fd_set readfds, testfds;
-
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
testfds = readfds;
@@ -412,12 +442,18 @@ int main(int argc, char* argv[])
Tparts msg_parts;
vector<string> submsgs=split_to_vector("<.>", rest_of_the_msg);
for (ulong submsg_num=0; submsg_num<submsgs.size(); submsg_num++){
+ debug("Submsg: "+submsgs[submsg_num]);
vector<string> before_msg_and_msg=split_to_vector("<m>",submsgs[submsg_num]);
+ debug("Size:"+toString(submsgs.size()));
if (before_msg_and_msg.size()>1){
vector<string> msg_type_and_body=split_to_vector("<t>",before_msg_and_msg[1]);
if (msg_type_and_body.size()>1){
- debug("msg_type="+msg_type_and_body[0]);
debug("msg_body="+msg_type_and_body[1]);
+ }else{
+ debug("No msg_body found");
+ }
+ if (msg_type_and_body.size()>0){
+ debug("msg_type="+msg_type_and_body[0]);
char msg_type=msg_type_and_body[0][0];
// debug("msg_type="+msg_type_str);
switch (msg_type){
@@ -429,10 +465,10 @@ int main(int argc, char* argv[])
case 'y': break; // continue waiting for catchup info
// no distfile in the queue
case 'n':
- quit(1,"Distfile: "+settings.arg_wait_distfile+" is not in the queue - quit");
+ quit(1,"Distfile(s): "+settings.arg_wait_distfiles+" is(are) not in the queue - quit");
break; //shouldn't get to this point - but just in case
case 'N':
- quit(0,"Distfile: "+settings.arg_wait_distfile+" is already downloaded - quit");
+ quit(0,"Distfile(s): "+settings.arg_wait_distfiles+" is(are) already downloaded - quit");
break; //shouldn't get to this point - but just in case
}
}
diff --git a/tuiclient/tuidistfile.cpp b/tuiclient/tuidistfile.cpp
index 5ac5d89..630dc52 100644
--- a/tuiclient/tuidistfile.cpp
+++ b/tuiclient/tuidistfile.cpp
@@ -29,6 +29,22 @@
vector <Ttuidistfile> tuidistfiles;
+bool Ttuidistfile::is_finished(){
+ try{
+ switch(status){
+// case DSCRIPTREJECTED:
+ case DDOWNLOADED:
+ case DFAILED:
+ case DALL_LM_AND_PF_MIRRORS_FAILED:
+ return 1;
+ default: return 0;
+ }
+ }catch(...){
+ error_log("Error: distfile.cpp: statusToString()");
+ }
+ return 0;
+}
+
string Ttuidistfile::statusToString(){
try{
switch(status){
diff --git a/tuiclient/tuidistfile.h b/tuiclient/tuidistfile.h
index 599dd4d..f2a6538 100644
--- a/tuiclient/tuidistfile.h
+++ b/tuiclient/tuidistfile.h
@@ -65,6 +65,7 @@ class Ttuidistfile{
{};
~Ttuidistfile(){};
string statusToString();
+ bool is_finished();
};
extern vector <Ttuidistfile> tuidistfiles;