[PD-dev] Observable, class_setfieldnames
Mathieu Bouchard
matju at artengine.ca
Thu Oct 6 10:46:45 CEST 2005
On Thu, 6 Oct 2005, Mathieu Bouchard wrote:
> hi everybody, I just added this:
> EXTERN void class_setfieldnames(t_class *x, const char *s);
Ok, now WHY I've added it: this is so that objects uploaded from server to
client don't have to be completely uploaded each time. I number the fields
so that I have a bitfield of which fields are "dirty".
This is very similar to how XSetWindowAttributes() sends data to an X11
server, except that it uses a bunch of #defines instead and it deals with
only one struct type and is not extensible.
nota bene: the following is only enabled with "scons desire=1".
I am implementing an observer/observable interface in t_gobj. Because I
want to keep ABI compatibility with most externals, I've taken out the one
field I could, g_next, and replaced it with a pointer to t_observable
called g_obs. The g_next field is now in that struct and so are the other
infos we need:
typedef struct _observable {
struct _gobj *master; /* pointer back to our t_gobj */
struct _gobj *next; /* formerly in t_gobj */
/* actual observable */
int dirty; /* bitset of fields */
int nobs; /* number of spies */
struct _gobj **obs;
/* virtual func for observer */
void (*notice)(struct _gobj *x, struct _gobj *origin, int dirty);
} t_observable;
And then there are a few functions for managing notifications.
EXTERN void observable_subscribe (t_observable *self, t_gobj *observer);
EXTERN void observable_unsubscribe (t_observable *self, t_gobj *observer);
Those two manage the relationships so that the observables know where to
forward their notifications.
EXTERN void observable_changed (t_observable *self, const char *k);
This records a change so that later a notification may be emitted.
EXTERN void observable_notify (t_observable *self);
This makes the observable notify its subscribers when asked to.
EXTERN void gobj_notice(t_gobj *x, t_gobj *origin, int dirty);
This is the function called on each subscribed object (observer). It
must have had glist_add called on it and then g_obs->notify must be set to
a valid function.
TODO:
* Pools of observables so that _notify may be batch-called on all of them
at once during idle time (or something...)
* Support for notices on portions of array data (intervals of indices)
* Something that actually uses that API
____________________________________________________________________
Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju
Freelance Digital Arts Engineer, Montréal QC Canada
More information about the Pd-dev
mailing list