Changed channel to a class.

I believe this interface is better to work with. Later I'll add the
"send message" interfaces to the channel class.
This commit is contained in:
Nicolás Ortega Froysa
2018-09-04 15:52:10 +02:00
parent 93fa26aa1a
commit 15067ab4ec
4 changed files with 89 additions and 43 deletions

View File

@ -26,12 +26,26 @@
namespace neocomm {
/**
* @brief Object to contain channel information.
*/
struct channel {
dht::InfoHash key; //!< The sha1 hash of the channel name.
std::future<size_t> token; //!< Token used to leave channel.
std::list<struct message> messages; //!< Messages received by channel.
class channel {
public:
channel(const std::string &name, dht::DhtRunner *network);
~channel();
inline std::string get_name() const {
return name;
}
//inline dht::InfoHash get_key() const {
//return key;
//}
//inline size_t get_token() {
//return token.get();
//}
private:
const std::string name;
const dht::InfoHash key;
dht::DhtRunner *network;
std::future<size_t> token;
std::list<struct message> messages;
};
}

View File

@ -21,7 +21,7 @@
#include "neocomm/channel.hpp"
#include <opendht.h>
#include <map>
#include <vector>
namespace neocomm {
@ -64,18 +64,12 @@ public:
*/
void export_nodes(const std::string &file_path); // TODO
/**
* @brief Join a channel.
*
* @param name The name of the channel to join.
*/
void join_channel(const std::string &name);
/**
* @brief Leave an already joined channel.
*
* @param name Name of the channel.
*/
channel *join_channel(const std::string &name);
channel *get_channel(const std::string &name);
void leave_channel(const std::string &name);
inline void leave_channel(channel *chan) {
leave_channel(chan->get_name());
}
/**
* @brief Get the current alias for the user.
@ -95,18 +89,9 @@ public:
}
private:
inline struct channel *get_channel(
const std::string &name) {
for(auto &i : channels)
{
if(i.first == name)
return &i.second;
}
return nullptr;
}
std::string alias;
dht::DhtRunner network;
std::map<std::string, struct channel> channels;
std::vector<channel*> channels;
};
}