.
This commit is contained in:
@@ -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)
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* hos_ruleengine_service.h
|
||||||
|
*
|
||||||
|
* Created on: 26.04.2015
|
||||||
|
* Author: matzman
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include <hos/common/observable.h>
|
||||||
|
#include <hos/cosgi/service/interface.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <Variant/Variant.h>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<package>
|
||||||
|
<name>hos_cosgi_webserver</name>
|
||||||
|
<version>0.0.0</version>
|
||||||
|
<description>The hos_cosgi_webserver package</description>
|
||||||
|
|
||||||
|
<!-- One maintainer tag required, multiple allowed, one person per tag -->
|
||||||
|
<!-- Example: -->
|
||||||
|
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
|
||||||
|
<maintainer email="matzman@todo.todo">matzman</maintainer>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- One license tag required, multiple allowed, one license per tag -->
|
||||||
|
<!-- Commonly used license strings: -->
|
||||||
|
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
|
||||||
|
<license>TODO</license>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Url tags are optional, but mutiple are allowed, one per tag -->
|
||||||
|
<!-- Optional attribute type can be: website, bugtracker, or repository -->
|
||||||
|
<!-- Example: -->
|
||||||
|
<!-- <url type="website">http://wiki.ros.org/hos_cosgi_webserver</url> -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Author tags are optional, mutiple are allowed, one per tag -->
|
||||||
|
<!-- Authors do not have to be maintianers, but could be -->
|
||||||
|
<!-- Example: -->
|
||||||
|
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- The *_depend tags are used to specify dependencies -->
|
||||||
|
<!-- Dependencies can be catkin packages or system dependencies -->
|
||||||
|
<!-- Examples: -->
|
||||||
|
<!-- Use build_depend for packages you need at compile time: -->
|
||||||
|
<!-- <build_depend>message_generation</build_depend> -->
|
||||||
|
<!-- Use buildtool_depend for build tool packages: -->
|
||||||
|
<!-- <buildtool_depend>catkin</buildtool_depend> -->
|
||||||
|
<!-- Use run_depend for packages you need at runtime: -->
|
||||||
|
<!-- <run_depend>message_runtime</run_depend> -->
|
||||||
|
<!-- Use test_depend for packages you need only for testing: -->
|
||||||
|
<!-- <test_depend>gtest</test_depend> -->
|
||||||
|
<buildtool_depend>catkin</buildtool_depend>
|
||||||
|
<build_depend>hos_celix</build_depend>
|
||||||
|
<build_depend>hos_cosgi_common</build_depend>
|
||||||
|
<build_depend>hos_cosgi_devicerepository</build_depend>
|
||||||
|
<build_depend>hos_cosgi_launcher</build_depend>
|
||||||
|
<build_depend>hos_cpp_common</build_depend>
|
||||||
|
<build_depend>hos_libhttpserver</build_depend>
|
||||||
|
<build_depend>hos_libvariant</build_depend>
|
||||||
|
<build_depend>roscpp</build_depend>
|
||||||
|
<run_depend>hos_celix</run_depend>
|
||||||
|
<run_depend>hos_cosgi_common</run_depend>
|
||||||
|
<run_depend>hos_cosgi_devicerepository</run_depend>
|
||||||
|
<run_depend>hos_cosgi_launcher</run_depend>
|
||||||
|
<run_depend>hos_cpp_common</run_depend>
|
||||||
|
<run_depend>hos_libhttpserver</run_depend>
|
||||||
|
<run_depend>hos_libvariant</run_depend>
|
||||||
|
<run_depend>roscpp</run_depend>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- The export tag contains other, unspecified, tags -->
|
||||||
|
<export>
|
||||||
|
<!-- Other tools can request additional information be placed here -->
|
||||||
|
|
||||||
|
</export>
|
||||||
|
</package>
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
* bundle_activator.cpp
|
||||||
|
*
|
||||||
|
* Created on: 26.04.2015
|
||||||
|
* Author: matzman
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <apr_general.h>
|
||||||
|
|
||||||
|
#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 <hos/cosgi/service/core/core_service.h>
|
||||||
|
#include "hos/cosgi/service/webserver/webserver_serviceimpl.h"
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
|
||||||
|
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<WebServerServiceImpl> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+45
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include <ros/ros.h>
|
||||||
|
#include <httpserver.hpp>
|
||||||
|
#include <hos/cosgi/service/devicerepository/devicerepository_service.h>
|
||||||
|
|
||||||
|
// Service Namespace
|
||||||
|
namespace hos {
|
||||||
|
namespace cosgi {
|
||||||
|
namespace service {
|
||||||
|
namespace webserver {
|
||||||
|
namespace resources {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DevicesHTTPResource : public httpserver::http_resource<DevicesHTTPResource> {
|
||||||
|
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
|
||||||
+45
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include <ros/ros.h>
|
||||||
|
#include <httpserver.hpp>
|
||||||
|
|
||||||
|
// Service Namespace
|
||||||
|
namespace hos {
|
||||||
|
namespace cosgi {
|
||||||
|
namespace service {
|
||||||
|
namespace webserver {
|
||||||
|
namespace resources {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SchemaHTTPResource : public httpserver::http_resource<SchemaHTTPResource> {
|
||||||
|
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
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* hos_ruleengine_service_impl.cpp
|
||||||
|
*
|
||||||
|
* Created on: 26.04.2015
|
||||||
|
* Author: matzman
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "webserver_serviceimpl.h"
|
||||||
|
#include <ros/ros.h>
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <Variant/Variant.h>
|
||||||
|
#include <celix/bundle_context.h>
|
||||||
|
#include <Variant/Variant.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace hos {
|
||||||
|
namespace cosgi {
|
||||||
|
namespace service {
|
||||||
|
namespace webserver {
|
||||||
|
|
||||||
|
using namespace ::libvariant;
|
||||||
|
using namespace httpserver;
|
||||||
|
|
||||||
|
|
||||||
|
template<> const char* implementation::ServiceInfo<WebServerServiceImpl>::name = service::webserver::WebServerServiceImpl::SERVICE_NAME;
|
||||||
|
template<> const int implementation::ServiceInfo<WebServerServiceImpl>::major = 0;
|
||||||
|
template<> const int implementation::ServiceInfo<WebServerServiceImpl>::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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* hos_ruleengine_service_impl.h
|
||||||
|
*
|
||||||
|
* Created on: 26.04.2015
|
||||||
|
* Author: matzman
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include <hos/cosgi/service/implementation.h>
|
||||||
|
#include <mutex>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <hos/cosgi/service/devicerepository/devicerepository_service.h>
|
||||||
|
#include <hos/cosgi/service/webserver/webserver_service.h>
|
||||||
|
#include <hos/cosgi/service/core/core_service.h>
|
||||||
|
#include <ros/ros.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <httpserver.hpp>
|
||||||
|
#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<WebServerServiceImpl> {
|
||||||
|
private:
|
||||||
|
|
||||||
|
service::core::CoreService* coreService = nullptr;
|
||||||
|
devicerepository::DeviceRepositoryService* repoService = nullptr;
|
||||||
|
ros::NodeHandle* nodehandle = nullptr;
|
||||||
|
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
|
std::unique_ptr<httpserver::webserver> webServer;
|
||||||
|
std::unique_ptr<resources::DevicesHTTPResource> devicesResource;
|
||||||
|
std::unique_ptr<resources::SchemaHTTPResource> 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
$(find hos_cosgi_launcher)/../../devel_isolated/hos_celix/share/celix/bundles/shell_tui.zip
|
$(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_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_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"/>
|
||||||
</node>
|
</node>
|
||||||
</launch>
|
</launch>
|
||||||
@@ -76,8 +76,8 @@ find_package(catkin REQUIRED)
|
|||||||
## CATKIN_DEPENDS: catkin_packages dependent projects also need
|
## CATKIN_DEPENDS: catkin_packages dependent projects also need
|
||||||
## DEPENDS: system dependencies of this project that dependent projects also need
|
## DEPENDS: system dependencies of this project that dependent projects also need
|
||||||
catkin_package(
|
catkin_package(
|
||||||
# INCLUDE_DIRS include
|
INCLUDE_DIRS include/${PROJECT_NAME}/
|
||||||
# LIBRARIES hos_libhttpserver
|
LIBRARIES gcrypt microhttpd httpserver
|
||||||
# CATKIN_DEPENDS other_catkin_pkg
|
# CATKIN_DEPENDS other_catkin_pkg
|
||||||
# DEPENDS system_lib
|
# DEPENDS system_lib
|
||||||
)
|
)
|
||||||
@@ -96,6 +96,10 @@ ExternalProject_Add( libgcrypt_project
|
|||||||
INSTALL_COMMAND make install
|
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
|
ExternalProject_Add( libmicrohttpd_project
|
||||||
DEPENDS libgcrypt_project
|
DEPENDS libgcrypt_project
|
||||||
@@ -105,8 +109,12 @@ ExternalProject_Add( libmicrohttpd_project
|
|||||||
INSTALL_COMMAND make install
|
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
|
DEPENDS libmicrohttpd_project
|
||||||
#SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/libhttpserver
|
#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
|
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
|
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
|
## Specify additional locations of header files
|
||||||
## Your package locations should be listed before other locations
|
## Your package locations should be listed before other locations
|
||||||
|
|||||||
+4
-3
@@ -318,9 +318,10 @@ _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
|
|||||||
# configured tree to be moved without reconfiguration.
|
# configured tree to be moved without reconfiguration.
|
||||||
|
|
||||||
AC_DEFUN([AM_AUX_DIR_EXPAND],
|
AC_DEFUN([AM_AUX_DIR_EXPAND],
|
||||||
[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
|
[dnl Rely on autoconf to set up CDPATH properly.
|
||||||
# Expand $ac_aux_dir to an absolute path.
|
AC_PREREQ([2.50])dnl
|
||||||
am_aux_dir=`cd "$ac_aux_dir" && pwd`
|
# expand $ac_aux_dir to an absolute path
|
||||||
|
am_aux_dir=`cd $ac_aux_dir && pwd`
|
||||||
])
|
])
|
||||||
|
|
||||||
# AM_CONDITIONAL -*- Autoconf -*-
|
# AM_CONDITIONAL -*- Autoconf -*-
|
||||||
|
|||||||
+2
-2
@@ -2666,8 +2666,8 @@ test "$program_suffix" != NONE &&
|
|||||||
ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
|
ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
|
||||||
program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
|
program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
|
||||||
|
|
||||||
# Expand $ac_aux_dir to an absolute path.
|
# expand $ac_aux_dir to an absolute path
|
||||||
am_aux_dir=`cd "$ac_aux_dir" && pwd`
|
am_aux_dir=`cd $ac_aux_dir && pwd`
|
||||||
|
|
||||||
if test x"${MISSING+set}" != xset; then
|
if test x"${MISSING+set}" != xset; then
|
||||||
case $am_aux_dir in
|
case $am_aux_dir in
|
||||||
|
|||||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
@set UPDATED 3 April 2015
|
@set UPDATED 19 May 2015
|
||||||
@set UPDATED-MONTH April 2015
|
@set UPDATED-MONTH May 2015
|
||||||
@set EDITION 0.9.42
|
@set EDITION 0.9.42
|
||||||
@set VERSION 0.9.42
|
@set VERSION 0.9.42
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@set UPDATED 3 April 2015
|
@set UPDATED 19 May 2015
|
||||||
@set UPDATED-MONTH April 2015
|
@set UPDATED-MONTH May 2015
|
||||||
@set EDITION 0.9.42
|
@set EDITION 0.9.42
|
||||||
@set VERSION 0.9.42
|
@set VERSION 0.9.42
|
||||||
|
|||||||
Reference in New Issue
Block a user