svn: /pecl/http/branches/DEV_2/ php_http_resource_factory.c php_http_resource_factory.h

From: Date: Sat, 21 May 2011 15:26:28 +0000
Subject: svn: /pecl/http/branches/DEV_2/ php_http_resource_factory.c php_http_resource_factory.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-15653@lists.php.net to get a copy of this message
mike Sat, 21 May 2011 15:26:28 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=311308 Log: * add a resource factory Changed paths: A pecl/http/branches/DEV_2/php_http_resource_factory.c A pecl/http/branches/DEV_2/php_http_resource_factory.h Added: pecl/http/branches/DEV_2/php_http_resource_factory.c =================================================================== --- pecl/http/branches/DEV_2/php_http_resource_factory.c (rev 0) +++ pecl/http/branches/DEV_2/php_http_resource_factory.c 2011-05-21 15:26:28 UTC (rev 311308) @@ -0,0 +1,79 @@ +/* + +--------------------------------------------------------------------+ + | PECL :: http | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met. | + +--------------------------------------------------------------------+ + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> | + +--------------------------------------------------------------------+ +*/ + +/* $Id:$ */ + +#include "php_http.h" +#include "php_http_resource_factory.h" + +PHP_HTTP_API php_http_resource_factory_t *php_http_resource_factory_init(php_http_resource_factory_t *f, php_http_resource_factory_ops_t *fops, void *data, void (*dtor)(void *data)) +{ + if (!f) { + f = emalloc(sizeof(*f)); + } + memset(f, 0, sizeof(*f)); + + memcpy(&f->fops, fops, sizeof(*fops)); + + f->data = data; + f->dtor = dtor; + + return f; +} + +PHP_HTTP_API void php_http_resource_factory_dtor(php_http_resource_factory_t *f) +{ + if (f->dtor) { + f->dtor(f->data); + } +} +PHP_HTTP_API void php_http_resource_factory_free(php_http_resource_factory_t **f) +{ + if (*f) { + php_http_resource_factory_dtor(*f); + efree(*f); + *f = NULL; + } +} + +PHP_HTTP_API void *php_http_resource_factory_handle_ctor(php_http_resource_factory_t *f TSRMLS_DC) +{ + if (f->fops.ctor) { + return f->fops.ctor(f->data TSRMLS_CC); + } + return NULL; +} + +PHP_HTTP_API void *php_http_resource_factory_handle_copy(php_http_resource_factory_t *f, void *handle TSRMLS_DC) +{ + if (f->fops.copy) { + return f->fops.copy(f->data, handle TSRMLS_CC); + } + return NULL; +} + +PHP_HTTP_API void php_http_resource_factory_handle_dtor(php_http_resource_factory_t *f, void *handle TSRMLS_DC) +{ + if (f->fops.dtor) { + f->fops.dtor(f->data, handle TSRMLS_CC); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + Added: pecl/http/branches/DEV_2/php_http_resource_factory.h =================================================================== --- pecl/http/branches/DEV_2/php_http_resource_factory.h (rev 0) +++ pecl/http/branches/DEV_2/php_http_resource_factory.h 2011-05-21 15:26:28 UTC (rev 311308) @@ -0,0 +1,53 @@ +/* + +--------------------------------------------------------------------+ + | PECL :: http | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met. | + +--------------------------------------------------------------------+ + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> | + +--------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_HTTP_RESOURCE_FACTORY_H +#define PHP_HTTP_RESOURCE_FACTORY_H + +typedef void *(*php_http_resource_factory_handle_ctor_t)(void *opaque TSRMLS_DC); +typedef void *(*php_http_resource_factory_handle_copy_t)(void *opaque, void *handle TSRMLS_DC); +typedef void (*php_http_resource_factory_handle_dtor_t)(void *opaque, void *handle TSRMLS_DC); + +typedef struct php_http_resource_factory_ops { + php_http_resource_factory_handle_ctor_t ctor; + php_http_resource_factory_handle_copy_t copy; + php_http_resource_factory_handle_dtor_t dtor; +} php_http_resource_factory_ops_t; + +typedef struct php_http_resource_factory { + php_http_resource_factory_ops_t fops; + + void *data; + void (*dtor)(void *data); + +} php_http_resource_factory_t; + +PHP_HTTP_API php_http_resource_factory_t *php_http_resource_factory_init(php_http_resource_factory_t *f, php_http_resource_factory_ops_t *fops, void *data, void (*dtor)(void *data)); +PHP_HTTP_API void php_http_resource_factory_dtor(php_http_resource_factory_t *f); +PHP_HTTP_API void php_http_resource_factory_free(php_http_resource_factory_t **f); + +PHP_HTTP_API void *php_http_resource_factory_handle_ctor(php_http_resource_factory_t *f TSRMLS_DC); +PHP_HTTP_API void *php_http_resource_factory_handle_copy(php_http_resource_factory_t *f, void *handle TSRMLS_DC); +PHP_HTTP_API void php_http_resource_factory_handle_dtor(php_http_resource_factory_t *f, void *handle TSRMLS_DC); + +#endif /* PHP_HTTP_RESOURCE_FACTORY_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */

« previous php.pecl.cvs (#15653) next »