From 386ef3ab04990eaebf64bc9fa57b41e7724bdfa8 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 15 Apr 2020 16:59:17 -0700 Subject: [PATCH] (ixcobra) make CobraConnection_EventType an enum class (CobraEventType) --- docs/CHANGELOG.md | 4 +++ ixbots/ixbots/IXCobraToSentryBot.cpp | 24 +++++++++--------- ixbots/ixbots/IXCobraToStatsdBot.cpp | 24 +++++++++--------- ixcobra/CMakeLists.txt | 2 ++ ixcobra/ixcobra/IXCobraConnection.cpp | 24 +++++++++--------- ixcobra/ixcobra/IXCobraConnection.h | 20 +++------------ ixcobra/ixcobra/IXCobraEventType.h | 25 +++++++++++++++++++ .../IXCobraMetricsThreadedPublisher.cpp | 18 ++++++------- ixwebsocket/IXWebSocketVersion.h | 2 +- test/IXCobraChatTest.cpp | 18 ++++++------- test/IXCobraMetricsPublisherTest.cpp | 14 +++++------ ws/ws_cobra_metrics_to_redis.cpp | 14 +++++------ ws/ws_cobra_publish.cpp | 16 ++++++------ ws/ws_cobra_subscribe.cpp | 22 ++++++++-------- 14 files changed, 122 insertions(+), 105 deletions(-) create mode 100644 ixcobra/ixcobra/IXCobraEventType.h diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ae7c440f..29c5fb8e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [9.2.8] - 2020-04-15 + +(ixcobra) make CobraConnection_EventType an enum class (CobraEventType) + ## [9.2.7] - 2020-04-14 (ixsentry) add a library method to upload a payload directly to sentry diff --git a/ixbots/ixbots/IXCobraToSentryBot.cpp b/ixbots/ixbots/IXCobraToSentryBot.cpp index 5eed276d..a2021e2e 100644 --- a/ixbots/ixbots/IXCobraToSentryBot.cpp +++ b/ixbots/ixbots/IXCobraToSentryBot.cpp @@ -181,12 +181,12 @@ namespace ix &throttled, &receivedCount, &fatalCobraError, - &queueManager](ix::CobraConnectionEventType eventType, + &queueManager](ix::CobraEventType eventType, const std::string& errMsg, const ix::WebSocketHttpHeaders& headers, const std::string& subscriptionId, CobraConnection::MsgId msgId) { - if (eventType == ix::CobraConnection_EventType_Open) + if (eventType == ix::CobraEventType::Open) { spdlog::info("Subscriber connected"); @@ -195,11 +195,11 @@ namespace ix spdlog::info("{}: {}", it.first, it.second); } } - if (eventType == ix::CobraConnection_EventType_Closed) + if (eventType == ix::CobraEventType::Closed) { spdlog::info("Subscriber closed"); } - else if (eventType == ix::CobraConnection_EventType_Authenticated) + else if (eventType == ix::CobraEventType::Authenticated) { spdlog::info("Subscriber authenticated"); conn.subscribe(channel, @@ -222,37 +222,37 @@ namespace ix queueManager.add(msg); }); } - else if (eventType == ix::CobraConnection_EventType_Subscribed) + else if (eventType == ix::CobraEventType::Subscribed) { spdlog::info("Subscriber: subscribed to channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_UnSubscribed) + else if (eventType == ix::CobraEventType::UnSubscribed) { spdlog::info("Subscriber: unsubscribed from channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_Error) + else if (eventType == ix::CobraEventType::Error) { spdlog::error("Subscriber: error {}", errMsg); } - else if (eventType == ix::CobraConnection_EventType_Published) + else if (eventType == ix::CobraEventType::Published) { spdlog::error("Published message hacked: {}", msgId); } - else if (eventType == ix::CobraConnection_EventType_Pong) + else if (eventType == ix::CobraEventType::Pong) { spdlog::info("Received websocket pong"); } - else if (eventType == ix::CobraConnection_EventType_Handshake_Error) + else if (eventType == ix::CobraEventType::HandshakeError) { spdlog::error("Subscriber: Handshake error: {}", errMsg); fatalCobraError = true; } - else if (eventType == ix::CobraConnection_EventType_Authentication_Error) + else if (eventType == ix::CobraEventType::AuthenticationError) { spdlog::error("Subscriber: Authentication error: {}", errMsg); fatalCobraError = true; } - else if (eventType == ix::CobraConnection_EventType_Subscription_Error) + else if (eventType == ix::CobraEventType::SubscriptionError) { spdlog::error("Subscriber: Subscription error: {}", errMsg); fatalCobraError = true; diff --git a/ixbots/ixbots/IXCobraToStatsdBot.cpp b/ixbots/ixbots/IXCobraToStatsdBot.cpp index b5ab9ccf..f58c473c 100644 --- a/ixbots/ixbots/IXCobraToStatsdBot.cpp +++ b/ixbots/ixbots/IXCobraToStatsdBot.cpp @@ -202,12 +202,12 @@ namespace ix conn.setEventCallback( [&conn, &channel, &filter, &position, &jsonWriter, verbose, &queueManager, &receivedCount, &fatalCobraError]( - ix::CobraConnectionEventType eventType, + ix::CobraEventType eventType, const std::string& errMsg, const ix::WebSocketHttpHeaders& headers, const std::string& subscriptionId, CobraConnection::MsgId msgId) { - if (eventType == ix::CobraConnection_EventType_Open) + if (eventType == ix::CobraEventType::Open) { spdlog::info("Subscriber connected"); @@ -216,11 +216,11 @@ namespace ix spdlog::info("{}: {}", it.first, it.second); } } - if (eventType == ix::CobraConnection_EventType_Closed) + if (eventType == ix::CobraEventType::Closed) { spdlog::info("Subscriber closed"); } - else if (eventType == ix::CobraConnection_EventType_Authenticated) + else if (eventType == ix::CobraEventType::Authenticated) { spdlog::info("Subscriber authenticated"); conn.subscribe(channel, @@ -239,37 +239,37 @@ namespace ix queueManager.add(msg); }); } - else if (eventType == ix::CobraConnection_EventType_Subscribed) + else if (eventType == ix::CobraEventType::Subscribed) { spdlog::info("Subscriber: subscribed to channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_UnSubscribed) + else if (eventType == ix::CobraEventType::UnSubscribed) { spdlog::info("Subscriber: unsubscribed from channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_Error) + else if (eventType == ix::CobraEventType::Error) { spdlog::error("Subscriber: error {}", errMsg); } - else if (eventType == ix::CobraConnection_EventType_Published) + else if (eventType == ix::CobraEventType::Published) { spdlog::error("Published message hacked: {}", msgId); } - else if (eventType == ix::CobraConnection_EventType_Pong) + else if (eventType == ix::CobraEventType::Pong) { spdlog::info("Received websocket pong"); } - else if (eventType == ix::CobraConnection_EventType_Handshake_Error) + else if (eventType == ix::CobraEventType::HandshakeError) { spdlog::error("Subscriber: Handshake error: {}", errMsg); fatalCobraError = true; } - else if (eventType == ix::CobraConnection_EventType_Authentication_Error) + else if (eventType == ix::CobraEventType::AuthenticationError) { spdlog::error("Subscriber: Authentication error: {}", errMsg); fatalCobraError = true; } - else if (eventType == ix::CobraConnection_EventType_Subscription_Error) + else if (eventType == ix::CobraEventType::SubscriptionError) { spdlog::error("Subscriber: Subscription error: {}", errMsg); fatalCobraError = true; diff --git a/ixcobra/CMakeLists.txt b/ixcobra/CMakeLists.txt index df802f01..c6a0b307 100644 --- a/ixcobra/CMakeLists.txt +++ b/ixcobra/CMakeLists.txt @@ -14,6 +14,8 @@ set (IXCOBRA_HEADERS ixcobra/IXCobraMetricsThreadedPublisher.h ixcobra/IXCobraMetricsPublisher.h ixcobra/IXCobraConfig.h + ixcobra/IXCobraEvent.h + ixcobra/IXCobraEventType.h ) add_library(ixcobra STATIC diff --git a/ixcobra/ixcobra/IXCobraConnection.cpp b/ixcobra/ixcobra/IXCobraConnection.cpp index 049a4d62..ceb62995 100644 --- a/ixcobra/ixcobra/IXCobraConnection.cpp +++ b/ixcobra/ixcobra/IXCobraConnection.cpp @@ -87,7 +87,7 @@ namespace ix _eventCallback = eventCallback; } - void CobraConnection::invokeEventCallback(ix::CobraConnectionEventType eventType, + void CobraConnection::invokeEventCallback(ix::CobraEventType eventType, const std::string& errorMsg, const WebSocketHttpHeaders& headers, const std::string& subscriptionId, @@ -105,7 +105,7 @@ namespace ix { std::stringstream ss; ss << errorMsg << " : received pdu => " << serializedPdu; - invokeEventCallback(ix::CobraConnection_EventType_Error, ss.str()); + invokeEventCallback(ix::CobraEventType::Error, ss.str()); } void CobraConnection::disconnect() @@ -124,7 +124,7 @@ namespace ix std::stringstream ss; if (msg->type == ix::WebSocketMessageType::Open) { - invokeEventCallback(ix::CobraConnection_EventType_Open, + invokeEventCallback(ix::CobraEventType::Open, std::string(), msg->openInfo.headers); sendHandshakeMessage(); @@ -136,7 +136,7 @@ namespace ix std::stringstream ss; ss << "Close code " << msg->closeInfo.code; ss << " reason " << msg->closeInfo.reason; - invokeEventCallback(ix::CobraConnection_EventType_Closed, + invokeEventCallback(ix::CobraEventType::Closed, ss.str()); } else if (msg->type == ix::WebSocketMessageType::Message) @@ -166,18 +166,18 @@ namespace ix } else if (action == "auth/handshake/error") { - invokeEventCallback(ix::CobraConnection_EventType_Handshake_Error, + invokeEventCallback(ix::CobraEventType::HandshakeError, msg->str); } else if (action == "auth/authenticate/ok") { _authenticated = true; - invokeEventCallback(ix::CobraConnection_EventType_Authenticated); + invokeEventCallback(ix::CobraEventType::Authenticated); flushQueue(); } else if (action == "auth/authenticate/error") { - invokeEventCallback(ix::CobraConnection_EventType_Authentication_Error, + invokeEventCallback(ix::CobraEventType::AuthenticationError, msg->str); } else if (action == "rtm/subscription/data") @@ -193,7 +193,7 @@ namespace ix } else if (action == "rtm/subscribe/error") { - invokeEventCallback(ix::CobraConnection_EventType_Subscription_Error, + invokeEventCallback(ix::CobraEventType::SubscriptionError, msg->str); } else if (action == "rtm/unsubscribe/ok") @@ -234,7 +234,7 @@ namespace ix } else if (msg->type == ix::WebSocketMessageType::Pong) { - invokeEventCallback(ix::CobraConnection_EventType_Pong); + invokeEventCallback(ix::CobraEventType::Pong); } }); } @@ -396,7 +396,7 @@ namespace ix if (!subscriptionId.isString()) return false; - invokeEventCallback(ix::CobraConnection_EventType_Subscribed, + invokeEventCallback(ix::CobraEventType::Subscribed, std::string(), WebSocketHttpHeaders(), subscriptionId.asString()); return true; @@ -414,7 +414,7 @@ namespace ix if (!subscriptionId.isString()) return false; - invokeEventCallback(ix::CobraConnection_EventType_UnSubscribed, + invokeEventCallback(ix::CobraEventType::UnSubscribed, std::string(), WebSocketHttpHeaders(), subscriptionId.asString()); return true; @@ -462,7 +462,7 @@ namespace ix uint64_t msgId = id.asUInt64(); - invokeEventCallback(ix::CobraConnection_EventType_Published, + invokeEventCallback(ix::CobraEventType::Published, std::string(), WebSocketHttpHeaders(), std::string(), msgId); diff --git a/ixcobra/ixcobra/IXCobraConnection.h b/ixcobra/ixcobra/IXCobraConnection.h index 7be0e112..0e9eda1a 100644 --- a/ixcobra/ixcobra/IXCobraConnection.h +++ b/ixcobra/ixcobra/IXCobraConnection.h @@ -8,6 +8,7 @@ #include #include +#include "IXCobraEventType.h" #include #include #include @@ -28,21 +29,6 @@ namespace ix class WebSocket; struct SocketTLSOptions; - enum CobraConnectionEventType - { - CobraConnection_EventType_Authenticated = 0, - CobraConnection_EventType_Error = 1, - CobraConnection_EventType_Open = 2, - CobraConnection_EventType_Closed = 3, - CobraConnection_EventType_Subscribed = 4, - CobraConnection_EventType_UnSubscribed = 5, - CobraConnection_EventType_Published = 6, - CobraConnection_EventType_Pong = 7, - CobraConnection_EventType_Handshake_Error = 8, - CobraConnection_EventType_Authentication_Error = 9, - CobraConnection_EventType_Subscription_Error = 10 - }; - enum CobraConnectionPublishMode { CobraConnection_PublishMode_Immediate = 0, @@ -50,7 +36,7 @@ namespace ix }; using SubscriptionCallback = std::function; - using EventCallback = std::function messageAcked(false); conn.setEventCallback([&conn, &channel, &data, &authenticated, &messageAcked]( - ix::CobraConnectionEventType eventType, + ix::CobraEventType eventType, const std::string& errMsg, const ix::WebSocketHttpHeaders& headers, const std::string& subscriptionId, CobraConnection::MsgId msgId) { - if (eventType == ix::CobraConnection_EventType_Open) + if (eventType == ix::CobraEventType::Open) { spdlog::info("Publisher connected"); @@ -53,7 +53,7 @@ namespace ix spdlog::info("{}: {}", it.first, it.second); } } - else if (eventType == ix::CobraConnection_EventType_Authenticated) + else if (eventType == ix::CobraEventType::Authenticated) { spdlog::info("Publisher authenticated"); authenticated = true; @@ -64,24 +64,24 @@ namespace ix spdlog::info("Published msg {}", msgId); } - else if (eventType == ix::CobraConnection_EventType_Subscribed) + else if (eventType == ix::CobraEventType::Subscribed) { spdlog::info("Publisher: subscribed to channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_UnSubscribed) + else if (eventType == ix::CobraEventType::UnSubscribed) { spdlog::info("Publisher: unsubscribed from channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_Error) + else if (eventType == ix::CobraEventType::Error) { spdlog::error("Publisher: error {}", errMsg); } - else if (eventType == ix::CobraConnection_EventType_Published) + else if (eventType == ix::CobraEventType::Published) { spdlog::info("Published message id {} acked", msgId); messageAcked = true; } - else if (eventType == ix::CobraConnection_EventType_Pong) + else if (eventType == ix::CobraEventType::Pong) { spdlog::info("Received websocket pong"); } diff --git a/ws/ws_cobra_subscribe.cpp b/ws/ws_cobra_subscribe.cpp index 00a3e2db..f60e7da4 100644 --- a/ws/ws_cobra_subscribe.cpp +++ b/ws/ws_cobra_subscribe.cpp @@ -106,12 +106,12 @@ namespace ix &msgPerSeconds, &quiet, &fluentd, - &fatalCobraError](ix::CobraConnectionEventType eventType, + &fatalCobraError](ix::CobraEventType eventType, const std::string& errMsg, const ix::WebSocketHttpHeaders& headers, const std::string& subscriptionId, CobraConnection::MsgId msgId) { - if (eventType == ix::CobraConnection_EventType_Open) + if (eventType == ix::CobraEventType::Open) { spdlog::info("Subscriber connected"); @@ -120,7 +120,7 @@ namespace ix spdlog::info("{}: {}", it.first, it.second); } } - else if (eventType == ix::CobraConnection_EventType_Authenticated) + else if (eventType == ix::CobraEventType::Authenticated) { spdlog::info("Subscriber authenticated"); spdlog::info("Subscribing to {} at position {}", channel, subscriptionPosition); @@ -145,37 +145,37 @@ namespace ix subscriptionPosition = position; }); } - else if (eventType == ix::CobraConnection_EventType_Subscribed) + else if (eventType == ix::CobraEventType::Subscribed) { spdlog::info("Subscriber: subscribed to channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_UnSubscribed) + else if (eventType == ix::CobraEventType::UnSubscribed) { spdlog::info("Subscriber: unsubscribed from channel {}", subscriptionId); } - else if (eventType == ix::CobraConnection_EventType_Error) + else if (eventType == ix::CobraEventType::Error) { spdlog::error("Subscriber: error {}", errMsg); } - else if (eventType == ix::CobraConnection_EventType_Published) + else if (eventType == ix::CobraEventType::Published) { spdlog::error("Published message hacked: {}", msgId); } - else if (eventType == ix::CobraConnection_EventType_Pong) + else if (eventType == ix::CobraEventType::Pong) { spdlog::info("Received websocket pong"); } - else if (eventType == ix::CobraConnection_EventType_Handshake_Error) + else if (eventType == ix::CobraEventType::HandshakeError) { spdlog::error("Subscriber: Handshake error: {}", errMsg); fatalCobraError = true; } - else if (eventType == ix::CobraConnection_EventType_Authentication_Error) + else if (eventType == ix::CobraEventType::AuthenticationError) { spdlog::error("Subscriber: Authentication error: {}", errMsg); fatalCobraError = true; } - else if (eventType == ix::CobraConnection_EventType_Subscription_Error) + else if (eventType == ix::CobraEventType::SubscriptionError) { spdlog::error("Subscriber: Subscription error: {}", errMsg); fatalCobraError = true;