4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
10 #include <libmainloop/defer.h>
22 static Rb_node retrb
=NULL
;
32 bool region_do_set_return(WRegion
*reg
, WPHolder
*ph
)
37 assert(!OBJ_IS_BEING_DESTROYED(reg
));
39 region_unset_return(reg
);
47 node
=rb_insertp(retrb
, reg
, ph
);
49 region_notify_change(reg
, ioncore_g
.notifies
.set_return
);
55 WPHolder
*region_make_return_pholder(WRegion
*reg
)
57 WRegion
*mgr
=region_manager(reg
);
62 return region_managed_get_pholder(mgr
, reg
);
67 extern WPHolder *region_set_return(WRegion *reg)
69 WPHolder *ph=region_make_return_pholder(reg);
72 if(region_do_set_return(reg, ph))
74 destroy_obj((Obj*)ph);
87 Rb_node
do_find(WRegion
*reg
)
95 node
=rb_find_pkey_n(retrb
, reg
, &found
);
97 return (found
? node
: NULL
);
101 WPHolder
*region_do_get_return(WRegion
*reg
)
103 Rb_node node
=do_find(reg
);
105 return (node
!=NULL
? (WPHolder
*)node
->v
.val
: NULL
);
109 WPHolder
*region_get_return(WRegion
*reg
)
111 /* Should managers be scanned? */
112 return region_do_get_return(reg
);
122 static WPHolder
*do_remove_node(Rb_node node
)
124 WPHolder
*ph
=(WPHolder
*)node
->v
.val
;
126 rb_delete_node(node
);
132 WPHolder
*region_unset_get_return(WRegion
*reg
)
139 region_notify_change(reg
, ioncore_g
.notifies
.unset_return
);
140 return do_remove_node(node
);
147 void region_unset_return(WRegion
*reg
)
149 WPHolder
*ph
=region_unset_get_return(reg
);
152 mainloop_defer_destroy((Obj
*)ph
);
159 /*{{{ Internal Lua exports */
164 WRegion
*region___return_target(WRegion
*reg
)
166 WPHolder
*ph
=region_get_return(reg
);
167 return (ph
!=NULL
? pholder_target(ph
) : NULL
);