module._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
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 2 of the License, or
6  * (at your option) any later version.
7  *
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.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * $Id: module.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 inherit "/classes/Object";
20 #include <classes.h>
21 #include <macros.h>
22 #include <assert.h>
23 #include <exception.h>
24 #include <attributes.h>
25 #include <events.h>
26 class module : public Object{
27 public:
28 
29 
30 
31 
32 
33 
34 protected:
35  void install_module() { }
36 
37 public:
38 protected:
39  void create_module() {}
40 
41 public:
42 protected:
43  void load_module() { }
44 
45 public:
46 bool check_swap() { return false; }
47 
48 /**
49 private:
50  * Callback function to initialize a module. This will call init_module()
51  * for any module.
52  *
53  */
54 protected:
55  final void init()
56 {
57  ::init();
58  init_module();
59 }
60 
61 public:
62 
63 /**
64 private:
65  * init_module is called by the Server when starting or when a package is
66  * registered.
67  *
68  */
69 private:
70 void init_module()
71 {
72 }
73 
74 public:
75 
76 /**
77  * Called from _Server when loading is finished.
78  *
79  */
80 protected:
81  void load_object()
82 {
83  load_module();
84 }
85 
86 public:
87 
88 void post_load_module()
89 {
90 }
91 
92 protected:
93  mapping read_config(string cdata, string roottag)
94 {
95  return Module.read_config(cdata, roottag);
96 }
97 
98 public:
99 
100 /**
101  * Called after all modules and factories are loaded at startup
102  * or right after the package has been installed. This way the function
103  * might use factories for installation for example. The server has
104  * basically started at this point.
105  *
106  */
107 void runtime_install()
108 {
109  if ( CALLER != _Server && !(CALLER->get_object_class() & CLASS_PACKAGE) )
110  return;
111 
112  install_module();
113 }
114 
115 /**
116  * Create the module.
117  *
118  * @param string|object id - the related id.
119  */
120 protected:
121 final void
122 create_object(string|object id)
123 {
124  do_set_attribute(OBJ_CREATION_TIME, time());
125  create_module();
126 }
127 
128 public:
129 
130 /**
131  * Create a duplicate of the module, which will fail in this case.
132  * The function was only overriden to prevent duplication of modules.
133  *
134  * @return throws an error.
135  */
136 final object duplicate()
137 {
138  THROW("Modules cannot be duplicated!", E_ERROR);
139  return 0;
140 }
141 
142 /**
143  * return the object class for global objets "0"
144  *
145  * @return the object class
146  */
147 int get_object_class()
148 {
149  return CLASS_MODULE | ::get_object_class();
150 }
151 
152 
153 /**
154  * Add a global event. This will only call the server object to
155  * listen to the appropriate events. This is basic functionality of a
156  * module. Register the event-callback function.
157  *
158  * @param int event - the event to subscribe to
159  * @param function cb - the callback function to be called
160  * @param int phase - the phase: blocking or notification
161  */
162 protected:
163  void add_global_event(int event, function cb, int phase)
164 {
165  _Server->add_global_event(event, cb, phase);
166 }
167 
168 public:
169 
170 /**
171  * Remove all subscribed global events.
172  *
173  * @see add_global_event
174  */
175 protected:
176  void remove_global_events()
177 {
178  _Server->remove_global_events();
179 }
180 
181 public:
182 
183 /**
184  * This function is called when an attribute is changed in the object,
185  * that acquires an attribute from this object.
186  *
187  * @param object o - the object where an attribute was changed
188  * @param key - the key of the attribute
189  * @param val - the new value of the attribute
190  * @return false will make the acquire set to none in the calling object
191  */
192 bool keep_acquire(object o, mixed key, mixed val)
193 {
194  return true; // should still acquire from module
195 }
196 
197 
198 protected:
199  void delete_object()
200 {
201  catch {
202  try_event( EVENT_DELETE, CALLER );
203  };
204  ::delete_object();
205 }
206 
207 public:
208 
209 
210 {
211 // do not run the default Object test
212 }
213 
214 
215 };