Skip to content

Commit bfcc768

Browse files
author
Jonathan Marsden
committed
Merge pull request #925 from leapmotion/fix-922
Forgot to register AutoNet for teardown and creation
2 parents c2dfc5b + a1f49c6 commit bfcc768

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/autonet/AutoNetServerImpl.cpp

+21-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ AutoNetServerImpl::AutoNetServerImpl(void):
2020
AutoNetServerImpl(std::unique_ptr<AutoNetTransportHttp>(new AutoNetTransportHttp))
2121
{
2222
auto* pCtxt = AutoCurrentContext().get();
23-
pCtxt->newContext += [this] (CoreContext* pChild) { NewContext(*pChild); };
23+
pCtxt->newContext += [this, pCtxt] (CoreContext* pChild) { NewContext(pCtxt, *pChild); };
2424
pCtxt->expiredContext += [this, pCtxt] { ExpiredContext(*pCtxt); };
2525
pCtxt->newObject += [this, pCtxt] (const CoreObjectDescriptor& desc) { NewObject(*pCtxt, desc); };
2626
}
@@ -153,16 +153,27 @@ void AutoNetServerImpl::Breakpoint(std::string name){
153153
}
154154

155155
// Update Functions
156-
void AutoNetServerImpl::NewContext(CoreContext& newCtxt){
156+
void AutoNetServerImpl::NewContext(CoreContext* pParent, CoreContext& newCtxt) {
157157
auto ctxt = newCtxt.shared_from_this();
158158

159-
*this += [this, ctxt] {
159+
// Need teardown and child creation notifications
160+
newCtxt.newContext += [this, &newCtxt] (CoreContext* pChild) {
161+
NewContext(&newCtxt, *pChild);
162+
};
163+
newCtxt.expiredContext += [this, &newCtxt] {
164+
ExpiredContext(newCtxt);
165+
};
166+
newCtxt.newObject += [this, &newCtxt](const CoreObjectDescriptor& desc) {
167+
NewObject(newCtxt, desc);
168+
};
169+
170+
*this += [this, pParent, ctxt] {
160171
Json::object context{
161172
{"name", autowiring::demangle(ctxt->GetSigilType())}
162173
};
163174

164-
if(ctxt != GetContext() && ctxt->GetParentContext())
165-
context["parent"] = ResolveContextID(ctxt->GetParentContext().get());
175+
if(pParent)
176+
context["parent"] = ResolveContextID(pParent);
166177

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

285296
SendMessage(hdl, "subscribed", types);
286297

298+
auto root = GetContext();
287299
for (auto ctxt : ContextEnumerator{ GetContext() }) {
288300
// Send update about this newly discovered context
289-
NewContext(*ctxt);
301+
NewContext(
302+
ctxt == root ? nullptr : ctxt->GetParentContext().get(),
303+
*ctxt
304+
);
290305

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

src/autonet/AutoNetServerImpl.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ class AutoNetServerImpl:
5050
/// <summary>
5151
/// Updates server when a new context is created
5252
/// </summary>
53-
/// <param name="ctxt">The new context</param>
54-
void NewContext(CoreContext& ctxt);
53+
/// <param name="pParent">The parent context, or nullptr if one does not exist</param>
54+
/// <param name="newCtxt">The new context</param>
55+
void NewContext(CoreContext* pParent, CoreContext& newCtxt);
5556

5657
/// <summary>
5758
/// Updates server when a context has expired

0 commit comments

Comments
 (0)