Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stubs): Retry Policy #85

Merged
merged 10 commits into from
Aug 2, 2023
35 changes: 35 additions & 0 deletions include/RetryPolicy/RetryPolicy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <api.h>
#include <cassandra.h>
#include <php.h>

#include <ZendCPP/ZendCPP.hpp>

BEGIN_EXTERN_C()

typedef struct
{
CassRetryPolicy *policy;
zend_object zendObject;
} php_driver_retry_policy;

extern PHP_SCYLLADB_API zend_class_entry *php_scylladb_retry_policy_default_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_downgrading_consistency_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_fallthrough_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_logging_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_scylladb_retry_policy_ce;

PHP_SCYLLADB_API php_driver_retry_policy *php_scylladb_retry_policy_default_instantiate(zval *dst);
PHP_SCYLLADB_API php_driver_retry_policy *php_scylladb_retry_policy_downgrading_consistency_instantiate(zval *dst);
PHP_SCYLLADB_API php_driver_retry_policy *php_scylladb_retry_policy_fallthrough_instantiate(zval *dst);
PHP_SCYLLADB_API php_driver_retry_policy *php_scylladb_retry_policy_logging_instantiate(zval *dst, php_driver_retry_policy *retry_policy);

zend_always_inline php_driver_retry_policy *php_scylladb_retry_policy_from_obj(zend_object *obj) {
return ZendCPP::ObjectFetch<php_driver_retry_policy>(obj);
}

#define Z_SCYLLADB_RETRY_POLICY_P(zv) php_scylladb_retry_policy_from_obj(Z_OBJ_P((zv)))
#define Z_SCYLLADB_RETRY_POLICY_DATE(zv) php_scylladb_retry_policy_from_obj(Z_OBJ((zv)))

END_EXTERN_C()
25 changes: 8 additions & 17 deletions include/php_driver_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <php.h>
#include <php_driver.h>
#include <RetryPolicy/RetryPolicy.h>

BEGIN_EXTERN_C()

Expand Down Expand Up @@ -52,7 +53,6 @@ BEGIN_EXTERN_C()
#define PHP_DRIVER_GET_FUNCTION(obj) php_driver_function_object_fetch(Z_OBJ_P(obj))
#define PHP_DRIVER_GET_AGGREGATE(obj) php_driver_aggregate_object_fetch(Z_OBJ_P(obj))
#define PHP_DRIVER_GET_TYPE(obj) php_driver_type_object_fetch(Z_OBJ_P(obj))
#define PHP_DRIVER_GET_RETRY_POLICY(obj) php_driver_retry_policy_object_fetch(Z_OBJ_P(obj))
#define PHP_DRIVER_GET_TIMESTAMP_GEN(obj) php_driver_timestamp_gen_object_fetch(Z_OBJ_P(obj))
#define PHP_DRIVER_GET_DURATION(obj) php_driver_duration_object_fetch(Z_OBJ_P(obj))

Expand Down Expand Up @@ -342,15 +342,6 @@ static zend_always_inline php_driver_future_rows *php_driver_future_rows_object_
return (php_driver_future_rows *)((char *)obj - ((size_t)(&(((php_driver_future_rows *)0)->zendObject))));
}

typedef struct php_driver_retry_policy_
{
CassRetryPolicy *policy;
zend_object zendObject;
} php_driver_retry_policy;
static zend_always_inline php_driver_retry_policy *php_driver_retry_policy_object_fetch(zend_object *obj)
{
return (php_driver_retry_policy *)((char *)obj - ((size_t)(&(((php_driver_retry_policy *)0)->zendObject))));
}

