QGpCoreTools/CoreApplicationPrivate.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2007-02-08
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef COREAPPLICATIONPRIVATE_H
00029 #define COREAPPLICATIONPRIVATE_H
00030 
00031 #include "QGpCoreToolsDLLExport.h"
00032 #include "PackageInfo.h"
00033 #include "AbstractStream.h"
00034 #include "Message.h"
00035 #include "ApplicationHelp.h"
00036 
00037 namespace QGpCoreTools {
00038 
00039 class PathTranslator;
00040 class ApplicationHelp;
00041 class Thread;
00042 
00043 class QGPCORETOOLS_EXPORT GlobalObject
00044 {
00045 public:
00046   GlobalObject() {}
00047   virtual ~GlobalObject() {}
00048 };
00049 
00050 class QGPCORETOOLS_EXPORT CoreApplicationPrivate
00051 {
00052   TRANSLATIONS("CoreApplicationPrivate")
00053 protected:
00054   CoreApplicationPrivate() {int argc=0; init(argc, 0);}
00055 public:
00056   CoreApplicationPrivate(int & argc, char ** argv) {init(argc, argv);}
00057   virtual ~CoreApplicationPrivate();
00058 
00059   static QString version();
00060   static QString version(QString item);
00061   static QString authors();
00062   virtual bool hasGui() const=0;
00063 
00064   static void checkBlocks(bool showLib, bool showUndeleted, const char * file=0, int line=0);
00065   static bool isBlockDamaged(void* v, const char * file, int line);
00066   static void printBlockInfo(void * ptr, const char * file, int line);
00067   static void setMemoryVerbose(bool v);
00068 
00069   static bool checkOptionArg(int& i, int argc, char ** argv, bool mandatory=true);
00070   void showHelp(int& i, int argc, char ** argv, ApplicationHelp * (*help)());
00071 
00072   static CoreApplicationPrivate * instance() {return _self;}
00073 
00074   void debugUserInterrupts(bool d);
00075   static QString backTrace();
00076   static QString backTraceBug();
00077   static QString bugInfo(Message::Severity sev, const QString& msg);
00078   static QString systemInfo();
00079   static QString appInfo();
00080   static QString platform();
00081   static void osSignal(int sigNum);
00082   static void messageOutput(QtMsgType type, const char *msg);
00083   static void messageOutputAbort(QtMsgType type, const char *msg);
00084   void reportBug(Message::Severity sev, const char * msg);
00085   void reportBugNow(Message::Severity sev, const char * msg);
00086   QThread * mainThread() const {return _thread;}
00087   static void sleep(int ms);
00088   static QString currentThreadName();
00089 
00090   Message * messageHandler() const {return _messageHandler;}
00091   QString translatePath(const QString& file, const QString& title, const QString& fileType);
00092 
00093   void setStream(AbstractStream * s, QThread * thread=0);
00094   void beginRedirectStream(AbstractStream * s, QThread * thread=0);
00095   void endRedirectStream(AbstractStream * s, QThread * thread=0);
00096   void freezeStream(bool b) const;
00097   void setStreamPrefix(const QString& prefix) {stream().setPrefix(prefix);}
00098   AbstractStream& stream(QThread * thread=0) const;
00099   void threadDeleted(Thread * thread);
00100 
00101   static void addGlobalObject(GlobalObject * ptr);
00102   static void removeGlobalObject(GlobalObject * ptr);
00103 
00104   static QString getStdin();
00105   static QStringList getFileList(int argc, char ** argv);
00106   static int userId();
00107   int terminalRows() const;
00108   int terminalCols() const;
00109 
00110   void addPlugin(QObject * p);
00111   void deletePlugin(QObject * p);
00112 
00113   static QString htmlBugReport(const QString& systemInfo, const QString& email=QString::null,
00114                                const QString &userInfo=QString::null);
00115 
00116   int maximumThreadCount() const {return _maximumThreadCount;}
00117 protected:
00118   void setTerminalSize();
00119   void askForUserInterrupt();
00120   void setMessageHandler(Message * m);
00121   static QString constructorApplicationName();
00122   void destructorCleanUp();
00123   void initInternalDebugger(bool reportBugs);
00124   void initTranslations();
00125   void checkAtomicOperations();
00126   virtual void setHelp(ApplicationHelp * h);
00127   void addArgumentList(int argc, char ** argv);
00128   void printArgumentLists() const;
00129 private:
00130   QList<QStringList> argumentLists() const;
00131   void terminalSize() const;
00132   void init (int & argc, char ** argv);
00133 
00134   static CoreApplicationPrivate * _self;
00135   static QString _crashingThread;
00136 
00137   QMap< QThread *, AbstractStream *> _streams;
00138   QThread * _thread;
00139   Message * _messageHandler;
00140   PathTranslator * _pathTranslator;
00141   QStringList _errors;
00142   QList<GlobalObject *> _globalPointers;
00143   QList<QObject *> _plugins;
00144   int _maximumThreadCount;
00145   bool _reportBugs, _debugUserInterrupts;
00146 
00147 
00148   mutable int _terminalCols, _terminalRows;
00149 };
00150 
00151 // Shorter name to access application function through static instance
00152 class App
00153 {
00154 public:
00155   static void setStream(AbstractStream * stream, QThread * thread=0) {
00156     return CoreApplicationPrivate::instance()->setStream(stream, thread);
00157   }
00158   static void beginRedirectStream(AbstractStream * stream, QThread * thread=0) {
00159     return CoreApplicationPrivate::instance()->beginRedirectStream(stream, thread);
00160   }
00161   static void endRedirectStream(AbstractStream * stream, QThread * thread=0) {
00162     return CoreApplicationPrivate::instance()->endRedirectStream(stream, thread);
00163   }
00164   static AbstractStream& stream(QThread * thread=0) {
00165     return CoreApplicationPrivate::instance()->stream(thread);
00166   }
00167   static void freezeStream(bool b) {
00168     CoreApplicationPrivate::instance()->freezeStream(b);
00169   }
00170   static void setStreamPrefix(const QString& prefix) {
00171     CoreApplicationPrivate::instance()->setStreamPrefix(prefix);
00172   }
00173   static void sleep(int ms) {
00174     CoreApplicationPrivate::sleep(ms);
00175   }
00176 };
00177 
00178 // Convenient macro definitions with code localization
00179 #ifdef MEMORY_CHECKER
00180 #define checkblocks(showLib, showUndeleted) CoreApplicationPrivate::checkBlocks(showLib, showUndeleted, __FILE__, __LINE__)
00181 #define isBlockDamaged(ptr) CoreApplicationPrivate::isBlockDamaged(ptr, __FILE__, __LINE__)
00182 #define printBlockInfo(ptr) CoreApplicationPrivate::printBlockInfo(ptr,__FILE__, __LINE__)
00183 #endif
00184 
00185 } // namespace QGpCoreTools
00186 
00187 #endif // COREAPPLICATIONPRIVATE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines