Moved the typed object registry into the same package with the rest of
the typed object stuff; made events typed so they can be transported; further wiring up of event dispatch over the network. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@34 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
//
|
||||
// $Id: AttributeChangedEvent.java,v 1.3 2001/06/01 20:35:39 mdb Exp $
|
||||
// $Id: AttributeChangedEvent.java,v 1.4 2001/06/11 17:44:04 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.dobj;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.threerings.cocktail.cher.Log;
|
||||
|
||||
/**
|
||||
@@ -13,8 +17,11 @@ import com.threerings.cocktail.cher.Log;
|
||||
*
|
||||
* @see DObjectManager.postEvent
|
||||
*/
|
||||
public class AttributeChangedEvent extends DEvent
|
||||
public class AttributeChangedEvent extends TypedEvent
|
||||
{
|
||||
/** The typed object code for this event. */
|
||||
public static final short TYPE = TYPE_BASE + 1;
|
||||
|
||||
/**
|
||||
* Constructs a new attribute changed event on the specified target
|
||||
* object with the supplied attribute name and value.
|
||||
@@ -106,6 +113,27 @@ public class AttributeChangedEvent extends DEvent
|
||||
return true;
|
||||
}
|
||||
|
||||
public short getType ()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
super.writeTo(out);
|
||||
out.writeUTF(_name);
|
||||
// out.write...(_value);
|
||||
}
|
||||
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
super.readFrom(in);
|
||||
_name = in.readUTF();
|
||||
// _value = in.read...
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
return "[CHANGE:targetOid=" + _toid + ", name=" + _name +
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
//
|
||||
// $Id: AttributesChangedEvent.java,v 1.2 2001/06/02 01:30:37 mdb Exp $
|
||||
// $Id: AttributesChangedEvent.java,v 1.3 2001/06/11 17:44:04 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.dobj;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An attribute<em>s</em> changed event is dispatched when multiple
|
||||
* attributes of a distributed object have been changed in a single
|
||||
@@ -10,8 +14,11 @@ package com.threerings.cocktail.cher.dobj;
|
||||
*
|
||||
* @see DObjectManager.postEvent
|
||||
*/
|
||||
public class AttributesChangedEvent extends DEvent
|
||||
public class AttributesChangedEvent extends TypedEvent
|
||||
{
|
||||
/** The typed object code for this event. */
|
||||
public static final short TYPE = TYPE_BASE + 2;
|
||||
|
||||
/**
|
||||
* Constructs a new attribute changed event on the specified target
|
||||
* object with the supplied attribute name and value.
|
||||
@@ -152,6 +159,35 @@ public class AttributesChangedEvent extends DEvent
|
||||
return true;
|
||||
}
|
||||
|
||||
public short getType ()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
super.writeTo(out);
|
||||
out.writeInt(_count);
|
||||
for (int i = 0; i < _count; i++) {
|
||||
out.writeUTF(_names[i]);
|
||||
// out.write...(_values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
super.readFrom(in);
|
||||
_count = in.readInt();
|
||||
_names = new String[_count];
|
||||
_values = new Object[_count];
|
||||
for (int i = 0; i < _count; i++) {
|
||||
_names[i] = in.readUTF();
|
||||
// _values[i] = ...
|
||||
}
|
||||
}
|
||||
|
||||
protected int _count;
|
||||
protected String[] _names;
|
||||
protected Object[] _values;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// $Id: TypedEvent.java,v 1.1 2001/06/11 17:44:04 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.dobj;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.threerings.cocktail.cher.io.TypedObject;
|
||||
|
||||
/**
|
||||
* A typed event is one that can be transmitted over the network. All
|
||||
* event classes that will be shared between the client and server should
|
||||
* derive from this class and be registered with the typed object factory
|
||||
* so that they can be serialized and unserialized.
|
||||
*/
|
||||
public abstract class TypedEvent extends DEvent implements TypedObject
|
||||
{
|
||||
/**
|
||||
* All event derived classes should base their typed object code on
|
||||
* this base value.
|
||||
*/
|
||||
public static final short TYPE_BASE = 400;
|
||||
|
||||
/**
|
||||
* Constructs a typed event, passing the target object id on to the
|
||||
* <code>DEvent</code> constructor.
|
||||
*/
|
||||
public TypedEvent (int targetOid)
|
||||
{
|
||||
super(targetOid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a blank typed event instance that will be unserialized
|
||||
* from the network.
|
||||
*/
|
||||
public TypedEvent ()
|
||||
{
|
||||
super(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes should override this function to write their fields
|
||||
* out to the supplied data output stream. They <em>must</em> be sure
|
||||
* to first call <code>super.writeTo()</code>.
|
||||
*/
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
out.writeInt(_toid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes should override this function to read their fields
|
||||
* from the supplied data input stream. They <em>must</em> be sure to
|
||||
* first call <code>super.readFrom()</code>.
|
||||
*/
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
_toid = in.readInt();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user