• Skip to content
  • Skip to link menu
KDE 4.1 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 <config.h>
00023 
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <errno.h>
00027 
00028 #include <QtCore/QString>
00029 #include <QtCore/QLibrary>
00030 #include <QtCore/QFile>
00031 #ifdef Q_WS_WIN
00032 #include <QtCore/QDir>
00033 #include <QtCore/QProcess>
00034 #include <QtCore/QStringList>
00035 #include <windows.h>
00036 #include <process.h>
00037 #include "kstandarddirs.h"
00038 #endif
00039 
00040 #ifndef Q_WS_WIN
00041 /* These are to link libkio even if 'smart' linker is used */
00042 #include <kio/authinfo.h>
00043 extern "C" KIO::AuthInfo* _kioslave_init_kio() { return new KIO::AuthInfo(); }
00044 #endif 
00045 
00046 int main(int argc, char **argv)
00047 {
00048      if (argc < 5)
00049      {
00050         fprintf(stderr, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
00051         exit(1);
00052      }
00053      QString libpath = QFile::decodeName(argv[1]);
00054 
00055      if (libpath.isEmpty())
00056      {
00057         fprintf(stderr, "library path is empty.\n");
00058         exit(1); 
00059      }
00060 
00061      QLibrary lib(libpath);
00062 #ifdef Q_WS_WIN
00063      qDebug("trying to load '%s'", qPrintable(libpath));
00064 #endif
00065      if ( !lib.load() || !lib.isLoaded() )
00066      {
00067 #ifdef Q_WS_WIN
00068         libpath = KStandardDirs::installPath("module") + QFileInfo(libpath).fileName();
00069         lib.setFileName( libpath );
00070         if(!lib.load() || !lib.isLoaded())
00071         {
00072             QByteArray kdedirs = qgetenv("KDEDIRS");
00073             if (!kdedirs.size()) {
00074               qDebug("not able to find '%s' because KDEDIRS environment variable is not set.\n"
00075                      "Set KDEDIRS to the KDE installation root dir and restart klauncher to fix this problem.",
00076                      qPrintable(libpath));
00077               exit(1);
00078             }
00079             QString paths = QString::fromLocal8Bit(kdedirs);
00080             QStringList pathlist = paths.split(';');
00081             Q_FOREACH(const QString &path, pathlist) {
00082               QString slave_path = path + QLatin1String("/lib/kde4/") + libpath;
00083               qDebug("trying to load '%s'",slave_path.toAscii().data());
00084               lib.setFileName(slave_path);
00085               if (lib.load() && lib.isLoaded() )
00086                 break;
00087             }
00088             if (!lib.isLoaded())
00089             {
00090               fprintf(stderr, "could not open %s: %s", libpath.data(),
00091                       qPrintable (lib.errorString()) );
00092               exit(1);
00093             }
00094         }
00095 #else
00096         fprintf(stderr, "could not open %s: %s", qPrintable(libpath),
00097                 qPrintable (lib.errorString()) );
00098         exit(1);
00099 #endif
00100      }  
00101 
00102      void* sym = lib.resolve("kdemain");
00103      if (!sym )
00104      {
00105         sym = lib.resolve("main");
00106         if (!sym )
00107         {
00108            fprintf(stderr, "Could not find main: %s\n", qPrintable(lib.errorString() ));
00109            exit(1);
00110         }
00111      }
00112 
00113 #ifdef Q_WS_WIN
00114      // enter debugger in case debugging is actived 
00115      QString slaveDebugWait( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_WAIT") ) );
00116      if (slaveDebugWait == QLatin1String("all") || slaveDebugWait == argv[2]) 
00117      {
00118 # ifdef Q_CC_MSVC
00119         // msvc debugger or windbg supports jit debugging, the latter requires setting up windbg jit with windbg -i
00120         DebugBreak();
00121 # else
00122         // gdb does not support win32 jit debug support, so implement it by ourself
00123         QByteArray buf(1024,0);
00124         GetModuleFileName(NULL,buf.data(),buf.size());
00125         QStringList params;
00126         params << buf;
00127         params << QString::number(GetCurrentProcessId());
00128         QProcess::startDetached("gdb",params);
00129         Sleep(1000);
00130 # endif
00131      } 
00132 # ifdef Q_CC_MSVC
00133      else {
00134         QString slaveDebugPopup( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_POPUP") ) );
00135         if (slaveDebugPopup == QLatin1String("all") || slaveDebugPopup == argv[2]) {
00136            // A workaround for OSes where DebugBreak() does not work in administrative mode (actually Vista with msvc 2k5)
00137            // - display a native message box so developer can attach the debugger to the KIO slave process and click OK.
00138            MessageBoxA(NULL, 
00139              QString("Please attach the debugger to process #%1 (%2)").arg(getpid()).arg(argv[0]).toLatin1(), 
00140              QString("\"%1\" KIO Slave Debugging").arg(argv[2]).toLatin1(), MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
00141         }
00142      }
00143 # endif
00144 #endif // Q_WS_WIN
00145 
00146      int (*func)(int, char *[]) = (int (*)(int, char *[])) sym;
00147 
00148      exit( func(argc-1, argv+1)); /* Launch! */
00149 }

KInit

Skip menu "KInit"
  • Main Page
  • Namespace List
  • 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
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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