diff --git a/autowiring/AutoPacket.h b/autowiring/AutoPacket.h index 94ceeaf13..1156227e7 100644 --- a/autowiring/AutoPacket.h +++ b/autowiring/AutoPacket.h @@ -40,6 +40,16 @@ class AutoPacket: AutoPacket(const AutoPacket& rhs) = delete; AutoPacket(AutoPacketFactory& factory); + //DEBUG BEGIN: Verify adherence to life plans + //QUESTION: Does this need to be promoted to a condition + //for calling Finalize in the destructor? + int debug_lifecycle; + static const int lifecycle_construct = 0; + static const int lifecycle_inpool = 1; + static const int lifecycle_issued = 2; + static const int lifecycle_destruct = 3; + //DEBUG END + public: ~AutoPacket(void); @@ -237,6 +247,12 @@ class AutoPacket: /// template AutoCheckout Checkout(std::shared_ptr ptr) { + if (!(debug_lifecycle == lifecycle_issued)) { + std::stringstream ss; + ss << "Checkout called in lifecycle: " << debug_lifecycle; + //throw std::runtime_error(ss.str()); + } + // This allows us to install correct entries for decorated input requests typedef typename subscriber_traits::type type; @@ -290,6 +306,12 @@ class AutoPacket: /// template void Unsatisfiable(void) { + if (!(debug_lifecycle == lifecycle_issued)) { + std::stringstream ss; + ss << "Unsatisfiable called in lifecycle: " << debug_lifecycle; + //throw std::runtime_error(ss.str()); + } + { // Insert a null entry at this location: std::lock_guard lk(m_lock); @@ -328,6 +350,12 @@ class AutoPacket: /// template const T& Decorate(std::shared_ptr t) { + if (!(debug_lifecycle == lifecycle_issued)) { + std::stringstream ss; + ss << "Decorate called in lifecycle: " << debug_lifecycle; + //throw std::runtime_error(ss.str()); + } + Checkout(t).Ready(); return *t; } @@ -346,6 +374,12 @@ class AutoPacket: /// template void DecorateImmediate(const Ts&... immeds) { + if (!(debug_lifecycle == lifecycle_issued)) { + std::stringstream ss; + ss << "DecorateImmediate called in lifecycle: " << debug_lifecycle; + //throw std::runtime_error(ss.str()); + } + // These are the things we're going to be working with while we perform immediate decoration: static const std::type_info* sc_typeInfo [] = {&typeid(Ts)...}; const void* pvImmeds[] = {&immeds...}; diff --git a/src/autowiring/AutoPacket.cpp b/src/autowiring/AutoPacket.cpp index 3df126b70..303eb1779 100644 --- a/src/autowiring/AutoPacket.cpp +++ b/src/autowiring/AutoPacket.cpp @@ -10,7 +10,7 @@ #include -AutoPacket::AutoPacket(AutoPacketFactory& factory) +AutoPacket::AutoPacket(AutoPacketFactory& factory) : debug_lifecycle(0) { // Traverse all contexts, adding their packet subscriber vectors one at a time: for(const auto& curContext : ContextEnumerator(factory.GetContext())) { @@ -59,7 +59,15 @@ AutoPacket::AutoPacket(AutoPacketFactory& factory) // This must appear in .cpp in order to avoid compilation failure due to: // "Arithmetic on a point to an incomplete type 'SatCounter'" -AutoPacket::~AutoPacket() {} +AutoPacket::~AutoPacket() { + if (debug_lifecycle == lifecycle_issued) { + std::cout << "Destruct before Finalize!" << std::endl; + } + if (debug_lifecycle == lifecycle_destruct) { + throw std::runtime_error("Destruct called Twice!"); + } + debug_lifecycle = 3; +} ObjectPool AutoPacket::CreateObjectPool(AutoPacketFactory& factory) { return ObjectPool( @@ -145,6 +153,13 @@ void AutoPacket::PulseSatisfaction(DecorationDisposition* pTypeSubs[], size_t nI } void AutoPacket::Reset(void) { + if (!(debug_lifecycle == lifecycle_construct || debug_lifecycle == lifecycle_issued)) { + std::stringstream ss; + ss << "Reset called in lifecycle: " << debug_lifecycle; + //throw std::runtime_error(ss.str()); + } + debug_lifecycle = lifecycle_inpool; + // Initialize all counters: std::lock_guard lk(m_lock); for(auto& satCounter : m_satCounters) @@ -156,6 +171,13 @@ void AutoPacket::Reset(void) { } void AutoPacket::Initialize(void) { + if (!(debug_lifecycle == lifecycle_inpool)) { + std::stringstream ss; + ss << "Initialize called in lifecycle: " << debug_lifecycle; + //throw std::runtime_error(ss.str()); + } + debug_lifecycle = lifecycle_issued; + // Find all subscribers with no required or optional arguments: std::list callCounters; for (auto& satCounter : m_satCounters) @@ -172,6 +194,12 @@ void AutoPacket::Initialize(void) { } void AutoPacket::Finalize(void) { + if (!(debug_lifecycle == lifecycle_issued)) { + std::stringstream ss; + ss << "Finalize called in lifecycle: " << debug_lifecycle; + //throw std::runtime_error(ss.str()); + } + // Queue calls to ensure that calls to Decorate inside of AutoFilter methods // will NOT effect the resolution of optional arguments. std::list callQueue;