From 831111812ebc60a392df9dcefb1ee694d3d53f82 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 19 Jun 2016 09:46:28 -0700 Subject: [PATCH] Export symbols on Windows dll builds --- include/cppkafka/buffer.h | 3 +- include/cppkafka/configuration.h | 3 +- include/cppkafka/consumer.h | 3 +- include/cppkafka/exceptions.h | 9 ++--- include/cppkafka/kafka_handle_base.h | 3 +- include/cppkafka/macros.h | 46 +++++++++++++++++++++++++ include/cppkafka/message.h | 3 +- include/cppkafka/metadata.h | 9 ++--- include/cppkafka/partition.h | 4 ++- include/cppkafka/producer.h | 3 +- include/cppkafka/topic.h | 3 +- include/cppkafka/topic_configuration.h | 3 +- include/cppkafka/topic_partition.h | 3 +- include/cppkafka/topic_partition_list.h | 11 +++--- 14 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 include/cppkafka/macros.h diff --git a/include/cppkafka/buffer.h b/include/cppkafka/buffer.h index 8cdcb28..a1aa580 100644 --- a/include/cppkafka/buffer.h +++ b/include/cppkafka/buffer.h @@ -34,6 +34,7 @@ #include #include #include +#include "macros.h" namespace cppkafka { @@ -47,7 +48,7 @@ namespace cppkafka { * pointer that this buffer points to will still until the call to Producer::produce * returns. */ -class Buffer { +class CPPKAFKA_API Buffer { public: /** * The type of data this buffer points to diff --git a/include/cppkafka/configuration.h b/include/cppkafka/configuration.h index 0b881ea..c67e900 100644 --- a/include/cppkafka/configuration.h +++ b/include/cppkafka/configuration.h @@ -40,6 +40,7 @@ #include "topic_configuration.h" #include "clonable_ptr.h" #include "configuration_base.h" +#include "macros.h" namespace cppkafka { @@ -56,7 +57,7 @@ class KafkaHandleBase; * * Some other overloads for Configuration::set are given via ConfigurationBase. */ -class Configuration : public ConfigurationBase { +class CPPKAFKA_API Configuration : public ConfigurationBase { public: using DeliveryReportCallback = std::function; using OffsetCommitCallback = std::function #include "kafka_handle_base.h" #include "message.h" +#include "macros.h" namespace cppkafka { @@ -92,7 +93,7 @@ class TopicConfiguration; * } * \endcode */ -class Consumer : public KafkaHandleBase { +class CPPKAFKA_API Consumer : public KafkaHandleBase { public: using AssignmentCallback = std::function; using RevocationCallback = std::function; diff --git a/include/cppkafka/exceptions.h b/include/cppkafka/exceptions.h index 3088e02..85652ef 100644 --- a/include/cppkafka/exceptions.h +++ b/include/cppkafka/exceptions.h @@ -33,13 +33,14 @@ #include #include #include +#include "macros.h" namespace cppkafka { /** * Base class for all cppkafka exceptions */ -class Exception : public std::exception { +class CPPKAFKA_API Exception : public std::exception { public: Exception(std::string message); @@ -51,7 +52,7 @@ private: /** * A configuration related error */ -class ConfigException : public Exception { +class CPPKAFKA_API ConfigException : public Exception { public: ConfigException(const std::string& config_name, const std::string& error); }; @@ -59,7 +60,7 @@ public: /** * Indicates a configuration option was not set */ -class ConfigOptionNotFound : public Exception { +class CPPKAFKA_API ConfigOptionNotFound : public Exception { public: ConfigOptionNotFound(const std::string& config_name); }; @@ -67,7 +68,7 @@ public: /** * A generic rdkafka handle error */ -class HandleException : public Exception { +class CPPKAFKA_API HandleException : public Exception { public: HandleException(rd_kafka_resp_err_t error_code); diff --git a/include/cppkafka/kafka_handle_base.h b/include/cppkafka/kafka_handle_base.h index 07e41f3..2e9088f 100644 --- a/include/cppkafka/kafka_handle_base.h +++ b/include/cppkafka/kafka_handle_base.h @@ -41,6 +41,7 @@ #include "topic_partition_list.h" #include "topic_configuration.h" #include "configuration.h" +#include "macros.h" namespace cppkafka { @@ -51,7 +52,7 @@ class TopicMetadata; /** * Base class for kafka consumer/producer */ -class KafkaHandleBase { +class CPPKAFKA_API KafkaHandleBase { public: using OffsetTuple = std::tuple; diff --git a/include/cppkafka/macros.h b/include/cppkafka/macros.h new file mode 100644 index 0000000..56f2bd8 --- /dev/null +++ b/include/cppkafka/macros.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef CPPKAFKA_MACROS_H +#define CPPKAFKA_MACROS_H + +// If cppkafka was built into a shared library +#if defined(_WIN32) && !defined(CPPKAFKA_STATIC) + // Export/import symbols, depending on whether we're compiling or consuming the lib + #ifdef cppkafka_EXPORTS + #define CPPKAFKA_API __declspec(dllexport) + #else + #define CPPKAFKA_API __declspec(dllimport) + #endif // cppkafka_EXPORTS +#else + // Otherwise, default this to an empty macro + #define CPPKAFKA_API +#endif // _WIN32 && !CPPKAFKA_STATIC + +#endif // CPPKAFKA_MACROS_H diff --git a/include/cppkafka/message.h b/include/cppkafka/message.h index 4e6ac4f..4048617 100644 --- a/include/cppkafka/message.h +++ b/include/cppkafka/message.h @@ -35,6 +35,7 @@ #include #include "buffer.h" #include "topic.h" +#include "macros.h" namespace cppkafka { @@ -48,7 +49,7 @@ namespace cppkafka { * necessary when calling Consumer::poll() as any poll operation that returns a null pointer will * return an empty message. */ -class Message { +class CPPKAFKA_API Message { public: /** * Constructs a message that won't take ownership of the given pointer diff --git a/include/cppkafka/metadata.h b/include/cppkafka/metadata.h index 05fecab..7aca711 100644 --- a/include/cppkafka/metadata.h +++ b/include/cppkafka/metadata.h @@ -36,13 +36,14 @@ #include #include #include +#include "macros.h" namespace cppkafka { /** * Represents the metadata for a partition */ -class PartitionMetadata { +class CPPKAFKA_API PartitionMetadata { public: PartitionMetadata(const rd_kafka_metadata_partition& partition); @@ -81,7 +82,7 @@ private: /** * Represents the metadata for a topic */ -class TopicMetadata { +class CPPKAFKA_API TopicMetadata { public: TopicMetadata(const rd_kafka_metadata_topic& topic); @@ -108,7 +109,7 @@ private: /** * Represents a broker's metadata */ -class BrokerMetadata { +class CPPKAFKA_API BrokerMetadata { public: BrokerMetadata(const rd_kafka_metadata_broker_t& broker); @@ -135,7 +136,7 @@ private: /** * Represents metadata for brokers, topics and partitions */ -class Metadata { +class CPPKAFKA_API Metadata { public: Metadata(const rd_kafka_metadata_t* ptr); diff --git a/include/cppkafka/partition.h b/include/cppkafka/partition.h index e6f3c49..bb2ff35 100644 --- a/include/cppkafka/partition.h +++ b/include/cppkafka/partition.h @@ -30,6 +30,8 @@ #ifndef CPPKAFKA_PARTITION_H #define CPPKAFKA_PARTITION_H +#include "macros.h" + namespace cppkafka { /** @@ -38,7 +40,7 @@ namespace cppkafka { * This class is basically a wrapper over an int that when default constructed will default * to using RD_KAFKA_PARTITION_UA so you don't need to use the macro name. */ -class Partition { +class CPPKAFKA_API Partition { public: /** * \brief Constructs an unassigned partition diff --git a/include/cppkafka/producer.h b/include/cppkafka/producer.h index 1125ca4..b552e51 100644 --- a/include/cppkafka/producer.h +++ b/include/cppkafka/producer.h @@ -36,6 +36,7 @@ #include "buffer.h" #include "topic.h" #include "partition.h" +#include "macros.h" namespace cppkafka { @@ -77,7 +78,7 @@ class TopicConfiguration; * * \endcode */ -class Producer : public KafkaHandleBase { +class CPPKAFKA_API Producer : public KafkaHandleBase { public: enum PayloadPolicy { COPY_PAYLOAD = RD_KAFKA_MSG_F_COPY, ///< Means RD_KAFKA_MSG_F_COPY diff --git a/include/cppkafka/topic.h b/include/cppkafka/topic.h index 0264bc8..83f08fd 100644 --- a/include/cppkafka/topic.h +++ b/include/cppkafka/topic.h @@ -34,6 +34,7 @@ #include #include #include +#include "macros.h" namespace cppkafka { @@ -42,7 +43,7 @@ namespace cppkafka { * * This is a simple wrapper over a rd_kafka_topic_t* */ -class Topic { +class CPPKAFKA_API Topic { public: /** * \brief Creates a Topic object that doesn't take ownership of the handle diff --git a/include/cppkafka/topic_configuration.h b/include/cppkafka/topic_configuration.h index 6599308..fe4262e 100644 --- a/include/cppkafka/topic_configuration.h +++ b/include/cppkafka/topic_configuration.h @@ -35,6 +35,7 @@ #include #include "clonable_ptr.h" #include "configuration_base.h" +#include "macros.h" namespace cppkafka { @@ -46,7 +47,7 @@ class Buffer; * * ConfigurationBase provides some extra overloads for set */ -class TopicConfiguration : public ConfigurationBase { +class CPPKAFKA_API TopicConfiguration : public ConfigurationBase { public: /** * \brief Partitioner callback diff --git a/include/cppkafka/topic_partition.h b/include/cppkafka/topic_partition.h index f5cb47d..2db8bac 100644 --- a/include/cppkafka/topic_partition.h +++ b/include/cppkafka/topic_partition.h @@ -33,13 +33,14 @@ #include #include #include +#include "macros.h" namespace cppkafka { /** * Represents a topic/partition */ -class TopicPartition { +class CPPKAFKA_API TopicPartition { public: /** * Special offsets enum diff --git a/include/cppkafka/topic_partition_list.h b/include/cppkafka/topic_partition_list.h index 355cabc..cc91dbc 100644 --- a/include/cppkafka/topic_partition_list.h +++ b/include/cppkafka/topic_partition_list.h @@ -34,6 +34,7 @@ #include #include #include +#include "macros.h" namespace cppkafka { @@ -47,12 +48,12 @@ using TopicPartitionsListPtr = std::unique_ptr; // Conversions between rdkafka handles and TopicPartitionList -TopicPartitionsListPtr convert(const std::vector& topic_partitions); -std::vector convert(const TopicPartitionsListPtr& topic_partitions); -std::vector convert(rd_kafka_topic_partition_list_t* topic_partitions); -TopicPartitionsListPtr make_handle(rd_kafka_topic_partition_list_t* handle); +CPPKAFKA_API TopicPartitionsListPtr convert(const std::vector& topic_partitions); +CPPKAFKA_API std::vector convert(const TopicPartitionsListPtr& topic_partitions); +CPPKAFKA_API std::vector convert(rd_kafka_topic_partition_list_t* topic_partitions); +CPPKAFKA_API TopicPartitionsListPtr make_handle(rd_kafka_topic_partition_list_t* handle); -std::ostream& operator<<(std::ostream& output, const TopicPartitionList& rhs); +CPPKAFKA_API std::ostream& operator<<(std::ostream& output, const TopicPartitionList& rhs); } // cppkafka