Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
RecipientsHandler Class Reference

#include <recipients_handler.hh>

Public Member Functions

 RecipientsHandler (size_t circbuf_size=10)
 
 ~RecipientsHandler ()
 
bool add (const std::string &id)
 
bool remove (const std::string &id)
 
bool send (const Frame &data)
 
void wipe ()
 

Private Types

typedef std::vector< Recipient * > container_t
 

Private Member Functions

container_t::iterator find (const boost::asio::ip::tcp::endpoint &ep)
 

Private Attributes

boost::asio::io_service m_service
 
const size_t m_circbuff_size
 
container_t m_recipients
 

Detailed Description

Definition at line 17 of file recipients_handler.hh.

Member Typedef Documentation

Definition at line 19 of file recipients_handler.hh.

Constructor & Destructor Documentation

RecipientsHandler::RecipientsHandler ( size_t  circbuf_size = 10)
inline

Definition at line 27 of file recipients_handler.hh.

28  :
29  m_circbuff_size(circbuf_size)
30  {}
const size_t m_circbuff_size
RecipientsHandler::~RecipientsHandler ( )
inline

Definition at line 32 of file recipients_handler.hh.

33  {
34  wipe();
35  }

Member Function Documentation

bool RecipientsHandler::add ( const std::string &  id)
inline

Definition at line 37 of file recipients_handler.hh.

38  {
39  if (find(make_endpoint(id)) == m_recipients.end())
40  {
41  m_recipients.push_back(
42  new Recipient(
43  m_service,
44  make_endpoint(id),
46  return true;
47  }
48 
49  return false;
50  }
const size_t m_circbuff_size
boost::asio::io_service m_service
boost::asio::ip::tcp::endpoint make_endpoint(const std::string &address)
container_t::iterator find(const boost::asio::ip::tcp::endpoint &ep)
bool RecipientsHandler::remove ( const std::string &  id)
inline

Definition at line 52 of file recipients_handler.hh.

53  {
54  container_t::iterator it = find(make_endpoint(id));
55 
56  if (it != m_recipients.end()) {
57  const Recipient* to_be_erased = *it;
58 
59  m_recipients.erase(it);
60 
61  // write on disk to_be_erased->m_cbuffer. If necessary...
62 
63  delete to_be_erased;
64  return true;
65  }
66 
67  return false;
68  }
boost::asio::ip::tcp::endpoint make_endpoint(const std::string &address)
container_t::iterator find(const boost::asio::ip::tcp::endpoint &ep)
bool RecipientsHandler::send ( const Frame data)
inline

Definition at line 70 of file recipients_handler.hh.

71  {
72  bool status = false;
73  if (m_recipients.size())
74  {
75  const size_t n = data.getSeqNumber() % m_recipients.size();
76  status = m_recipients[n]->sendIfPossible(data);
77  }
78  return status;
79  }
const int n
Definition: JPolint.hh:786
unsigned int getSeqNumber() const
Definition: frame.hh:29
void RecipientsHandler::wipe ( )
inline

Definition at line 81 of file recipients_handler.hh.

82  {
83  for (size_t i = 0; i < m_recipients.size(); ++i)
84  {
85  delete m_recipients[i];
86  }
87  m_recipients.clear();
88  }
container_t::iterator RecipientsHandler::find ( const boost::asio::ip::tcp::endpoint &  ep)
inlineprivate

Definition at line 92 of file recipients_handler.hh.

93  {
94  container_t::iterator it = m_recipients.begin();
95  for (container_t::const_iterator et = m_recipients.end(); it != et; ++it)
96  {
97  if ((*it)->m_endpoint == ep)
98  {
99  break;
100  }
101  }
102 
103  return it;
104  }

Member Data Documentation

boost::asio::io_service RecipientsHandler::m_service
private

Definition at line 21 of file recipients_handler.hh.

const size_t RecipientsHandler::m_circbuff_size
private

Definition at line 22 of file recipients_handler.hh.

container_t RecipientsHandler::m_recipients
private

Definition at line 23 of file recipients_handler.hh.


The documentation for this class was generated from the following file: