Skip to content

Commit

Permalink
Merge pull request #852 from leapmotion/ref-standardincludes
Browse files Browse the repository at this point in the history
Standardize the Autowiring include structure
  • Loading branch information
Veronica Zheng committed Feb 26, 2016
2 parents 417eb33 + 16a79b3 commit 70dcf56
Show file tree
Hide file tree
Showing 180 changed files with 174 additions and 91 deletions.
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
include(AddPCH)
include(ConditionalSources)
include(InstallHeaders)

get_filename_component(AUTOWIRING_ROOT_DIR . ABSOLUTE)

Expand Down Expand Up @@ -157,14 +158,6 @@ install(FILES
COMPONENT autowiring
)

# Install public header files
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/autowiring
DESTINATION include
COMPONENT autowiring
FILES_MATCHING PATTERN "*.h"
)

# Install autoboost headers on ARM, which still requires them
if(CMAKE_COMPILER_IS_GNUCC AND ("${CMAKE_CXX_COMPILER}" MATCHES "androideabi"))
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
Expand Down
39 changes: 39 additions & 0 deletions cmake-modules/InstallHeaders.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Installs headers for the named target
# Syntax:
# install_headers TARGET <target> DESTINATION <destination> ...
#
# NOEXCLUDE_STDAFX Also install the precompiled header file
# <target> The target whose sources are to be installed
# <destination> The root of the destination folder where files will be copied
#
# Additional options are passed after FILES to the cmake install command
include(CMakeParseArguments)

function(install_headers)
set(options NOEXCLUDE_STDAFX)
set(oneValueArgs TARGET DESTINATION)
set(multiValueArgs)

cmake_parse_arguments(opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT opt_TARGET)
message(FATAL_ERROR "Cannot install files for a nonexistent target")
endif()

get_target_property(target_SRCS ${opt_TARGET} SOURCES)
foreach(src IN LISTS target_SRCS)
if(NOT ${opt_NOEXCLUDE_STDAFX} AND ${src} STREQUAL "stdafx.h")
continue()
endif()

get_filename_component(src_ext ${src} EXT)
if(src_ext STREQUAL ".h")
get_filename_component(src_rel ${src} DIRECTORY)
install(
FILES ${src}
DESTINATION ${opt_DESTINATION}/${src_rel}
${opt_UNPARSED_ARGUMENTS}
)
endif()
endforeach()
endfunction()
26 changes: 13 additions & 13 deletions examples/AutoNetExample.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#include <autowiring/Autowired.h>
#include <autowiring/AutoNetServer.h>
#include <autonet/AutoNetServer.h>
#include <iostream>
#include THREAD_HEADER

