1 | void GBP_callback(GBDATA *gbd, int *cl, GB_CB_TYPE cb_type){ |
---|
2 | char *perl_func; |
---|
3 | char *perl_cl; |
---|
4 | dSP ; |
---|
5 | I32 i; |
---|
6 | SV *sv; |
---|
7 | perl_func = (char *)cl; |
---|
8 | perl_cl = perl_func + strlen(perl_func) + 1; |
---|
9 | |
---|
10 | PUSHMARK(sp); |
---|
11 | sv = sv_newmortal(); |
---|
12 | sv_setref_pv(sv, "GBDATAPtr", (void*)gbd); |
---|
13 | XPUSHs(sv); |
---|
14 | XPUSHs(sv_2mortal(newSVpv(perl_cl, 0))); |
---|
15 | if (cb_type & GB_CB_DELETE) { |
---|
16 | XPUSHs(sv_2mortal(newSVpv("DELETED", 0))); |
---|
17 | }else{ |
---|
18 | XPUSHs(sv_2mortal(newSVpv("CHANGED", 0))); |
---|
19 | } |
---|
20 | |
---|
21 | PUTBACK; |
---|
22 | i = perl_call_pv(perl_func,G_DISCARD); |
---|
23 | if (i) { |
---|
24 | croak("Your perl function '%s' should not return any values",perl_func); |
---|
25 | } |
---|
26 | return; |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | static GB_HASH *gbp_cp_hash_table = 0; |
---|
31 | |
---|
32 | GB_ERROR GBP_add_callback(GBDATA *gbd, char *perl_func, char *perl_cl){ |
---|
33 | char *data = 0; |
---|
34 | char *arg = 0; |
---|
35 | GB_ERROR error = 0; |
---|
36 | |
---|
37 | if (gbp_cp_hash_table ==0) gbp_cp_hash_table = GBS_create_hash(4096, GB_MIND_CASE); |
---|
38 | |
---|
39 | data = (char *)calloc(1,strlen(perl_func) + strlen(perl_cl) + 100); |
---|
40 | arg = (char *)calloc(1,strlen(perl_func) + strlen(perl_cl) + 2); |
---|
41 | sprintf(arg,"%s%c%s",perl_func,'\0',perl_cl); |
---|
42 | sprintf(data,"%p:%s%c%s",gbd,perl_func,'\1',perl_cl); |
---|
43 | if (!GBS_read_hash(gbp_cp_hash_table,data)){ |
---|
44 | GBS_write_hash(gbp_cp_hash_table,data,(long)data); |
---|
45 | error = GB_add_callback(gbd,GB_CB_DELETE|GB_CB_CHANGED,GBP_callback, (int *)arg); |
---|
46 | }else{ |
---|
47 | free(arg); |
---|
48 | } |
---|
49 | free(data); |
---|
50 | return error; |
---|
51 | } |
---|
52 | |
---|
53 | GB_ERROR GBP_remove_callback(GBDATA *gbd, char *perl_func, char *perl_cl){ |
---|
54 | char *data = 0; |
---|
55 | char *arg = 0; |
---|
56 | if (gbp_cp_hash_table ==0) gbp_cp_hash_table = GBS_create_hash(4096, GB_MIND_CASE); |
---|
57 | data = (char *)calloc(1,strlen(perl_func) + strlen(perl_cl) + 100); |
---|
58 | sprintf(data,"%p:%s%c%s",gbd,perl_func,'\1',perl_cl); |
---|
59 | arg =(char *)GBS_read_hash(gbp_cp_hash_table,data); |
---|
60 | if (!arg){ |
---|
61 | free(data); |
---|
62 | return GB_export_errorf("Sorry: You never installed a callback '%s:%s'",perl_func,perl_cl); |
---|
63 | }else{ |
---|
64 | GBS_write_hash(gbp_cp_hash_table,data,0); |
---|
65 | free(data); |
---|
66 | free(arg); |
---|
67 | GB_remove_callback(gbd,GB_CB_DELETE|GB_CB_CHANGED,GBP_callback, (int *)data); |
---|
68 | } |
---|
69 | return 0; |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | char *static_pntr = 0; |
---|