messaginghub.h

Go to the documentation of this file.
00001 
00002 /*
00003     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00004     Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; see the file COPYING. If not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00019     Boston, MA  02111-1307  USA
00020 */
00021 
00022 
00023 #ifndef messaginghubH
00024 #define messaginghubH
00025 
00026  #include <set>
00027 
00028  #include <sigc++/sigc++.h>
00029  #include "loki/Singleton.h"
00030 
00031  #include "../ascstring.h"
00032 
00034   class StatusMessageWindowHolder {
00035     public:
00036        class UserData {
00037              friend class StatusMessageWindowHolder;
00038              int counter;  
00039           public:
00040              UserData() : counter(1) {};
00041              virtual ~UserData() {};
00042              virtual void SetText( const ASCString& text ) {};
00043        
00044        };
00045     private:   
00046        UserData* userData;
00047     protected:
00048        void copy( const StatusMessageWindowHolder& smw );
00049        void unlink();
00050     public:
00051        StatusMessageWindowHolder();
00052        StatusMessageWindowHolder( UserData* ud ) : userData(ud) {};
00053        StatusMessageWindowHolder( const StatusMessageWindowHolder& smw );
00054        StatusMessageWindowHolder& operator=( const StatusMessageWindowHolder& smw );    
00055        void close();
00056        void SetText( const ASCString& text );
00057        virtual ~StatusMessageWindowHolder();
00058  };
00059 
00060 
00061  class MessagingHubBase {
00062       std::set<ASCString> enabledLogCategories;
00063 
00064     protected:
00065        int verbosity;
00066     
00067     public:
00068        MessagingHubBase() : verbosity(0) {};
00069        void setVerbosity( int v ) { verbosity = v; };
00070        int  getVerbosity() { return verbosity; };
00071        
00072        void setLoggingCategory( const ASCString& category, bool enable );
00073        bool logCategoryEnabled( const ASCString& category );
00074    
00075        enum MessageType { FatalError, Error, Warning, InfoMessage, StatusInfo, LogMessage };
00076        
00078        SigC::Signal1<void, const ASCString&> fatalError;
00079 
00081        SigC::Signal0<void> exitHandler;
00082               
00084        SigC::Signal1<void, const ASCString&> error;
00085        
00087        SigC::Signal1<void, const ASCString&> warning;
00088        
00090        SigC::Signal1<void, const ASCString&> infoMessage;
00091        
00093        SigC::Signal1<void, const ASCString&> statusInformation;
00094        
00096        SigC::Signal2<void, const ASCString&,int> logMessage;
00097 
00099        SigC::Signal2<void, const ASCString&,const ASCString&> logCategorizedMessage;
00100 
00102        void message( MessageType type, const char* msg, ... );
00103 
00105        void message( MessageType type, const ASCString& msg );
00106 
00107 
00117        StatusMessageWindowHolder infoMessageWindow( const ASCString& msg );
00118         
00120        SigC::Signal1<StatusMessageWindowHolder, const ASCString&> messageWindowFactory;
00121               
00122    };
00123        
00124  typedef Loki::SingletonHolder<MessagingHubBase,Loki::CreateUsingNew,Loki::NoDestroy > MessagingHub;
00125 
00126 
00127  
00128  extern void fatalError ( const char* formatstring, ... );
00129  extern void fatalError ( const ASCString& string );
00130  extern void errorMessage ( const ASCString& string );
00131  extern void warningMessage ( const ASCString& string );
00132  extern void infoMessage ( const ASCString& string );
00133  extern void statusMessage ( const ASCString& string );
00134        
00135  extern void displayLogMessage ( int msgVerbosity, const char* message, ... );
00136  extern void displayLogMessage ( int msgVerbosity, const ASCString& message );
00137  extern void logMessage ( const ASCString& category, const ASCString& message );
00138  
00139 #endif

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