if(DEBUG) System.err.println("##### " + getClass().getName() + ".writeRequest:" + oid + " " + zInterface + " " + operation);
++ _requestsSend;
++ _message_count;
IMethodDescription iMethodDescription = zInterface.getMethodDescription(operation);
byte header = 0;
boolean bigHeader = false;
if(_out_oid == null || !oid.equals(_out_oid)) { // change the oid?
header |= NEWOID;
_out_oid = oid;
bigHeader = true;
}
else
oid = null;
if(_out_interface == null || !_out_interface.equals(zInterface)) { // change interface
header |= NEWTYPE;
_out_interface = zInterface;
bigHeader = true;
}
else
zInterface = null;
if(_out_threadId == null || !_out_threadId.equals(threadId)) { // change thread id
header |= NEWTID;
_out_threadId = threadId;
bigHeader = true;
}
else
threadId = null;
boolean hasExFlags = false;
// if synchron is provided, test if it differs from declaration
if(synchron[0] != null) {
if(iMethodDescription.isOneway() == synchron[0].booleanValue()) {
bigHeader = true;
hasExFlags = true;
}
}
else
synchron[0] = new Boolean(!iMethodDescription.isOneway());
// if mustReply is provided and if it differs from synchron
// then we have to write it
if(mustReply[0] != null && (mustReply[0] != synchron[0])) {
bigHeader = true;
hasExFlags = true;
}
else
mustReply[0] = synchron[0];
if(bigHeader) { // something has changed, send big header
header |= BIG_HEADER; // big header
header |= REQUEST;
header |= hasExFlags ? MOREFLAGS : 0;
if(iMethodDescription.getIndex() > 255)
header |= LONGMETHODID;
_marshal.writebyte(header);
if(hasExFlags) {// are there extended flags to write?
byte exFlags = 0;
exFlags |= synchron[0].booleanValue() ? SYNCHRONOUSE : 0;
exFlags |= mustReply[0].booleanValue() ? MUSTREPLY : 0;
_marshal.writebyte(exFlags);
}
// write the method id
if(iMethodDescription.getIndex() > 255)
_marshal.writeshort((short)iMethodDescription.getIndex());
else
_marshal.writebyte((byte)iMethodDescription.getIndex());
if(zInterface != null) // has the interface changed? -> write it
_marshal.writeTypeDescrption(zInterface);
if(oid != null) // has the oid changed? -> write it
_marshal.writeOid(_out_oid);
if(threadId != null) // has the thread id changed? -> write it
_marshal.writeThreadId(threadId);
}
else { // simple request
if(iMethodDescription.getIndex() <= 0x2f) // does the method id fit in the header?
_marshal.writebyte((byte)iMethodDescription.getIndex());
else { // no
header |= DIR_MID;
header |= iMethodDescription.getIndex() >> 8;
_marshal.writebyte(header);
_marshal.writebyte((byte)(iMethodDescription.getIndex() & 0xff));
}
}
// write the in parameters
ITypeDescription in_sig[] = iMethodDescription.getInSignature();
ITypeDescription out_sig[] = iMethodDescription.getOutSignature();
for(int i = 0; i < in_sig.length; ++ i) {
if(in_sig[i] != null) { // is it an in parameter?
if(out_sig[i] != null) // is it also an out parameter?
_marshal.writeObject(out_sig[i].getComponentType(), ((Object [])params[i])[0]);
else // in only
_marshal.writeObject(in_sig[i], params[i]);
}
}
if(synchron[0].booleanValue()) // if we are waiting for a reply, the reply is pending
putPendingRequest(_out_threadId, new Object[]{params, out_sig, iMethodDescription.getReturnSignature()});
}