From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- arts/kde/mcop-dcop/mcopdcopobject.cpp | 152 ++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 arts/kde/mcop-dcop/mcopdcopobject.cpp (limited to 'arts/kde/mcop-dcop/mcopdcopobject.cpp') diff --git a/arts/kde/mcop-dcop/mcopdcopobject.cpp b/arts/kde/mcop-dcop/mcopdcopobject.cpp new file mode 100644 index 000000000..f1d1acad5 --- /dev/null +++ b/arts/kde/mcop-dcop/mcopdcopobject.cpp @@ -0,0 +1,152 @@ +/* + Copyright (c) 2001 Nikolas Zimmermann + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include + +#include +//#include +//#include +#include + +#include +#include + +using namespace std; + +#include "mcopdcoptools.h" +#include "mcopdcopobject.h" + +class MCOPDCOPObjectPrivate +{ +public: + QMap dynamicFunctions; +}; + +MCOPDCOPObject::MCOPDCOPObject(QCString name) : DCOPObject(name) +{ + d = new MCOPDCOPObjectPrivate(); +} + +MCOPDCOPObject::~MCOPDCOPObject() +{ + delete d; +} + +QCStringList MCOPDCOPObject::functionsDynamic() +{ + QCStringList returnList; + + QMap::iterator it; + for(it = d->dynamicFunctions.begin(); it != d->dynamicFunctions.end(); ++it) + returnList.append(it.key()); + + return returnList; +} + +Arts::Buffer *MCOPDCOPObject::callFunction(MCOPEntryInfo *entry, QCString ifaceName, const QByteArray &data) +{ + Arts::Object workingObject = Arts::SubClass(string(ifaceName)); + Arts::DynamicRequest request(workingObject); + request.method(string(entry->functionName())); + + if(entry->signatureList().size() > 0) + { + QCStringList list = entry->signatureList(); + + QCStringList::iterator it; + for(it = list.begin(); it != list.end(); ++it) + { + QCString param = *it; + + kdDebug() << "PARAM: " << param << endl; + + QDataStream argStream(data, IO_ReadOnly); + + if(param == "long") + request.param(MCOPDCOPTools::getLong(argStream)); + else if(param == "string") + request.param(MCOPDCOPTools::getString(argStream)); + } + } + + Arts::AnyRef result; + if(!request.invoke(result)) + return 0; + + Arts::Buffer *newBuffer = new Arts::Buffer(); + result.write(newBuffer); + + return newBuffer; +} + +bool MCOPDCOPObject::processDynamic(const QCString &fun, const QByteArray &data, QCString &replyType, QByteArray &replyData) +{ + QMap::iterator it; + for(it = d->dynamicFunctions.begin(); it != d->dynamicFunctions.end(); ++it) + { + MCOPEntryInfo *entry = it.data(); + + if((entry->functionName() + entry->signature()) == fun) + { + QCString type = entry->functionType(); + + if(type == "void") + { + replyType = type; + + Arts::Buffer *result = callFunction(entry, objId(), data); + + if(result != 0) + delete result; + } + else if(type == "string") + { + replyType = "QCString"; + + QDataStream reply(replyData, IO_WriteOnly); + reply << "fooo!"; + } + else if(type == "long") + { + replyType = type; + + long returnCode = -1; + + Arts::Buffer *result = callFunction(entry, objId(), data); + + if(result != 0) + { + returnCode = result->readLong(); + delete result; + } + + QDataStream reply(replyData, IO_WriteOnly); + reply << returnCode; + } + + return true; + } + } + + return false; +} + +void MCOPDCOPObject::addDynamicFunction(QCString value, MCOPEntryInfo *entry) +{ + d->dynamicFunctions.insert(value, entry); +} -- cgit v1.2.1