]> git.decadent.org.uk Git - ion3.git/blob - ioncore/basicpholder.c
d5c85a4fca897ae7404d2d05c49d1ce86881daf5
[ion3.git] / ioncore / basicpholder.c
1 /*
2  * ion/ioncore/basicpholder.c
3  *
4  * Copyright (c) Tuomo Valkonen 2005-2007. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <libtu/objp.h>
13 #include <libtu/obj.h>
14 #include <libtu/pointer.h>
15
16 #include "basicpholder.h"
17
18
19 /*{{{ Init/deinit */
20
21
22 static void basicpholder_watch_handler(Watch *watch, Obj *reg)
23 {
24     WBasicPHolder *ph=FIELD_TO_STRUCT(WBasicPHolder, reg_watch, watch);
25     pholder_redirect(&(ph->ph), (WRegion*)reg);
26 }
27
28
29 bool basicpholder_init(WBasicPHolder *ph, WRegion *reg, 
30                        WBasicPHolderHandler *hnd)
31 {
32     assert(reg!=NULL && hnd!=NULL);
33     
34     pholder_init(&(ph->ph));
35
36     watch_init(&(ph->reg_watch));
37     
38     if(!watch_setup(&(ph->reg_watch), (Obj*)reg, basicpholder_watch_handler)){
39         pholder_deinit(&(ph->ph));
40         return FALSE;
41     }
42     
43     ph->hnd=hnd;
44     
45     return TRUE;
46 }
47  
48
49 WBasicPHolder *create_basicpholder(WRegion *reg, 
50                                    WBasicPHolderHandler *hnd)
51 {
52     CREATEOBJ_IMPL(WBasicPHolder, basicpholder, (p, reg, hnd));
53 }
54
55
56 void basicpholder_deinit(WBasicPHolder *ph)
57 {
58     watch_reset(&(ph->reg_watch));
59     pholder_deinit(&(ph->ph));
60 }
61
62
63 /*}}}*/
64
65
66 /*{{{ Dynfuns */
67
68
69 WRegion *basicpholder_do_attach(WBasicPHolder *ph, int flags,
70                                 WRegionAttachData *data)
71 {
72     WRegion *reg=(WRegion*)ph->reg_watch.obj;
73
74     if(reg==NULL || ph->hnd==NULL)
75         return FALSE;
76
77     return ph->hnd(reg, flags, data);
78 }
79
80
81 bool basicpholder_do_goto(WBasicPHolder *ph)
82 {
83     WRegion *reg=(WRegion*)ph->reg_watch.obj;
84     
85     if(reg!=NULL)
86         return region_goto((WRegion*)reg);
87     
88     return FALSE;
89 }
90
91
92 WRegion *basicpholder_do_target(WBasicPHolder *ph)
93 {
94     return (WRegion*)ph->reg_watch.obj;
95 }
96
97
98 /*}}}*/
99
100
101 /*{{{ Class information */
102
103
104 static DynFunTab basicpholder_dynfuntab[]={
105     {(DynFun*)pholder_do_attach, 
106      (DynFun*)basicpholder_do_attach},
107
108     {(DynFun*)pholder_do_goto, 
109      (DynFun*)basicpholder_do_goto},
110
111     {(DynFun*)pholder_do_target, 
112      (DynFun*)basicpholder_do_target},
113     
114     END_DYNFUNTAB
115 };
116
117 IMPLCLASS(WBasicPHolder, WPHolder, basicpholder_deinit, 
118           basicpholder_dynfuntab);
119
120
121 /*}}}*/
122