Files
awslabs_aws-crt-php/ext/crt.c
T
Justin Boswell 9171857448 Updated CRT library, test process, EventLoopGroup API updates (#16)
* Updated to latest aws-crt-ffi, updated EventLoopGroup/options init

* Removed test-ci target, just use test for everything now

* Added event_loop_group API to CRT/stubs

* Removed headers (all generated) from format-check

* Added the ability to force extension vs FFI

* make test will now trigger composer run test/phpunit, and force tests with both FFI and extension

* Updated builder version, removed redundant php7 test run

* Removed type annotations that anger php5, limited backends on php5
2021-03-12 11:47:55 -08:00

155 lines
3.7 KiB
C

/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include "php_aws_crt.h"
#include "api.h"
#include "awscrt_arginfo.h"
ZEND_DECLARE_MODULE_GLOBALS(awscrt);
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY(
"awscrt.log_level",
"",
PHP_INI_ALL,
OnUpdateLongGEZero,
log_level,
zend_awscrt_globals,
awscrt_globals)
PHP_INI_END()
static PHP_MINIT_FUNCTION(awscrt) {
REGISTER_INI_ENTRIES();
aws_crt_init();
return SUCCESS;
}
static PHP_MSHUTDOWN_FUNCTION(awscrt) {
UNREGISTER_INI_ENTRIES();
aws_crt_clean_up();
return SUCCESS;
}
static PHP_GINIT_FUNCTION(awscrt) {
#if defined(COMPILE_DL_ASTKIT) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
awscrt_globals->log_level = 0;
}
/* aws_crt_last_error() */
PHP_FUNCTION(aws_crt_last_error) {
RETURN_LONG(aws_crt_last_error());
}
/* aws_crt_error_str(int error_code) */
PHP_FUNCTION(aws_crt_error_str) {
zend_ulong error_code = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error_code) == FAILURE) {
RETURN_NULL();
}
AWS_RETURN_STRING(aws_crt_error_str(error_code));
}
/* aws_crt_error_name(int error_code) */
PHP_FUNCTION(aws_crt_error_name) {
zend_ulong error_code = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error_code) == FAILURE) {
RETURN_NULL();
}
AWS_RETURN_STRING(aws_crt_error_name(error_code));
}
/* aws_crt_error_debug_str(int error_code) */
PHP_FUNCTION(aws_crt_error_debug_str) {
zend_ulong error_code = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error_code) == FAILURE) {
RETURN_NULL();
}
AWS_RETURN_STRING(aws_crt_error_debug_str(error_code));
}
PHP_FUNCTION(aws_crt_event_loop_group_options_new) {
aws_crt_event_loop_group_options *options = aws_crt_event_loop_group_options_new();
RETURN_LONG((zend_ulong)options);
}
PHP_FUNCTION(aws_crt_event_loop_group_options_release) {
zend_ulong php_options = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_options) == FAILURE) {
return;
}
aws_crt_event_loop_group_options *options = (void *)php_options;
aws_crt_event_loop_group_options_release(options);
}
PHP_FUNCTION(aws_crt_event_loop_group_options_set_max_threads) {
zend_ulong php_options = 0;
zend_ulong num_threads = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &php_options, &num_threads) == FAILURE) {
RETURN_NULL();
}
aws_crt_event_loop_group_options *options = (void *)php_options;
aws_crt_event_loop_group_options_set_max_threads(options, num_threads);
}
PHP_FUNCTION(aws_crt_event_loop_group_new) {
zend_ulong php_options = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_options) == FAILURE) {
RETURN_NULL();
}
aws_crt_event_loop_group_options *options = (void *)php_options;
struct aws_event_loop_group *elg = aws_crt_event_loop_group_new(options);
RETURN_LONG((zend_ulong)elg);
}
PHP_FUNCTION(aws_crt_event_loop_group_release) {
zend_ulong php_elg = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_elg) == FAILURE) {
return;
}
struct aws_event_loop_group *elg = (void *)php_elg;
aws_crt_event_loop_group_release(elg);
}
zend_module_entry awscrt_module_entry = {
STANDARD_MODULE_HEADER,
"awscrt",
ext_functions, /* functions */
PHP_MINIT(awscrt),
PHP_MSHUTDOWN(awscrt),
NULL, /* RINIT */
NULL, /* RSHUTDOWN */
NULL, /* MINFO */
NO_VERSION_YET,
PHP_MODULE_GLOBALS(awscrt),
PHP_GINIT(awscrt),
NULL, /* GSHUTDOWN */
NULL, /* RPOSTSHUTDOWN */
STANDARD_MODULE_PROPERTIES_EX,
};
#ifdef COMPILE_DL_AWSCRT
ZEND_GET_MODULE(awscrt)
#endif