More work on things.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3900 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-03-01 23:52:52 +00:00
parent 679133091b
commit 740e00c731
22 changed files with 684 additions and 19 deletions
@@ -67,6 +67,21 @@ public class ClientObject extends DObject
}
// AUTO-GENERATED: METHODS START
public function addToReceivers (elem :DSetEntry) :void
{
requestEntryAdd(RECEIVERS, elem);
}
public function removeFromReceivers (key :Object) :void
{
requestEntryRemove(RECEIVERS, key);
}
public function updateReceivers (elem :DSetEntry) :void
{
requestEntryUpdate(RECEIVERS, elem);
}
public function setReceivers (value :DSet) :void
{
requestAttributeChange(RECEIVERS, value, this.receivers);
@@ -0,0 +1,117 @@
//
// $Id: InvocationMarshaller.java 3832 2006-02-04 03:49:53Z ray $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.data {
import com.threerings.util.ClassUtil;
import com.threerings.io.Streamable;
import com.threerings.presents.Log;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.ConfirmListener;
import com.threerings.presents.client.ResultListener;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.InvocationResponseEvent;
/**
* Provides a base from which all invocation service marshallers extend.
* Handles functionality common to all marshallers.
*/
public class InvocationMarshaller
implements Streamable, InvocationService
{
/**
* Initializes this invocation marshaller instance with the requisite
* information to allow it to operate in the wide world. This is
* called by the invocation manager when an invocation provider is
* registered and should not be called otherwise.
*/
public function init (invOid :int, invCode :int) :void
{
_invOid = invOid;
_invCode = invCode;
}
/**
* Sets the invocation oid to which this marshaller should send its
* invocation service requests. This is called by the invocation
* manager in certain initialization circumstances.
*/
public function setInvocationOid (invOid :int) :void
{
_invOid = invOid;
}
/**
* Returns the code assigned to this marshaller.
*/
public function getInvocationCode () :int
{
return _invCode;
}
/**
* Called by generated invocation marshaller code; packages up and
* sends the specified invocation service request.
*/
protected function sendRequest (
client :Client, methodId :int, args :Array) :void
{
client.getInvocationDirector().sendRequest(
_invOid, _invCode, methodId, args);
}
/**
* Generates a string representation of this instance.
*/
public function toString () :String
{
return "[invOid=" + _invOid + ", code=" + _invCode +
", type=" + ClassUtil.getClassName(this) + "]";
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeInt(_invOid);
out.writeInt(_invCode);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
_invOid = ins.readInt();
_invCode = ins.readInt();
}
/** The oid of the invocation object, where invocation service
* requests are sent. */
protected var _invOid :int;
/** The invocation service code assigned to this service when it was
* registered on the server. */
protected var _invCode :int;
}
}
@@ -0,0 +1,87 @@
package com.threerings.presents.data {
import com.threerings.util.ClassUtil;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
import com.threerings.presents.client.InvocationListener;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.InvocationResponseEvent;
import com.threerings.presents.Log;
public class ListenerMarshaller
implements Streamable, InvocationListener
{
/** The method id used to dispatch a requestFailed response. */
public const REQUEST_FAILED_RSPID :int = 0;
/** The oid of the invocation service requester. */
public var callerOid :int;
/** The request id associated with this listener. */
public var requestId :int;
/** The actual invocation listener associated with this
* marshalling listener. This is only valid on the client. */
public var listener :InvocationListener;
/** The time at which this listener marshaller was registered.
* This is only valid on the client. */
public var mapStamp :Number;
/** The distributed object manager to use when dispatching proxied
* responses. This is only valid on the server. */
public var omgr :DObjectManager;
// documentation inherited from interface
public function requestFailed (cause :String) :void
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, REQUEST_FAILED_RSPID,
[ cause ]));
}
/**
* Called to dispatch an invocation response to our target
* listener.
*/
public function dispatchResponse (methodId :int, args :Array) :void
{
if (methodId == REQUEST_FAILED_RSPID) {
listener.requestFailed((args[0] as String));
} else {
Log.warning("Requested to dispatch unknown invocation " +
"response [listener=" + listener +
", methodId=" + methodId +
", args=" + args + "].");
}
}
/**
* Generates a string representation of this instance.
*/
public function toString () :String
{
return "[callerOid=" + callerOid + ", reqId=" + requestId +
", type=" + ClassUtil.getClassName(this) + "]";
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeInt(callerOid);
out.writeShort(requestId);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
callerOid = ins.readInt();
requestId = ins.readShort();
}
}
}