Browse Source

Merge pull request #264 from hanseuljun/cpp-export

Exporting C++ API for Windows
Paul-Louis Ageneau 4 years ago
parent
commit
3ff5801512

+ 4 - 1
CMakeLists.txt

@@ -247,7 +247,10 @@ add_library(LibDataChannel::LibDataChannelStatic ALIAS datachannel-static)
 install(TARGETS datachannel LIBRARY DESTINATION lib)
 install(FILES ${LIBDATACHANNEL_HEADERS} DESTINATION include/rtc)
 
-if(NOT MSVC)
+if(MSVC)
+	target_compile_options(datachannel PRIVATE /wd4251)
+	target_compile_options(datachannel-static PRIVATE /wd4251)
+else()
 	target_compile_options(datachannel PRIVATE -Wall -Wextra)
 	target_compile_options(datachannel-static PRIVATE -Wall -Wextra)
 endif()

+ 4 - 4
include/rtc/candidate.hpp

@@ -25,7 +25,7 @@
 
 namespace rtc {
 
-class Candidate {
+class RTC_CPP_EXPORT Candidate {
 public:
 	enum class Family { Unresolved, Ipv4, Ipv6 };
 	enum class Type { Unknown, Host, ServerReflexive, PeerReflexive, Relayed };
@@ -76,8 +76,8 @@ private:
 
 } // namespace rtc
 
-std::ostream &operator<<(std::ostream &out, const rtc::Candidate &candidate);
-std::ostream &operator<<(std::ostream &out, const rtc::Candidate::Type &type);
-std::ostream &operator<<(std::ostream &out, const rtc::Candidate::TransportType &transportType);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate &candidate);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate::Type &type);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate::TransportType &transportType);
 
 #endif

+ 1 - 1
include/rtc/channel.hpp

