diff options
author | 2010-08-10 17:22:53 +0300 | |
---|---|---|
committer | 2010-08-10 17:22:53 +0300 | |
commit | 7f6664f049ed6b7674d3613f777710490c44c17c (patch) | |
tree | 2d84fa7bfdd98a8d5b178093e5d474020ed73043 /tuiclient | |
parent | Replace default folders. (diff) | |
download | idfetch-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.
Diffstat (limited to 'tuiclient')
-rw-r--r-- | tuiclient/settings.h | 6 | ||||
-rw-r--r-- | tuiclient/str.cpp | 4 | ||||
-rw-r--r-- | tuiclient/tuiclient.cpp | 70 | ||||
-rw-r--r-- | tuiclient/tuidistfile.cpp | 16 | ||||
-rw-r--r-- | tuiclient/tuidistfile.h | 1 |
5 files changed, 77 insertions, 20 deletions
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; |