--- /dev/null
+# Doxyfile 1.8.5
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = "Resource and persistent handle factory API"
+PROJECT_NUMBER =
+PROJECT_BRIEF = "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."
+PROJECT_LOGO = "/home/mike/Downloads/raphf.png"
+OUTPUT_DIRECTORY =
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = YES
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 4
+ALIASES =
+TCL_SUBST =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+EXTENSION_MAPPING =
+MARKDOWN_SUPPORT = YES
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = YES
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = NO
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = php_raphf.h
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS =
+RECURSIVE = NO
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE =
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES =
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = YES
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = YES
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = YES
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED = DOXYGEN TSRMLS_C= TSRMLS_D= TSRMLS_CC= TSRMLS_DC= PHP_RAPHF_API=
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+MSCGEN_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = YES
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = NO
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = YES
+CALLER_GRAPH = YES
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
#include "ext/standard/info.h"
#include "php_raphf.h"
+struct php_persistent_handle_globals {
+ ulong limit;
+ HashTable hash;
+};
+
+ZEND_BEGIN_MODULE_GLOBALS(raphf)
+ struct php_persistent_handle_globals persistent_handle;
+ZEND_END_MODULE_GLOBALS(raphf)
+
+#ifdef ZTS
+# define PHP_RAPHF_G ((zend_raphf_globals *) \
+ (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)])
+#else
+# define PHP_RAPHF_G (&raphf_globals)
+#endif
+
ZEND_DECLARE_MODULE_GLOBALS(raphf)
typedef int STATUS;
# define inline
#endif
-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))
+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))
{
if (!f) {
f = emalloc(sizeof(*f));
return f;
}
-PHP_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf)
+unsigned php_resource_factory_addref(php_resource_factory_t *rf)
{
return ++rf->refcount;
}
-PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f)
+void php_resource_factory_dtor(php_resource_factory_t *f)
{
--f->refcount;
}
}
-PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f)
+void php_resource_factory_free(php_resource_factory_t **f)
{
if (*f) {
php_resource_factory_dtor(*f);
}
}
-PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
+void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
void *init_arg TSRMLS_DC)
{
if (f->fops.ctor) {
return NULL;
}
-PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f,
+void *php_resource_factory_handle_copy(php_resource_factory_t *f,
void *handle TSRMLS_DC)
{
if (f->fops.copy) {
return NULL;
}
-PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f,
+void php_resource_factory_handle_dtor(php_resource_factory_t *f,
void *handle TSRMLS_DC)
{
if (f->fops.dtor) {
return status;
}
-PHP_RAPHF_API php_persistent_handle_factory_t *php_persistent_handle_concede(
+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_RAPHF_API void *php_persistent_handle_acquire(
+void *php_persistent_handle_acquire(
php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC)
{
int key;
return handle;
}
-PHP_RAPHF_API void *php_persistent_handle_accrete(
+void *php_persistent_handle_accrete(
php_persistent_handle_factory_t *a, void *handle TSRMLS_DC)
{
void *new_handle = NULL;
return new_handle;
}
-PHP_RAPHF_API void php_persistent_handle_release(
+void php_persistent_handle_release(
php_persistent_handle_factory_t *a, void *handle TSRMLS_DC)
{
php_persistent_handle_list_t *list;
}
}
-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)
+void php_persistent_handle_cleanup(const char *name_str, size_t name_len,
+ const char *ident_str, size_t ident_len TSRMLS_DC)
{
php_persistent_handle_provider_t *provider;
php_persistent_handle_list_t *list;
}
}
-PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC)
+HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC)
{
if (zend_hash_num_elements(&PHP_RAPHF_G->persistent_handle.hash)) {
if (!ht) {
(php_resource_factory_handle_dtor_t) php_persistent_handle_release
};
-PHP_RAPHF_API php_resource_factory_ops_t *
-php_persistent_handle_get_resource_factory_ops(void)
+php_resource_factory_ops_t *php_persistent_handle_get_resource_factory_ops(void)
{
return &php_persistent_handle_resource_factory_ops;
}
#ifndef PHP_RAPHF_H
#define PHP_RAPHF_H
+#ifndef DOXYGEN
+
extern zend_module_entry raphf_module_entry;
#define phpext_raphf_ptr &raphf_module_entry
#ifdef PHP_WIN32
# define PHP_RAPHF_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
-# define PHP_RAPHF_API __attribute__ ((visibility("default")))
+# define PHP_RAPHF_API extern __attribute__ ((visibility("default")))
#else
-# define PHP_RAPHF_API
+# define PHP_RAPHF_API extern
#endif
#ifdef ZTS
# include "TSRM.h"
#endif
+#endif
+
+/**
+ * A resource constructor.
+ *
+ * @param opaque is the \a data from php_persistent_handle_provide()
+ * @param init_arg is the \a init_arg from php_resource_factory_init()
+ * @return the created (persistent) handle
+ */
typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque,
void *init_arg TSRMLS_DC);
+
+/**
+ * The copy constructor of a resource.
+ *
+ * @param opaque the factory's data
+ * @param handle the (persistent) handle to copy
+ */
typedef void *(*php_resource_factory_handle_copy_t)(void *opaque,
void *handle TSRMLS_DC);
+
+/**
+ * The destructor of a resource.
+ *
+ * @param opaque the factory's data
+ * @param handle the handle to destroy
+ */
typedef void (*php_resource_factory_handle_dtor_t)(void *opaque,
void *handle TSRMLS_DC);
+/**
+ * The resource ops consisting of a ctor, a copy ctor and a dtor.
+ *
+ * Define this ops and register them with php_persistent_handle_provide()
+ * in MINIT.
+ */
typedef struct php_resource_factory_ops {
+ /** The resource constructor */
php_resource_factory_handle_ctor_t ctor;
+ /** The resource's copy constructor */
php_resource_factory_handle_copy_t copy;
+ /** The resource's destructor */
php_resource_factory_handle_dtor_t dtor;
} php_resource_factory_ops_t;
+/**
+ * The resource factory.
+ */
typedef struct php_resource_factory {
+ /** The resource ops */
php_resource_factory_ops_t fops;
-
+ /** Opaque user data */
void *data;
+ /** User data destructor */
void (*dtor)(void *data);
-
+ /** How often this factory is referenced */
unsigned refcount;
} php_resource_factory_t;
+/**
+ * Initialize a resource factory.
+ *
+ * If you register a \a dtor for a resource factory used with a persistent
+ * handle provider, be sure to call php_persistent_handle_cleanup() for your
+ * registered provider in MSHUTDOWN, else the dtor will point to no longer
+ * available memory if the extension has already been unloaded.
+ *
+ * @param f the factory to initialize; if NULL allocated on the heap
+ * @param fops the resource ops to assign to the factory
+ * @param data opaque user data; may be NULL
+ * @param dtor a destructor for the data; may be NULL
+ * @return \a f or an allocated resource factory
+ */
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));
+
+/**
+ * Increase the refcount of the resource factory.
+ *
+ * @param rf the resource factory
+ * @return the new refcount
+ */
PHP_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf);
+
+/**
+ * Destroy the resource factory.
+ *
+ * If the factory's refcount reaches 0, the \a dtor for \a data is called.
+ *
+ * @param f the resource factory
+ */
PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f);
+
+/**
+ * Destroy and free the resource factory.
+ *
+ * Calls php_resource_factory_dtor() and frees \æ f if the factory's refcount
+ * reached 0.
+ *
+ * @param f the resource factory
+ */
PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f);
+/**
+ * Construct a resource by the resource factory \a f
+ *
+ * @param f the resource factory
+ * @param init_arg for the resource constructor
+ * @return the new resource
+ */
PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
void *init_arg TSRMLS_DC);
+
+/**
+ * Create a copy of the resource \a handle
+ *
+ * @param f the resource factory
+ * @param handle the resource to copy
+ * @return the copy
+ */
PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f,
void *handle TSRMLS_DC);
+
+/**
+ * Destroy (and free) the resource
+ *
+ * @param f the resource factory
+ * @param handle the resource to destroy
+ */
PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f,
void *handle TSRMLS_DC);
+/**
+ * Persistent handles storage
+ */
typedef struct php_persistent_handle_list {
+ /** Storage of free resources */
HashTable free;
+ /** Count of acquired resources */
ulong used;
} php_persistent_handle_list_t;
+/**
+ * Definition of a persistent handle provider.
+ * Holds a resource factory an a persistent handle list.
+ */
typedef struct php_persistent_handle_provider {
- php_persistent_handle_list_t list; /* "ident" => array(handles) entries */
+ /**
+ * The list of free handles.
+ * Hash of "ident" => array(handles) entries. Persistent handles are
+ * acquired out of this list.
+ */
+ php_persistent_handle_list_t list;
+
+ /**
+ * The resource factory.
+ * New handles are created by this factory.
+ */
php_resource_factory_t rf;
} php_persistent_handle_provider_t;
typedef struct php_persistent_handle_factory php_persistent_handle_factory_t;
+/**
+ * Wakeup the persistent handle on re-acquisition.
+ */
typedef void (*php_persistent_handle_wakeup_t)(
php_persistent_handle_factory_t *f, void **handle TSRMLS_DC);
+/**
+ * Retire the persistent handle on release.
+ */
typedef void (*php_persistent_handle_retire_t)(
php_persistent_handle_factory_t *f, void **handle TSRMLS_DC);
+/**
+ * Definition of a persistent handle factory.
+ *
+ * php_persistent_handle_concede() will return a pointer to a
+ * php_persistent_handle_factory if a provider for the \a name_str has
+ * been registered with php_persistent_handle_provide().
+ */
struct php_persistent_handle_factory {
+ /** The persistent handle provider */
php_persistent_handle_provider_t *provider;
-
+ /** The persistent handle wakeup routine; may be NULL */
php_persistent_handle_wakeup_t wakeup;
+ /** The persistent handle retire routine; may be NULL */
php_persistent_handle_retire_t retire;
+ /** The ident for which this factory manages resources */
struct {
+ /** ident string */
char *str;
+ /** ident length */
size_t len;
} ident;
+ /** Whether it has to be free'd on php_persistent_handle_abandon() */
unsigned free_on_abandon:1;
};
-struct php_persistent_handle_globals {
- ulong limit;
- HashTable hash;
-};
-
+/**
+ * Register a persistent handle provider in MINIT.
+ *
+ * Registers a factory provider for \a name_str with \a fops resource factory
+ * ops. Call this in your MINIT.
+ *
+ * A php_resource_factory will be created with \a fops, \a data and \a dtor
+ * and will be stored together with a php_persistent_handle_list in the global
+ * raphf hash.
+ *
+ * A php_persistent_handle_factory can then be retrieved by
+ * php_persistent_handle_concede() at runtime.
+ *
+ * @param name_str the provider name, e.g. "http\Client\Curl"
+ * @param name_len the provider name length, e.g. strlen("http\Client\Curl")
+ * @param fops the resource factory ops
+ * @param data opaque user data
+ * @param dtor \a data destructor
+ * @return SUCCESS/FAILURE
+ */
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);
+
+/**
+ * Retrieve a persistent handle factory at runtime.
+ *
+ * If a persistent handle provider has been registered for \a name_str, a new
+ * php_persistent_handle_factory creating resources in the \a ident_str
+ * namespace will be constructed.
+ *
+ * The wakeup routine \a wakeup and the retire routine \a retire will be
+ * assigned to the new php_persistent_handle_factory.
+ *
+ * @param a pointer to a factory; allocated on the heap if NULL
+ * @param name_str the provider name, e.g. "http\Client\Curl"
+ * @param name_len the provider name length, e.g. strlen("http\Client\Curl")
+ * @param ident_str the subsidiary namespace, e.g. "php.net:80"
+ * @param ident_len the subsidiary namespace lenght, e.g. strlen("php.net:80")
+ * @param wakeup any persistent handle wakeup routine
+ * @param retire any persistent handle retire routine
+ * @return \a a or an allocated persistent handle factory
+ */
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);
+
+/**
+ * Abandon the persistent handle factory.
+ *
+ * Destroy a php_persistent_handle_factory created by
+ * php_persistent_handle_concede(). If the memory for the factory was allocated,
+ * it will automatically be free'd.
+ *
+ * @param a the persistent handle factory to destroy
+ */
PHP_RAPHF_API void php_persistent_handle_abandon(
php_persistent_handle_factory_t *a);
+
+/**
+ * Acquire a persistent handle.
+ *
+ * That is, either re-use a resource from the free list or create a new handle.
+ *
+ * If a handle is acquired from the free list, the
+ * php_persistent_handle_factory::wakeup callback will be executed for that
+ * handle.
+ *
+ * @param a the persistent handle factory
+ * @param init_arg the \a init_arg for php_resource_factory_handle_ctor()
+ * @return the acquired resource
+ */
PHP_RAPHF_API void *php_persistent_handle_acquire(
php_persistent_handle_factory_t *a, void *init_arg TSRMLS_DC);
+
+/**
+ * Release a persistent handle.
+ *
+ * That is, either put it back into the free list for later re-use or clean it
+ * up with php_resource_factory_handle_dtor().
+ *
+ * If a handle is put back into the free list, the
+ * php_persistent_handle_factory::retire callback will be executed for that
+ * handle.
+ *
+ * @param a the persistent handle factory
+ * @param handle the handle to release
+ */
PHP_RAPHF_API void php_persistent_handle_release(
php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
+
+/**
+ * Copy a persistent handle.
+ *
+ * Let the underlying resource factory copy the \a handle.
+ *
+ * @param a the persistent handle factory
+ * @param handle the resource to accrete
+ */
PHP_RAPHF_API void *php_persistent_handle_accrete(
php_persistent_handle_factory_t *a, void *handle TSRMLS_DC);
+/**
+ * Retrieve persistent handle resource factory ops.
+ *
+ * These ops can be used to mask a persistent handle factory as
+ * resource factory itself, so you can transparently use the
+ * resource factory API, both for persistent and non-persistent
+ * ressources.
+ *
+ * Example:
+ * ~~~~~~~~~~~~~~~{.c}
+ * php_resource_factory_t *create_my_rf(const char *persistent_id_str,
+ * size_t persistent_id_len TSRMLS_DC)
+ * {
+ * php_resource_factory_t *rf;
+ *
+ * if (persistent_id_str) {
+ * php_persistent_handle_factory_t *pf;
+ * php_resource_factory_ops_t *ops;
+ *
+ * ops = php_persistent_handle_get_resource_factory_ops();
+ *
+ * pf = php_persistent_handle_concede(NULL, "my", 2,
+ * persistent_id_str, persistent_id_len, NULL, NULL TSRMLS_CC);
+ *
+ * rf = php_resource_factory_init(NULL, ops, pf, php_persistent_handle_abandon);
+ * } else {
+ * rf = php_resource_factory_init(NULL, &myops, NULL, NULL);
+ * }
+ * return rf;
+ * }
+ * ~~~~~~~~~~~~~~~
+ */
PHP_RAPHF_API php_resource_factory_ops_t *
php_persistent_handle_get_resource_factory_ops(void);
+/**
+ * Clean persistent handles up.
+ *
+ * Destroy persistent handles of provider \a name_str and in subsidiary
+ * namespace \a ident_str.
+ *
+ * If \a name_str is NULL, all persistent handles of all providers with a
+ * matching \a ident_str will be cleaned up.
+ *
+ * If \a ident_str is NULL all persistent handles of the provider will be
+ * cleaned up.
+ *
+ * Ergo, if both, \a name_str and \a ident_str are NULL, then all
+ * persistent handles will be cleaned up.
+ *
+ * You must call this in MSHUTDOWN, if your resource factory ops hold a
+ * registered php_resource_factory::dtor, else the dtor will point to
+ * memory not any more available if the extension has already been unloaded.
+ *
+ * @param name_str the provider name; may be NULL
+ * @param name_len the provider name length
+ * @param ident_str the subsidiary namespace name; may be NULL
+ * @param ident_len the subsidiary namespace name length
+ */
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);
-PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC);
-ZEND_BEGIN_MODULE_GLOBALS(raphf)
- struct php_persistent_handle_globals persistent_handle;
-ZEND_END_MODULE_GLOBALS(raphf)
-
-#ifdef ZTS
-# define PHP_RAPHF_G ((zend_raphf_globals *) \
- (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)])
-#else
-# define PHP_RAPHF_G (&raphf_globals)
-#endif
+/**
+ * Retrieve statistics about the current process/thread's persistent handles.
+ *
+ * @return a HashTable like:
+ * ~~~~~~~~~~~~~~~
+ * [
+ * "name" => [
+ * "ident" => [
+ * "used" => 1,
+ * "free" => 0,
+ * ]
+ * ]
+ * ]
+ * ~~~~~~~~~~~~~~~
+ */
+PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht TSRMLS_DC);
#endif /* PHP_RAPHF_H */