@@ -28,7 +28,7 @@
 
 namespace rtc {
 
-class Channel {
+class RTC_CPP_EXPORT Channel {
 public:
 	Channel() = default;
 	virtual ~Channel() = default;

+ 3 - 3
include/rtc/configuration.hpp

@@ -26,7 +26,7 @@
 
 namespace rtc {
 
-struct IceServer {
+struct RTC_CPP_EXPORT IceServer {
 	enum class Type { Stun, Turn };
 	enum class RelayType { TurnUdp, TurnTcp, TurnTls };
 
@@ -51,7 +51,7 @@ struct IceServer {
 	RelayType relayType;
 };
 
-struct ProxyServer {
+struct RTC_CPP_EXPORT ProxyServer {
 	enum class Type { None = 0, Socks5, Http, Last = Http };
 
 	ProxyServer(Type type_, string ip_, uint16_t port_, string username_ = "",
@@ -64,7 +64,7 @@ struct ProxyServer {
 	string password;
 };
 
-struct Configuration {
+struct RTC_CPP_EXPORT Configuration {
 	std::vector<IceServer> iceServers;
 	std::optional<ProxyServer> proxyServer;
 	bool enableIceTcp = false;

+ 2 - 2
include/rtc/datachannel.hpp

@@ -36,7 +36,7 @@ namespace rtc {
 class SctpTransport;
 class PeerConnection;
 
-class DataChannel : public std::enable_shared_from_this<DataChannel>, public Channel {
+class RTC_CPP_EXPORT DataChannel : public std::enable_shared_from_this<DataChannel>, public Channel {
 public:
 	DataChannel(std::weak_ptr<PeerConnection> pc, uint16_t stream, string label, string protocol,
 	            Reliability reliability);
@@ -87,7 +87,7 @@ private:
 	friend class PeerConnection;
 };
 
-class NegociatedDataChannel final : public DataChannel {
+class RTC_CPP_EXPORT NegociatedDataChannel final : public DataChannel {
 public:
 	NegociatedDataChannel(std::weak_ptr<PeerConnection> pc, uint16_t stream, string label,
 	                      string protocol, Reliability reliability);

+ 4 - 4
include/rtc/description.hpp

@@ -32,7 +32,7 @@
 
 namespace rtc {
 
-class Description {
+class RTC_CPP_EXPORT Description {
 public:
 	enum class Type { Unspec, Offer, Answer, Pranswer, Rollback };
 	enum class Role { ActPass, Passive, Active };
@@ -245,8 +245,8 @@ private:
 
 } // namespace rtc
 
-std::ostream &operator<<(std::ostream &out, const rtc::Description &description);
-std::ostream &operator<<(std::ostream &out, rtc::Description::Type type);
-std::ostream &operator<<(std::ostream &out, rtc::Description::Role role);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Description &description);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::Description::Type type);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::Description::Role role);
 
 #endif

+ 3 - 0
include/rtc/include.hpp

@@ -28,9 +28,12 @@
 #endif
 
 #ifdef _WIN32
+#define RTC_CPP_EXPORT __declspec(dllexport)
 #ifndef _WIN32_WINNT
 #define _WIN32_WINNT 0x0602 // Windows 8
 #endif
+#else
+#define RTC_CPP_EXPORT
 #endif
 
 #include "log.hpp"

+ 1 - 1
include/rtc/init.hpp

@@ -27,7 +27,7 @@ namespace rtc {
 
 using init_token = std::shared_ptr<void>;
 
-class Init {
+class RTC_CPP_EXPORT Init {
 public:
 	static init_token Token();
 	static void Preload();

+ 4 - 2
include/rtc/log.hpp

@@ -35,6 +35,8 @@
 #pragma warning(pop)
 #endif
 
+#include "include.hpp"
+
 namespace rtc {
 
 enum class LogLevel { // Don't change, it must match plog severity
@@ -47,8 +49,8 @@ enum class LogLevel { // Don't change, it must match plog severity
 	Verbose = 6
 };
 
-void InitLogger(LogLevel level);
-void InitLogger(plog::Severity severity, plog::IAppender *appender = nullptr);
+RTC_CPP_EXPORT void InitLogger(LogLevel level);
+RTC_CPP_EXPORT void InitLogger(plog::Severity severity, plog::IAppender *appender = nullptr);
 } // namespace rtc
 
 #endif

+ 1 - 1
include/rtc/message.hpp

@@ -29,7 +29,7 @@
 
 namespace rtc {
 
-struct Message : binary {
+struct RTC_CPP_EXPORT Message : binary {
 	enum Type { Binary, String, Control, Reset };
 
 	Message(const Message &message) = default;

+ 5 - 5
include/rtc/peerconnection.hpp

@@ -50,14 +50,14 @@ class SctpTransport;
 using certificate_ptr = std::shared_ptr<Certificate>;
 using future_certificate_ptr = std::shared_future<certificate_ptr>;
 
-struct DataChannelInit {
+struct RTC_CPP_EXPORT DataChannelInit {
 	Reliability reliability = {};
 	bool negotiated = false;
 	std::optional<uint16_t> id = nullopt;
 	string protocol = "";
 };
 
-class PeerConnection final : public std::enable_shared_from_this<PeerConnection> {
+class RTC_CPP_EXPORT PeerConnection final : public std::enable_shared_from_this<PeerConnection> {
 public:
 	enum class State : int {
 		New = RTC_NEW,
@@ -203,8 +203,8 @@ private:
 
 } // namespace rtc
 
-std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::State state);
-std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::GatheringState state);
-std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::SignalingState state);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::State state);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::GatheringState state);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::SignalingState state);
 
 #endif

+ 2 - 2
include/rtc/rtcp.hpp

@@ -29,7 +29,7 @@
 
 namespace rtc {
 
-class RtcpHandler {
+class RTC_CPP_EXPORT RtcpHandler {
 protected:
 	/**
 	 * Use this callback when trying to send custom data (such as RTCP) to the client.
@@ -64,7 +64,7 @@ public:
 class Track;
 
 // An RtcpSession can be plugged into a Track to handle the whole RTCP session
-class RtcpReceivingSession : public RtcpHandler {
+class RTC_CPP_EXPORT RtcpReceivingSession : public RtcpHandler {
 public:
 	rtc::message_ptr incoming(rtc::message_ptr ptr) override;
 	rtc::message_ptr outgoing(rtc::message_ptr ptr) override;

+ 1 - 1
include/rtc/track.hpp

@@ -35,7 +35,7 @@ namespace rtc {
 class DtlsSrtpTransport;
 #endif
 
-class Track final : public std::enable_shared_from_this<Track>, public Channel {
+class RTC_CPP_EXPORT Track final : public std::enable_shared_from_this<Track>, public Channel {
 public:
 	Track(Description::Media description);
 	~Track() = default;

+ 1 - 1
include/rtc/websocket.hpp

@@ -38,7 +38,7 @@ class TcpTransport;
 class TlsTransport;
 class WsTransport;
 
-class WebSocket final : public Channel, public std::enable_shared_from_this<WebSocket> {
+class RTC_CPP_EXPORT WebSocket final : public Channel, public std::enable_shared_from_this<WebSocket> {
 public:
 	enum class State : int {
 		Connecting = 0,