Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / perl / perl-common.h
1 #ifndef __PERL_COMMON_H
2 #define __PERL_COMMON_H
3
4 /* helper defines */
5 #define new_pv(a) \
6         (newSVpv((a) == NULL ? "" : (a), (a) == NULL ? 0 : strlen(a)))
7
8 #define is_hvref(o) \
9         ((o) && SvROK(o) && SvRV(o) && (SvTYPE(SvRV(o)) == SVt_PVHV))
10
11 #define hvref(o) \
12         (is_hvref(o) ? (HV *)SvRV(o) : NULL)
13
14 typedef void (*PERL_OBJECT_FUNC) (HV *hv, void *object);
15
16 typedef struct {
17         char *name;
18         PERL_OBJECT_FUNC fill_func;
19 } PLAIN_OBJECT_INIT_REC;
20
21 /* Returns the package who called us */
22 const char *perl_get_package(void);
23 /* Parses the package part from function name */
24 char *perl_function_get_package(const char *function);
25 /* If SV is a string, prefix it with given package.
26    Increases the reference counter for the return value. */
27 SV *perl_func_sv_inc(SV *func, const char *package);
28
29 /* For compatibility with perl 5.004 and older */
30 #ifndef HAVE_PL_PERL
31 #  define PL_sv_undef sv_undef
32 extern STRLEN PL_na;
33 #endif
34
35 #ifndef pTHX_
36 #  define pTHX_
37 #endif
38
39 #ifndef aTHX_
40 #  define aTHX_
41 #endif
42
43 #define iobject_bless(object) \
44         ((object) == NULL ? &PL_sv_undef : \
45         irssi_bless_iobject((object)->type, (object)->chat_type, object))
46
47 #define simple_iobject_bless(object) \
48         ((object) == NULL ? &PL_sv_undef : \
49         irssi_bless_iobject((object)->type, 0, object))
50
51 #define plain_bless(object, stash) \
52         ((object) == NULL ? &PL_sv_undef : \
53         irssi_bless_plain(stash, object))
54
55 SV *irssi_bless_iobject(int type, int chat_type, void *object);
56 SV *irssi_bless_plain(const char *stash, void *object);
57 int irssi_is_ref_object(SV *o);
58 void *irssi_ref_object(SV *o);
59
60 void irssi_add_object(int type, int chat_type, const char *stash,
61                       PERL_OBJECT_FUNC func);
62 void irssi_add_plain(const char *stash, PERL_OBJECT_FUNC func);
63 void irssi_add_plains(PLAIN_OBJECT_INIT_REC *objects);
64
65 char *perl_get_use_list(void);
66
67 void perl_command(const char *cmd, SERVER_REC *server, WI_ITEM_REC *item);
68
69 void perl_chatnet_fill_hash(HV *hv, CHATNET_REC *chatnet);
70 void perl_connect_fill_hash(HV *hv, SERVER_CONNECT_REC *conn);
71 void perl_server_fill_hash(HV *hv, SERVER_REC *server);
72 void perl_window_item_fill_hash(HV *hv, WI_ITEM_REC *item);
73 void perl_channel_fill_hash(HV *hv, CHANNEL_REC *channel);
74 void perl_query_fill_hash(HV *hv, QUERY_REC *query);
75 void perl_nick_fill_hash(HV *hv, NICK_REC *nick);
76
77 #define irssi_boot(x) { \
78         extern void boot_Irssi__##x(pTHX_ CV *cv); \
79         irssi_callXS(boot_Irssi__##x, cv, mark); \
80         }
81 void irssi_callXS(void (*subaddr)(pTHX_ CV* cv), CV *cv, SV **mark);
82
83 void perl_common_start(void);
84 void perl_common_stop(void);
85
86 #endif