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

Kross

interpreter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  * interpreter.cpp
00003  * This file is part of the KDE project
00004  * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #include "interpreter.h"
00021 #include "script.h"
00022 #include "action.h"
00023 #include "manager.h"
00024 
00025 #include <klibloader.h>
00026 
00027 extern "C"
00028 {
00029     typedef void* (*def_interpreter_func)(int version, Kross::InterpreterInfo*);
00030 }
00031 
00032 using namespace Kross;
00033 
00034 /*************************************************************************
00035  * InterpreterInfo
00036  */
00037 
00038 namespace Kross {
00039 
00041     class InterpreterInfo::Private
00042     {
00043         public:
00045             QString interpretername;
00047             QString library;
00049             QString wildcard;
00051             QStringList mimetypes;
00053             Option::Map options;
00055             Interpreter* interpreter;
00056     };
00057 
00058 }
00059 
00060 InterpreterInfo::InterpreterInfo(const QString& interpretername, const QString& library, const QString& wildcard, QStringList mimetypes, Option::Map options)
00061     : ErrorInterface()
00062     , d( new Private() )
00063 {
00064     d->interpretername = interpretername;
00065     d->library = library;
00066     d->wildcard = wildcard;
00067     d->mimetypes = mimetypes;
00068     d->options = options;
00069     d->interpreter = 0;
00070 }
00071 
00072 InterpreterInfo::~InterpreterInfo()
00073 {
00074     delete d->interpreter;
00075     //d->interpreter = 0;
00076     delete d;
00077 }
00078 
00079 const QString InterpreterInfo::interpreterName() const
00080 {
00081     return d->interpretername;
00082 }
00083 
00084 const QString InterpreterInfo::wildcard() const
00085 {
00086     return d->wildcard;
00087 }
00088 
00089 const QStringList InterpreterInfo::mimeTypes() const
00090 {
00091     return d->mimetypes;
00092 }
00093 
00094 bool InterpreterInfo::hasOption(const QString& key) const
00095 {
00096     return d->options.contains(key);
00097 }
00098 
00099 InterpreterInfo::Option* InterpreterInfo::option(const QString& name) const
00100 {
00101     return d->options[name];
00102 }
00103 
00104 const QVariant InterpreterInfo::optionValue(const QString& name, const QVariant& defaultvalue) const
00105 {
00106     Option* o = option(name);
00107     return o ? o->value : defaultvalue;
00108 }
00109 
00110 InterpreterInfo::Option::Map InterpreterInfo::options()
00111 {
00112     return d->options;
00113 }
00114 
00115 Interpreter* InterpreterInfo::interpreter()
00116 {
00117     if(d->interpreter) // buffered
00118         return d->interpreter;
00119 
00120     if(hadError()) // the interpreter can't be loaded
00121         return 0;
00122 
00123     #ifdef KROSS_INTERPRETER_DEBUG
00124         krossdebug( QString("Loading the interpreter library for %1").arg(d->interpretername) );
00125     #endif
00126 
00127     // Load the krosspython library.
00128     KLibLoader *loader = KLibLoader::self();
00129 
00130     KLibrary* library = loader->library( d->library, QLibrary::ExportExternalSymbolsHint );
00131     if(! library) {
00132         setError(i18n("Could not load interpreter library \"%1\"",d->library), loader->lastErrorMessage());
00133         return 0;
00134     }
00135 
00136     // Get the extern "C" krosspython_instance function.
00137     def_interpreter_func interpreter_func;
00138     interpreter_func = (def_interpreter_func) library->resolveFunction("krossinterpreter");
00139     // and execute the extern krosspython_instance function.
00140     d->interpreter = interpreter_func
00141         ? (Interpreter*) (interpreter_func)(KROSS_VERSION, this)
00142         : 0;
00143     if(! d->interpreter) {
00144         setError(i18n("Incompatible interpreter library."));
00145     }
00146     else {
00147         // Job done. The library is loaded and our Interpreter* points
00148         // to the external Kross::Python::Interpreter* instance.
00149         #ifdef KROSS_INTERPRETER_DEBUG
00150             krossdebug("Successfully loaded Interpreter instance from library.");
00151         #endif
00152     }
00153 
00154     // finally unload the library.
00155     library->unload();
00156     // and return the interpreter instance or NULL if loading failed.
00157     return d->interpreter;
00158 }
00159 
00160 /*************************************************************************
00161  * Interpreter
00162  */
00163 
00164 namespace Kross {
00165 
00167     class Interpreter::Private
00168     {
00169         public:
00171             InterpreterInfo* interpreterinfo;
00172 
00173             Private(InterpreterInfo* info) : interpreterinfo(info) {}
00174     };
00175 
00176 }
00177 
00178 Interpreter::Interpreter(InterpreterInfo* info)
00179     : ErrorInterface()
00180     , d( new Private(info) )
00181 {
00182 }
00183 
00184 Interpreter::~Interpreter()
00185 {
00186     delete d;
00187 }
00188 
00189 InterpreterInfo* Interpreter::interpreterInfo() const
00190 {
00191     return d->interpreterinfo;
00192 }
00193 
00194 void Interpreter::virtual_hook(int id, void* data)
00195 {
00196     Q_UNUSED(id);
00197     Q_UNUSED(data);
00198 }

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • 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
  •   WTF
  • KJSEmbed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • 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