Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackcatn13 committed Oct 17, 2017
2 parents f3d7fe2 + 479672b commit d622a9f
Show file tree
Hide file tree
Showing 91 changed files with 96 additions and 10,624 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Python/pybind11"]
path = Python/pybind11
url = https://github.com/pybind/pybind11
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enable_testing()
set(CMAKE_CXX_STANDARD 14)
option(TOOLS "Build the given tools." ON)
option(TESTS "Build test program." OFF)
option(PYTHON "Build the python library." OFF)
option(PYTHON "Build the python library." ON)

set(CMAKE_CXX_FLAGS_PROFILE ${CMAKE_CXX_FLAGS} "-ggdb -Wall -std=c++14 -lpthread --coverage")
add_compile_options(-std=c++14)
Expand All @@ -27,6 +27,3 @@ endif(TOOLS)
if(TESTS)
add_subdirectory(Test)
endif(TESTS)
if(PYTHON)
add_subdirectory(Python)
endif(PYTHON)
4 changes: 3 additions & 1 deletion Lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ include_directories(../BundleAgent)
add_library(${LIBRARY_NAME} SHARED ${LIB_SOURCES})

install(TARGETS ${LIBRARY_NAME}
LIBRARY DESTINATION lib)
LIBRARY DESTINATION lib)

install(FILES ${LIB_HEADERS} DESTINATION include)
25 changes: 5 additions & 20 deletions Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
project(aDTNPlus)
cmake_minimum_required(VERSION 2.8.12)

set(Python_ADDITIONAL_VERSIONS 3.3 3.4 3.5 3.6 3.7)
if (NOT ${EXAMPLE_PYTHON_VERSION} STREQUAL "")
find_package(PythonLibs ${EXAMPLE_PYTHON_VERSION} EXACT)
if (NOT PythonLibs_FOUND)
find_package(PythonLibs ${EXAMPLE_PYTHON_VERSION} REQUIRED)
endif()
else()
find_package(PythonLibs REQUIRED)
endif()
string(REPLACE "+" "" PYTHONLIBS_VERSION_STRING "+${PYTHONLIBS_VERSION_STRING}")
project(aDTNPlus)

include_directories(${PYTHON_INCLUDE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/pybind11-1.2/include)
add_subdirectory(pybind11)
include_directories(../Lib)
include_directories(../BundleAgent)
add_library(aDTNPlus SHARED
aDTNPlusPython.cpp
)

set_target_properties(aDTNPlus PROPERTIES PREFIX "")
set_target_properties(aDTNPlus PROPERTIES SUFFIX ".so")
target_link_libraries(aDTNPlus aDTNLib Bundle_lib)
pybind11_add_module(aDTNPlus aDTNPlusPython.cpp)
target_link_libraries(aDTNPlus PRIVATE aDTNLib Bundle_lib)
117 changes: 28 additions & 89 deletions Python/aDTNPlusPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,10 @@
#include "Bundle/ForwardingMEB.h"
#include "Bundle/RoutingSelectionMEB.h"

PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);

/**
* Helper class to define a Block
*/
class PyBlock : public Block {
public:
using Block::Block;

std::string toRaw() {
PYBIND11_OVERLOAD_PURE(std::string, Block, toRaw);
}

std::string toString() {
PYBIND11_OVERLOAD_PURE(std::string, Block, toString);
}
};

