messaginghub.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 
00012  #include "messaginghub.h"
00013 
00014  
00015 StatusMessageWindowHolder :: StatusMessageWindowHolder( const StatusMessageWindowHolder& smw )
00016    : userData( NULL )
00017 {
00018    copy(smw);
00019 }
00020  
00021 StatusMessageWindowHolder::StatusMessageWindowHolder()
00022 {
00023    userData = new UserData;
00024 }
00025 
00026 
00027 void StatusMessageWindowHolder::unlink()
00028 {
00029    if ( userData ) {
00030       userData->counter -= 1;
00031       if ( userData->counter <= 0 ) {
00032          delete userData;
00033          userData = NULL;
00034       }
00035    }
00036 }
00037 
00038 void StatusMessageWindowHolder::copy( const StatusMessageWindowHolder& smw )
00039 {
00040    if ( smw.userData ) {
00041       unlink();
00042       userData = smw.userData;
00043       userData->counter += 1;
00044    } else {
00045       userData = new UserData;
00046    }   
00047 }
00048 
00049 void StatusMessageWindowHolder::close()
00050 {
00051    unlink();
00052 }   
00053 
00054 void StatusMessageWindowHolder::SetText( const ASCString& text )
00055 {
00056    if ( userData )
00057       userData->SetText( text );
00058 }
00059 
00060 
00061 StatusMessageWindowHolder& StatusMessageWindowHolder::operator=( const StatusMessageWindowHolder& smw )
00062 {
00063    copy(smw);
00064    return *this;
00065 }
00066 
00067 
00068 StatusMessageWindowHolder::~StatusMessageWindowHolder()
00069 {
00070    unlink();
00071 }
00072 
00073 StatusMessageWindowHolder MessagingHubBase::infoMessageWindow( const ASCString& msg ) { 
00074    return StatusMessageWindowHolder( messageWindowFactory( msg )); 
00075 }
00076 
00077 
00078 void MessagingHubBase::message( MessageType type, const ASCString& message )
00079 {
00080    switch ( type ) {
00081       case FatalError: fatalError( message ); 
00082                        exitHandler();
00083                        break;
00084       case Error:      error ( message ); break;
00085       case Warning:    warning( message ); break;
00086       case InfoMessage: infoMessage( message ); break;
00087       case StatusInfo: statusInformation( message ); break;
00088       case LogMessage: logMessage( message, 0 ); break;
00089    };   
00090 
00091 }
00092 
00093 void MessagingHubBase::setLoggingCategory( const ASCString& category, bool enable )
00094 {
00095    if ( enable ) {
00096       if ( enabledLogCategories.find( category ) == enabledLogCategories.end())
00097          enabledLogCategories.insert( category );
00098    } else {
00099       if ( enabledLogCategories.find( category ) != enabledLogCategories.end())
00100          enabledLogCategories.erase( category );
00101    }
00102 }
00103 
00104  
00105 void MessagingHubBase::message( MessageType type, const char* msg, ... )
00106 {
00107    va_list arglist;
00108    va_start ( arglist, msg );
00109 
00110    ASCString my_message;
00111    my_message.vaformat( msg, arglist );
00112    
00113    message( type, my_message );  
00114    
00115    va_end ( arglist );
00116 }
00117  
00118   
00119 void displayLogMessage ( int msgVerbosity, const char* message, ... )
00120 {
00121    va_list arglist;
00122    va_start ( arglist, message );
00123    if ( msgVerbosity <= MessagingHub::Instance().getVerbosity() ) {
00124       char buf[10000];
00125       vsprintf ( buf, message, arglist );
00126 
00127       displayLogMessage( msgVerbosity, ASCString(buf) );
00128    }
00129    va_end ( arglist );
00130 }
00131 
00132 void displayLogMessage ( int msgVerbosity, const ASCString& message )
00133 {
00134    if ( msgVerbosity <= MessagingHub::Instance().getVerbosity() ) 
00135       MessagingHub::Instance().logMessage( message, msgVerbosity );
00136 
00137 }
00138 
00139 
00140 bool MessagingHubBase::logCategoryEnabled(const ASCString& category)
00141 {
00142    return enabledLogCategories.find( category ) != enabledLogCategories.end();
00143 }
00144 
00145 void logMessage ( const ASCString& category, const ASCString& message )
00146 {
00147    if ( MessagingHub::Instance().logCategoryEnabled( category ) )
00148       MessagingHub::Instance().logCategorizedMessage( category, message );
00149 }
00150 
00151 void fatalError ( const ASCString& string )
00152 {
00153    MessagingHub::Instance().message( MessagingHubBase::FatalError, string );
00154 }
00155 
00156 void fatalError ( const char* msg, ... )
00157 {
00158    va_list arglist;
00159    va_start ( arglist, msg );
00160 
00161    ASCString message;
00162    message.vaformat( msg, arglist );
00163 
00164    fatalError( message );
00165       
00166    va_end ( arglist );
00167 }
00168 
00169 
00170 void warning ( const ASCString& str )
00171 {
00172    MessagingHub::Instance().message( MessagingHubBase::Warning, str );
00173 }
00174 
00175 void warningMessage ( const ASCString& str )
00176 {
00177    MessagingHub::Instance().message( MessagingHubBase::Warning, str );
00178 }
00179 
00180 void errorMessage ( const ASCString& string )
00181 {
00182    MessagingHub::Instance().message( MessagingHubBase::Error, string );
00183 }
00184 
00185 void infoMessage ( const ASCString& string )
00186 {
00187    MessagingHub::Instance().message( MessagingHubBase::InfoMessage, string );
00188 }
00189 
00190 void statusMessage ( const ASCString& string )
00191 {
00192    MessagingHub::Instance().message( MessagingHubBase::StatusInfo, string );
00193 }
00194 

Generated on Mon May 21 01:26:35 2012 for Advanced Strategic Command by  doxygen 1.5.1