From 0d62915a11c3aaf9b59f3c71ad2a706832c4284e Mon Sep 17 00:00:00 2001 From: matzman Date: Wed, 20 May 2015 01:21:56 +0200 Subject: [PATCH] . --- src/hos_cosgi_webserver/CMakeLists.txt | 209 ++++++++++++++++++ .../service/webserver/webserver_service.h | 34 +++ src/hos_cosgi_webserver/package.xml | 66 ++++++ .../src/bundle_activator.cpp | 168 ++++++++++++++ .../resources/DevicesHTTPResource.cpp | 45 ++++ .../webserver/resources/DevicesHTTPResource.h | 32 +++ .../resources/SchemaHTTPResource.cpp | 45 ++++ .../webserver/resources/SchemaHTTPResource.h | 31 +++ .../webserver/webserver_serviceimpl.cpp | 84 +++++++ .../service/webserver/webserver_serviceimpl.h | 78 +++++++ src/hos_launch/launch/hos_cosgi.launch | 3 +- src/hos_libhttpserver/CMakeLists.txt | 18 +- .../src/libmicrohttpd/aclocal.m4 | 7 +- .../src/libmicrohttpd/configure | 4 +- .../src/libmicrohttpd/doc/libmicrohttpd.info | Bin 195255 -> 195253 bytes .../src/libmicrohttpd/doc/stamp-vti | 4 +- .../src/libmicrohttpd/doc/version.texi | 4 +- 17 files changed, 819 insertions(+), 13 deletions(-) create mode 100644 src/hos_cosgi_webserver/CMakeLists.txt create mode 100644 src/hos_cosgi_webserver/include/hos_cosgi_webserver/hos/cosgi/service/webserver/webserver_service.h create mode 100644 src/hos_cosgi_webserver/package.xml create mode 100644 src/hos_cosgi_webserver/src/bundle_activator.cpp create mode 100644 src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.cpp create mode 100644 src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.h create mode 100644 src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.cpp create mode 100644 src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.h create mode 100644 src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.cpp create mode 100644 src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.h diff --git a/src/hos_cosgi_webserver/CMakeLists.txt b/src/hos_cosgi_webserver/CMakeLists.txt new file mode 100644 index 00000000..b2292395 --- /dev/null +++ b/src/hos_cosgi_webserver/CMakeLists.txt @@ -0,0 +1,209 @@ +cmake_minimum_required(VERSION 2.8.3) +project(hos_cosgi_webserver) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + hos_celix + hos_cosgi_common + hos_cosgi_devicerepository + hos_cosgi_launcher + hos_cpp_common + hos_libhttpserver + hos_libvariant + roscpp +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +find_package(APR REQUIRED) +find_package(CELIX REQUIRED) +find_package(Boost REQUIRED) + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependencies might have been +## pulled in transitively but can be declared for certainty nonetheless: +## * add a build_depend tag for "message_generation" +## * add a run_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# std_msgs # Or other packages containing msgs +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if you package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES hos_cosgi_webserver +# CATKIN_DEPENDS hos_celix hos_cosgi_common hos_cosgi_devicerepository hos_cosgi_launcher hos_cpp_common hos_libhttpserver hos_libvariant roscpp +# DEPENDS system_lib +) + +########### +## Build ## +########### + +add_definitions( + -std=c++11 +) + +## Specify additional locations of header files +## Your package locations should be listed before other locations +# include_directories(include) +include_directories( + ${catkin_INCLUDE_DIRS} + ${APR_INCLUDE_DIR} + ${APR_INCLUDE_DIR}/apr-1.0 + include/${PROJECT_NAME}/ + ${hos_libvariant_INCLUDE_DIRS}/hos_libvariant +) + +set(BUNDLE_SYMBOLICNAME "hos.hos_webserver") +set(BUNDLE_VERSION "1.0.0") +set(BUNDLE_NAME "hos_webserver") + +bundle(hos_cosgi_webserver + SOURCES + ${PROJECT_SOURCE_DIR}/src/bundle_activator + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/webserver/webserver_serviceimpl + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource +) +target_link_libraries(hos_cosgi_webserver + ${catkin_LIBRARIES} + ${APR_LIBRARIES} +) + + +## Declare a cpp library +# add_library(hos_cosgi_webserver +# src/${PROJECT_NAME}/hos_cosgi_webserver.cpp +# ) + +## Declare a cpp executable +# add_executable(hos_cosgi_webserver_node src/hos_cosgi_webserver_node.cpp) + +## Add cmake target dependencies of the executable/library +## as an example, message headers may need to be generated before nodes +# add_dependencies(hos_cosgi_webserver_node hos_cosgi_webserver_generate_messages_cpp) + +## Specify libraries to link a library or executable target against +# target_link_libraries(hos_cosgi_webserver_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +## Mark cpp header files for installation +install(DIRECTORY include/${PROJECT_NAME}/ + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} + FILES_MATCHING PATTERN "*.h" +) + +install(FILES + ${CMAKE_BINARY_DIR}/hos_cosgi_webserver.zip + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/bundles +) + + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# install(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables and/or libraries for installation +# install(TARGETS hos_cosgi_webserver hos_cosgi_webserver_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_hos_cosgi_webserver.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) diff --git a/src/hos_cosgi_webserver/include/hos_cosgi_webserver/hos/cosgi/service/webserver/webserver_service.h b/src/hos_cosgi_webserver/include/hos_cosgi_webserver/hos/cosgi/service/webserver/webserver_service.h new file mode 100644 index 00000000..d3e56945 --- /dev/null +++ b/src/hos_cosgi_webserver/include/hos_cosgi_webserver/hos/cosgi/service/webserver/webserver_service.h @@ -0,0 +1,34 @@ +/* + * hos_ruleengine_service.h + * + * Created on: 26.04.2015 + * Author: matzman + */ + +#pragma once + + +#include +#include +#include +#include + + +namespace hos { +namespace cosgi { +namespace service { +namespace webserver { + + +class WebServerService : public virtual interface::Service { +public: + static constexpr const char* SERVICE_NAME = "hos_webserver_service"; +}; + + +} // namespace webserver +} // namespace service +} // namespace cosgi +} // namespace hos + + diff --git a/src/hos_cosgi_webserver/package.xml b/src/hos_cosgi_webserver/package.xml new file mode 100644 index 00000000..db718137 --- /dev/null +++ b/src/hos_cosgi_webserver/package.xml @@ -0,0 +1,66 @@ + + + hos_cosgi_webserver + 0.0.0 + The hos_cosgi_webserver package + + + + + matzman + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + hos_celix + hos_cosgi_common + hos_cosgi_devicerepository + hos_cosgi_launcher + hos_cpp_common + hos_libhttpserver + hos_libvariant + roscpp + hos_celix + hos_cosgi_common + hos_cosgi_devicerepository + hos_cosgi_launcher + hos_cpp_common + hos_libhttpserver + hos_libvariant + roscpp + + + + + + + + \ No newline at end of file diff --git a/src/hos_cosgi_webserver/src/bundle_activator.cpp b/src/hos_cosgi_webserver/src/bundle_activator.cpp new file mode 100644 index 00000000..55252f51 --- /dev/null +++ b/src/hos_cosgi_webserver/src/bundle_activator.cpp @@ -0,0 +1,168 @@ +/* + * bundle_activator.cpp + * + * Created on: 26.04.2015 + * Author: matzman + */ + +#include +#include + +#include + +#include "ros/ros.h" + +extern "C" { + #include "celix/bundle_activator.h" + #include "celix/bundle_context.h" + #include "celix/service_listener.h" + #include "celix/service_reference.h" + #include "celix/constants.h" +} + +#include +#include "hos/cosgi/service/webserver/webserver_serviceimpl.h" +#include +#include + + +using namespace hos::cosgi::service::webserver; +using namespace hos::cosgi::service::devicerepository; +using namespace hos::cosgi::service::core; +using namespace hos::cosgi; + +struct UserData { + apr_pool_t* memoryPool = nullptr; + std::unique_ptr serviceImpl = nullptr; + service_registration_pt serviceReg = nullptr; + serviceListener myServiceListener; + bundle_context_pt bundleContext; +}; + + +celix_status_t cb_serviceChanged(void* listener, service_event_pt event) { + UserData* myUserData = (UserData*) ((serviceListener*)listener)->handle; + if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED) { + char* serviceName = nullptr; + bool checkReg = false; + serviceReference_getProperty(event->reference, (char*)OSGI_FRAMEWORK_OBJECTCLASS, &serviceName); + if (serviceName && std::strcmp(serviceName, DeviceRepositoryService::SERVICE_NAME) == 0) { + DeviceRepositoryService *service = nullptr; + bundleContext_getService(myUserData->bundleContext, event->reference, (void**)&service); + myUserData->serviceImpl->setRepoService(service); + checkReg = true; + } + // Register hos-devicerepository-service + if (checkReg && !myUserData->serviceReg && myUserData->serviceImpl->isInitialized()) { + bundleContext_registerService(myUserData->bundleContext, (char*)WebServerServiceImpl::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); + } + } else if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) { + } + return CELIX_SUCCESS; +} + +celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { + celix_status_t status = CELIX_START_ERROR; + apr_pool_t* memoryPool = nullptr; + // Create APR memory pool + apr_status_t astatus = apr_pool_create(&memoryPool, NULL); + if (astatus != APR_SUCCESS) { + ROS_ERROR("WebServerService: Could not create APR memory pool (%i).", astatus); + } else { + // Create user data + UserData* myUserData = (UserData*)apr_palloc(memoryPool, sizeof(UserData)); + if (myUserData != nullptr) { + myUserData->memoryPool = memoryPool; + myUserData->bundleContext = context; + *userData = (void*)myUserData; + status = CELIX_SUCCESS; + ROS_INFO("WebServerService: Bundle successfully created"); + } else { + ROS_ERROR("WebServerService: Could not create user data struct"); + apr_pool_destroy(memoryPool); + } + } + return status; +} + +celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { + celix_status_t status = CELIX_SUCCESS; + if (userData != nullptr) { + UserData* myUserData = (UserData*)userData; + // Create hos-devicerepository-service + if (myUserData->serviceReg != nullptr) { + serviceRegistration_unregister(myUserData->serviceReg); + myUserData->serviceReg = nullptr; + } + myUserData->serviceImpl.reset(new WebServerServiceImpl()); + // Get HOS Core Service + service_reference_pt ref = nullptr; + bundleContext_getServiceReference(context, (char*)CoreService::SERVICE_NAME, &ref); + CoreService* coreService = nullptr; + bundleContext_getService(context, ref, (void**)&coreService); + if (coreService == nullptr) { + ROS_ERROR("WebServerService: Could not retrieve HOSCoreService. Are you using hos_cosgi_launcher?"); + } else { + myUserData->serviceImpl->setCoreService(coreService); + } + // Get HOS Core Service + service_reference_pt ref2 = nullptr; + bundleContext_getServiceReference(context, (char*)DeviceRepositoryService::SERVICE_NAME, &ref2); + DeviceRepositoryService* repoService = nullptr; + bundleContext_getService(context, ref2, (void**)&repoService); + if (repoService) { + myUserData->serviceImpl->setRepoService(repoService); + } + // Register hos-devicerepository-service + if (myUserData->serviceImpl->isInitialized()) { + bundleContext_registerService(context, (char*)WebServerServiceImpl::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); + } + // Register service listener + myUserData->myServiceListener.handle = myUserData; + myUserData->myServiceListener.serviceChanged = cb_serviceChanged; + bundleContext_addServiceListener(context, &myUserData->myServiceListener, nullptr); + ROS_INFO("WebServerService: Bundle successfully started"); + } else { + ROS_ERROR("WebServerService: Could not start bundle, user data struct is null"); + } + return status; +} + +celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { + celix_status_t status = CELIX_ILLEGAL_STATE; + if (userData != nullptr) { + UserData* myUserData = (UserData*)userData; + status = bundleContext_removeServiceListener(context, &myUserData->myServiceListener); + if (myUserData->serviceReg != nullptr) { + serviceRegistration_unregister(myUserData->serviceReg); + myUserData->serviceReg = nullptr; + } + if (myUserData->serviceImpl) { + myUserData->serviceImpl.reset(); + } + ROS_INFO("WebServerService: Bundle successfully stopped"); + status = CELIX_SUCCESS; + } else { + ROS_ERROR("WebServerService: Could not stop bundle, user data struct is null"); + } + return status; +} + +celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { + celix_status_t status = CELIX_ILLEGAL_STATE; + if (userData != nullptr) { + apr_pool_t* memoryPool = ((UserData*)userData)->memoryPool; + if (memoryPool != nullptr) { + apr_pool_destroy(memoryPool); + ROS_INFO("WebServerService: Bundle successfully destroyed"); + } else { + ROS_ERROR("WebServerService: Could not destroy bundle, there is no APR memory pool"); + } + status = CELIX_SUCCESS; + } else { + ROS_ERROR("WebServerService: Could not destroy bundle, user data struct is null"); + } + return status; +} + + diff --git a/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.cpp b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.cpp new file mode 100644 index 00000000..d61261e5 --- /dev/null +++ b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.cpp @@ -0,0 +1,45 @@ + +#include "DevicesHTTPResource.h" + + +// Service Namespace +namespace hos { +namespace cosgi { +namespace service { +namespace webserver { +namespace resources { + +using namespace httpserver; + +DevicesHTTPResource::DevicesHTTPResource(devicerepository::DeviceRepositoryService* repoService) + : repoService(repoService) { + disallow_all(); + set_allowing(MHD_HTTP_METHOD_GET, true); + set_allowing(MHD_HTTP_METHOD_POST, true); +} + + +void DevicesHTTPResource::render_GET(const httpserver::http_request& req, httpserver::http_response** res) { + std::cout << "DevicesHTTPResource::render_GET()" << std::endl; + std::cout << req; + *res = new http_response(http_response_builder("GET response", 200).string_response()); + std::cout << **res; +} + + +void DevicesHTTPResource::render_POST(const httpserver::http_request& req, httpserver::http_response** res) { + std::cout << "DevicesHTTPResource::render_POST()" << std::endl; + std::cout << req; + *res = new http_response(http_response_builder("POST response", 200).string_response()); + std::cout << **res; +} + + +} // namespace resources +} // namespace webserver +} // namespace service +} // namespace cosgi +} // namespace hos + + + diff --git a/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.h b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.h new file mode 100644 index 00000000..981d1e94 --- /dev/null +++ b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/DevicesHTTPResource.h @@ -0,0 +1,32 @@ + +#pragma once + + +#include +#include +#include + +// Service Namespace +namespace hos { +namespace cosgi { +namespace service { +namespace webserver { +namespace resources { + + + +class DevicesHTTPResource : public httpserver::http_resource { +private: + devicerepository::DeviceRepositoryService* repoService = nullptr; +public: + DevicesHTTPResource(devicerepository::DeviceRepositoryService* repoService); + + void render_GET(const httpserver::http_request& req, httpserver::http_response** res); + void render_POST(const httpserver::http_request& req, httpserver::http_response** res); +}; + +} // namespace resources +} // namespace webserver +} // namespace service +} // namespace cosgi +} // namespace hos diff --git a/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.cpp b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.cpp new file mode 100644 index 00000000..c282eddd --- /dev/null +++ b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.cpp @@ -0,0 +1,45 @@ + +#include "SchemaHTTPResource.h" + + +// Service Namespace +namespace hos { +namespace cosgi { +namespace service { +namespace webserver { +namespace resources { + +using namespace httpserver; + +SchemaHTTPResource::SchemaHTTPResource(ros::NodeHandle* nodehandle) + : nodehandle(nodehandle) { + disallow_all(); + set_allowing(MHD_HTTP_METHOD_GET, true); + set_allowing(MHD_HTTP_METHOD_POST, true); +} + + +void SchemaHTTPResource::render_GET(const httpserver::http_request& req, httpserver::http_response** res) { + std::cout << "SchemaHTTPResource::render_GET()" << std::endl; + std::cout << req; + *res = new http_response(http_response_builder("GET response", 200).string_response()); + std::cout << **res; +} + + +void SchemaHTTPResource::render_POST(const httpserver::http_request& req, httpserver::http_response** res) { + std::cout << "SchemaHTTPResource::render_POST()" << std::endl; + std::cout << req; + *res = new http_response(http_response_builder("POST response", 200).string_response()); + std::cout << **res; +} + + +} // namespace resources +} // namespace webserver +} // namespace service +} // namespace cosgi +} // namespace hos + + + diff --git a/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.h b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.h new file mode 100644 index 00000000..d08d57d3 --- /dev/null +++ b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/resources/SchemaHTTPResource.h @@ -0,0 +1,31 @@ + +#pragma once + + +#include +#include + +// Service Namespace +namespace hos { +namespace cosgi { +namespace service { +namespace webserver { +namespace resources { + + + +class SchemaHTTPResource : public httpserver::http_resource { +private: + ros::NodeHandle* nodehandle = nullptr; +public: + SchemaHTTPResource(ros::NodeHandle* nodehandle); + + void render_GET(const httpserver::http_request& req, httpserver::http_response** res); + void render_POST(const httpserver::http_request& req, httpserver::http_response** res); +}; + +} // namespace resources +} // namespace webserver +} // namespace service +} // namespace cosgi +} // namespace hos diff --git a/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.cpp b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.cpp new file mode 100644 index 00000000..e7e02dfd --- /dev/null +++ b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.cpp @@ -0,0 +1,84 @@ +/* + * hos_ruleengine_service_impl.cpp + * + * Created on: 26.04.2015 + * Author: matzman + */ + +#include "webserver_serviceimpl.h" +#include +#include +#include +#include +#include +#include +#include + + +namespace hos { +namespace cosgi { +namespace service { +namespace webserver { + +using namespace ::libvariant; +using namespace httpserver; + + +template<> const char* implementation::ServiceInfo::name = service::webserver::WebServerServiceImpl::SERVICE_NAME; +template<> const int implementation::ServiceInfo::major = 0; +template<> const int implementation::ServiceInfo::minor = 6; + +WebServerServiceImpl::~WebServerServiceImpl() { + webServer->stop(); +} + +void WebServerServiceImpl::setCoreService(service::core::CoreService* coreService) { + if (coreService && !this->coreService) { + this->coreService = coreService; + this->nodehandle = coreService->getPrivateNodeHandle(); + int major = 0, minor = 0; + coreService->getServiceVersion(major, minor); + ROS_INFO_STREAM("WebServerService: Found HOSCoreService Version " << major << "." << minor); + if (repoService) { + init(); + } + } +} + +void WebServerServiceImpl::setRepoService(devicerepository::DeviceRepositoryService* repoService) { + if (repoService && !this->repoService) { + this->repoService = repoService; + int major = 0, minor = 0; + repoService->getServiceVersion(major, minor); + ROS_INFO_STREAM("WebServerService: Found HOSDeviceRepositoryService Version " << major << "." << minor); + if (coreService) { + init(); + } + } +} + +void WebServerServiceImpl::init() { + create_webserver serverParams(8888); + serverParams.max_threads(5).regex_checking(); + webServer.reset(new webserver::webserver(serverParams)); + devicesResource.reset(new resources::DevicesHTTPResource(repoService)); + schemaResource.reset(new resources::SchemaHTTPResource(nodehandle)); + webServer->register_resource("/hos/devices", devicesResource.get(), true); + webServer->register_resource("/hos/schemas", schemaResource.get(), true); + webServer->start(false); + initialized = true; + ROS_INFO_STREAM("WebServerService: Initialized and Ready."); +} + + +} // namespace webserver +} // namespace service +} // namespace cosgi +} // namespace hos + + + + + + + diff --git a/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.h b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.h new file mode 100644 index 00000000..77124d4f --- /dev/null +++ b/src/hos_cosgi_webserver/src/hos/cosgi/service/webserver/webserver_serviceimpl.h @@ -0,0 +1,78 @@ +/* + * hos_ruleengine_service_impl.h + * + * Created on: 26.04.2015 + * Author: matzman + */ + +#pragma once + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "resources/SchemaHTTPResource.h" +#include "resources/DevicesHTTPResource.h" + + + +// Service Namespace +namespace hos { +namespace cosgi { +namespace service { +namespace webserver { + + +class WebServerServiceImpl; +class WebServerServiceImpl : + public virtual WebServerService, + public virtual implementation::Service { +private: + + service::core::CoreService* coreService = nullptr; + devicerepository::DeviceRepositoryService* repoService = nullptr; + ros::NodeHandle* nodehandle = nullptr; + + bool initialized = false; + + std::unique_ptr webServer; + std::unique_ptr devicesResource; + std::unique_ptr schemaResource; + + void init(); + +public: + ~WebServerServiceImpl(); + + /* Initialization */ + + void setCoreService(service::core::CoreService* coreService); + void setRepoService(devicerepository::DeviceRepositoryService* repoService); + + /* Public Service Implementations */ + + /* Observer Callbacks */ + /* Internal Stuff */ + + bool isInitialized() { return initialized; } + + devicerepository::DeviceRepositoryService* getDeviceRepository() { return repoService; } +}; + + +} // namespace webserver +} // namespace service +} // namespace cosgi +} // namespace hos + + + + diff --git a/src/hos_launch/launch/hos_cosgi.launch b/src/hos_launch/launch/hos_cosgi.launch index 00788978..81ef721a 100644 --- a/src/hos_launch/launch/hos_cosgi.launch +++ b/src/hos_launch/launch/hos_cosgi.launch @@ -11,6 +11,7 @@ $(find hos_cosgi_launcher)/../../devel_isolated/hos_celix/share/celix/bundles/shell_tui.zip $(find hos_cosgi_launcher)/../../build_isolated/hos_cosgi_scripting_python/hos_cosgi_scripting_python.zip $(find hos_cosgi_launcher)/../../build_isolated/hos_cosgi_ruleengine/hos_cosgi_ruleengine.zip - $(find hos_cosgi_launcher)/../../build_isolated/hos_cosgi_devicerepository/hos_cosgi_devicerepository.zip"/> + $(find hos_cosgi_launcher)/../../build_isolated/hos_cosgi_devicerepository/hos_cosgi_devicerepository.zip + $(find hos_cosgi_launcher)/../../build_isolated/hos_cosgi_webserver/hos_cosgi_webserver.zip"/> \ No newline at end of file diff --git a/src/hos_libhttpserver/CMakeLists.txt b/src/hos_libhttpserver/CMakeLists.txt index 7f2139ec..13ce829a 100644 --- a/src/hos_libhttpserver/CMakeLists.txt +++ b/src/hos_libhttpserver/CMakeLists.txt @@ -76,8 +76,8 @@ find_package(catkin REQUIRED) ## CATKIN_DEPENDS: catkin_packages dependent projects also need ## DEPENDS: system dependencies of this project that dependent projects also need catkin_package( -# INCLUDE_DIRS include -# LIBRARIES hos_libhttpserver + INCLUDE_DIRS include/${PROJECT_NAME}/ + LIBRARIES gcrypt microhttpd httpserver # CATKIN_DEPENDS other_catkin_pkg # DEPENDS system_lib ) @@ -96,6 +96,10 @@ ExternalProject_Add( libgcrypt_project INSTALL_COMMAND make install ) +add_library( gcrypt SHARED IMPORTED ) +set_property( TARGET gcrypt PROPERTY IMPORTED_LOCATION "${CATKIN_DEVEL_PREFIX}/lib/libgcrypt.so") +add_dependencies( gcrypt libgcrypt_project ) + ExternalProject_Add( libmicrohttpd_project DEPENDS libgcrypt_project @@ -105,8 +109,12 @@ ExternalProject_Add( libmicrohttpd_project INSTALL_COMMAND make install ) +add_library( microhttpd SHARED IMPORTED ) +set_property( TARGET microhttpd PROPERTY IMPORTED_LOCATION "${CATKIN_DEVEL_PREFIX}/lib/libmicrohttpd.so") +add_dependencies( microhttpd libmicrohttpd_project ) -ExternalProject_Add( libhttpserver + +ExternalProject_Add( libhttpserver_project DEPENDS libmicrohttpd_project #SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/libhttpserver DOWNLOAD_COMMAND cp -rf ${CMAKE_CURRENT_SOURCE_DIR}/src/libhttpserver ${CMAKE_CURRENT_BINARY_DIR} && cd ${CMAKE_CURRENT_BINARY_DIR}/libhttpserver && ./bootstrap @@ -115,6 +123,10 @@ ExternalProject_Add( libhttpserver INSTALL_COMMAND make install ) +add_library( httpserver SHARED IMPORTED ) +set_property( TARGET httpserver PROPERTY IMPORTED_LOCATION "${CATKIN_DEVEL_PREFIX}/lib/libhttpserver.so") +add_dependencies( httpserver libhttpserver_project ) + ## Specify additional locations of header files ## Your package locations should be listed before other locations diff --git a/src/hos_libhttpserver/src/libmicrohttpd/aclocal.m4 b/src/hos_libhttpserver/src/libmicrohttpd/aclocal.m4 index fdc4449a..96258cce 100644 --- a/src/hos_libhttpserver/src/libmicrohttpd/aclocal.m4 +++ b/src/hos_libhttpserver/src/libmicrohttpd/aclocal.m4 @@ -318,9 +318,10 @@ _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], -[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl -# Expand $ac_aux_dir to an absolute path. -am_aux_dir=`cd "$ac_aux_dir" && pwd` +[dnl Rely on autoconf to set up CDPATH properly. +AC_PREREQ([2.50])dnl +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- diff --git a/src/hos_libhttpserver/src/libmicrohttpd/configure b/src/hos_libhttpserver/src/libmicrohttpd/configure index a846be6b..08d040cf 100755 --- a/src/hos_libhttpserver/src/libmicrohttpd/configure +++ b/src/hos_libhttpserver/src/libmicrohttpd/configure @@ -2666,8 +2666,8 @@ test "$program_suffix" != NONE && ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` -# Expand $ac_aux_dir to an absolute path. -am_aux_dir=`cd "$ac_aux_dir" && pwd` +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` if test x"${MISSING+set}" != xset; then case $am_aux_dir in diff --git a/src/hos_libhttpserver/src/libmicrohttpd/doc/libmicrohttpd.info b/src/hos_libhttpserver/src/libmicrohttpd/doc/libmicrohttpd.info index 7db83c7d3ae42ef30d67db7ba883bbe1c67081db..c460a85f9e76b194255dffb7fbdd9c168ef82d32 100644 GIT binary patch delta 545 zcmYjN&ubGw6lUI%Y~1ZZtZ7IkcBO}kP?(wQ?CeHR53RklK}8Q91k=r?Ew;NMjfkf~ zJb0=I5#Pa!|ABarp8F5@4|q@yz1a#SO_LnN*)@WP2k-mA<9px!sr~uXezTWnfwR_l z{^{*QW3s;N8?X8X+3y>$d;;9UgC}Gf>jN+^aqC{xsyVH#jaobEw35zFBMu`asmHKA zfD)1+O!vNB&&?|)xD2d%(u``(&Q{n-HoM(+b8)xZc^Y<=tHsQ0hU?0$3Yh`?HGl$P zcsITB_|P*frU2~NV%}9JeLO549)hAf17#b2~GvRI0Keu)~;Fn zat1cA3HY!;^g&sb+|8IP8VDi&$sex~GpD3Jn?2@+p%v-AkC< zBsonm$yrKNa?0lc!=oXT^2(P&w{bj#xxYU-BRB^%Yq5y8Mldz0v}ikF62~g=0wysY z!93_-jXhG#DMp!x2Lrf>M<*~WUAF_bP)YtCAZo6h~lhMx89$od1ETBMr* delta 569 zcmYk2O=}ZT6o#1-W~QBqqC^tgP&z9qLiOG|-`PmXKyI~gYv(2aND z!c|Kli~BpekS+wVzd-#7BI43+nwjaM^kycaiwoyG@439^Js;2YlXLy(KsAlEC=T|H z$1f`XY6aeB@`p^8PBIxDoPnv0f9UmPW+H59&uG78^n=}2MC1M--tUB6%3S1_Je)v7 z^7!clYAb_qm@sS;4{Mu)9&H)>K{p<}N|LCzI!xkGH(?fW{bG6nys1Hr|CxYNA*g7^ z+rMOfBL!Kq_;Cui_}vsVz2~6e*Y(^ z3Uf`DI3;LiQ2i^me;1--A&<8+SgeSR`Q<~Yt}+i{mlRE-y3-j3UFHd37Gz0b9`Uiw zzh%(mUo&XvMkflGk8CtcW8|O$DU*Hq4D%}UOzD*v8Cjlav`rsVLWTzI<( zO^Z4|JCNp7h7tB%T#|c-()^MjwuQ;;r0bi{S2xz%8-hB>Cj9yZtTdee#3zr0W?P6@ z8bAFcytXeup2Mgd8L#QL5yPHK(2N*cZzF0v4SVzr!#)uQ)0VZzVb9p=?25OuN3|>T C8@jas diff --git a/src/hos_libhttpserver/src/libmicrohttpd/doc/stamp-vti b/src/hos_libhttpserver/src/libmicrohttpd/doc/stamp-vti index c8c24ba0..dbbe7e46 100644 --- a/src/hos_libhttpserver/src/libmicrohttpd/doc/stamp-vti +++ b/src/hos_libhttpserver/src/libmicrohttpd/doc/stamp-vti @@ -1,4 +1,4 @@ -@set UPDATED 3 April 2015 -@set UPDATED-MONTH April 2015 +@set UPDATED 19 May 2015 +@set UPDATED-MONTH May 2015 @set EDITION 0.9.42 @set VERSION 0.9.42 diff --git a/src/hos_libhttpserver/src/libmicrohttpd/doc/version.texi b/src/hos_libhttpserver/src/libmicrohttpd/doc/version.texi index c8c24ba0..dbbe7e46 100644 --- a/src/hos_libhttpserver/src/libmicrohttpd/doc/version.texi +++ b/src/hos_libhttpserver/src/libmicrohttpd/doc/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 3 April 2015 -@set UPDATED-MONTH April 2015 +@set UPDATED 19 May 2015 +@set UPDATED-MONTH May 2015 @set EDITION 0.9.42 @set VERSION 0.9.42