1 /*******************************************************************************
2 *
3 * HEADER: hook.h
4 *
5 ********************************************************************************
6 *
7 * DESCRIPTION: C::B::C hooks
8 *
9 ********************************************************************************
10 *
11 * Copyright (c) 2002-2020 Marcus Holland-Moritz. All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the same terms as Perl itself.
14 *
15 *******************************************************************************/
16 
17 #ifndef _CBC_HOOK_H
18 #define _CBC_HOOK_H
19 
20 /*===== GLOBAL INCLUDES ======================================================*/
21 
22 
23 /*===== LOCAL INCLUDES =======================================================*/
24 
25 
26 /*===== DEFINES ==============================================================*/
27 
28 #define SHF_ALLOW_ARG_SELF   0x00000001U
29 #define SHF_ALLOW_ARG_TYPE   0x00000002U
30 #define SHF_ALLOW_ARG_DATA   0x00000004U
31 #define SHF_ALLOW_ARG_HOOK   0x00000008U
32 
33 #define SHF_ALLOW_ALL_ARGS   0xFFFFFFFFU
34 
35 
36 /*===== TYPEDEFS =============================================================*/
37 
38 typedef enum {
39   HOOK_ARG_SELF,
40   HOOK_ARG_TYPE,
41   HOOK_ARG_DATA,
42   HOOK_ARG_HOOK
43 } HookArgType;
44 
45 typedef struct {
46   SV *sub;
47   AV *arg;
48 } SingleHook;
49 
50 #include "token/t_hookid.h"
51 
52 typedef struct {
53   SingleHook hooks[HOOKID_COUNT];
54 } TypeHooks;
55 
56 
57 /*===== FUNCTION PROTOTYPES ==================================================*/
58 
59 #define single_hook_fill CBC_single_hook_fill
60 void single_hook_fill(pTHX_ const char *hook, const char *type, SingleHook *sth,
61                             SV *sub, U32 allowed_args);
62 
63 #define single_hook_new CBC_single_hook_new
64 SingleHook *single_hook_new(const SingleHook *h);
65 
66 #define hook_new CBC_hook_new
67 TypeHooks *hook_new(const TypeHooks *h);
68 
69 #define single_hook_update CBC_single_hook_update
70 void single_hook_update(SingleHook *dst, const SingleHook *src);
71 
72 #define hook_update CBC_hook_update
73 void hook_update(TypeHooks *dst, const TypeHooks *src);
74 
75 #define single_hook_delete CBC_single_hook_delete
76 void single_hook_delete(SingleHook *hook);
77 
78 #define hook_delete CBC_hook_delete
79 void hook_delete(TypeHooks *h);
80 
81 #define single_hook_call CBC_single_hook_call
82 SV *single_hook_call(pTHX_ SV *self, const char *hook_id_str, const char *id_pre,
83                      const char *id, const SingleHook *hook, SV *in, int mortal);
84 
85 #define hook_call CBC_hook_call
86 SV *hook_call(pTHX_ SV *self, const char *id_pre, const char *id,
87               const TypeHooks *pTH, enum HookId hook_id, SV *in, int mortal);
88 
89 #define find_hooks CBC_find_hooks
90 int find_hooks(pTHX_ const char *type, HV *hooks, TypeHooks *pTH);
91 
92 #define get_single_hook CBC_get_single_hook
93 SV *get_single_hook(pTHX_ const SingleHook *hook);
94 
95 #define get_hooks CBC_get_hooks
96 HV *get_hooks(pTHX_ const TypeHooks *pTH);
97 
98 #endif
99