00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#include <kdebug.h>
00020
00021
#include <core.h>
00022
00023
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 }