Skip to content

Commit

Permalink
Merge pull request #925 from leapmotion/fix-922
Browse files Browse the repository at this point in the history
Forgot to register AutoNet for teardown and creation
  • Loading branch information
Jonathan Marsden committed May 5, 2016
2 parents c2dfc5b + a1f49c6 commit bfcc768
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
27 changes: 21 additions & 6 deletions src/autonet/AutoNetServerImpl.cpp
Expand Up @@ -20,7 +20,7 @@ AutoNetServerImpl::AutoNetServerImpl(void):
AutoNetServerImpl(std::unique_ptr<AutoNetTransportHttp>(new AutoNetTransportHttp))
{
auto* pCtxt = AutoCurrentContext().get();
pCtxt->newContext += [this] (CoreContext* pChild) { NewContext(*pChild); };
pCtxt->newContext += [this, pCtxt] (CoreContext* pChild) { NewContext(pCtxt, *pChild); };
pCtxt->expiredContext += [this, pCtxt] { ExpiredContext(*pCtxt); };
pCtxt->newObject += [this, pCtxt] (const CoreObjectDescriptor& desc) { NewObject(*pCtxt, desc); };
}
Expand Down Expand Up @@ -153,16 +153,27 @@ void AutoNetServerImpl::Breakpoint(std::string name){
}

// Update Functions
void AutoNetServerImpl::NewContext(CoreContext& newCtxt){
void AutoNetServerImpl::NewContext(CoreContext* pParent, CoreContext& newCtxt) {
auto ctxt = newCtxt.shared_from_this();

*this += [this, ctxt] {
// Need teardown and child creation notifications
newCtxt.newContext += [this, &newCtxt] (CoreContext* pChild) {
NewContext(&newCtxt, *pChild);
};
newCtxt.expiredContext += [this, &newCtxt] {
ExpiredContext(newCtxt);
};
newCtxt.newObject += [this, &newCtxt](const CoreObjectDescriptor& desc) {
NewObject(newCtxt, desc);
};

*this += [this, pParent, ctxt] {
Json::object context{
{"name", autowiring::demangle(ctxt->GetSigilType())}
};

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

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

SendMessage(hdl, "subscribed", types);

auto root = GetContext();
for (auto ctxt : ContextEnumerator{ GetContext() }) {
// Send update about this newly discovered context
NewContext(*ctxt);
NewContext(
ctxt == root ? nullptr : ctxt->GetParentContext().get(),
*ctxt
);

// Build total image of all objects, recursively:
for (const auto* pObj : ctxt->BuildObjectState())
Expand Down
5 changes: 3 additions & 2 deletions src/autonet/AutoNetServerImpl.hpp
Expand Up @@ -50,8 +50,9 @@ class AutoNetServerImpl:
/// <summary>
/// Updates server when a new context is created
/// </summary>
/// <param name="ctxt">The new context</param>
void NewContext(CoreContext& ctxt);
/// <param name="pParent">The parent context, or nullptr if one does not exist</param>
/// <param name="newCtxt">The new context</param>
void NewContext(CoreContext* pParent, CoreContext& newCtxt);

/// <summary>
/// Updates server when a context has expired
Expand Down

0 comments on commit bfcc768

Please sign in to comment.