urpConnect update
a=lsv@sparc.spb.su
This commit is contained in:
idk%eng.sun.com 2001-06-19 00:16:08 +00:00
Родитель b62b13324a
Коммит 4a1c6ce82c
10 изменённых файлов: 181 добавлений и 105 удалений

Просмотреть файл

@ -17,7 +17,7 @@
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
* Sergey Lunegov <lvv@sparc.spb.su>
*/
/*
@ -85,16 +85,19 @@ urpComponentLoader::urpComponentLoader()
return;
}
_orb->GetORB(&orb);
bcOID oid;
// bcOID oid;
bcOID oid = -860880895;
transport = new urpConnector();
PRStatus status = transport->Open("socket,host=indra,port=20009");
PRStatus status = transport->Open("socket,host=localhost,port=20009");
if(status != PR_SUCCESS) {
printf("Error during opening connection\n");
exit(-1);
}
man = new urpManager(PR_TRUE, nsnull, transport->GetConnection());
stub = new urpStub(man);
oid = orb->RegisterStub(stub);
urpConnection* conn = transport->GetConnection();
man = new urpManager(PR_TRUE, nsnull, conn);
stub = new urpStub(man, conn);
// oid = orb->RegisterStub(stub);
orb->RegisterStubWithOID(stub, &oid);
xpcomStubsAndProxies->GetProxy(oid, NS_GET_IID(nsIComponentManager), orb, &proxy);
compM = (nsIComponentManager*)proxy;
}

Просмотреть файл

@ -28,6 +28,7 @@
#include "nsIInterfaceInfoManager.h"
#include "nsIComponentManager.h"
#include "urpITest.h"
#include "urpTestImpl.h"
static char * className = "initImpl";
@ -103,6 +104,10 @@ initImpl::initImpl() {
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
urpITest *object = new urpTestImpl();
object->AddRef();
serverComponent->Test6(object);
{
urpITest *p1;
serverComponent->Test7(&p1);

Просмотреть файл

@ -87,9 +87,12 @@ nsIInterfaceInfo *interfaceInfo;
printf("Error during opening connection\n");
exit(-1);
}
urpManager* man = new urpManager(PR_TRUE, nsnull, transport->GetConnection());
stub = new urpStub(man);
bcOID oid = orb->RegisterStub(stub);
urpConnection* conn = transport->GetConnection();
urpManager* man = new urpManager(PR_TRUE, nsnull, conn);
stub = new urpStub(man, conn);
bcOID oid = 1221591041;
// bcOID oid = orb->RegisterStub(stub);
orb->RegisterStubWithOID(stub, &oid);
printf("---urpTestImpl oid=%ld iid=%s\n",oid, NS_GET_IID(urpITest).ToString());
r = xpcomStubsAndProxies->GetProxy(oid,NS_GET_IID(urpITest),orb,(nsISupports**)&proxy);
if (NS_FAILED(r)) {
@ -148,7 +151,7 @@ nsIInterfaceInfo *interfaceInfo;
}
/*********************************************/
// proxy->Test6(object);
proxy->Test6(object);
/*********************************************/
{
urpITest *p1;
@ -167,6 +170,7 @@ nsIInterfaceInfo *interfaceInfo;
}
// trans->Close();
delete conn;
transport->Close();
}

Просмотреть файл

