Resource and persistent handle factory API
A facility to manage possibly persistent resources with a comprehensible API. Provides simliar functionality like the zend_list API, but with more flexiblity and freedom.
php_raphf_api.h
Go to the documentation of this file.
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_API_H
14 #define PHP_RAPHF_API_H
15 
16 #include "php_raphf.h"
17 
25 typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, void *init_arg);
26 
33 typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, void *handle);
34 
41 typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, void *handle);
42 
49 typedef struct php_resource_factory_ops {
57 
61 typedef struct php_resource_factory {
65  void *data;
67  void (*dtor)(void *data);
69  unsigned refcount;
71 
88  void (*dtor)(void *data));
89 
97 
106 
116 
125  void *init_arg);
126 
135  void *handle);
136 
144  void *handle);
145 
151  HashTable free;
153  ulong used;
155 
167 
174 
176 
181  php_persistent_handle_factory_t *f, void **handle);
186  php_persistent_handle_factory_t *f, void **handle);
187 
202 
204  zend_string *ident;
205 
207  unsigned free_on_abandon:1;
208 };
209 
230  zend_string *name, php_resource_factory_ops_t *fops,
231  void *data, void (*dtor)(void *));
232 
252  zend_string *name, zend_string *ident,
255 
267 
282  php_persistent_handle_factory_t *a, void *init_arg);
283 
298  php_persistent_handle_factory_t *a, void *handle);
299 
309  php_persistent_handle_factory_t *a, void *handle);
310 
343 
356 
364 
387 PHP_RAPHF_API void php_persistent_handle_cleanup(zend_string *name,
388  zend_string *ident);
389 
405 PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht);
406 
407 #endif /* PHP_RAPHF_API_H */
408 
409 
410 /*
411  * Local variables:
412  * tab-width: 4
413  * c-basic-offset: 4
414  * End:
415  * vim600: noet sw=4 ts=4 fdm=marker
416  * vim<600: noet sw=4 ts=4
417  */
void(* dtor)(void *data)
User data destructor.
Definition: php_raphf_api.h:67
void * data
Opaque user data.
Definition: php_raphf_api.h:65
php_resource_factory_handle_copy_t copy
The resource's copy constructor.
Definition: php_raphf_api.h:53
void php_resource_factory_free(php_resource_factory_t **f)
Destroy and free the resource factory.
Definition: php_raphf_api.c:84
void *(* php_resource_factory_handle_ctor_t)(void *opaque, void *init_arg)
A resource constructor.
Definition: php_raphf_api.h:25
void(* php_persistent_handle_wakeup_t)(php_persistent_handle_factory_t *f, void **handle)
Wakeup the persistent handle on re-acquisition.
Definition: php_raphf_api.h:180
php_persistent_handle_list_t list
The list of free handles.
Definition: php_raphf_api.h:166
HashTable * php_persistent_handle_statall(HashTable *ht)
Retrieve statistics about the current process/thread's persistent handles.
Definition: php_raphf_api.c:493
unsigned php_resource_factory_addref(php_resource_factory_t *rf)
Increase the refcount of the resource factory.
Definition: php_raphf_api.c:70
void(* php_persistent_handle_retire_t)(php_persistent_handle_factory_t *f, void **handle)
Retire the persistent handle on release.
Definition: php_raphf_api.h:185
void php_persistent_handle_cleanup(zend_string *name, zend_string *ident)
Clean persistent handles up.
Definition: php_raphf_api.c:463
Persistent handles storage.
Definition: php_raphf_api.h:149
struct php_persistent_handle_list php_persistent_handle_list_t
Persistent handles storage.
unsigned refcount
How often this factory is referenced.
Definition: php_raphf_api.h:69
php_resource_factory_handle_dtor_t dtor
The resource's destructor.
Definition: php_raphf_api.h:55
void php_persistent_handle_abandon(php_persistent_handle_factory_t *a)
Abandon the persistent handle factory.
Definition: php_raphf_api.c:374
Definition of a persistent handle factory.
Definition: php_raphf_api.h:195
php_persistent_handle_retire_t retire
The persistent handle retire routine; may be NULL.
Definition: php_raphf_api.h:201
unsigned free_on_abandon
Whether it has to be free'd on php_persistent_handle_abandon()
Definition: php_raphf_api.h:207
php_resource_factory_t rf
The resource factory.
Definition: php_raphf_api.h:172
void *(* php_resource_factory_handle_copy_t)(void *opaque, void *handle)
The copy constructor of a resource.
Definition: php_raphf_api.h:33
#define PHP_RAPHF_API
Definition: php_raphf.h:26
void * php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *init_arg)
Acquire a persistent handle.
Definition: php_raphf_api.c:389
php_resource_factory_handle_ctor_t ctor
The resource constructor.
Definition: php_raphf_api.h:51
void(* php_resource_factory_handle_dtor_t)(void *opaque, void *handle)
The destructor of a resource.
Definition: php_raphf_api.h:41
HashTable free
Storage of free resources.
Definition: php_raphf_api.h:151
The resource ops consisting of a ctor, a copy ctor and a dtor.
Definition: php_raphf_api.h:49
php_persistent_handle_provider_t * provider
The persistent handle provider.
Definition: php_raphf_api.h:197
ulong used
Count of acquired resources.
Definition: php_raphf_api.h:153
php_resource_factory_ops_t * php_persistent_handle_get_resource_factory_ops(void)
Retrieve persistent handle resource factory ops.
Definition: php_raphf_api.c:516
void php_resource_factory_dtor(php_resource_factory_t *f)
Destroy the resource factory.
Definition: php_raphf_api.c:75
php_resource_factory_t * php_persistent_handle_resource_factory_init(php_resource_factory_t *a, php_persistent_handle_factory_t *pf)
Create a resource factory for persistent handles.
Definition: php_raphf_api.c:118
struct php_resource_factory php_resource_factory_t
The resource factory.
void * php_resource_factory_handle_ctor(php_resource_factory_t *f, void *init_arg)
Construct a resource by the resource factory f.
Definition: php_raphf_api.c:95
Definition of a persistent handle provider.
Definition: php_raphf_api.h:160
zend_string * ident
The ident for which this factory manages resources.
Definition: php_raphf_api.h:204
The resource factory.
Definition: php_raphf_api.h:61
void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *handle)
Release a persistent handle.
Definition: php_raphf_api.c:440
php_persistent_handle_factory_t * php_persistent_handle_concede(php_persistent_handle_factory_t *a, zend_string *name, zend_string *ident, php_persistent_handle_wakeup_t wakeup, php_persistent_handle_retire_t retire)
Retrieve a persistent handle factory at runtime.
Definition: php_raphf_api.c:341
void php_resource_factory_handle_dtor(php_resource_factory_t *f, void *handle)
Destroy (and free) the resource.
Definition: php_raphf_api.c:111
void * php_resource_factory_handle_copy(php_resource_factory_t *f, void *handle)
Create a copy of the resource handle.
Definition: php_raphf_api.c:103
struct php_persistent_handle_provider php_persistent_handle_provider_t
Definition of a persistent handle provider.
php_persistent_handle_wakeup_t wakeup
The persistent handle wakeup routine; may be NULL.
Definition: php_raphf_api.h:199
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))
Initialize a resource factory.
Definition: php_raphf_api.c:52
ZEND_RESULT_CODE php_persistent_handle_provide(zend_string *name, php_resource_factory_ops_t *fops, void *data, void(*dtor)(void *))
Register a persistent handle provider in MINIT.
Definition: php_raphf_api.c:311
zend_bool php_resource_factory_is_persistent(php_resource_factory_t *a)
Check whether a resource factory is a persistent handle resource factory.
Definition: php_raphf_api.c:126
struct php_resource_factory_ops php_resource_factory_ops_t
The resource ops consisting of a ctor, a copy ctor and a dtor.
php_resource_factory_ops_t fops
The resource ops.
Definition: php_raphf_api.h:63
void * php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *handle)
Copy a persistent handle.
Definition: php_raphf_api.c:423