PYBIND11_PLUGIN(aDTNPlus) {
pybind11::module m("aDTNPlus", "This module contains a library to interact "
"with the aDTNPlus platform.");
PYBIND11_MODULE(aDTNPlus, m) {
m.doc() =
"This module contains a library to interact with the aDTNPlus platform.";

pybind11::class_<adtnSocket>(m, "Socket")
.def(pybind11::init<std::string, int, bool>(), "Generates an adtnSocket, "
Expand Down Expand Up @@ -97,7 +80,16 @@ PYBIND11_PLUGIN(aDTNPlus) {
"the arrival and the depart time of the bundle in the different"
"node it travels.")
.def("getRoute", &adtnSocket::getRouteReporting, "If the last received "
"bundle contains a routeReporting MEB it will return the route.");
"bundle contains a routeReporting MEB it will return the route.")
.def("addFrameworkExtension", &adtnSocket::addFrameworkExtension, "Adds "
"a framework extension.\nIf the extension already exists it will "
"overwrite it, otherwise it will be created",
pybind11::arg("frameworkId"), pybind11::arg("extensionId"),
pybind11::arg("code"))
.def("getBundleState", &adtnSocket::getBundleState, "If the last "
"received bundle contains a Framework MEB it will return the "
"BundleState (a json in string format) of the given framework",
pybind11::arg("frameworkId"));

pybind11::class_<Bundle, std::shared_ptr<Bundle>>(m, "Bundle")
.def(pybind11::init<std::string>(), "", pybind11::arg("rawData"))
Expand Down Expand Up @@ -156,81 +148,28 @@ PYBIND11_PLUGIN(aDTNPlus) {
pybind11::enum_<MetadataTypes>(m, "MetadataTypes")
.value("ROUTING_SELECTION_MEB", MetadataTypes::ROUTING_SELECTION_MEB)
.value("FORWARDING_MEB", MetadataTypes::FORWARDING_MEB)
.value("ROUTE_REPORTING_MEB", MetadataTypes::ROUTE_REPORTING_MEB)
.value("CODE_DATA_CARRIER_MEB", MetadataTypes::CODE_DATA_CARRIER_MEB)
.value("FRAMEWORK_MEB", MetadataTypes::FRAMEWORK_MEB)
.export_values();

pybind11::enum_<RoutingAlgorithms>(m, "RoutingAlgorithms")
.value("ANTI_REBOTING", RoutingAlgorithms::ANTI_REBOTING)
.value("FLOODING", RoutingAlgorithms::FLOODING)
.export_values();

pybind11::class_<PyBlock, std::shared_ptr<PyBlock>> block(m, "Block");
block.alias<Block>()
.def(pybind11::init<std::string>(), "", pybind11::arg("rawData"))
.def(pybind11::init<>(), "")
.def_property_readonly("raw", &Block::getRaw, "")
.def("toRaw", &Block::toRaw, "")
.def("__str__", &Block::toString, "");

pybind11::class_<PrimaryBlock, std::shared_ptr<Block>>(m, "PrimaryBlock",
block)
.def(pybind11::init<std::string>(), "", pybind11::arg("rawData"))
.def(pybind11::init<std::string, std::string, uint64_t, uint64_t>(), "",
pybind11::arg("source"), pybind11::arg("destination"),
pybind11::arg("timestamp"), pybind11::arg("seqNumber"))
.def("set", &PrimaryBlock::setPrimaryProcFlag, "")
.def("unset", &PrimaryBlock::unsetPrimaryProcFlag, "")
.def("check", &PrimaryBlock::checkPrimaryProcFlag, "")
.def_property_readonly("destination", &PrimaryBlock::getDestination, "")
.def_property_readonly("source", &PrimaryBlock::getSource, "")
.def_property("reportTo", &PrimaryBlock::getReportTo,
&PrimaryBlock::setReportTo, "")
.def_property("custodian", &PrimaryBlock::getCustodian,
&PrimaryBlock::setCustodian, "")
.def_property_readonly("timestamp",
&PrimaryBlock::getCreationTimestamp, "")
.def_property("lifetime", &PrimaryBlock::getLifetime,
&PrimaryBlock::setLifetime, "")
.def_property_readonly("timestampSeqNumber",
&PrimaryBlock::getCreationTimestampSeqNumber, "");

pybind11::class_<CanonicalBlock, std::shared_ptr<Block>> canonicalBlock(m,
"CanonicalBlock", block);
canonicalBlock.def(pybind11::init<std::string>(), "",
pybind11::arg("rawData"))
.def(pybind11::init<>(), "")
.def_property_readonly("blockType", &CanonicalBlock::getBlockType)
.def("set", &CanonicalBlock::setProcFlag, "")
.def("unset", &CanonicalBlock::unsetProcFlag, "")
.def("check", &CanonicalBlock::checkProcFlag, "");

pybind11::class_<PayloadBlock, std::shared_ptr<Block>> payloadBlock(m,
"PayloadBlock", canonicalBlock);
payloadBlock.def(pybind11::init<std::string, bool>(), "",
pybind11::arg("payload"), pybind11::arg("isRaw") = false)
.def_property_readonly("payload", &PayloadBlock::getPayload, "");

pybind11::class_<MetadataExtensionBlock> metadata(m, "MetadataExtensionBlock",
canonicalBlock);
metadata.def(pybind11::init<uint8_t, std::string>(), "",
pybind11::arg("metadataType"), pybind11::arg("metadata"))
.def(pybind11::init<std::string>(), "", pybind11::arg("rawData"))
.def_property_readonly("type", &MetadataExtensionBlock::getMetadataType,
"")
.def_property_readonly("metadata", &MetadataExtensionBlock::getMetadata,
"");

pybind11::class_<ForwardingMEB, std::shared_ptr<Block>>(m,
"ForwardingMEB", metadata)
.def(pybind11::init<std::string, bool>(), "", pybind11::arg("softCode"),
pybind11::arg("isRaw") = false)
.def_property_readonly("softCode", &ForwardingMEB::getSoftCode, "");
pybind11::enum_<FrameworksIds>(m, "FrameworksIds")
.value("FIRST_FRAMEWORK", FrameworksIds::FIRST_FRAMEWORK)
.export_values();

pybind11::class_<RoutingSelectionMEB, std::shared_ptr<Block>>(m,
"RoutingSelectionMEB", metadata)
.def(pybind11::init<uint8_t>(), "", pybind11::arg("selection"))
.def(pybind11::init<std::string>(), "", pybind11::arg("rawData"))
.def_property_readonly("selection", &RoutingSelectionMEB::getSelection,
"");
return m.ptr();
pybind11::enum_<FirstFrameworkExtensionsIds>(m, "FirstFrameworkExtensionsIds")
.value("CONTAINER_CREATION",
FirstFrameworkExtensionsIds::CONTAINER_CREATION)
.value("CONTAINER_DELETION",
FirstFrameworkExtensionsIds::CONTAINER_DELETION)
.value("DESTINATION", FirstFrameworkExtensionsIds::DESTINATION)
.value("LIFETIME", FirstFrameworkExtensionsIds::LIFETIME)
.value("FORWARD", FirstFrameworkExtensionsIds::FORWARD)
.export_values();
}

1 change: 1 addition & 0 deletions Python/pybind11
Submodule pybind11 added at 6a81db
26 changes: 0 additions & 26 deletions Python/pybind11-1.2/.appveyor.yml

This file was deleted.

29 changes: 0 additions & 29 deletions Python/pybind11-1.2/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions Python/pybind11-1.2/.gitmodules

This file was deleted.

41 changes: 0 additions & 41 deletions Python/pybind11-1.2/.travis.yml

This file was deleted.

Loading

0 comments on commit d622a9f

Please sign in to comment.