testplugin.cpp

00001 /***************************************************************************
00002  * testplugin.cpp
00003  * This file is part of the KDE project
00004  * copyright (C)2005 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 "testplugin.h"
00021 #include "testobject.h"
00022 
00023 #include <kdebug.h>
00024 
00025 /************************************************************************
00026  * TestPluginObject
00027  */
00028 
00029 TestPluginObject::TestPluginObject(const QString& name)
00030     : Kross::Api::Class<TestPluginObject>(name)
00031 {
00032     this->addFunction("internalfunc1",
00033         new Kross::Api::ProxyFunction <
00034             TestPluginObject,
00035             uint (TestPluginObject::*)(uint),
00036             Kross::Api::ProxyValue< Kross::Api::Variant, uint >, // returnvalue
00037             Kross::Api::ProxyValue< Kross::Api::Variant, uint > // first argument
00038             > ( this, &TestPluginObject::internalfunc1 )
00039     );
00040 
00041     addFunction("func1", &TestPluginObject::func1);
00042     addFunction("func2", &TestPluginObject::func2,
00043         Kross::Api::ArgumentList()
00044             << Kross::Api::Argument("Kross::Api::Variant::String")
00045             << Kross::Api::Argument("Kross::Api::Variant::String") );
00046     addFunction("func3", &TestPluginObject::func3,
00047         Kross::Api::ArgumentList()
00048             << Kross::Api::Argument("Kross::Api::Variant::String")
00049             << Kross::Api::Argument("Kross::Api::Variant::String") );
00050     addFunction("func4", &TestPluginObject::func4,
00051         Kross::Api::ArgumentList()
00052             << Kross::Api::Argument("Kross::Api::Variant::String")
00053             << Kross::Api::Argument("Kross::Api::Variant::String")
00054             << Kross::Api::Argument("Kross::Api::Variant::String") );
00055     addFunction("func5", &TestPluginObject::func5,
00056         Kross::Api::ArgumentList()
00057             << Kross::Api::Argument("Kross::Api::Variant::String")
00058             << Kross::Api::Argument("Kross::Api::Variant::String")
00059             << Kross::Api::Argument("Kross::Api::Variant::String") );
00060     addFunction("func6", &TestPluginObject::func6,
00061         Kross::Api::ArgumentList()
00062             << Kross::Api::Argument("Kross::Api::List") );
00063     addFunction("func7", &TestPluginObject::func7,
00064         Kross::Api::ArgumentList()
00065             << Kross::Api::Argument("Kross::Api::List")
00066             << Kross::Api::Argument("Kross::Api::Variant") );
00067     addFunction("func8", &TestPluginObject::func8,
00068         Kross::Api::ArgumentList()
00069             << Kross::Api::Argument("Kross::Api::Variant")
00070             << Kross::Api::Argument("Kross::Api::Variant") );
00071     addFunction("func9", &TestPluginObject::func9,
00072         Kross::Api::ArgumentList()
00073             << Kross::Api::Argument("Kross::Api::Variant")
00074             << Kross::Api::Argument("Kross::Api::Variant") );
00075 
00076 }
00077 
00078 TestPluginObject::~TestPluginObject()
00079 {
00080 }
00081 
00082 const QString TestPluginObject::getClassName() const
00083 {
00084     return "TestPluginObject";
00085 }
00086 
00087 uint TestPluginObject::internalfunc1(uint i)
00088 {
00089     kdDebug() << "CALLED => TestPluginObject::internalfunc1" << endl;
00090     return i;
00091 }
00092 
00093 Kross::Api::Object::Ptr TestPluginObject::func1(Kross::Api::List::Ptr /*args*/)
00094 {
00095     //kdDebug() << "CALLED => TestPluginObject::func1 args=" << args->toString() << endl;
00096     return 0;
00097 }
00098 
00099 Kross::Api::Object::Ptr TestPluginObject::func2(Kross::Api::List::Ptr /*args*/)
00100 {
00101     //kdDebug() << "CALLED => TestPluginObject::func2 args=" << args->toString() << endl;
00102     return new Kross::Api::Variant("func2returnvalue");
00103 }
00104 
00105 Kross::Api::Object::Ptr TestPluginObject::func3(Kross::Api::List::Ptr /*args*/)
00106 {
00107     //kdDebug() << "CALLED => TestPluginObject::func3 args=" << args->toString() << endl;
00108     return new Kross::Api::Variant("func3returnvalue");
00109 }
00110 
00111 Kross::Api::Object::Ptr TestPluginObject::func4(Kross::Api::List::Ptr /*args*/)
00112 {
00113     //kdDebug() << "CALLED => TestPluginObject::func4 args=" << args->toString() << endl;
00114     return new Kross::Api::Variant("func4returnvalue");
00115 }
00116 
00117 Kross::Api::Object::Ptr TestPluginObject::func5(Kross::Api::List::Ptr /*args*/)
00118 {
00119     //kdDebug() << "CALLED => TestPluginObject::func5 args=" << args->toString() << endl;
00120     return new Kross::Api::Variant("func5returnvalue");
00121 }
00122 
00123 Kross::Api::Object::Ptr TestPluginObject::func6(Kross::Api::List::Ptr args)
00124 {
00125     Kross::Api::List* list = Kross::Api::Object::fromObject< Kross::Api::List >( args->item(0) );
00126     return list->item(0);
00127 }
00128 
00129 Kross::Api::Object::Ptr TestPluginObject::func7(Kross::Api::List::Ptr args)
00130 {
00131     return args->item(0);
00132 }
00133 
00134 Kross::Api::Object::Ptr TestPluginObject::func8(Kross::Api::List::Ptr args)
00135 {
00136     return args->item(0);
00137 }
00138 
00139 Kross::Api::Object::Ptr TestPluginObject::func9(Kross::Api::List::Ptr args)
00140 {
00141     return args->item(0);
00142 }
00143 
00144 /************************************************************************
00145  * TestPluginModule
00146  */
00147 
00148 TestPluginModule::TestPluginModule(const QString& name)
00149     : Kross::Api::Module(name)
00150     , m_testobject( new TestObject() )
00151 
00152 {
00153     addChild( new TestPluginObject("testpluginobject1") );
00154 
00155     // Let's wrap a whole instance and it's methodfunctions.
00156     Kross::Api::Event<TestObject> *testobjectclass =
00157         new Kross::Api::Event<TestObject>("testpluginobject2", this);
00158     addChild(testobjectclass);
00159 
00160     testobjectclass->addFunction("func1",
00161         new Kross::Api::ProxyFunction <
00162             TestObject,
00163             uint (TestObject::*)(uint),
00164             Kross::Api::ProxyValue< Kross::Api::Variant, uint >, // returnvalue
00165             Kross::Api::ProxyValue< Kross::Api::Variant, uint > // first argument
00166             > ( m_testobject, &TestObject::func1 )
00167     );
00168     testobjectclass->addFunction("func2",
00169         new Kross::Api::ProxyFunction <
00170             TestObject,
00171             void (TestObject::*)(QString, int),
00172             Kross::Api::ProxyValue< Kross::Api::Variant, void >, // returnvalue
00173             Kross::Api::ProxyValue< Kross::Api::Variant, QString >, // first argument
00174             Kross::Api::ProxyValue< Kross::Api::Variant, int > // second argument
00175             > ( m_testobject, &TestObject::func2 )
00176     );
00177     testobjectclass->addFunction("func3",
00178         new Kross::Api::ProxyFunction<
00179             TestObject,
00180             QString (TestObject::*)(QString, int),
00181             Kross::Api::ProxyValue< Kross::Api::Variant, QString >, // returnvalue
00182             Kross::Api::ProxyValue< Kross::Api::Variant, QString >, // first argument
00183             Kross::Api::ProxyValue< Kross::Api::Variant, int > // second argument
00184             > ( m_testobject, &TestObject::func3) );
00185     testobjectclass->addFunction("func4",
00186         new Kross::Api::ProxyFunction<
00187             TestObject,
00188             const QString& (TestObject::*)(const QString&, int) const,
00189             Kross::Api::ProxyValue< Kross::Api::Variant, const QString& >, // returnvalue
00190             Kross::Api::ProxyValue< Kross::Api::Variant, const QString& >, // first argument
00191             Kross::Api::ProxyValue< Kross::Api::Variant, int > // second argument
00192             > ( m_testobject, &TestObject::func4) );
00193 }
00194 
00195 TestPluginModule::~TestPluginModule()
00196 {
00197     delete m_testobject;
00198 }
00199 
00200 const QString TestPluginModule::getClassName() const
00201 {
00202     return "TestPluginModule";
00203 }
00204 

Generated on Thu Feb 9 17:59:11 2006 for Kross by  doxygen 1.4.6