Added getter functions.

This commit is contained in:
Nicolás Ortega Froysa 2017-11-18 10:59:00 +01:00
parent 5c5adbc109
commit c8964ad81a
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
2 changed files with 28 additions and 0 deletions

View File

@ -143,6 +143,21 @@ int NeoComm_join_channel(const char *channel_name);
*/ */
int NeoComm_leave_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 * @brief Get the next available message (in chronological order) for
* a given channel. * a given channel.

View File

@ -28,6 +28,8 @@ static std::uniform_int_distribution<dht::Value::Id> rand_id;
static std::map<time_t, int> sent_messages; static std::map<time_t, int> sent_messages;
static std::string channel_list;
int NeoComm_join_channel(const char *channel_name) { int NeoComm_join_channel(const char *channel_name) {
if(not node.isRunning()) if(not node.isRunning())
{ {
@ -101,3 +103,14 @@ int NeoComm_leave_channel(const char *channel_name) {
channels.erase(s_chan_name); channels.erase(s_chan_name);
return 1; 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();
}