Brief description of class still missing. More...
#include <CoreApplicationPrivate.h>
Public Member Functions | |
void | addPlugin (QObject *p) |
void | beginRedirectStream (AbstractStream *s, QThread *thread=0) |
CoreApplicationPrivate (int &argc, char **argv) | |
void | debugUserInterrupts (bool d) |
void | deletePlugin (QObject *p) |
void | endRedirectStream (AbstractStream *s, QThread *thread=0) |
void | freezeStream (bool b) const |
virtual bool | hasGui () const =0 |
QThread * | mainThread () const |
int | maximumThreadCount () const |
Message * | messageHandler () const |
void | reportBug (Message::Severity sev, const char *msg) |
void | reportBugNow (Message::Severity sev, const char *msg) |
void | setStream (AbstractStream *s, QThread *thread=0) |
void | setStreamPrefix (const QString &prefix) |
void | showHelp (int &i, int argc, char **argv, ApplicationHelp *(*help)()) |
AbstractStream & | stream (QThread *thread=0) const |
int | terminalCols () const |
int | terminalRows () const |
void | threadDeleted (Thread *thread) |
QString | translatePath (const QString &file, const QString &title, const QString &fileType) |
virtual | ~CoreApplicationPrivate () |
Static Public Member Functions | |
static void | addGlobalObject (GlobalObject *ptr) |
static QString | appInfo () |
static QString | authors () |
static QString | backTrace () |
static QString | backTraceBug () |
static QString | bugInfo (Message::Severity sev, const QString &msg) |
static void | checkBlocks (bool showLib, bool showUndeleted, const char *file=0, int line=0) |
static bool | checkOptionArg (int &i, int argc, char **argv, bool mandatory=true) |
static QString | currentThreadName () |
static QStringList | getFileList (int argc, char **argv) |
static QString | getStdin () |
static QString | htmlBugReport (const QString &systemInfo, const QString &email=QString::null, const QString &userInfo=QString::null) |
static CoreApplicationPrivate * | instance () |
static bool | isBlockDamaged (void *v, const char *file, int line) |
static void | messageOutput (QtMsgType type, const char *msg) |
static void | messageOutputAbort (QtMsgType type, const char *msg) |
static void | osSignal (int sigNum) |
static QString | platform () |
static void | printBlockInfo (void *ptr, const char *file, int line) |
static void | removeGlobalObject (GlobalObject *ptr) |
static void | setMemoryVerbose (bool v) |
static void | sleep (int ms) |
static QString | systemInfo () |
static int | userId () |
static QString | version () |
static QString | version (QString item) |
Protected Member Functions | |
void | addArgumentList (int argc, char **argv) |
void | askForUserInterrupt () |
void | checkAtomicOperations () |
CoreApplicationPrivate () | |
void | destructorCleanUp () |
void | initInternalDebugger (bool reportBugs) |
void | initTranslations () |
void | printArgumentLists () const |
virtual void | setHelp (ApplicationHelp *h) |
void | setMessageHandler (Message *m) |
void | setTerminalSize () |
Static Protected Member Functions | |
static QString | constructorApplicationName () |
Brief description of class still missing.
Full description of class still missing
QGpCoreTools::CoreApplicationPrivate::CoreApplicationPrivate | ( | ) | [inline, protected] |
{int argc=0; init(argc, 0);}
QGpCoreTools::CoreApplicationPrivate::CoreApplicationPrivate | ( | int & | argc, |
char ** | argv | ||
) | [inline] |
{init(argc, argv);}
Description of destructor still missing
{ }
void QGpCoreTools::CoreApplicationPrivate::addArgumentList | ( | int | argc, |
char ** | argv | ||
) | [protected] |
Referenced by QGpGuiTools::Application::Application(), and QGpCoreTools::CoreApplication::CoreApplication().
{ QStringList arguments; arguments.reserve(argc+1); for(int i=0; i<argc; i++) { arguments.append(argv[i]); if(arguments.last()=="-args") { // Do not add to history return; } } QList<QStringList> list=argumentLists(); int index=list.indexOf(arguments); if(index>-1) { list.removeAt(index); } list.prepend(arguments); while(list.count()>50) list.removeLast(); QList<QVariant> tmplist; tmplist.reserve(list.count()); for(QList<QStringList>::const_iterator it=list.begin(); it!=list.end(); it++) { tmplist.append(*it); } QSettings reg; reg.setValue("applicationArguments", tmplist); }
void QGpCoreTools::CoreApplicationPrivate::addGlobalObject | ( | GlobalObject * | ptr | ) | [static] |
References instance().
Referenced by QGpGuiTools::PropertyEditor::PropertyEditor().
{ instance()->_globalPointers.append(ptr); }
void QGpCoreTools::CoreApplicationPrivate::addPlugin | ( | QObject * | p | ) |
QString QGpCoreTools::CoreApplicationPrivate::appInfo | ( | ) | [static] |
References systemInfo(), QGpCoreTools::XMLStringStream::toString(), version(), and QGpCoreTools::XMLClass::writeProperty().
Referenced by reportBugNow().
{ XMLStringStream s(QIODevice::WriteOnly); XMLClass::writeProperty(s, "application", QCoreApplication::applicationName()); XMLClass::writeProperty(s, "version", version()); XMLClass::writeProperty(s, "system", systemInfo()); return s.toString(); }
void QGpCoreTools::CoreApplicationPrivate::askForUserInterrupt | ( | ) | [protected] |
References QGpCoreTools::Message::Answer1, hasGui(), MSG_ID, QGpCoreTools::Message::no(), QGpCoreTools::Message::question(), QGpCoreTools::tr(), and QGpCoreTools::Message::yes().
Referenced by reportBugNow().
{ if(!hasGui()) printf("\n"); // Avoid uggly output if interrupt occured while printing something. if(Message::question(MSG_ID, tr("User interrupt"), tr("Is this process blocked? Answer 'Yes' to generate a bug report."), Message::yes(), Message::no())==Message::Answer1) { ::exit(0); } }
QString QGpCoreTools::CoreApplicationPrivate::authors | ( | ) | [static] |
Returns the authorship message
References QGpCoreTools::PackageInfo::list().
Referenced by QGpCoreTools::ApplicationHelp::exec().
{ QString appName=QCoreApplication::applicationName(); for(QList<PackageInfo>::iterator it=PackageInfo::list()->begin();it!=PackageInfo::list()->end(); it++ ) { if(it->package()==appName) { return it->authors(); } } return QString::null; }
QString QGpCoreTools::CoreApplicationPrivate::backTrace | ( | ) | [static] |
Analyse current stack and return it as a string
References QGpCoreTools::Thread::lockThreads(), str, QGpCoreTools::Thread::threadNames(), and QGpCoreTools::Thread::unlockThreads().
Referenced by backTraceBug(), and bugInfo().
{ QString str; #ifdef TRACE_ENABLED QStringList tList=Thread::threadNames(); Thread::lockThreads(); QList< QStack<const TraceStamp *> * > sList=Thread::stacks(); for(int i=0; i<sList.count(); i++ ) { str += "---- thread "; str += tList.at(i); str += "\n"; str += Trace::backTrace(sList.at(i)); } Thread::unlockThreads(); #elif defined(Q_WS_X11) && !defined(Q_CC_SUN) && !defined(NO_BACKTRACE) void *frames[50]; size_t size; char ** strings; size_t i; size=backtrace (frames, 50); strings=backtrace_symbols (frames, size); size_t functionLen=0; int status; // Demangle, see doc at http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/namespaceabi.html for(i=0; i < size; i++) { // get value between (...+ char * mangledName=strchr(strings[i], '(' ); if(mangledName) { char * mangledNameEnd=strchr(mangledName, '+' ); if(mangledNameEnd) { char * mangledString=new char[mangledNameEnd-mangledName]; strncpy(mangledString, mangledName+1, mangledNameEnd-mangledName-1); mangledString[mangledNameEnd-mangledName-1]='\0'; char * functionName=abi::__cxa_demangle(mangledString, 0, &functionLen, &status); str+=functionName; delete [] mangledString; } else { str+=strings[i]; } } else { str+=strings[i]; } str+="\n"; } /*str+="---- raw function names\n"; for(i=0; i < size; i++) { str+=strings[i]; str+="\n"; }*/ free (strings); #endif return str; }
QString QGpCoreTools::CoreApplicationPrivate::backTraceBug | ( | ) | [static] |
Analyse current stack for instrumented bugs and return it as a string
References backTrace(), QGpCoreTools::Thread::bugStacks(), QGpCoreTools::Thread::lockThreads(), QGpCoreTools::Thread::logVectors(), str, QGpCoreTools::Thread::threadNames(), and QGpCoreTools::Thread::unlockThreads().
Referenced by bugInfo().
{ QString str; QStringList tList=Thread::threadNames(); Thread::lockThreads(); QList< QStack<TraceBug *> * > sList=Thread::bugStacks(); for(int i=0; i<sList.count(); i++ ) { str += "---- thread "; str += tList.at(i); str += "\n"; str += TraceBug::backTrace(sList.at(i)); } QList< QVector<TraceLog *> * > lList=Thread::logVectors(); for(int i=0; i<lList.count(); i++ ) { str += "---- thread "; str += tList.at(i); str += "\n"; str += TraceLog::backTrace(lList.at(i)); } Thread::unlockThreads(); return str; }
void QGpCoreTools::CoreApplicationPrivate::beginRedirectStream | ( | AbstractStream * | s, |
QThread * | thread = 0 |
||
) |
Begins a redirection to stream s.
References QGpCoreTools::SharedObject::addReference(), QGpCoreTools::SharedObject::removeReference(), QGpCoreTools::AbstractStream::setNext(), and QGpCoreTools::AbstractStream::setPrevious().
Referenced by QGpCoreTools::App::beginRedirectStream().
{ if(!thread) { thread=QThread::currentThread(); } QMap<QThread *, AbstractStream *>::iterator it; it=_streams.find(thread); ASSERT(it!=_streams.end()); AbstractStream * original=it.value(); original->setNext(s); s->setPrevious(original); AbstractStream::removeReference(original); it.value()=s; s->addReference(); }
QString QGpCoreTools::CoreApplicationPrivate::bugInfo | ( | Message::Severity | sev, |
const QString & | msg | ||
) | [static] |
References backTrace(), backTraceBug(), QGpCoreTools::Message::severityString(), QGpCoreTools::Thread::threadNames(), QGpCoreTools::XMLStringStream::toString(), and QGpCoreTools::XMLClass::writeProperty().
Referenced by reportBug(), and reportBugNow().
{ XMLStringStream s(QIODevice::WriteOnly); XMLClass::writeProperty(s, "severity", Message::severityString(sev)); XMLClass::writeProperty(s, "message", msg); XMLClass::writeProperty(s, "time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")); XMLClass::writeProperty(s, "threads", Thread::threadNames().join(",")); XMLClass::writeProperty(s, "currentThread", _crashingThread); XMLClass::writeProperty(s, "stack", backTrace()); XMLClass::writeProperty(s, "bugStack", backTraceBug()); return s.toString(); }
void QGpCoreTools::CoreApplicationPrivate::checkAtomicOperations | ( | ) | [protected] |
Check whether atomic operations are available for current processor and issue warnings if not satisfied. Implemented for Qt>=4.4.0. Streams must be initialized
References QGpCoreTools::endl(), and stream().
Referenced by QGpGuiTools::Application::Application(), and QGpCoreTools::CoreApplication::CoreApplication().
{ #if(QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)) /* Currently not used in sesarray package so left commented if( !QAtomicInt::isReferenceCountingNative()) App::stream() << "WARNING: Atomic 'reference counting' is not available for your processor" << endl; if(!QAtomicInt::isFetchAndAddNative()) App::stream() << "WARNING: Atomic 'fetch and add' is not available for your processor" << endl; */ if( !QAtomicInt::isTestAndSetNative()) App::stream() << "WARNING: Atomic 'test and set' is not available for your processor" << endl; if( !QAtomicInt::isFetchAndStoreNative()) App::stream() << "WARNING: Atomic 'fetch and store' is not available for your processor" << endl; #endif }
void QGpCoreTools::CoreApplicationPrivate::checkBlocks | ( | bool | showLib, |
bool | showUndeleted, | ||
const char * | file = 0 , |
||
int | line = 0 |
||
) | [static] |
Check for undeleted blocks
Referenced by destructorCleanUp().
{ #ifdef DO_MEMORY_CHECK MemoryCheckerPrivate::checkBlocks(showLib, showUndeleted, file, line); #else Q_UNUSED(showLib) Q_UNUSED(showUndeleted) Q_UNUSED(file) Q_UNUSED(line) #endif }
bool QGpCoreTools::CoreApplicationPrivate::checkOptionArg | ( | int & | i, |
int | argc, | ||
char ** | argv, | ||
bool | mandatory = true |
||
) | [static] |
Check if option argument at i is available. If not and if mandatory is true, the application exits with error code 2. Else, it returns true if an argument is available.
This function can be used even without a QtbCoreApplication running.
References QGpCoreTools::endl(), sOut(), and QGpCoreTools::tr().
Referenced by showHelp().
{ i++; if(i<argc) { bool ok; if(argv[i][0]=='-' ) { QByteArray option(argv[i]); option.toDouble(&ok); if(ok) { // Argument is a number return true; } if(option.contains(" ")) { // Argument contains spaces, certainly not an option return true; } } else return true; } if(mandatory) { // Do not use app because it is not sure whether it is already created. QTextStream sOut(stderr); sOut << tr("Option %1 requires an argument, see -help for details.").arg(argv[i-1] ) << ::endl; ::exit(2); } i--; // Not a mandatory argument return false; }
QString QGpCoreTools::CoreApplicationPrivate::constructorApplicationName | ( | ) | [static, protected] |
Internal use only: needed in CoreApplication and Application constructors. There QCoreApplication::applicationName() is not yet available. As progam is executed this function no longer returns the application name if plugins are loaded.
References QGpCoreTools::PackageInfo::list().
Referenced by QGpCoreTools::CoreApplication::CoreApplication().
{ return PackageInfo::list()->last().package(); }
QString QGpCoreTools::CoreApplicationPrivate::currentThreadName | ( | ) | [static] |
Returns name of currently running thread
Referenced by osSignal().
{ Thread * t=qobject_cast<Thread *>(QThread::currentThread()); if(t) { return t->objectName(); } else { return "main thread"; } }
void QGpCoreTools::CoreApplicationPrivate::debugUserInterrupts | ( | bool | d | ) |
References osSignal(), and TRACE.
Referenced by QGpCoreTools::ArgumentStdinReader::read(), and QGpCoreTools::File::readLine().
void QGpCoreTools::CoreApplicationPrivate::deletePlugin | ( | QObject * | p | ) |
void QGpCoreTools::CoreApplicationPrivate::destructorCleanUp | ( | ) | [protected] |
In normal destructor, QCoreApplication is no longer available, hence strange behavior. This function must be called by CoreApplication and other related objects
References checkBlocks(), QGpCoreTools::AbstractNumericalCache::clear(), QGpCoreTools::XMLClassFactory::clearFactories(), QGpCoreTools::TraceLog::clearMainVector(), QGpCoreTools::SharedObject::removeReference(), reportBugNow(), and QGpCoreTools::Message::Warning.
Referenced by QGpGuiTools::Application::~Application(), QGpCoreTools::CoreApplication::~CoreApplication(), QGpGuiTools::PluginApplication::~PluginApplication(), and QGpCoreTools::PluginCoreApplication::~PluginCoreApplication().
{ AbstractNumericalCache::clear(); delete _pathTranslator; XMLClassFactory::clearFactories(); delete _messageHandler; qDeleteAll(_plugins); TraceLog::clearMainVector(); // Cleanup global pointers qDeleteAll(_globalPointers); // Clear streams foreach(AbstractStream * s, _streams) { AbstractStream::removeReference(s); } checkBlocks(false, true); if(!_errors.isEmpty()) { reportBugNow(Message::Warning, "Quitting application with remaining error messages" ); } }
void QGpCoreTools::CoreApplicationPrivate::endRedirectStream | ( | AbstractStream * | s, |
QThread * | thread = 0 |
||
) |
Ends a redirection to stream s.
References QGpCoreTools::AbstractStream::next(), QGpCoreTools::AbstractStream::previous(), QGpCoreTools::SharedObject::removeReference(), QGpCoreTools::AbstractStream::setNext(), and QGpCoreTools::AbstractStream::setPrevious().
Referenced by QGpCoreTools::App::endRedirectStream().
{ ASSERT(s->previous()); if(!thread) { thread=QThread::currentThread(); } if(s->next()) { // This is not the current stream, another redirection is active s->next()->setPrevious(s->previous()); // s might be deleted here according to reference counting } else { QMap<QThread *, AbstractStream *>::iterator it; it=_streams.find(thread); ASSERT(it!=_streams.end()); ASSERT(it.value()==s); AbstractStream * original=s->previous(); original->setNext(0); it.value()=original; original->addReference(); AbstractStream::removeReference(s); } }
void QGpCoreTools::CoreApplicationPrivate::freezeStream | ( | bool | b | ) | const |
References QGpCoreTools::AbstractStream::freeze(), and stream().
Referenced by dispersion_curve_init_(), and QGpCoreTools::App::freezeStream().
QStringList QGpCoreTools::CoreApplicationPrivate::getFileList | ( | int | argc, |
char ** | argv | ||
) | [static] |
Convert all remaining arguments into file names (accepting wildchars)
Referenced by main().
{ QStringList files; for(int index=1; index < argc; index++) files.append(argv[index]); // Replace file names that include "*" with all their corresponding entries QDir d; QStringList result; QString file; foreach(file, files) { QFileInfo fi (file); QDir dloc(d); dloc.cd(fi.dir().path()); QStringList filters; filters << fi.fileName(); QStringList list=dloc.entryList(filters); foreach(file, list) result << dloc.absoluteFilePath(file); } return result; }
QString QGpCoreTools::CoreApplicationPrivate::getStdin | ( | ) | [static] |
Read stdin until a line ending by 'END'. Mostly used by '-reportbug' option to read backtrace infromation.
References QGpCoreTools::File::readLine(), str, and TRACE.
{ TRACE; QString str; while(true) { QString l=File::readLine(false); if(l=="END\n") break; str+=l; } return str; }
virtual bool QGpCoreTools::CoreApplicationPrivate::hasGui | ( | ) | const [pure virtual] |
Implemented in QGpGuiTools::Application, QGpCoreTools::CoreApplication, QGpCoreTools::PluginCoreApplication, and QGpGuiTools::PluginApplication.
Referenced by askForUserInterrupt(), and reportBugNow().
QString QGpCoreTools::CoreApplicationPrivate::htmlBugReport | ( | const QString & | systemInfo, |
const QString & | email = QString::null , |
||
const QString & | userInfo = QString::null |
||
) | [static] |
References userId().
{ QString h; h="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" "<html>\n" "<head>\n" " <title>Report a bug to Geopsy.org</title>\n" "</head>\n" "<body>\n" "<form action=\"http://www.geopsy.org/bugs/backtrace.php\" method=\"post\">\n" " <input type=\"hidden\" name=\"userid\" value=\"%1\"/>\n" " <b>Your email*:</b> <input name=\"email\" type=\"text\" value=\"%2\" size=\"45\"/>\n" " <input type=\"submit\" value=\"Submit\"/><br/>\n" " <b>Environment and crash information:</b><br/>\n" " <textarea name=\"systemInfo\" rows=\"20\" cols=\"80\" readonly>\n" "%3\n" "</textarea><br/>\n" " <b>Additional information:</b><br/>\n" " Can you reproduce the application crash? How did it happen?...<br/>\n" "<textarea name=\"userInfo\" rows=\"20\" cols=\"80\">%4</textarea><br/>\n" "</form>\n" "</body></html>"; return h.arg(userId()).arg(email).arg(systemInfo).arg(userInfo); }
void QGpCoreTools::CoreApplicationPrivate::initInternalDebugger | ( | bool | reportBugs | ) | [protected] |
References messageOutput(), messageOutputAbort(), and osSignal().
Referenced by QGpGuiTools::Application::Application(), and QGpCoreTools::CoreApplication::CoreApplication().
{ _reportBugs=reportBugs; if(_reportBugs) { // Redirect exception signals signal (SIGABRT, osSignal); signal (SIGSEGV, osSignal); #ifndef Q_WS_WIN signal (SIGBUS, osSignal); #endif // User interrupts _debugUserInterrupts=true; signal (SIGINT, osSignal); signal (SIGTERM, osSignal); // Redirect ASSERT messages qInstallMsgHandler(messageOutput); } else { // Redirect ASSERT messages qInstallMsgHandler(messageOutputAbort); } }
void QGpCoreTools::CoreApplicationPrivate::initTranslations | ( | ) | [protected] |
References instance(), and QGpCoreTools::PackageInfo::list().
Referenced by QGpGuiTools::Application::Application(), and QGpCoreTools::CoreApplication::CoreApplication().
{ for(QList<PackageInfo>::iterator it=PackageInfo::list()->begin();it!=PackageInfo::list()->end(); it++ ) { QString langFile=it->package()+"."+QLocale::system().name(); QTranslator * t=new QTranslator(QCoreApplication::instance()); QDir d(it->shareDir()); d.cd("lang"); if(t->load(langFile, d.absolutePath())) { QCoreApplication::instance()->installTranslator(t); } else { delete t; switch (QLocale::system().language()) { case QLocale::C: case QLocale::English: break; default: { // In any case the graphical log viewer is still not started. Hence this message will be lost // to system terminal. For command line tools (e.g. gpdcreport) these kind of message must be // sent through stderr and the redirection of the main application stream is done after the // application initialization. Therefore we use the normal stderr directly. // Remove the warning... rather useless, kept only for debug. //QTextStream s(stderr); //s << QString("No translation found for language %1" ).arg(QLocale::system().name()) << ::endl; } break; } } } }
static CoreApplicationPrivate* QGpCoreTools::CoreApplicationPrivate::instance | ( | ) | [inline, static] |
Reimplemented in QGpGuiTools::Application, and QGpCoreTools::CoreApplication.
Referenced by addGlobalObject(), QGpCoreTools::App::beginRedirectStream(), QGpCoreTools::App::endRedirectStream(), QGpCoreTools::App::freezeStream(), initTranslations(), QGpCoreTools::CoreApplication::instance(), messageOutput(), osSignal(), removeGlobalObject(), reportBugNow(), QGpCoreTools::App::setStream(), QGpCoreTools::App::setStreamPrefix(), and QGpCoreTools::App::stream().
{return _self;}
bool QGpCoreTools::CoreApplicationPrivate::isBlockDamaged | ( | void * | v, |
const char * | file, | ||
int | line | ||
) | [static] |
Check for damaged blocks
{ #ifdef DO_MEMORY_CHECK return MemoryCheckerPrivate::isBlockDamaged(v, file, line); #else Q_UNUSED(v) Q_UNUSED(file) Q_UNUSED(line) return false; #endif }
QThread* QGpCoreTools::CoreApplicationPrivate::mainThread | ( | ) | const [inline] |
{return _thread;}
int QGpCoreTools::CoreApplicationPrivate::maximumThreadCount | ( | ) | const [inline] |
Referenced by QGpCoreTools::Thread::idealThreadCount(), and QGpGuiTools::LoopProgressWidget::setLoop().
{return _maximumThreadCount;}
Message* QGpCoreTools::CoreApplicationPrivate::messageHandler | ( | ) | const [inline] |
Referenced by QGpCoreTools::Message::critical(), QGpCoreTools::Message::getExistingDirectory(), QGpCoreTools::Message::getOpenFileName(), QGpCoreTools::Message::getOpenFileNames(), QGpCoreTools::Message::getSaveFileName(), QGpCoreTools::Message::information(), QGpCoreTools::MessageContext::MessageContext(), QGpCoreTools::Message::question(), QGpCoreTools::Message::warning(), and QGpCoreTools::MessageContext::~MessageContext().
{return _messageHandler;}
void QGpCoreTools::CoreApplicationPrivate::messageOutput | ( | QtMsgType | type, |
const char * | msg | ||
) | [static] |
Receive all message from Qt library, stack warning or output bugs
References QGpCoreTools::Message::Critical, QGpCoreTools::Message::Fatal, QGpCoreTools::Message::Information, instance(), reportBug(), reportBugNow(), and QGpCoreTools::Message::Warning.
Referenced by initInternalDebugger().
{ qInstallMsgHandler(0); // avoid recursion switch (type) { case QtDebugMsg: #ifdef QT_NO_DEBUG instance()->reportBug(Message::Information, msg); #else printf("[qDebug] Information: %s\n", msg); #endif break; case QtWarningMsg: instance()->reportBug(Message::Warning, msg); break; case QtCriticalMsg: instance()->reportBug(Message::Critical, msg); break; case QtFatalMsg: instance()->reportBugNow(Message::Fatal, msg); ::exit(2); } qInstallMsgHandler(messageOutput); }
void QGpCoreTools::CoreApplicationPrivate::messageOutputAbort | ( | QtMsgType | type, |
const char * | msg | ||
) | [static] |
Receive all message from Qt library, stack warning or output bugs
Referenced by initInternalDebugger().
{ qInstallMsgHandler(0); // avoid recursion switch (type) { case QtDebugMsg: printf("[qDebug] Information: %s\n", msg); break; case QtWarningMsg: printf("[qDebug] Warning: %s\n", msg); break; case QtCriticalMsg: printf("[qDebug] Critical: %s\n", msg); break; case QtFatalMsg: printf("[qDebug] Fatal: %s\n", msg); abort(); } qInstallMsgHandler(messageOutputAbort); }
void QGpCoreTools::CoreApplicationPrivate::osSignal | ( | int | sig | ) | [static] |
In case an exception occurs during normal execution
References currentThreadName(), QGpCoreTools::Message::Fatal, instance(), reportBugNow(), and sleep().
Referenced by debugUserInterrupts(), and initInternalDebugger().
{ static QAtomicInt lock=false; if(lock.fetchAndStoreOrdered(true)) { signal(sig, SIG_DFL); sleep(10000); fprintf(stderr, "Exception occured while processing exceptions.\n"); fprintf(stderr, "No backtrace information can be provided\n"); fprintf(stderr, "Eventually kill remaining instances:\n"); fprintf(stderr, " ps\n" ); fprintf(stderr, " pkill <application name>\n" ); ::exit(2); } _crashingThread=currentThreadName(); switch (sig) { case SIGABRT: instance()->reportBugNow(Message::Fatal, "Abort Signal" ); break; case SIGINT: instance()->reportBugNow(Message::Fatal, "Interrupted Signal" ); break; case SIGTERM: instance()->reportBugNow(Message::Fatal, "Terminated Signal" ); break; case SIGSEGV: instance()->reportBugNow(Message::Fatal, "Segmentation fault Signal" ); break; #ifndef Q_WS_WIN case SIGBUS: instance()->reportBugNow(Message::Fatal, "Bus error Signal" ); break; #endif default: break; } ::exit(2); }
QString QGpCoreTools::CoreApplicationPrivate::platform | ( | ) | [static] |
Returns platform codes compatible with download website Used only by UpdateIcon to retrieve the most up-to-date release.
{ #if defined(Q_WS_WIN) return "win32"; #elif defined(Q_WS_MAC) switch (QSysInfo::MacintoshVersion) { case QSysInfo::MV_9: case QSysInfo::MV_CHEETAH: case QSysInfo::MV_PUMA: case QSysInfo::MV_JAGUAR: case QSysInfo::MV_PANTHER: case QSysInfo::MV_TIGER: case QSysInfo::MV_Unknown: return "mac-notsupported"; case QSysInfo::MV_LEOPARD: if(QSysInfo::ByteOrder==QSysInfo::BigEndian) { return "mac-ppc-leopard"; } else { return "mac-intel-leopard"; } case QSysInfo::MV_SNOWLEOPARD: return "mac-snowleopard"; case QSysInfo::MV_LION: return "mac-lion"; case QSysInfo::MV_MOUNTAINLION: return "mac-mountainlion"; } #else return "src"; #endif }
void QGpCoreTools::CoreApplicationPrivate::printArgumentLists | ( | ) | const [protected] |
References QGpCoreTools::flush(), and QGpCoreTools::tr().
Referenced by QGpGuiTools::Application::Application(), and QGpCoreTools::CoreApplication::CoreApplication().
{ QList<QStringList> list=argumentLists(); QTextStream s(stdout); s << tr("# History of command line arguments:\n"); for(int i=list.count()-1; i>=0; i--) { const QStringList& args=list.at(i); QStringList::const_iterator ita=args.begin(); if(args.count()>2) { s << *ita; for(ita++; ita!=args.end(); ita++) { QString arg=*ita; arg.replace(" ", "\\ "); s << " " << arg; } } s << "\n"; } s << ::flush; }
void QGpCoreTools::CoreApplicationPrivate::printBlockInfo | ( | void * | ptr, |
const char * | file, | ||
int | line | ||
) | [static] |
Print block information
{ #ifdef DO_MEMORY_CHECK MemoryCheckerPrivate::printBlockInfo(ptr, file, line); #else Q_UNUSED(ptr) Q_UNUSED(file) Q_UNUSED(line) #endif }
void QGpCoreTools::CoreApplicationPrivate::removeGlobalObject | ( | GlobalObject * | ptr | ) | [static] |
References instance().
void QGpCoreTools::CoreApplicationPrivate::reportBug | ( | Message::Severity | sev, |
const char * | msg | ||
) |
Delayed bug report to user (wait for end of program). Not fatal error message. Stack it and report only when quitting or on fatal error
References bugInfo(), QGpCoreTools::Message::Fatal, reportBugNow(), QGpCoreTools::Message::severityString(), and str.
Referenced by QGpCoreTools::Cache::enlarge(), QGpCoreTools::Cache::makeAvailable(), and messageOutput().
{ QString str=bugInfo(sev, msg); printf("[bug report] %s: %s\n", Message::severityString(sev).toAscii().data(), msg); // Bug submitted to trolltech internal to QWorkspace on closing application QByteArray msgBA(msg); if(msgBA.startsWith("QCoreApplication::postEvent: Unexpected null receiver")) return; // Message output under Mac by graphical applications //if(msgBA.startsWith("QObject::moveToThread")) return; // Message output given when restoring workspaces after an upgrade if(msgBA.startsWith("QMainWindow::restoreState()")) return; // Message output given by Qt especially under Windows if(msgBA.startsWith("QObject::startTimer")) return; if(msgBA.startsWith("QFileSystemWatcher: failed to add paths:")) return; // Common message received under Linux for Qt 4.7 if(msgBA.startsWith("X Error: BadWindow (invalid Window parameter) 3")) return; if(msgBA.startsWith("X Error")) { /*static bool userNotWarned=true; if (userNotWarned) { userNotWarned=false; Message::warning(MSG_ID, translate("CoreApplicationPrivate", "X11 server error"), tr("If you are running this application through a ssh connection, " "you can avoid X11 errors and improve the graphical quality by a proper configuration of your X11 server. " "See http://www.geopsy.org/faq.html for details.")); }*/ //return; } // Message received when paper size is not supported by print driver if(msgBA.startsWith("QPrinter::setPaperSize: Illegal paper size")) return; // Message received under X11, when closing many Geopsy.org applications in one action if(msgBA.startsWith("QClipboard::setData: Cannot set X11 selection owner for CLIPBOARD")) return; if(msgBA.startsWith("Application asked to unregister timer")) { reportBugNow(Message::Fatal, msg); // debug those warnings } _errors << str; }
void QGpCoreTools::CoreApplicationPrivate::reportBugNow | ( | Message::Severity | sev, |
const char * | msg | ||
) |
Immediate bug report to user (fatal or quitting application)
References appInfo(), askForUserInterrupt(), bugInfo(), hasGui(), instance(), str, QGpCoreTools::XMLStringStream::toString(), and QGpCoreTools::XMLClass::writeChildren().
Referenced by destructorCleanUp(), messageOutput(), osSignal(), and reportBug().
{ XMLStringStream sError(QIODevice::WriteOnly); XMLClass::writeChildren(sError, "Error", bugInfo(sev, msg)); if(!_errors.isEmpty()) { for(int i=_errors.count()-1;i>=0;i--) { XMLClass::writeChildren(sError, "Error", _errors.at(i)); } _errors.clear(); } XMLStringStream sReport(QIODevice::WriteOnly); XMLClass::writeChildren(sReport, "CrashReport", sError.toString() + appInfo()); QString str=sReport.toString(); QProcess p; p.setProcessChannelMode(QProcess::ForwardedChannels); if(strcmp(msg,"Terminated Signal")==0 || strcmp(msg,"Interrupted Signal")==0) { if(!hasGui()) instance()->askForUserInterrupt(); p.start("\""+QCoreApplication::applicationFilePath()+"\" -reportint"); } else { p.start("\""+QCoreApplication::applicationFilePath()+"\" -reportbug"); } p.write(str.toAscii().data()); p.write("END\n"); if(p.waitForStarted(10000)) { while(!p.waitForFinished (10000)) {} } else { QString bugFileName=QDir::home().absoluteFilePath("sendmeto_bug_at_geopsy.org"); FILE * f=fopen(bugFileName.toAscii().data(),"a"); fprintf(f,"%s\n",str.toAscii().data()); fclose(f); printf("Cannot restart \"%s\" in bug report mode (timed out)\n",QCoreApplication::applicationFilePath().toAscii().data()); printf("Bug report save in %s.\nPlease send this bug report to bug@geopsy.org\n",bugFileName.toAscii().data()); } }
void QGpCoreTools::CoreApplicationPrivate::setHelp | ( | ApplicationHelp * | h | ) | [protected, virtual] |
Reimplemented in QGpGuiTools::Application.
References QGpCoreTools::ApplicationHelp::addGroup(), QGpCoreTools::ApplicationHelp::addOption(), QGpCoreTools::ApplicationHelp::sections(), str, and QGpCoreTools::tr().
Referenced by showHelp().
{ QList<QByteArray> sections=h->sections(); qSort(sections); QString str=tr("Shows help. SECTION may be empty or: all, html, latex, generic, debug"); for(QList<QByteArray>::iterator it=sections.begin();it!=sections.end();it++) { str+= ", " + *it; } h->addGroup(tr("Generic"),"generic"); h->addOption(tr("-h, -help [<SECTION>]"), str); h->addOption(tr("-args"), tr("Lists the argument history")); h->addOption(tr("-version"), tr("Shows version information")); h->addOption(tr("-app-version"), tr("Shows short version information")); h->addOption(tr("-j, -jobs <N>"), tr("Allows a maximum of N simulteneous jobs for parallel " "computations (default=%1).").arg(QThread::idealThreadCount())); h->addGroup(tr("Debug"),"debug"); h->addOption(tr("-nobugreport"), tr("Does not generate bug reports in case of error.")); h->addOption(tr("-reportbug"), tr("Starts bug report dialog, information about bug is passed through stdin. This " "option is used internally to report bugs if option -nobugreport is not " "specified.")); h->addOption(tr("-reportint"), tr("Starts bug report dialog, information about interruption is passed through stdin. This " "option is used internally to report interruptions if option -nobugreport is not " "specified.")); }
void QGpCoreTools::CoreApplicationPrivate::setMemoryVerbose | ( | bool | v | ) | [static] |
{ #ifdef DO_MEMORY_CHECK MemoryCheckerPrivate::setVerbose(v); #else Q_UNUSED(v) #endif }
void QGpCoreTools::CoreApplicationPrivate::setMessageHandler | ( | Message * | m | ) | [protected] |
Referenced by QGpGuiTools::Application::Application(), QGpCoreTools::CoreApplication::CoreApplication(), QGpGuiTools::PluginApplication::PluginApplication(), QGpCoreTools::PluginCoreApplication::PluginCoreApplication(), QGpGuiTools::Application::setConsoleMessage(), and QGpGuiTools::Application::setGuiMessage().
{
delete _messageHandler;
_messageHandler=m;
}
void QGpCoreTools::CoreApplicationPrivate::setStream | ( | AbstractStream * | s, |
QThread * | thread = 0 |
||
) |
References QGpCoreTools::SharedObject::addReference(), and QGpCoreTools::SharedObject::removeReference().
Referenced by QGpGuiTools::LogWidget::addView(), main(), and QGpCoreTools::App::setStream().
{ if(!thread) { thread=QThread::currentThread(); } QMap<QThread *, AbstractStream *>::iterator it; it=_streams.find(thread); if(it!=_streams.end()) { AbstractStream * original=it.value(); AbstractStream::removeReference(original); it.value()=s; } else { _streams.insert(thread, s); } s->addReference(); }
void QGpCoreTools::CoreApplicationPrivate::setStreamPrefix | ( | const QString & | prefix | ) | [inline] |
Referenced by main(), and QGpCoreTools::App::setStreamPrefix().
void QGpCoreTools::CoreApplicationPrivate::setTerminalSize | ( | ) | [protected] |
void QGpCoreTools::CoreApplicationPrivate::showHelp | ( | int & | i, |
int | argc, | ||
char ** | argv, | ||
ApplicationHelp *(*)() | help | ||
) |
References checkOptionArg(), QGpCoreTools::ApplicationHelp::exec(), help(), and setHelp().
Referenced by QGpGuiTools::Application::Application(), QGpCoreTools::CoreApplication::CoreApplication(), and main().
{ ApplicationHelp * h=help(); setHelp(h); if(checkOptionArg(i, argc, argv, false)) { h->exec(argv[i]); } else { h->exec(); } delete h; }
void QGpCoreTools::CoreApplicationPrivate::sleep | ( | int | ms | ) | [static] |
Cross-platform sleep main thread for ms milliseconds
Referenced by osSignal().
{ #ifdef Q_WS_WIN ::Sleep(ms); #else if(ms>10000) ::sleep(ms/1000); else ::usleep(ms*1000); #endif }
AbstractStream & QGpCoreTools::CoreApplicationPrivate::stream | ( | QThread * | thread = 0 | ) | const |
Returns a reference to the current stream of thread.
Referenced by checkAtomicOperations(), freezeStream(), QGpGuiTools::LogWidget::removeView(), QGpGuiTools::LogWidget::setViewName(), QGpCoreTools::App::stream(), and QGpGuiTools::LogWidget::text().
{ if(!thread) { thread=QThread::currentThread(); } QMap<QThread *, AbstractStream *>::const_iterator it; it=_streams.find(thread); if(it==_streams.end()) { // Current thread has no attached stream, back to application // default stream. it=_streams.find(_thread); } return * it.value(); }
QString QGpCoreTools::CoreApplicationPrivate::systemInfo | ( | ) | [static] |
Referenced by appInfo().
{ #if defined(Q_WS_WIN) switch (QSysInfo::WindowsVersion) { case QSysInfo::WV_DOS_based: case QSysInfo::WV_32s: return "Windows 3.1"; case QSysInfo::WV_95: return "Windows 95"; case QSysInfo::WV_98: return "Windows 98"; case QSysInfo::WV_Me: return "Windows Me"; case QSysInfo::WV_NT_based: case QSysInfo::WV_NT: return "Windows NT"; case QSysInfo::WV_2000: return "Windows 2000"; case QSysInfo::WV_XP: return "Windows XP"; case QSysInfo::WV_2003: return "Windows Server 2003"; case QSysInfo::WV_VISTA: return "Windows Vista"; case QSysInfo::WV_WINDOWS7: return "Windows 7"; case QSysInfo::WV_WINDOWS8: return "Windows 8"; case QSysInfo::WV_CE_based: case QSysInfo::WV_CE: return "Windows CE\n"; case QSysInfo::WV_CE_5: return "Windows CE 5\n"; case QSysInfo::WV_CE_6: return "Windows CE 6\n"; case QSysInfo::WV_CENET: return "Windows CE .NET"; } return "Windows ??"; #elif defined(Q_WS_MAC) switch (QSysInfo::MacintoshVersion) { case QSysInfo::MV_Unknown: break; case QSysInfo::MV_9: return "Mac OS 9"; case QSysInfo::MV_CHEETAH: return "Mac OS X Cheetah (10.0)"; case QSysInfo::MV_PUMA: return "Mac OS X Puma (10.1)"; case QSysInfo::MV_JAGUAR: return "Mac OS X Jaguar (10.2)"; case QSysInfo::MV_PANTHER: return "Mac OS X Panther (10.3)"; case QSysInfo::MV_TIGER: return "Mac OS X Tiger (10.4)"; case QSysInfo::MV_LEOPARD: return "Mac OS X Leopard (10.5)"; case QSysInfo::MV_SNOWLEOPARD: return "Mac OS X Snow Leopard (10.6)"; case QSysInfo::MV_LION: return "Mac OS X Lion (10.7)"; case QSysInfo::MV_MOUNTAINLION: return "Mac OS X Mountain Liom (10.8)"; } return "Mac OS X ??"; #else QProcess uname; uname.start("uname"); if(uname.waitForFinished(-1)) { return uname.readAll().data(); } else { return "Linux"; } #endif }
int QGpCoreTools::CoreApplicationPrivate::terminalCols | ( | ) | const |
{ if(_terminalCols==0) { terminalSize(); } return _terminalCols; }
int QGpCoreTools::CoreApplicationPrivate::terminalRows | ( | ) | const |
{ if(_terminalRows==0) { terminalSize(); } return _terminalRows; }
void QGpCoreTools::CoreApplicationPrivate::threadDeleted | ( | Thread * | thread | ) |
Remove references attached to thread.
References QGpCoreTools::SharedObject::removeReference().
Referenced by QGpCoreTools::Thread::~Thread().
{ QMap<QThread *, AbstractStream *>::const_iterator it; it=_streams.find(thread); if(it!=_streams.end()) { AbstractStream::removeReference(it.value()); _streams.remove(thread); } }
QString QGpCoreTools::CoreApplicationPrivate::translatePath | ( | const QString & | file, |
const QString & | title, | ||
const QString & | fileType | ||
) |
Return a translated path. If not successuful (user cancel), the string is empty.
References QGpCoreTools::PathTranslator::translate().
{ if(!_pathTranslator) { _pathTranslator=new PathTranslator; } return _pathTranslator->translate(file, title, fileType); }
int QGpCoreTools::CoreApplicationPrivate::userId | ( | ) | [static] |
Return an integer that "uniquely" identify the user. In fact this is just random number stored in QSettings. It is initialized only if not found in QSettings. This is mainly used to identify different users behind a proxy server. Each user is then identified by its IP address or http proxy address (if any) and this integer number.
Referenced by htmlBugReport().
{ #ifdef Q_WS_MAC QSettings reg(QCoreApplication::organizationDomain()); #else QSettings reg(QCoreApplication::organizationName()); #endif if(reg.contains("id")) { return reg.value("id").toInt(); } else { int id=rand(); reg.setValue("id",id); return id; } }
QString QGpCoreTools::CoreApplicationPrivate::version | ( | ) | [static] |
Returns a complete description of all versions
References QGpCoreTools::PackageInfo::list(), and str.
Referenced by appInfo().
{ QString str=" Qt "; str+=qVersion(); str+="\n"; for(QList<PackageInfo>::iterator it=PackageInfo::list()->begin();it!=PackageInfo::list()->end(); it++ ) { str+=" "+it->package().leftJustified(20,' ')+it->version(); if(it->distribution().isEmpty()) { str+="\n"; } else { str+=" from "+it->distribution()+"\n"; } str+=" (built on "+it->versionTime()+")\n"; } return str; }
QString QGpCoreTools::CoreApplicationPrivate::version | ( | QString | item | ) | [static] |
Returns the version of item
References QGpCoreTools::PackageInfo::list().
{ for(QList<PackageInfo>::iterator it=PackageInfo::list()->begin();it!=PackageInfo::list()->end(); it++ ) { if(it->package()==item) { return it->version(); } } return QString::null; }