Commit f2807d11 authored by Martin Hurton's avatar Martin Hurton

Remove i_properties interface

We use metadata_t directly. No need for generic interface now.
parent c5cd92da
/*
Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ZMQ_I_PROPERTIES_HPP_INCLUDED__
#define __ZMQ_I_PROPERTIES_HPP_INCLUDED__
#include <string>
namespace zmq
{
// Interface for accessing message properties.
// Implementers are supposed to use reference counting to
// manage object's lifetime.
struct i_properties
{
virtual ~i_properties () {}
// Returns pointer to property value or NULL if
// property not found.
virtual const char *get (const std::string &property) const = 0;
virtual void add_ref () = 0;
// Drop reference. Returns true iff the reference
// counter drops to zero.
virtual bool drop_ref () = 0;
};
}
#endif
......@@ -21,13 +21,13 @@
#define __ZMQ_METADATA_HPP_INCLUDED__
#include <map>
#include <string>
#include "atomic_counter.hpp"
#include "i_properties.hpp"
namespace zmq
{
class metadata_t : public i_properties
class metadata_t
{
public:
......
......@@ -26,7 +26,7 @@
#include "stdint.hpp"
#include "likely.hpp"
#include "i_properties.hpp"
#include "metadata.hpp"
#include "err.hpp"
// Check whether the sizes of public representation of the message (zmq_msg_t)
......@@ -42,7 +42,7 @@ bool zmq::msg_t::check ()
int zmq::msg_t::init ()
{
u.vsm.properties = NULL;
u.vsm.metadata = NULL;
u.vsm.type = type_vsm;
u.vsm.flags = 0;
u.vsm.size = 0;
......@@ -54,13 +54,13 @@ int zmq::msg_t::init_size (size_t size_)
{
file_desc = -1;
if (size_ <= max_vsm_size) {
u.vsm.properties = NULL;
u.vsm.metadata = NULL;
u.vsm.type = type_vsm;
u.vsm.flags = 0;
u.vsm.size = (unsigned char) size_;
}
else {
u.lmsg.properties = NULL;
u.lmsg.metadata = NULL;
u.lmsg.type = type_lmsg;
u.lmsg.flags = 0;
u.lmsg.content =
......@@ -90,14 +90,14 @@ int zmq::msg_t::init_data (void *data_, size_t size_, msg_free_fn *ffn_,
// Initialize constant message if there's no need to deallocate
if (ffn_ == NULL) {
u.cmsg.properties = NULL;
u.cmsg.metadata = NULL;
u.cmsg.type = type_cmsg;
u.cmsg.flags = 0;
u.cmsg.data = data_;
u.cmsg.size = size_;
}
else {
u.lmsg.properties = NULL;
u.lmsg.metadata = NULL;
u.lmsg.type = type_lmsg;
u.lmsg.flags = 0;
u.lmsg.content = (content_t*) malloc (sizeof (content_t));
......@@ -118,7 +118,7 @@ int zmq::msg_t::init_data (void *data_, size_t size_, msg_free_fn *ffn_,
int zmq::msg_t::init_delimiter ()
{
u.delimiter.properties = NULL;
u.delimiter.metadata = NULL;
u.delimiter.type = type_delimiter;
u.delimiter.flags = 0;
return 0;
......@@ -150,9 +150,9 @@ int zmq::msg_t::close ()
}
}
if (u.base.properties != NULL)
if (u.base.properties->drop_ref ())
delete u.base.properties;
if (u.base.metadata != NULL)
if (u.base.metadata->drop_ref ())
delete u.base.metadata;
// Make the message invalid.
u.base.type = 0;
......@@ -205,8 +205,8 @@ int zmq::msg_t::copy (msg_t &src_)
}
}
if (src_.u.base.properties != NULL)
src_.u.base.properties->add_ref ();
if (src_.u.base.metadata != NULL)
src_.u.base.metadata->add_ref ();
*this = src_;
......@@ -275,17 +275,17 @@ void zmq::msg_t::set_fd (int64_t fd_)
file_desc = fd_;
}
zmq::i_properties *zmq::msg_t::properties () const
zmq::metadata_t *zmq::msg_t::metadata () const
{
return u.base.properties;
return u.base.metadata;
}
void zmq::msg_t::set_properties (zmq::i_properties *properties_)
void zmq::msg_t::set_metadata (zmq::metadata_t *metadata_)
{
assert (properties_ != NULL);
assert (u.base.properties == NULL);
properties_->add_ref ();
u.base.properties = properties_;
assert (metadata_ != NULL);
assert (u.base.metadata == NULL);
metadata_->add_ref ();
u.base.metadata = metadata_;
}
bool zmq::msg_t::is_identity () const
......@@ -317,8 +317,8 @@ void zmq::msg_t::add_refs (int refs_)
{
zmq_assert (refs_ >= 0);
// Operation not supported for messages with properties.
zmq_assert (u.base.properties == NULL);
// Operation not supported for messages with metadata.
zmq_assert (u.base.metadata == NULL);
// No copies required.
if (!refs_)
......@@ -340,8 +340,8 @@ bool zmq::msg_t::rm_refs (int refs_)
{
zmq_assert (refs_ >= 0);
// Operation not supported for messages with properties.
zmq_assert (u.base.properties == NULL);
// Operation not supported for messages with metadata.
zmq_assert (u.base.metadata == NULL);
// No copies required.
if (!refs_)
......
......@@ -25,7 +25,7 @@
#include "config.hpp"
#include "atomic_counter.hpp"
#include "i_properties.hpp"
#include "metadata.hpp"
// Signature for free function to deallocate the message content.
// Note that it has to be declared as "C" so that it is the same as
......@@ -71,8 +71,8 @@ namespace zmq
void reset_flags (unsigned char flags_);
int64_t fd ();
void set_fd (int64_t fd_);
i_properties *properties () const;
void set_properties (i_properties *properties_);
metadata_t *metadata () const;
void set_metadata (metadata_t *metadata_);
bool is_identity () const;
bool is_credential () const;
bool is_delimiter () const;
......@@ -92,7 +92,7 @@ namespace zmq
// Size in bytes of the largest message that is still copied around
// rather than being reference-counted.
enum { msg_t_size = 48 };
enum { max_vsm_size = msg_t_size - (8 + sizeof (i_properties *) + 3) };
enum { max_vsm_size = msg_t_size - (8 + sizeof (metadata_t *) + 3) };
// Shared message buffer. Message data are either allocated in one
// continuous block along with this structure - thus avoiding one
......@@ -134,37 +134,37 @@ namespace zmq
// the union.
union {
struct {
i_properties *properties;
unsigned char unused [msg_t_size - (8 + sizeof (i_properties *) + 2)];
metadata_t *metadata;
unsigned char unused [msg_t_size - (8 + sizeof (metadata_t *) + 2)];
unsigned char type;
unsigned char flags;
} base;
struct {
i_properties *properties;
metadata_t *metadata;
unsigned char data [max_vsm_size];
unsigned char size;
unsigned char type;
unsigned char flags;
} vsm;
struct {
i_properties *properties;
metadata_t *metadata;
content_t *content;
unsigned char unused [msg_t_size - (8 + sizeof (i_properties *) + sizeof (content_t*) + 2)];
unsigned char unused [msg_t_size - (8 + sizeof (metadata_t *) + sizeof (content_t*) + 2)];
unsigned char type;
unsigned char flags;
} lmsg;
struct {
i_properties *properties;
metadata_t *metadata;
void* data;
size_t size;
unsigned char unused
[msg_t_size - (8 + sizeof (i_properties *) + sizeof (void*) + sizeof (size_t) + 2)];
[msg_t_size - (8 + sizeof (metadata_t *) + sizeof (void*) + sizeof (size_t) + 2)];
unsigned char type;
unsigned char flags;
} cmsg;
struct {
i_properties *properties;
unsigned char unused [msg_t_size - (8 + sizeof (i_properties *) + 2)];
metadata_t *metadata;
unsigned char unused [msg_t_size - (8 + sizeof (metadata_t *) + 2)];
unsigned char type;
unsigned char flags;
} delimiter;
......
......@@ -814,7 +814,7 @@ int zmq::stream_engine_t::decode_and_push (msg_t *msg_)
if (mechanism->decode (msg_) == -1)
return -1;
if (metadata)
msg_->set_properties (metadata);
msg_->set_metadata (metadata);
if (session->push_msg (msg_) == -1) {
if (errno == EAGAIN)
write_msg = &stream_engine_t::push_one_then_decode_and_push;
......
......@@ -63,7 +63,7 @@ struct iovec {
#include "err.hpp"
#include "msg.hpp"
#include "fd.hpp"
#include "i_properties.hpp"
#include "metadata.hpp"
#if !defined ZMQ_HAVE_WINDOWS
#include <unistd.h>
......@@ -647,9 +647,9 @@ int zmq_msg_set (zmq_msg_t *, int, int)
const char *zmq_msg_gets (zmq_msg_t *msg_, const char *property_)
{
zmq::i_properties *properties = ((zmq::msg_t*) msg_)->properties ();
if (properties)
return properties->get (std::string (property_));
zmq::metadata_t *metadata = ((zmq::msg_t*) msg_)->metadata ();
if (metadata)
return metadata->get (std::string (property_));
else
return NULL;
}
......
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