Skip to content

Commit

Permalink
All gateway public functions have been declared for export, gateway l…
Browse files Browse the repository at this point in the history
…ibrary is created as a DLL. All tests pass and samples run.

Pulled in latest submodules, now I can build shared DLLs for iothub and C-shared.

Gateway app can build with a relatively simple cmake file.

Install the files in the binary dir, rather than making it a function.
  • Loading branch information
darobs committed Dec 19, 2016
1 parent a614e6a commit 01edca8
Show file tree
Hide file tree
Showing 54 changed files with 239 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,5 @@ browse.VC.db
api_reference/

# install prefix
install-deps/
install-deps/
Testing/Temporary/CTestCostData.txt
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "deps/azure-c-shared-utility"]
path = deps/c-utility
url = https://github.com/Azure/azure-c-shared-utility
[submodule "deps/azure-iot-sdks"]
path = deps/iot-sdk
url = https://github.com/azure/azure-iot-sdks
[submodule "deps/parson"]
path = deps/parson
url = https://github.com/kgabis/parson
Expand All @@ -25,3 +22,6 @@
[submodule "deps/umqtt"]
path = deps/umqtt
url = https://github.com/azure/azure-umqtt-c
[submodule "deps/iot-sdk-c"]
path = deps/iot-sdk-c
url = https://github.com/Azure/azure-iot-sdk-c.git
58 changes: 51 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ else()
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

# tests and samples should use pre-install path to gateway.so
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${CMAKE_CURRENT_BINARY_DIR}/core/)

#the following variables are project-wide and can be used with cmake-gui
option(skip_unittests "set skip_unittests to ON to skip unittests (default is OFF)[if possible, they are always built]" OFF)
option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF) [if possible, they are always built]" OFF)
option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF)
option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF) " OFF)
option(nuget_e2e_tests "" OFF)
option(install_executables "should cmake run cmake's install function (that includes dynamic link libraries) [it does for yocto]" OFF)
option(install_modules "should cmake install the default gateway modules" OFF)
option(enable_java_binding "set enable_java_binding to ON to enable building of Java binding (default is OFF)" OFF)
Expand All @@ -51,6 +55,7 @@ option(use_amqp "set use_amqp to ON if amqp is to be used, set to OFF to not use
option(use_http "set use_http to ON if http is to be used, set to OFF to not use http" ON)
option(use_mqtt "set use_mqtt to ON if mqtt is to be used, set to OFF to not use mqtt" ON)


SET(use_condition ON CACHE BOOL "Build C shared utility with condition code" FORCE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Expand Down Expand Up @@ -120,11 +125,9 @@ endfunction()

function(add_sample_to_solution sampleName)
set_target_properties(${sampleName} PROPERTIES FOLDER "Samples")
#if(DEFINED ${dependency_install_prefix})
set_target_properties(${sampleName} PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
)
#endif()
set_target_properties(${sampleName} PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
)
endfunction()


Expand Down Expand Up @@ -184,6 +187,46 @@ function(install_broker whatIsBuilding whatIsBuildingLocation)
endif()
endfunction(install_broker)

set(preinstall_gateway_library_dll ${CMAKE_CURRENT_BINARY_DIR}/core/$(Configuration)/gateway.dll)

function(copy_gateway_dll whatIsBuilding whatIsBuildingLocation)
if(WIN32)
add_custom_command(TARGET ${whatIsBuilding} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${preinstall_gateway_library_dll}
${whatIsBuildingLocation})
if(EXISTS "${azure_c_shared_utility_DIR}/../bin/${SHARED_UTIL_LIB}.dll")
add_custom_command(TARGET ${whatIsBuilding} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${azure_c_shared_utility_DIR}/../bin/${SHARED_UTIL_LIB}.dll"
${whatIsBuildingLocation})
endif()


endif()
endfunction(copy_gateway_dll)

function(copy_iothub_client_dll whatIsBuilding whatIsBuildingLocation)
if(WIN32)
if(EXISTS "${azure_iot_sdks_DIR}/../bin/iothub_client.dll")
add_custom_command(TARGET ${whatIsBuilding} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${azure_iot_sdks_DIR}/../bin/iothub_client.dll"
${whatIsBuildingLocation})
endif()
endif()
endfunction(copy_iothub_client_dll)

function(copy_iothub_service_dll whatIsBuilding whatIsBuildingLocation)
if(WIN32)
if(EXISTS "${azure_iot_sdks_DIR}/../bin/iothub_service_client.dll")
add_custom_command(TARGET ${whatIsBuilding} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${azure_iot_sdks_DIR}/../bin/iothub_service_client.dll"
${whatIsBuildingLocation})
endif()
endif()
endfunction(copy_iothub_service_dll)

if(${ARCHITECTURE} STREQUAL "x86_64")
set(dotnet_managed_binding_dll ${CMAKE_CURRENT_BINARY_DIR}/../bindings/dotnet/dotnet-binding/Microsoft.Azure.IoT.Gateway/bin/x64/$(Configuration)/Microsoft.Azure.IoT.Gateway.dll CACHE INTERNAL "The location of the Microsoft.Azure.IoT.Gateway.dll (windows)" FORCE)
Expand All @@ -193,6 +236,7 @@ if(${ARCHITECTURE} STREQUAL "x86_64")
set(dotnet_sensor_module_dll ${CMAKE_CURRENT_BINARY_DIR}/../bindings/dotnet/dotnet-binding/SensorModule/bin/x64/$(Configuration)/SensorModule.dll CACHE INTERNAL "The location of the SensorModule.dll (windows)" FORCE)

set(dotnet_printer_module_dll ${CMAKE_CURRENT_BINARY_DIR}/../bindings/dotnet/dotnet-binding/PrinterModule/bin/x64/$(Configuration)/PrinterModule.dll CACHE INTERNAL "The location of the PrinterModule.dll (windows)" FORCE)

elseif(${ARCHITECTURE} STREQUAL "x86")
set(dotnet_managed_binding_dll ${CMAKE_CURRENT_BINARY_DIR}/../bindings/dotnet/dotnet-binding/Microsoft.Azure.IoT.Gateway/bin/x86/$(Configuration)/Microsoft.Azure.IoT.Gateway.dll CACHE INTERNAL "The location of the Microsoft.Azure.IoT.Gateway.dll (windows)" FORCE)

Expand Down
2 changes: 1 addition & 1 deletion bindings/dotnet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ target_link_libraries(dotnet_static gateway mscoree)
linkSharedUtil(dotnet)
linkSharedUtil(dotnet_static)

if(NOT ${skip_unittests})
if(${run_unittests})
add_subdirectory(tests)
endif()

Expand Down
1 change: 1 addition & 0 deletions bindings/dotnet/tests/dotnet_e2e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if(TARGET ${theseTestsName}_exe)
add_dependencies(${theseTestsName}_exe dotnet)

install_broker(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) )
copy_gateway_dll(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) )
install_binaries(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) ${dotnet_managed_binding_dll} )
install_binaries(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) ${dotnet_e2etest_module_dll} )
install_binaries(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) ${dotnet_host_binding_dll} )
Expand Down
2 changes: 1 addition & 1 deletion bindings/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ linkSharedUtil(java_module_host_static)
add_binding_to_solution(java_module_host)
add_binding_to_solution(java_module_host_static)

