| # arts Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# mcopdcopobject.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    00017 */
    00018
    00019 #include <kdebug.h>
    00020
    00021 #include <core.h>
    00022 //#include <object.h>
    00023 //#include <reference.h>
    00024 #include <dynamicrequest.h>
    00025
    00026 #include <qmap.h>
    00027 #include <qdatastream.h>
    00028
    00029 using namespace std;
    00030
    00031 #include "mcopdcoptools.h"
    00032 #include "mcopdcopobject.h"
    00033
    00034 class MCOPDCOPObjectPrivate
    00035 {
    00036 public:
    00037     QMap<QCString, MCOPEntryInfo *> dynamicFunctions;
    00038 };
    00039
    00040 MCOPDCOPObject::MCOPDCOPObject(QCString name) : DCOPObject(name)
    00041 {
    00042     d = new MCOPDCOPObjectPrivate();
    00043 }
    00044
    00045 MCOPDCOPObject::~MCOPDCOPObject()
    00046 {
    00047     delete d;
    00048 }
    00049
    00050 QCStringList MCOPDCOPObject::functionsDynamic()
    00051 {
    00052     QCStringList returnList;
    00053
    00054     QMap<QCString, MCOPEntryInfo *>::iterator it;
    00055     for(it = d->dynamicFunctions.begin(); it != d->dynamicFunctions.end(); ++it)
    00056         returnList.append(it.key());
    00057
    00058     return returnList;
    00059 }
    00060
    00061 Arts::Buffer *MCOPDCOPObject::callFunction(MCOPEntryInfo *entry, QCString ifaceName, const QByteArray &data)
    00062 {
    00063     Arts::Object workingObject = Arts::SubClass(string(ifaceName));
    00064     Arts::DynamicRequest request(workingObject);
    00065     request.method(string(entry->functionName()));
    00066
    00067     if(entry->signatureList().size() > 0)
    00068     {
    00069         QCStringList list = entry->signatureList();
    00070
    00071         QCStringList::iterator it;
    00072         for(it = list.begin(); it != list.end(); ++it)
    00073         {
    00074             QCString param = *it;
    00075
    00076             kdDebug() << "PARAM: " << param << endl;
    00077
    00078             QDataStream argStream(data, IO_ReadOnly);
    00079
    00080             if(param == "long")
    00081                 request.param(MCOPDCOPTools::getLong(argStream));
    00082             else if(param == "string")
    00083                 request.param(MCOPDCOPTools::getString(argStream));
    00084         }
    00085     }
    00086
    00087     Arts::AnyRef result;
    00088     if(!request.invoke(result))
    00089         return 0;
    00090
    00091     Arts::Buffer *newBuffer = new Arts::Buffer();
    00092     result.write(newBuffer);
    00093
    00094     return newBuffer;
    00095 }
    00096
    00097 bool MCOPDCOPObject::processDynamic(const QCString &fun, const QByteArray &data, QCString &replyType, QByteArray &replyData)
    00098 {
    00099     QMap<QCString, MCOPEntryInfo *>::iterator it;
    00100     for(it = d->dynamicFunctions.begin(); it != d->dynamicFunctions.end(); ++it)
    00101     {
    00102         MCOPEntryInfo *entry = it.data();
    00103
    00104         if((entry->functionName() + entry->signature()) == fun)
    00105         {
    00106             QCString type = entry->functionType();
    00107
    00108             if(type == "void")
    00109             {
    00110                 replyType = type;
    00111
    00112                 Arts::Buffer *result = callFunction(entry, objId(), data);
    00113
    00114                 if(result != 0)
    00115                     delete result;
    00116             }
    00117             else if(type == "string")
    00118             {
    00119                 replyType = "QCString";
    00120
    00121                 QDataStream reply(replyData, IO_WriteOnly);
    00122                 reply << "fooo!";
    00123             }
    00124             else if(type == "long")
    00125             {
    00126                 replyType = type;
    00127
    00128                 long returnCode = -1;
    00129
    00130                 Arts::Buffer *result = callFunction(entry, objId(), data);
    00131
    00132                 if(result != 0)
    00133                 {
    00134                     returnCode = result->readLong();
    00135                     delete result;
    00136                 }
    00137
    00138                 QDataStream reply(replyData, IO_WriteOnly);
    00139                 reply << returnCode;
    00140             }
    00141
    00142             return true;
    00143         }
    00144     }
    00145
    00146     return false;
    00147 }
    00148
    00149 void MCOPDCOPObject::addDynamicFunction(QCString value, MCOPEntryInfo *entry)
    00150 {
    00151     d->dynamicFunctions.insert(value, entry);
    00152 }

This file is part of the documentation for arts Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:27:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003