struct size_visitor : public boost::static_visitor<std::size_t>
{
- std::size_t operator()(const bool value) { return sizeof(bool); }
- std::size_t operator()(const int32_t value) { return sizeof(int64_t); }
- std::size_t operator()(const uint32_t value) { return sizeof(int64_t); }
- std::size_t operator()(const int64_t value) { return sizeof(int64_t); }
- std::size_t operator()(const uint64_t value) { return sizeof(int64_t); }
- std::size_t operator()(const float value) { return sizeof(float); }
- std::size_t operator()(const double value) { return sizeof(float); }
- std::size_t operator()(const std::string& value) { return value.size(); }
- std::size_t operator()(const std::wstring& value) { return value.size(); }
- std::size_t operator()(const std::vector<int8_t>& value) { return value.size(); }
+ static inline long round_up(long x)
+ {
+ return ((x-1) & (~0x03L)) + 4;
+ }
+
+ std::size_t operator()(const bool value) { return round_up(sizeof(bool)); }
+ std::size_t operator()(const int32_t value) { return round_up(sizeof(int64_t)); }
+ std::size_t operator()(const uint32_t value) { return round_up(sizeof(int64_t)); }
+ std::size_t operator()(const int64_t value) { return round_up(sizeof(int64_t)); }
+ std::size_t operator()(const uint64_t value) { return round_up(sizeof(int64_t)); }
+ std::size_t operator()(const float value) { return round_up(sizeof(float)); }
+ std::size_t operator()(const double value) { return round_up(sizeof(float)); }
+ std::size_t operator()(const std::string& value) { return round_up(value.size() + 1); }
+ std::size_t operator()(const std::wstring& value) { return round_up(value.size() + 1); }
+ std::size_t operator()(const std::vector<int8_t>& value) { return round_up(value.size()); }
};
void write_osc_event(byte_vector& destination, const core::monitor::message& e)
{
- try
- {
- std::size_t size = 256; // This should be enough to cover address, padding and meta-data.
+ std::size_t size = 256; // This should be enough to cover address, padding and meta-data.
- size_visitor size_visitor;
- BOOST_FOREACH(auto& data, e.data())
- size += boost::apply_visitor(size_visitor, data);
+ size_visitor size_visitor;
+ BOOST_FOREACH(const auto& data, e.data())
+ size += boost::apply_visitor(size_visitor, data);
- destination.resize(size);
+ destination.resize(size);
- ::osc::OutboundPacketStream o(reinterpret_cast<char*>(destination.data()), static_cast<unsigned long>(destination.size()));
+ ::osc::OutboundPacketStream o(reinterpret_cast<char*>(destination.data()), static_cast<unsigned long>(destination.size()));
- o << ::osc::BeginMessage(e.path().c_str());
+ o << ::osc::BeginMessage(e.path().c_str());
- param_visitor<decltype(o)> param_visitor(o);
- BOOST_FOREACH(auto& data, e.data())
- boost::apply_visitor(param_visitor, data);
+ param_visitor<decltype(o)> param_visitor(o);
+ BOOST_FOREACH(const auto& data, e.data())
+ boost::apply_visitor(param_visitor, data);
- o << ::osc::EndMessage;
+ o << ::osc::EndMessage;
- destination.resize(o.Size());
- }
- catch(...)
- {
- }
+ destination.resize(o.Size());
}
struct client::impl
{
{
boost::lock_guard<boost::mutex> lock(updates_mutex_);
- write_osc_event(updates_[msg.path()], msg);
+
+ try
+ {
+ write_osc_event(updates_[msg.path()], msg);
+ }
+ catch(...)
+ {
+ updates_.erase(msg.path());
+ }
}
cond_.notify_all();