diff --git a/cpp/src/ipaaca.cc b/cpp/src/ipaaca.cc index b22a46944721a5f4ace57836f30971f9b7dc5aef..68691e233c50ae7f75da6959d1cb2e34884bf7f9 100644 --- a/cpp/src/ipaaca.cc +++ b/cpp/src/ipaaca.cc @@ -22,12 +22,17 @@ void initialize_ipaaca_rsb() Factory::getInstance().setDefaultParticipantConfig(config); boost::shared_ptr<IUConverter> iu_converter(new IUConverter()); - boost::shared_ptr<IUPayloadUpdateConverter> payload_update_converter(new IUPayloadUpdateConverter()); - boost::shared_ptr<IULinkUpdateConverter> link_update_converter(new IULinkUpdateConverter()); stringConverterRepository()->registerConverter(iu_converter); + + boost::shared_ptr<IUPayloadUpdateConverter> payload_update_converter(new IUPayloadUpdateConverter()); stringConverterRepository()->registerConverter(payload_update_converter); + + boost::shared_ptr<IULinkUpdateConverter> link_update_converter(new IULinkUpdateConverter()); stringConverterRepository()->registerConverter(link_update_converter); + boost::shared_ptr<ProtocolBufferConverter<protobuf::IUCommission> > iu_commission_converter(new ProtocolBufferConverter<protobuf::IUCommission> ()); + stringConverterRepository()->registerConverter(iu_commission_converter); + //IPAACA_TODO("initialize all converters") } /* @@ -127,31 +132,61 @@ void SmartLinkMap::_replace_links(const LinkMap& links) //}}} // Buffer//{{{ -void Buffer::_allocate_unique_name(const std::string& basename) { +void Buffer::_allocate_unique_name(const std::string& basename, const std::string& function) { std::string uuid = ipaaca::generate_uuid_string(); - std::string name = basename + "-" + uuid.substr(0,8); - _unique_name = name; + _basename = basename; + _uuid = uuid.substr(0,8); + _unique_name = basename + "ID" + _uuid + "/" + function; } //}}} // OutputBuffer//{{{ OutputBuffer::OutputBuffer(const std::string& basename) -:Buffer(basename) +:Buffer(basename, "OB") { + _id_prefix = _basename + "-" + _uuid + "-IU-"; } + void OutputBuffer::_send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name) { - IPAACA_IMPLEMENT_ME + IULinkUpdate* lup = new ipaaca::IULinkUpdate(); + Informer<ipaaca::IULinkUpdate>::DataPtr ldata(lup); + lup->uid = iu->uid(); + lup->is_delta = is_delta; + lup->revision = revision; + lup->is_delta = true; + lup->new_links = new_links; + if (is_delta) lup->links_to_remove = links_to_remove; + lup->writer_name = writer_name; + Informer<AnyType>::Ptr informer = _get_informer(iu->category()); + informer->publish(ldata); } + void OutputBuffer::_send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, std::string>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name) { - IPAACA_IMPLEMENT_ME + IUPayloadUpdate* pup = new ipaaca::IUPayloadUpdate(); + Informer<ipaaca::IUPayloadUpdate>::DataPtr pdata(pup); + pup->uid = iu->uid(); + pup->is_delta = is_delta; + pup->revision = revision; + pup->new_items = new_items; + if (is_delta) pup->keys_to_remove = keys_to_remove; + pup->writer_name = writer_name; + Informer<AnyType>::Ptr informer = _get_informer(iu->category()); + informer->publish(pdata); } + void OutputBuffer::_send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name) { - IPAACA_IMPLEMENT_ME + Informer<protobuf::IUCommission>::DataPtr data(new protobuf::IUCommission()); + data->set_uid(iu->uid()); + data->set_revision(revision); + data->set_writer_name(writer_name); + Informer<AnyType>::Ptr informer = _get_informer(iu->category()); + informer->publish(data); } + void OutputBuffer::add(IU::ref iu) { //IPAACA_IMPLEMENT_ME diff --git a/cpp/src/ipaaca.h b/cpp/src/ipaaca.h index d8c1ff77df09fc15a26f9c3e0eb884188a9ccded..4413952a325c68bc36925ea3ffc1e73cd9abb663 100644 --- a/cpp/src/ipaaca.h +++ b/cpp/src/ipaaca.h @@ -137,14 +137,16 @@ class Buffer { //: public boost::enable_shared_from_this<Buffer> { friend class IU; friend class RemotePushIU; protected: + std::string _uuid; + std::string _basename; std::string _unique_name; protected: _IPAACA_ABSTRACT_ virtual void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") = 0; _IPAACA_ABSTRACT_ virtual void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, std::string>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") = 0; _IPAACA_ABSTRACT_ virtual void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") = 0; void _allocate_unique_name(const std::string& basename); - inline Buffer(const std::string& basename) { - _allocate_unique_name(basename); + inline Buffer(const std::string& basename, const std::string& function) { + _allocate_unique_name(basename, function); } public: virtual inline ~Buffer() { } @@ -158,6 +160,7 @@ class OutputBuffer: public Buffer { //, public boost::enable_shared_from_this<Ou protected: std::map<std::string, Informer<AnyType>::Ptr> _informer_store; IUStore _iu_store; + Lock _iu_id_counter_lock; protected: // informing functions void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef");