diff --git a/CMakeLists.txt b/CMakeLists.txt index 23f0d684..dfdc194c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,6 @@ target_sources( PRIVATE src/websocketserver/WebSocketServer.cpp src/websocketserver/WebSocketServer_Protocol.cpp src/websocketserver/WebSocketServer.h - src/websocketserver/rpc/WebSocketSession.cpp src/websocketserver/rpc/WebSocketSession.h src/websocketserver/types/WebSocketCloseCode.h src/websocketserver/types/WebSocketOpCode.h) diff --git a/cmake/legacy.cmake b/cmake/legacy.cmake index 4bcda73b..4790a084 100644 --- a/cmake/legacy.cmake +++ b/cmake/legacy.cmake @@ -67,7 +67,6 @@ target_sources( src/websocketserver/WebSocketServer.cpp src/websocketserver/WebSocketServer_Protocol.cpp src/websocketserver/WebSocketServer.h - src/websocketserver/rpc/WebSocketSession.cpp src/websocketserver/rpc/WebSocketSession.h src/websocketserver/types/WebSocketCloseCode.h src/websocketserver/types/WebSocketOpCode.h diff --git a/src/websocketserver/rpc/WebSocketSession.cpp b/src/websocketserver/rpc/WebSocketSession.cpp deleted file mode 100644 index e5e10314..00000000 --- a/src/websocketserver/rpc/WebSocketSession.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* -obs-websocket -Copyright (C) 2016-2021 Stephane Lepin -Copyright (C) 2020-2021 Kyle Manning - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see -*/ - -#include "WebSocketSession.h" -#include "../../eventhandler/types/EventSubscription.h" - -WebSocketSession::WebSocketSession() - : _remoteAddress(""), - _connectedAt(0), - _incomingMessages(0), - _outgoingMessages(0), - _encoding(0), - _challenge(""), - _rpcVersion(OBS_WEBSOCKET_RPC_VERSION), - _isIdentified(false), - _eventSubscriptions(EventSubscription::All) -{ -} - -std::string WebSocketSession::RemoteAddress() -{ - std::lock_guard lock(_remoteAddressMutex); - std::string ret(_remoteAddress); - return ret; -} - -void WebSocketSession::SetRemoteAddress(std::string address) -{ - std::lock_guard lock(_remoteAddressMutex); - _remoteAddress = address; -} - -uint64_t WebSocketSession::ConnectedAt() -{ - return _connectedAt.load(); -} - -void WebSocketSession::SetConnectedAt(uint64_t at) -{ - _connectedAt.store(at); -} - -uint64_t WebSocketSession::IncomingMessages() -{ - return _incomingMessages.load(); -} - -void WebSocketSession::IncrementIncomingMessages() -{ - _incomingMessages++; -} - -uint64_t WebSocketSession::OutgoingMessages() -{ - return _outgoingMessages.load(); -} - -void WebSocketSession::IncrementOutgoingMessages() -{ - _outgoingMessages++; -} - -uint8_t WebSocketSession::Encoding() -{ - return _encoding.load(); -} - -void WebSocketSession::SetEncoding(uint8_t encoding) -{ - _encoding.store(encoding); -} - -bool WebSocketSession::AuthenticationRequired() -{ - return _authenticationRequired.load(); -} - -void WebSocketSession::SetAuthenticationRequired(bool required) -{ - _authenticationRequired.store(required); -} - -std::string WebSocketSession::Secret() -{ - std::lock_guard lock(_secretMutex); - std::string ret(_secret); - return ret; -} - -void WebSocketSession::SetSecret(std::string secret) -{ - std::lock_guard lock(_secretMutex); - _secret = secret; -} - -std::string WebSocketSession::Challenge() -{ - std::lock_guard lock(_challengeMutex); - std::string ret(_challenge); - return ret; -} - -void WebSocketSession::SetChallenge(std::string challengeString) -{ - std::lock_guard lock(_challengeMutex); - _challenge = challengeString; -} - -uint8_t WebSocketSession::RpcVersion() -{ - return _rpcVersion.load(); -} - -void WebSocketSession::SetRpcVersion(uint8_t version) -{ - _rpcVersion.store(version); -} - -bool WebSocketSession::IsIdentified() -{ - return _isIdentified.load(); -} - -void WebSocketSession::SetIsIdentified(bool identified) -{ - _isIdentified.store(identified); -} - -uint64_t WebSocketSession::EventSubscriptions() -{ - return _eventSubscriptions.load(); -} - -void WebSocketSession::SetEventSubscriptions(uint64_t subscriptions) -{ - _eventSubscriptions.store(subscriptions); -} diff --git a/src/websocketserver/rpc/WebSocketSession.h b/src/websocketserver/rpc/WebSocketSession.h index eecf8795..8e328641 100644 --- a/src/websocketserver/rpc/WebSocketSession.h +++ b/src/websocketserver/rpc/WebSocketSession.h @@ -24,6 +24,7 @@ with this program. If not, see #include #include +#include "../../eventhandler/types/EventSubscription.h" #include "plugin-macros.generated.h" class WebSocketSession; @@ -31,56 +32,78 @@ typedef std::shared_ptr SessionPtr; class WebSocketSession { public: - WebSocketSession(); + inline std::string RemoteAddress() + { + std::lock_guard lock(_remoteAddressMutex); + return _remoteAddress; + } + inline void SetRemoteAddress(std::string address) + { + std::lock_guard lock(_remoteAddressMutex); + _remoteAddress = address; + } - std::string RemoteAddress(); - void SetRemoteAddress(std::string address); + inline uint64_t ConnectedAt() { return _connectedAt; } + inline void SetConnectedAt(uint64_t at) { _connectedAt = at; } - uint64_t ConnectedAt(); - void SetConnectedAt(uint64_t at); + inline uint64_t IncomingMessages() { return _incomingMessages; } + inline void IncrementIncomingMessages() { _incomingMessages++; } - uint64_t IncomingMessages(); - void IncrementIncomingMessages(); + inline uint64_t OutgoingMessages() { return _outgoingMessages; } + inline void IncrementOutgoingMessages() { _outgoingMessages++; } - uint64_t OutgoingMessages(); - void IncrementOutgoingMessages(); + inline uint8_t Encoding() { return _encoding; } + inline void SetEncoding(uint8_t encoding) { _encoding = encoding; } - uint8_t Encoding(); - void SetEncoding(uint8_t encoding); + inline bool AuthenticationRequired() { return _authenticationRequired; } + inline void SetAuthenticationRequired(bool required) { _authenticationRequired = required; } - bool AuthenticationRequired(); - void SetAuthenticationRequired(bool required); + inline std::string Secret() + { + std::lock_guard lock(_secretMutex); + return _secret; + } + inline void SetSecret(std::string secret) + { + std::lock_guard lock(_secretMutex); + _secret = secret; + } - std::string Secret(); - void SetSecret(std::string secret); + inline std::string Challenge() + { + std::lock_guard lock(_challengeMutex); + return _challenge; + } + inline void SetChallenge(std::string challenge) + { + std::lock_guard lock(_challengeMutex); + _challenge = challenge; + } - std::string Challenge(); - void SetChallenge(std::string challenge); + inline uint8_t RpcVersion() { return _rpcVersion; } + inline void SetRpcVersion(uint8_t version) { _rpcVersion = version; } - uint8_t RpcVersion(); - void SetRpcVersion(uint8_t version); + inline bool IsIdentified() { return _isIdentified; } + inline void SetIsIdentified(bool identified) { _isIdentified = identified; } - bool IsIdentified(); - void SetIsIdentified(bool identified); - - uint64_t EventSubscriptions(); - void SetEventSubscriptions(uint64_t subscriptions); + inline uint64_t EventSubscriptions() { return _eventSubscriptions; } + inline void SetEventSubscriptions(uint64_t subscriptions) { _eventSubscriptions = subscriptions; } std::mutex OperationMutex; private: std::mutex _remoteAddressMutex; std::string _remoteAddress; - std::atomic _connectedAt; - std::atomic _incomingMessages; - std::atomic _outgoingMessages; - std::atomic _encoding; - std::atomic _authenticationRequired; + std::atomic _connectedAt = 0; + std::atomic _incomingMessages = 0; + std::atomic _outgoingMessages = 0; + std::atomic _encoding = 0; + std::atomic _authenticationRequired = false; std::mutex _secretMutex; std::string _secret; std::mutex _challengeMutex; std::string _challenge; - std::atomic _rpcVersion; - std::atomic _isIdentified; - std::atomic _eventSubscriptions; + std::atomic _rpcVersion = OBS_WEBSOCKET_RPC_VERSION; + std::atomic _isIdentified = false; + std::atomic _eventSubscriptions = EventSubscription::All; };