typedef struct php_driver_ssl_
{
Expand Down Expand Up @@ -875,17 +866,17 @@ void php_driver_define_TypeTuple();
void php_driver_define_TypeUserType();
void php_driver_define_TypeCustom();

extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_default_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_scylladb_retry_policy_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_scylladb_retry_policy_default_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_downgrading_consistency_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_fallthrough_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_retry_policy_logging_ce;

void php_driver_define_RetryPolicy();
void php_driver_define_RetryPolicyDefault();
void php_driver_define_RetryPolicyDowngradingConsistency();
void php_driver_define_RetryPolicyFallthrough();
void php_driver_define_RetryPolicyLogging();
zend_class_entry*php_scylladb_define_RetryPolicy(void);
void php_scylladb_define_RetryPolicyDefault(zend_class_entry* retry_policy_interface);
void php_driver_define_RetryPolicyDowngradingConsistency(zend_class_entry* retry_policy_interface);
void php_driver_define_RetryPolicyFallthrough(zend_class_entry* retry_policy_interface);
void php_driver_define_RetryPolicyLogging(zend_class_entry* retry_policy_interface);

extern PHP_SCYLLADB_API zend_class_entry *php_driver_timestamp_gen_ce;
extern PHP_SCYLLADB_API zend_class_entry *php_driver_timestamp_gen_monotonic_ce;
Expand Down
10 changes: 5 additions & 5 deletions php_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,11 @@ PHP_MINIT_FUNCTION(php_driver) {
php_driver_define_TypeUserType();
php_driver_define_TypeCustom();

php_driver_define_RetryPolicy();
php_driver_define_RetryPolicyDefault();
php_driver_define_RetryPolicyDowngradingConsistency();
php_driver_define_RetryPolicyFallthrough();
php_driver_define_RetryPolicyLogging();
auto * retry_policy_interface = php_scylladb_define_RetryPolicy();
php_scylladb_define_RetryPolicyDefault(retry_policy_interface);
php_driver_define_RetryPolicyDowngradingConsistency(retry_policy_interface);
php_driver_define_RetryPolicyFallthrough(retry_policy_interface);
php_driver_define_RetryPolicyLogging(retry_policy_interface);

php_driver_define_TimestampGenerator();
php_driver_define_TimestampGeneratorMonotonic();
Expand Down
5 changes: 3 additions & 2 deletions src/Cluster/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <php_driver.h>
#include <php_driver_globals.h>
#include <php_driver_types.h>
#include <ZendCPP/ZendCPP.hpp>
#include <util/consistency.h>

#include "BuilderHandlers.h"
Expand Down Expand Up @@ -643,11 +644,11 @@ ZEND_METHOD(Cassandra_Cluster_Builder, withRetryPolicy)
zval *retry_policy = nullptr;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT_OF_CLASS(retry_policy, php_driver_retry_policy_ce)
Z_PARAM_OBJECT_OF_CLASS(retry_policy, php_scylladb_retry_policy_ce)
ZEND_PARSE_PARAMETERS_END();

php_driver_cluster_builder *self = PHP_DRIVER_GET_CLUSTER_BUILDER(getThis());
php_driver_retry_policy *policy = PHP_DRIVER_GET_RETRY_POLICY(retry_policy);
auto *policy = ZendCPP::ObjectFetch<php_driver_retry_policy>(retry_policy);

if (self->retry_policy != nullptr)
{
Expand Down
4 changes: 2 additions & 2 deletions src/DateTime/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define NUM_NANOSECONDS_PER_DAY 86399999999999LL
#define NANOSECONDS_PER_SECOND 1000000000LL

static cass_int64_t php_driver_time_now_ns() {
static cass_int64_t php_scylladb_time_now_ns() {
cass_int64_t seconds;
cass_int64_t nanoseconds;
#if defined(__APPLE__) && defined(__MACH__)
Expand Down Expand Up @@ -82,7 +82,7 @@ PHP_SCYLLADB_API zend_result php_scylladb_time_initialize(php_scylladb_time *sel
zend_string *nanosecondsStr,
zend_long nanoseconds) {
if (nanosecondsStr == nullptr && nanoseconds == -1) {
self->time = php_driver_time_now_ns();
self->time = php_scylladb_time_now_ns();
return SUCCESS;
}

Expand Down
50 changes: 50 additions & 0 deletions src/DateTime/Timeuuid_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 36db175b25ad8d988ad4abce8e4577c3fa97b447 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Cassandra_Timeuuid___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO(0, uuid, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Cassandra_Timeuuid_type, 0, 0, Cassandra\\Type, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Cassandra_Timeuuid_time, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Cassandra_Timeuuid_version arginfo_class_Cassandra_Timeuuid_time

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Cassandra_Timeuuid_uuid, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Cassandra_Timeuuid___toString arginfo_class_Cassandra_Timeuuid_uuid


ZEND_METHOD(Cassandra_Timeuuid, __construct);
ZEND_METHOD(Cassandra_Timeuuid, type);
ZEND_METHOD(Cassandra_Timeuuid, time);
ZEND_METHOD(Cassandra_Timeuuid, version);
ZEND_METHOD(Cassandra_Timeuuid, uuid);
ZEND_METHOD(Cassandra_Timeuuid, __toString);


static const zend_function_entry class_Cassandra_Timeuuid_methods[] = {
ZEND_ME(Cassandra_Timeuuid, __construct, arginfo_class_Cassandra_Timeuuid___construct, ZEND_ACC_PUBLIC)
ZEND_ME(Cassandra_Timeuuid, type, arginfo_class_Cassandra_Timeuuid_type, ZEND_ACC_PUBLIC)
ZEND_ME(Cassandra_Timeuuid, time, arginfo_class_Cassandra_Timeuuid_time, ZEND_ACC_PUBLIC)
ZEND_ME(Cassandra_Timeuuid, version, arginfo_class_Cassandra_Timeuuid_version, ZEND_ACC_PUBLIC)
ZEND_ME(Cassandra_Timeuuid, uuid, arginfo_class_Cassandra_Timeuuid_uuid, ZEND_ACC_PUBLIC)
ZEND_ME(Cassandra_Timeuuid, __toString, arginfo_class_Cassandra_Timeuuid___toString, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

static zend_class_entry *register_class_Cassandra_Timeuuid(zend_class_entry *class_entry_Cassandra_Value)
{
zend_class_entry ce, *class_entry;

INIT_NS_CLASS_ENTRY(ce, "Cassandra", "Timeuuid", class_Cassandra_Timeuuid_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zend_class_implements(class_entry, 1, class_entry_Cassandra_Value);

return class_entry;
}
4 changes: 2 additions & 2 deletions src/DefaultSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ PHP_METHOD(DefaultSession, execute) {
if (opts->serial_consistency >= 0) serial_consistency = opts->serial_consistency;

if (!Z_ISUNDEF(opts->retry_policy))
retry_policy = (PHP_DRIVER_GET_RETRY_POLICY(&opts->retry_policy))->policy;
retry_policy = (ZendCPP::ObjectFetch<php_driver_retry_policy>(&opts->retry_policy))->policy;

timestamp = opts->timestamp;
}
Expand Down Expand Up @@ -709,7 +709,7 @@ PHP_METHOD(DefaultSession, executeAsync) {
if (opts->serial_consistency >= 0) serial_consistency = opts->serial_consistency;

if (!Z_ISUNDEF(opts->retry_policy))
retry_policy = (PHP_DRIVER_GET_RETRY_POLICY(&opts->retry_policy))->policy;
retry_policy = ZendCPP::ObjectFetch<php_driver_retry_policy>((&opts->retry_policy))->policy;

timestamp = opts->timestamp;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutionOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static zend_result build_from_array(php_driver_execution_options *self, zval *op
if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "retry_policy", sizeof("retry_policy"), retry_policy))
{
if (Z_TYPE_P(retry_policy) != IS_OBJECT &&
!instanceof_function(Z_OBJCE_P(retry_policy), php_driver_retry_policy_ce))
!instanceof_function(Z_OBJCE_P(retry_policy), php_scylladb_retry_policy_ce))
{
throw_invalid_argument(retry_policy, "retry_policy",
"an instance of " PHP_DRIVER_NAMESPACE "\\RetryPolicy");
Expand Down
58 changes: 30 additions & 28 deletions src/RetryPolicy/DefaultPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,53 @@
* limitations under the License.
*/

#include "php_driver.h"
#include "php_driver_types.h"
#include "util/types.h"
#include <ZendCPP/ZendCPP.hpp>
#include <RetryPolicy/RetryPolicy.h>

BEGIN_EXTERN_C()

zend_class_entry *php_driver_retry_policy_default_ce = NULL;
#include "DefaultPolicy_arginfo.h"

static zend_function_entry php_driver_retry_policy_default_methods[] = {
PHP_FE_END
};
zend_class_entry *php_scylladb_retry_policy_default_ce = nullptr;

static zend_object_handlers php_driver_retry_policy_default_handlers;
static zend_object_handlers php_scylladb_retry_policy_default_handlers;

static void
php_driver_retry_policy_default_free(zend_object *object )
PHP_SCYLLADB_API php_driver_retry_policy *php_scylladb_retry_policy_default_instantiate(zval *dst)
{
php_driver_retry_policy *self = PHP5TO7_ZEND_OBJECT_GET(retry_policy, object);
zval val;

cass_retry_policy_free(self->policy);
if (object_init_ex(&val, php_scylladb_retry_policy_default_ce) == FAILURE) {
return nullptr;
}

zend_object_std_dtor(&self->zendObject);
ZVAL_OBJ(dst, Z_OBJ(val));

auto* obj = ZendCPP::ObjectFetch<php_driver_retry_policy>(dst);
obj->policy = cass_retry_policy_default_new();
return obj;
}

static zend_object*
php_driver_retry_policy_default_new(zend_class_entry *ce )
{
php_driver_retry_policy *self = PHP5TO7_ZEND_OBJECT_ECALLOC(retry_policy, ce);

self->policy = cass_retry_policy_default_new();
static void php_scylladb_retry_policy_default_free(zend_object *object)
{
auto *self = ZendCPP::ObjectFetch<php_driver_retry_policy>(object);

PHP5TO7_ZEND_OBJECT_INIT_EX(retry_policy, retry_policy_default, self, ce);
cass_retry_policy_free(self->policy);
}

void php_driver_define_RetryPolicyDefault()
static zend_object*php_scylladb_retry_policy_default_new(zend_class_entry *ce)
{
zend_class_entry ce;
auto *self = ZendCPP::Allocate<php_driver_retry_policy>(ce, &php_scylladb_retry_policy_default_handlers);
self->policy = cass_retry_policy_default_new();
return &self->zendObject;
}

INIT_CLASS_ENTRY(ce, PHP_DRIVER_NAMESPACE "\\RetryPolicy\\DefaultPolicy", php_driver_retry_policy_default_methods);
php_driver_retry_policy_default_ce = zend_register_internal_class(&ce );
zend_class_implements(php_driver_retry_policy_default_ce , 1, php_driver_retry_policy_ce);
php_driver_retry_policy_default_ce->ce_flags |= ZEND_ACC_FINAL;
php_driver_retry_policy_default_ce->create_object = php_driver_retry_policy_default_new;
void php_scylladb_define_RetryPolicyDefault(zend_class_entry* retry_policy_interface)
{
php_scylladb_retry_policy_default_ce = register_class_Cassandra_RetryPolicy_DefaultPolicy(retry_policy_interface);
php_scylladb_retry_policy_default_ce->create_object = php_scylladb_retry_policy_default_new;

memcpy(&php_driver_retry_policy_default_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
ZendCPP::InitHandlers<php_driver_retry_policy>(&php_scylladb_retry_policy_default_handlers);
php_scylladb_retry_policy_default_handlers.free_obj = php_scylladb_retry_policy_default_free;
}
END_EXTERN_C()
END_EXTERN_C()
11 changes: 11 additions & 0 deletions src/RetryPolicy/DefaultPolicy.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* @generate-class-entries
*/
namespace Cassandra\RetryPolicy {
/**
* @strict-properties
*/
final class DefaultPolicy implements \Cassandra\RetryPolicy { }
}
21 changes: 21 additions & 0 deletions src/RetryPolicy/DefaultPolicy_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 15eeabd10fd045bbcd44886c3126a196b70a7603 */




static const zend_function_entry class_Cassandra_RetryPolicy_DefaultPolicy_methods[] = {
ZEND_FE_END
};

static zend_class_entry *register_class_Cassandra_RetryPolicy_DefaultPolicy(zend_class_entry *class_entry_Cassandra_RetryPolicy)
{
zend_class_entry ce, *class_entry;

INIT_NS_CLASS_ENTRY(ce, "Cassandra\\RetryPolicy", "DefaultPolicy", class_Cassandra_RetryPolicy_DefaultPolicy_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zend_class_implements(class_entry, 1, class_entry_Cassandra_RetryPolicy);

return class_entry;
}
Loading
Loading