From ca28c0e618890330d429c0dc12429255b20f0c90 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:44 +0200 Subject: tagging ychat-0.5.0 --- sman.cpp | 95 +++++++++++++++++----------------------------------------------- 1 file changed, 25 insertions(+), 70 deletions(-) (limited to 'sman.cpp') diff --git a/sman.cpp b/sman.cpp index ab3468a..4c95b32 100644 --- a/sman.cpp +++ b/sman.cpp @@ -5,89 +5,44 @@ sman::sman() { - this->sessions=new hmap(80); - this->session_count=0; - pthread_mutex_init( &mut_sessions, NULL ); - pthread_mutex_init( &mut_session_count, NULL ); + this->sessions=new hmap(80); + this->sessioncount=0; } sman::~sman() { - pthread_mutex_lock( &mut_sessions ); - delete this->sessions; - pthread_mutex_unlock( &mut_sessions ); - - pthread_mutex_destroy( &mut_sessions ); - pthread_mutex_destroy( &mut_session_count ); -} -string sman::generate_id( int len ) -{ - string valid_chars=".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; - string s_ret=""; - srand(time(0)+160682); - for(int i=0;isessions; } -sess *sman::create_session( ) +string sman::generateId( int len ) { - string new_id=this->generate_id( s_tool::string2int( s_conf::get - ().get_val( "SESSION_LENGTH" ) ) ); - - sess *new_sess= new sess( new_id ); - - pthread_mutex_lock( &mut_session_count ); - this->session_count++; -#ifdef NCURSES - print_sessions(); -#endif - pthread_mutex_unlock( &mut_session_count ); - - pthread_mutex_lock( &mut_sessions ); - this->sessions->add_elem( new_sess, new_id ); - pthread_mutex_unlock( &mut_sessions ); - - - return new_sess; + string valid_chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; + string s_ret=""; + srand(time(0)+160682); + for(int i=0;isessions->get_elem( s_id ); - pthread_mutex_unlock( &mut_sessions ); + string new_id=this->generateId(s_tool::string2int( s_conf::get().get_val( "SESSION_LENGTH" ) ) ); - return ret_sess; -} -void sman::destroy_session( string s_id ) -{ - pthread_mutex_lock( &mut_session_count ); - this->session_count--; -#ifdef NCURSES - print_sessions(); -#endif - pthread_mutex_unlock( &mut_session_count ); + sess *new_sess= new sess( new_id ); - this->sessions->del_elem( s_id ); + this->sessioncount++; + this->sessions->add_elem( new_sess, new_id ); + + return new_sess; } -#ifdef NCURSES -void sman::print_sessions() +sess *sman::getSession( string s_id ) { - pthread_mutex_lock ( &s_mutx::get().mut_stdout ); - mvprintw( NCUR_SESSION_X,NCUR_SESSION_Y, "Sessions: %d ", session_count); - refresh(); - pthread_mutex_unlock( &s_mutx::get().mut_stdout ); + return this->sessions->get_elem( s_id ); } - -void sman::print_init_ncurses() +void sman::destroySession( string s_id ) { - pthread_mutex_lock( &mut_session_count ); - print_sessions(); - pthread_mutex_unlock( &mut_session_count ); + this->sessioncount--; + this->sessions->del_elem( s_id ); } - -#endif #endif -- cgit v1.2.3