Skip to content

Commit

Permalink
Adding life-cycle testing to AutoPacket. Presently, the lifecycle ass…
Browse files Browse the repository at this point in the history
…umptions are not satisfied.
  • Loading branch information
GabrielHare committed Jul 30, 2014
1 parent bb804e2 commit 441a2f9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
34 changes: 34 additions & 0 deletions autowiring/AutoPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -237,6 +247,12 @@ class AutoPacket:
/// </remarks>
template<class T>
AutoCheckout<T> Checkout(std::shared_ptr<T> 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<T>::type type;

Expand Down Expand Up @@ -290,6 +306,12 @@ class AutoPacket:
/// </remarks>
template<class T>
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<std::mutex> lk(m_lock);
Expand Down Expand Up @@ -328,6 +350,12 @@ class AutoPacket:
/// </remarks>
template<class T>
const T& Decorate(std::shared_ptr<T> t) {
if (!(debug_lifecycle == lifecycle_issued)) {
std::stringstream ss;
ss << "Decorate called in lifecycle: " << debug_lifecycle;
//throw std::runtime_error(ss.str());
}

Checkout<T>(t).Ready();
return *t;
}
Expand All @@ -346,6 +374,12 @@ class AutoPacket:
/// </remarks>
template<class... Ts>
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...};
Expand Down
32 changes: 30 additions & 2 deletions src/autowiring/AutoPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <iostream>

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())) {
Expand Down Expand Up @@ -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> AutoPacket::CreateObjectPool(AutoPacketFactory& factory) {
return ObjectPool<AutoPacket>(
Expand Down Expand Up @@ -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<std::mutex> lk(m_lock);
for(auto& satCounter : m_satCounters)
Expand All @@ -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<SatCounter*> callCounters;
for (auto& satCounter : m_satCounters)
Expand All @@ -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<SatCounter*> callQueue;
Expand Down

0 comments on commit 441a2f9

Please sign in to comment.