Merge bitbucket.org:mike_php_net/ext-raphf
[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 "0.1.0"
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, void *init_arg TSRMLS_DC);
34 typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, void *handle TSRMLS_DC);
35 typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, void *handle TSRMLS_DC);
36
37 typedef struct php_resource_factory_ops {
38 php_resource_factory_handle_ctor_t ctor;
39 php_resource_factory_handle_copy_t copy;
40 php_resource_factory_handle_dtor_t dtor;
41 } php_resource_factory_ops_t;
42
43 typedef struct php_resource_factory {
44 php_resource_factory_ops_t fops;
45
46 void *data;
47 void (*dtor)(void *data);
48
49 unsigned refcount;
50 } php_resource_factory_t;
51
52 PHP_RAPHF_API php_resource_factory_t *php_resource_factory_init(php_resource_factory_t *f, php_resource_factory_ops_t *fops, void *data, void (*dtor)(void *data));
53 PHP_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf);
54 PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f);
55 PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f);
56
57 PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f, void *init_arg TSRMLS_DC);
58 PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f, void *handle TSRMLS_DC);
59 PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f, void *handle TSRMLS_DC);
60
61 typedef struct php_persistent_handle_list {
62 HashTable free;
63 ulong used;
64 } php_persistent_handle_list_t;
65
66 typedef struct php_persistent_handle_provider {
67 php_persistent_handle_list_t list; /* "ident" => array(handles) entries */
68 php_resource_factory_t rf;
69 } php_persistent_handle_provider_t;
70
71 typedef struct php_persistent_handle_factory php_persistent_handle_factory_t;
72
73 typedef void (*php_persistent_handle_wakeup_t)(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC);
74 typedef void (*php_persistent_handle_retire_t)(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC);
75
76 struct php_persistent_handle_factory {
77 php_persistent_handle_provider_t *provider;
78
79 php_persistent_handle_wakeup_t wakeup;
80 php_persistent_handle_retire_t retire;
81
82 struct {
83 char *str;
84 size_t len;
85 } ident;
86
87 unsigned free_on_abandon:1;
88 };
89
90 struct php_persistent_handle_globals {
91 ulong limit;
92 HashTable hash;
93 };
94
95 PHP_RAPHF_API int /* SUCCESS|FAILURE */ php_persistent_handle_provide(const char *name_str, size_t name_len, php_resource_factory_ops_t *fops, void *data, void (*dtor)(void *) TSRMLS_DC);
96 PHP_RAPHF_API php_persistent_handle_factory_t *php_persistent_handle_concede(php_persistent_handle_factory_t *a, const char *name_str, size_t name_len, const char *ident_str, size_t ident_len,php_persistent_handle_wakeup_t wakeup, php_persistent_handle_retire_t retire TSRMLS_DC);
97 PHP_RAPHF_API void php_persistent_handle_abandon(php_persistent_handle_factory_t *a);
98 PHP_RAPHF_API void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC);
99 PHP_RAPHF_API void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
100 PHP_RAPHF_API void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
101
102 PHP_RAPHF_API php_resource_factory_ops_t *php_persistent_handle_get_resource_factory_ops(void);
103
104 PHP_RAPHF_API void php_persistent_handle_cleanup(const char *name_str, size_t name_len, const char *ident_str, size_t ident_len TSRMLS_DC);
105 PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC);
106
107 ZEND_BEGIN_MODULE_GLOBALS(raphf)
108 struct php_persistent_handle_globals persistent_handle;
109 ZEND_END_MODULE_GLOBALS(raphf)
110
111 #ifdef ZTS
112 # define PHP_RAPHF_G ((zend_raphf_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)])
113 #else
114 # define PHP_RAPHF_G (&raphf_globals)
115 #endif
116
117 #endif /* PHP_RAPHF_H */
118
119
120 /*
121 * Local variables:
122 * tab-width: 4
123 * c-basic-offset: 4
124 * End:
125 * vim600: noet sw=4 ts=4 fdm=marker
126 * vim<600: noet sw=4 ts=4
127 */