#include <manager.h>
Inheritance diagram for Kross::Api::Manager:


Definition at line 55 of file manager.h.
Public Types | |
| typedef KSharedPtr< MainModule > | Ptr |
| Shared pointer to implement reference-counting. | |
Public Member Functions | |
| ~Manager () | |
| QMap< QString, InterpreterInfo * > | getInterpreterInfos () |
| bool | hasInterpreterInfo (const QString &interpretername) const |
| InterpreterInfo * | getInterpreterInfo (const QString &interpretername) |
| const QString & | getInterpreternameForFile (const QString &file) |
| KSharedPtr< ScriptContainer > | getScriptContainer (const QString &scriptname) |
| Interpreter * | getInterpreter (const QString &interpretername) |
| const QStringList | getInterpreters () |
| bool | addModule (Module::Ptr module) |
| Module::Ptr | loadModule (const QString &modulename) |
| virtual const QString | getClassName () const |
| bool | hadException () |
| Exception::Ptr | getException () |
| void | setException (Exception::Ptr exception) |
| bool | hasChild (const QString &name) const |
| Object::Ptr | hasChild (List::Ptr args) |
| EventSignal::Ptr | addSignal (const QString &name, QObject *sender, QCString signal) |
| EventSlot::Ptr | addSlot (const QString &name, QObject *receiver, QCString slot) |
| QtObject::Ptr | addQObject (QObject *object, const QString &name=QString::null) |
| EventAction::Ptr | addKAction (KAction *action, const QString &name=QString::null) |
| virtual Kross::Api::Object::Ptr | get (const QString &, void *=0) |
| void | addFunction (const QString &name, FunctionPtr function, const ArgumentList &=ArgumentList()) |
| void | addFunction (const QString &name, Function *function) |
| void | addProxyFunction (const QString &name, INSTANCE *instance, METHOD method) |
| void | addProxyFunction (const QString &name, INSTANCE *instance, METHOD method) |
| Same as above, but with three arguments. | |
| void | addProxyFunction (const QString &name, INSTANCE *instance, METHOD method) |
| Same as above, but with two arguments. | |
| void | addProxyFunction (const QString &name, INSTANCE *instance, METHOD method) |
| Same as above, but with one argument. | |
| void | addProxyFunction (const QString &name, INSTANCE *instance, METHOD method) |
| Same as above, but with no arguments. | |
| bool | isAFunction (const QString &name) const |
| virtual Object::Ptr | call (const QString &name, List::Ptr arguments) |
| virtual Object::Ptr | call (const QString &name, KSharedPtr< List > arguments) |
| Object::Ptr | getChild (List::Ptr args) |
| Object::Ptr | getChild (const QString &name) const |
| Object::Ptr | getChildrenList (List::Ptr args) |
| Object::Ptr | getChildrenDict (List::Ptr args) |
| Object::Ptr | callChild (List::Ptr args) |
| const QString & | getName () const |
| virtual const QString | toString () |
| Object::Ptr | getParent () const |
| QMap< QString, Object::Ptr > | getChildren () const |
| bool | addChild (Object::Ptr object, const QString &name=QString::null) |
| void | removeChild (const QString &name) |
| void | removeAllChildren () |
| virtual QStringList | getCalls () |
Static Public Member Functions | |
| static Manager * | scriptManager () |
| template<class T> | |
| static T * | fromObject (Object::Ptr object) |
Protected Member Functions | |
| Manager () | |
Protected Attributes | |
| ArgumentList | m_arglist |
|
|
Constructor. Use scriptManager() to access the Manager singleton instance. Definition at line 85 of file manager.cpp. References QFile::encodeName(), Kross::Api::ManagerPrivate::interpreterinfos, QString::isEmpty(), and QMap::replace(). Referenced by scriptManager(). 00086 : MainModule("Kross") // the manager has the name "Kross" 00087 , d( new ManagerPrivate() ) 00088 { 00089 #ifdef KROSS_PYTHON_LIBRARY 00090 QString pythonlib = QFile::encodeName( KLibLoader::self()->findLibrary(KROSS_PYTHON_LIBRARY) ); 00091 if(! pythonlib.isEmpty()) { // If the Kross Python plugin exists we offer it as supported scripting language. 00092 InterpreterInfo::Option::Map pythonoptions; 00093 pythonoptions.replace("restricted", 00094 new InterpreterInfo::Option("Restricted", "Restricted Python interpreter", QVariant(false,0)) 00095 ); 00096 d->interpreterinfos.replace("python", 00097 new InterpreterInfo("python", 00098 pythonlib, // library 00099 "*.py", // file filter-wildcard 00100 QStringList() << /* "text/x-python" << */ "application/x-python", // mimetypes 00101 pythonoptions // options 00102 ) 00103 ); 00104 } 00105 #endif 00106 #ifdef KROSS_RUBY_LIBRARY 00107 QString rubylib = QFile::encodeName( KLibLoader::self()->findLibrary(KROSS_RUBY_LIBRARY) ); 00108 if(! rubylib.isEmpty()) { // If the Kross Ruby plugin exists we offer it as supported scripting language. 00109 InterpreterInfo::Option::Map rubyoptions; 00110 rubyoptions.replace("safelevel", 00111 new InterpreterInfo::Option("safelevel", "Level of safety of the Ruby interpreter", QVariant(0)) // 0 -> unsafe, 4 -> very safe 00112 ); 00113 d->interpreterinfos.replace("ruby", 00114 new InterpreterInfo("ruby", 00115 rubylib, // library 00116 "*.rb", // file filter-wildcard 00117 QStringList() << /* "text/x-ruby" << */ "application/x-ruby", // mimetypes 00118 rubyoptions // options 00119 ) 00120 ); 00121 } else { 00122 kdDebug() << "Ruby interpreter for kross in unavailable" << endl; 00123 } 00124 #endif 00125 }
|
|
|
Destructor. Definition at line 127 of file manager.cpp. References QMap::begin(), QMap::end(), and Kross::Api::ManagerPrivate::interpreterinfos. 00128 { 00129 for(QMap<QString, InterpreterInfo*>::Iterator it = d->interpreterinfos.begin(); it != d->interpreterinfos.end(); ++it) 00130 delete it.data(); 00131 delete d; 00132 }
|
|
||||||||||||
|
Add a new child. Replaces a possible already existing child with such a name.
Definition at line 79 of file object.cpp. References QString::arg(), QString::isEmpty(), QString::isNull(), and QMap::replace(). Referenced by Kross::Api::MainModule::addKAction(), Kross::Api::MainModule::addQObject(), Kross::Api::MainModule::addSignal(), Kross::Api::MainModule::addSlot(), Kross::Api::QtObject::QtObject(), and TestPluginModule::TestPluginModule(). 00080 { 00081 QString n = name.isNull() ? object->getName() : name; 00082 00083 #ifdef KROSS_API_OBJECT_ADDCHILD_DEBUG 00084 kdDebug() << QString("Kross::Api::Object::addChild() object.name='%2' object.classname='%3'") 00085 .arg(n).arg(object->getClassName()) << endl; 00086 #endif 00087 00088 if(n.isEmpty()) // prevent invalid items. 00089 return false; //throw Exception::Ptr( new Exception( QString("Failed to add child object to object '%1'. Invalid name for class '%2'.").arg(getName()).arg(object->getClassName()) ) ); 00090 00091 object->m_parent = this; 00092 m_children.replace(n, object); 00093 return true; 00094 }
|
|
||||||||||||
|
Add a methodfunction to the list of functions this Object supports.
Definition at line 119 of file event.h. 00120 { 00121 m_functions.replace(name, function); 00122 }
|
|
||||||||||||||||
|
Add a Callable methodfunction to the list of functions this Object supports. The FunctionPtr points to the concret Object::Ptr myfuncname(List::Ptr) method in the class defined with template T.
Definition at line 101 of file event.h. 00102 { 00103 m_functions.replace(name, new VarFunction0<T>(static_cast<T*>(this), function)); 00104 }
|
|
||||||||||||
|
Add a KAction to the eventcollection. The KAction will be wrapped by a EventAction and will be added to this collection.
Definition at line 110 of file mainmodule.cpp. References Kross::Api::Object::addChild(). 00111 { 00112 EventAction* event = new EventAction(name, this, action); 00113 if(! addChild(event)) { 00114 kdWarning() << QString("Failed to add KAction name='%1'").arg(action->name()) << endl; 00115 delete event; 00116 return 0; 00117 } 00118 return event; 00119 }
|
|
|
Add the an external module to the global shared list of loaded modules.
Definition at line 199 of file manager.cpp. References Kross::Api::ManagerPrivate::modules, and QMap::replace(). Referenced by TestWindow::TestWindow(). 00200 { 00201 QString name = module->getName(); 00202 //if( d->modules.contains(name) ) return false; 00203 d->modules.replace(name, module); 00204 return true; 00205 }
|
|
||||||||||||||||
|
Template function to add a Kross::Api::ProxyFunction as builtin-function to this Event instance. Definition at line 129 of file event.h. 00130 { 00131 m_functions.replace(name, 00132 new Kross::Api::ProxyFunction < 00133 INSTANCE, METHOD, 00134 RET, ARG1, ARG2, ARG3, ARG4 00135 > ( instance, method ) ); 00136 }
|
|
||||||||||||
|
Add a QObject to the eventcollection. All signals and slots the QObject has will be added to a new EventCollection instance which is child of this EventCollection instance.
Definition at line 99 of file mainmodule.cpp. References Kross::Api::Object::addChild(), and QObject::name(). 00100 { 00101 QtObject* qtobject = new QtObject(this, object, name); 00102 if(! addChild(qtobject)) { 00103 kdWarning() << QString("Failed to add QObject name='%1'").arg(object->name()) << endl; 00104 delete qtobject; 00105 return 0; 00106 } 00107 return qtobject; 00108 }
|
|
||||||||||||||||
|
Add a Qt signal to the Module by creating an EventSignal for it.
Definition at line 78 of file mainmodule.cpp. References Kross::Api::Object::addChild(). 00079 { 00080 EventSignal* event = new EventSignal(name, this, sender, signal); 00081 if(! addChild(event)) { 00082 kdWarning() << QString("Failed to add signal name='%1' signature='%2'").arg(name).arg(signal) << endl; 00083 return 0; 00084 } 00085 return event; 00086 }
|
|
||||||||||||||||
|
Add a Qt slot to the Module by creating an EventSlot for it.
Definition at line 88 of file mainmodule.cpp. References Kross::Api::Object::addChild(). 00089 { 00090 EventSlot* event = new EventSlot(name, this, receiver, slot); 00091 if(! addChild(event)) { 00092 kdWarning() << QString("Failed to add slot name='%1' signature='%2'").arg(name).arg(slot) << endl; 00093 delete event; 00094 return 0; 00095 } 00096 return event; 00097 }
|
|
||||||||||||
|
Pass a call to the object and evaluated it recursive down the object-hierachy. Objects like Class are able to handle call's by just implementing this function. If the call is done the called() method will be executed recursive from bottom up the call hierachy.
Reimplemented in Kross::Api::EventScript, Kross::Api::EventSignal, and Kross::Api::EventSlot. Referenced by Kross::Api::Callable::call(), and Kross::Api::Callable::callChild(). |
|
||||||||||||
|
Overloaded method to handle function-calls.
Reimplemented from Kross::Api::Callable. Definition at line 210 of file event.h. 00211 { 00212 #ifdef KROSS_API_EVENT_CALL_DEBUG 00213 kdDebug() << QString("Event::call() name='%1' getName()='%2'").arg(name).arg(getName()) << endl; 00214 #endif 00215 00216 Function* function = m_functions[name]; 00217 if(function) { 00218 #ifdef KROSS_API_EVENT_CALL_DEBUG 00219 kdDebug() << QString("Event::call() name='%1' is a builtin function.").arg(name) << endl; 00220 #endif 00221 00222 //FIXME checkArguments(arguments); 00223 return function->call(arguments); 00224 } 00225 00226 if(name.isNull()) { 00227 // If no name is defined, we return a reference to our instance. 00228 return this; 00229 } 00230 00231 // Redirect the call to the Kross::Api::Callable we are inheritated from. 00232 return Callable::call(name, arguments); 00233 }
|
|
|
Wrapper for the Kross::Api::Object::call() method to call a children. Definition at line 172 of file callable.cpp. References Kross::Api::Object::call(), and Kross::Api::Variant::toString(). Referenced by Kross::Api::Callable::call(). 00173 { 00174 //kdDebug() << QString("Kross::Api::Callable::callChild() getName()=%1").arg(getName()) << endl; 00175 return Object::call(Variant::toString(args->item(0)), args); 00176 }
|
|
||||||||||
|
Try to convert the Object instance to the template class T.
Definition at line 198 of file object.h. 00199 { 00200 T* t = (T*) object.data(); 00201 if(! t) 00202 throw KSharedPtr<Exception>( new Exception(QString("Object \"%1\" invalid.").arg(object ? object->getClassName() : "")) ); 00203 return t; 00204 }
|
|
||||||||||||
|
Method to load from Kross::Api::Object inherited classes this module implements from within other modules. Reimplemented in TestPluginModule. Definition at line 70 of file module.h.
|
|
|
Return a list of supported callable objects.
Reimplemented in Kross::Python::PythonObject. Definition at line 186 of file object.h. 00186 { return QStringList(); }
|
|
|
Return the defined child or NULL if there is no such object with that name avaible.
Definition at line 69 of file object.cpp. Referenced by Kross::Api::Callable::getChild().
|
|
|
Wrapper for the Kross::Api::Object::getChild() method to return a children this object has. Definition at line 146 of file callable.cpp. References Kross::Api::Object::getChild(), Kross::Api::Object::getName(), and Kross::Api::Variant::toString(). Referenced by Kross::Api::Callable::call(). 00147 { 00148 QString s = Variant::toString(args->item(0)); 00149 //kdDebug() << QString("Kross::Api::Callable::getChild() getName()=%1 childName=%2").arg(getName()).arg(s) << endl; 00150 Object::Ptr obj = Object::getChild(s); 00151 if(! obj) 00152 throw Exception::Ptr( new Exception(QString("The object '%1' has no child object '%2'").arg(getName()).arg(s)) ); 00153 return obj; 00154 }
|
|
|
Return all children.
Definition at line 74 of file object.cpp. Referenced by Kross::Api::Callable::getChildrenDict(), and Kross::Api::Callable::getChildrenList().
|
|
|
Wrapper for the Kross::Api::Object::getChild() method to return a dictonary of children this object has.
Definition at line 166 of file callable.cpp. References Kross::Api::Object::getChildren(). Referenced by Kross::Api::Callable::call(). 00167 { 00168 //kdDebug()<<"Kross::Api::Callable::getChildrenDict()"<<endl; 00169 return new Dict(Object::getChildren(), "Kross::Api::Callable::getChildrenDict::Dict"); 00170 }
|
|
|
Wrapper for the Kross::Api::Object::getChildren() method to return a list of childrennames this object has.
Definition at line 156 of file callable.cpp. References QMap::begin(), QMap::end(), and Kross::Api::Object::getChildren(). Referenced by Kross::Api::Callable::call(). 00157 { 00158 QStringList list; 00159 QMap<QString, Object::Ptr> children = getChildren(); 00160 QMap<QString, Object::Ptr>::Iterator it( children.begin() ); 00161 for(; it != children.end(); ++it) 00162 list.append( it.key() ); 00163 return new Variant(list); 00164 }
|
|
|
Reimplemented from Kross::Api::Callable. Definition at line 53 of file mainmodule.cpp.
|
|
|
Definition at line 63 of file mainmodule.cpp. References Kross::Api::MainModulePrivate::exception. Referenced by Kross::Api::ScriptAction::activate(). 00064 { 00065 return d->exception; 00066 }
|
|
|
Return the Interpreter instance defined by the interpretername.
Definition at line 174 of file manager.cpp. References QMap::contains(), Kross::Api::ManagerPrivate::interpreterinfos, and Kross::Api::MainModule::setException(). 00175 { 00176 setException(0); // clear previous exceptions 00177 00178 if(! d->interpreterinfos.contains(interpretername)) { 00179 setException( new Exception(QString("No such interpreter '%1'").arg(interpretername)) ); 00180 return 0; 00181 } 00182 00183 return d->interpreterinfos[interpretername]->getInterpreter(); 00184 }
|
|
|
Definition at line 144 of file manager.cpp. References Kross::Api::ManagerPrivate::interpreterinfos. Referenced by Kross::Api::ScriptContainer::getOption(), and Kross::Api::ScriptContainer::setOption(). 00145 { 00146 return d->interpreterinfos[interpretername]; 00147 }
|
|
|
Definition at line 134 of file manager.cpp. References Kross::Api::ManagerPrivate::interpreterinfos. Referenced by Kross::Api::ScriptGUIClient::openScriptFile(). 00135 { 00136 return d->interpreterinfos; 00137 }
|
|
|
Definition at line 149 of file manager.cpp. References QMap::begin(), QMap::end(), QString::find(), Kross::Api::ManagerPrivate::interpreterinfos, QRegExp::setPattern(), and QRegExp::setWildcard(). Referenced by Kross::Api::ScriptContainer::initialize(). 00150 { 00151 QRegExp rx; 00152 rx.setWildcard(true); 00153 for(QMap<QString, InterpreterInfo*>::Iterator it = d->interpreterinfos.begin(); it != d->interpreterinfos.end(); ++it) { 00154 rx.setPattern((*it)->getWildcard()); 00155 if( file.find(rx) >= 0 ) 00156 return (*it)->getInterpretername(); 00157 } 00158 return QString::null; 00159 }
|
|
|
Definition at line 186 of file manager.cpp. References QMap::begin(), QMap::end(), and Kross::Api::ManagerPrivate::interpreterinfos. 00187 { 00188 QStringList list; 00189 00190 QMap<QString, InterpreterInfo*>::Iterator it( d->interpreterinfos.begin() ); 00191 for(; it != d->interpreterinfos.end(); ++it) 00192 list << it.key(); 00193 00194 //list << "TestCase"; 00195 00196 return list; 00197 }
|
|
|
Return the name this object has.
Reimplemented in Kross::Api::ScriptContainer. Definition at line 49 of file object.cpp. Referenced by Kross::Api::Event< QtObject >::call(), Kross::Api::Callable::call(), Kross::Api::Callable::getChild(), and Kross::Api::Module::~Module().
|
|
|
Return the parent object or NULL if this object doesn't has a parent.
Definition at line 59 of file object.cpp.
|
|
|
Return the existing ScriptContainer with scriptname or create a new ScriptContainer instance and associate the passed scriptname with it.
Definition at line 161 of file manager.cpp. Referenced by TestWindow::TestWindow(). 00162 { 00163 //TODO at the moment we don't share ScriptContainer instances. 00164 00165 //if(d->m_scriptcontainers.contains(scriptname)) 00166 // return d->m_scriptcontainers[scriptname]; 00167 ScriptContainer* scriptcontainer = new ScriptContainer(scriptname); 00168 //ScriptContainer script(this, scriptname); 00169 //d->m_scriptcontainers.replace(scriptname, scriptcontainer); 00170 00171 return scriptcontainer; 00172 }
|
|
|
Definition at line 58 of file mainmodule.cpp. References Kross::Api::MainModulePrivate::exception. Referenced by Kross::Api::ScriptAction::activate(), Kross::Api::ScriptContainer::classInstance(), and Kross::Api::ScriptContainer::execute(). 00059 { 00060 return d->exception != 0; 00061 }
|
|
|
Wrapper for the Kross::Api::Object::hasChild() method to check if this object has children. Definition at line 139 of file callable.cpp. References Kross::Api::Object::hasChild(), and Kross::Api::Variant::toString(). Referenced by Kross::Api::Callable::call(). 00140 { 00141 //kdDebug() << QString("Kross::Api::Callable::hasChild() getName()=%1").arg(getName()) << endl; 00142 return new Variant( Object::hasChild( Variant::toString(args->item(0)) ), 00143 "Kross::Api::Callable::hasChild::Bool" ); 00144 }
|
|
|
Returns if the defined child is avaible.
Reimplemented from Kross::Api::Object. Definition at line 73 of file mainmodule.cpp. References Kross::Api::Object::hasChild(). 00074 { 00075 return Object::hasChild(name); 00076 }
|
|
|
Definition at line 139 of file manager.cpp. References QMap::contains(), and Kross::Api::ManagerPrivate::interpreterinfos. 00140 { 00141 return d->interpreterinfos.contains(interpretername); 00142 }
|
|
|
Check if a function is a member of this Callable
Definition at line 187 of file event.h. 00188 { 00189 return m_functions.contains(name); 00190 }
|
|
|
Load an external module and return it.
Definition at line 207 of file manager.cpp. References QString::arg(), QMap::contains(), and Kross::Api::ManagerPrivate::modules. 00208 { 00209 Module::Ptr module = 0; 00210 00211 if(d->modules.contains(modulename)) { 00212 module = d->modules[modulename]; 00213 if(module) 00214 return module; 00215 else 00216 kdDebug() << QString("Manager::loadModule(%1) =======> Modulename registered, but module is invalid!").arg(modulename) << endl; 00217 } 00218 00219 KLibLoader* loader = KLibLoader::self(); 00220 KLibrary* lib = loader->globalLibrary( modulename.latin1() ); 00221 if(! lib) { 00222 kdWarning() << QString("Failed to load module '%1': %2").arg(modulename).arg(loader->lastErrorMessage()) << endl; 00223 return 0; 00224 } 00225 kdDebug() << QString("Successfully loaded module '%1'").arg(modulename) << endl; 00226 00227 def_module_func func; 00228 func = (def_module_func) lib->symbol("init_module"); 00229 00230 if(! func) { 00231 kdWarning() << QString("Failed to determinate init function in module '%1'").arg(modulename) << endl; 00232 return 0; 00233 } 00234 00235 module = (Kross::Api::Module*) (func)(this); 00236 lib->unload(); 00237 00238 if(! module) { 00239 kdWarning() << QString("Failed to load module '%1'").arg(modulename) << endl; 00240 return 0; 00241 } 00242 00243 // Don't remember module cause we like to have freeing it handled by the caller. 00244 //d->modules.replace(modulename, module); 00245 00246 //kdDebug() << QString("Kross::Api::Manager::loadModule modulename='%1' module='%2'").arg(modulename).arg(module->toString()) << endl; 00247 return module; 00248 }
|
|
|
Remove all children. Definition at line 104 of file object.cpp. References QMap::clear(). 00105 { 00106 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG 00107 kdDebug() << "Kross::Api::Object::removeAllChildren()" << endl; 00108 #endif 00109 m_children.clear(); 00110 }
|
|
|
Remove an existing child.
Definition at line 96 of file object.cpp. References QMap::remove(). 00097 { 00098 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG 00099 kdDebug() << QString("Kross::Api::Object::removeChild() name='%1'").arg(name) << endl; 00100 #endif 00101 m_children.remove(name); 00102 }
|
|
|
Return the Manager instance. Always use this function to access the Manager singleton. Definition at line 72 of file manager.cpp. References Kross::Api::m_manager, Kross::Api::m_managerdeleter, and Manager(). Referenced by Kross::Api::ScriptContainer::getOption(), Kross::Api::ScriptContainer::initialize(), Kross::Api::ScriptGUIClient::openScriptFile(), Kross::Api::ScriptAction::setInterpreterName(), Kross::Api::ScriptContainer::setOption(), and TestWindow::TestWindow(). 00073 { 00074 if(! m_manager) { 00075 // Create the Manager-singleton on demand and let the 00076 // KStaticDeleter take care of freeing it if not needed 00077 // any longer. 00078 m_managerdeleter.setObject(m_manager, new Manager()); 00079 } 00080 00081 // and finally return the singleton. 00082 return m_manager; 00083 }
|
|
|
Set the Exception this module throwed.
Definition at line 68 of file mainmodule.cpp. References Kross::Api::MainModulePrivate::exception. Referenced by Kross::Api::ScriptContainer::classInstance(), Kross::Api::ScriptContainer::execute(), getInterpreter(), and Kross::Api::ScriptContainer::initialize(). 00069 { 00070 d->exception = exception; 00071 }
|
|
|
Reimplemented in Kross::Api::Dict, Kross::Api::Exception, Kross::Api::List, and Kross::Api::Variant. Definition at line 54 of file object.cpp. References QString::arg(), and Kross::Api::Object::getClassName(). 00055 { 00056 return QString("%1 (%2)").arg(m_name).arg(getClassName()); 00057 }
|
|
|
List of arguments this callable object supports. Definition at line 123 of file callable.h. |
1.4.6