summaryrefslogtreecommitdiff
path: root/src/ncur
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
committerPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
commit312fe18cb5f97143f3600b207e979bc559256b6f (patch)
treede14514b4b4c20adf0eecdcd261ae21839f6a645 /src/ncur
parentf038883a6e004eb4312ba1e761da06b596e14d3f (diff)
tagging yhttpd-0.7.0yhttpd-0.7.0
Diffstat (limited to 'src/ncur')
-rwxr-xr-xsrc/ncur/menu.cpp149
-rwxr-xr-xsrc/ncur/menu.h27
-rwxr-xr-xsrc/ncur/ncur.cpp359
-rwxr-xr-xsrc/ncur/ncur.h50
4 files changed, 273 insertions, 312 deletions
diff --git a/src/ncur/menu.cpp b/src/ncur/menu.cpp
index dcacc9b..c5734a5 100755
--- a/src/ncur/menu.cpp
+++ b/src/ncur/menu.cpp
@@ -6,111 +6,112 @@
#ifndef MENU_CPP
#define MENU_CPP
-using namespace std;
-menu::menu( int i_startx, int i_starty, int i_width, int i_height, char *c_header, char **choices, int i_numchoices, const chtype ch )
+using namespace std; menu::menu( int i_startx, int i_starty, int i_width, int i_height, char *c_header, char **choices, int i_numchoices, const chtype ch )
{
- this->i_startx = i_startx;
- this->i_starty = i_starty;
- this->i_height = i_height;
- this->i_width = i_width;
- this->c_header = c_header;
- this->choices = choices;
- this->i_numchoices = i_numchoices;
-
- initialize( ch );
+ this->i_startx = i_startx;
+ this->i_starty = i_starty;
+ this->i_height = i_height;
+ this->i_width = i_width;
+ this->c_header = c_header;
+ this->choices = choices;
+ this->i_numchoices = i_numchoices;
+
+ initialize( ch );
}
menu::~menu()
{
- /*
- wborder(win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
- wrefresh(win);
- delwin(win);
- */
+ /*
+ wborder(win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
+ wrefresh(win);
+ delwin(win);
+ */
}
void
menu::initialize( const chtype ch )
{
- this->i_highlight = 1;
- this->i_choice = 0;
+ this->i_highlight = 1;
+ this->i_choice = 0;
- win = newwin( i_height, i_width, i_starty, i_startx );
- wbkgd(win, ch);
+ win = newwin( i_height, i_width, i_starty, i_startx );
+ wbkgd(win, ch);
}
void
menu::display()
{
- int x, y, i;
+ int x, y, i;
- x = 2;
- y = 2;
+ x = 2;
+ y = 2;
- box( win, 0, 0 );
- mvwprintw( win, y++, x, "%s", c_header );
+ box( win, 0, 0 );
+ mvwprintw( win, y++, x, "%s", c_header );
- for( i = 0; i < i_numchoices; i++ )
- {
- ++y;
-
- if( i_highlight == i+1 ) // Highlight the current selection.
- {
- wattron( win, A_REVERSE);
- mvwprintw( win, y, x, "%d. %s", i, choices[i]);
- wattroff( win, A_REVERSE);
- } else
+ for( i=0; i<i_numchoices; i++ )
{
- mvwprintw( win, y, x, "%d. %s", i, choices[i]);
+ y++;
+
+ if( i_highlight == i + 1 ) /* High light the present choice */
+ {
+ wattron( win, A_REVERSE);
+ mvwprintw( win, y, x, "%d. %s", i, choices[i]);
+ wattroff( win, A_REVERSE);
+ }
+ else
+ {
+ mvwprintw( win, y, x, "%d. %s", i, choices[i]);
+ }
}
- }
- wrefresh( win );
+ wrefresh( win );
}
void
menu::start( void (*swich_case_menu_action)(int) )
{
- refresh();
- bool b_flag = 1;
+ refresh();
+ bool b_flag = 1;
- while( b_flag )
- {
- keypad(win, 1);
- display();
- c = wgetch( win );
-
- switch(c)
+ while( b_flag )
{
- case KEY_UP:
- if( i_highlight == 1 )
- i_highlight = i_numchoices;
- else
- --i_highlight;
- break;
-
- case KEY_DOWN:
- if( i_highlight == i_numchoices )
- i_highlight = 1;
- else
- ++i_highlight;
- break;
-
- case 10:
- i_choice = i_highlight;
- break;
-
- default:
- mvprintw( NCUR_MENU_CHAR_X, NCUR_MENU_CHAR_Y, "%3d %c ", c, c);
- refresh();
- break;
+ keypad(win, 1);
+ display();
+ c = wgetch( win );
+
+ switch(c)
+ {
+ case KEY_UP:
+ if( i_highlight == 1 )
+ i_highlight = i_numchoices;
+ else
+ --i_highlight;
+ break;
+
+ case KEY_DOWN:
+ if( i_highlight == i_numchoices )
+ i_highlight = 1;
+ else
+ ++i_highlight;
+ break;
+
+ case 10:
+ i_choice = i_highlight;
+ break;
+
+ default:
+ mvprintw( NCUR_MENU_CHAR_X, NCUR_MENU_CHAR_Y, "%3d %c ", c, c);
+ refresh();
+ break;
+ }
+
+
+ // Menu action.
+ ( *swich_case_menu_action ) ( i_choice );
+ i_choice = 0;
}
-
- // Menu action.
- ( *swich_case_menu_action ) ( i_choice );
- i_choice = 0;
- }
}
#endif
diff --git a/src/ncur/menu.h b/src/ncur/menu.h
index af7dbe9..7e4fc5b 100755
--- a/src/ncur/menu.h
+++ b/src/ncur/menu.h
@@ -1,7 +1,6 @@
#include "../incl.h"
#ifdef NCURSES
-
#ifndef MENU_H
#define MENU_H
@@ -12,27 +11,23 @@ using namespace std;
class menu
{
private:
- char **choices;
- char *c_header;
+ char **choices;
+ char *c_header;
- int i_startx, i_starty, i_width, i_height, i_highlight, i_choice,
- i_numchoices, c;
+ int i_startx, i_starty, i_width, i_height, i_highlight, i_choice,
+ i_numchoices, c;
- WINDOW *win;
+ WINDOW *win;
- void initialize( const chtype ch );
+ void initialize( const chtype ch );
public:
- explicit menu( int i_startx, int i_starty, int i_width, int i_height, char *c_header, char **choices, int i_numchoices, const chtype ch );
- ~menu( );
-
- void display();
- void start( void (*swich_case_menu_action)(int) );
+ explicit menu( int i_startx, int i_starty, int i_width, int i_height, char *c_header, char **choices, int i_numchoices, const chtype ch );
+ ~menu( );
- void activate_menu_win()
- {
- keypad(win, 1);
- }
+ void display();
+ void start( void (*swich_case_menu_action)(int) );
+ void activate_menu_win() { keypad(win, 1); }
};
#endif
diff --git a/src/ncur/ncur.cpp b/src/ncur/ncur.cpp
index 4f63f01..e9e7753 100755
--- a/src/ncur/ncur.cpp
+++ b/src/ncur/ncur.cpp
@@ -11,282 +11,253 @@ using namespace std;
#ifdef NCURSES
-const string GMAKE_PARAMS[] =
- { "clean_base", "clean_modules", "all"
- };
+const string GMAKE_PARAMS[] = { "clean_base", "clean_modules", "all" };
const int GMAKE_ELEMENTS = 3;
ncur::ncur( )
{
- p_messagelist = new list<char*>;
- pthread_mutex_init( &mut_messages, NULL );
- pthread_mutex_init( &mut_is_ready, NULL );
- i_message_length = 45;
- b_is_ready = false;
+ p_messagelist = new list<char*>;
+ pthread_mutex_init( &mut_messages, NULL );
+ pthread_mutex_init( &mut_is_ready, NULL );
+ i_message_length = 45;
+ b_is_ready = false;
}
ncur::~ncur()
{
- pthread_mutex_destroy( &mut_messages );
- pthread_mutex_destroy( &mut_is_ready );
+ pthread_mutex_destroy( &mut_messages );
+ pthread_mutex_destroy( &mut_is_ready );
}
void
ncur::start( void *p_void )
{
- ncur::init_ncurses();
-
- char *choices[] = {
- "Unload all modules ", //<<
- "Reload all modules ", //<<
- //>>" ",
- //>>" ",
- "Clear template cache ",
- "Run garbage collector ", //<<
- //>>" ",
- "Show max res. set size ",
- "Compile changed sources ",
- "Recompile all sources ",
- "Show source stats ",
- "Command line interface ",
- //<<*
+ ncur::init_ncurses();
+
+ char *choices[] = {
+ "Unload all modules ",
+ "Reload all modules ",
+ "Clear template cache ",
+ " ",
+ "Show max res. set size ",
+ "Compile changed sources ",
+ "Recompile all sources ",
+ "Show source stats ",
+ "Command Line Interface ",
#ifdef DATABASE
- "Close DB connections ",
#else
- " ",
#endif
- //*>>
- //>>" ",
- "Shut down server"
- };
- p_serveroutput = newwin( 19, 49, 1, 31 );
- wbkgd(p_serveroutput, COLOR_PAIR(1));
+ " ",
+ "Shut down server"
+ };
- box ( p_serveroutput, 0, 0 );
- mvwprintw( p_serveroutput, 2, 2, NCURMSG );
- wrefresh ( p_serveroutput );
+ p_serveroutput = newwin( 19, 49, 1, 31 );
+ wbkgd(p_serveroutput, COLOR_PAIR(1));
- print( string("yChat ") + VERSION );
+ box ( p_serveroutput, 0, 0 );
+ mvwprintw( p_serveroutput, 2, 2, NCURMSG );
+ wrefresh ( p_serveroutput );
+ print( VERSION );
- p_menu = new menu( 1, 1, 30, 19, NCURADM, choices, 11, COLOR_PAIR(1));
- mvprintw(NCUR_SERVER_HEADER_X,NCUR_SERVER_HEADER_Y, NCURSE0);
- mvprintw(NCUR_POOL_HEADER_X,NCUR_POOL_HEADER_Y, NCURSE1);
- mvprintw(NCUR_DATA_HEADER_X,NCUR_DATA_HEADER_Y, NCURSE2); //<<
- mvprintw(NCUR_CHAT_HEADER_X,NCUR_CHAT_HEADER_Y, NCURSE3); //<<
- mvprintw(NCUR_CACHED_HEADER_X,NCUR_CACHED_HEADER_Y, NCURSE4);
+ p_menu = new menu( 1, 1, 30, 19, NCURADM, choices, 11, COLOR_PAIR(1));
- wrap::HTML->print_cached(0);
+ mvprintw( NCUR_SERVER_HEADER_X,NCUR_SERVER_HEADER_Y, "HTTP server:");
+ mvprintw( NCUR_POOL_HEADER_X,NCUR_POOL_HEADER_Y, "Thread pool:");
+#ifdef DATABASE
+#endif
+ mvprintw( NCUR_CACHED_HEADER_X,NCUR_CACHED_HEADER_Y, "Caching:");
+ wrap::HTML->print_cached(0);
- is_ready(true);
- wrap::SMAN->print_init_ncurses(); //<<
- wrap::STAT->print_num_rooms(); //<<
+ is_ready( true );
- p_menu->start( &switch_main_menu_ );
+ p_menu->start( &switch_main_menu_ );
- shutdown();
+ shutdown();
}
void
ncur::shutdown()
{
- ncur::close_ncurses();
+ ncur::close_ncurses();
}
void
ncur::print( string *p_msg )
{
- print( *p_msg );
+ print( *p_msg );
}
void
ncur::print( string s_msg )
{
- print( (char*)s_msg.c_str() );
+ print( (char*)s_msg.c_str() );
}
void
ncur::print( char* c_print )
{
- // Removing \n
- if ( strlen(c_print) > i_message_length )
- {
- string s_tmp(c_print);
- print( s_tmp.substr( 0, i_message_length ) );
- print( s_tmp.substr( i_message_length, s_tmp.length()-i_message_length ) );
- return;
- }
-
- int i;
- char* c_temp = new char[i_message_length];
- memcpy( c_temp, c_print, strlen(c_print) );
-
- for ( i = strlen(c_print); i < i_message_length; ++i )
- c_temp[i] = ' ';
-
- c_temp[i] = '\0';
-
- pthread_mutex_lock( &mut_messages );
-
- if ( p_messagelist->size() > 12 )
- {
- char* c_front = p_messagelist->front();
- p_messagelist->pop_front();
- free(c_front);
- }
-
- p_messagelist->push_back( c_temp );
+ // Removing \n
+ if ( strlen(c_print) > i_message_length )
+ {
+ string s_tmp(c_print);
+ print( s_tmp.substr( 0, i_message_length ) );
+ print( s_tmp.substr( i_message_length, s_tmp.length()-i_message_length ) );
+ return;
+ }
+
+ int i;
+ char* c_temp = new char[i_message_length];
+ memcpy( c_temp, c_print, strlen(c_print) );
+ for ( i = strlen(c_print); i < i_message_length; i++ )
+ c_temp[i] = ' ';
+ c_temp[i] = '\0';
+
+ pthread_mutex_lock( &mut_messages );
+
+ if ( p_messagelist->size() > 12 )
+ {
+ char* c_front = p_messagelist->front();
+ p_messagelist->pop_front();
+ free( c_front );
+ }
+ p_messagelist->push_back( c_temp );
- if ( is_ready() )
- {
- list<char*>::iterator iter;
- iter = p_messagelist->begin();
- for ( i = 4; i < 18 && iter != p_messagelist->end(); ++i, ++iter )
+ if ( is_ready() )
+ {
+ list<char*>::iterator iter;
+ iter = p_messagelist->begin();
+
+ for ( i=4; i<18 && iter != p_messagelist->end(); i++, iter++ )
mvwprintw( p_serveroutput, i, 2, *iter );
- wrefresh ( p_serveroutput );
- }
+ wrefresh ( p_serveroutput );
+ }
- pthread_mutex_unlock( &mut_messages );
+ pthread_mutex_unlock( &mut_messages );
}
void
ncur::switch_main_menu_( int i_choice )
{
- int i;
-
- if( i_choice != 0 )
- switch ( i_choice )
- {
- //<<*
- case 1:
- wrap::MODL->unload_modules();
- mvprintw( 20,2, "Unloaded all modules ");
- refresh();
- break;
- case 2:
- wrap::MODL->reload_modules();
- mvprintw( 20,2, "Reloaded all modules ");
- refresh();
- break;
- //*>>
- case 3:
- wrap::HTML->clear_cache();
- mvprintw( 20,2, "Cleared the template cache ");
- refresh();
- break;
- case 4:
- //<<*
- if ( ! wrap::GCOL->remove_garbage() )
- wrap::NCUR->print( GAROFFNE );
- mvprintw( 20,2, "Garbage collector activated ");
- //*>>
- refresh();
- break;
- case 5:
- mvprintw( 20,2, "Showing max resident set size in memory ");
- wrap::NCUR->print( STATRSS + string("(") + tool::int2string(
- wrap::STAT->get_ru_maxrss()) + string(")"));
- break;
- case 6:
- tool::shell_command( string(GMAKE), METH_NCURSES);
- break;
- case 7:
- for ( i = 0; i < GMAKE_ELEMENTS; i++ )
- tool::shell_command( GMAKE + GMAKE_PARAMS[i], METH_NCURSES);
- break;
- case 8:
- tool::shell_command( string(GMAKE) + " stats", METH_NCURSES);
- break;
- case 9:
-#ifdef CLI
-
- wrap::NCUR->is_ready(false);
- refresh(); /* Print it on to the real screen */
-
- def_prog_mode(); /* Save the tty modes */
- endwin(); /* End curses mode temporarily */
- new cli(); /* Start CLI mode */
- reset_prog_mode(); /* Return to the previous tty mode*/
- /* stored by def_prog_mode() */
- refresh(); /* Do refresh() to restore the */
- /* Screen contents */
- wrap::NCUR->is_ready(true);
- wrap::NCUR->activate_menu_win();
+ int i;
+
+ if( i_choice != 0 )
+ switch ( i_choice )
+ {
+ case 1:
+ wrap::MODL->unload_modules();
+ mvprintw( 20,2, "Unloaded all modules ");
+ refresh();
+ break;
+ case 2:
+ wrap::MODL->reload_modules();
+ mvprintw( 20,2, "Reloaded all modules ");
+ refresh();
+ break;
+ case 3:
+ wrap::HTML->clear_cache();
+ mvprintw( 20,2, "Cleared the template cache ");
+ refresh();
+ break;
+ case 4:
+ refresh();
+ break;
+ case 5:
+ mvprintw( 20,2, "Showing max resident set size in memory ");
+ wrap::NCUR->print( STATRSS + string("(") + tool::int2string(
+ wrap::STAT->get_ru_maxrss()) + string(")"));
+ break;
+ case 6:
+ tool::shell_command( string(GMAKE), METH_NCURSES);
+ break;
+ case 7:
+ for ( i = 0; i < GMAKE_ELEMENTS; i++ )
+ tool::shell_command( GMAKE + GMAKE_PARAMS[i], METH_NCURSES);
+ break;
+ case 8:
+ tool::shell_command( string(GMAKE) + " stats", METH_NCURSES);
+ break;
+ case 9:
+#ifdef CLI
+ wrap::NCUR->is_ready(false);
+ refresh(); /* Print it on to the real screen */
+
+ def_prog_mode(); /* Save the tty modes */
+ endwin(); /* End curses mode temporarily */
+ new cli(); /* Start CLI mode */
+ reset_prog_mode(); /* Return to the previous tty mode*/
+ /* stored by def_prog_mode() */
+ refresh(); /* Do refresh() to restore the */
+ /* Screen contents */
+ wrap::NCUR->is_ready(true);
+ wrap::NCUR->activate_menu_win();
#else
-
- mvprintw( 20,2, "CLI mode has not been compiled in! ");
+ mvprintw( 20,2, "CLI mode has not been compiled in! ");
#endif
-
- break;
- case 10:
+ break;
+ case 10:
#ifdef DATABASE
-
- wrap::DATA->disconnect_all_connections(); //<<
#endif
-
- break;
-
- case 11: // Shut down server
- if ( ! wrap::GCOL->remove_garbage() ) //<<
- wrap::NCUR->print( GAROFFNE ); //<<
- mvprintw( 21,2, "Good bye !");
- close_ncurses();
- exit(0);
- break;
-
- default:
- mvprintw( 20,2, "Selection # %d not yet implemented!", i_choice-1);
- wrap::NCUR->print( "Selection not yet implemented!" );
- refresh();
- break;
- }
+ break;
+
+ case 11: // Shut down server
+ mvprintw( 21,2, "Good bye !");
+ close_ncurses();
+ exit(0);
+ break;
+
+ default:
+ mvprintw( 20,2, "Selection # %d not yet implemented!", i_choice-1);
+ wrap::NCUR->print( "Selection not yet implemented!" );
+ refresh();
+ break;
+ }
}
void
ncur::init_ncurses()
{
- initscr();
- start_color();
- clear();
- noecho();
- cbreak(); // Line buffering disabled. pass on everything
- init_pair(1, COLOR_WHITE, COLOR_BLUE);
- mvprintw( 0,2, (char*)(tool::ychat_version()).c_str());
- refresh();
+ initscr();
+ start_color();
+ clear();
+ noecho();
+ cbreak(); // Line buffering disabled. pass on everything
+ init_pair(1, COLOR_WHITE, COLOR_BLUE);
+ mvprintw( 0,2, (char*)(tool::yhttpd_version()).c_str());
+ refresh();
}
void
ncur::close_ncurses()
{
- refresh();
- clrtoeol();
- refresh();
- endwin();
+ refresh();
+ clrtoeol();
+ refresh();
+ endwin();
}
void
ncur::is_ready( bool b_is_ready )
{
- pthread_mutex_lock( &mut_is_ready );
- this->b_is_ready = b_is_ready;
- pthread_mutex_unlock( &mut_is_ready );
+ pthread_mutex_lock( &mut_is_ready );
+ this->b_is_ready = b_is_ready;
+ pthread_mutex_unlock( &mut_is_ready );
}
bool
ncur::is_ready()
{
- bool b_ret;
- pthread_mutex_lock( &mut_is_ready );
- b_ret = b_is_ready;
- pthread_mutex_unlock( &mut_is_ready );
- return b_ret;
+ bool b_ret;
+ pthread_mutex_lock( &mut_is_ready );
+ b_ret = b_is_ready;
+ pthread_mutex_unlock( &mut_is_ready );
+ return b_ret;
}
-
#endif
#endif
diff --git a/src/ncur/ncur.h b/src/ncur/ncur.h
index 74ed60e..692a48a 100755
--- a/src/ncur/ncur.h
+++ b/src/ncur/ncur.h
@@ -1,10 +1,8 @@
#include "../incl.h"
#ifdef NCURSES
-
#ifndef NCUR_H
#define NCUR_H
-
#include <ncurses.h>
#include <list>
@@ -16,34 +14,30 @@ using namespace std;
class ncur : public thro
{
private:
- menu* p_menu;
- WINDOW* p_serveroutput;
- list<char*>* p_messagelist; // contains the messages for p_serveroutput!
- int i_message_length; // the maximum length of a system message!
- bool b_is_ready; // is set to TRUE if the admin interface is initialized.
- static void init_ncurses();
- static void close_ncurses();
-
- pthread_mutex_t mut_messages;
- pthread_mutex_t mut_is_ready;
+ menu* p_menu;
+ WINDOW* p_serveroutput;
+ list<char*>* p_messagelist; // contains the messages for p_serveroutput!
+ pthread_mutex_t mut_messages; // for syncronization of p_serveroutput!
+ int i_message_length; // the maximum length of a system message!
+ bool b_is_ready; // is set to TRUE if the admin interface is initialized.
+ static void init_ncurses();
+ static void close_ncurses();
+ pthread_mutex_t mut_is_ready;
public:
- ncur( ); // a standard constructor.
- ~ncur( );
-
- void start( void *p_void );
- void print( char* c_print );
- void print( string s_msg );
- void print( string* p_msg );
- void is_ready( bool b_is_ready );
- bool is_ready();
- static void switch_main_menu_( int i_choice );
- void shutdown();
-
- void activate_menu_win()
- {
- p_menu->activate_menu_win();
- }
+ ncur( ); // a standard constructor.
+ ~ncur( );
+
+ void start( void *p_void );
+ virtual void print( char* c_print );
+ virtual void print( string s_msg );
+ virtual void print( string* p_msg );
+ void is_ready( bool b_is_ready );
+ bool is_ready();
+ static void switch_main_menu_( int i_choice );
+ void shutdown();
+ void activate_menu_win()
+ { p_menu->activate_menu_win(); }
};
#endif