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