disable PHP_RAPHF_DEBUG_PHANDLES
[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 /* $Id$ */
14
15 #ifndef PHP_RAPHF_H
16 #define PHP_RAPHF_H
17
18 extern zend_module_entry raphf_module_entry;
19 #define phpext_raphf_ptr &raphf_module_entry
20
21 #define PHP_RAPHF_VERSION "1.0.0dev"
22
23 #ifdef PHP_WIN32
24 # define PHP_RAPHF_API __declspec(dllexport)
25 #elif defined(__GNUC__) && __GNUC__ >= 4
26 # define PHP_RAPHF_API __attribute__ ((visibility("default")))
27 #else
28 # define PHP_RAPHF_API
29 #endif
30
31 #ifdef ZTS
32 # include "TSRM.h"
33 #endif
34
35 typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, void *init_arg TSRMLS_DC);
36 typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, void *handle TSRMLS_DC);
37 typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, void *handle TSRMLS_DC);
38
39 typedef struct php_resource_factory_ops {
40 php_resource_factory_handle_ctor_t ctor;
41 php_resource_factory_handle_copy_t copy;
42 php_resource_factory_handle_dtor_t dtor;
43 } php_resource_factory_ops_t;
44
45 typedef struct php_resource_factory {
46 php_resource_factory_ops_t fops;
47
48 void *data;
49 void (*dtor)(void *data);
50
51 unsigned refcount;
52 } php_resource_factory_t;
53
54 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));
55 PHP_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf);
56 PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f);
57 PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f);
58
59 PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f, void *init_arg TSRMLS_DC);
60 PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f, void *handle TSRMLS_DC);
61 PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f, void *handle TSRMLS_DC);
62
63 typedef struct php_persistent_handle_factory {
64 void *provider;
65
66 struct {
67 char *str;
68 size_t len;
69 } ident;
70
71 unsigned free_on_abandon:1;
72 } php_persistent_handle_factory_t;
73
74 struct php_persistent_handle_globals {
75 ulong limit;
76 struct {
77 ulong h;
78 char *s;
79 size_t l;
80 } ident;
81 };
82
83 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 *));
84 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 TSRMLS_DC);
85 PHP_RAPHF_API void php_persistent_handle_abandon(php_persistent_handle_factory_t *a);
86 PHP_RAPHF_API void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC);
87 PHP_RAPHF_API void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
88 PHP_RAPHF_API void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
89
90 PHP_RAPHF_API php_resource_factory_ops_t *php_persistent_handle_get_resource_factory_ops(void);
91
92 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);
93 PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC);
94
95 ZEND_BEGIN_MODULE_GLOBALS(raphf)
96 struct php_persistent_handle_globals persistent_handle;
97 ZEND_END_MODULE_GLOBALS(raphf)
98
99 #ifdef ZTS
100 # define PHP_RAPHF_G ((zend_raphf_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)])
101 #else
102 # define PHP_RAPHF_G (&raphf_globals)
103 #endif
104
105 #endif /* PHP_RAPHF_H */
106
107
108 /*
109 * Local variables:
110 * tab-width: 4
111 * c-basic-offset: 4
112 * End:
113 * vim600: noet sw=4 ts=4 fdm=marker
114 * vim<600: noet sw=4 ts=4
115 */