ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/cfperl.h
(Generate patch)

Comparing deliantra/server/include/cfperl.h (file contents):
Revision 1.55 by root, Tue Feb 13 16:23:31 2007 UTC vs.
Revision 1.64 by root, Sat May 19 00:08:11 2007 UTC

2// cfperl.h perl interface 2// cfperl.h perl interface
3// 3//
4#ifndef CFPERL_H__ 4#ifndef CFPERL_H__
5#define CFPERL_H__ 5#define CFPERL_H__
6 6
7#include <cstdarg>
7#include <cstdio> 8#include <cstdio>
9#include <bitset>
8 10
9using namespace std; 11using namespace std;
10 12
11#include <EXTERN.h> 13#include <EXTERN.h>
12#include <perl.h> 14#include <perl.h>
87# define def(klass,name) EVENT_ ## klass ## _ ## name, 89# define def(klass,name) EVENT_ ## klass ## _ ## name,
88# include "eventinc.h" 90# include "eventinc.h"
89# undef def 91# undef def
90 NUM_EVENT_TYPES 92 NUM_EVENT_TYPES
91}; 93};
94
95// in which global events or per-type events are we interested
96extern bitset<NUM_EVENT_TYPES> ev_want_event;
97extern bitset<NUM_TYPES> ev_want_type;
92 98
93#define ARG_AV(o) DT_AV , static_cast<AV *> (o) 99#define ARG_AV(o) DT_AV , static_cast<AV *> (o)
94#define ARG_INT(v) DT_INT , static_cast<int> (v) 100#define ARG_INT(v) DT_INT , static_cast<int> (v)
95#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v) 101#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v)
96#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v) 102#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v)
136 F_DESTROYED = 0x01, 142 F_DESTROYED = 0x01,
137 F_DEBUG_TRACE = 0x02, 143 F_DEBUG_TRACE = 0x02,
138 }; 144 };
139 145
140 // object is delete'd after the refcount reaches 0 146 // object is delete'd after the refcount reaches 0
147 int ACC (RW, flags);
141 mutable int ACC (RW, refcnt); 148 mutable int ACC (RW, refcnt);
142 int ACC (RW, flags);
143 149
144 MTH void refcnt_inc () const { ++refcnt; } 150 MTH void refcnt_inc () const { ++refcnt; }
145 MTH void refcnt_dec () const { --refcnt; } 151 MTH void refcnt_dec () const { --refcnt; }
146 152
147 MTH int refcnt_cnt () const; 153 MTH int refcnt_cnt () const;
183 189
184 virtual ~attachable (); 190 virtual ~attachable ();
185 191
186 attachable &operator =(const attachable &src); 192 attachable &operator =(const attachable &src);
187 193
194 bool vinvoke (event_type event, va_list &ap);
188 bool invoke (event_type event, ...); 195 bool invoke (event_type event, ...)
196 {
197 if (ev_want_event [event] || cb)
198 {
199 va_list ap;
200 va_start (ap, event);
201 vinvoke (event, ap);
202 va_end (ap);
203 }
204 }
205
189 MTH void instantiate (); 206 MTH void instantiate ();
190 void reattach (); 207 void reattach ();
191 208
192protected: 209protected:
193 // do the real refcount checking work 210 // do the real refcount checking work
205 222
206extern struct global gbl_ev; 223extern struct global gbl_ev;
207 224
208////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 225//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
209 226
210struct object_freezer : dynbuf 227struct object_freezer : dynbuf_text
211{ 228{
212 AV *av; 229 AV *av;
213 230
214 object_freezer (); 231 object_freezer ();
215 ~object_freezer (); 232 ~object_freezer ();
335 352
336 operator bool () { return !!av; } 353 operator bool () { return !!av; }
337}; 354};
338 355
339// compatibility support, should be removed when no longer needed 356// compatibility support, should be removed when no longer needed
340int fprintf (object_freezer &freezer, const char *format, ...); 357void fprintf (object_freezer &freezer, const char *format, ...);
341int fputs (const char *s, object_freezer &freezer); 358void fputs (const char *s, object_freezer &freezer);
342 359
343struct object_thawer 360struct object_thawer
344{ 361{
345 SV *text; // text part 362 SV *text; // text part
346 AV *av; // perl part 363 AV *av; // perl part
347 int linenum; 364 int linenum;
348 char *line; // current beginning of line 365 char *line; // current beginning of line
349 char *last_keyword, *last_value; 366 keyword kw;
367 char *kw_str, *value;
350 const char *name; 368 const char *name;
351 369
352 operator bool () { return !!text; } 370 operator bool () { return !!text; }
353 371
354 object_thawer (const char *path = 0); 372 object_thawer (const char *path = 0);
355 object_thawer (const char *data, AV *perlav); 373 object_thawer (const char *data, AV *perlav);
356 ~object_thawer (); 374 ~object_thawer ();
357 375
358 void get (attachable *obj, int oid); 376 void get (attachable *obj, int oid);
359 377
360 keyword get_kv (); // also parse value for later use 378 // parse next line
361 void skip_kv (keyword kw); 379 void next ();
380 // skip the current key-value (usually fetch next line, for
381 // multiline-fields, skips untilt he corresponding end-kw
382 void skip ();
362 383
384 //TODO: remove, deprecated
385 keyword get_kv ()
386 {
387 next ();
388 return kw;
389 }
390
363 const char *get_str () { return last_value; } // may be 0 391 char *get_str () { return value; } // may be 0
364 392
365 void get (shstr &sh) const; 393 void get (shstr &sh) const;
366 void get_ornull (shstr &sh) const { sh = last_value; } 394 void get_ornull (shstr &sh) const { sh = value; }
367 void get_ml (keyword kend, shstr &sh); 395 void get_ml (keyword kend, shstr &sh);
368 396
369 sint32 get_sint32 () const; 397 sint32 get_sint32 () const;
370 sint64 get_sint64 () const; 398 sint64 get_sint64 () const;
371 double get_double () const; 399 double get_double () const;
381 void get (sint32 &i) { i = get_sint32 (); } 409 void get (sint32 &i) { i = get_sint32 (); }
382 410
383 void get (uint32 &i) { i = get_sint64 (); } 411 void get (uint32 &i) { i = get_sint64 (); }
384 void get (sint64 &i) { i = get_sint64 (); } 412 void get (sint64 &i) { i = get_sint64 (); }
385 413
386 bool parse_error (keyword kw, const char *type = 0, const char *name = 0, bool skip = true); 414 bool parse_error (const char *type = 0, const char *name = 0, bool skip = true);
387}; 415};
388 416
389//TODO: remove 417//TODO: remove
390char *fgets (char *s, int n, object_thawer &thawer); 418char *fgets (char *s, int n, object_thawer &thawer);
391 419
395 static struct CoroAPI *GCoroAPI; 423 static struct CoroAPI *GCoroAPI;
396 424
397 static int nready () { return CORO_NREADY; } 425 static int nready () { return CORO_NREADY; }
398 static int cede () { return CORO_CEDE ; } 426 static int cede () { return CORO_CEDE ; }
399 427
428 static double (*time)();
429 static double next_cede;
400 static int cede_counter; 430 static int cede_counter;
401 431
432 static void do_cede_every ();
433 static void do_cede_to_tick ();
434 static void do_cede_to_tick_every ();
435
402 static void cede_every (int count) 436 static void cede_every (int count)
403 { 437 {
404 if (++cede_counter >= count) 438 if (++cede_counter >= count)
405 { 439 do_cede_every ();
406 cede_counter = 0;
407
408 if (coroapi::nready ())
409 coroapi::cede ();
410 }
411 } 440 }
441
442 static void cede_to_tick ()
443 {
444 if (time () >= next_cede)
445 do_cede_to_tick ();
446 }
447
448 static void cede_to_tick_every (int count)
449 {
450 if (++cede_counter >= count)
451 cede_to_tick ();
452 }
453
454 static void wait_for_tick ();
455 static void wait_for_tick_begin ();
412}; 456};
413 457
414struct watcher_base 458struct watcher_base
415{ 459{
416 static struct EventAPI *GEventAPI; 460 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines