summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-03 02:26:47 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-03 02:26:47 +0300
commita6e670966225d22234a0700e8d49773b30e5dc2e (patch)
treecfedf01667a97089d64a3b5c365e61b78a9960cf
parentAdd [scripting_and_scheduling] section to segget.conf file. (diff)
downloadidfetch-a6e670966225d22234a0700e8d49773b30e5dc2e.tar.gz
idfetch-a6e670966225d22234a0700e8d49773b30e5dc2e.tar.bz2
idfetch-a6e670966225d22234a0700e8d49773b30e5dc2e.zip
Add distfiles window to tuiclient.
Distfiles window shows progress on distfile downloads.
-rw-r--r--segget/connection.cpp7
-rw-r--r--segget/distfile.cpp6
-rw-r--r--segget/distfile.h2
-rw-r--r--segget/pkg.cpp3
-rw-r--r--segget/requestserver.cpp22
-rw-r--r--segget/segget.cpp6
-rw-r--r--segget/ui_server.cpp41
-rw-r--r--segget/ui_server.h5
-rw-r--r--tuiclient/colors.cpp38
-rw-r--r--tuiclient/colors.h11
-rw-r--r--tuiclient/distfilewindow.cpp58
-rw-r--r--tuiclient/distfilewindow.h40
-rw-r--r--tuiclient/helpwindow.h2
-rw-r--r--tuiclient/mainwindow.cpp38
-rw-r--r--tuiclient/mainwindow.h8
-rw-r--r--tuiclient/scrollwindow.cpp8
-rw-r--r--tuiclient/str.cpp45
-rw-r--r--tuiclient/str.h13
-rw-r--r--tuiclient/tuiclient.cpp88
-rw-r--r--tuiclient/tuiclient.h13
-rw-r--r--tuiclient/tuidistfile.cpp31
-rw-r--r--tuiclient/tuidistfile.h55
-rw-r--r--tuiclient/twindow.cpp8
-rw-r--r--tuiclient/twindow.h3
24 files changed, 449 insertions, 102 deletions
diff --git a/segget/connection.cpp b/segget/connection.cpp
index 2f8399c..274d9ca 100644
--- a/segget/connection.cpp
+++ b/segget/connection.cpp
@@ -45,7 +45,6 @@ int Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegme
total_dld_bytes=0;
bytes_per_last_interval=0;
gettimeofday(&start_time,NULL);
- active=true;
debug("Connecting network"+toString(network_num));
segment->parent_distfile->active_connections_num++;
@@ -76,7 +75,7 @@ int Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegme
if (run_user_python_script(connection_num)){
return REJECTED_BY_USER_PYTHON_SCRIPT;
}
-
+ active=true;
debug("aaaaa");
Pcurr_mirror->start();
debug("bbbbb");
@@ -153,7 +152,7 @@ void Tconnection::stop(CURLcode connection_result){
Pcurr_mirror=find_mirror(strip_mirror_name(segment->url));
}
*/
-
+ debug("before gettimeofday");
timeval now_time;
gettimeofday(&now_time,NULL);
@@ -161,7 +160,9 @@ void Tconnection::stop(CURLcode connection_result){
switch (network_array[network_num].network_mode){
case MODE_LOCAL:{
// prnt_distfile->network_distfile_brokers_array[network_num].mirror_fails_vector[mirror_num]=true;
+ debug("before setting mirror fail");
segment->parent_distfile->network_distfile_brokers_array[network_num].local_mirror_failed(mirror_num);
+ debug("after setting mirror fail");
// find_mirror(strip_mirror_name(segment->url));
break;
}
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index 4f56bbe..d8f8eda 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -209,6 +209,7 @@ bool Tdistfile::check_if_dld(){
bool Tdistfile::load_distfile_from_json(json_object* json_obj_distfile){
try{
+ debug("Entered distfile.cpp: load_distfile_from_json()");
json_object* json_obj_buffer;
json_obj_buffer=json_object_object_get(json_obj_distfile,"name");
if (json_obj_buffer){
@@ -664,8 +665,11 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){
void Tdistfile::inc_dld_segments_count(Tsegment* current_segment){
try{
stats.inc_dld_size(current_segment->segment_size);
- if (++dld_segments_count==segments_count)
+ dld_bytes+=current_segment->segment_size;
+ ui_server.send_distfile_progress_msg_to_all_clients(name+" "+toString(dld_segments_count)+" "+toString(segments_count)+" "+toString(dld_bytes)+" "+toString(size));
+ if (++dld_segments_count==segments_count){
combine_segments();
+ }
stats.dld_segments_count++;
}catch(...){
error_log("Error: distfile.cpp: inc_dld_segments_count()");
diff --git a/segget/distfile.h b/segget/distfile.h
index 69f20c7..ebf2b4a 100644
--- a/segget/distfile.h
+++ b/segget/distfile.h
@@ -95,6 +95,7 @@ class Tdistfile{
bool choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num);
public:
uint dld_segments_count;
+ ulong dld_bytes;
Tnetwork_distfile_broker network_distfile_brokers_array[MAX_NETWORKS];
string json_data;
// bool downloaded;
@@ -119,6 +120,7 @@ class Tdistfile{
uint segment_size;
Tdistfile():
dld_segments_count(0),
+ dld_bytes(0),
json_data(""),
// downloaded(0),
status(DNEW),
diff --git a/segget/pkg.cpp b/segget/pkg.cpp
index e3a0a41..20cf0c0 100644
--- a/segget/pkg.cpp
+++ b/segget/pkg.cpp
@@ -38,13 +38,14 @@ Tpkg request_server_pkg;
int Tpkg::push_back_distfile(json_object* json_obj_distfile){
try{
- distfile_count++;
Tdistfile * Pcur_distfile=new Tdistfile();
if (Pcur_distfile->load_distfile_from_json(json_obj_distfile)){
error_log("Error in pkg.cpp: push_back_distfile(): while loading distfile");
return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
}else{
+ debug("pkg.cpp: push_back_distfile(): json import ok - pushback distfile");
Pdistfile_list.push_back(Pcur_distfile);
+ distfile_count++;
return R_PF_ADDED_TO_PROXY_QUEUE;
}
}catch(...){
diff --git a/segget/requestserver.cpp b/segget/requestserver.cpp
index fd1111f..7fd76d3 100644
--- a/segget/requestserver.cpp
+++ b/segget/requestserver.cpp
@@ -61,13 +61,13 @@ void *run_request_server(void * ){
int nread;
testfds = readfds;
- debug("proxyfether is waiting for connections");
+ debug("requestserver is waiting for connections");
result = select(FD_SETSIZE, &testfds, (fd_set *)0, (fd_set *)0, (struct timeval *) 0);
// debug("proxyfether done waiting");
if(result < 1) {
- error_log("Error in proxyfetcher.cpp : run");
+ error_log("Error in requestserver.cpp : run");
exit(1);
}
@@ -78,12 +78,12 @@ void *run_request_server(void * ){
//If the activity is on server_sockfd, it must be a request for a new connection, and you add the associated client_sockfd to the descriptor set:
if(fd == server_sockfd) {
- debug("new client - read");
+ debug("requestserver: new client - read");
client_len = sizeof(client_address);
client_sockfd = accept(server_sockfd,
(struct sockaddr *)&client_address, &client_len);
FD_SET(client_sockfd, &readfds);
- debug("adding client on fd:"+toString(client_sockfd));
+ debug("requestserver: adding client on fd:"+toString(client_sockfd));
//If it isn’t the server, it must be client activity. If close is received, the client has gone away, and you remove it from the descriptor set. Otherwise, you “serve” the client as in the previous examples.
}else{
@@ -92,27 +92,32 @@ void *run_request_server(void * ){
if(nread == 0) {
close(fd);
FD_CLR(fd, &readfds);
- debug("removing client on fd:"+toString(fd));
+ debug("requestserver: removing client on fd:"+toString(fd));
}else{
char buffer[100000]="";
if (nread!=read(fd, &buffer, nread)){
- error_log("Error in proxyfetcher.cpp : run_proxy_fetcher_server(): Not all data has been read from proxy-fetcher-client");
+ error_log("Error in requestserver.cpp : run_request_server(): Not all data has been read from proxy-fetcher-client");
}
// debug("serving client - read");
// debug("serving client on fd"+toString(fd));
string recv_msg=buffer;
// error_log("Received a msg from the client:"+recv_msg);
// char send_buffer[10]="";
+ debug("trying to add distfile via requestserver");
json_object* json_obj_distfile=json_tokener_parse(buffer);
string distfile_name=json_object_get_string(json_object_object_get(json_obj_distfile,"name"));
int result=proxy_fetcher_pkg.find_distfile(distfile_name);
+ debug("search for distfile ended");
switch (result){
case R_PF_NOT_REQUESTED_YET:
case R_PF_ERROR_ADDING_TO_PROXY_QUEUE: // if error - try with request_server
{
+ debug("Search in proxy_fetcher distfiles list");
result=proxy_fetcher_pkg.find_distfile(distfile_name);
+ debug("ENDED search in proxy_fetcher distfiles list");
switch (result){
case R_PF_NOT_REQUESTED_YET:{
+ debug("push_back distfile to the queue");
result=request_server_pkg.push_back_distfile(json_obj_distfile);
break;
}
@@ -122,10 +127,11 @@ void *run_request_server(void * ){
}
default: break;
}
+ debug("Ended trying to add distfile");
string send_response=toString(result);
// if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)msg.length()){
if (write(fd, send_response.c_str(), send_response.length())!=(int)send_response.length()){
- error_log("Error in proxyfetcher.cpp: run_proxy_fetcher_server(): response msg size and sent data size are different.");
+ error_log("Error in requestserver.cpp: run_request_server(): response msg size and sent data size are different.");
};
}
}
@@ -133,7 +139,7 @@ void *run_request_server(void * ){
}
}
}catch(...){
- error_log("Error in proxyfetcher.cpp: run_proxy_fetcher_server()");
+ error_log("Error in requestserver.cpp: run_request_server()");
return (void*)1;
}
}
diff --git a/segget/segget.cpp b/segget/segget.cpp
index 7160c60..6a0d1c4 100644
--- a/segget/segget.cpp
+++ b/segget/segget.cpp
@@ -100,8 +100,10 @@ int pkg_choose_segment(Tpkg * cur_pkg, uint connection_num){
try{
uint distfile_num(0);
uint segment_num(0);
+ debug("Entered pkg_choose_segment()");
while(distfile_num<cur_pkg->distfile_count){
// if (Ppkg_array[pkg_num]->distfile_vector[distfile_num].allows_new_actions()){
+ debug("considering distfile:"+toString(distfile_num));
if (cur_pkg->Pdistfile_list[distfile_num]->allows_new_actions()){
debug("segment_num:"+toString(segment_num));
debug("segment_count:"+toString(cur_pkg->Pdistfile_list[distfile_num]->segments_count));
@@ -140,15 +142,18 @@ int pkg_choose_segment(Tpkg * cur_pkg, uint connection_num){
int choose_segment(uint connection_num){
try{
+ debug("Entered choose_segment()");
// for (uint pkg_num=0; pkg_num<stats.pkg_count; pkg_num++){
// debug("pkg_num:"+toString(pkg_num));
// if (0==pkg_choose_segment(Ppkg_array[pkg_num], connection_num)){
// return 0;
// }
// }
+
if (0==pkg_choose_segment(&request_server_pkg, connection_num)){
return 0;
}
+ debug("choose_segment() goes for proxy-fetcher distfiles");
// download distfiles as a proxy-fetcher
if (0==pkg_choose_segment(&proxy_fetcher_pkg, connection_num)){
return 0;
@@ -217,6 +222,7 @@ int download_pkgs(){
};
debug("Exit connection activation sycle");
}
+ debug("After attempt to start connection activation cycle");
U=stats.active_connections_counter;
debug("before multi_perform");
// while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(cm, &U)){};
diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp
index dd68330..29eb5f4 100644
--- a/segget/ui_server.cpp
+++ b/segget/ui_server.cpp
@@ -61,24 +61,8 @@ void Tui_server::init(){
FD_SET(server_sockfd, &readfds);
send_to_fd_busy=false;
}
-//prevent simultaneous writes
-string Tui_server::encode_connection_msg(uint y, string msg){
-// if (send_to_fd_idle) {
- string message="<m>c<t>"+toString(y)+"<y>"+msg+"<.>";
- return message;
-}
-string Tui_server::encode_log_msg(string msg){
-// if (send_to_fd_idle) {
- string message="<m>l<t>"+msg+"<.>";
- return message;
-}
-
-string Tui_server::encode_error_log_msg(string msg){
-// if (send_to_fd_idle) {
- string message="<m>e<t>"+msg+"<.>";
- return message;
-}
+//prevent simultaneous writes
ulong Tui_server::send_to_fd(uint fd, string msg){
// if (send_to_fd_idle) {
@@ -98,21 +82,36 @@ ulong Tui_server::send_to_fd(uint fd, string msg){
return 0;
}
+void Tui_server::send_connection_msg_to_fd(uint fd, uint y, string msg){
+ string message="<m>c<t>"+toString(y)+"<y>"+msg+"<.>";
+ send_to_fd(fd, message);
+}
+
void Tui_server::send_connection_msg_to_all_clients(uint y, string msg){
+ string message="<m>c<t>"+toString(y)+"<y>"+msg+"<.>";
for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){
- send_to_fd(fd, encode_connection_msg(y, msg));
+ send_to_fd(fd, message);
}
}
void Tui_server::send_log_msg_to_all_clients(string msg){
+ string message="<m>l<t>"+msg+"<.>";
for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){
- send_to_fd(fd, encode_log_msg(msg));
+ send_to_fd(fd, message);
}
}
void Tui_server::send_error_log_msg_to_all_clients(string msg){
+ string message="<m>e<t>"+msg+"<.>";
+ for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){
+ send_to_fd(fd, message);
+ }
+}
+
+void Tui_server::send_distfile_progress_msg_to_all_clients(string msg){
+ string message="<m>d<t>"+msg+"<.>";
for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){
- send_to_fd(fd, encode_error_log_msg(msg));
+ send_to_fd(fd, message);
}
}
@@ -151,7 +150,7 @@ void *run_ui_server(void * ){
// Get this info to catch up!
for (uint line_num=0; line_num<=max_published_screenline_num;line_num++){
- ui_server.send_to_fd(client_sockfd, ui_server.encode_connection_msg(line_num, screenlines[line_num]));
+ ui_server.send_connection_msg_to_fd(client_sockfd, line_num, screenlines[line_num]);
debug_no_msg("Sending to client line:"+toString(line_num)+" "+screenlines[line_num]);
// ui_server.send(line_num,screenlines[line_num]);
}
diff --git a/segget/ui_server.h b/segget/ui_server.h
index db67e13..21dbc9e 100644
--- a/segget/ui_server.h
+++ b/segget/ui_server.h
@@ -53,13 +53,12 @@ class Tui_server{
uint max_fd_num;
fd_set readfds, testfds;
void init();
- string encode_connection_msg(uint y, string msg);
- string encode_log_msg(string msg);
- string encode_error_log_msg(string msg);
ulong send_to_fd(uint fd, string msg);
+ void send_connection_msg_to_fd(uint fd, uint y, string msg);
void send_connection_msg_to_all_clients(uint y, string msg);
void send_log_msg_to_all_clients(string msg);
void send_error_log_msg_to_all_clients(string msg);
+ void send_distfile_progress_msg_to_all_clients(string msg);
};
extern Tui_server ui_server;
diff --git a/tuiclient/colors.cpp b/tuiclient/colors.cpp
index 4e0ef4a..0b1959d 100644
--- a/tuiclient/colors.cpp
+++ b/tuiclient/colors.cpp
@@ -26,24 +26,43 @@
#include "colors.h"
-void color_downloads(){
+void color_default_window(WINDOW * window){
if(has_colors()){
start_color(); /* Start color */
- attron(COLOR_PAIR(1));
+ wbkgd(window, COLOR_PAIR(4));
+ wattron(window, COLOR_PAIR(4));
}
}
-void color_info(){
+void color_scroll_window(WINDOW * window){
if(has_colors()){
start_color(); /* Start color */
- attron(COLOR_PAIR(2));
+ wbkgd(window, COLOR_PAIR(5));
+ wattron(window, COLOR_PAIR(5));
}
}
-void color_status(){
+void color_downloads(WINDOW * window){
if(has_colors()){
start_color(); /* Start color */
- attron(COLOR_PAIR(3));
+// wbkgd(window, COLOR_PAIR(1));
+ wattron(window, COLOR_PAIR(1));
+ }
+}
+
+void color_info(WINDOW * window){
+ if(has_colors()){
+ start_color(); /* Start color */
+// wbkgd(window, COLOR_PAIR(2));
+ wattron(window,COLOR_PAIR(2));
+ }
+}
+
+void color_status(WINDOW * window){
+ if(has_colors()){
+ start_color(); /* Start color */
+// wbkgd(window, COLOR_PAIR(3));
+ wattron(window,COLOR_PAIR(3));
}
}
@@ -54,6 +73,9 @@ void colors_connected(){
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_BLACK, COLOR_CYAN);
init_pair(3, COLOR_GREEN, COLOR_BLUE);
+ init_pair(4, COLOR_BLACK, COLOR_GREEN);
+ init_pair(5, COLOR_GREEN, COLOR_BLACK);
+// init_pair(4, COLOR_BLACK, COLOR_WHITE);
// attrset(A_REVERSE);
attrset(A_DIM);
}
@@ -66,7 +88,9 @@ void colors_disconnected(){
init_pair(1, COLOR_BLACK, COLOR_WHITE);
init_pair(2, COLOR_WHITE, COLOR_BLACK);
init_pair(3, COLOR_BLACK, COLOR_RED);
-// attrset(A_BOLD);
+ init_pair(4, COLOR_WHITE, COLOR_BLACK);
+ init_pair(5, COLOR_RED, COLOR_BLACK);
+/// attrset(A_BOLD);
// attrset(A_REVERSE);
}
} \ No newline at end of file
diff --git a/tuiclient/colors.h b/tuiclient/colors.h
index ba3c591..ea77f02 100644
--- a/tuiclient/colors.h
+++ b/tuiclient/colors.h
@@ -10,7 +10,8 @@
* This file is part of Segget.
*
* Segget is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
+* modify it under t color_downloads(window);
+he terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
@@ -29,9 +30,11 @@
#include <ncurses.h>
-void color_downloads();
-void color_info();
-void color_status();
+void color_default_window(WINDOW * window);
+void color_scroll_window(WINDOW * window);
+void color_downloads(WINDOW * window);
+void color_info(WINDOW * window);
+void color_status(WINDOW * window);
void colors_connected();
void colors_disconnected();
#endif \ No newline at end of file
diff --git a/tuiclient/distfilewindow.cpp b/tuiclient/distfilewindow.cpp
new file mode 100644
index 0000000..22c7f49
--- /dev/null
+++ b/tuiclient/distfilewindow.cpp
@@ -0,0 +1,58 @@
+/*
+* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
+*
+* Project: IDFetch.
+* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
+* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
+* Mentoring organization: Gentoo Linux.
+* Sponsored by GSOC 2010.
+*
+* This file is part of Segget.
+*
+* Segget is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* Segget is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Segget; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "distfilewindow.h"
+
+void Tdistfile_window::compose(){
+ color_default_window(window);
+ make_frame();
+// box(window, ACS_VLINE, ACS_HLINE);
+// getmaxyx(window,height,width);
+ bottom_screenline_num=height-2;
+// color_status();
+// msg_status();
+// color_info();
+// for (uint y=bottom_screenline_num,status_line_num=0; y<height-2; y++,status_line_num++){
+// msg_line(y+1,screen_info_lines[status_line_num]);
+// }
+// color_downloads(window);
+// screenlines[26]="Max_num:"+toString(max_received_screenline_num);
+ ulong distfile_num=top_position;
+ for (int y=0; y<bottom_screenline_num and distfile_num<tuidistfiles.size(); y++, distfile_num++){
+ msg_line(y+1,field("",distfile_num+1,4)+") "
+ +"("+toString(tuidistfiles[distfile_num].dld_bytes*100/tuidistfiles[distfile_num].size)+"%) "
+ +tuidistfiles[distfile_num].name
+ +" Segments: "+toString(tuidistfiles[distfile_num].dld_segments)
+ +"/"+toString(tuidistfiles[distfile_num].segments_count)
+ +" Bytes: "+toString(tuidistfiles[distfile_num].dld_bytes)
+ +"/"+toString(tuidistfiles[distfile_num].size));
+ }
+ wrefresh(window);
+// mainwindow.distfiles_win.add_line(parts[0]+"("+toString(atol(parts[3].c_str())*100/)+"%)"+" "+parts[1]+"/"+parts[2]+" "+parts[3]+"/"+parts[4]);
+}
+
+
+
diff --git a/tuiclient/distfilewindow.h b/tuiclient/distfilewindow.h
new file mode 100644
index 0000000..e7e5593
--- /dev/null
+++ b/tuiclient/distfilewindow.h
@@ -0,0 +1,40 @@
+/*
+* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
+*
+* Project: IDFetch.
+* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
+* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
+* Mentoring organization: Gentoo Linux.
+* Sponsored by GSOC 2010.
+*
+* This file is part of Segget.
+*
+* Segget is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* Segget is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Segget; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef _DISTFILEWINDOW_H_
+#define _DISTFILEWINDOW_H_
+
+#include "twindow.h"
+#include "tuidistfile.h"
+
+using namespace std;
+
+class Tdistfile_window: public Twindow{
+ public:
+ void compose();
+};
+
+#endif \ No newline at end of file
diff --git a/tuiclient/helpwindow.h b/tuiclient/helpwindow.h
index 883b586..71826f4 100644
--- a/tuiclient/helpwindow.h
+++ b/tuiclient/helpwindow.h
@@ -26,10 +26,10 @@
#ifndef _HELPWINDOW_H_
#define _HELPWINDOW_H_
-
#include "twindow.h"
using namespace std;
+
class Thelp_window: public Twindow{
public:
// Thelp_window(int height_, int width_, int y_, int x_);
diff --git a/tuiclient/mainwindow.cpp b/tuiclient/mainwindow.cpp
index 6a27022..55a16e7 100644
--- a/tuiclient/mainwindow.cpp
+++ b/tuiclient/mainwindow.cpp
@@ -40,24 +40,24 @@ void Tmainwindow::disconnected(){
set_status("[Connecting... Attempt:"+toString(attempt_num)+". Waiting for 1 sec, before next reconnect.]");
}
void Tmainwindow::msg_status(){
- msg_short(0,width/2-13,"tuiclient to segget daemon");
+ msg_short(0,2,"Tuiclient "+status_str);
+ msg_short(0,width-40,"[h-Help] [q-Quit]");
msg_short(0,width-20,"[Lines:"+toString(top_position+1)+"-"+toString(top_position+1+bottom_screenline_num)+"/"+toString(max_received_screenline_num+1)+"]");
- msg_short(height-1,2,status_str);
- msg_short(height-1,width-18,"[h-Help] [q-Quit]");
+// msg_short(height-1,2,status_str);
+// msg_short(height-1,width-18,"");
}
void Tmainwindow::compose(){
//clear();
box(window, ACS_VLINE, ACS_HLINE);
getmaxyx(window,height,width);
- bottom_screenline_num=height-3;
- color_status();
+ screenlines[27]=sms;
+ bottom_screenline_num=height-2;
+ color_status(window);
msg_status();
- color_info();
- for (uint y=bottom_screenline_num,status_line_num=0; y<height-2; y++,status_line_num++){
- msg_line(y+1,screen_info_lines[status_line_num]);
- }
- color_downloads();
+ color_info(window);
+ msg_short(height-1,2,screen_info_lines[0]);
+ color_downloads(window);
// screenlines[26]="Max_num:"+toString(max_received_screenline_num);
for (int y=0, line_num=top_position; y<bottom_screenline_num; y++, line_num++){
msg_line(y+1,screenlines[line_num]);
@@ -65,14 +65,19 @@ void Tmainwindow::compose(){
wrefresh(window);
//and show children
if (log_win.visible && error_log_win.visible){
- int modd = (height-3)%4;
- log_win.resize((height-3)/4+modd, width, 1+(height-3)/4*2, 0);
- error_log_win.resize((height-3)/4, width, 1+(height-3)/4*3+modd, 0);
+ int modd = (height-2)%4;
+ log_win.resize((height-2)/4+modd, width, 1+(height-2)/4*2, 0);
+ error_log_win.resize((height-2)/4, width, 1+(height-2)/4*3+modd, 0);
}else{
- int modd = (height-3)%2;
- log_win.resize((height-3)/2+modd, width, 1+(height-3)/2, 0);
- error_log_win.resize((height-3)/2+modd, width, 1+(height-3)/2, 0);
+ int modd = (height-2)%2;
+ log_win.resize((height-2)/2+modd, width, 1+(height-2)/2, 0);
+ error_log_win.resize((height-2)/2+modd, width, 1+(height-2)/2, 0);
}
+ int modd = (height-2)%2;
+ distfiles_win.resize((height-3)/2+modd, width, 1+(height-3)/2, 0);
+
+ distfiles_win.show();
+
log_win.show();
error_log_win.show();
@@ -113,6 +118,7 @@ void Tmainwindow::init(){
notfresh=TRUE;
help_win.init(" HELP ",14,31,5,5);
log_win.init(" LOG ",12,50,5,5);
+ distfiles_win.init(" DISTFILES ",12,50,5,5);
error_log_win.init(" ERROR LOG ",12,50,5,5);
}
diff --git a/tuiclient/mainwindow.h b/tuiclient/mainwindow.h
index cff1c75..0c80c30 100644
--- a/tuiclient/mainwindow.h
+++ b/tuiclient/mainwindow.h
@@ -29,13 +29,13 @@
#include <ncurses.h>
#include <sys/types.h>
-
-using namespace std;
-
#include "twindow.h"
#include "helpwindow.h"
+#include "distfilewindow.h"
#include "scrollwindow.h"
+using namespace std;
+
const uint CONNECTION_LINES=5;
const uint MAX_LINES=200;
@@ -45,6 +45,7 @@ class Tmainwindow: public Twindow{
Thelp_window help_win;
Tscroll_window log_win;
Tscroll_window error_log_win;
+ Tdistfile_window distfiles_win;
bool exit_flag;
bool connected_status;
string screenlines[200];
@@ -54,6 +55,7 @@ class Tmainwindow: public Twindow{
help_win(),
log_win(),
error_log_win(),
+ distfiles_win(),
exit_flag(FALSE),
connected_status(FALSE),
attempt_num(0)
diff --git a/tuiclient/scrollwindow.cpp b/tuiclient/scrollwindow.cpp
index 6e7354c..cdfafad 100644
--- a/tuiclient/scrollwindow.cpp
+++ b/tuiclient/scrollwindow.cpp
@@ -31,10 +31,11 @@
void Tscroll_window::compose(){
// msg_text=msg_text+" ";
//
- make_frame();
getmaxyx(window,height,width);
- bottom_screenline_num=height-1;
- color_downloads();
+ bottom_screenline_num=height-2;
+ color_scroll_window(window);
+ make_frame();
+ color_downloads(window);
// screenlines[26]="Max_num:"+toString(max_received_screenline_num);
top_position=scroll_lines.size()-height+2; // +2 for border lines
if (top_position<0) {top_position=0;};
@@ -47,6 +48,7 @@ void Tscroll_window::compose(){
void Tscroll_window::add_line(string line){
+ max_received_screenline_num=scroll_lines.size();
scroll_lines.push_back(line);
if (scroll_lines.size()>SCROLL_LINES_MAX_NUM){
scroll_lines.erase(scroll_lines.begin(),scroll_lines.begin()+scroll_lines.size()-SCROLL_LINES_MAX_NUM);
diff --git a/tuiclient/str.cpp b/tuiclient/str.cpp
index cfc4fb9..f831331 100644
--- a/tuiclient/str.cpp
+++ b/tuiclient/str.cpp
@@ -27,6 +27,35 @@
#include "str.h"
using namespace std;
+int atoi(string num_str){
+ return atoi(num_str.c_str());
+}
+
+long atol(string num_str){
+ return atol(num_str.c_str());
+}
+
+
+Tparts split(string splitter, string str){
+ Tparts result;
+ int splitter_pos=str.find(splitter);
+ result.before=str.substr(0,splitter_pos);
+ result.after=str.substr(splitter_pos+splitter.length());
+ return result;
+}
+
+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);
+ }
+ parts.push_back(str);
+ return parts;
+}
+
template<typename T> string toString(T t){
stringstream s;
s << t;
@@ -82,4 +111,18 @@ string trim(std::string const& source, char const* delims) {
error_log("Error in str.cpp: trim()");
return "";
}
-} \ No newline at end of file
+}
+
+string field(string prefix,ulong t, int width){
+ try{
+ stringstream s1,s2;
+ s1 << t;
+ width=width+prefix.length();
+ s2.width(width);
+ s2 << prefix+s1.str();
+ return s2.str();
+ }catch(...){
+ error_log("Error in str.cpp: field()");
+ return "";
+ }
+}
diff --git a/tuiclient/str.h b/tuiclient/str.h
index ef77aab..ab1ba71 100644
--- a/tuiclient/str.h
+++ b/tuiclient/str.h
@@ -29,13 +29,26 @@
#include <string>
#include <sstream>
#include <algorithm>
+#include <vector>
#include "log.h"
using namespace std;
+class Tparts{
+ public:
+ string before, after;
+ Tparts():
+ before(""),
+ after("")
+ {};
+};
+
template<typename T> string toString(T t);
+Tparts split(string splitter, string str);
+vector <string> split_to_vector(string splitter, string str);
string trim(std::string const& source, char const* delims = " \t\r\n");
int lower_char(int c);
string noupper(string s);
+string field(string prefix,ulong t, int width);
#endif \ No newline at end of file
diff --git a/tuiclient/tuiclient.cpp b/tuiclient/tuiclient.cpp
index 69531ca..e8ac7b6 100644
--- a/tuiclient/tuiclient.cpp
+++ b/tuiclient/tuiclient.cpp
@@ -47,27 +47,61 @@ void quit(){
//error while ending curses
}
}
+Twindow * next_window(){
+ cur_window_num++;
+ if (cur_window_num>3) cur_window_num=0;
+ switch (cur_window_num){
+ case 0:
+ mainwindow.log_win.visible=false;
+ mainwindow.error_log_win.visible=false;
+ mainwindow.distfiles_win.visible=false;
+ return &mainwindow;
+ case 1:
+ mainwindow.log_win.visible=true;
+ mainwindow.error_log_win.visible=false;
+ mainwindow.distfiles_win.visible=false;
+ return &mainwindow.log_win;
+ case 2:
+ mainwindow.log_win.visible=false;
+ mainwindow.error_log_win.visible=true;
+ mainwindow.distfiles_win.visible=false;
+ return &mainwindow.error_log_win;
+ case 3:
+ mainwindow.log_win.visible=false;
+ mainwindow.error_log_win.visible=false;
+ mainwindow.distfiles_win.visible=true;
+ return &mainwindow.distfiles_win;
+ }
+ return &mainwindow;
+}
+
void * watch_keyboard_thread_function(void *){
+ Twindow * cur_window=&mainwindow.distfiles_win;
while (true){
char key=getch();
switch (key){
+ //tab - move between windows
+ case (char)9:cur_window=next_window();
//KEY_DOWN
- case (char)2:mainwindow.down(1);break;
+ case (char)2:cur_window->down(1);mainwindow.screenlines[25]=toString((int)key);break;
//KEY_RIGHT
- case (char)5:mainwindow.down(1);break;
+ case (char)5:cur_window->down(1);mainwindow.screenlines[25]=toString((int)key);break;
//KEY_UP
- case (char)3:mainwindow.up(1);break;
+ case (char)3:cur_window->up(1);mainwindow.screenlines[25]=toString((int)key);break;
//KEY_LEFT
- case (char)4:mainwindow.up(1);break;
+ case (char)4:cur_window->up(1);mainwindow.screenlines[25]=toString((int)key);break;
//KEY_PG_DOWN
- case (char)82:mainwindow.down(mainwindow.bottom_screenline_num);break;
+ case (char)82:cur_window->down(mainwindow.bottom_screenline_num);break;
//KEY_PG_UP
- case (char)83:mainwindow.up(mainwindow.bottom_screenline_num);break;
- case 'u':
- case 'U':mainwindow.up(1);break;
+ case (char)83:cur_window->up(mainwindow.bottom_screenline_num);break;
case 'd':
- case 'D':mainwindow.down(1);break;
+ case 'D':mainwindow.distfiles_win.toggle();
+ mainwindow.log_win.visible=false;
+ mainwindow.error_log_win.visible=false;
+ cur_window=&mainwindow.distfiles_win;
+ mainwindow.show();
+ break;
case 'q':
case 'Q':quit();break;
case 'h':
@@ -76,7 +110,7 @@ void * watch_keyboard_thread_function(void *){
case 'L':mainwindow.log_win.toggle(); mainwindow.show();break;
case 'e':
case 'E':mainwindow.error_log_win.toggle(); mainwindow.show();break;
-// default: screenlines[25]=toString((int)key);
+ default: mainwindow.screenlines[25]=toString((int)key);
}
}
return 0;
@@ -93,15 +127,6 @@ void * refresh_screen_thread_function(void *){
return 0;
}
-
-Tparts split(string splitter, string str){
- Tparts result;
- int splitter_pos=str.find(splitter);
- result.before=str.substr(0,splitter_pos);
- result.after=str.substr(splitter_pos+splitter.length());
- return result;
-}
-
void decode_connection_msg(string msg_body){
Tparts parts=split("<y>",msg_body);
int line_num=atoi(parts.before.c_str());
@@ -114,6 +139,30 @@ void decode_connection_msg(string msg_body){
}
}
+void decode_downloaded_distfile_msg(string msg_body){
+ vector <string> parts;
+ parts=split_to_vector(" ", msg_body);
+ if (parts.size()>4){
+ for (ulong cur_distfile=0;cur_distfile<tuidistfiles.size();cur_distfile++){
+ if (tuidistfiles[cur_distfile].name==parts[0]){
+ tuidistfiles[cur_distfile].dld_segments=atol(parts[1]);
+ tuidistfiles[cur_distfile].segments_count=atol(parts[2]);
+ tuidistfiles[cur_distfile].dld_bytes=atol(parts[3]);
+ tuidistfiles[cur_distfile].size=atol(parts[4]);
+ return;
+ }
+ }
+ Ttuidistfile a_tuidistfile;
+ a_tuidistfile.name=parts[0];
+ a_tuidistfile.dld_segments=atol(parts[1]);
+ a_tuidistfile.segments_count=atol(parts[2]);
+ a_tuidistfile.dld_bytes=atol(parts[3]);
+ a_tuidistfile.size=atol(parts[4]);
+ tuidistfiles.push_back(a_tuidistfile);
+ mainwindow.distfiles_win.max_received_screenline_num=tuidistfiles.size();
+ }
+}
+
void decode_log_msg(string msg_body){
mainwindow.log_win.add_line(msg_body);
}
@@ -223,6 +272,7 @@ int main()
case 'c': decode_connection_msg(msg_parts.before); break;
case 'l': decode_log_msg(msg_parts.before);break;
case 'e': decode_error_log_msg(msg_parts.before);break;
+ case 'd': decode_downloaded_distfile_msg(msg_parts.before);break;
}
}
};
diff --git a/tuiclient/tuiclient.h b/tuiclient/tuiclient.h
index ad7cdac..cf1223c 100644
--- a/tuiclient/tuiclient.h
+++ b/tuiclient/tuiclient.h
@@ -45,6 +45,8 @@
#include "config.cpp"
#include "log.cpp"
#include "settings.cpp"
+#include "tuidistfile.cpp"
+#include "distfilewindow.cpp"
#define BUFFER_SIZE 2000
@@ -55,18 +57,9 @@
using namespace std;
-class Tparts{
- public:
- string before, after;
- Tparts():
- before(""),
- after("")
- {};
-};
-
-
Tmainwindow mainwindow;
+int cur_window_num=0;
int sockfd;
void quit();
void * watch_keyboard_thread_function(void * ptr);
diff --git a/tuiclient/tuidistfile.cpp b/tuiclient/tuidistfile.cpp
new file mode 100644
index 0000000..09bd414
--- /dev/null
+++ b/tuiclient/tuidistfile.cpp
@@ -0,0 +1,31 @@
+ /*
+* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
+*
+* Project: IDFetch.
+* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
+* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
+* Mentoring organization: Gentoo Linux.
+* Sponsored by GSOC 2010.
+*
+* This file is part of Segget.
+*
+* Segget is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* Segget is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Segget; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "tuidistfile.h"
+
+
+
+
diff --git a/tuiclient/tuidistfile.h b/tuiclient/tuidistfile.h
new file mode 100644
index 0000000..fa857b8
--- /dev/null
+++ b/tuiclient/tuidistfile.h
@@ -0,0 +1,55 @@
+ /*
+* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
+*
+* Project: IDFetch.
+* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
+* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
+* Mentoring organization: Gentoo Linux.
+* Sponsored by GSOC 2010.
+*
+* This file is part of Segget.
+*
+* Segget is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* Segget is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Segget; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef __TUIDISTFILE_H__
+#define __TUIDISTFILE_H__
+#include <string>
+#include <vector>
+
+using namespace std;
+
+class Ttuidistfile{
+ public:
+ string name;
+ ulong size;
+ ulong dld_bytes;
+ ulong dld_segments;
+ ulong segments_count;
+ Ttuidistfile():
+ name(""),
+ size(0),
+ dld_bytes(0),
+ dld_segments(0),
+ segments_count(0)
+ {};
+ ~Ttuidistfile(){};
+};
+
+vector <Ttuidistfile> tuidistfiles;
+//vector <string> tuidistfiles;
+//string tuidistfiles;
+
+#endif
diff --git a/tuiclient/twindow.cpp b/tuiclient/twindow.cpp
index e4ee2f7..d451435 100644
--- a/tuiclient/twindow.cpp
+++ b/tuiclient/twindow.cpp
@@ -26,6 +26,8 @@
#include "twindow.h"
+string sms;
+
void Twindow::init(string caption_, int height_, int width_, int y_, int x_){
caption=caption_;
height=height_;
@@ -67,6 +69,8 @@ void Twindow::up(int inc){
}else{
top_position=tmp_top_position;
}
+ sms="UP"+toString(top_position);
+
}
void Twindow::down(uint inc){
int tmp_top_position=top_position+inc;
@@ -80,6 +84,7 @@ void Twindow::down(uint inc){
top_position=tmp_top_position;
}
}
+ sms="DOWN "+toString(top_position)+"------>"+toString(bottom_screenline_num);
}
void Twindow::center(uint max_y, uint max_x){
@@ -101,9 +106,10 @@ void Twindow::make_frame(){
wclear(window);
box(window, ACS_VLINE, ACS_HLINE);
mvwaddstr(window,0,(width-caption.length())/2,caption.c_str());
+ msg_short(0,width-20,"[Lines:"+toString(top_position+1)+"-"+toString(top_position+bottom_screenline_num)+"/"+toString(max_received_screenline_num)+"]");
+ msg_short(height-1,width-27,"[Up/Dn/PgUp/PgDn - scroll]");
}
-
void Twindow::refresh(){
if (notfresh){
show();
diff --git a/tuiclient/twindow.h b/tuiclient/twindow.h
index aa84214..89c5108 100644
--- a/tuiclient/twindow.h
+++ b/tuiclient/twindow.h
@@ -30,6 +30,7 @@
#include <ncurses.h>
#include <sys/types.h>
#include "colors.h"
+//#include "tuiclient.h"
using namespace std;
@@ -78,4 +79,6 @@ class Twindow{
void show();
virtual void compose(){};
};
+
+extern string sms;
#endif \ No newline at end of file