Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AutoNet regression #924

Merged
merged 1 commit into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/autonet/AutoNetServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ void AutoNetServerImpl::NewContext(CoreContext& newCtxt){
{"name", autowiring::demangle(ctxt->GetSigilType())}
};

if(ctxt->GetParentContext()){
if(ctxt != GetContext() && ctxt->GetParentContext())
context["parent"] = ResolveContextID(ctxt->GetParentContext().get());
}

BroadcastMessage("newContext", ResolveContextID(ctxt.get()), context);
};
Expand Down Expand Up @@ -284,12 +283,19 @@ void AutoNetServerImpl::HandleSubscribe(websocketpp::connection_hdl hdl) {
}

SendMessage(hdl, "subscribed", types);
GetContext()->BuildCurrentState();

for (auto ctxt : ContextEnumerator{ GetContext() }) {
// Send update about this newly discovered context
NewContext(*ctxt);

// Build total image of all objects, recursively:
for (const auto* pObj : ctxt->BuildObjectState())
NewObject(*ctxt, *pObj);
}

// Send breakpoint message
for(const auto& breakpoint : m_breakpoints) {
for(const auto& breakpoint : m_breakpoints)
SendMessage(hdl, "breakpoint", breakpoint);
}
}

void AutoNetServerImpl::HandleUnsubscribe(websocketpp::connection_hdl hdl) {
Expand Down
5 changes: 5 additions & 0 deletions src/autonet/test/BreakpointTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class WaitsThenSimulatesResume:
}
};


struct MySigil {};

TEST_F(BreakpointTest, SimplePauseAndResume) {
AutoCreateContextT<MySigil> child;

AutoCurrentContext()->Initiate();
AutoRequired<ExposedAutoNetServer> autonet;
AutoRequired<BreakpointThread> thread;
Expand Down
23 changes: 6 additions & 17 deletions src/autowiring/CoreContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,25 +677,14 @@ AnySharedPointer CoreContext::Await(auto_id id, std::chrono::nanoseconds timeout
return memo.m_value;
}

void CoreContext::BuildCurrentState(void) {
auto glbl = GlobalCoreContext::Get();
if(m_pParent)
m_pParent->newContext(this);

// Enumerate objects injected into this context
for(auto& object : m_concreteTypes)
newObject(object);
std::vector<const autowiring::CoreObjectDescriptor*> CoreContext::BuildObjectState(void) const {
std::vector<const autowiring::CoreObjectDescriptor*> retVal;
retVal.reserve(m_concreteTypes.size());

// Recurse on all children
std::lock_guard<std::mutex> lk(m_stateBlock->m_lock);
for(const auto& c : m_children) {
auto cur = c.lock();
if(!cur)
continue;

// Recurse into the child instance:
cur->BuildCurrentState();
}
for(const auto& obj : m_concreteTypes)
retVal.push_back(&obj);
return retVal;
}

void CoreContext::Dump(std::ostream& os) const {
Expand Down
8 changes: 5 additions & 3 deletions src/autowiring/CoreContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,13 @@ class CoreContext:
return reg.m_value != nullptr;
}

/// \internal
/// <summary>
/// Sends AutowiringEvents to build current state.
/// Gets a snapshot of all of the objects currently in the context
/// </summary>
/// <summary>
/// The returned vector will only be valid for as long as this CoreContext is
/// </summary>
void BuildCurrentState(void);
std::vector<const autowiring::CoreObjectDescriptor*> BuildObjectState(void) const;

/// <summary>
/// A copy of the current list of child CoreRunnables of this context.
Expand Down