//
//
// 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
Expand Down Expand Up @@ -65,30 +65,30 @@ int main() {

// Initiate context to start threads
ctxt->Initiate();

// Create a bunch of example Contexts and Context Members
auto ctxt2 = ctxt->Create<ContextB>();
auto ctxt3 = ctxt->Create<ContextC>();

ctxt2->Initiate();

{
CurrentContextPusher pshr(ctxt3);
AutoRequired<TestThread2> bar;
}

std::shared_ptr<CoreContext> newContext;

{
CurrentContextPusher pshr(ctxt2);
AutoRequired<TestThread1> foo;

AutoRequired<TestAutoFilter<const TestData<0>&, TestData<1>&>> filter01;
AutoRequired<TestAutoFilter<const TestData<1>&, TestData<2>&>> filter12;

// Give time to open AutoNet Visualizer
std::this_thread::sleep_for(std::chrono::seconds(10));

*foo += std::chrono::seconds(1),[&ctxt]{
ctxt->Inject<ThisClassGetsAddedLater<4>>();
};
Expand Down
4 changes: 2 additions & 2 deletions scripts/copyright_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# Enforce LeapMotion copyright notice
#

ENFORCED_FILES="autowiring examples src"
ENFORCED_FILES="examples src"
COPYRIGHT_HEADER="// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved."

# Go to root directory
for f in $(find $ENFORCED_FILES -name *.hpp -o -name *.cpp -o -name *.h);
do
do
if [ "$(head -n 1 $f)" != "$COPYRIGHT_HEADER" ];
then
if [ "$BAD_FILES" == "" ]
Expand Down
4 changes: 2 additions & 2 deletions scripts/whitespace_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# Enforce spaces instead of tabs
#

ENFORCED_FILES="autowiring examples src CMakeLists.txt"
ENFORCED_FILES="examples src CMakeLists.txt"

# Go to root directory

if grep -qr $'\t' $ENFORCED_FILES
then
then
echo
echo "The Autowiring project prohibits tabs for spacing."
echo
Expand Down
7 changes: 4 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
include_directories(
# Need to make sure all of our tests can find gtest
${PROJECT_SOURCE_DIR}/contrib/gtest-1.7.0/fused-src
${PROJECT_SOURCE_DIR}/autowiring
${PROJECT_SOURCE_DIR}/src/autowiring
${PROJECT_SOURCE_DIR}/src/autotesting

# All projects in this folder have named access to other projects here
.
)

add_subdirectory(autonet)
add_subdirectory(autowiring)
add_subdirectory(autotesting)
add_subdirectory(benchmark)
28 changes: 14 additions & 14 deletions autowiring/AutoNetServer.h → src/autonet/AutoNetServer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#pragma once
#include "CoreThread.h"
#include "index_tuple.h"
#include <autowiring/CoreThread.h>
#include <autowiring/Decompose.h>
#include <autowiring/index_tuple.h>
#include <sstream>
#include STL_UNORDERED_MAP
#include FUNCTIONAL_HEADER
Expand Down Expand Up @@ -37,7 +37,7 @@ class AutoNetTransport {
/// Transmits the specified string message to the remote host
/// </summary>
virtual void Send(AutoNetTransportHandler::connection_hdl hdl, const std::string& msg) = 0;

/// <summary>
/// Assigns the handler for operations occuring on this transport
/// </summary>
Expand All @@ -63,7 +63,7 @@ class AutoNetServer:
static AutoNetServer* New(std::unique_ptr<AutoNetTransport> transport) {
return NewAutoNetServerImpl(std::move(transport));
}

static AutoNetServer* New(void) {
return NewAutoNetServerImpl();
}
Expand All @@ -73,7 +73,7 @@ class AutoNetServer:
/// </summary>
/// <param name="name">The identifier for this breakpoint</param>
virtual void Breakpoint(std::string name) = 0;

/// Add a custom event handler. Arguments must be primative types are strings
template<typename Fx>
void AddEventHandler(const std::string& event, Fx&& handler) {
Expand All @@ -84,24 +84,24 @@ class AutoNetServer:
typename make_index_tuple<Decompose<decltype(&Fx::operator())>::N>::type()
);
}

/// Send a custom event to all clients.
template<typename... Args>
void SendEvent(const std::string& event, Args... args) {
SendEvent(event, std::vector<std::string>{parseToString(args)...});
}

protected:
// Send event with arguments parsed as vector of string
virtual void SendEvent(const std::string& event, const std::vector<std::string>& args) = 0;

// Map of callbacks keyed by event type
std::unordered_map<std::string, std::vector<std::function<void(std::vector<std::string>)>>> m_handlers;

private:
// Add a handler that will be called when an event is received from the client
void AddEventHandlerInternal(const std::string& event, std::function<void(const std::vector<std::string>&)> handler);

// Extract arguments from list of strings, parse and pass to handler
template<typename Fx, typename... Args, int... N>
void AddEventHandler(const std::string& event, Fx&& handler, void (Fx::*pfn)(Args...) const, index_tuple<N...>) {
Expand All @@ -115,26 +115,26 @@ class AutoNetServer:
}
);
}

// parse type to string
template<class T>
std::string parseToString(const T& t){
std::ostringstream ss;
ss << t;
return ss.str();
}

