diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca.h b/ipaacalib/cpp/include/ipaaca/ipaaca.h index 3edd62c365fd521b3514e84334850a55a059e6b2..eaf13de74b010f1b1974058ed01bff476ac39eec 100644 --- a/ipaacalib/cpp/include/ipaaca/ipaaca.h +++ b/ipaacalib/cpp/include/ipaaca/ipaaca.h @@ -55,6 +55,7 @@ #include <boost/bind.hpp> #include <boost/function.hpp> #include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> #include <boost/pointer_cast.hpp> #include <boost/lexical_cast.hpp> #endif @@ -456,7 +457,7 @@ class Payload//{{{ protected: std::string _owner_name; std::map<std::string, std::string> _store; - boost::shared_ptr<IUInterface> _iu; + boost::weak_ptr<IUInterface> _iu; protected: void initialize(boost::shared_ptr<IUInterface> iu); inline void _set_owner_name(const std::string& name) { _owner_name = name; } @@ -560,7 +561,7 @@ class IU: public IUInterface {//{{{ IU(const std::string& category, IUAccessMode access_mode=IU_ACCESS_PUSH, bool read_only=false, const std::string& payload_type="MAP" ); public: inline ~IU() { - IPAACA_IMPLEMENT_ME + //IPAACA_IMPLEMENT_ME } static boost::shared_ptr<IU> create(const std::string& category, IUAccessMode access_mode=IU_ACCESS_PUSH, bool read_only=false, const std::string& payload_type="MAP" ); inline Payload& payload() { return _payload; } @@ -585,7 +586,7 @@ class Message: public IU {//{{{ Message(const std::string& category, IUAccessMode access_mode=IU_ACCESS_MESSAGE, bool read_only=true, const std::string& payload_type="MAP" ); public: inline ~Message() { - IPAACA_IMPLEMENT_ME + //IPAACA_IMPLEMENT_ME } static boost::shared_ptr<Message> create(const std::string& category, IUAccessMode access_mode=IU_ACCESS_MESSAGE, bool read_only=true, const std::string& payload_type="MAP" ); protected: @@ -610,7 +611,7 @@ class RemotePushIU: public IUInterface {//{{{ static boost::shared_ptr<RemotePushIU> create(); public: inline ~RemotePushIU() { - IPAACA_IMPLEMENT_ME + //IPAACA_IMPLEMENT_ME } inline Payload& payload() { return _payload; } inline const Payload& const_payload() const { return _payload; } @@ -638,7 +639,7 @@ class RemoteMessage: public IUInterface {//{{{ static boost::shared_ptr<RemoteMessage> create(); public: inline ~RemoteMessage() { - IPAACA_IMPLEMENT_ME + //IPAACA_IMPLEMENT_ME } inline Payload& payload() { return _payload; } inline const Payload& const_payload() const { return _payload; } diff --git a/ipaacalib/cpp/include/ipaaca/util/notifier.h b/ipaacalib/cpp/include/ipaaca/util/notifier.h index 1a5d4e898848ab6e7c2f81c4089d6290f77d8cb5..4c012c8783ebef451aba477ac7174a8c26b71ca6 100644 --- a/ipaacalib/cpp/include/ipaaca/util/notifier.h +++ b/ipaacalib/cpp/include/ipaaca/util/notifier.h @@ -9,7 +9,7 @@ #define _IPAACA_COMP_NOTIF_FUNCTION "function" #define _IPAACA_COMP_NOTIF_STATE "state" #define _IPAACA_COMP_NOTIF_SEND_CATS "send_categories" -#define _IPAACA_COMP_NOTIF_RECV_CATS "receive_categories" +#define _IPAACA_COMP_NOTIF_RECV_CATS "recv_categories" #define _IPAACA_COMP_NOTIF_STATE_NEW "new" #define _IPAACA_COMP_NOTIF_STATE_OLD "old" diff --git a/ipaacalib/cpp/src/ipaaca.cc b/ipaacalib/cpp/src/ipaaca.cc index d22ce25848638bd918800e730edeb5aa8f1ec247..6d822dd990990c0c84bf28fb330f1a508aca9623 100644 --- a/ipaacalib/cpp/src/ipaaca.cc +++ b/ipaacalib/cpp/src/ipaaca.cc @@ -650,6 +650,7 @@ void InputBuffer::_handle_iu_events(EventPtr event) boost::shared_ptr<RemoteMessage> iu = boost::static_pointer_cast<RemoteMessage>(event->getData()); //_iu_store[iu->uid()] = iu; //iu->_set_buffer(this); + //std::cout << "REFCNT after cast, before calling handlers: " << iu.use_count() << std::endl; call_iu_event_handlers(iu, false, IU_MESSAGE, iu->category() ); //_iu_store.erase(iu->uid()); } else { @@ -1158,7 +1159,7 @@ PayloadEntryProxy::operator double() void Payload::initialize(boost::shared_ptr<IUInterface> iu) { - _iu = iu; + _iu = boost::weak_ptr<IUInterface>(iu); } PayloadEntryProxy Payload::operator[](const std::string& key) @@ -1175,20 +1176,20 @@ inline void Payload::_internal_set(const std::string& k, const std::string& v, c std::map<std::string, std::string> _new; std::vector<std::string> _remove; _new[k]=v; - _iu->_modify_payload(true, _new, _remove, writer_name ); + _iu.lock()->_modify_payload(true, _new, _remove, writer_name ); _store[k] = v; } inline void Payload::_internal_remove(const std::string& k, const std::string& writer_name) { std::map<std::string, std::string> _new; std::vector<std::string> _remove; _remove.push_back(k); - _iu->_modify_payload(true, _new, _remove, writer_name ); + _iu.lock()->_modify_payload(true, _new, _remove, writer_name ); _store.erase(k); } void Payload::_internal_replace_all(const std::map<std::string, std::string>& new_contents, const std::string& writer_name) { std::vector<std::string> _remove; - _iu->_modify_payload(false, new_contents, _remove, writer_name ); + _iu.lock()->_modify_payload(false, new_contents, _remove, writer_name ); _store = new_contents; } inline std::string Payload::get(const std::string& k) { @@ -1313,6 +1314,7 @@ AnnotatedData IUConverter::deserialize(const std::string& wireSchema, const std: { // Create a "Message-type IU" boost::shared_ptr<RemoteMessage> obj = RemoteMessage::create(); + //std::cout << "REFCNT after create: " << obj.use_count() << std::endl; // transfer pbo data to obj obj->_uid = pbo->uid(); obj->_revision = pbo->revision(); diff --git a/ipaacalib/cpp/src/util/notifier.cc b/ipaacalib/cpp/src/util/notifier.cc index a295e87ee64724e4082155bbf15a4d024740167e..7dd9ede94dd4946e1274e483f536fc1839f3ad64 100644 --- a/ipaacalib/cpp/src/util/notifier.cc +++ b/ipaacalib/cpp/src/util/notifier.cc @@ -73,6 +73,7 @@ void ComponentNotifier::submit_notify(const std::string& current_state) iu->payload()[_IPAACA_COMP_NOTIF_SEND_CATS] = send_categories; iu->payload()[_IPAACA_COMP_NOTIF_RECV_CATS] = recv_categories; out_buf->add(iu); + //LOG_IPAACA_CONSOLE( "Sending a ComponentNotify: " << name << " " << function << " " << current_state << " " << send_categories << " " << recv_categories ) } void ComponentNotifier::initialize() {