if(NOT ${skip_unittests})
if(${run_unittests})
add_subdirectory(tests)
endif()

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ target_include_directories(nodejs_binding_static PUBLIC $ENV{NODE_INCLUDE})
add_binding_to_solution(nodejs_binding)
add_binding_to_solution(nodejs_binding_static)

if(NOT ${skip_unittests})
if(${run_unittests})
add_subdirectory(tests)
endif()

Expand Down
5 changes: 5 additions & 0 deletions bindings/nodejs/tests/nodejs_int/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ target_link_libraries(${theseTestsName}_exe ${LIBS})
target_include_directories(nodejs_binding_static PUBLIC $ENV{NODE_INCLUDE})
install_broker(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) )
copy_node_dll(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) )
copy_gateway_dll(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) )

set_target_properties(${theseTestsName}_exe PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
)

if(WIN32)
target_include_directories(
Expand Down
21 changes: 18 additions & 3 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ set(gateway_h_sources
./inc/module_access.h
./inc/experimental/event_system.h
./inc/gateway.h
./inc/gateway_export.h
./inc/gateway_version.h
./inc/module_loader.h
./inc/dynamic_library.h
./src/gateway_internal.h
../deps/parson/parson.h
)

# Add the module loaders
Expand Down Expand Up @@ -140,31 +142,44 @@ endif()

include_directories(./inc)

add_library(gateway
add_library(gateway SHARED
${gateway_c_sources}
${gateway_h_sources}
)

add_library(gateway_static STATIC
${gateway_c_sources}
${gateway_h_sources}
)

if(WIN32)
target_link_libraries(gateway parson nanomsg aziotsharedutil ${dynamic_loader_library})
target_link_libraries(gateway_static parson nanomsg aziotsharedutil ${dynamic_loader_library})
else()
target_link_libraries(gateway parson nanomsg aziotsharedutil ${dynamic_loader_library})

target_link_libraries(gateway ${NN_REQUIRED_LIBRARIES})
target_link_libraries(gateway m)

target_link_libraries(gateway_static parson nanomsg aziotsharedutil ${dynamic_loader_library})

target_link_libraries(gateway_static ${NN_REQUIRED_LIBRARIES})
target_link_libraries(gateway_static m)
endif()

if(WIN32)
target_link_libraries(gateway rpcrt4.lib)
target_link_libraries(gateway_static rpcrt4.lib)
else()
find_package(PkgConfig REQUIRED)
pkg_search_module(UIDLINUX REQUIRED uuid)

target_link_libraries(gateway uuid)
target_link_libraries(gateway_static uuid)
endif()

#this adds the tests to the build process
if(NOT ${skip_unittests})
if(${run_unittests})
add_subdirectory(tests)
endif()

Expand Down Expand Up @@ -197,7 +212,7 @@ else()
set(AIG_INCLUDE_DIRS ${AIG_HEADER_INSTALL_PREFIX})
endif()

install(TARGETS gateway EXPORT gatewayTargets
install(TARGETS gateway gateway_static EXPORT gatewayTargets
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${LIB_INSTALL_DIR}/../bin
Expand Down
17 changes: 17 additions & 0 deletions core/azure_iot_gateway_sdkConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ else()
link_directories("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()

# install required gateway DLLs to current project
if (WIN32)
file(
INSTALL
"${azure_iot_gateway_sdk_DIR}/../bin/gateway.dll"
DESTINATION
"${CMAKE_CURRENT_BINARY_DIR}"
)

file(
INSTALL
"${azure_c_shared_utility_DIR}/../bin/aziotsharedutil.dll"
DESTINATION
"${CMAKE_CURRENT_BINARY_DIR}"
)
endif()

link_directories("${CMAKE_CURRENT_LIST_DIR}/../lib")

include("${CMAKE_CURRENT_LIST_DIR}/azure_iot_gateway_sdkTargets.cmake")
19 changes: 10 additions & 9 deletions core/inc/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef struct BROKER_HANDLE_DATA_TAG* BROKER_HANDLE;
#include "azure_c_shared_utility/macro_utils.h"
#include "message.h"
#include "module.h"
#include "gateway_export.h"

#ifdef __cplusplus
#include <cstddef>
Expand Down Expand Up @@ -56,7 +57,7 @@ DEFINE_ENUM(BROKER_RESULT, BROKER_RESULT_VALUES);
*
* @return A valid #BROKER_HANDLE upon success, or @c NULL upon failure.
*/
extern BROKER_HANDLE Broker_Create(void);
GATEWAY_EXPORT BROKER_HANDLE Broker_Create(void);

/** @brief Increments the reference count of a message broker.
*
Expand All @@ -65,7 +66,7 @@ extern BROKER_HANDLE Broker_Create(void);
*
* @param broker The #BROKER_HANDLE to be cloned.
*/
extern void Broker_IncRef(BROKER_HANDLE broker);
GATEWAY_EXPORT void Broker_IncRef(BROKER_HANDLE broker);

/** @brief Decrements the reference count of a message broker.
*
Expand All @@ -75,7 +76,7 @@ extern void Broker_IncRef(BROKER_HANDLE broker);
*
* @param broker The #BROKER_HANDLE whose ref count will be decremented.
*/
extern void Broker_DecRef(BROKER_HANDLE broker);
GATEWAY_EXPORT void Broker_DecRef(BROKER_HANDLE broker);

/** @brief Publishes a message to the message broker.
*
Expand All @@ -93,7 +94,7 @@ extern void Broker_DecRef(BROKER_HANDLE broker);
*
* @return A #BROKER_RESULT describing the result of the function.
*/
extern BROKER_RESULT Broker_Publish(BROKER_HANDLE broker, MODULE_HANDLE source, MESSAGE_HANDLE message);
GATEWAY_EXPORT BROKER_RESULT Broker_Publish(BROKER_HANDLE broker, MODULE_HANDLE source, MESSAGE_HANDLE message);

/** @brief Adds a module to the message broker.
*
Expand All @@ -108,7 +109,7 @@ extern BROKER_RESULT Broker_Publish(BROKER_HANDLE broker, MODULE_HANDLE source,
*
* @return A #BROKER_RESULT describing the result of the function.
*/
extern BROKER_RESULT Broker_AddModule(BROKER_HANDLE broker, const MODULE* module);
GATEWAY_EXPORT BROKER_RESULT Broker_AddModule(BROKER_HANDLE broker, const MODULE* module);

/** @brief Removes a module from the message broker.
*
Expand All @@ -117,7 +118,7 @@ extern BROKER_RESULT Broker_AddModule(BROKER_HANDLE broker, const MODULE* module
*
* @return A #BROKER_RESULT describing the result of the function.
*/
extern BROKER_RESULT Broker_RemoveModule(BROKER_HANDLE broker, const MODULE* module);
GATEWAY_EXPORT BROKER_RESULT Broker_RemoveModule(BROKER_HANDLE broker, const MODULE* module);

/** @brief Adds a route to the message broker.
*
Expand All @@ -132,7 +133,7 @@ extern BROKER_RESULT Broker_RemoveModule(BROKER_HANDLE broker, const MODULE* mod
*
* @return A #BROKER_RESULT describing the result of the function.
*/
extern BROKER_RESULT Broker_AddLink(BROKER_HANDLE broker, const BROKER_LINK_DATA* link);
GATEWAY_EXPORT BROKER_RESULT Broker_AddLink(BROKER_HANDLE broker, const BROKER_LINK_DATA* link);

/** @brief Removes a route from the message broker.
*
Expand All @@ -141,13 +142,13 @@ extern BROKER_RESULT Broker_AddLink(BROKER_HANDLE broker, const BROKER_LINK_DATA
*
* @return A #BROKER_RESULT describing the result of the function.
*/
extern BROKER_RESULT Broker_RemoveLink(BROKER_HANDLE broker, const BROKER_LINK_DATA* link);
GATEWAY_EXPORT BROKER_RESULT Broker_RemoveLink(BROKER_HANDLE broker, const BROKER_LINK_DATA* link);

/** @brief Disposes of resources allocated by a message broker.
*
* @param broker The #BROKER_HANDLE to be destroyed.
*/
extern void Broker_Destroy(BROKER_HANDLE broker);
GATEWAY_EXPORT void Broker_Destroy(BROKER_HANDLE broker);

#ifdef __cplusplus
}
Expand Down
15 changes: 8 additions & 7 deletions core/inc/experimental/event_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define EVENT_SYSTEM_H

#include "gateway.h"
#include "gateway_export.h"

#ifdef __cplusplus
extern "C"
Expand Down Expand Up @@ -72,10 +73,10 @@ typedef void* GATEWAY_EVENT_CTX;
*/
typedef void(*GATEWAY_CALLBACK)(GATEWAY_HANDLE gateway, GATEWAY_EVENT event_type, GATEWAY_EVENT_CTX context, void* user_param);

extern EVENTSYSTEM_HANDLE EventSystem_Init(void);
extern void EventSystem_AddEventCallback(EVENTSYSTEM_HANDLE event_system, GATEWAY_EVENT event_type, GATEWAY_CALLBACK callback, void* user_param);
extern void EventSystem_ReportEvent(EVENTSYSTEM_HANDLE event_system, GATEWAY_HANDLE gw, GATEWAY_EVENT event_type);
extern void EventSystem_Destroy(EVENTSYSTEM_HANDLE event_system);
GATEWAY_EXPORT EVENTSYSTEM_HANDLE EventSystem_Init(void);
GATEWAY_EXPORT void EventSystem_AddEventCallback(EVENTSYSTEM_HANDLE event_system, GATEWAY_EVENT event_type, GATEWAY_CALLBACK callback, void* user_param);
GATEWAY_EXPORT void EventSystem_ReportEvent(EVENTSYSTEM_HANDLE event_system, GATEWAY_HANDLE gw, GATEWAY_EVENT event_type);
GATEWAY_EXPORT void EventSystem_Destroy(EVENTSYSTEM_HANDLE event_system);

/** @brief Registers a function to be called on a callback thread when_all
* #GATEWAY_EVENT happens
Expand All @@ -89,7 +90,7 @@ extern void EventSystem_Destroy(EVENTSYSTEM_HANDLE event_system);
* @param user_param User defined parameter that will be later provided
* to the called callback
*/
extern void Gateway_AddEventCallback(GATEWAY_HANDLE gw, GATEWAY_EVENT event_type, GATEWAY_CALLBACK callback, void* user_param);
GATEWAY_EXPORT void Gateway_AddEventCallback(GATEWAY_HANDLE gw, GATEWAY_EVENT event_type, GATEWAY_CALLBACK callback, void* user_param);

/** @brief Returns a snapshot copy of information about running modules.
*
Expand All @@ -103,14 +104,14 @@ extern void Gateway_AddEventCallback(GATEWAY_HANDLE gw, GATEWAY_EVENT event_type
* @return A #VECTOR_HANDLE of pointers to #GATEWAY_MODULE_INFO on success.
* NULL on failure.
*/
extern VECTOR_HANDLE Gateway_GetModuleList(GATEWAY_HANDLE gw);
GATEWAY_EXPORT VECTOR_HANDLE Gateway_GetModuleList(GATEWAY_HANDLE gw);

/** @brief Destroys the list returned by @c Gateway_GetModuleList
*
* @param module_list A vector handle as returned from
* @c Gateway_GetModuleList
*/
extern void Gateway_DestroyModuleList(VECTOR_HANDLE module_list);
GATEWAY_EXPORT void Gateway_DestroyModuleList(VECTOR_HANDLE module_list);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 01edca8

Please sign in to comment.