Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Ambrose committed Feb 29, 2024
1 parent 7074a0d commit 0da55e2
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 15 deletions.
5 changes: 5 additions & 0 deletions include/aws/mqtt/private/client_impl_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ struct aws_mqtt_client_connection_vtable {
int (*get_stats_fn)(void *impl, struct aws_mqtt_connection_operation_statistics *stats);

enum aws_mqtt311_impl_type (*get_impl_type)(const void *impl);

struct aws_event_loop *(*get_event_loop)(const void *impl);
};

struct aws_mqtt_client_connection {
Expand All @@ -139,4 +141,7 @@ AWS_MQTT_API bool aws_mqtt_compare_uint16_t_eq(const void *a, const void *b);

AWS_MQTT_API bool aws_mqtt_byte_cursor_hash_equality(const void *a, const void *b);

AWS_MQTT_API struct aws_event_loop *aws_mqtt_client_connection_get_event_loop(
const struct aws_mqtt_client_connection *connection);

#endif /* AWS_MQTT_PRIVATE_CLIENT_IMPL_SHARED_H */
9 changes: 6 additions & 3 deletions include/aws/mqtt/private/request-response/protocol_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ struct aws_protocol_adapter_connection_event {
};

typedef void(
aws_protocol_adapter_subscription_event_fn)(struct aws_protocol_adapter_subscription_event *event, void *user_data);
aws_protocol_adapter_subscription_event_fn)(const struct aws_protocol_adapter_subscription_event *event, void *user_data);

typedef void(aws_protocol_adapter_incoming_publish_fn)(
struct aws_protocol_adapter_incoming_publish_event *publish,
const struct aws_protocol_adapter_incoming_publish_event *publish,
void *user_data);

typedef void(aws_protocol_adapter_terminate_callback_fn)(void *user_data);

typedef void(
aws_protocol_adapter_connection_event_fn)(struct aws_protocol_adapter_connection_event *event, void *user_data);
aws_protocol_adapter_connection_event_fn)(const struct aws_protocol_adapter_connection_event *event, void *user_data);

/*
* Set of callbacks invoked by the protocol adapter. These must all be set.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef AWS_MQTT_PRIVATE_REQUEST_RESPONSE_REQUEST_RESPONSE_CLIENT_H
#define AWS_MQTT_PRIVATE_REQUEST_RESPONSE_REQUEST_RESPONSE_CLIENT_H

/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/mqtt/mqtt.h>

struct aws_mqtt_protocol_adapter;
struct aws_mqtt_protocol_adapter_options;
struct aws_mqtt_request_response_client;
struct aws_mqtt_request_response_client_options;

struct aws_protocol_adapter_factory_options {
struct aws_event_loop *loop;
void *creation_context;
struct aws_mqtt_protocol_adapter * (*mqtt_protocol_adaptor_factory_fn)(struct aws_mqtt_request_response_client *, struct aws_mqtt_protocol_adapter_options *, void *);
};

AWS_EXTERN_C_BEGIN

struct aws_mqtt_request_response_client *aws_mqtt_request_response_client_new_from_adaptor_factory(struct aws_allocator *allocator, const struct aws_protocol_adapter_factory_options *factory_options, const struct aws_mqtt_request_response_client_options *client_options);

AWS_EXTERN_C_END

#endif /* AWS_MQTT_PRIVATE_REQUEST_RESPONSE_REQUEST_RESPONSE_CLIENT_H */
33 changes: 33 additions & 0 deletions include/aws/mqtt/request-response/request_response_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef AWS_MQTT_REQUEST_RESPONSE_REQUEST_RESPONSE_CLIENT_H
#define AWS_MQTT_REQUEST_RESPONSE_REQUEST_RESPONSE_CLIENT_H

/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include "aws/mqtt/mqtt.h"

struct aws_mqtt_request_response_client;
struct aws_mqtt_client_connection;
struct aws_mqtt5_client;

struct aws_mqtt_request_response_client_options {
size_t max_subscriptions;
uint32_t operation_timeout_seconds;
};

AWS_EXTERN_C_BEGIN

struct aws_mqtt_request_response_client *aws_mqtt_request_response_client_new_from_mqtt311_client(struct aws_allocator *allocator, struct aws_mqtt_client_connection *client, const struct aws_mqtt_request_response_client_options *options);

struct aws_mqtt_request_response_client *aws_mqtt_request_response_client_new_from_mqtt5_client(struct aws_allocator *allocator, struct aws_mqtt5_client *client, const struct aws_mqtt_request_response_client_options *options);

struct aws_mqtt_request_response_client *aws_mqtt_request_response_client_acquire(struct aws_mqtt_request_response_client *client);

struct aws_mqtt_request_response_client *aws_mqtt_request_response_client_release(struct aws_mqtt_request_response_client *client);


AWS_EXTERN_C_END

#endif /* AWS_MQTT_REQUEST_RESPONSE_REQUEST_RESPONSE_CLIENT_H */
11 changes: 9 additions & 2 deletions source/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3322,12 +3322,18 @@ static void s_aws_mqtt_client_connection_311_release(void *impl) {
aws_ref_count_release(&connection->ref_count);
}

enum aws_mqtt311_impl_type s_aws_mqtt_client_connection_3_get_impl(const void *impl) {
static enum aws_mqtt311_impl_type s_aws_mqtt_client_connection_311_get_impl(const void *impl) {
(void)impl;

return AWS_MQTT311_IT_311_CONNECTION;
}

static struct aws_event_loop *s_aws_mqtt_client_connection_311_get_event_loop(const void *impl) {
const struct aws_mqtt_client_connection_311_impl *connection = impl;

return connection->loop;
}

static struct aws_mqtt_client_connection_vtable s_aws_mqtt_client_connection_311_vtable = {
.acquire_fn = s_aws_mqtt_client_connection_311_acquire,
.release_fn = s_aws_mqtt_client_connection_311_release,
Expand All @@ -3351,7 +3357,8 @@ static struct aws_mqtt_client_connection_vtable s_aws_mqtt_client_connection_311
.unsubscribe_fn = s_aws_mqtt_client_connection_311_unsubscribe,
.publish_fn = s_aws_mqtt_client_connection_311_publish,
.get_stats_fn = s_aws_mqtt_client_connection_311_get_stats,
.get_impl_type = s_aws_mqtt_client_connection_3_get_impl,
.get_impl_type = s_aws_mqtt_client_connection_311_get_impl,
.get_event_loop = s_aws_mqtt_client_connection_311_get_event_loop,
};

static struct aws_mqtt_client_connection_vtable *s_aws_mqtt_client_connection_311_vtable_ptr =
Expand Down
4 changes: 4 additions & 0 deletions source/client_impl_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,7 @@ bool aws_mqtt_byte_cursor_hash_equality(const void *a, const void *b) {

return aws_byte_cursor_eq(a_cursor, b_cursor);
}

struct aws_event_loop *aws_mqtt_client_connection_get_event_loop(const struct aws_mqtt_client_connection *connection) {
return (*connection->vtable->get_event_loop)(connection->impl);
}
5 changes: 3 additions & 2 deletions source/request-response/protocol_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aws/mqtt/private/mqtt311_listener.h>
#include <aws/mqtt/private/request-response/weak_ref.h>
#include <aws/mqtt/private/v5/mqtt5_client_impl.h>
#include <aws/mqtt/private/v5/mqtt5_to_mqtt3_adapter_impl.h>
#include <aws/mqtt/v5/mqtt5_client.h>
#include <aws/mqtt/v5/mqtt5_listener.h>

Expand Down Expand Up @@ -428,8 +429,8 @@ struct aws_mqtt_protocol_adapter *aws_mqtt_protocol_adapter_new_from_311(
}

if (aws_mqtt_client_connection_get_impl_type(connection) != AWS_MQTT311_IT_311_CONNECTION) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
return NULL;
struct aws_mqtt_client_connection_5_impl *adapter_impl = connection->impl;
return aws_mqtt_protocol_adapter_new_from_5(allocator, options, adapter_impl->client);
}

struct aws_mqtt_client_connection_311_impl *impl = connection->impl;
Expand Down
Loading

0 comments on commit 0da55e2

Please sign in to comment.