Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #19 from grf14003/dev
Version 1.0
  • Loading branch information
grf14003 committed May 9, 2020
2 parents 45c3a73 + c3619f3 commit 4c4fdc9
Show file tree
Hide file tree
Showing 265 changed files with 30,721 additions and 518 deletions.
10 changes: 6 additions & 4 deletions .gitignore
@@ -1,7 +1,9 @@
.vs/*

# Excluding the build and executable folders
breadcrumbs/build/*
!breadcrumbs/build/.blank
breadcrumbs/bin/*
!breadcrumbs/bin/.blank
bfs/build/*
!bfs/build/.blank
bfs/bin/*
!bfs/bin/.blank
*.log
*__pycache__*
File renamed without changes.
File renamed without changes.
177 changes: 177 additions & 0 deletions bfs/CMakeLists.txt
@@ -0,0 +1,177 @@
cmake_minimum_required (VERSION 2.6)

message("Starting CMAKE")
set(MSVC true)
project(Bfs)
string(TOLOWER ${PROJECT_NAME} ROOT_FOLDER_DIRNAME)
# The version number.
set (Bfs_VERSION_MAJOR 1)
set (Bfs_VERSION_MINOR 0)

# Setting paths
message("Setting paths...")
set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src) # Code directory
set(CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/build) # Object files and such (.o)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) # Compiled executables for execution and test (.exe)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin) # Compiled executables for execution and test (.exe)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin) # Compiled executables for execution and test (.exe)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) # Compiled libraries (.lib and .dll)
set(CMAKE_INCLUDE_PATH ${PROJECT_SOURCE_DIR}/include) # Publicly accessible header files
set(IMPLEMENATION_PATH ${PROJECT_SOURCE_DIR}/implementations)

message("Root directory: ${PROJECT_SOURCE_DIR}")
message("Source directory: ${CMAKE_SOURCE_DIR}")
message("Build directory: ${CMAKE_BINARY_DIR}")
message("Executable directory: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message("Library directory: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
message("")

# Including all tools
file(GLOB TOOL_INCLUDES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/tools/*")

# Adding tools
foreach(X IN LISTS TOOL_INCLUDES)
message("Including library with ${X}")
add_subdirectory(${X})
endforeach()

# Configure a header file to pass some of the CMake settings to the source code
set (Bfs_ALGORITHM_SERVER_PORT \"27634\")

configure_file (
"${PROJECT_SOURCE_DIR}/CMakeConfig.h.in"
"${CMAKE_INCLUDE_PATH}/CMakeConfig.h"
)

# Adding public includes to include search path
include_directories("${CMAKE_INCLUDE_PATH}")
# Adding private include files from source tree
include_directories("${CMAKE_SOURCE_DIR}")# Including dll header files
file(GLOB LIB_INCLUDES CONFIGURE_DEPENDS "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/*/")
foreach(X IN LISTS LIB_INCLUDES)
message("Including lib headers: ${X}")
include_directories(${X})
endforeach()

find_library(TactorInterface NAME TactorInterface.lib PATHS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ea_tdk)
find_library(TActionManager NAME TActionManager.lib PATHS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ea_tdk)

