… | |
… | |
60 | |
60 | |
61 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | |
62 | |
63 | void cfperl_init (); |
63 | void cfperl_init (); |
64 | void cfperl_main (); |
64 | void cfperl_main (); |
|
|
65 | void cfperl_emergency_save (); |
|
|
66 | void cfperl_cleanup (int make_core); |
65 | |
67 | |
66 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
67 | |
69 | |
68 | // virtual server time, excluding time jumps and lag |
70 | // virtual server time, excluding time jumps and lag |
69 | extern double runtime; |
71 | extern double runtime; |
… | |
… | |
120 | double cfperl_result_DOUBLE (int idx); |
122 | double cfperl_result_DOUBLE (int idx); |
121 | int cfperl_result_INT (int idx); |
123 | int cfperl_result_INT (int idx); |
122 | |
124 | |
123 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
125 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | |
126 | |
|
|
127 | INTERFACE_CLASS (attachable) |
125 | struct attachable |
128 | struct attachable |
126 | { |
129 | { |
127 | static MGVTBL vtbl; |
130 | static MGVTBL vtbl; |
128 | |
131 | |
129 | static unordered_vector<attachable *> mortals; |
132 | static unordered_vector<attachable *> mortals; |
130 | static void check_mortals (); |
133 | MTH static void check_mortals (); |
131 | |
134 | |
132 | enum { |
135 | enum { |
133 | F_DESTROYED = 0x01, |
136 | F_DESTROYED = 0x01, |
134 | F_BORROWED = 0x02, |
137 | F_DEBUG_TRACE = 0x02, |
135 | }; |
138 | }; |
136 | |
139 | |
137 | // object is delete'd after the refcount reaches 0 |
140 | // object is delete'd after the refcount reaches 0 |
|
|
141 | int ACC (RW, flags); |
138 | mutable int refcnt; |
142 | mutable int ACC (RW, refcnt); |
139 | int flags; |
|
|
140 | |
143 | |
141 | void refcnt_inc () const { ++refcnt; } |
144 | MTH void refcnt_inc () const { ++refcnt; } |
142 | void refcnt_dec () const { --refcnt; } |
145 | MTH void refcnt_dec () const { --refcnt; } |
143 | |
146 | |
|
|
147 | MTH int refcnt_cnt () const; |
144 | // check wether the object has died and destroy |
148 | // check wether the object has died and destroy |
145 | void refcnt_chk () { if (refcnt <= 0) do_check (); } |
149 | MTH void refcnt_chk () { if (refcnt <= 0) do_check (); } |
146 | |
150 | |
147 | // destroy the object unless it was already destroyed |
151 | // destroy the object unless it was already destroyed |
148 | // this politely asks everybody interested the reduce |
152 | // this politely asks everybody interested the reduce |
149 | // the refcount to 0 as soon as possible. |
153 | // the refcount to 0 as soon as possible. |
150 | void destroy (); |
154 | MTH void destroy (); |
151 | |
155 | |
152 | // return wether an object was destroyed already |
156 | // return wether an object was destroyed already |
153 | bool destroyed () const { return flags & F_DESTROYED; } |
157 | MTH bool destroyed () const { return flags & F_DESTROYED; } |
154 | |
158 | |
155 | virtual void gather_callbacks (AV *&callbacks, event_type event) const; |
159 | virtual void gather_callbacks (AV *&callbacks, event_type event) const; |
156 | |
160 | |
157 | #if 0 |
161 | #if 0 |
158 | private: |
162 | private: |
… | |
… | |
162 | |
166 | |
163 | HV *self; // CF+ perl self |
167 | HV *self; // CF+ perl self |
164 | AV *cb; // CF+ callbacks |
168 | AV *cb; // CF+ callbacks |
165 | shstr attach; // generic extension attachment information |
169 | shstr attach; // generic extension attachment information |
166 | |
170 | |
|
|
171 | void sever_self (); // sever this object from its self, if it has one. |
167 | void optimise (); // possibly save some memory by destroying unneeded data |
172 | void optimise (); // possibly save some memory by destroying unneeded data |
168 | |
173 | |
169 | attachable () |
174 | attachable () |
170 | : flags (0), refcnt (0), self (0), cb (0), attach (0) |
175 | : flags (0), refcnt (0), self (0), cb (0), attach (0) |
171 | { |
176 | { |
172 | } |
177 | } |
… | |
… | |
179 | virtual ~attachable (); |
184 | virtual ~attachable (); |
180 | |
185 | |
181 | attachable &operator =(const attachable &src); |
186 | attachable &operator =(const attachable &src); |
182 | |
187 | |
183 | bool invoke (event_type event, ...); |
188 | bool invoke (event_type event, ...); |
184 | void instantiate (); |
189 | MTH void instantiate (); |
185 | void reattach (); |
190 | void reattach (); |
186 | |
191 | |
187 | protected: |
192 | protected: |
188 | // do the real refcount checking work |
193 | // do the real refcount checking work |
189 | void do_check (); |
194 | void do_check (); |
… | |
… | |
200 | |
205 | |
201 | extern struct global gbl_ev; |
206 | extern struct global gbl_ev; |
202 | |
207 | |
203 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
208 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
204 | |
209 | |
205 | struct object_freezer : dynbuf |
210 | struct object_freezer : dynbuf_text |
206 | { |
211 | { |
207 | AV *av; |
212 | AV *av; |
208 | |
213 | |
209 | object_freezer (); |
214 | object_freezer (); |
210 | ~object_freezer (); |
215 | ~object_freezer (); |
… | |
… | |
248 | } |
253 | } |
249 | |
254 | |
250 | *p = '\n'; |
255 | *p = '\n'; |
251 | } |
256 | } |
252 | |
257 | |
253 | void put (keyword k, const char *v) |
258 | void put (keyword k, const char *v = 0) |
254 | { |
259 | { |
255 | put_string (k, v); |
260 | put_string (k, v); |
256 | } |
261 | } |
257 | |
262 | |
258 | void put (keyword k, const shstr &v) |
263 | void put (keyword k, const shstr &v) |
… | |
… | |
323 | void put (keyword k, const refptr<T> &v) |
328 | void put (keyword k, const refptr<T> &v) |
324 | { |
329 | { |
325 | put (k, (T *)v); |
330 | put (k, (T *)v); |
326 | } |
331 | } |
327 | |
332 | |
328 | bool save (const char *filename); |
333 | bool save (const char *path); |
329 | char *as_string (); // like strdup |
334 | char *as_string (); // like strdup |
330 | |
335 | |
331 | operator bool () { return !!av; } |
336 | operator bool () { return !!av; } |
332 | }; |
337 | }; |
333 | |
338 | |
334 | // compatibility support, should be removed when no longer needed |
339 | // compatibility support, should be removed when no longer needed |
335 | int fprintf (object_freezer &freezer, const char *format, ...); |
340 | void fprintf (object_freezer &freezer, const char *format, ...); |
336 | int fputs (const char *s, object_freezer &freezer); |
341 | void fputs (const char *s, object_freezer &freezer); |
337 | |
342 | |
338 | struct object_thawer |
343 | struct object_thawer |
339 | { |
344 | { |
340 | SV *text; // text part |
345 | SV *text; // text part |
341 | AV *av; // perl part |
346 | AV *av; // perl part |
|
|
347 | int linenum; |
342 | char *line; // current beginning of line |
348 | char *line; // current beginning of line |
343 | char *last_keyword, *last_value; |
349 | keyword kw; |
|
|
350 | char *kw_str, *value; |
|
|
351 | const char *name; |
344 | |
352 | |
345 | operator bool () { return !!text; } |
353 | operator bool () { return !!text; } |
346 | |
354 | |
347 | object_thawer (const char *filename = 0); |
355 | object_thawer (const char *path = 0); |
348 | object_thawer (const char *data, AV *perlav); |
356 | object_thawer (const char *data, AV *perlav); |
349 | ~object_thawer (); |
357 | ~object_thawer (); |
350 | |
358 | |
351 | void get (attachable *obj, int oid); |
359 | void get (attachable *obj, int oid); |
352 | |
360 | |
353 | keyword get_kv (); // also parse value for later use |
361 | // parse next line |
354 | void skip_kv (keyword kw); |
362 | void next (); |
|
|
363 | // skip the current key-value (usually fetch next line, for |
|
|
364 | // multiline-fields, skips untilt he corresponding end-kw |
|
|
365 | void skip (); |
355 | |
366 | |
|
|
367 | //TODO: remove, deprecated |
|
|
368 | keyword get_kv () |
|
|
369 | { |
|
|
370 | next (); |
|
|
371 | return kw; |
|
|
372 | } |
|
|
373 | |
356 | const char *get_str () { return last_value; } // may be 0 |
374 | char *get_str () { return value; } // may be 0 |
357 | |
375 | |
358 | void get (shstr &sh) const; |
376 | void get (shstr &sh) const; |
359 | void get_ornull (shstr &sh) const { sh = last_value; } |
377 | void get_ornull (shstr &sh) const { sh = value; } |
360 | void get_ml (keyword kend, shstr &sh); |
378 | void get_ml (keyword kend, shstr &sh); |
361 | |
379 | |
362 | sint32 get_sint32 () const; |
380 | sint32 get_sint32 () const; |
363 | sint64 get_sint64 () const; |
381 | sint64 get_sint64 () const; |
364 | double get_double () const; |
382 | double get_double () const; |
… | |
… | |
373 | void get (uint16 &i) { i = get_sint32 (); } |
391 | void get (uint16 &i) { i = get_sint32 (); } |
374 | void get (sint32 &i) { i = get_sint32 (); } |
392 | void get (sint32 &i) { i = get_sint32 (); } |
375 | |
393 | |
376 | void get (uint32 &i) { i = get_sint64 (); } |
394 | void get (uint32 &i) { i = get_sint64 (); } |
377 | void get (sint64 &i) { i = get_sint64 (); } |
395 | void get (sint64 &i) { i = get_sint64 (); } |
378 | }; |
|
|
379 | |
396 | |
|
|
397 | bool parse_error (const char *type = 0, const char *name = 0, bool skip = true); |
|
|
398 | }; |
|
|
399 | |
|
|
400 | //TODO: remove |
380 | char *fgets (char *s, int n, object_thawer &thawer); |
401 | char *fgets (char *s, int n, object_thawer &thawer); |
381 | |
402 | |
382 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
403 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
383 | |
404 | |
384 | struct coroapi { |
405 | struct coroapi { |
385 | static struct CoroAPI *GCoroAPI; |
406 | static struct CoroAPI *GCoroAPI; |
386 | |
407 | |
387 | static int nready () { return CORO_NREADY; } |
408 | static int nready () { return CORO_NREADY; } |
388 | static int cede () { return CORO_CEDE ; } |
409 | static int cede () { return CORO_CEDE ; } |
|
|
410 | |
|
|
411 | static double (*time)(); |
|
|
412 | static double next_cede; |
|
|
413 | static int cede_counter; |
|
|
414 | |
|
|
415 | static void do_cede_every (); |
|
|
416 | static void do_cede_to_tick (); |
|
|
417 | static void do_cede_to_tick_every (); |
|
|
418 | |
|
|
419 | static void cede_every (int count) |
|
|
420 | { |
|
|
421 | if (++cede_counter >= count) |
|
|
422 | do_cede_every (); |
|
|
423 | } |
|
|
424 | |
|
|
425 | static void cede_to_tick () |
|
|
426 | { |
|
|
427 | if (time () >= next_cede) |
|
|
428 | do_cede_to_tick (); |
|
|
429 | } |
|
|
430 | |
|
|
431 | static void cede_to_tick_every (int count) |
|
|
432 | { |
|
|
433 | if (++cede_counter >= count) |
|
|
434 | cede_to_tick (); |
|
|
435 | } |
|
|
436 | |
|
|
437 | static void wait_for_tick (); |
|
|
438 | static void wait_for_tick_begin (); |
389 | }; |
439 | }; |
390 | |
440 | |
391 | struct watcher_base |
441 | struct watcher_base |
392 | { |
442 | { |
393 | static struct EventAPI *GEventAPI; |
443 | static struct EventAPI *GEventAPI; |