From 76b44902c2f6f8879456fe406d1a792ba381fce9 Mon Sep 17 00:00:00 2001 From: Graham Tremper Date: Mon, 4 Aug 2014 15:15:26 -0700 Subject: [PATCH] Created AutoNetExample Moved example from AutoNetTest --- .../AutoNetExample.cpp | 95 ++++++++----------- examples/CMakeLists.txt | 14 +++ src/autonet/test/AutoNetServerTest.hpp | 7 -- src/autonet/test/BreakpointTest.cpp | 47 +++++++++ src/autonet/test/CMakeLists.txt | 3 +- 5 files changed, 100 insertions(+), 66 deletions(-) rename src/autonet/test/AutoNetServerTest.cpp => examples/AutoNetExample.cpp (61%) delete mode 100644 src/autonet/test/AutoNetServerTest.hpp create mode 100644 src/autonet/test/BreakpointTest.cpp diff --git a/src/autonet/test/AutoNetServerTest.cpp b/examples/AutoNetExample.cpp similarity index 61% rename from src/autonet/test/AutoNetServerTest.cpp rename to examples/AutoNetExample.cpp index 8ca04af9c..8bc1dd658 100644 --- a/src/autonet/test/AutoNetServerTest.cpp +++ b/examples/AutoNetExample.cpp @@ -1,8 +1,21 @@ -#include "stdafx.h" -#include "AutoNetServerTest.hpp" -#include "AutoNetServer.h" -#include "Autowired.h" -#include THREAD_HEADER +// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. +#include +#include +#include +#include + +// +// AutoNetServer +// +// This example creates a sample context structure to view with the +// AutoNetVisualizer. It creates contexts and adds dummy context members +// at timed intervals to show off the dynamic nature of the visualizer. +// You can view the visualizer at leapmotion.github.io/autonet +// + +// +// Declaration of dummy classes to view in the visualizer +// class TestThread1: public CoreThread @@ -26,63 +39,38 @@ class ContextA {}; class ContextB {}; class ContextC {}; -class ExposedAutoNetServer: - public AutoNetServer -{ -public: - using AutoNetServer::HandleResumeFromBreakpoint; -}; -class BreakpointThread: - public BasicThread -{ - void Run(void) override { - Autowired 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 autonet; - auto autonetInternal = static_cast(autonet.get()); - autonetInternal->HandleResumeFromBreakpoint("Main"); - autonetInternal->HandleResumeFromBreakpoint("InThread"); - } -}; - -TEST_F(AutoNetServerTest, Breakpoint) { - AutoCurrentContext()->Initiate(); - AutoRequired autonet; - AutoRequired thread; - AutoRequired(); - - autonet->Breakpoint("Main"); -} - -TEST_F(AutoNetServerTest, SimpleTest) { +int main() { AutoGlobalContext global; auto ctxt = global->Create(); CurrentContextPusher pshr(ctxt); + // To use the visualizer, you just need to AutoRequire the AutoNetServer AutoRequired server; - ctxt->Initiate(); + // Initiate context to start threads + ctxt->Initiate(); + + // Create a bunch of example Contexts and Context Members auto ctxt2 = ctxt->Create(); auto ctxt3 = ctxt->Create(); - + ctxt2->Initiate(); - + + { + CurrentContextPusher pshr(ctxt3); + AutoRequired bar; + } + std::shared_ptr newContext; - + { CurrentContextPusher pshr(ctxt2); AutoRequired foo; + + // Give time to open AutoNet Visualizer + std::this_thread::sleep_for(std::chrono::seconds(10)); + *foo += std::chrono::seconds(1),[&ctxt]{ ctxt->Inject>(); }; @@ -114,15 +102,8 @@ TEST_F(AutoNetServerTest, SimpleTest) { ctxt3->SignalShutdown(true); ctxt3.reset(); }; - *foo += std::chrono::seconds(12), [&ctxt]{ - ctxt->SignalShutdown(); - }; - } - - { - CurrentContextPusher pshr(ctxt3); - AutoRequired bar; } + // This will wait indefinitly untill you manual quit the example ctxt->Wait(); -} +} \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a3b9058f4..164f33f70 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,3 +13,17 @@ set_property(TARGET EventExample PROPERTY FOLDER "Examples") add_executable(AutoFilterExample AutoFilterExample.cpp) target_link_libraries(AutoFilterExample Autowiring) set_property(TARGET AutoFilterExample PROPERTY FOLDER "Examples") + +find_package(Boost QUIET COMPONENTS system) +if(NOT Boost_FOUND) + message("Cannot build AutoNetExample, boost not installed on this system") + return() +endif() + +include_directories( + ${Boost_INCLUDE_DIR} +) + +add_executable(AutoNetExample AutoNetExample.cpp) +target_link_libraries(AutoNetExample Autowiring AutoNet) +set_property(TARGET AutoNetExample PROPERTY FOLDER "Examples") diff --git a/src/autonet/test/AutoNetServerTest.hpp b/src/autonet/test/AutoNetServerTest.hpp deleted file mode 100644 index 6240b8930..000000000 --- a/src/autonet/test/AutoNetServerTest.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. -#pragma once -#include - -class AutoNetServerTest: - public testing::Test -{}; diff --git a/src/autonet/test/BreakpointTest.cpp b/src/autonet/test/BreakpointTest.cpp new file mode 100644 index 000000000..991c389c3 --- /dev/null +++ b/src/autonet/test/BreakpointTest.cpp @@ -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 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 autonet; + auto autonetInternal = static_cast(autonet.get()); + autonetInternal->HandleResumeFromBreakpoint("Main"); + autonetInternal->HandleResumeFromBreakpoint("InThread"); + } +}; + +TEST_F(BreakpointTest, SimplePauseAndResume) { + AutoCurrentContext()->Initiate(); + AutoRequired autonet; + AutoRequired thread; + AutoRequired(); + + autonet->Breakpoint("Main"); +} diff --git a/src/autonet/test/CMakeLists.txt b/src/autonet/test/CMakeLists.txt index f7d1e95d5..e07c1170c 100644 --- a/src/autonet/test/CMakeLists.txt +++ b/src/autonet/test/CMakeLists.txt @@ -5,8 +5,7 @@ include_directories( set( AutoNetTest_SRCS - AutoNetServerTest.hpp - AutoNetServerTest.cpp + BreakpointTest.cpp gtest-all-guard.cpp )