add pecl/http-v2 tests; release 1.0.3
[m6w6/ext-raphf] / php_raphf.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: raphf |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_RAPHF_H
14 #define PHP_RAPHF_H
15
16 extern zend_module_entry raphf_module_entry;
17 #define phpext_raphf_ptr &raphf_module_entry
18
19 #define PHP_RAPHF_VERSION "1.0.2"
20
21 #ifdef PHP_WIN32
22 # define PHP_RAPHF_API __declspec(dllexport)
23 #elif defined(__GNUC__) && __GNUC__ >= 4
24 # define PHP_RAPHF_API __attribute__ ((visibility("default")))
25 #else
26 # define PHP_RAPHF_API
27 #endif
28
29 #ifdef ZTS
30 # include "TSRM.h"
31 #endif
32
33 typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque,
34 void *init_arg TSRMLS_DC);
35 typedef void *(*php_resource_factory_handle_copy_t)(void *opaque,
36 void *handle TSRMLS_DC);
37 typedef void (*php_resource_factory_handle_dtor_t)(void *opaque,
38 void *handle TSRMLS_DC);
39
40 typedef struct php_resource_factory_ops {
41 php_resource_factory_handle_ctor_t ctor;
42 php_resource_factory_handle_copy_t copy;
43 php_resource_factory_handle_dtor_t dtor;
44 } php_resource_factory_ops_t;
45
46 typedef struct php_resource_factory {
47 php_resource_factory_ops_t fops;
48
49 void *data;
50 void (*dtor)(void *data);
51
52 unsigned refcount;
53 } php_resource_factory_t;
54
55 PHP_RAPHF_API php_resource_factory_t *php_resource_factory_init(
56 php_resource_factory_t *f, php_resource_factory_ops_t *fops, void *data,
57 void (*dtor)(void *data));
58 PHP_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf);
59 PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f);
60 PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f);
61
62 PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
63 void *init_arg TSRMLS_DC);
64 PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f,
65 void *handle TSRMLS_DC);
66 PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f,
67 void *handle TSRMLS_DC);
68
69 typedef struct php_persistent_handle_list {
70 HashTable free;
71 ulong used;
72 } php_persistent_handle_list_t;
73
74 typedef struct php_persistent_handle_provider {
75 php_persistent_handle_list_t list; /* "ident" => array(handles) entries */
76 php_resource_factory_t rf;
77 } php_persistent_handle_provider_t;
78
79 typedef struct php_persistent_handle_factory php_persistent_handle_factory_t;
80
81 typedef void (*php_persistent_handle_wakeup_t)(
82 php_persistent_handle_factory_t *f, void **handle TSRMLS_DC);
83 typedef void (*php_persistent_handle_retire_t)(
84 php_persistent_handle_factory_t *f, void **handle TSRMLS_DC);
85
86 struct php_persistent_handle_factory {
87 php_persistent_handle_provider_t *provider;
88
89 php_persistent_handle_wakeup_t wakeup;
90 php_persistent_handle_retire_t retire;
91
92 struct {
93 char *str;
94 size_t len;
95 } ident;
96
97 unsigned free_on_abandon:1;
98 };
99
100 struct php_persistent_handle_globals {
101 ulong limit;
102 HashTable hash;
103 };
104
105 PHP_RAPHF_API int /* SUCCESS|FAILURE */ php_persistent_handle_provide(
106 const char *name_str, size_t name_len, php_resource_factory_ops_t *fops,
107 void *data, void (*dtor)(void *) TSRMLS_DC);
108 PHP_RAPHF_API php_persistent_handle_factory_t *php_persistent_handle_concede(
109 php_persistent_handle_factory_t *a, const char *name_str,
110 size_t name_len, const char *ident_str, size_t ident_len,
111 php_persistent_handle_wakeup_t wakeup,
112 php_persistent_handle_retire_t retire TSRMLS_DC);
113 PHP_RAPHF_API void php_persistent_handle_abandon(
114 php_persistent_handle_factory_t *a);
115 PHP_RAPHF_API void *php_persistent_handle_acquire(
116 php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC);
117 PHP_RAPHF_API void php_persistent_handle_release(
118 php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
119 PHP_RAPHF_API void *php_persistent_handle_accrete(
120 php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
121
122 PHP_RAPHF_API php_resource_factory_ops_t *
123 php_persistent_handle_get_resource_factory_ops(void);
124
125 PHP_RAPHF_API void php_persistent_handle_cleanup(const char *name_str,
126 size_t name_len, const char *ident_str, size_t ident_len TSRMLS_DC);
127 PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC);
128
129 ZEND_BEGIN_MODULE_GLOBALS(raphf)
130 struct php_persistent_handle_globals persistent_handle;
131 ZEND_END_MODULE_GLOBALS(raphf)
132
133 #ifdef ZTS
134 # define PHP_RAPHF_G ((zend_raphf_globals *) \
135 (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)])
136 #else
137 # define PHP_RAPHF_G (&raphf_globals)
138 #endif
139
140 #endif /* PHP_RAPHF_H */
141
142
143 /*
144 * Local variables:
145 * tab-width: 4
146 * c-basic-offset: 4
147 * End:
148 * vim600: noet sw=4 ts=4 fdm=marker
149 * vim<600: noet sw=4 ts=4
150 */