From c8964ad81a2059f7c6638965e4acb98a74a8df68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sat, 18 Nov 2017 10:59:00 +0100 Subject: [PATCH] Added getter functions. --- include/neocomm.h | 15 +++++++++++++++ src/channel.cpp | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/neocomm.h b/include/neocomm.h index 8f19501..b30348b 100644 --- a/include/neocomm.h +++ b/include/neocomm.h @@ -143,6 +143,21 @@ int NeoComm_join_channel(const char *channel_name); */ int NeoComm_leave_channel(const char *channel_name); +/** + * @brief Retrieve a list of the channels that the client is listening to. + * + * @return A list of channels separated by spaces. + */ +const char *NeoComm_get_channel_list(); + +/** + * @brief Retrieve the current number of channels that the client is listening + * to. + * + * @return The number of channels the client is listening to. + */ +unsigned int NeoComm_get_num_channels(); + /** * @brief Get the next available message (in chronological order) for * a given channel. diff --git a/src/channel.cpp b/src/channel.cpp index 6034c39..f627b62 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -28,6 +28,8 @@ static std::uniform_int_distribution rand_id; static std::map sent_messages; +static std::string channel_list; + int NeoComm_join_channel(const char *channel_name) { if(not node.isRunning()) { @@ -101,3 +103,14 @@ int NeoComm_leave_channel(const char *channel_name) { channels.erase(s_chan_name); return 1; } + +const char *NeoComm_get_channel_list() { + channel_list.clear(); + for(auto &i : channels) + channel_list += i.first + " "; + return channel_list.c_str(); +} + +unsigned int NeoComm_get_num_channels() { + return channels.size(); +}