kmcop.cpp

00001 /*
00002    Copyright (c) 2001 Nikolas Zimmermann <wildfox@kde.org>
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 */
00018 
00019 #include <kdebug.h>
00020 #include <kuniqueapplication.h>
00021 #include <kaboutdata.h>
00022 #include <kcmdlineargs.h>
00023 #include <klocale.h>
00024 #include <dcopclient.h>
00025 
00026 #include <qvaluelist.h>
00027 #include <qcstring.h>
00028 
00029 #include <kartsdispatcher.h>
00030 #include <soundserver.h>
00031 #include <dispatcher.h>
00032 #include <object.h>
00033 #include <core.h>
00034 
00035 #include "mcopdcopobject.h"
00036 
00037 #include "kmcop.moc"
00038 
00039 using namespace Arts;
00040 using namespace std;
00041 
00042 class KMCOPPrivate
00043 {
00044 public:
00045     MCOPInfo mcopInfo; 
00046     QPtrList<MCOPDCOPObject> list;
00047 };
00048 
00049 int main(int argc, char **argv)
00050 {
00051     KAboutData aboutdata("kmcop", I18N_NOOP("KMCOP"),
00052                          "0.1", I18N_NOOP("KDE MCOP-DCOP Bridge"),
00053                          KAboutData::License_GPL, "(C) 2001, Nikolas Zimmermann");
00054     aboutdata.addAuthor("Nikolas Zimmermann", I18N_NOOP("Author"), "wildfox@kde.org");
00055 
00056     KCmdLineArgs::init(argc, argv, &aboutdata);
00057     KUniqueApplication::addCmdLineOptions();
00058 
00059     if(!KUniqueApplication::start())
00060     {
00061         kdDebug() << "Running kmcop found" << endl;
00062         return 0;
00063     }
00064 
00065     KUniqueApplication app;
00066     app.disableSessionManagement();
00067 
00068     KArtsDispatcher dispatcher;
00069 
00070     KMCOP notify;
00071     app.dcopClient()->setDefaultObject("arts");
00072     app.dcopClient()->setDaemonMode(true);
00073     
00074     return app.exec();
00075 }
00076 
00077 KMCOP::KMCOP() : QObject(), DCOPObject("arts")
00078 {
00079     d = new KMCOPPrivate();
00080     d->mcopInfo = Reference("global:Arts_MCOPInfo");
00081     d->list.setAutoDelete(true);
00082 }
00083 
00084 KMCOP::~KMCOP()
00085 {
00086     delete d;
00087 }
00088 
00089 int KMCOP::objectCount()
00090 {
00091     return d->mcopInfo.objectCount();
00092 }
00093 
00094 QCString KMCOP::correctType(const QCString &str)
00095 {
00096     if(str == "string")
00097         return "QCString";
00098     return str;
00099 }
00100 
00101 void KMCOP::addInterfacesHackHackHack()
00102 {
00103     for(int i = 0; i <= objectCount(); i++)
00104     {
00105         Arts::Object obj = d->mcopInfo.objectForNumber(i);
00106         
00107         if(!obj.isNull())       
00108         {
00109             QCString interfaceName = obj._interfaceName().c_str();
00110 
00111             if(interfaceName != "Arts::TraderOffer")
00112             {
00113                 Arts::InterfaceRepo ifaceRepo = Dispatcher::the()->interfaceRepo();
00114 
00115                 MCOPDCOPObject *interface = new MCOPDCOPObject(interfaceName);
00116                 d->list.append(interface);
00117             
00118                 InterfaceDef ifaceDef = ifaceRepo.queryInterface(string(interfaceName));
00119                 vector<MethodDef> ifaceMethods = ifaceDef.methods;
00120 
00121                 vector<MethodDef>::iterator ifaceMethodsIterator;
00122                 for(ifaceMethodsIterator = ifaceMethods.begin(); ifaceMethodsIterator != ifaceMethods.end(); ifaceMethodsIterator++)
00123                 {
00124                     QCString function, signature;
00125 
00126                     MCOPEntryInfo *entry = new MCOPEntryInfo();
00127                     
00128                     MethodDef currentMethod = *ifaceMethodsIterator;
00129                     vector<ParamDef> currentParameters = currentMethod.signature;
00130 
00131                     QCString newType = correctType(QCString(currentMethod.type.c_str()));
00132                     
00133                     entry->setFunctionType(newType);
00134                     entry->setFunctionName(QCString(currentMethod.name.c_str()));
00135                     
00136                     function = entry->functionType() + QCString(" ") + entry->functionName() + QCString("(");
00137                     
00138                     signature = QCString("(");
00139 
00140                     QCStringList signatureList;
00141                     
00142                     vector<ParamDef>::iterator methodParametersIterator;
00143                     for(methodParametersIterator = currentParameters.begin(); methodParametersIterator != currentParameters.end(); methodParametersIterator++)
00144                     {
00145                         ParamDef parameter = *methodParametersIterator;
00146                         if(methodParametersIterator != currentParameters.begin())
00147                         {
00148                             function += QCString(", ");                     
00149                             signature += QCString(",");
00150                         }
00151                         
00152                         QCString correctParameter = correctType(QCString(parameter.type.c_str()));
00153                         
00154                         function += correctParameter;
00155                         signature += correctParameter;
00156 
00157                         signatureList.append(QCString(parameter.type.c_str()));
00158                     }
00159                     
00160                     function += QCString(")");
00161                     signature += QCString(")");
00162 
00163                     entry->setSignature(signature);
00164                     entry->setSignatureList(signatureList);
00165 
00166                     interface->addDynamicFunction(function, entry);
00167                 }
00168             }
00169         }
00170     }
00171 }
KDE Home | KDE Accessibility Home | Description of Access Keys