# puts all .cpp files inside src to the SOURCES variable
# TODO: replace this with a script for collecting cpp files
file(GLOB_RECURSE BFS_SOURCE CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/*.cpp")

file(GLOB IMPLEMENTAIONS CONFIGURE_DEPENDS "${IMPLEMENATION_PATH}/*/")
foreach(IMPL IN LISTS IMPLEMENTAIONS)

message("\n=== Starting implementation(${IMPL}) build... ===")
# Check if implementation config file exists
if(EXISTS "${IMPL}/CMakeLists.txt")
message("Found configuration file!")
add_subdirectory(${IMPL})
endif()

set(IMPL_ALGO_PATH ${IMPL}/algos) # BFS Implemenation algo source file path
set(IMPL_IO_PROCS_PATH ${IMPL}/io_procs)
set(IMPL_INCLUDE_PATH ${IMPL}/include)

message("Implementation algo directory: ${IMPL_ALGO_PATH}")
message("Implementation io_procs directory: ${IMPL_IO_PROCS_PATH}")
message("Implementation include directory: ${IMPL_INCLUDE_PATH}")
message("")

# Adding implementation include
include_directories("${IMPL_INCLUDE_PATH}")

set(Bfs_TEMP_ALGORITHM_CLIENT_LIMIT 20)

file(MAKE_DIRECTORY ${IMPL}/gen)

file(GLOB ALGOS_EXECS CONFIGURE_DEPENDS "${IMPL_ALGO_PATH}/*.cpp")
foreach(X IN LISTS ALGOS_EXECS)
get_filename_component(N ${X} NAME_WE)
set(Bfs_TEMP_ALGORITHM_NAME ${N})
message("Generating Algorithm main(): ${PROJECT_SOURCE_DIR}/${ROOT_FOLDER_DIRNAME}/gen/${N}.cpp")
configure_file("${CMAKE_SOURCE_DIR}/template/AlgorithmTemplate.cpp.in" ${IMPL}/gen/${N}.cpp)
endforeach()

file(GLOB IO_PROC_EXECS CONFIGURE_DEPENDS "${IMPL_IO_PROCS_PATH}/*.cpp")
foreach(X IN LISTS IO_PROC_EXECS)
get_filename_component(N ${X} NAME_WE)
set(Bfs_TEMP_IOPROC_NAME ${N})
message("Generating IO Processor main(): ${PROJECT_SOURCE_DIR}/${ROOT_FOLDER_DIRNAME}/gen/${N}.cpp")
configure_file("${CMAKE_SOURCE_DIR}/template/IOProcessorTemplate.cpp.in" ${IMPL}/gen/${N}.cpp)
endforeach()
message("")

# Compiling BFS implementation source files
file(GLOB_RECURSE IMPL_SRC CONFIGURE_DEPENDS "${IMPL}/*.cpp")
list(FILTER IMPL_SRC EXCLUDE REGEX "${IMPL}/gen/*")
list(FILTER IMPL_SRC EXCLUDE REGEX "${IMPL}/algos/*")
list(FILTER IMPL_SRC EXCLUDE REGEX "${IMPL}/io_procs/*")

# Getting template output files to create executables
file(GLOB IMPL_EXECS CONFIGURE_DEPENDS "${IMPL}/gen/*.cpp")

# Adding executables
# This is fine for now, but we may want to switch to a more manual versio so we can
# configure which files are included in which exe's
foreach(X IN LISTS IMPL_EXECS)
get_filename_component(N ${X} NAME_WE)
message(STATUS "Generating Executable: ${N}.exe Main File: ${X}")

# Including any DLLs or LIBs
set(ALL_LIBS "")
message("Libs Stored in ${N}_IMPL_DLLS: ${${N}_IMPL_LIBS}")
foreach(LIB_PATH IN ITEMS ${${N}_IMPL_LIBS})
set(LIB_ABS_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${LIB_PATH}")
if (IS_DIRECTORY ${LIB_ABS_PATH})
# Need to include all DLLs and LIBs in the directory
file(GLOB DLLS CONFIGURE_DEPENDS "${LIB_ABS_PATH}/*.dll")
file(GLOB LIBS CONFIGURE_DEPENDS "${LIB_ABS_PATH}/*.lib")
foreach(DLL IN ITEMS ${DLLS})
get_filename_component(DLL_N ${DLL} NAME)
message("Adding DLL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DLL_N}")
file(COPY ${DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endforeach()
foreach(LIB IN ITEMS ${LIBS})
get_filename_component(LIB_N ${LIB} NAME_WE)
find_library(${LIB_N} NAME ${LIB_N}.lib PATHS ${LIB})
message("Linking library: ${${LIB_N}}")
list(APPEND ALL_LIBS ${LIB_N})
endforeach()
else()
# Need to include just the given Library file (DLL or LIB)
get_filename_component(EXTENSION ${LIB_ABS_PATH} EXT)
if(${EXTENSION} STREQUAL ".dll")
get_filename_component(DLL_N ${LIB_ABS_PATH} NAME)
message("Adding DLL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DLL_N}")
configure_file(${LIB_ABS_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DLL_N} COPYONLY)
elseif(${EXTENSION} STREQUAL ".lib")
get_filename_component(LIB_N ${LIB_ABS_PATH} NAME_WE)
find_library(${LIB_N} NAME ${LIB_N}.lib PATHS ${LIB_ABS_PATH})
message("Linking library: ${${LIB_N}}")
list(APPEND ALL_LIBS ${LIB_N})
endif()
endif()
endforeach()

# Getting Algorithm or IO Processor implementation source file:
set(EXEC_IMPL_SRC_FILE "")
if(EXISTS ${IMPL}/algos/${N}.cpp)
set(EXEC_IMPL_SRC_FILE "${IMPL}/algos/${N}.cpp")
elseif(EXISTS ${IMPL}/io_procs/${N}.cpp)
set(EXEC_IMPL_SRC_FILE "${IMPL}/io_procs/${N}.cpp")
endif()

add_executable(${N} ${IMPL_SRC} ${EXEC_IMPL_SRC_FILE} ${X} ${BFS_SOURCE})

# Exe specialized libraries
foreach(LIB IN ITEMS ${ALL_LIBS})
target_link_libraries(${N} ${${LIB}})
endforeach()

# All exe's depend on tinyxmls
target_link_libraries(${N} tinyxml2)

endforeach()
endforeach()
10 changes: 8 additions & 2 deletions breadcrumbs/CMakeSettings.json → bfs/CMakeSettings.json
Expand Up @@ -10,7 +10,13 @@
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
"variables": [
{
"name": "CMAKE_INSTALL_PREFIX",
"value": "C:/Users/Greg/Documents/git/bfs/breadcrumbs/install/basic_build",
"type": "PATH"
}
]
}
]
}
}
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions bfs/config/config.txt
@@ -0,0 +1 @@
int i = 0
22 changes: 22 additions & 0 deletions bfs/config/sample_config_file.cfg
@@ -0,0 +1,22 @@
<?xml version = "1.0"?>
<algorithm>
<name>TestAlgo</name>
<type>Breadcrumbs</type>
<logger>
<level>4</level>
</logger>
</algorithm>
<io_processor>
<name>VirtualInputProcessor0</name>
<type>VirtualInputProcessor</type>
<logger>
<level>2</level>
</logger>
</io_processor>
<io_processor>
<name>VirtualOutputProcessor0</name>
<type>VirtualOutputProcessor</type>
<logger>
<level>1</level>
</logger>
</io_processor>
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions bfs/implementations/breadcrumbs/CMakeLists.txt
@@ -0,0 +1,4 @@

