[PATCH] Xi: check all handlers before applying property changes.

Simon Thum simon.thum at gmx.de
Fri Oct 10 02:54:56 PDT 2008


Peter Hutterer wrote:
> something like
> 
> --
> RegisterHandler(myHandler, HEAD);
> RegisterHandler(otherHandler, TAIL);
> 
> void myHandler(foo) {
> 
>    CallNextHandler(); /* causes otherHandler to be called */
>    return PROP_HANDLED;
> }
> --
> 
> Where CallNextHandler calls the handler next in the queue.
> Do I get that right? 
Except for the void before myHandler(), yes :)

> If so, a few questions:
> - A handler that registers at the head of the queue, assumes it is before
>   other handlers. Thus it has to be aware of other handlers in the first
>   place?
Yes, that would be the uncommon case, in which we should be well aware
we're doing something special.

> - Two handlers that place themselves at the head of the queue now both assume
>   they are called first?
That's an assumption you shouldn't make. You can make the assumption
that you're called before the others already in.

> - What if the handler order has to be different for each property?
You need two handlers. Keep in mind handlers may well handle different
property sets, so order can't depend on the prop alone.

> - What reason would a handler have for registering at the tail, other than
>   that it doesn't care whether it is ever called or not? 
Well, be a nice citizen and don't set the house afire :)
A rule of thumb might be: Who does CallNextHandler() may use HEAD. It
should clearly be the exception, not the rule.

I just used HEAD/TAIL since I didn't see a need for more complicated
schemes, like priority.

>   At which point - what's the point of this handler anyway?
To simply do its job, just as anyone else. And if it gets 'fired', there
should be a reason for this.

> - if myHandler allows pass-through after changing state, what if otherHandler
>   returns an error code?
That's indeed a problem. You shouldn't do it :)
Either you call the rest first, if that's impossible, you should be
prepared to undo stuff.

I think when it gets that complicated, your situation is complicated
anyway. And when stuff is complicated, it's always better to have at
least some control.

Baseline is: Register TAIL, do your job. Or register HEAD, and the
stakes are higher. (I love it when code resembles life)

You also might want to consider this:
http://www.cs.clemson.edu/~malloy/courses/patterns/chain.html

Cheers,

Simon



More information about the xorg mailing list