summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-27 02:02:00 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-27 02:02:00 +0300
commit67845f83986e67f204bbc51d93d6ca1a1e7796ab (patch)
tree8d82d6ce4b978b577396f9e3d17a5a9fc609d30e
parentAdd command line option --pkglist-file to request application (diff)
downloadidfetch-67845f83986e67f204bbc51d93d6ca1a1e7796ab.tar.gz
idfetch-67845f83986e67f204bbc51d93d6ca1a1e7796ab.tar.bz2
idfetch-67845f83986e67f204bbc51d93d6ca1a1e7796ab.zip
Add log and error_log windows to tuiclient
-rw-r--r--segget/connection.cpp6
-rw-r--r--segget/distfile.cpp3
-rw-r--r--segget/log.cpp4
-rw-r--r--segget/proxyfetcher.cpp2
-rw-r--r--segget/requestserver.cpp2
-rw-r--r--segget/tui.cpp47
-rw-r--r--segget/tui.h17
-rw-r--r--segget/ui_server.cpp45
-rw-r--r--segget/ui_server.h17
-rw-r--r--tuiclient/helpwindow.cpp13
-rw-r--r--tuiclient/mainwindow.cpp21
-rw-r--r--tuiclient/mainwindow.h5
-rw-r--r--tuiclient/scrollwindow.cpp54
-rw-r--r--tuiclient/scrollwindow.h49
-rw-r--r--tuiclient/tuiclient.cpp76
-rw-r--r--tuiclient/tuiclient.h11
-rw-r--r--tuiclient/twindow.cpp19
-rw-r--r--tuiclient/twindow.h6
18 files changed, 325 insertions, 72 deletions
diff --git a/segget/connection.cpp b/segget/connection.cpp
index 5dec26a..a9d438e 100644
--- a/segget/connection.cpp
+++ b/segget/connection.cpp
@@ -92,9 +92,9 @@ void Tconnection::stop(CURLcode connection_result){
debug("Finished connection for distfile: "+segment->parent_distfile->name+" Segment#:"+toString(segment->segment_num)+" Network#"+toString(network_num)+" Status: "+toString(connection_result));
if (connection_result){
string error_str=curl_easy_strerror(connection_result);
- debug(" ERROR "+toString(connection_result)+": "+error_str);
+ debug(" ERROR "+toString(connection_result)+": "+error_str);
error_log("Finished connection for distfile: "+segment->parent_distfile->name+" Segment#:"+toString(segment->segment_num)+" Network#"+toString(network_num)+" Status: "+toString(connection_result));
- error_log(" ERROR "+toString(connection_result)+": "+error_str);
+ error_log(" ERROR "+toString(connection_result)+": "+error_str);
}
msg_clean_connection(connection_num);
@@ -154,7 +154,7 @@ void Tconnection::stop(CURLcode connection_result){
}
}
// error -> start downloading again
- msg_status2(segment->connection_num, toString(connection_result)+"]- Failed download "+segment->file_name);
+// msg_status2(segment->connection_num, toString(connection_result)+"]- Failed download "+segment->file_name);
debug(toString(connection_result)+"]- Failed download "+segment->url);
Pcurr_mirror->stop(time_left_from(connection_array[connection_num].start_time),0);
if (segment->try_num>=settings.max_tries){
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index f3825a1..ba5778d 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -814,7 +814,7 @@ int Tdistfile::combine_segments(){
status=DFAILED;
return 12;
}
-/*
+
if (! sha512_ok(settings.distfiles_dir+"/"+name,SHA512)){
status=DFAILED;
return 13;
@@ -834,7 +834,6 @@ int Tdistfile::combine_segments(){
status=DFAILED;
return 16;
}
- */
status=DDOWNLOADED;
if (settings.provide_mirror_dir!="none"){
symlink_distfile_to_provide_mirror_dir();
diff --git a/segget/log.cpp b/segget/log.cpp
index 7916382..6af0ffa 100644
--- a/segget/log.cpp
+++ b/segget/log.cpp
@@ -54,7 +54,7 @@ void log_no_msg(string log_msg_text){
void log(string log_msg_text){
log_no_msg(log_msg_text);
try{
- msg(LOG_LINE_NUM,0, "LOG:"+log_msg_text);
+ msg_log(log_msg_text);
}catch(...){
error_log("Error in tui.cpp: log()");
}
@@ -111,7 +111,7 @@ void error_log_no_msg(string error_msg_text){
void error_log(string error_msg_text){
error_log_no_msg(error_msg_text);
try{
- msg(ERROR_LINE_NUM,0, "ERROR:"+error_msg_text);
+ msg_error_log(error_msg_text);
}catch(...){
error_log_no_msg("Error in tui.cpp: error_log()");
}
diff --git a/segget/proxyfetcher.cpp b/segget/proxyfetcher.cpp
index 0895729..6f91680 100644
--- a/segget/proxyfetcher.cpp
+++ b/segget/proxyfetcher.cpp
@@ -101,7 +101,7 @@ void *run_proxy_fetcher_server(void * ){
// 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);
+// error_log("Received a msg from the client:"+recv_msg);
string send_response;
// char send_buffer[10]="";
diff --git a/segget/requestserver.cpp b/segget/requestserver.cpp
index 74e214b..de365d2 100644
--- a/segget/requestserver.cpp
+++ b/segget/requestserver.cpp
@@ -101,7 +101,7 @@ void *run_request_server(void * ){
// 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);
+// error_log("Received a msg from the client:"+recv_msg);
// char send_buffer[10]="";
json_object* json_obj_distfile=json_tokener_parse(buffer);
string distfile_name=json_object_get_string(json_object_object_get(json_obj_distfile,"name"));
diff --git a/segget/tui.cpp b/segget/tui.cpp
index 5f4545b..423547a 100644
--- a/segget/tui.cpp
+++ b/segget/tui.cpp
@@ -27,7 +27,11 @@
#include "tui.h"
extern Tsettings settings;
-const uint CONNECTION_LINES=5;
+const uint CONNECTION_LINES=3;
+string screenlines[DEBUG_LINE_NUM+1];
+vector<string> log_lines;
+uint log_lines_counter=0;
+uint max_published_screenline_num;
//bool msg_idle=true;
void msg(uint y, uint x, string msg_text){
@@ -36,7 +40,7 @@ void msg(uint y, uint x, string msg_text){
try{
if (max_published_screenline_num<y && y<MAX_LINES) max_published_screenline_num=y;
screenlines[y]=msg_text;
- ui_server.send_all_clients(y,msg_text);
+ ui_server.send_connection_msg_to_all_clients(y,msg_text);
// string ready_msg_text=msg_text+" ";
string ready_msg_text=msg_text+"";
mvaddstr(y,x,ready_msg_text.c_str());
@@ -48,14 +52,6 @@ void msg(uint y, uint x, string msg_text){
// }
}
-void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text){
- try{
- msg(connection_num*CONNECTION_LINES+1,0,"DF#"+toString(distfile_num)+" Seg#"+toString(segment_num)+" "+msg_text);
- }catch(...){
- error_log_no_msg("Error in tui.cpp: msg_connecting()");
- }
-}
-
void msg_segment_progress(uint connection_num, uint network_num, uint segment_num, uint try_num, ulong dld_bytes, ulong total_bytes, ulong speed, ulong avg_speed){
try{
@@ -103,6 +99,14 @@ void msg_segment_progress(uint connection_num, uint network_num, uint segment_nu
}
}
+void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text){
+ try{
+ msg(connection_num*CONNECTION_LINES+1,0,"DF#"+toString(distfile_num)+" Seg#"+toString(segment_num)+" "+msg_text);
+ }catch(...){
+ error_log_no_msg("Error in tui.cpp: msg_connecting()");
+ }
+}
+/*
void msg_status1(uint connection_num, uint segment_num, string msg_text){
try{
msg(connection_num*CONNECTION_LINES+2,0,"Seg#"+toString(segment_num)+" "+msg_text);
@@ -117,6 +121,8 @@ void msg_status2(uint connection_num, string msg_text){
error_log_no_msg("Error in tui.cpp: msg_status2()");
}
}
+*/
+
void msg_clean_connection(uint connection_num){
try{
msg(connection_num*CONNECTION_LINES,0,"");
@@ -132,9 +138,26 @@ void msg_clean_connection(uint connection_num){
error_log_no_msg("Error in tui.cpp: msg_clean_connection()");
}
}
-void msg_error(string error_text){
+void msg_log(string log_text){
+ try{
+ ui_server.send_log_msg_to_all_clients(log_text);
+ log_lines.push_back(log_text);
+ if (log_lines.size()>LOG_LINES_MAX_NUM){
+ log_lines.erase(log_lines.begin(),log_lines.begin()+log_lines.size()-LOG_LINES_MAX_NUM);
+ }
+// msg(20,0, error_text);
+ }catch(...){
+ error_log_no_msg("Error in tui.cpp: msg_error()");
+ }
+}
+void msg_error_log(string error_log_text){
try{
- msg(20,0, error_text);
+ ui_server.send_error_log_msg_to_all_clients(error_log_text);
+ log_lines.push_back(error_log_text);
+ if (log_lines.size()>LOG_LINES_MAX_NUM){
+ log_lines.erase(log_lines.begin(),log_lines.begin()+log_lines.size()-LOG_LINES_MAX_NUM);
+ }
+// msg(20,0, error_text);
}catch(...){
error_log_no_msg("Error in tui.cpp: msg_error()");
}
diff --git a/segget/tui.h b/segget/tui.h
index 612ea5a..079c568 100644
--- a/segget/tui.h
+++ b/segget/tui.h
@@ -27,6 +27,7 @@
#ifndef __TUI_H__
#define __TUI_H__
#include <ncurses.h>
+#include <vector>
#include "settings.h"
#include "ui_server.h"
#include "utils.h"
@@ -34,6 +35,19 @@
using namespace std;
+const uint MAX_LINES=200;
+const uint TOTAL_LINE_NUM=MAX_LINES;
+const uint ERROR_LINE_NUM=MAX_LINES+1;
+const uint LOG_LINE_NUM=MAX_LINES+2;
+const uint DEBUG_LINE_NUM=MAX_LINES+3;
+const uint LOG_LINES_MAX_NUM=200;
+
+extern string screenlines[DEBUG_LINE_NUM+1];
+extern uint max_published_screenline_num;
+
+extern vector<string> log_lines;
+extern uint log_lines_counter;
+
void msg_total(string msg_text);
void msg(uint y, uint x, string msg_text);
void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text);
@@ -41,6 +55,7 @@ void msg_segment_progress(uint connection_num, uint network_num, uint segment_nu
void msg_status1(uint connection_num, uint segment_num, string msg_text);
void msg_status2(uint connection_num, string msg_text);
void msg_clean_connection(uint connection_num);
-void msg_error(string error_text);
+void msg_log(string log_text);
+void msg_error_log(string error_log_text);
void msg_total(string msg_text);
#endif \ No newline at end of file
diff --git a/segget/ui_server.cpp b/segget/ui_server.cpp
index 8e4f2cd..dd68330 100644
--- a/segget/ui_server.cpp
+++ b/segget/ui_server.cpp
@@ -26,9 +26,7 @@
#include "ui_server.h"
-uint max_published_screenline_num;
Tui_server ui_server;
-string screenlines[DEBUG_LINE_NUM+1];
void Tui_server::init(){
socklen_t server_len;
@@ -64,7 +62,25 @@ void Tui_server::init(){
send_to_fd_busy=false;
}
//prevent simultaneous writes
-ulong Tui_server::send_to_fd(uint fd, uint y, string msg){
+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;
+}
+
+ulong Tui_server::send_to_fd(uint fd, string msg){
// if (send_to_fd_idle) {
while (send_to_fd_busy){
sleep(1);
@@ -72,9 +88,8 @@ ulong Tui_server::send_to_fd(uint fd, uint y, string msg){
send_to_fd_busy=true;
if (fd !=server_sockfd){
if(FD_ISSET(fd,&ui_server.readfds)) {
- string message="<y>"+toString(y)+"<s>"+msg+"<.>";
- ulong bytes_written=write(fd, message.c_str(), message.length());
- if (bytes_written!=message.length()){
+ ulong bytes_written=write(fd, msg.c_str(), msg.length());
+ if (bytes_written!=msg.length()){
debug("Error: Not all data has been sent to ui_client()");
}
}
@@ -83,9 +98,21 @@ ulong Tui_server::send_to_fd(uint fd, uint y, string msg){
return 0;
}
-void Tui_server::send_all_clients(uint y, string msg){
+void Tui_server::send_connection_msg_to_all_clients(uint y, string msg){
+ for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){
+ send_to_fd(fd, encode_connection_msg(y, msg));
+ }
+}
+
+void Tui_server::send_log_msg_to_all_clients(string msg){
+ for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){
+ send_to_fd(fd, encode_log_msg(msg));
+ }
+}
+
+void Tui_server::send_error_log_msg_to_all_clients(string msg){
for(uint fd = 0; fd <= ui_server.max_fd_num; fd++){
- send_to_fd(fd, y, msg);
+ send_to_fd(fd, encode_error_log_msg(msg));
}
}
@@ -124,7 +151,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, line_num, screenlines[line_num]);
+ ui_server.send_to_fd(client_sockfd, ui_server.encode_connection_msg(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 6723fc4..db67e13 100644
--- a/segget/ui_server.h
+++ b/segget/ui_server.h
@@ -38,19 +38,13 @@
#include <stdlib.h>
#include <string>
#include "settings.h"
+#include "tui.h"
using namespace std;
#define MAX_BIND_ATTEMPTS 5
-const uint MAX_LINES=200;
-const uint TOTAL_LINE_NUM=MAX_LINES;
-const uint ERROR_LINE_NUM=MAX_LINES+1;
-const uint LOG_LINE_NUM=MAX_LINES+2;
-const uint DEBUG_LINE_NUM=MAX_LINES+3;
//const uint MAX_LINES=200;
-extern string screenlines[DEBUG_LINE_NUM+1];
-extern uint max_published_screenline_num;
class Tui_server{
public:
@@ -59,8 +53,13 @@ class Tui_server{
uint max_fd_num;
fd_set readfds, testfds;
void init();
- ulong send_to_fd(uint fd, uint y, string msg);
- void send_all_clients(uint y, string msg);
+ 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_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);
};
extern Tui_server ui_server;
diff --git a/tuiclient/helpwindow.cpp b/tuiclient/helpwindow.cpp
index da51d75..f61bb84 100644
--- a/tuiclient/helpwindow.cpp
+++ b/tuiclient/helpwindow.cpp
@@ -29,14 +29,15 @@
void Thelp_window::compose(){
// msg_text=msg_text+" ";
//
- box(window, ACS_VLINE, ACS_HLINE);
- mvwaddstr(window,0,12," HELP ");
+ make_frame();
mvwaddstr(window,2,1,"q - quit");
mvwaddstr(window,3,1,"h - show this help");
mvwaddstr(window,4,1,"l - show log");
- mvwaddstr(window,5,1,"Up - scroll 1 line up");
- mvwaddstr(window,6,1,"Down - scroll 1 line down");
- mvwaddstr(window,7,1,"PgUp - scroll 1 page up");
- mvwaddstr(window,8,1,"PgDown - scroll 1 page down");
+ mvwaddstr(window,5,1,"e - show error log");
+ mvwaddstr(window,6,1,"d - show distfiles queue");
+ mvwaddstr(window,7,1,"Up - scroll 1 line up");
+ mvwaddstr(window,8,1,"Down - scroll 1 line down");
+ mvwaddstr(window,9,1,"PgUp - scroll 1 page up");
+ mvwaddstr(window,10,1,"PgDown - scroll 1 page down");
wrefresh(window);
} \ No newline at end of file
diff --git a/tuiclient/mainwindow.cpp b/tuiclient/mainwindow.cpp
index e1ba179..6a27022 100644
--- a/tuiclient/mainwindow.cpp
+++ b/tuiclient/mainwindow.cpp
@@ -50,7 +50,7 @@ void Tmainwindow::compose(){
//clear();
box(window, ACS_VLINE, ACS_HLINE);
getmaxyx(window,height,width);
- bottom_screenline_num=height-6;
+ bottom_screenline_num=height-3;
color_status();
msg_status();
color_info();
@@ -58,12 +58,24 @@ void Tmainwindow::compose(){
msg_line(y+1,screen_info_lines[status_line_num]);
}
color_downloads();
- screenlines[26]="Max_num:"+toString(max_received_screenline_num);
+// 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]);
}
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);
+ }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);
+ }
+ log_win.show();
+ error_log_win.show();
+
help_win.center(height,width);
help_win.show();
}
@@ -99,5 +111,8 @@ void Tmainwindow::init(){
exit_flag=FALSE;
visible=TRUE;
notfresh=TRUE;
- help_win.init(12,30,5,5);
+ help_win.init(" HELP ",14,31,5,5);
+ log_win.init(" LOG ",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 5a81e2f..cff1c75 100644
--- a/tuiclient/mainwindow.h
+++ b/tuiclient/mainwindow.h
@@ -34,6 +34,7 @@ using namespace std;
#include "twindow.h"
#include "helpwindow.h"
+#include "scrollwindow.h"
const uint CONNECTION_LINES=5;
const uint MAX_LINES=200;
@@ -42,6 +43,8 @@ class Tmainwindow: public Twindow{
public:
Thelp_window help_win;
+ Tscroll_window log_win;
+ Tscroll_window error_log_win;
bool exit_flag;
bool connected_status;
string screenlines[200];
@@ -49,6 +52,8 @@ class Tmainwindow: public Twindow{
ulong attempt_num;
Tmainwindow():
help_win(),
+ log_win(),
+ error_log_win(),
exit_flag(FALSE),
connected_status(FALSE),
attempt_num(0)
diff --git a/tuiclient/scrollwindow.cpp b/tuiclient/scrollwindow.cpp
new file mode 100644
index 0000000..6e7354c
--- /dev/null
+++ b/tuiclient/scrollwindow.cpp
@@ -0,0 +1,54 @@
+/*
+* 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 "scrollwindow.h"
+
+//Tscroll_window::~Tscroll_window(){};
+
+void Tscroll_window::compose(){
+// msg_text=msg_text+" ";
+//
+ make_frame();
+ getmaxyx(window,height,width);
+ bottom_screenline_num=height-1;
+ color_downloads();
+// 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;};
+ uint line_num=top_position;
+ for (int y=0; (y<bottom_screenline_num && line_num<scroll_lines.size()); y++, line_num++){
+ msg_line(y+1,scroll_lines[line_num]);
+ }
+ wrefresh(window);
+}
+
+
+void Tscroll_window::add_line(string line){
+ 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);
+ }
+} \ No newline at end of file
diff --git a/tuiclient/scrollwindow.h b/tuiclient/scrollwindow.h
new file mode 100644
index 0000000..19b1e0a
--- /dev/null
+++ b/tuiclient/scrollwindow.h
@@ -0,0 +1,49 @@
+/*
+* 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 _SCROLLWINDOW_H_
+#define _SCROLLWINDOW_H_
+
+const uint SCROLL_LINES_MAX_NUM=200;
+
+#include "twindow.h"
+#include <vector>
+
+using namespace std;
+class Tscroll_window: public Twindow{
+ public:
+ vector<string> scroll_lines;
+ uint scroll_lines_counter;
+ Tscroll_window():
+ scroll_lines(),
+ scroll_lines_counter(0)
+ {};
+ ~Tscroll_window(){};
+ void add_line(string line);
+ void compose();
+};
+
+#endif \ No newline at end of file
diff --git a/tuiclient/tuiclient.cpp b/tuiclient/tuiclient.cpp
index a9ce8d2..69531ca 100644
--- a/tuiclient/tuiclient.cpp
+++ b/tuiclient/tuiclient.cpp
@@ -64,14 +64,18 @@ void * watch_keyboard_thread_function(void *){
case (char)82:mainwindow.down(mainwindow.bottom_screenline_num);break;
//KEY_PG_UP
case (char)83:mainwindow.up(mainwindow.bottom_screenline_num);break;
- case 'u':mainwindow.up(1);break;
+ case 'u':
case 'U':mainwindow.up(1);break;
- case 'd':mainwindow.down(1);break;
+ case 'd':
case 'D':mainwindow.down(1);break;
- case 'q':quit();break;
+ case 'q':
case 'Q':quit();break;
- case 'h':mainwindow.help_win.toggle(); mainwindow.show();break;
+ case 'h':
case 'H':mainwindow.help_win.toggle(); mainwindow.show();break;
+ case 'l':
+ 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);
}
}
@@ -89,6 +93,35 @@ 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());
+ if (line_num<200){
+ mainwindow.set_line(line_num, parts.after);
+// set_line(line_num, "||"+toString(line_num)+"||("+first_part.substr(0,first_part.find("<s>")+3)+")"+msg_text);
+// set_line(line_num, "||"+toString(line_num)+"||("+original_msg);
+ }else{
+ mainwindow.screen_info_lines[line_num-200]=parts.after;
+ }
+}
+
+void decode_log_msg(string msg_body){
+ mainwindow.log_win.add_line(msg_body);
+}
+
+void decode_error_log_msg(string msg_body){
+ mainwindow.error_log_win.add_line(msg_body);
+}
+
int main()
{
try{
@@ -124,7 +157,7 @@ int main()
int len;
struct sockaddr_in address;
- string recv_msg, first_part, msg_text;
+ string rest_of_the_msg, first_part, msg_text;
//Create a socket for the client:
int result=-1;
@@ -134,8 +167,8 @@ int main()
//Name the socket, as agreed with the server:
address.sin_family = AF_INET;
- address.sin_addr.s_addr = inet_addr("127.0.0.1");
- address.sin_port = htons(9999);
+ address.sin_addr.s_addr = inet_addr(settings.ui_ip.c_str());
+ address.sin_port = htons(settings.ui_port);
len = sizeof(address);
//Connect your socket to the server’s socket:
result = connect(sockfd, (struct sockaddr *)&address, len);
@@ -175,20 +208,21 @@ int main()
error_log("Error in tuiclient.cpp : main() read bytes count does NOT match declared count.");
};
//recv_msg=recv_msg+recv_buffer;
- recv_msg=recv_msg+recv_buffer;
- while (recv_msg.find("<.>")!=recv_msg.npos){
- string original_msg=recv_msg;
- recv_msg=recv_msg.substr(recv_msg.find("<y>")+3,recv_msg.npos);
- first_part=recv_msg.substr(0,recv_msg.find("<.>"));
- recv_msg=recv_msg.substr(recv_msg.find("<.>")+3);
- uint line_num=atoi(first_part.substr(0,first_part.find("<s>")).c_str());
- msg_text=first_part.substr(first_part.find("<s>")+3,first_part.npos);
- if (line_num<200){
- mainwindow.set_line(line_num, msg_text);
-// set_line(line_num, "||"+toString(line_num)+"||("+first_part.substr(0,first_part.find("<s>")+3)+")"+msg_text);
-// set_line(line_num, "||"+toString(line_num)+"||("+original_msg);
- }else{
- mainwindow.screen_info_lines[line_num-200]=msg_text;
+ rest_of_the_msg=rest_of_the_msg+recv_buffer;
+ Tparts msg_parts;
+ while (rest_of_the_msg.find("<.>")!=rest_of_the_msg.npos){
+ msg_parts=split("<m>",rest_of_the_msg);
+ msg_parts=split("<t>",msg_parts.after);
+ char msg_type=msg_parts.before[0];
+ debug("msg_type="+msg_type);
+ msg_parts=split("<.>",msg_parts.after);
+ string msg_body=msg_parts.before;
+ debug("msg_body="+msg_body);
+ rest_of_the_msg=msg_parts.after;
+ switch (msg_type){
+ 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;
}
}
};
diff --git a/tuiclient/tuiclient.h b/tuiclient/tuiclient.h
index 6cb5fd9..ad7cdac 100644
--- a/tuiclient/tuiclient.h
+++ b/tuiclient/tuiclient.h
@@ -40,6 +40,7 @@
#include "twindow.cpp"
#include "mainwindow.cpp"
#include "helpwindow.cpp"
+#include "scrollwindow.cpp"
#include "colors.cpp"
#include "config.cpp"
#include "log.cpp"
@@ -54,6 +55,16 @@
using namespace std;
+class Tparts{
+ public:
+ string before, after;
+ Tparts():
+ before(""),
+ after("")
+ {};
+};
+
+
Tmainwindow mainwindow;
int sockfd;
diff --git a/tuiclient/twindow.cpp b/tuiclient/twindow.cpp
index 233c499..e4ee2f7 100644
--- a/tuiclient/twindow.cpp
+++ b/tuiclient/twindow.cpp
@@ -26,7 +26,8 @@
#include "twindow.h"
-void Twindow::init(int height_, int width_, int y_, int x_){
+void Twindow::init(string caption_, int height_, int width_, int y_, int x_){
+ caption=caption_;
height=height_;
width=width_;
y=y_;
@@ -87,6 +88,22 @@ void Twindow::center(uint max_y, uint max_x){
mvwin(window,y,x);
}
+void Twindow::resize(uint new_height, uint new_width, uint new_y, uint new_x){
+ y=new_y;
+ x=new_x;
+ height=new_height;
+ width=new_width;
+ mvwin(window,y,x);
+ wresize(window,height,width);
+}
+
+void Twindow::make_frame(){
+ wclear(window);
+ box(window, ACS_VLINE, ACS_HLINE);
+ mvwaddstr(window,0,(width-caption.length())/2,caption.c_str());
+}
+
+
void Twindow::refresh(){
if (notfresh){
show();
diff --git a/tuiclient/twindow.h b/tuiclient/twindow.h
index 32ab4b4..aa84214 100644
--- a/tuiclient/twindow.h
+++ b/tuiclient/twindow.h
@@ -36,6 +36,7 @@ using namespace std;
class Twindow{
public:
WINDOW * window;
+ string caption;
uint width;
uint height;
uint y;
@@ -49,6 +50,7 @@ class Twindow{
Twindow():
window(0),
+ caption(""),
width(10),
height(10),
y(1),
@@ -63,13 +65,15 @@ class Twindow{
virtual ~Twindow(){};
Twindow(const Twindow &L); // copy constructor
Twindow & operator=(const Twindow &L);
- void init(int height_, int width_, int y_, int x_);
+ void init(string caption_, int height_, int width_, int y_, int x_);
void toggle();
void msg_line(uint y, string msg_text);
void msg_short(uint y, uint x, string msg_text);
void up(int inc);
void down(uint inc);
void center(uint max_y, uint max_x);
+ void resize(uint new_height, uint new_width, uint new_y, uint new_x);
+ void make_frame();
void refresh();
void show();
virtual void compose(){};