-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from leapmotion/example-autonet
AutoNet and AutoFilter examples
- Loading branch information
Showing
7 changed files
with
154 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,51 @@ | ||
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. | ||
#include <autowiring/Autowired.h> | ||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
|
||
// | ||
// AutoFilter | ||
// | ||
// AutoFilter provides a declarative way to to create a filter graph network | ||
// within a context. Packets on this network have the same domain as events | ||
// (snooping works with packets as well). An AutoFilter is made by creating | ||
// a ContextMember that implements the AutoFilter(...) member function. | ||
// | ||
|
||
class StringFilter { | ||
public: | ||
void AutoFilter(std::string msg) { | ||
std::cout << "Filter Update: " << msg << std::endl; | ||
} | ||
}; | ||
|
||
class StringIntFilter { | ||
public: | ||
void AutoFilter(std::string msg, int num) { | ||
std::cout << "Other Filter Update: " << msg << " : " << num << std::endl; | ||
} | ||
}; | ||
|
||
int main() { | ||
std::cout << "Hello World" << std::endl; | ||
} | ||
// Initiate the current context | ||
AutoCurrentContext()->Initiate(); | ||
|
||
// Inject our AutoFilter enabled context members into the context | ||
AutoRequired<StringFilter>(); | ||
AutoRequired<StringIntFilter>(); | ||
|
||
// Each context automatically includes an AutoPacketFactory type. This | ||
// can be used to create new packets in the AutoFilter network | ||
Autowired<AutoPacketFactory> factory; | ||
|
||
// When decorating a packet, all AutoFilters that have that type as an argument | ||
// will be called. It is only called when all argument types have been decorated | ||
auto packet = factory->NewPacket(); | ||
|
||
packet->Decorate(std::string("Hello World")); | ||
|
||
std::cout << "StringIntFilter not called yet" << std::endl; | ||
|
||
// StringIntFilter will now be called since all AutoFilter arguments have ben decorated | ||
packet->Decorate(42); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "stdafx.h" | ||
#include "AutoNetServer.h" | ||
#include "Autowired.h" | ||
#include THREAD_HEADER | ||
|
||
class BreakpointTest: | ||
public testing::Test | ||
{}; | ||
|
||
class ExposedAutoNetServer: | ||
public AutoNetServer | ||
{ | ||
public: | ||
using AutoNetServer::HandleResumeFromBreakpoint; | ||
}; | ||
|
||
class BreakpointThread: | ||
public BasicThread | ||
{ | ||
void Run(void) override { | ||
Autowired<AutoNetServer> autonet; | ||
autonet->Breakpoint("InThread"); | ||
std::cout << "Thread finished" << std::endl; | ||
} | ||
}; | ||
|
||
class WaitsThenSimulatesResume: | ||
public BasicThread | ||
{ | ||
void Run(void) override { | ||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
|
||
AutowiredFast<AutoNetServer> autonet; | ||
auto autonetInternal = static_cast<ExposedAutoNetServer*>(autonet.get()); | ||
autonetInternal->HandleResumeFromBreakpoint("Main"); | ||
autonetInternal->HandleResumeFromBreakpoint("InThread"); | ||
} | ||
}; | ||
|
||
TEST_F(BreakpointTest, SimplePauseAndResume) { | ||
AutoCurrentContext()->Initiate(); | ||
AutoRequired<AutoNetServer> autonet; | ||
AutoRequired<BreakpointThread> thread; | ||
AutoRequired<WaitsThenSimulatesResume>(); | ||
|
||
autonet->Breakpoint("Main"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.