diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca.h b/ipaacalib/cpp/include/ipaaca/ipaaca.h index ce554a9041c6b18c15f93925a67d16f988496e82..60b46daf0effc3370c0e7cb8c55b8eb4a86dc296 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca.h @@ -476,6 +476,7 @@ class Payload//{{{ void _remotely_enforced_delitem(const std::string& k); void _remotely_enforced_setitem(const std::string& k, const std::string& v); void _internal_replace_all(const std::map<std::string, std::string>& new_contents, const std::string& writer_name=""); + void _internal_merge(const std::map<std::string, std::string>& contents_to_merge, const std::string& writer_name=""); void _internal_set(const std::string& k, const std::string& v, const std::string& writer_name=""); void _internal_remove(const std::string& k, const std::string& writer_name=""); public: @@ -485,6 +486,7 @@ class Payload//{{{ operator std::map<std::string, std::string>(); inline void set(const std::map<std::string, std::string>& all_elems) { _internal_replace_all(all_elems); } inline void set(const std::string& k, const std::string& v) { _internal_set(k, v); } + inline void merge(const std::map<std::string, std::string>& elems_to_merge) { _internal_merge(elems_to_merge); } inline void remove(const std::string& k) { _internal_remove(k); } std::string get(const std::string& k); typedef boost::shared_ptr<Payload> ptr; diff --git a/ipaacalib/cpp/src/ipaaca.cc b/ipaacalib/cpp/src/ipaaca.cc index 6d822dd990990c0c84bf28fb330f1a508aca9623..7a7198efc41e7199eca2355250f21598e9ac6afb 100644 --- a/ipaacalib/cpp/src/ipaaca.cc +++ b/ipaacalib/cpp/src/ipaaca.cc @@ -291,6 +291,7 @@ CallbackIUCommission::CallbackIUCommission(Buffer* buffer): _buffer(buffer) { } boost::shared_ptr<int> CallbackIUPayloadUpdate::call(const std::string& methodName, boost::shared_ptr<IUPayloadUpdate> update) { + //std::cout << "-- Received a modify_payload with " << update->new_items.size() << " keys to merge." << std::endl; IUInterface::ptr iui = _buffer->get(update->uid); if (! iui) { IPAACA_WARNING("Remote InBuffer tried to spuriously write non-existent IU " << update->uid) @@ -304,15 +305,17 @@ boost::shared_ptr<int> CallbackIUPayloadUpdate::call(const std::string& methodNa return boost::shared_ptr<int>(new int(0)); } if (update->is_delta) { + // FIXME FIXME this is an unsolved problem atm: deletes in a delta update are + // sent individually. We should have something like _internal_merge_and_remove for (std::vector<std::string>::const_iterator it=update->keys_to_remove.begin(); it!=update->keys_to_remove.end(); ++it) { iu->payload()._internal_remove(*it, update->writer_name); //_buffer->unique_name()); } - for (std::map<std::string, std::string>::const_iterator it=update->new_items.begin(); it!=update->new_items.end(); ++it) { - iu->payload()._internal_set(it->first, it->second, update->writer_name); //_buffer->unique_name()); - } + // but it is solved for pure merges: + iu->payload()._internal_merge(update->new_items, update->writer_name); } else { iu->payload()._internal_replace_all(update->new_items, update->writer_name); //_buffer->unique_name()); } + //std::cout << "-- Calling update handler due to remote write." << std::endl; _buffer->call_iu_event_handlers(iu, true, IU_UPDATED, iu->category()); revision_t revision = iu->revision(); iu->_revision_lock.unlock(); @@ -859,6 +862,7 @@ void IU::_modify_payload(bool is_delta, const std::map<std::string, std::string> } _increase_revision_number(); if (is_published()) { + //std::cout << "Sending a payload update with " << new_items.size() << " entries to merge." << std::endl; _buffer->_send_iu_payload_update(this, is_delta, _revision, new_items, keys_to_remove, writer_name); } _revision_lock.unlock(); @@ -956,6 +960,7 @@ void RemotePushIU::_modify_links(bool is_delta, const LinkMap& new_links, const } void RemotePushIU::_modify_payload(bool is_delta, const std::map<std::string, std::string>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name) { + //std::cout << "-- Sending a modify_payload with " << new_items.size() << " keys to merge." << std::endl; if (_committed) { throw IUCommittedError(); } @@ -1192,6 +1197,15 @@ void Payload::_internal_replace_all(const std::map<std::string, std::string>& ne _iu.lock()->_modify_payload(false, new_contents, _remove, writer_name ); _store = new_contents; } +void Payload::_internal_merge(const std::map<std::string, std::string>& contents_to_merge, const std::string& writer_name) +{ + std::vector<std::string> _remove; + _iu.lock()->_modify_payload(true, contents_to_merge, _remove, writer_name ); + _store.insert(contents_to_merge.begin(), contents_to_merge.end()); + //for (std::map<std::string, std::string>::iterator it = contents_to_merge.begin(); it!=contents_to_merge.end(); i++) { + // _store[it->first] = it->second; + //} +} inline std::string Payload::get(const std::string& k) { if (_store.count(k)>0) return _store[k]; else return IPAACA_PAYLOAD_DEFAULT_STRING_VALUE; diff --git a/ipaacalib/cpp/src/util/notifier.cc b/ipaacalib/cpp/src/util/notifier.cc index a2b96583dafa4a195572ef588a7e1042330cffd5..2bc834fb6dd04816e25beaaa7da483e175770b8b 100644 --- a/ipaacalib/cpp/src/util/notifier.cc +++ b/ipaacalib/cpp/src/util/notifier.cc @@ -5,9 +5,8 @@ namespace util { ComponentNotifier::~ComponentNotifier() { - LOG_IPAACA_CONSOLE("~ComponentNotifier") + //LOG_IPAACA_CONSOLE("~ComponentNotifier") if (initialized) { - LOG_IPAACA_CONSOLE(" - notifying") go_down(); } }