@ -25,6 +25,7 @@
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
static NS_DEFINE_CID(compManag, NS_COMPONENTMANAGER_CID);
struct localThreadArg {
urpManager *mgr;
@ -50,6 +51,8 @@ int main( int argc, char *argv[] ) {
nsresult rv = NS_InitXPCOM(NULL, NULL);
NS_ASSERTION( NS_SUCCEEDED(rv), "NS_InitXPCOM failed" );
(void) nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBCIID, &rv);
if (NS_FAILED(rv)) {
printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
@ -64,17 +67,19 @@ printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
bcIORB *orb;
_orb->GetORB(&orb);
bcIStub *stub = nsnull;
urpITest *object = new urpTestImpl();
object->AddRef();
NS_WITH_SERVICE(nsIComponentManager, mComp, compManag, &rv);
if (NS_FAILED(rv)) {
printf("compManager failed\n");
return -1;
}
urpITest *proxy = nsnull;
xpcomStubsAndProxies->GetStub((nsISupports*)object, &stub);
xpcomStubsAndProxies->GetStub((nsISupports*)mComp, &stub);
bcOID oid = orb->RegisterStub(stub);
urpTransport* trans = new urpAcceptor();
PRStatus status = trans->Open(connectString);
if(status == PR_SUCCESS) printf("succes %ld\n",oid);
else printf("failed\n");
object->AddRef();
urpManager* mngr = new urpManager(PR_FALSE, orb, nsnull);
rv = NS_OK;
while(NS_SUCCEEDED(rv)) {

Просмотреть файл

@ -69,6 +69,29 @@ struct localThreadArg {
}
};
struct sendThreadArg {
urpManager* man;
char header;
urpPacket* message;
bcIID iid;
bcOID oid;
bcTID tid;
PRUint16 methodId;
urpConnection* connection;
sendThreadArg(urpManager* m, char header, urpPacket* message, bcIID iid,
bcOID oid, bcTID tid, PRUint16 methodId,
urpConnection* conn) {
this->man = m;
this->header = header;
this->message = message;
this->iid = iid;
this->oid = oid;
this->tid = tid;
this->methodId = methodId;
this->connection = conn;
}
};
struct monitCall {
PRMonitor *mon;
bcICall* call;
@ -86,12 +109,23 @@ void thread_start( void *arg )
nsresult rv = manager->ReadMessage( connection, ic );
}
void send_thread_start (void * arg) {
urpManager *manager = ((sendThreadArg *)arg)->man;
char header = ((sendThreadArg *)arg)->header;
urpPacket* mes = ((sendThreadArg *)arg)->message;
bcIID iid = ((sendThreadArg *)arg)->iid;
bcOID oid = ((sendThreadArg *)arg)->oid;
bcTID tid = ((sendThreadArg *)arg)->tid;
PRUint16 methodId = ((sendThreadArg *)arg)->methodId;
urpConnection* conn = ((sendThreadArg *)arg)->connection;
nsresult rv = manager->ReadLongRequest(header, mes, iid, oid,
tid, methodId, conn);
}
urpManager::urpManager(PRBool IsClient, bcIORB *orb, urpConnection* conn) {
broker = orb;
monitTable = new nsHashtable(20);
if(IsClient) {
connTable = nsnull;
connection = conn;
localThreadArg *arg = new localThreadArg( this, conn, PR_TRUE );
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
thread_start,
@ -104,16 +138,13 @@ urpManager::urpManager(PRBool IsClient, bcIORB *orb, urpConnection* conn) {
printf("Error couldn't run listener\n");
exit(-1);
}
} else {
connection = nsnull;
connTable = new nsHashtable(20);
}
}
urpManager::~urpManager() {
if(connTable)
delete connTable;
if(monitTable)
delete monitTable;
}
@ -122,7 +153,8 @@ void urpManager::SendUrpRequest(bcOID oid, bcIID iid,
PRUint16 methodIndex,
nsIInterfaceInfo* interfaceInfo,
bcICall *call,
PRUint32 paramCount, const nsXPTMethodInfo* info) {
PRUint32 paramCount, const nsXPTMethodInfo* info,
urpConnection* connection) {
printf("this is method sendUrpRequest and mid is %x\n",methodIndex);
long size = 0;
long messagesCount = 0;
@ -169,18 +201,12 @@ void urpManager::SendUrpRequest(bcOID oid, bcIID iid,
mt->WriteType(iid, message);
mt->WriteOid(oid, message);
bcTID thrID = (bcTID)PR_GetCurrentThread();
printf("OID is written %ld\n", thrID);
printf("OID is written %ld\n", oid);
mt->WriteThreadID(thrID, message);
broker = call->GetORB();
mt->WriteParams(call, paramCount, info, interfaceInfo, message, methodIndex);
delete mt;
if(connTable) {
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
urpConnection* con = connTable->Get(&thrHK);
con->Write(message);
} else
connection->Write(message);
connection->Write(message);
delete message;
}
@ -192,11 +218,12 @@ nsresult
urpManager::ReadReply(urpPacket* message, char header,
bcICall* call, PRUint32 paramCount,
const nsXPTMethodInfo *info,
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex,
urpConnection* conn) {
nsresult rv = NS_OK;
printf("this is method readReply\n");
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
rv = mt->ReadParams(paramCount, info, message, interfaceInfo, methodIndex, call, broker, this);
rv = mt->ReadParams(paramCount, info, message, interfaceInfo, methodIndex, call, broker, this, conn);
delete mt;
return rv;
}
@ -204,22 +231,45 @@ urpManager::ReadReply(urpPacket* message, char header,
nsresult
urpManager::ReadMessage(urpConnection* conn, PRBool isClient) {
nsresult rv = NS_OK;
if(!isClient) {
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
connTable->Put(&thrHK, conn);
}
PRBool inserted = PR_FALSE;
bcTID tid;
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
if((header & REQUEST) != 0) { // a request ?
bcIID iid;
bcOID oid;
PRUint16 methodId;
if((header & LONGMETHODID) != 0) // usigned short ?
methodId = message->ReadShort();
else
methodId = message->ReadByte();
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_FALSE);
if((header & NEWTYPE) != 0)
iid = mt->ReadType(message);
if((header & NEWOID) != 0) // new oid?
oid = mt->ReadOid(message);
if((header & NEWTID) != 0) // new thread id ?
tid = mt->ReadThreadID(message);
delete mt;
sendThreadArg *arg = new sendThreadArg( this, header,
message, iid, oid, tid, methodId, conn);
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
send_thread_start,
arg,
PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD,
0);
} else { // a reply
bcIID iid; bcOID oid; bcMID mid;
bcTID tid;
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
if((header & NEWTID) != 0) { // new thread id ?
printf("new threadID\n");
@ -248,20 +298,17 @@ urpManager::ReadMessage(urpConnection* conn, PRBool isClient) {
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(mid, (const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
ReadReply(message, header, mc->call, paramCount, info, interfaceInfo, mid);
ReadReply(message, header, mc->call, paramCount,
info, interfaceInfo, mid, conn);
PR_EnterMonitor(mc->mon);
PR_Notify(mc->mon);
PR_ExitMonitor(mc->mon);
}
}
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);
else { // only a short request header
// rv = ReadShortRequest(header, message);
break;
}
}
return rv;
}
@ -277,7 +324,8 @@ urpManager::ReadShortRequest(char header, urpPacket* message) {
nsresult
urpManager::SendReply(bcTID tid, bcICall* call, PRUint32 paramCount,
const nsXPTMethodInfo* info,
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex,
urpConnection* connection) {
nsresult rv = NS_OK;
char header = (char)BIG_HEADER;
header |= NEWTID;
@ -289,39 +337,19 @@ urpManager::SendReply(bcTID tid, bcICall* call, PRUint32 paramCount,
methodIndex);
delete mt;
if(NS_FAILED(rv)) return rv;
if(connTable) {
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
urpConnection* con = (urpConnection*)connTable->Get(&thrHK);
con->Write(message);
} else
connection->Write(message);
connection->Write(message);
delete message;
return rv;
}
nsresult
urpManager::ReadLongRequest(char header, urpPacket* message) {
bcIID iid;
bcOID oid;
bcTID tid;
PRUint16 methodId;
urpManager::ReadLongRequest(char header, urpPacket* message,
bcIID iid, bcOID oid, bcTID tid,
PRUint16 methodId, urpConnection* conn) {
nsresult rv = NS_OK;
if((header & LONGMETHODID) != 0) // usigned short ?
methodId = message->ReadShort();
else
methodId = message->ReadByte();
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_FALSE);
if((header & NEWTYPE) != 0)
iid = mt->ReadType(message);
if((header & NEWOID) != 0) // new oid?
oid = mt->ReadOid(message);
if((header & NEWTID) != 0) // new thread id ?
tid = mt->ReadThreadID(message);
printf("method readLongRequest: tid %ld %ld\n",tid,oid);
char ignore_cache = ((header & IGNORECACHE) != 0); // do not use cache for this request?
@ -356,11 +384,13 @@ char* name;
interfaceInfo->GetMethodInfo(methodId,(const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
bcICall *call = broker->CreateCall(&iid, &oid, methodId);
mt->ReadParams(paramCount, info, message, interfaceInfo, methodId, call, broker, this);
mt->ReadParams(paramCount, info, message, interfaceInfo, methodId, call, broker, this, conn);
delete mt;
delete message;
//nb return value; excepion handling
broker->SendReceive(call);
rv = SendReply(tid, call, paramCount, info, interfaceInfo, methodId);
rv = SendReply(tid, call, paramCount, info, interfaceInfo,
methodId, conn);
return rv;
}

Просмотреть файл

@ -30,6 +30,8 @@
class urpManager {
friend void send_thread_start (void * arg);
public:
urpManager(PRBool IsClient, bcIORB *orb, urpConnection* connection);
~urpManager();
@ -37,25 +39,31 @@ public:
PRUint16 methodIndex,
nsIInterfaceInfo* interfaceInfo,
bcICall *call,
PRUint32 paramCount, const nsXPTMethodInfo* info);
PRUint32 paramCount, const nsXPTMethodInfo* info,
urpConnection* conn);
nsresult ReadMessage(urpConnection* conn, PRBool ic);
nsresult SetCall(bcICall* call, PRMonitor *m);
nsresult RemoveCall();
private:
nsHashtable* connTable;
nsHashtable* monitTable;
bcIORB *broker;
urpConnection* connection;
/* for ReadReply */
nsIInterfaceInfo *interfaceInfo;
void TransformMethodIDAndIID();
nsresult ReadReply(urpPacket* message, char header,
bcICall* call, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex);
nsresult ReadLongRequest(char header, urpPacket* message);
bcICall* call, PRUint32 paramCount,
const nsXPTMethodInfo *info,
nsIInterfaceInfo *interfaceInfo,
PRUint16 methodIndex, urpConnection* conn);
nsresult ReadLongRequest(char header, urpPacket* message,
bcIID iid, bcOID oid, bcTID tid,
PRUint16 methodId, urpConnection* conn);
nsresult ReadShortRequest(char header, urpPacket* message);
nsresult SendReply(bcTID tid, bcICall* call, PRUint32 paramCount,
const nsXPTMethodInfo* info,
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex);
nsIInterfaceInfo *interfaceInfo,
PRUint16 methodIndex, urpConnection* conn);
};
#endif

Просмотреть файл

@ -134,17 +134,19 @@ urpMarshalToolkit::WriteElement(bcIUnMarshaler *um, nsXPTParamInfo * param, uint
}
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++) {
if(data != nsnull) {
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;
}
}
} else {
length = nsCRT::strlen((const char*)data);
length+=1;
}
}
message->WriteString((char*)data,length);
break;
}
@ -216,6 +218,14 @@ urpMarshalToolkit::WriteParams(bcICall *call, PRUint32 paramCount, const nsXPTMe
nsresult rv = NS_OK;
bcIAllocator * allocator = new urpAllocator(nsAllocator::GetGlobalAllocator());
bcIUnMarshaler *um = call->GetUnMarshaler();
if(!isClient) {
nsresult result;
um->ReadSimple(&result, bc_T_U32);
if(!NS_SUCCEEDED(result)) {
printf("Returned result is error on server side\n");
}
message->WriteInt(result);
}
for(i=0;i<paramCount;i++) {
short cache_index;
nsXPTParamInfo param = info->GetParam(i);
@ -242,7 +252,8 @@ nsresult
urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex, bcIAllocator* allocator,
bcIMarshaler* m, bcIORB *broker, urpManager* man) {
bcIMarshaler* m, bcIORB *broker, urpManager* man,
urpConnection* conn) {
void* data = allocator->Alloc(sizeof(void*));
nsresult r = NS_OK;
switch(type) {
@ -321,7 +332,7 @@ urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
nsIID iid = ReadType(message);
nsISupports *proxy = NULL;
if (oid != 0) {
urpStub* stub = new urpStub(man);
urpStub* stub = new urpStub(man, conn);
broker->RegisterStubWithOID(stub, &oid);
}
m->WriteSimple(&oid, XPTType2bcXPType(type));
@ -345,7 +356,7 @@ urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
m->WriteSimple(&arraySize,bc_T_U32);
char *current = *(char**)data;
for (int i = 0; i < arraySize; i++) {
ReadElement(param,datumType.TagPart(),interfaceInfo, message, methodIndex, allocator, m, broker, man);
ReadElement(param,datumType.TagPart(),interfaceInfo, message, methodIndex, allocator, m, broker, man, conn);
}
} else {
size_t length = 0;
@ -368,11 +379,18 @@ urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
}
nsresult
urpMarshalToolkit::ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpManager* man) {
urpMarshalToolkit::ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpManager* man, urpConnection* conn) {
bcIAllocator * allocator = new urpAllocator(nsAllocator::GetGlobalAllocator());
bcIMarshaler* m = call->GetMarshaler();
int i;
nsresult rv = NS_OK;
if(isClient) {
nsresult result = message->ReadInt();
m->WriteSimple(&result, bc_T_U32);
if (!NS_SUCCEEDED(result)) {
printf("Returned result is error on client side\n");
}
}
for(i=0;i<paramCount;i++) {
short cache_index;
nsXPTParamInfo param = info->GetParam(i);
@ -384,7 +402,7 @@ urpMarshalToolkit::ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info,
}
rv = ReadElement(&param, param.GetType().TagPart(), interfaceInfo,
message, methodIndex, allocator, m, orb, man);
message, methodIndex, allocator, m, orb, man, conn);
if(NS_FAILED(rv)) {
delete allocator;
delete m;

Просмотреть файл

@ -35,7 +35,7 @@ public:
urpMarshalToolkit(PRBool isClient);
~urpMarshalToolkit();
nsresult ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpManager* man);
nsresult ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpManager* man, urpConnection* conn);
nsresult WriteParams(bcICall *call, PRUint32 paramCount, const nsXPTMethodInfo * info, nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex);
void WriteType(bcIID iid, urpPacket* message);
@ -55,7 +55,8 @@ private:
nsresult ReadElement(nsXPTParamInfo * param, uint8 type,
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex, bcIAllocator * allocator,
bcIMarshaler* m, bcIORB *orb, urpManager* man);
bcIMarshaler* m, bcIORB *orb, urpManager* man,
urpConnection* conn);
bcXPType XPTType2bcXPType(uint8 type);
};

Просмотреть файл

@ -30,8 +30,9 @@
#include "urpManager.h"
urpStub::urpStub(urpManager* man) {
urpStub::urpStub(urpManager* man, urpConnection* conn) {
manager = man;
connection = conn;
}
@ -72,7 +73,7 @@ printf("ThreadID is written %d %p %p %p %p\n",paramCount, call, mon, manager, th
exit(-1);
}
manager->SendUrpRequest(oid, iid, mid, interfaceInfo, call, paramCount,
info);
info, connection);
if(NS_FAILED(PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT))) {
printf("Can't wait on cond var\n");
exit(-1);

Просмотреть файл

@ -30,11 +30,12 @@
class urpStub : public bcIStub {
public:
urpStub(urpManager* man);
urpStub(urpManager* man, urpConnection* con);
virtual ~urpStub();
virtual void Dispatch(bcICall *call) ;
private:
urpManager* manager;
urpConnection* connection;
};
#endif