• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KInit

kioslave.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of the KDE libraries
00003  * Copyright (c) 1999-2000 Waldo Bastian <bastian@kde.org>
00004  *           (c) 1999 Mario Weilguni <mweilguni@sime.com>
00005  *           (c) 2001 Lubos Lunak <l.lunak@kde.org>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License version 2 as published by the Free Software Foundation.
00010  *
00011  * This library 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 GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include <kdebug.h>
00023 #include <config.h>
00024 
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <errno.h>
00028 #include <locale.h>
00029 
00030 #include <QtCore/QString>
00031 #include <QtCore/QLibrary>
00032 #include <QtCore/QFile>
00033 #ifdef Q_WS_WIN
00034 #include <QtCore/QDir>
00035 #include <QtCore/QProcess>
00036 #include <QtCore/QStringList>
00037 #include <windows.h>
00038 #include <process.h>
00039 #include "kstandarddirs.h"
00040 #endif
00041 
00042 #ifndef Q_WS_WIN
00043 /* These are to link libkio even if 'smart' linker is used */
00044 #include <kio/authinfo.h>
00045 extern "C" KIO::AuthInfo* _kioslave_init_kio() { return new KIO::AuthInfo(); }
00046 #endif 
00047 
00048 int main(int argc, char **argv)
00049 {
00050      if (argc < 5)
00051      {
00052         fprintf(stderr, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
00053         exit(1);
00054      }
00055      setlocale(LC_ALL, "");
00056      QString libpath = QFile::decodeName(argv[1]);
00057 
00058      if (libpath.isEmpty())
00059      {
00060         fprintf(stderr, "library path is empty.\n");
00061         exit(1); 
00062      }
00063 
00064      QLibrary lib(libpath);
00065 #ifdef Q_WS_WIN
00066      qDebug("trying to load '%s'", qPrintable(libpath));
00067 #endif
00068      if ( !lib.load() || !lib.isLoaded() )
00069      {
00070 #ifdef Q_WS_WIN
00071         libpath = KStandardDirs::installPath("module") + QFileInfo(libpath).fileName();
00072         lib.setFileName( libpath );
00073         if(!lib.load() || !lib.isLoaded())
00074         {
00075             QByteArray kdedirs = qgetenv("KDEDIRS");
00076             if (!kdedirs.size()) {
00077               qDebug("not able to find '%s' because KDEDIRS environment variable is not set.\n"
00078                      "Set KDEDIRS to the KDE installation root dir and restart klauncher to fix this problem.",
00079                      qPrintable(libpath));
00080               exit(1);
00081             }
00082             QString paths = QString::fromLocal8Bit(kdedirs);
00083             QStringList pathlist = paths.split(';');
00084             Q_FOREACH(const QString &path, pathlist) {
00085               QString slave_path = path + QLatin1String("/lib/kde4/") + QFileInfo(libpath).fileName();
00086               qDebug("trying to load '%s'",slave_path.toAscii().data());
00087               lib.setFileName(slave_path);
00088               if (lib.load() && lib.isLoaded() )
00089                 break;
00090             }
00091             if (!lib.isLoaded())
00092             {
00093               qWarning("could not open %s: %s", libpath.data(), qPrintable (lib.errorString()) );
00094               exit(1);
00095             }
00096         }
00097 #else
00098         fprintf(stderr, "could not open %s: %s", qPrintable(libpath),
00099                 qPrintable (lib.errorString()) );
00100         exit(1);
00101 #endif
00102      }  
00103 
00104      void* sym = lib.resolve("kdemain");
00105      if (!sym )
00106      {
00107         fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(lib.errorString() ));
00108         exit(1);
00109      }
00110 
00111 #ifdef Q_WS_WIN
00112      // enter debugger in case debugging is actived 
00113      QString slaveDebugWait( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_WAIT") ) );
00114      if (slaveDebugWait == QLatin1String("all") || slaveDebugWait == argv[2]) 
00115      {
00116 # ifdef Q_CC_MSVC
00117         // msvc debugger or windbg supports jit debugging, the latter requires setting up windbg jit with windbg -i
00118         DebugBreak();
00119 # else
00120         // gdb does not support win32 jit debug support, so implement it by ourself
00121         WCHAR buf[1024];
00122         GetModuleFileName(NULL,buf, 1024);
00123         QStringList params;
00124         params << QString::fromUtf16((const unsigned short*)buf);
00125         params << QString::number(GetCurrentProcessId());
00126         QProcess::startDetached("gdb",params);
00127         Sleep(1000);
00128 # endif
00129      } 
00130 # ifdef Q_CC_MSVC
00131      else {
00132         QString slaveDebugPopup( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_POPUP") ) );
00133         if (slaveDebugPopup == QLatin1String("all") || slaveDebugPopup == argv[2]) {
00134            // A workaround for OSes where DebugBreak() does not work in administrative mode (actually Vista with msvc 2k5)
00135            // - display a native message box so developer can attach the debugger to the KIO slave process and click OK.
00136            MessageBoxA(NULL, 
00137              QString("Please attach the debugger to process #%1 (%2)").arg(getpid()).arg(argv[0]).toLatin1(), 
00138              QString("\"%1\" KIO Slave Debugging").arg(argv[2]).toLatin1(), MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
00139         }
00140      }
00141 # endif
00142 #endif // Q_WS_WIN
00143 
00144      int (*func)(int, char *[]) = (int (*)(int, char *[])) sym;
00145 
00146      exit( func(argc-1, argv+1)); /* Launch! */
00147 }

KInit

Skip menu "KInit"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal