@@ -50,39 +50,39 @@ namespace cppkafka {
50
50
// Callback proxies
51
51
52
52
void delivery_report_callback_proxy (rd_kafka_t *, const rd_kafka_message_t * msg, void *opaque) {
53
+ static const string callback_name (" delivery report" );
53
54
Producer* handle = static_cast <Producer*>(opaque);
54
55
Message message = Message::make_non_owning ((rd_kafka_message_t *)msg);
55
- const auto & callback = handle->get_configuration ().get_delivery_report_callback ();
56
- if (callback) {
57
- callback (*handle, message);
58
- }
56
+ CallbackInvoker<void (Producer&, const Message&)>
57
+ (callback_name, handle->get_configuration ().get_delivery_report_callback (), handle)
58
+ (*handle, message);
59
59
}
60
60
61
61
void offset_commit_callback_proxy (rd_kafka_t *, rd_kafka_resp_err_t err,
62
62
rd_kafka_topic_partition_list_t *offsets, void *opaque) {
63
+ static const string callback_name (" offset commit" );
63
64
Consumer* handle = static_cast <Consumer*>(opaque);
64
65
TopicPartitionList list = offsets ? convert (offsets) : TopicPartitionList{};
65
- const auto & callback = handle->get_configuration ().get_offset_commit_callback ();
66
- if (callback) {
67
- callback (*handle, err, list);
68
- }
66
+ CallbackInvoker<void (Consumer&, Error, const TopicPartitionList&)>
67
+ (callback_name, handle->get_configuration ().get_offset_commit_callback (), handle)
68
+ (*handle, err, list);
69
69
}
70
70
71
71
void error_callback_proxy (rd_kafka_t *, int err, const char *reason, void *opaque) {
72
+ static const string callback_name (" error" );
72
73
KafkaHandleBase* handle = static_cast <KafkaHandleBase*>(opaque);
73
- const auto & callback = handle->get_configuration ().get_error_callback ();
74
- if (callback) {
75
- callback (*handle, err, reason);
76
- }
74
+ CallbackInvoker<void (KafkaHandleBase&, int , const std::string&)>
75
+ (callback_name, handle->get_configuration ().get_error_callback (), handle)
76
+ (*handle, err, reason);
77
77
}
78
78
79
79
void throttle_callback_proxy (rd_kafka_t *, const char * broker_name,
80
80
int32_t broker_id, int throttle_time_ms, void *opaque) {
81
+ static const string callback_name (" throttle" );
81
82
KafkaHandleBase* handle = static_cast <KafkaHandleBase*>(opaque);
82
- const auto & callback = handle->get_configuration ().get_throttle_callback ();
83
- if (callback) {
84
- callback (*handle, broker_name, broker_id, milliseconds (throttle_time_ms));
85
- }
83
+ CallbackInvoker<void (KafkaHandleBase&, const std::string&, int32_t , std::chrono::milliseconds)>
84
+ (callback_name, handle->get_configuration ().get_throttle_callback (), handle)
85
+ (*handle, broker_name, broker_id, milliseconds (throttle_time_ms));
86
86
}
87
87
88
88
void log_callback_proxy (const rd_kafka_t * h, int level,
@@ -95,23 +95,23 @@ void log_callback_proxy(const rd_kafka_t* h, int level,
95
95
}
96
96
97
97
int stats_callback_proxy (rd_kafka_t *, char *json, size_t json_len, void *opaque) {
98
+ static const string callback_name (" statistics" );
98
99
KafkaHandleBase* handle = static_cast <KafkaHandleBase*>(opaque);
99
- const auto & callback = handle->get_configuration ().get_stats_callback ();
100
- if (callback) {
101
- callback (*handle, string (json, json + json_len));
102
- }
100
+ CallbackInvoker<void (KafkaHandleBase&, const std::string&)>
101
+ (callback_name, handle->get_configuration ().get_stats_callback (), handle)
102
+ (*handle, string (json, json + json_len));
103
103
return 0 ;
104
104
}
105
105
106
106
int socket_callback_proxy (int domain, int type, int protocol, void * opaque) {
107
+ static const string callback_name (" socket" );
107
108
KafkaHandleBase* handle = static_cast <KafkaHandleBase*>(opaque);
108
- const auto & callback = handle->get_configuration ().get_socket_callback ();
109
- if (callback) {
110
- return callback (domain, type, protocol);
111
- }
112
- else {
113
- return -1 ;
109
+ if (handle->get_configuration ().get_socket_callback ()) {
110
+ return CallbackInvoker<int (int , int , int )>
111
+ (callback_name, handle->get_configuration ().get_socket_callback (), handle)
112
+ (domain, type, protocol);
114
113
}
114
+ return -1 ;
115
115
}
116
116
117
117
// Configuration
0 commit comments