This commit is contained in:
Matthias Janetschek
2015-06-05 15:58:53 +02:00
parent 8fc57cc92e
commit f925e43d1f
85 changed files with 11613 additions and 394 deletions
+1
View File
@@ -8,6 +8,7 @@ find_package(catkin REQUIRED COMPONENTS
hos_cosgi_core
hos_cosgi_scripting
hos_cpp_utils
hos_cosgi_webserver
hos_deps
roscpp
hos_cpp_cron
@@ -6,6 +6,7 @@
#include <hos/cosgi/service/Interface.h>
#include <string>
#include <vector>
#include <chrono>
#include <memory>
@@ -57,11 +58,39 @@ public:
enum class RuleEngineEventType : int {
RULEPKG_ADDED,
RULEPKG_REMOVED,
RULEPKG_UPDATED,
RULEPKG_STATE_CHANGED,
RULE_ADDED,
RULE_REMOVED,
RULE_UPDATED,
RULE_STATE_CHANGED,
ALL_EVENTS,
CHANGE_EVENTS
};
class RuleEngineEvent {
public:
typedef std::chrono::system_clock::time_point timestamp_t;
RuleEngineEventType eventType;
const timestamp_t timestamp;
RuleEngineEvent(const RuleEngineEventType& type, const timestamp_t& timestamp)
: eventType(type), timestamp(timestamp) {}
};
/**
* Public COSGI interface of the rule engine service.
*/
class RuleEngineService
: public virtual interface::Service {
: public virtual interface::ObservableService<RuleEngineEventType, RuleEngineEvent> {
public:
+1
View File
@@ -48,6 +48,7 @@
<build_depend>hos_deps</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>hos_cpp_cron</build_depend>
<build_depend>hos_cosgi_webserver</build_depend>
<run_depend>hos_celix</run_depend>
<run_depend>hos_cosgi_devicerepository</run_depend>
<run_depend>hos_cosgi_core</run_depend>
@@ -22,6 +22,21 @@
#include <string>
namespace std {
/**
* Specialization of std::hash for RuleEngineEventType.
*
* Required by std::map.
*/
template <>
class hash <hos::cosgi::service::ruleengine::RuleEngineEventType>{
public :
size_t operator()(const hos::cosgi::service::ruleengine::RuleEngineEventType& x) const {
return static_cast<size_t>(x);
}
};
} // namespace std
// Service Namespace
namespace hos {
@@ -40,9 +55,11 @@ class RulePackageImpl;
/**
* Implementation of RuleEngineService.
**/
class RuleEngineServiceImpl :
public virtual RuleEngineService,
public implementation::Service<RuleEngineServiceImpl> {
class RuleEngineServiceImpl
: public virtual RuleEngineService,
public implementation::Service<RuleEngineServiceImpl>,
public implementation::Observable<RuleEngineEventType, RuleEngineEvent> {
//public implementation::ObservableService<DeviceRepositoryServiceImpl, > { /* Why does this one not work? */
private:
typedef std::map<std::string, std::shared_ptr<rules::RulePackageImpl>> rulePkgMap_t;
@@ -0,0 +1,10 @@
/*
* RuleEngineHandler.cpp
*
* Created on: 05.06.2015
* Author: matthias
*/
@@ -0,0 +1,106 @@
#pragma once
#include <hos/cosgi/service/Implementation.h>
#include <hos/cosgi/service/webserver/WebServerService.h>
#include <hos/cosgi/service/webserver/webresource/WebResourceHandlerImpl.h>
#include <hos/cosgi/service/ruleengine/RuleEngineService.h>
#include <Poco/Net/HTTPRequestHandler.h>
#include <Variant/Variant.h>
#include <ros/ros.h>
#include <vector>
#include <string>
#include <queue>
#include <condition_variable>
#include <memory>
#include <thread>
#include <functional>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
// Service Namespace
namespace hos {
namespace cosgi {
namespace service {
namespace ruleengine {
namespace webresource {
class RuleEngineHandler;
class RuleEngineHandlerFactory;
enum class RuleEngineAPIMethod {
GET,
SET,
EVENT,
UNKNOWN
};
class RuleEngineHandlerFactory
: public virtual webserver::WebResourceHandlerFactory,
public implementation::Service<RuleEngineHandlerFactory> {
private:
webserver::WebServerService* service = nullptr;
RuleEngineService* ruleService;
boost::asio::io_service io_service;
std::unique_ptr<std::thread> io_service_thread;
public:
RuleEngineHandlerFactory(RuleEngineService* ruleService);
~RuleEngineHandlerFactory();
virtual Poco::Net::HTTPRequestHandler* createRequestHandler(Poco::URI matchUri, const Poco::Net::HTTPServerRequest& request, bool ssl ) noexcept override;
virtual void setWebServerService(webserver::WebServerService* service) noexcept override {
this->service = service;
}
virtual bool excludeFromAuthentication() noexcept override {
return false;
}
boost::asio::io_service& getIOService() {
return io_service;
}
};
class RuleEngineHandler
: public webserver::webresource::WebResourceHandlerImpl {
protected:
RuleEngineHandlerFactory* parent;
Poco::URI matchUri;
RuleEngineService* ruleService;
bool ssl;
public:
RuleEngineHandler( RuleEngineHandlerFactory* parent,
Poco::URI matchUri,
RuleEngineService* ruleService,
bool ssl = false )
: parent(parent), matchUri(matchUri), ruleService(ruleService), ssl(ssl) {}
virtual void _handleRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp) override;
static RuleEngineAPIMethod getRuleEngineAPIMethod(Poco::Net::HTTPServerRequest &req) noexcept;
};
} // namespace webresource
} // namespace ruleengine
} // namespace service
} // namespace cosgi
} // namespace hos