• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • arts
 

arts

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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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 <tqmap.h>
00027 #include <tqdatastream.h>
00028 
00029 using namespace std;
00030 
00031 #include "mcopdcoptools.h"
00032 #include "mcopdcopobject.h"
00033 
00034 class MCOPDCOPObjectPrivate
00035 {
00036 public:
00037     TQMap<TQCString, MCOPEntryInfo *> dynamicFunctions;
00038 };
00039 
00040 MCOPDCOPObject::MCOPDCOPObject(TQCString 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     TQMap<TQCString, 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, TQCString ifaceName, const TQByteArray &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             TQCString param = *it;
00075 
00076             kdDebug() << "PARAM: " << param << endl;
00077             
00078             TQDataStream 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 TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
00098 {
00099     TQMap<TQCString, 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             TQCString 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 = "TQCString";
00120                 
00121                 TQDataStream 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                 TQDataStream reply(replyData, IO_WriteOnly);
00139                 reply << returnCode;
00140             }
00141             
00142             return true;
00143         }
00144     }
00145 
00146     return false;
00147 }
00148 
00149 void MCOPDCOPObject::addDynamicFunction(TQCString value, MCOPEntryInfo *entry)
00150 {
00151     d->dynamicFunctions.insert(value, entry);
00152 }

arts

Skip menu "arts"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

arts

Skip menu "arts"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for arts by doxygen 1.7.1
This website is maintained by Timothy Pearson.