set (VirtualOutputIOProcessor_IMPL_LIBS
"ea_tdk"
PARENT_SCOPE)
27 changes: 27 additions & 0 deletions bfs/implementations/breadcrumbs/algos/AlgoBreadcrumbs.cpp
@@ -0,0 +1,27 @@

#include "AlgoBreadcrumbs.hpp"


void AlgoBreadcrumbs::loop()
{
int msgCount = 0;
Attribute msgCountAttrib = { "MSGCOUNT", sizeof(int), &msgCount };

map<string, Attribute> attribs = pollForAttributesMap();
if (attribs.size() > 0)
{
auto testKeyIter = attribs.find(string("testKey1"));
if (testKeyIter != attribs.end())
{
char value = *((char*) (*testKeyIter).second.getValue());
cout << "Test key 1 value updated to " << value << endl;
}

sendAttribute(msgCountAttrib);
}
}

bool AlgoBreadcrumbs::loopCondition()
{
return true;
}
@@ -1,13 +1,13 @@

#include <stdio.h>
#include "Config.hpp"

#include "AlgoBreadcrumbs.hpp"
#include "VirtualOutputProcessor.hpp"


int main()
{
Algorithm* algorithm = new AlgoBreadcrumbs(1);
Algorithm* algorithm = new AlgoBreadcrumbs(20);

// Loop
while (algorithm->loopCondition())
Expand Down
23 changes: 23 additions & 0 deletions bfs/implementations/breadcrumbs/gen/VirtualOutputIOProcessor.cpp
@@ -0,0 +1,23 @@

#include <iostream>

#include "DataSyncThread.hpp"
#include "VirtualOutputIOProcessor.hpp"


int main()
{
IOProcessor* client = new VirtualOutputIOProcessor;

if (!client->init())
{
while (client->loopCondition())
client->loop();

int result = client->close();
delete client;
return result;
}

return 0;
}
File renamed without changes.
@@ -0,0 +1,18 @@
#ifndef VIRTUAL_OUTPUT_IO_PROCESSOR_HPP
#define VIRTUAL_OUTPUT_IO_PROCESSOR_HPP

#include "IOProcessor.hpp"

class VirtualOutputIOProcessor : public IOProcessor
{
public:
using IOProcessor::IOProcessor;

void loop();
bool loopCondition();

private:
int iterations = 10;
};

#endif
@@ -0,0 +1,26 @@

#include "VirtualOutputIOProcessor.hpp"


void VirtualOutputIOProcessor::loop()
{
char testValue = 'a' + iterations;
Attribute attrib("testKey1", 1, &testValue);
getComms()->sendAttribute(attrib);

if (getComms()->areIncomingAttributesAvailable()) {
vector<Attribute> attribs = getComms()->getIncomingAttributes();
for (Attribute attr : attribs)
{
cout << "Attribute " << attr.getKey() << " received!" << endl;
}
}

Sleep(500);
iterations--;
}

bool VirtualOutputIOProcessor::loopCondition()
{
return iterations >= 0;
}
Expand Up @@ -12,6 +12,10 @@ public:

virtual void loop() = 0;
virtual bool loopCondition() { return false; };

vector<Attribute> pollForAttributes() { return server->getAllIncomingAttributes(); };
map<string, Attribute> pollForAttributesMap() { return server->getAllIncomingAttributesMap(); };
void sendAttribute(Attribute attrib) { server->sendAttributeToAll(attrib); };
private:
size_t numIoProcs = 0;
AlgorithmServer* server;
Expand Down

0 comments on commit 4c4fdc9

Please sign in to comment.