*not part of the build*

urp connect update


git-svn-id: svn://10.0.0.236/trunk@96522 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
idk%eng.sun.com
2001-06-06 09:44:44 +00:00
parent 46a6e60ecb
commit 162f7f89cc
27 changed files with 1914 additions and 878 deletions

View File

@@ -23,54 +23,85 @@
#include "prmem.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIAllocator.h"
#include "nsCOMPtr.h"
#include "xptcall.h"
#include "nsCRT.h"
#include "urpManager.h"
#include <unistd.h>
#include "urpStub.h"
#include "urpMarshalToolkit.h"
#include "nsIModule.h"
#include "bcIXPCOMStubsAndProxies.h"
#include "bcXPCOMStubsAndProxiesCID.h"
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
class urpAllocator : public bcIAllocator { //nb make is smarter. It should deallocate allocated memory.
class threadHashKey : public nsHashKey {
public:
urpAllocator(nsIAllocator *_allocator) {
allocator = _allocator;
}
virtual ~urpAllocator() {}
virtual void * Alloc(size_t size) {
return allocator->Alloc(size);
}
virtual void Free(void *ptr) {
allocator->Free(ptr);
}
virtual void * Realloc(void* ptr, size_t size) {
return allocator->Realloc(ptr,size);
}
threadHashKey(bcTID thrdID) : threadID(thrdID) {}
virtual PRUint32 HashCode(void) const
{
return PRUint32(threadID);
}
virtual PRBool Equals(const nsHashKey *aKey) const
{
return ((threadHashKey*)aKey)->threadID == threadID;
}
virtual nsHashKey *Clone(void) const
{
return new threadHashKey(threadID);
}
private:
nsCOMPtr<nsIAllocator> allocator;
bcTID threadID;
};
urpManager::urpManager(urpTransport* trans) {
broker = NULL;
connection = NULL;
transport = trans;
nsresult r;
struct localThreadArg {
urpManager *mgr;
urpConnection *conn;
PRBool isClnt;
localThreadArg( urpManager *mgr, urpConnection *conn, PRBool ic ) {
this->mgr = mgr;
this->conn = conn;
this->isClnt = ic;
}
};
void thread_start( void *arg )
{
urpManager *manager = ((localThreadArg *)arg)->mgr;
urpConnection *connection = ((localThreadArg *)arg)->conn;
PRBool ic = ((localThreadArg *)arg)->isClnt;
nsresult rv = manager->ReadMessage( connection, ic );
}
urpManager::urpManager(urpTransport* trans, bcIORB *orb) {
urpManager::urpManager(PRBool IsClient, bcIORB *orb, urpConnection* conn) {
broker = orb;
connection = NULL;
transport = trans;
connection = conn;
connTable = nsnull;
if(IsClient) {
//then
localThreadArg *arg = new localThreadArg( this, conn, PR_TRUE );
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
thread_start,
arg,
PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD,
0);
if(thr == nsnull) {
printf("Error couldn't run listener\n");
exit(-1);
}
}
}
urpManager::~urpManager() {
if(connTable)
delete connTable;
}
@@ -78,10 +109,13 @@ urpManager::~urpManager() {
void urpManager::SendUrpRequest(bcOID oid, bcIID iid,
PRUint16 methodIndex,
nsIInterfaceInfo* interfaceInfo,
bcICall *call, nsXPTCVariant* params,
bcICall *call,
PRUint32 paramCount, const nsXPTMethodInfo* info) {
printf("this is method sendUrpRequest and mid is %x\n",methodIndex);
connection = transport->GetConnection();
if(connection == nsnull) {
printf("Connection is NULL in SendUrpRequest\n");
exit(-1);
}
long size = 0;
long messagesCount = 0;
urpPacket* message = new urpPacket();
@@ -122,520 +156,95 @@ void urpManager::SendUrpRequest(bcOID oid, bcIID iid,
else
message->WriteByte((char)methodIndex);
}
printf("header is written\n");
WriteType(iid, message);
printf("Type is written\n");
WriteOid(oid, message);
printf("OID is written\n");
WriteThreadID(1000, message);
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
mt->WriteType(iid, message);
mt->WriteOid(oid, message);
bcTID thrID = (bcTID)PR_GetCurrentThread();
printf("OID is written %ld\n", thrID);
mt->WriteThreadID(thrID, message);
broker = call->GetORB();
WriteParams(params, paramCount, info, interfaceInfo, message, methodIndex);
printf("params are written\n");
mt->WriteParams(call, paramCount, info, interfaceInfo, message, methodIndex);
delete mt;
connection->Write(message);
delete message;
printf("package is written\n");
}
void urpManager::TransformMethodIDAndIID() {
printf("this is method transformMethodIDAndIID\n");
}
void
urpManager::WriteType(bcIID iid, urpPacket* message) {
short cache_index;
char typeClass = INTERFACE;
int found = 0;
if(0) //here should be checking on whether class is simple or not
printf("class is simple\n");
else {
if(0) { // here should be checking on whether cache is used
printf("cache is used\n");
cache_index = 0x0;
}
else
cache_index = (short)0xffff;
message->WriteByte((char)typeClass | (found ? 0x0 : 0x80));
printf("write type is %x\n",(char)typeClass | (found ? 0x0 : 0x80));
message->WriteShort(cache_index);
printf("write type is %x\n",cache_index);
if(!found) {
char* iidStr = iid.ToString();
message->WriteString(iidStr, strlen(iidStr));
PR_Free(iidStr);
}
}
}
bcIID
urpManager::ReadType(urpPacket* message) {
char byte = (char)message->ReadByte();
char typeClassValue = byte & 0xff;
short cache_index = message->ReadShort();
int& size = 0;
nsIID iid;
char* name = message->ReadString(size);
iid.Parse(name);
PR_Free(name);
return iid;
}
void
urpManager::WriteOid(bcOID oid, urpPacket* message) {
short cache_index;
int found = 0;
if(0) { // here should be checking on whether cache is used
printf("cache is used\n");
cache_index = 0x0;
}
else
cache_index = (short)0xffff;
char* str = (char*)calloc(100, sizeof(char));
sprintf(str,"%ld",oid);
message->WriteString(str, strlen(str));
free(str);
message->WriteShort(cache_index);
}
bcOID
urpManager::ReadOid(urpPacket* message) {
int& size = 0;
bcOID result;
char* str = message->ReadString(size);
short cache_index = message->ReadShort();
result = (bcOID)atol(str);
PR_Free(str);
return result;
}
void
urpManager::WriteThreadID(bcTID tid, urpPacket* message) {
short cache_index;
int found = 0;
char realTID[5] = {0x54, 0x14, 0x78, 0x71, 0x27};
if(0) { // here should be checking on whether cache is used
printf("cache is used\n");
cache_index = 0x0;
}
else
cache_index = (short)0xffff;
message->WriteOctetStream(realTID, 5);
message->WriteShort(cache_index);
}
bcTID
urpManager::ReadThreadID(urpPacket* message) {
int& size = 0;
bcTID result;
char* array = message->ReadOctetStream(size);
short cache_index = message->ReadShort();
result= (bcTID)array[0];
PR_Free(array);
return result;
}
nsresult
urpManager::MarshalElement(void *data, nsXPTParamInfo * param, uint8 type, uint8 ind,
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex, const nsXPTMethodInfo *info,
nsXPTCVariant* params) {
nsresult r = NS_OK;
switch(type) {
case nsXPTType::T_IID :
printf("Marshalim T_IID\n");
data = *(char**)data;
message->WriteString((char*)data, strlen((char*)data));
break;
case nsXPTType::T_I8 :
message->WriteByte(*(char*)data);
break;
case nsXPTType::T_I16 :
message->WriteShort(*(short*)data);
break;
case nsXPTType::T_I32 :
message->WriteInt(*(int*)data);
break;
case nsXPTType::T_I64 :
message->WriteLong(*(long*)data);
break;
case nsXPTType::T_U8 :
message->WriteByte(*(char*)data);
break;
case nsXPTType::T_U16 :
message->WriteShort(*(short*)data);
break;
case nsXPTType::T_U32 :
message->WriteInt(*(int*)data);
break;
case nsXPTType::T_U64 :
message->WriteLong(*(long*)data);
break;
case nsXPTType::T_FLOAT :
message->WriteFloat(*(float*)data);
break;
case nsXPTType::T_DOUBLE :
message->WriteDouble(*(double*)data);
break;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
{
data = *(char **)data;
size_t length = 0;
if (type == nsXPTType::T_WCHAR_STR) {
length = nsCRT::strlen((const PRUnichar*)data);
length *= 2;
length +=2;
for (int i = 0; i < length && type == nsXPTType::T_WCHAR_STR; i++) {
char c = ((char*)data)[i];
}
} else {
length = nsCRT::strlen((const char*)data);
length+=1;
}
message->WriteString((char*)data,length);
break;
}
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
nsIID *iid;
if (type == nsXPTType::T_INTERFACE) {
if(NS_FAILED(r = interfaceInfo->GetIIDForParam(methodIndex, param, &iid))) {
return r;
}
} else {
uint8 argnum;
if (NS_FAILED(r = interfaceInfo->GetInterfaceIsArgNumberForParam(methodIndex, param, &argnum))) {
return r;
}
const nsXPTParamInfo& arg_param = info->GetParam(argnum);
const nsXPTType& arg_type = arg_param.GetType();
if(arg_type.IsPointer() &&
arg_type.TagPart() == nsXPTType::T_IID) {
if(arg_param.IsOut())
iid =*((nsID**)params[argnum].val.p);
else
iid = (nsID*)params[argnum].val.p;
}
}
bcOID oid = 0;
if (*(char**)data != NULL) {
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
return r;
}
xpcomStubsAndProxies->GetOID(*(nsISupports**)data, broker,&oid);
}
WriteOid(oid, message);
bcIID biid = *(iid);
WriteType(biid, message);
break;
}
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_ARRAY: //nb array of interfaces [to do]
{
PRUint32 arraySize;
if (!GetArraySizeFromParam(interfaceInfo,info, *param,methodIndex,
ind,params,GET_LENGTH, &arraySize)) {
return r;
}
if (type == nsXPTType::T_ARRAY) {
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return r;
}
message->WriteInt(arraySize);
PRInt16 elemSize = GetSimpleSize(datumType);
char *current = *(char**)data;
for (unsigned int i = 0; i < arraySize; i++, current+=elemSize)
{
r = MarshalElement(current,param,datumType.TagPart(),0,
interfaceInfo, message, methodIndex, info, params);
if(NS_FAILED(r)) return r;
}
} else {
size_t length = 0;
if (type == nsXPTType::T_PWSTRING_SIZE_IS) {
length = arraySize * sizeof(PRUnichar);
} else {
length = arraySize;
}
message->WriteString((char*)data, length);
}
break;
}
default:
return r;
}
return r;
}
nsresult
urpManager::WriteParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo* interfaceInfo, urpPacket* message, PRUint16 methodIndex) {
int i;
nsresult rv = NS_OK;
for(i=0;i<paramCount;i++) {
short cache_index;
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
if ((transport->IsClient() && !param.IsIn()) ||
(transport->IsServer() && !param.IsOut())) {
continue;
}
nsXPTCVariant *value = & params[i];
void *data;
data = (isOut) ? value->val.p : value;
rv = MarshalElement(data, &param,param.GetType().TagPart(), i, interfaceInfo, message, methodIndex, info, params);
if(NS_FAILED(rv)) return rv;
/*
if(0) //here should be checking on whether class is simple or not
printf("class is simple\n");
else {
if(0) { // here should be checking on whether cache is used
printf("cache is used\n");
cache_index = 0x0;
}
else
cache_index = (short)0xffff;
message->writeByte((char)typeClass | (found ? 0x0 : 0x80));
message->writeShort(cache_index);
if(!found)
message->writeString("com.sun.star.uno.XNamingService", 31);
}
*/
}
return rv;
}
nsresult
urpManager::UnMarshal(void *data, nsXPTParamInfo * param, uint8 type,
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex, bcIAllocator * allocator) {
nsresult r = NS_OK;
switch(type) {
case nsXPTType::T_IID :
{
printf("Unmarsahalim T_IID\n");
/*
*(char**)data = (char*)new nsIID();
data = *(char**)data;
*/
int& size = 0;
*(char**)data = message->ReadString(size);
break;
}
case nsXPTType::T_I8 :
*(char*)data = message->ReadByte();
break;
case nsXPTType::T_I16 :
*(short*)data = message->ReadShort();
break;
case nsXPTType::T_I32 :
*(int*)data = message->ReadInt();
break;
case nsXPTType::T_I64 :
*(long*)data = message->ReadLong();
break;
case nsXPTType::T_U8 :
*(char*)data = message->ReadByte();
break;
case nsXPTType::T_U16 :
*(short*)data = message->ReadShort();
break;
case nsXPTType::T_U32 :
*(int*)data = message->ReadInt();
break;
case nsXPTType::T_U64 :
*(long*)data = message->ReadLong();
break;
case nsXPTType::T_FLOAT :
*(float*)data = message->ReadFloat();
break;
case nsXPTType::T_DOUBLE :
*(double*)data = message->ReadDouble();
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
{
int& size = 0;
*(char**)data = message->ReadString(size);
break;
}
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
bcOID oid = ReadOid(message);
nsIID iid = ReadType(message);
nsISupports *proxy = NULL;
if (oid != 0) {
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies,
kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xp failed\n");
return r;
}
xpcomStubsAndProxies->GetProxy(oid, iid, broker,&proxy);
}
*(nsISupports**)data = proxy;
break;
}
case nsXPTType::T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return r;
}
PRUint32 arraySize;
PRInt16 elemSize = GetSimpleSize(datumType);
arraySize = message->ReadInt();
char * current;
*(char**)data = current = (char *) allocator->Alloc(elemSize*arraySize);
//nb what about arraySize=0?
for (unsigned int i = 0; i < arraySize; i++, current+=elemSize) {
r = UnMarshal(current, param, datumType.TagPart(), interfaceInfo, message, methodIndex, allocator);
if(NS_FAILED(r)) return r;
}
break;
}
default:
return r;
}
return r;
}
nsresult
urpManager::ReadParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
bcIAllocator * allocator = new urpAllocator(nsAllocator::GetGlobalAllocator());
int i;
nsresult rv = NS_OK;
for(i=0;i<paramCount;i++) {
short cache_index;
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
nsXPTCMiniVariant tmpValue = params[i]; //we need to set value for client side
nsXPTCMiniVariant * value;
value = &tmpValue;
if (transport->IsServer() && param.IsOut()) {
value->val.p = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is good
params[i].Init(*value,param.GetType(),0);
params[i].ptr = params[i].val.p = value->val.p;
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
}
if ((transport->IsServer() && !param.IsIn()) ||
(transport->IsClient() && !param.IsOut())) {
continue;
}
void *data;
data = (isOut) ? value->val.p : value;
rv = UnMarshal(data, &param, param.GetType().TagPart(), interfaceInfo,
message, methodIndex, allocator);
if(NS_FAILED(rv)) return rv;
params[i].Init(*value,param.GetType(),0);
/*
if(0) //here should be checking on whether class is simple or not
printf("class is simple\n");
else {
if(0) { // here should be checking on whether cache is used
printf("cache is used\n");
cache_index = 0x0;
}
else
cache_index = (short)0xffff;
message->writeByte((char)typeClass | (found ? 0x0 : 0x80));
message->writeShort(cache_index);
if(!found)
message->writeString("com.sun.star.uno.XNamingService", 31);
}
*/
}
delete allocator;
return rv;
}
nsresult
urpManager::ReadReply(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
nsresult rv = NS_OK;
printf("this is method readReply\n");
urpPacket* message = connection->Read();
char header = message->ReadByte();
printf("header in reply is %x %x %x\n",header, BIG_HEADER, header & BIG_HEADER);
if((header & BIG_HEADER) != 0) { // full header?
if((header & REQUEST) != 0) // a request ?
printf("long request\n");
else // reply
rv = ParseReply(message, header, params, paramCount,
info, interfaceInfo, methodIndex);
}
else
printf("short request header\n");
delete connection;
delete message;
// transport->close();
return rv;
}
nsresult
urpManager::ParseReply(urpPacket* message, char header,
nsXPTCVariant* params, PRUint32 paramCount,
urpManager::ReadReply(urpPacket* message, char header,
bcICall* call, PRUint32 paramCount,
const nsXPTMethodInfo *info,
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
nsresult rv = NS_OK;
printf("this is method readReply\n");
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
if((header & NEWTID) != 0) { // new thread id ?
printf("new threadID\n");
bcTID tid = ReadThreadID(message);
bcTID tid = mt->ReadThreadID(message);
}
else
printf("old threadID\n");
rv = ReadParams(params, paramCount, info, message, interfaceInfo, methodIndex);
rv = mt->ReadParams(paramCount, info, message, interfaceInfo, methodIndex, call, broker, connection);
delete mt;
return rv;
}
nsresult
urpManager::HandleRequest(urpConnection* conn) {
printf("method handleRequest\n");
connection = conn;
urpPacket* message = connection->Read();
urpManager::ReadMessage(urpConnection* conn, PRBool isClient) {
nsresult rv = NS_OK;
char header = message->ReadByte();
bcTID tid;
if((header & BIG_HEADER) != 0) { // full header?
if((header & REQUEST) != 0) // a request ?
rv = ReadLongRequest(header, message);
else // a reply
printf("Error: here should be request\n");
}
else // only a short request header
rv = ReadShortRequest(header, message);
delete message;
if(!isClient) {
if(connTable == nsnull)
connTable = new nsHashtable(20);
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
connTable->Put(&thrHK, conn);
}
while(conn->GetStatus() == urpSuccess) {
urpPacket* message = conn->Read();
char header = message->ReadByte();
bcTID tid;
if((header & BIG_HEADER) != 0) { // full header?
if((header & REQUEST) != 0) // a request ?
rv = ReadLongRequest(header, message);
else { // a reply
bcIID iid; bcOID oid; bcMID mid;
call->GetParams(&iid, &oid, &mid);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
printf("Error in ReadMessage\n");
return NS_ERROR_FAILURE; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
printf("Error in ReadMessage in second place\n");
return NS_ERROR_FAILURE;
}
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(mid, (const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
ReadReply(message, header, call, paramCount, info, interfaceInfo, mid);
PR_EnterMonitor(mon);
PR_Notify(mon);
PR_ExitMonitor(mon);
mon = NULL;
}
}
else // only a short request header
rv = ReadShortRequest(header, message);
delete message;
}
if(!isClient) {
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
connTable->Remove(&thrHK);
}
return rv;
}
@@ -648,7 +257,7 @@ urpManager::ReadShortRequest(char header, urpPacket* message) {
}
nsresult
urpManager::SendReply(bcTID tid, nsXPTCVariant *params, PRUint32 paramCount,
urpManager::SendReply(bcTID tid, bcICall* call, PRUint32 paramCount,
const nsXPTMethodInfo* info,
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
nsresult rv = NS_OK;
@@ -656,13 +265,19 @@ urpManager::SendReply(bcTID tid, nsXPTCVariant *params, PRUint32 paramCount,
header |= NEWTID;
urpPacket* message = new urpPacket();
message->WriteByte(header);
WriteThreadID(tid, message);
rv = WriteParams(params, paramCount, info, interfaceInfo, message,
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_FALSE);
mt->WriteThreadID(tid, message);
rv = mt->WriteParams(call, paramCount, info, interfaceInfo, message,
methodIndex);
delete mt;
if(NS_FAILED(rv)) return rv;
if(connTable) {
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
connection = (urpConnection*)connTable->Get(&thrHK);
}
connection->Write(message);
delete message;
delete connection;
return rv;
}
@@ -679,16 +294,17 @@ urpManager::ReadLongRequest(char header, urpPacket* message) {
else
methodId = message->ReadByte();
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_FALSE);
if((header & NEWTYPE) != 0)
iid = ReadType(message);
iid = mt->ReadType(message);
if((header & NEWOID) != 0) // new oid?
oid = ReadOid(message);
oid = mt->ReadOid(message);
if((header & NEWTID) != 0) // new thread id ?
tid = ReadThreadID(message);
tid = mt->ReadThreadID(message);
printf("method readLongRequest: tid %ld\n",tid);
printf("method readLongRequest: tid %ld %ld\n",tid,oid);
char ignore_cache = ((header & IGNORECACHE) != 0); // do not use cache for this request?
char mustReply;
@@ -706,116 +322,32 @@ printf("method readLongRequest: tid %ld\n",tid);
nsIInterfaceInfoManager* iimgr;
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
printf("here oblomalis\n");
delete mt;
return NS_ERROR_FAILURE; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
printf("zdesia oblom\n");
delete mt;
return NS_ERROR_FAILURE;
}
char* name;
interfaceInfo->GetName(&name);
printf("in handleRequest interface name is %s\n",name);
nsXPTCVariant *params;
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(methodId,(const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
if (paramCount > 0) {
params = (nsXPTCVariant *) PR_Malloc(sizeof(nsXPTCVariant)*paramCount);
}
ReadParams(params, paramCount, info, message, interfaceInfo, methodId);
nsXPTCMiniVariant* tempVari = (nsXPTCMiniVariant *) PR_Malloc(sizeof(nsXPTCMiniVariant)*paramCount);
for(int ii =0; ii<paramCount;ii++)
tempVari[ii] = params[ii];
//nb return value; excepion handling
// XPTC_InvokeByIndex(object, methodId, paramCount, params);
bcICall *call = broker->CreateCall(&iid, &oid, methodId);
bcIMarshaler *marshaler = call->GetMarshaler();
bcXPCOMMarshalToolkit * mt = new bcXPCOMMarshalToolkit(methodId, interfaceInfo, tempVari,broker);
mt->Marshal(marshaler);
mt->ReadParams(paramCount, info, message, interfaceInfo, methodId, call, broker, connection);
delete mt;
//nb return value; excepion handling
broker->SendReceive(call);
bcIUnMarshaler * unmarshaler = call->GetUnMarshaler();
mt->UnMarshal(unmarshaler);
delete call; delete marshaler; delete unmarshaler; delete mt;
rv = SendReply(tid, params, paramCount, info, interfaceInfo, methodId);
PR_Free(tempVari);
PR_Free(params);
rv = SendReply(tid, call, paramCount, info, interfaceInfo, methodId);
return rv;
}
nsresult urpManager::GetArraySizeFromParam( nsIInterfaceInfo *_interfaceInfo,
const nsXPTMethodInfo* method,
const nsXPTParamInfo& param,
uint16 _methodIndex,
uint8 paramIndex,
nsXPTCVariant* nativeParams,
SizeMode mode,
PRUint32* result) {
//code borrowed from mozilla/js/src/xpconnect/src/xpcwrappedjsclass.cpp
uint8 argnum;
nsresult rv;
if(mode == GET_SIZE) {
rv = _interfaceInfo->GetSizeIsArgNumberForParam(_methodIndex, &param, 0, &argnum);
} else {
rv = _interfaceInfo->GetLengthIsArgNumberForParam(_methodIndex, &param, 0, &argnum);
}
if(NS_FAILED(rv)) {
return PR_FALSE;
}
const nsXPTParamInfo& arg_param = method->GetParam(argnum);
const nsXPTType& arg_type = arg_param.GetType();
// XXX require PRUint32 here - need to require in compiler too!
if(arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_U32)
return PR_FALSE;
if(arg_param.IsOut())
*result = *(PRUint32*)nativeParams[argnum].val.p;
else
*result = nativeParams[argnum].val.u32;
return PR_TRUE;
nsresult
urpManager::SetCall(bcICall* call, PRMonitor *m) {
this->call = call;
this->mon = m;
return NS_OK;
}
PRInt16 urpManager::GetSimpleSize(uint8 type) {
PRInt16 size = -1;
switch(type) {
case nsXPTType::T_I8:
case nsXPTType::T_U8:
size = sizeof(PRInt8);
break;
case nsXPTType::T_I16:
case nsXPTType::T_U16:
size = sizeof(PRInt16);
break;
case nsXPTType::T_I32:
case nsXPTType::T_U32:
size = sizeof(PRInt32);
break;
case nsXPTType::T_I64:
case nsXPTType::T_U64:
size = sizeof(PRInt64);
break;
case nsXPTType::T_FLOAT:
size = sizeof(float);
break;
case nsXPTType::T_DOUBLE:
size = sizeof(double);
break;
case nsXPTType::T_BOOL:
size = sizeof(PRBool);
break;
case nsXPTType::T_CHAR:
size = sizeof(char);
break;
case nsXPTType::T_WCHAR:
size = sizeof(PRUnichar);
break;
default:
size = sizeof(void*);
}
return size;
}