Commit 9fc3692e authored by Simon Giesecke's avatar Simon Giesecke

Problem: read-only arguments of mtrie are not declared as const

Solution: add const, introduce typedef
parent 31387f84
...@@ -57,14 +57,12 @@ zmq::mtrie_t::~mtrie_t () ...@@ -57,14 +57,12 @@ zmq::mtrie_t::~mtrie_t ()
} }
} }
bool zmq::mtrie_t::add (unsigned char *prefix_, size_t size_, pipe_t *pipe_) bool zmq::mtrie_t::add (prefix_t prefix_, size_t size_, pipe_t *pipe_)
{ {
return add_helper (prefix_, size_, pipe_); return add_helper (prefix_, size_, pipe_);
} }
bool zmq::mtrie_t::add_helper (unsigned char *prefix_, bool zmq::mtrie_t::add_helper (prefix_t prefix_, size_t size_, pipe_t *pipe_)
size_t size_,
pipe_t *pipe_)
{ {
// We are at the node corresponding to the prefix. We are done. // We are at the node corresponding to the prefix. We are done.
if (!size_) { if (!size_) {
...@@ -139,9 +137,7 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, ...@@ -139,9 +137,7 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_,
void zmq::mtrie_t::rm (pipe_t *pipe_, void zmq::mtrie_t::rm (pipe_t *pipe_,
void (*func_) (unsigned char *data_, void (*func_) (prefix_t data_, size_t size_, void *arg_),
size_t size_,
void *arg_),
void *arg_, void *arg_,
bool call_on_uniq_) bool call_on_uniq_)
{ {
...@@ -154,7 +150,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, ...@@ -154,7 +150,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_,
unsigned char **buff_, unsigned char **buff_,
size_t buffsize_, size_t buffsize_,
size_t maxbuffsize_, size_t maxbuffsize_,
void (*func_) (unsigned char *data_, void (*func_) (prefix_t data_,
size_t size_, size_t size_,
void *arg_), void *arg_),
void *arg_, void *arg_,
...@@ -275,14 +271,12 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, ...@@ -275,14 +271,12 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_,
} }
} }
bool zmq::mtrie_t::rm (unsigned char *prefix_, size_t size_, pipe_t *pipe_) bool zmq::mtrie_t::rm (prefix_t prefix_, size_t size_, pipe_t *pipe_)
{ {
return rm_helper (prefix_, size_, pipe_); return rm_helper (prefix_, size_, pipe_);
} }
bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, bool zmq::mtrie_t::rm_helper (prefix_t prefix_, size_t size_, pipe_t *pipe_)
size_t size_,
pipe_t *pipe_)
{ {
if (!size_) { if (!size_) {
if (pipes) { if (pipes) {
...@@ -372,7 +366,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, ...@@ -372,7 +366,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_,
return ret; return ret;
} }
void zmq::mtrie_t::match (unsigned char *data_, void zmq::mtrie_t::match (prefix_t data_,
size_t size_, size_t size_,
void (*func_) (pipe_t *pipe_, void *arg_), void (*func_) (pipe_t *pipe_, void *arg_),
void *arg_) void *arg_)
......
...@@ -44,43 +44,45 @@ class pipe_t; ...@@ -44,43 +44,45 @@ class pipe_t;
class mtrie_t class mtrie_t
{ {
public: public:
typedef const unsigned char *prefix_t;
mtrie_t (); mtrie_t ();
~mtrie_t (); ~mtrie_t ();
// Add key to the trie. Returns true if it's a new subscription // Add key to the trie. Returns true if it's a new subscription
// rather than a duplicate. // rather than a duplicate.
bool add (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_); bool add (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
// Remove all subscriptions for a specific peer from the trie. // Remove all subscriptions for a specific peer from the trie.
// The call_on_uniq_ flag controls if the callback is invoked // The call_on_uniq_ flag controls if the callback is invoked
// when there are no subscriptions left on some topics or on // when there are no subscriptions left on some topics or on
// every removal. // every removal.
void rm (zmq::pipe_t *pipe_, void
void (*func_) (unsigned char *data_, size_t size_, void *arg_), rm (zmq::pipe_t *pipe_,
void *arg_, void (*func_) (const unsigned char *data_, size_t size_, void *arg_),
bool call_on_uniq_); void *arg_,
bool call_on_uniq_);
// Remove specific subscription from the trie. Return true is it was // Remove specific subscription from the trie. Return true is it was
// actually removed rather than de-duplicated. // actually removed rather than de-duplicated.
bool rm (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_); bool rm (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
// Signal all the matching pipes. // Signal all the matching pipes.
void match (unsigned char *data_, void match (prefix_t data_,
size_t size_, size_t size_,
void (*func_) (zmq::pipe_t *pipe_, void *arg_), void (*func_) (zmq::pipe_t *pipe_, void *arg_),
void *arg_); void *arg_);
private: private:
bool add_helper (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_); bool add_helper (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
void void rm_helper (zmq::pipe_t *pipe_,
rm_helper (zmq::pipe_t *pipe_, unsigned char **buff_,
unsigned char **buff_, size_t buffsize_,
size_t buffsize_, size_t maxbuffsize_,
size_t maxbuffsize_, void (*func_) (prefix_t data_, size_t size_, void *arg_),
void (*func_) (unsigned char *data_, size_t size_, void *arg_), void *arg_,
void *arg_, bool call_on_uniq_);
bool call_on_uniq_); bool rm_helper (prefix_t prefix_, size_t size_, zmq::pipe_t *pipe_);
bool rm_helper (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
bool is_redundant () const; bool is_redundant () const;
typedef std::set<zmq::pipe_t *> pipes_t; typedef std::set<zmq::pipe_t *> pipes_t;
......
...@@ -188,7 +188,7 @@ int zmq::xpub_t::xsetsockopt (int option_, ...@@ -188,7 +188,7 @@ int zmq::xpub_t::xsetsockopt (int option_,
return 0; return 0;
} }
static void stub (unsigned char *data_, size_t size_, void *arg_) static void stub (zmq::mtrie_t::prefix_t data_, size_t size_, void *arg_)
{ {
LIBZMQ_UNUSED (data_); LIBZMQ_UNUSED (data_);
LIBZMQ_UNUSED (size_); LIBZMQ_UNUSED (size_);
...@@ -295,7 +295,7 @@ bool zmq::xpub_t::xhas_in () ...@@ -295,7 +295,7 @@ bool zmq::xpub_t::xhas_in ()
return !pending_data.empty (); return !pending_data.empty ();
} }
void zmq::xpub_t::send_unsubscription (unsigned char *data_, void zmq::xpub_t::send_unsubscription (zmq::mtrie_t::prefix_t data_,
size_t size_, size_t size_,
void *arg_) void *arg_)
{ {
......
...@@ -66,8 +66,9 @@ class xpub_t : public socket_base_t ...@@ -66,8 +66,9 @@ class xpub_t : public socket_base_t
private: private:
// Function to be applied to the trie to send all the subscriptions // Function to be applied to the trie to send all the subscriptions
// upstream. // upstream.
static void static void send_unsubscription (zmq::mtrie_t::prefix_t data_,
send_unsubscription (unsigned char *data_, size_t size_, void *arg_); size_t size_,
void *arg_);
// Function to be applied to each matching pipes. // Function to be applied to each matching pipes.
static void mark_as_matching (zmq::pipe_t *pipe_, void *arg_); static void mark_as_matching (zmq::pipe_t *pipe_, void *arg_);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment