base: Add WebSocketSession

This commit is contained in:
tt2468 2021-04-27 14:52:04 -07:00
parent c4b27ed340
commit fb22b31612
2 changed files with 123 additions and 0 deletions

82
src/WebSocketSession.cpp Normal file
View File

@ -0,0 +1,82 @@
#include "WebSocketSession.h"
WebSocketSession::WebSocketSession() :
incomingMessages(0),
outgoingMessages(0),
rpcVersion(OBS_WEBSOCKET_RPC_VERSION),
isIdentified(false),
ignoreInvalidMessages(false),
ignoreNonFatalRequestChecks(false),
eventSubscriptions(0)
{
}
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::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);
}
bool WebSocketSession::IgnoreInvalidMessages()
{
return ignoreInvalidMessages.load();
}
void WebSocketSession::SetIgnoreInvalidMessages(bool ignore)
{
ignoreInvalidMessages.store(ignore);
}
bool WebSocketSession::IgnoreNonFatalRequestChecks()
{
return ignoreNonFatalRequestChecks.load();
}
void WebSocketSession::SetIgnoreNonFatalRequestChecks(bool ignore)
{
ignoreNonFatalRequestChecks.store(ignore);
}
uint64_t WebSocketSession::EventSubscriptions()
{
return eventSubscriptions.load();
}
void WebSocketSession::SetEventSubscriptions(uint64_t subscriptions)
{
eventSubscriptions.store(subscriptions);
}

41
src/WebSocketSession.h Normal file
View File

@ -0,0 +1,41 @@
#pragma once
#include <atomic>
#include "plugin-macros.generated.h"
class WebSocketSession
{
public:
WebSocketSession();
uint64_t IncomingMessages();
void IncrementIncomingMessages();
uint64_t OutgoingMessages();
void IncrementOutgoingMessages();
uint8_t RpcVersion();
void SetRpcVersion(uint8_t version);
bool IsIdentified();
void SetIsIdentified(bool identified);
bool IgnoreInvalidMessages();
void SetIgnoreInvalidMessages(bool ignore);
bool IgnoreNonFatalRequestChecks();
void SetIgnoreNonFatalRequestChecks(bool ignore);
uint64_t EventSubscriptions();
void SetEventSubscriptions(uint64_t subscriptions);
private:
std::atomic<uint64_t> incomingMessages;
std::atomic<uint64_t> outgoingMessages;
std::atomic<uint8_t> rpcVersion;
std::atomic<bool> isIdentified;
std::atomic<bool> ignoreInvalidMessages;
std::atomic<bool> ignoreNonFatalRequestChecks;
std::atomic<uint64_t> eventSubscriptions;
};