// parse string to primative type
template<class T>
inline T parseFromString(const std::string& str){
std::istringstream ss(str);
typename std::decay<T>::type val;
ss >> std::boolalpha >> val;

if (ss.fail()) {
autowiring::ThrowFailedTypeParseException(str, typeid(T));
}

return val;
}
};
Expand Down
8 changes: 3 additions & 5 deletions src/autonet/AutoNetServerImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "AutoNetServerImpl.hpp"
#include "at_exit.h"
#include "autowiring.h"
#include <autowiring/autowiring.h>
#include <autowiring/at_exit.h>
#include <autowiring/demangle.h>
#include "AutoNetTransportHttp.hpp"
#include "demangle.h"
#include "CoreObjectDescriptor.h"
#include "TypeRegistry.h"
#include <iostream>
#include FUTURE_HEADER

Expand Down
4 changes: 3 additions & 1 deletion src/autonet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set(AutoNet_SRCS
)

# All include files are located in /autowiring from here, so prepend that to all sources
rewrite_header_paths(AutoNet_SRCS)
add_pch(AutoNet_SRCS "stdafx.h" "stdafx.cpp")

add_library(AutoNet STATIC ${AutoNet_SRCS})
Expand All @@ -27,6 +26,9 @@ add_subdirectory(test)
# Install library
#

# Install public header files
install_headers(TARGET AutoNet DESTINATION include/autonet COMPONENT autowiring)

if(NOT NO_INSTALL_AUTONET AND NOT AUTOWIRING_IS_EMBEDDED)
install(TARGETS AutoNet EXPORT AutowiringTargets
DESTINATION lib
Expand Down
4 changes: 2 additions & 2 deletions src/autonet/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define NOMINMAX
#endif

#include "AutowiringConfig.h"
#include <autowiring/AutowiringConfig.h>

// Defined when Autowiring is being built, as opposed to when it is being linked
#define AUTOWIRING_IS_BEING_BUILT
Expand All @@ -21,6 +21,6 @@
#endif

// C++11 glue logic, for platforms that have incomplete C++11 support
#include "C++11/cpp11.h"
#include <autowiring/C++11/cpp11.h>

#define ARRAYCOUNT(x) sizeof(ArraySize(x))
2 changes: 1 addition & 1 deletion src/autonet/test/AutoNetTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "gtest-all-guard.hpp"
#include <autotesting/gtest-all-guard.hpp>

int main(int argc, const char* argv []) {
return autotesting_main(argc, argv);
Expand Down
10 changes: 5 additions & 5 deletions src/autonet/test/BreakpointTest.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "src/autonet/AutoNetServerImpl.hpp"
#include "AutoNetServer.h"
#include "Autowired.h"
#include <autonet/AutoNetServer.h>
#include <autonet/AutoNetServerImpl.hpp>
#include <autowiring/autowiring.h>
#include THREAD_HEADER

class BreakpointTest:
Expand All @@ -12,7 +12,7 @@ class BreakpointTest:
class ExposedAutoNetServer:
public AutoNetServerImpl
{
public:
public:
void HandleResumeFromBreakpoint(const std::string& breakpoint) {
*this += [this, breakpoint] {
for (const auto& handler : this->m_handlers["resumeFromBreakpoint"]){
Expand Down Expand Up @@ -50,6 +50,6 @@ TEST_F(BreakpointTest, SimplePauseAndResume) {
AutoRequired<ExposedAutoNetServer> autonet;
AutoRequired<BreakpointThread> thread;
AutoRequired<WaitsThenSimulatesResume>();

autonet->Breakpoint("Main");
}
8 changes: 4 additions & 4 deletions src/autonet/test/RPCTest.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "AutoNetServer.h"
#include "src/autonet/AutoNetServerImpl.hpp"
#include "Autowired.h"
#include <autonet/AutoNetServer.h>
#include <autonet/AutoNetServerImpl.hpp>
#include <autowiring/autowiring.h>

class RPCTest:
public testing::Test
Expand All @@ -15,5 +15,5 @@ TEST_F(RPCTest, SimpleSend) {
}

TEST_F(RPCTest, SimpleReceive) {

}
Loading

0 comments on commit 70dcf56

Please sign in to comment.