Implement object broker mechanism.
[screen-lua.git] / src / script.h
blobdda07acf49aa43f503cb5393104550a00c3b69c6
1 /* Copyright (c) 2008 Sadrul Habib Chowdhury (sadrul@users.sf.net)
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 3, or (at your option)
6 * any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program (see the file COPYING); if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
18 ****************************************************************
19 * $Id$ FAU
21 #ifndef SCRIPT_H
22 #define SCRIPT_H
23 struct win;
25 /***Language binding***/
26 struct binding
28 char * name;
29 int inited;
30 int registered;
31 int (*bd_Init) __P((void));
32 int (*bd_Finit) __P((void));
33 int (*bd_call) __P((const char *func, const char **argv));
34 /*Returns zero on failure, non zero on success*/
35 int (*bd_Source) __P((const char *, int));
36 /* The return value is significant:
37 * a non-zero value will stop further
38 * notification to the rest of the chain.*/
39 int (*bd_dispatch) __P((void *handler, const char *params, va_list va));
41 struct binding *b_next;
44 void LoadBindings(void);
45 void FinalizeBindings(void);
46 void ScriptCmd __P((int argc, const char **argv));
48 /***Script events***/
50 struct script_event;
51 /* Script event listener */
52 struct listener
54 /*Binding dependent event handler data*/
55 void *handler;
56 struct binding *bd;
58 /* smaller means higher privilege.*/
59 unsigned int priv;
60 struct listener *chain;
61 struct listener *prev;
64 /* the script_event structure needs to be zeroed before using.
65 * embeding this structure directly into screen objects will do the job, as
66 * long as the objects are created from calloc() call.*/
67 struct script_event
69 /* expected parameter description of this event. */
70 char *params;
71 struct listener listeners;
73 struct script_event* object_get_event __P((char *obj, const char *name));
74 int trigger_sevent(struct script_event *ev, VA_DOTS);
75 int register_listener(struct script_event *ev, struct listener *l);
76 void unregister_listener(struct listener *l);
78 struct broker
80 void *obj;
81 int ref;
82 int valid;
83 struct broker *b_next;
86 /* At most one broker object is created and reused for one object.
87 * A counter is maintained for broker references. A broker to valid object can
88 * be dereferenced as many times as you wish. But once the object is
89 * invalidated, each dereference action will decrease the counter by one, and
90 * return a NULL pointer. The binding should further invalidate the script
91 * variable that refers to the broker. This scheme will work for languages
92 * that always treat host objects as reference and never do value copy.*/
93 struct broker *get_obj_broker(void *obj);
94 void * get_broker_obj(struct broker *broker);
95 void broker_inv_obj(void *obj);
97 struct gevents
99 struct script_event cmdexecuted;
100 struct script_event detached;
101 struct script_event onattach;
102 struct script_event forechanged;
103 struct script_event processcaption;
105 extern struct gevents globalevents;
106 #endif