From fc917fca7dcc8542ad053eb20a49598af4cf3983 Mon Sep 17 00:00:00 2001 From: Matthias Larisch Date: Mon, 30 Nov 2015 23:42:37 +0100 Subject: [PATCH] Forgot MumbleChannelJoiner component --- MumbleChannelJoiner.cpp | 25 +++++++++++++++++++++++++ MumbleChannelJoiner.hpp | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 MumbleChannelJoiner.cpp create mode 100644 MumbleChannelJoiner.hpp diff --git a/MumbleChannelJoiner.cpp b/MumbleChannelJoiner.cpp new file mode 100644 index 0000000..30ad1b1 --- /dev/null +++ b/MumbleChannelJoiner.cpp @@ -0,0 +1,25 @@ +#include "MumbleChannelJoiner.hpp" + +#include +using namespace std; + +mumble::MumbleChannelJoiner::MumbleChannelJoiner(std::string channelNameRegex) : channelNameRegex(boost::regex(channelNameRegex)), +logger(log4cpp::Category::getInstance("MumbleChannelJoiner")){ +} + +void mumble::MumbleChannelJoiner::checkChannel(std::string channel_name, int channel_id) { + boost::smatch s; + logger.debug("Channel %s available (%d)", channel_name.c_str(), channel_id); + + + if(boost::regex_match(channel_name, s, channelNameRegex)) { + this->channel_id = channel_id; + } +} + +void mumble::MumbleChannelJoiner::maybeJoinChannel(mumble::MumbleCommunicator *mc) { + if(channel_id > -1) { + mc->joinChannel(channel_id); + } +} + diff --git a/MumbleChannelJoiner.hpp b/MumbleChannelJoiner.hpp new file mode 100644 index 0000000..356d022 --- /dev/null +++ b/MumbleChannelJoiner.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include +#include +#include "MumbleCommunicator.hpp" + +namespace mumble { + class MumbleChannelJoiner : boost::noncopyable { + public: + MumbleChannelJoiner(std::string channelNameRegex); + + void checkChannel(std::string channel_name, int channel_id); + void maybeJoinChannel(mumble::MumbleCommunicator *mc); + + private: + log4cpp::Category &logger; + boost::regex channelNameRegex; + int channel_id; + }; +}