Browse Source

Reorganized includes to hide Init implementation

Paul-Louis Ageneau 4 năm trước cách đây
mục cha
commit
0fddf50245

+ 5 - 2
CMakeLists.txt

@@ -43,7 +43,7 @@ set(LIBDATACHANNEL_SOURCES
 	${CMAKE_CURRENT_SOURCE_DIR}/src/configuration.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/datachannel.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/description.cpp
-	${CMAKE_CURRENT_SOURCE_DIR}/src/init.cpp
+	${CMAKE_CURRENT_SOURCE_DIR}/src/global.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/log.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/message.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/peerconnection.cpp
@@ -75,7 +75,7 @@ set(LIBDATACHANNEL_HEADERS
 	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediahandler.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpreceivingsession.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/common.hpp
-	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/init.hpp
+	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/global.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/log.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/message.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/peerconnection.hpp
@@ -107,6 +107,7 @@ set(LIBDATACHANNEL_IMPL_SOURCES
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlssrtptransport.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlstransport.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/icetransport.cpp
+	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/init.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/peerconnection.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/logcounter.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/sctptransport.cpp
@@ -129,6 +130,8 @@ set(LIBDATACHANNEL_IMPL_HEADERS
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlssrtptransport.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/dtlstransport.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/icetransport.hpp
+	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/init.hpp
+	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/internals.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/peerconnection.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/queue.hpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/impl/logcounter.hpp

+ 44 - 0
include/rtc/global.hpp

@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2020-2021 Paul-Louis Ageneau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef RTC_GLOBAL_H
+#define RTC_GLOBAL_H
+
+#include "common.hpp"
+
+#include <chrono>
+
+namespace rtc {
+
+RTC_EXPORT void Preload();
+RTC_EXPORT void Cleanup();
+
+struct SctpSettings {
+	optional<size_t> recvBufferSize;
+	optional<size_t> sendBufferSize;
+	optional<size_t> maxChunksOnQueue;
+	optional<size_t> initialCongestionWindow;
+	optional<unsigned int> congestionControlModule;
+	optional<std::chrono::milliseconds> delayedSackTime;
+};
+
+RTC_EXPORT void SetSctpSettings(SctpSettings s);
+
+} // namespace rtc
+
+#endif

+ 0 - 1
include/rtc/peerconnection.hpp

@@ -24,7 +24,6 @@
 #include "datachannel.hpp"
 #include "description.hpp"
 #include "common.hpp"
-#include "init.hpp"
 #include "message.hpp"
 #include "reliability.hpp"
 #include "track.hpp"

+ 4 - 5
include/rtc/rtc.hpp

@@ -21,12 +21,12 @@
 
 // C++ API
 #include "common.hpp"
-#include "init.hpp" // for rtc::Cleanup()
+#include "global.hpp"
 #include "log.hpp"
 //
 #include "datachannel.hpp"
-#include "track.hpp"
 #include "peerconnection.hpp"
+#include "track.hpp"
 
 #if RTC_ENABLE_WEBSOCKET
 
@@ -38,14 +38,13 @@
 #if RTC_ENABLE_MEDIA
 
 // Media handling
-#include "rtcpreceivingsession.hpp"
 #include "mediachainablehandler.hpp"
-#include "rtcpsrreporter.hpp"
 #include "rtcpnackresponder.hpp"
+#include "rtcpreceivingsession.hpp"
+#include "rtcpsrreporter.hpp"
 
 // Opus/h264 streaming
 #include "h264packetizationhandler.hpp"
 #include "opuspacketizationhandler.hpp"
 
 #endif // RTC_ENABLE_MEDIA
-

+ 2 - 1
src/candidate.cpp

@@ -17,7 +17,8 @@
  */
 
 #include "candidate.hpp"
-#include "globals.hpp"
+
+#include "impl/internals.hpp"
 
 #include <algorithm>
 #include <array>

+ 1 - 1
src/channel.cpp

@@ -17,8 +17,8 @@
  */
 
 #include "channel.hpp"
-#include "globals.hpp"
 
+#include "impl/internals.hpp"
 #include "impl/channel.hpp"
 
 namespace rtc {

+ 1 - 1
src/datachannel.cpp

@@ -17,11 +17,11 @@
  */
 
 #include "datachannel.hpp"
-#include "globals.hpp"
 #include "common.hpp"
 #include "peerconnection.hpp"
 
 #include "impl/datachannel.hpp"
+#include "impl/internals.hpp"
 #include "impl/peerconnection.hpp"
 
 #ifdef _WIN32

+ 31 - 0
src/global.cpp

@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2020-2021 Paul-Louis Ageneau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "global.hpp"
+
+#include "impl/init.hpp"
+
+namespace rtc {
+
+void Preload() { Init::Preload(); }
+void Cleanup() { Init::Cleanup(); }
+
+void SetSctpSettings(SctpSettings s) { Init::SetSctpSettings(std::move(s)); }
+
+} // namespace rtc
+

+ 1 - 1
src/impl/datachannel.cpp

@@ -18,7 +18,7 @@
 
 #include "datachannel.hpp"
 #include "common.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 #include "logcounter.hpp"
 #include "peerconnection.hpp"
 #include "sctptransport.hpp"

+ 1 - 1
src/impl/dtlstransport.cpp

@@ -17,7 +17,7 @@
  */
 
 #include "dtlstransport.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 #include "icetransport.hpp"
 
 #include <chrono>

+ 1 - 1
src/impl/icetransport.cpp

@@ -18,7 +18,7 @@
 
 #include "icetransport.hpp"
 #include "configuration.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 #include "transport.hpp"
 
 #include <iostream>

+ 6 - 5
src/init.cpp → src/impl/init.cpp

@@ -17,7 +17,7 @@
  */
 
 #include "init.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 
 #include "impl/certificate.hpp"
 #include "impl/dtlstransport.hpp"
@@ -42,7 +42,6 @@ namespace rtc {
 namespace {
 
 void doInit() {
-	PLOG_DEBUG << "Global initialization";
 
 #ifdef _WIN32
 	WSADATA wsaData;
@@ -69,8 +68,6 @@ void doInit() {
 }
 
 void doCleanup() {
-	PLOG_DEBUG << "Global cleanup";
-
 	impl::ThreadPool::Instance().join();
 
 	impl::SctpTransport::Cleanup();
@@ -129,6 +126,7 @@ void Init::SetSctpSettings(SctpSettings s) {
 Init::Init() {
 	// Mutex is locked by Token() here
 	if (!std::exchange(Initialized, true)) {
+		PLOG_DEBUG << "Global initialization";
 		doInit();
 		impl::SctpTransport::SetSettings(CurrentSctpSettings);
 	}
@@ -140,8 +138,11 @@ Init::~Init() {
 		std::unique_lock lock(Mutex);
 		if (Global)
 			return;
-		if (std::exchange(Initialized, false))
+
+		if (std::exchange(Initialized, false)) {
+			PLOG_DEBUG << "Global cleanup";
 			doCleanup();
+		}
 	});
 	t.detach();
 }

+ 4 - 16
include/rtc/init.hpp → src/impl/init.hpp

@@ -16,10 +16,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef RTC_INIT_H
-#define RTC_INIT_H
+#ifndef RTC_IMPL_INIT_H
+#define RTC_IMPL_INIT_H
 
 #include "common.hpp"
+#include "global.hpp" // for SctpSettings
 
 #include <chrono>
 #include <mutex>
@@ -28,16 +29,7 @@ namespace rtc {
 
 using init_token = shared_ptr<void>;
 
-struct SctpSettings {
-	optional<size_t> recvBufferSize;
-	optional<size_t> sendBufferSize;
-	optional<size_t> maxChunksOnQueue;
-	optional<size_t> initialCongestionWindow;
-	optional<unsigned int> congestionControlModule;
-	optional<std::chrono::milliseconds> delayedSackTime;
-};
-
-class RTC_CPP_EXPORT Init {
+class Init {
 public:
 	static init_token Token();
 	static void Preload();
@@ -56,10 +48,6 @@ private:
 	static std::recursive_mutex Mutex;
 };
 
-inline void Preload() { Init::Preload(); }
-inline void Cleanup() { Init::Cleanup(); }
-inline void SetSctpSettings(SctpSettings s) { Init::SetSctpSettings(std::move(s)); }
-
 } // namespace rtc
 
 #endif

+ 3 - 3
src/globals.hpp → src/impl/internals.hpp

@@ -16,8 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef RTC_GLOBALS_H
-#define RTC_GLOBALS_H
+#ifndef RTC_IMPL_INTERNALS_H
+#define RTC_IMPL_INTERNALS_H
 
 #include "common.hpp"
 
@@ -26,7 +26,7 @@ namespace rtc {
 const size_t MAX_NUMERICNODE_LEN = 48; // Max IPv6 string representation length
 const size_t MAX_NUMERICSERV_LEN = 6;  // Max port string representation length
 
-const uint16_t DEFAULT_SCTP_PORT = 5000;                  // SCTP port to use by default
+const uint16_t DEFAULT_SCTP_PORT = 5000; // SCTP port to use by default
 
 const size_t DEFAULT_LOCAL_MAX_MESSAGE_SIZE = 256 * 1024; // Default local max message size
 const size_t DEFAULT_MAX_MESSAGE_SIZE = 65536; // Remote max message size if not specified in SDP

+ 1 - 1
src/impl/peerconnection.cpp

@@ -21,7 +21,7 @@
 #include "certificate.hpp"
 #include "common.hpp"
 #include "dtlstransport.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 #include "icetransport.hpp"
 #include "logcounter.hpp"
 #include "peerconnection.hpp"

+ 1 - 1
src/impl/sctptransport.cpp

@@ -18,7 +18,7 @@
 
 #include "sctptransport.hpp"
 #include "dtlstransport.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 #include "logcounter.hpp"
 
 #include <chrono>

+ 1 - 1
src/impl/tcptransport.cpp

@@ -17,7 +17,7 @@
  */
 
 #include "tcptransport.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 
 #if RTC_ENABLE_WEBSOCKET
 

+ 1 - 1
src/impl/track.cpp

@@ -17,7 +17,7 @@
  */
 
 #include "track.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 #include "logcounter.hpp"
 #include "peerconnection.hpp"
 

+ 1 - 1
src/impl/websocket.cpp

@@ -19,7 +19,7 @@
 #if RTC_ENABLE_WEBSOCKET
 
 #include "websocket.hpp"
-#include "globals.hpp"
+#include "internals.hpp"
 #include "common.hpp"
 #include "threadpool.hpp"
 

+ 2 - 1
src/nalunit.cpp

@@ -19,7 +19,8 @@
 #if RTC_ENABLE_MEDIA
 
 #include "nalunit.hpp"
-#include "globals.hpp"
+
+#include "impl/internals.hpp"
 
 #include <cmath>
 

+ 2 - 4
src/track.cpp

@@ -17,8 +17,8 @@
  */
 
 #include "track.hpp"
-#include "globals.hpp"
 
+#include "impl/internals.hpp"
 #include "impl/track.hpp"
 
 namespace rtc {
@@ -46,9 +46,7 @@ bool Track::isOpen(void) const { return impl()->isOpen(); }
 
 bool Track::isClosed(void) const { return impl()->isClosed(); }
 
-size_t Track::maxMessageSize() const {
-	return impl()->maxMessageSize();
-}
+size_t Track::maxMessageSize() const { return impl()->maxMessageSize(); }
 
 void Track::setMediaHandler(shared_ptr<MediaHandler> handler) {
 	impl()->setMediaHandler(std::move(handler));

+ 1 - 1
src/websocket.cpp

@@ -19,10 +19,10 @@
 #if RTC_ENABLE_WEBSOCKET
 
 #include "websocket.hpp"
-#include "globals.hpp"
 #include "common.hpp"
 
 #include "impl/websocket.hpp"
+#include "impl/internals.hpp"
 
 #include <regex>