diff --git a/src/hos_celix/CMakeLists.txt b/src/hos_celix/CMakeLists.txt index 5f805e81..72044ca6 100644 --- a/src/hos_celix/CMakeLists.txt +++ b/src/hos_celix/CMakeLists.txt @@ -77,7 +77,7 @@ 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 + INCLUDE_DIRS include/${PROJECT_NAME}/ LIBRARIES celix_framework celix_utils dependency_manager2 CFG_EXTRAS celix-extras.cmake # CATKIN_DEPENDS other_catkin_pkg diff --git a/src/hos_celix/include/hos_celix/archive.h b/src/hos_celix/include/hos_celix/celix/archive.h similarity index 100% rename from src/hos_celix/include/hos_celix/archive.h rename to src/hos_celix/include/hos_celix/celix/archive.h diff --git a/src/hos_celix/include/hos_celix/array_list.h b/src/hos_celix/include/hos_celix/celix/array_list.h similarity index 100% rename from src/hos_celix/include/hos_celix/array_list.h rename to src/hos_celix/include/hos_celix/celix/array_list.h diff --git a/src/hos_celix/include/hos_celix/bundle.h b/src/hos_celix/include/hos_celix/celix/bundle.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle.h rename to src/hos_celix/include/hos_celix/celix/bundle.h diff --git a/src/hos_celix/include/hos_celix/bundle_activator.h b/src/hos_celix/include/hos_celix/celix/bundle_activator.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle_activator.h rename to src/hos_celix/include/hos_celix/celix/bundle_activator.h diff --git a/src/hos_celix/include/hos_celix/bundle_archive.h b/src/hos_celix/include/hos_celix/celix/bundle_archive.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle_archive.h rename to src/hos_celix/include/hos_celix/celix/bundle_archive.h diff --git a/src/hos_celix/include/hos_celix/bundle_context.h b/src/hos_celix/include/hos_celix/celix/bundle_context.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle_context.h rename to src/hos_celix/include/hos_celix/celix/bundle_context.h diff --git a/src/hos_celix/include/hos_celix/bundle_event.h b/src/hos_celix/include/hos_celix/celix/bundle_event.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle_event.h rename to src/hos_celix/include/hos_celix/celix/bundle_event.h diff --git a/src/hos_celix/include/hos_celix/bundle_listener.h b/src/hos_celix/include/hos_celix/celix/bundle_listener.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle_listener.h rename to src/hos_celix/include/hos_celix/celix/bundle_listener.h diff --git a/src/hos_celix/include/hos_celix/bundle_revision.h b/src/hos_celix/include/hos_celix/celix/bundle_revision.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle_revision.h rename to src/hos_celix/include/hos_celix/celix/bundle_revision.h diff --git a/src/hos_celix/include/hos_celix/bundle_state.h b/src/hos_celix/include/hos_celix/celix/bundle_state.h similarity index 100% rename from src/hos_celix/include/hos_celix/bundle_state.h rename to src/hos_celix/include/hos_celix/celix/bundle_state.h diff --git a/src/hos_celix/include/hos_celix/capability.h b/src/hos_celix/include/hos_celix/celix/capability.h similarity index 100% rename from src/hos_celix/include/hos_celix/capability.h rename to src/hos_celix/include/hos_celix/celix/capability.h diff --git a/src/hos_celix/include/hos_celix/celix_errno.h b/src/hos_celix/include/hos_celix/celix/celix_errno.h similarity index 100% rename from src/hos_celix/include/hos_celix/celix_errno.h rename to src/hos_celix/include/hos_celix/celix/celix_errno.h diff --git a/src/hos_celix/include/hos_celix/celix_log.h b/src/hos_celix/include/hos_celix/celix/celix_log.h similarity index 100% rename from src/hos_celix/include/hos_celix/celix_log.h rename to src/hos_celix/include/hos_celix/celix/celix_log.h diff --git a/src/hos_celix/include/hos_celix/celix_threads.h b/src/hos_celix/include/hos_celix/celix/celix_threads.h similarity index 100% rename from src/hos_celix/include/hos_celix/celix_threads.h rename to src/hos_celix/include/hos_celix/celix/celix_threads.h diff --git a/src/hos_celix/include/hos_celix/celixbool.h b/src/hos_celix/include/hos_celix/celix/celixbool.h similarity index 100% rename from src/hos_celix/include/hos_celix/celixbool.h rename to src/hos_celix/include/hos_celix/celix/celixbool.h diff --git a/src/hos_celix/include/hos_celix/constants.h b/src/hos_celix/include/hos_celix/celix/constants.h similarity index 100% rename from src/hos_celix/include/hos_celix/constants.h rename to src/hos_celix/include/hos_celix/celix/constants.h diff --git a/src/hos_celix/include/hos_celix/dependency_manager_2/dm_activator_base.h b/src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_activator_base.h similarity index 100% rename from src/hos_celix/include/hos_celix/dependency_manager_2/dm_activator_base.h rename to src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_activator_base.h diff --git a/src/hos_celix/include/hos_celix/dependency_manager_2/dm_component.h b/src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_component.h similarity index 100% rename from src/hos_celix/include/hos_celix/dependency_manager_2/dm_component.h rename to src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_component.h diff --git a/src/hos_celix/include/hos_celix/dependency_manager_2/dm_dependency_manager.h b/src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_dependency_manager.h similarity index 100% rename from src/hos_celix/include/hos_celix/dependency_manager_2/dm_dependency_manager.h rename to src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_dependency_manager.h diff --git a/src/hos_celix/include/hos_celix/dependency_manager_2/dm_service_dependency.h b/src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_service_dependency.h similarity index 100% rename from src/hos_celix/include/hos_celix/dependency_manager_2/dm_service_dependency.h rename to src/hos_celix/include/hos_celix/celix/dependency_manager_2/dm_service_dependency.h diff --git a/src/hos_celix/include/hos_celix/deployment_admin/resource_processor.h b/src/hos_celix/include/hos_celix/celix/deployment_admin/resource_processor.h similarity index 100% rename from src/hos_celix/include/hos_celix/deployment_admin/resource_processor.h rename to src/hos_celix/include/hos_celix/celix/deployment_admin/resource_processor.h diff --git a/src/hos_celix/include/hos_celix/device_manager/device.h b/src/hos_celix/include/hos_celix/celix/device_manager/device.h similarity index 100% rename from src/hos_celix/include/hos_celix/device_manager/device.h rename to src/hos_celix/include/hos_celix/celix/device_manager/device.h diff --git a/src/hos_celix/include/hos_celix/device_manager/driver.h b/src/hos_celix/include/hos_celix/celix/device_manager/driver.h similarity index 100% rename from src/hos_celix/include/hos_celix/device_manager/driver.h rename to src/hos_celix/include/hos_celix/celix/device_manager/driver.h diff --git a/src/hos_celix/include/hos_celix/device_manager/driver_locator.h b/src/hos_celix/include/hos_celix/celix/device_manager/driver_locator.h similarity index 100% rename from src/hos_celix/include/hos_celix/device_manager/driver_locator.h rename to src/hos_celix/include/hos_celix/celix/device_manager/driver_locator.h diff --git a/src/hos_celix/include/hos_celix/device_manager/driver_selector.h b/src/hos_celix/include/hos_celix/celix/device_manager/driver_selector.h similarity index 100% rename from src/hos_celix/include/hos_celix/device_manager/driver_selector.h rename to src/hos_celix/include/hos_celix/celix/device_manager/driver_selector.h diff --git a/src/hos_celix/include/hos_celix/device_manager/match.h b/src/hos_celix/include/hos_celix/celix/device_manager/match.h similarity index 100% rename from src/hos_celix/include/hos_celix/device_manager/match.h rename to src/hos_celix/include/hos_celix/celix/device_manager/match.h diff --git a/src/hos_celix/include/hos_celix/event_admin/event_admin.h b/src/hos_celix/include/hos_celix/celix/event_admin/event_admin.h similarity index 100% rename from src/hos_celix/include/hos_celix/event_admin/event_admin.h rename to src/hos_celix/include/hos_celix/celix/event_admin/event_admin.h diff --git a/src/hos_celix/include/hos_celix/event_admin/event_constants.h b/src/hos_celix/include/hos_celix/celix/event_admin/event_constants.h similarity index 100% rename from src/hos_celix/include/hos_celix/event_admin/event_constants.h rename to src/hos_celix/include/hos_celix/celix/event_admin/event_constants.h diff --git a/src/hos_celix/include/hos_celix/event_admin/event_handler.h b/src/hos_celix/include/hos_celix/celix/event_admin/event_handler.h similarity index 100% rename from src/hos_celix/include/hos_celix/event_admin/event_handler.h rename to src/hos_celix/include/hos_celix/celix/event_admin/event_handler.h diff --git a/src/hos_celix/include/hos_celix/exports.h b/src/hos_celix/include/hos_celix/celix/exports.h similarity index 100% rename from src/hos_celix/include/hos_celix/exports.h rename to src/hos_celix/include/hos_celix/celix/exports.h diff --git a/src/hos_celix/include/hos_celix/filter.h b/src/hos_celix/include/hos_celix/celix/filter.h similarity index 100% rename from src/hos_celix/include/hos_celix/filter.h rename to src/hos_celix/include/hos_celix/celix/filter.h diff --git a/src/hos_celix/include/hos_celix/framework.h b/src/hos_celix/include/hos_celix/celix/framework.h similarity index 100% rename from src/hos_celix/include/hos_celix/framework.h rename to src/hos_celix/include/hos_celix/celix/framework.h diff --git a/src/hos_celix/include/hos_celix/framework_event.h b/src/hos_celix/include/hos_celix/celix/framework_event.h similarity index 100% rename from src/hos_celix/include/hos_celix/framework_event.h rename to src/hos_celix/include/hos_celix/celix/framework_event.h diff --git a/src/hos_celix/include/hos_celix/framework_exports.h b/src/hos_celix/include/hos_celix/celix/framework_exports.h similarity index 100% rename from src/hos_celix/include/hos_celix/framework_exports.h rename to src/hos_celix/include/hos_celix/celix/framework_exports.h diff --git a/src/hos_celix/include/hos_celix/framework_listener.h b/src/hos_celix/include/hos_celix/celix/framework_listener.h similarity index 100% rename from src/hos_celix/include/hos_celix/framework_listener.h rename to src/hos_celix/include/hos_celix/celix/framework_listener.h diff --git a/src/hos_celix/include/hos_celix/hash_map.h b/src/hos_celix/include/hos_celix/celix/hash_map.h similarity index 100% rename from src/hos_celix/include/hos_celix/hash_map.h rename to src/hos_celix/include/hos_celix/celix/hash_map.h diff --git a/src/hos_celix/include/hos_celix/linked_list.h b/src/hos_celix/include/hos_celix/celix/linked_list.h similarity index 100% rename from src/hos_celix/include/hos_celix/linked_list.h rename to src/hos_celix/include/hos_celix/celix/linked_list.h diff --git a/src/hos_celix/include/hos_celix/linked_list_iterator.h b/src/hos_celix/include/hos_celix/celix/linked_list_iterator.h similarity index 100% rename from src/hos_celix/include/hos_celix/linked_list_iterator.h rename to src/hos_celix/include/hos_celix/celix/linked_list_iterator.h diff --git a/src/hos_celix/include/hos_celix/listener_hook_service.h b/src/hos_celix/include/hos_celix/celix/listener_hook_service.h similarity index 100% rename from src/hos_celix/include/hos_celix/listener_hook_service.h rename to src/hos_celix/include/hos_celix/celix/listener_hook_service.h diff --git a/src/hos_celix/include/hos_celix/log_service/log_entry.h b/src/hos_celix/include/hos_celix/celix/log_service/log_entry.h similarity index 100% rename from src/hos_celix/include/hos_celix/log_service/log_entry.h rename to src/hos_celix/include/hos_celix/celix/log_service/log_entry.h diff --git a/src/hos_celix/include/hos_celix/log_service/log_helper.h b/src/hos_celix/include/hos_celix/celix/log_service/log_helper.h similarity index 100% rename from src/hos_celix/include/hos_celix/log_service/log_helper.h rename to src/hos_celix/include/hos_celix/celix/log_service/log_helper.h diff --git a/src/hos_celix/include/hos_celix/log_service/log_listener.h b/src/hos_celix/include/hos_celix/celix/log_service/log_listener.h similarity index 100% rename from src/hos_celix/include/hos_celix/log_service/log_listener.h rename to src/hos_celix/include/hos_celix/celix/log_service/log_listener.h diff --git a/src/hos_celix/include/hos_celix/log_service/log_reader_service.h b/src/hos_celix/include/hos_celix/celix/log_service/log_reader_service.h similarity index 100% rename from src/hos_celix/include/hos_celix/log_service/log_reader_service.h rename to src/hos_celix/include/hos_celix/celix/log_service/log_reader_service.h diff --git a/src/hos_celix/include/hos_celix/log_service/log_service.h b/src/hos_celix/include/hos_celix/celix/log_service/log_service.h similarity index 100% rename from src/hos_celix/include/hos_celix/log_service/log_service.h rename to src/hos_celix/include/hos_celix/celix/log_service/log_service.h diff --git a/src/hos_celix/include/hos_celix/manifest.h b/src/hos_celix/include/hos_celix/celix/manifest.h similarity index 100% rename from src/hos_celix/include/hos_celix/manifest.h rename to src/hos_celix/include/hos_celix/celix/manifest.h diff --git a/src/hos_celix/include/hos_celix/module.h b/src/hos_celix/include/hos_celix/celix/module.h similarity index 100% rename from src/hos_celix/include/hos_celix/module.h rename to src/hos_celix/include/hos_celix/celix/module.h diff --git a/src/hos_celix/include/hos_celix/properties.h b/src/hos_celix/include/hos_celix/celix/properties.h similarity index 100% rename from src/hos_celix/include/hos_celix/properties.h rename to src/hos_celix/include/hos_celix/celix/properties.h diff --git a/src/hos_celix/include/hos_celix/requirement.h b/src/hos_celix/include/hos_celix/celix/requirement.h similarity index 100% rename from src/hos_celix/include/hos_celix/requirement.h rename to src/hos_celix/include/hos_celix/celix/requirement.h diff --git a/src/hos_celix/include/hos_celix/service_event.h b/src/hos_celix/include/hos_celix/celix/service_event.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_event.h rename to src/hos_celix/include/hos_celix/celix/service_event.h diff --git a/src/hos_celix/include/hos_celix/service_factory.h b/src/hos_celix/include/hos_celix/celix/service_factory.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_factory.h rename to src/hos_celix/include/hos_celix/celix/service_factory.h diff --git a/src/hos_celix/include/hos_celix/service_listener.h b/src/hos_celix/include/hos_celix/celix/service_listener.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_listener.h rename to src/hos_celix/include/hos_celix/celix/service_listener.h diff --git a/src/hos_celix/include/hos_celix/service_reference.h b/src/hos_celix/include/hos_celix/celix/service_reference.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_reference.h rename to src/hos_celix/include/hos_celix/celix/service_reference.h diff --git a/src/hos_celix/include/hos_celix/service_registration.h b/src/hos_celix/include/hos_celix/celix/service_registration.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_registration.h rename to src/hos_celix/include/hos_celix/celix/service_registration.h diff --git a/src/hos_celix/include/hos_celix/service_registry.h b/src/hos_celix/include/hos_celix/celix/service_registry.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_registry.h rename to src/hos_celix/include/hos_celix/celix/service_registry.h diff --git a/src/hos_celix/include/hos_celix/service_tracker.h b/src/hos_celix/include/hos_celix/celix/service_tracker.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_tracker.h rename to src/hos_celix/include/hos_celix/celix/service_tracker.h diff --git a/src/hos_celix/include/hos_celix/service_tracker_customizer.h b/src/hos_celix/include/hos_celix/celix/service_tracker_customizer.h similarity index 100% rename from src/hos_celix/include/hos_celix/service_tracker_customizer.h rename to src/hos_celix/include/hos_celix/celix/service_tracker_customizer.h diff --git a/src/hos_celix/include/hos_celix/shell/command.h b/src/hos_celix/include/hos_celix/celix/shell/command.h similarity index 100% rename from src/hos_celix/include/hos_celix/shell/command.h rename to src/hos_celix/include/hos_celix/celix/shell/command.h diff --git a/src/hos_celix/include/hos_celix/shell/command_impl.h b/src/hos_celix/include/hos_celix/celix/shell/command_impl.h similarity index 100% rename from src/hos_celix/include/hos_celix/shell/command_impl.h rename to src/hos_celix/include/hos_celix/celix/shell/command_impl.h diff --git a/src/hos_celix/include/hos_celix/shell/shell.h b/src/hos_celix/include/hos_celix/celix/shell/shell.h similarity index 100% rename from src/hos_celix/include/hos_celix/shell/shell.h rename to src/hos_celix/include/hos_celix/celix/shell/shell.h diff --git a/src/hos_celix/include/hos_celix/utils.h b/src/hos_celix/include/hos_celix/celix/utils.h similarity index 100% rename from src/hos_celix/include/hos_celix/utils.h rename to src/hos_celix/include/hos_celix/celix/utils.h diff --git a/src/hos_celix/include/hos_celix/version.h b/src/hos_celix/include/hos_celix/celix/version.h similarity index 100% rename from src/hos_celix/include/hos_celix/version.h rename to src/hos_celix/include/hos_celix/celix/version.h diff --git a/src/hos_celix/include/hos_celix/version_range.h b/src/hos_celix/include/hos_celix/celix/version_range.h similarity index 100% rename from src/hos_celix/include/hos_celix/version_range.h rename to src/hos_celix/include/hos_celix/celix/version_range.h diff --git a/src/hos_celix/include/hos_celix/wire.h b/src/hos_celix/include/hos_celix/celix/wire.h similarity index 100% rename from src/hos_celix/include/hos_celix/wire.h rename to src/hos_celix/include/hos_celix/celix/wire.h diff --git a/src/hos_cosgi_common/CMakeLists.txt b/src/hos_cosgi_common/CMakeLists.txt index d8575a02..85101221 100644 --- a/src/hos_cosgi_common/CMakeLists.txt +++ b/src/hos_cosgi_common/CMakeLists.txt @@ -78,7 +78,7 @@ find_package(catkin REQUIRED COMPONENTS ## CATKIN_DEPENDS: catkin_packages dependent projects also need ## DEPENDS: system dependencies of this project that dependent projects also need catkin_package( - INCLUDE_DIRS include + INCLUDE_DIRS include/${PROJECT_NAME}/ # LIBRARIES hos_cosgi_common CATKIN_DEPENDS hos_celix # DEPENDS system_lib diff --git a/src/hos_cosgi_common/include/hos_cosgi_common/cosgi_common.h b/src/hos_cosgi_common/include/hos_cosgi_common/cosgi_common.h deleted file mode 100644 index 591bfb53..00000000 --- a/src/hos_cosgi_common/include/hos_cosgi_common/cosgi_common.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * cosgi_common.h - * - * Created on: 19.04.2015 - * Author: matzman - */ - -#ifndef INCLUDE_HOS_COSGI_COMMON_COSGI_CORE_H_ -#define INCLUDE_HOS_COSGI_COMMON_COSGI_CORE_H_ - - -namespace hos { -namespace cosgi{ - - -class COSGI_Object_Interface { -public: - virtual ~COSGI_Object_Interface() {} -}; - - -class COSGI_Service_Interface : public COSGI_Object_Interface { -public: - virtual const char* getServiceName() = 0; - virtual void getServiceVersion(int& major, int& minor) = 0; -}; - - -} // namespace cosgi -} // namespace hos - -#endif /* INCLUDE_HOS_COSGI_COMMON_COSGI_CORE_H_ */ diff --git a/src/hos_cosgi_common/include/hos_cosgi_common/hos/cosgi/service/implementation.h b/src/hos_cosgi_common/include/hos_cosgi_common/hos/cosgi/service/implementation.h new file mode 100644 index 00000000..cbe3bab9 --- /dev/null +++ b/src/hos_cosgi_common/include/hos_cosgi_common/hos/cosgi/service/implementation.h @@ -0,0 +1,159 @@ +/* + * impl.h + * + * Created on: 09.05.2015 + * Author: matzman + */ + +#ifndef INCLUDE_HOS_COSGI_COMMON_HOS_COSGI_SERVICE_IMPLEMENTATION_H_ +#define INCLUDE_HOS_COSGI_COMMON_HOS_COSGI_SERVICE_IMPLEMENTATION_H_ + +#include "interface.h" + +#include +#include +#include +#include +#include + + +namespace hos { +namespace cosgi{ +namespace service { +namespace implementation { + + +template +struct ServiceInfo { + static const char* name; + static const int major; + static const int minor; +}; + + +template +class Service : public virtual interface::Service { +public: + virtual const char* getServiceName() { return ServiceInfo<_Service>::name; }; + virtual void getServiceVersion(int& major, int& minor) override { + major = ServiceInfo<_Service>::major; + minor = ServiceInfo<_Service>::minor; + } +}; + + + + +template class Observable {}; + + +template +class Observable<_Event> : public virtual interface::Observable<_Event> { +protected: + std::mutex _observersMutex; + typedef interface::Observer<_Event> observer_type; + typedef std::unordered_set observers_type; + observers_type _observers; +public: + virtual ~Observable() {} + virtual void addObserver(observer_type* o) override { + std::lock_guard lock(_observersMutex); + if (o != nullptr) { + auto elem = _observers.find(o); + if (elem == _observers.end()) { + _observers.insert(o); + } + } + } + virtual void deleteObserver(observer_type* o) override { + std::lock_guard lock(_observersMutex); + if (o != nullptr) { + auto elem = _observers.find(o); + if (elem != _observers.end()) { + _observers.erase(elem); + } + } + } + virtual void deleteObservers() override { + std::lock_guard lock(_observersMutex); + _observers.clear(); + }; + virtual size_t countObservers() override { + std::lock_guard lock(_observersMutex); + return _observers.size(); + } + virtual void notifyObservers(const _Event* e) override { + std::lock_guard lock(_observersMutex); + for (auto l : _observers) { + l->notificationReceived(this, e); + } + } +}; + + + + +template +class Observable<_Key, _Event> : public virtual interface::Observable<_Key, _Event> { +protected: + std::mutex _observersMutex; + typedef interface::Observer<_Key, _Event> observer_type; + typedef std::unordered_multimap<_Key, observer_type*> observers_type; + observers_type _observers; +public: + virtual ~Observable() {} + virtual void addObserver(_Key k, observer_type* o) override { + std::lock_guard lock(_observersMutex); + if (o != nullptr) { + bool _found = false; + auto range = _observers.equal_range(k); + for (auto i = range.first; i != range.second; i++) { + if (i.second == o) { + _found = true; + break; + } + } + if (!_found) { + _observers.insert({k, o}); + } + } + } + virtual void deleteObserver(_Key k, observer_type* o) override { + std::lock_guard lock(_observersMutex); + if (o != nullptr) { + bool _found = false; + auto range = _observers.equal_range(k); + for (auto i = range.first; i != range.second; i++) { + if (i.second == o) { + _observers.erase(i); + break; + } + } + } + } + virtual void deleteObservers() override { + std::lock_guard lock(_observersMutex); + _observers.clear(); + } + virtual size_t countObservers() override { + std::lock_guard lock(_observersMutex); + return _observers.size(); + } + void notifyObservers(_Key k, const _Event* e) override { + std::lock_guard lock(_observersMutex); + auto ol = _observers.equal_range(k); + std::for_each(ol.first, ol.second, [&](const typename observer_type::value_type& o) { + o.second->notificationReceived(this, k, e); + }); + } +}; + + + +} // namespace implementation +} // namespace service +} // namespace cosgi +} // namespace hos + + +#endif /* INCLUDE_HOS_COSGI_COMMON_HOS_COSGI_SERVICE_IMPLEMENTATION_H_ */ diff --git a/src/hos_cosgi_common/include/hos_cosgi_common/hos/cosgi/service/interface.h b/src/hos_cosgi_common/include/hos_cosgi_common/hos/cosgi/service/interface.h new file mode 100644 index 00000000..0ace68d2 --- /dev/null +++ b/src/hos_cosgi_common/include/hos_cosgi_common/hos/cosgi/service/interface.h @@ -0,0 +1,87 @@ +/* + * cosgi_common.h + * + * Created on: 19.04.2015 + * Author: matzman + */ + +#ifndef INCLUDE_HOS_COSGI_COMMON_COSGI_CORE_H_ +#define INCLUDE_HOS_COSGI_COMMON_COSGI_CORE_H_ + + +#include + + +namespace hos { +namespace cosgi{ +namespace service { +namespace interface { + + +class Object { +public: + virtual ~Object() {} +}; + + +class Service : public virtual Object { +public: + virtual const char* getServiceName() = 0; + virtual void getServiceVersion(int& major, int& minor) = 0; +}; + + +template class Observer {}; +template class Observable {}; +template class ObservableObject : public virtual Object, public virtual Observable<_Args...> {}; +template class ObservableService : public virtual Service, public virtual Observable<_Args...> {}; + + +template +class Observer<_Event> : public virtual Object { +public: + typedef Observable<_Event> observable_type; + virtual void notificationReceived(observable_type* o, const _Event* e) = 0; +}; + + +template +class Observer<_Key, _Event> : public virtual Object { +public: + typedef Observable<_Key, _Event> observable_type; + virtual void notificationReceived(observable_type* o, const _Key& key, const _Event* e) = 0; +}; + + +template +class Observable<_Event> : public virtual Object { +protected: + virtual void notifyObservers(const _Event* e) = 0; +public: + typedef Observer<_Event> observer_type; + virtual void addObserver(observer_type* o) = 0; + virtual void deleteObserver(observer_type* o) = 0; + virtual void deleteObservers() = 0; + virtual size_t countObservers() = 0; +}; + + +template +class Observable<_Key, _Event> : public virtual Object { +protected: + virtual void notifyObservers(const _Key& key, const _Event* e) = 0; +public: + typedef Observer<_Key, _Event> observer_type; + virtual void addObserver(_Key& key, observer_type* o) = 0; + virtual void deleteObserver(_Key& key, observer_type* o) = 0; + virtual void deleteObservers() = 0; + virtual size_t countObservers() = 0; +}; + + +} // namespace interface +} // namespace service +} // namespace cosgi +} // namespace hos + +#endif /* INCLUDE_HOS_COSGI_COMMON_COSGI_CORE_H_ */ diff --git a/src/hos_cosgi_devicerepository/CMakeLists.txt b/src/hos_cosgi_devicerepository/CMakeLists.txt index e82d5d3f..9dd033a7 100644 --- a/src/hos_cosgi_devicerepository/CMakeLists.txt +++ b/src/hos_cosgi_devicerepository/CMakeLists.txt @@ -89,7 +89,7 @@ find_package(Boost 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 + INCLUDE_DIRS include/${PROJECT_NAME}/ # LIBRARIES hos_cosgi_devicerepository CATKIN_DEPENDS hos_celix hos_core_msgs hos_cosgi_launcher roscpp hos_cosgi_common hos_libvariant hos_cpp_common # DEPENDS system_lib @@ -110,7 +110,7 @@ include_directories( ${catkin_INCLUDE_DIRS} ${APR_INCLUDE_DIR} ${APR_INCLUDE_DIR}/apr-1.0 - include + include/${PROJECT_NAME}/ ${hos_libvariant_INCLUDE_DIRS}/hos_libvariant ) @@ -121,7 +121,7 @@ set(BUNDLE_NAME "hos_devicerepository") bundle(hos_cosgi_devicerepository SOURCES ${PROJECT_SOURCE_DIR}/src/bundle_activator - ${PROJECT_SOURCE_DIR}/src/hos_devicerepository_service_impl + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/devicerepository/devicerepository_serviceimpl ) target_link_libraries(hos_cosgi_devicerepository ${catkin_LIBRARIES} diff --git a/src/hos_cosgi_devicerepository/include/hos_cosgi_devicerepository/hos_devicerepository_service.h b/src/hos_cosgi_devicerepository/include/hos_cosgi_devicerepository/hos/cosgi/service/devicerepository/devicerepository_service.h similarity index 70% rename from src/hos_cosgi_devicerepository/include/hos_cosgi_devicerepository/hos_devicerepository_service.h rename to src/hos_cosgi_devicerepository/include/hos_cosgi_devicerepository/hos/cosgi/service/devicerepository/devicerepository_service.h index de2606a7..2abf2cbd 100644 --- a/src/hos_cosgi_devicerepository/include/hos_cosgi_devicerepository/hos_devicerepository_service.h +++ b/src/hos_cosgi_devicerepository/include/hos_cosgi_devicerepository/hos/cosgi/service/devicerepository/devicerepository_service.h @@ -2,33 +2,25 @@ #define _HOS_DEVICEREPOSITORY_SERVICE_H_ -#include -#include +#include +#include +#include #include #include #include -// Forward declarations -namespace libvariant { - class Variant; -} -namespace hos { - namespace cosgi { - namespace devicerepository { - class Device; - } - } -} - - - // Service Namespace namespace hos { namespace cosgi { +namespace service { namespace devicerepository { +// Forward declarations +class Device; + +using namespace ::libvariant; /** @@ -41,6 +33,7 @@ public: Device* const device; DeviceEvent(Device* device, EventType type) : device(device), eventType(type) {} }; + /** * Device added **/ @@ -62,9 +55,9 @@ public: **/ class DeviceStatusMsgEvent : public DeviceEvent { public: - DeviceStatusMsgEvent(Device* device, const libvariant::Variant& statusMsg) + DeviceStatusMsgEvent(Device* device, const Variant statusMsg) : DeviceEvent(device, DeviceEvent::EventType::STATUS_UPDATED), statusMsg(statusMsg) {} - const libvariant::Variant& statusMsg; + const Variant statusMsg; }; /** @@ -72,9 +65,9 @@ public: **/ class DeviceCmdMsgEvent : public DeviceEvent { public: - DeviceCmdMsgEvent(Device* device, const libvariant::Variant& cmdMsg) + DeviceCmdMsgEvent(Device* device, const Variant cmdMsg) : DeviceEvent(device, DeviceEvent::EventType::COMMAND_RECEIVED), cmdMsg(cmdMsg) {} - const libvariant::Variant& cmdMsg; + const Variant cmdMsg; }; @@ -82,15 +75,18 @@ public: /** * Public interface of an device object **/ -class Device : public COSGI_Object_Interface, public common::IObservable { +class Device : public virtual interface::ObservableObject { public: virtual const std::string& getDeviceID() = 0; virtual const std::string& getDeviceType() = 0; virtual const std::string& getCmdTopic() = 0; virtual const std::string& getStatusTopic() = 0; - virtual const libvariant::Variant& getCurrentState() = 0; - virtual const libvariant::Variant& getLastState() = 0; + virtual const Variant& getCurrentState() = 0; + virtual const Variant& getLastState() = 0; + + virtual void sendCommand(const Variant cmd) = 0; + virtual bool stateChanged() = 0; }; @@ -98,11 +94,9 @@ public: /** * Public Interface of the device repository service **/ -class HOSDeviceRepositoryService : public COSGI_Service_Interface, public common::IObservable { +class DeviceRepositoryService : public virtual interface::ObservableService { public: static constexpr const char* SERVICE_NAME = "hos_devicerepository_service"; - static constexpr int SERVICE_VERSION_MAJOR = 1; - static constexpr int SERVICE_VERSION_MINOR = 0; virtual std::shared_ptr getDevice(std::string device_id) = 0; virtual size_t getDevices(std::vector>& devices) = 0; @@ -111,6 +105,7 @@ public: } // namespace devicerepository +} // namespace service } // namespace cosgi } // namespace hos diff --git a/src/hos_cosgi_devicerepository/launch/cosgi_devicerepository.launch b/src/hos_cosgi_devicerepository/launch/cosgi_devicerepository.launch index 65876dda..10f841d1 100644 --- a/src/hos_cosgi_devicerepository/launch/cosgi_devicerepository.launch +++ b/src/hos_cosgi_devicerepository/launch/cosgi_devicerepository.launch @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/src/hos_cosgi_devicerepository/src/bundle_activator.cpp b/src/hos_cosgi_devicerepository/src/bundle_activator.cpp index 9812e3e3..ca1d8c94 100644 --- a/src/hos_cosgi_devicerepository/src/bundle_activator.cpp +++ b/src/hos_cosgi_devicerepository/src/bundle_activator.cpp @@ -7,25 +7,25 @@ #include "ros/ros.h" extern "C" { - #include "hos_celix/bundle_activator.h" - #include "hos_celix/bundle_context.h" + #include "celix/bundle_activator.h" + #include "celix/bundle_context.h" } -#include -#include "hos_devicerepository_service_impl.h" +#include +#include "hos/cosgi/service/devicerepository/devicerepository_serviceimpl.h" -#include +#include #include #include using namespace hos::cosgi; -using namespace hos::cosgi::devicerepository; +using namespace hos::cosgi::service::devicerepository; struct UserData { apr_pool_t* memoryPool = nullptr; - std::unique_ptr serviceImpl; + std::unique_ptr serviceImpl; service_registration_pt serviceReg = nullptr; }; @@ -60,11 +60,11 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) if (myUserData->serviceReg != nullptr) { serviceRegistration_unregister(myUserData->serviceReg); } - myUserData->serviceImpl.reset(new HOSDeviceRepositoryServiceImpl()); + myUserData->serviceImpl.reset(new DeviceRepositoryServiceImpl()); // Get HOS Core Service service_reference_pt ref = nullptr; - bundleContext_getServiceReference(context, (char*)core::HOSCoreService::SERVICE_NAME, &ref); - core::HOSCoreService* coreService = nullptr; + bundleContext_getServiceReference(context, (char*)service::core::CoreService::SERVICE_NAME, &ref); + service::core::CoreService* coreService = nullptr; bundleContext_getService(context, ref, (void**)&coreService); if (coreService == nullptr) { ROS_ERROR("DeviceRepositoryService: Could not retrieve HOSCoreService. Are you using hos_cosgi_launcher?"); @@ -73,7 +73,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) } // Register hos-devicerepository-service if (myUserData->serviceImpl->isInitialized()) { - bundleContext_registerService(context, (char*)HOSDeviceRepositoryService::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); + bundleContext_registerService(context, (char*)DeviceRepositoryService::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); } ROS_INFO("DeviceRepositoryService: Bundle successfully started"); } else { diff --git a/src/hos_cosgi_devicerepository/src/hos_devicerepository_service_impl.cpp b/src/hos_cosgi_devicerepository/src/hos/cosgi/service/devicerepository/devicerepository_serviceimpl.cpp similarity index 76% rename from src/hos_cosgi_devicerepository/src/hos_devicerepository_service_impl.cpp rename to src/hos_cosgi_devicerepository/src/hos/cosgi/service/devicerepository/devicerepository_serviceimpl.cpp index 77fd2c48..577fd598 100644 --- a/src/hos_cosgi_devicerepository/src/hos_devicerepository_service_impl.cpp +++ b/src/hos_cosgi_devicerepository/src/hos/cosgi/service/devicerepository/devicerepository_serviceimpl.cpp @@ -5,8 +5,8 @@ * Author: matzman */ -#include "hos_devicerepository_service_impl.h" -#include +#include "devicerepository_serviceimpl.h" +#include #include #include #include @@ -17,8 +17,15 @@ namespace hos { namespace cosgi { +namespace service { namespace devicerepository { + +template<> const char* implementation::ServiceInfo::name = service::devicerepository::DeviceRepositoryService::SERVICE_NAME; +template<> const int implementation::ServiceInfo::major = 0; +template<> const int implementation::ServiceInfo::minor = 4; + + DeviceImpl::DeviceImpl(std::string deviceID, std::string type, std::string statusTopic, std::string cmdTopic) : deviceID(deviceID), deviceType(type), statusTopic(statusTopic), cmdTopic(cmdTopic) { std::cout << "GenericDeviceImpl(" << deviceID << ", " << type << ", " << statusTopic << ", " << cmdTopic << ")" << std::endl; @@ -38,7 +45,15 @@ void DeviceImpl::handleCommandMsg(Variant& msg) { notifyObservers(&event); } -void HOSDeviceRepositoryServiceImpl::setCoreService(core::HOSCoreService* coreService) { +void DeviceImpl::sendCommand(const Variant cmd) { + std::lock_guard lock(objMutex); +} + +bool DeviceImpl::stateChanged() { + return currentState == lastState; +} + +void DeviceRepositoryServiceImpl::setCoreService(service::core::CoreService* coreService) { if (coreService && !this->coreService) { this->coreService = coreService; this->nodehandle = coreService->getPrivateNodeHandle(); @@ -49,7 +64,7 @@ void HOSDeviceRepositoryServiceImpl::setCoreService(core::HOSCoreService* coreSe } } -void HOSDeviceRepositoryServiceImpl::init() { +void DeviceRepositoryServiceImpl::init() { nodehandle->getParam("device_repository_prefix", deviceRepositoryPrefix); nodehandle->getParam("hos_status_topic", hosStatusTopic); XmlRpc::XmlRpcValue rawValue; @@ -66,13 +81,13 @@ void HOSDeviceRepositoryServiceImpl::init() { } } } - hosStatusSub = nodehandle->subscribe(hosStatusTopic, 1000, &HOSDeviceRepositoryServiceImpl::hosStatusMsgCallback, this); + hosStatusSub = nodehandle->subscribe(hosStatusTopic, 1000, &DeviceRepositoryServiceImpl::hosStatusMsgCallback, this); schemaLoader.reset(new libvariant::HosSchemaLoader()); initialized = true; ROS_INFO_STREAM("DeviceRepositoryService: Initialized and Ready."); } -void HOSDeviceRepositoryServiceImpl::addDevice(std::string name) { +void DeviceRepositoryServiceImpl::addDevice(std::string name) { std::stringstream ss; ss << deviceRepositoryPrefix << "/" << name; XmlRpc::XmlRpcValue rawValue; @@ -80,7 +95,7 @@ void HOSDeviceRepositoryServiceImpl::addDevice(std::string name) { addDevice(name, rawValue); } -void HOSDeviceRepositoryServiceImpl::addDevice(std::string name, XmlRpc::XmlRpcValue& rawValue) { +void DeviceRepositoryServiceImpl::addDevice(std::string name, XmlRpc::XmlRpcValue& rawValue) { std::lock_guard lock(serviceMutex); std::string type, statusTopic, cmdTopic; XmlRpc::XmlRpcValue& typeRaw = rawValue["type"]; @@ -100,31 +115,32 @@ void HOSDeviceRepositoryServiceImpl::addDevice(std::string name, XmlRpc::XmlRpcV cmdTopic = static_cast(cmdTopicRaw); std::shared_ptr dev = std::make_shared(name, type, statusTopic, cmdTopic); devices.insert({name, dev}); - // cmd topic - auto& entry = subscripedTopics[dev->getCmdTopic()]; - std::cout << "subCount1: " << entry.first << "." << std::endl; - if (entry.first <= 0) { - entry.second = nodehandle->subscribe(dev->getCmdTopic(), 1000, &HOSDeviceRepositoryServiceImpl::cmdMsgCallback, this); - std::cout << "subscriped to " << dev->getCmdTopic() << "." << std::endl; - } - entry.first= entry.first + 1; - subscripedTopics[dev->getCmdTopic()] = entry; + // status topic - entry = subscripedTopics[dev->getStatusTopic()]; - std::cout << "subCount2: " << entry.first << "." << std::endl; + auto& entry = subscripedTopics[dev->getStatusTopic()]; if (entry.first <= 0) { - entry.second = nodehandle->subscribe(dev->getStatusTopic(), 1000, &HOSDeviceRepositoryServiceImpl::statusMsgCallback, this); + entry.second = nodehandle->subscribe(dev->getStatusTopic(), 1000, &DeviceRepositoryServiceImpl::statusMsgCallback, this); std::cout << "subscriped to " << dev->getStatusTopic() << "." << std::endl; } entry.first= entry.first + 1; subscripedTopics[dev->getStatusTopic()] = entry; + + // cmd topic + auto& entry2 = subscripedTopics[dev->getCmdTopic()]; + if (entry2.first <= 0) { + entry2.second = nodehandle->subscribe(dev->getCmdTopic(), 1000, &DeviceRepositoryServiceImpl::cmdMsgCallback, this); + std::cout << "subscriped to " << dev->getCmdTopic() << "." << std::endl; + } + entry2.first= entry2.first + 1; + subscripedTopics[dev->getCmdTopic()] = entry2; + // send device added event DeviceAddedEvent event(dev.get()); notifyObservers(&event); } -void HOSDeviceRepositoryServiceImpl::removeDevice(std::string name) { +void DeviceRepositoryServiceImpl::removeDevice(std::string name) { std::lock_guard lock(serviceMutex); auto& dev = devices[name]; if (dev) { @@ -136,11 +152,11 @@ void HOSDeviceRepositoryServiceImpl::removeDevice(std::string name) { } -std::shared_ptr HOSDeviceRepositoryServiceImpl::getDevice(std::string device_id) { +std::shared_ptr DeviceRepositoryServiceImpl::getDevice(std::string device_id) { return std::static_pointer_cast(this->devices[device_id]); } -size_t HOSDeviceRepositoryServiceImpl::getDevices(std::vector>& devices) { +size_t DeviceRepositoryServiceImpl::getDevices(std::vector>& devices) { std::lock_guard lock(serviceMutex); size_t retval = 0; for (auto item : this->devices) { @@ -151,13 +167,7 @@ size_t HOSDeviceRepositoryServiceImpl::getDevices(std::vector lock(serviceMutex); std::cout << "HOSDeviceRepositoryServiceImpl::statusMsgCallback" << std::endl; Variant s = schemaLoader->GetSchema(std::string("hos:schema://").append(msg->device_type).append("/status")); @@ -175,7 +185,7 @@ void HOSDeviceRepositoryServiceImpl::statusMsgCallback(const hos_core_msgs::Devi } } -void HOSDeviceRepositoryServiceImpl::cmdMsgCallback(const hos_core_msgs::DeviceCommand::ConstPtr& msg) { +void DeviceRepositoryServiceImpl::cmdMsgCallback(const hos_core_msgs::DeviceCommand::ConstPtr& msg) { std::lock_guard lock(serviceMutex); std::cout << "HOSDeviceRepositoryServiceImpl::cmdMsgCallback" << std::endl; Variant s = schemaLoader->GetSchema(std::string("hos:schema://").append(msg->device_type).append("/command")); @@ -193,7 +203,7 @@ void HOSDeviceRepositoryServiceImpl::cmdMsgCallback(const hos_core_msgs::DeviceC } } -void HOSDeviceRepositoryServiceImpl::hosStatusMsgCallback(const hos_core_msgs::HosStatusUpdate::ConstPtr& msg) { +void DeviceRepositoryServiceImpl::hosStatusMsgCallback(const hos_core_msgs::HosStatusUpdate::ConstPtr& msg) { std::lock_guard lock(serviceMutex); std::cout << "HOSDeviceRepositoryServiceImpl::hosStatusMsgCallback" << std::endl; Variant s = schemaLoader->GetSchema(std::string("hos:schema://core/msgs/hosstatusupdate")); @@ -230,6 +240,7 @@ void HOSDeviceRepositoryServiceImpl::hosStatusMsgCallback(const hos_core_msgs::H } // namespace devicerepository +} // namespace service } // namespace cosgi } // namespace hos diff --git a/src/hos_cosgi_devicerepository/src/hos_devicerepository_service_impl.h b/src/hos_cosgi_devicerepository/src/hos/cosgi/service/devicerepository/devicerepository_serviceimpl.h similarity index 61% rename from src/hos_cosgi_devicerepository/src/hos_devicerepository_service_impl.h rename to src/hos_cosgi_devicerepository/src/hos/cosgi/service/devicerepository/devicerepository_serviceimpl.h index 10c59325..eb50bcb9 100644 --- a/src/hos_cosgi_devicerepository/src/hos_devicerepository_service_impl.h +++ b/src/hos_cosgi_devicerepository/src/hos/cosgi/service/devicerepository/devicerepository_serviceimpl.h @@ -5,11 +5,11 @@ * Author: matzman */ -#ifndef SRC_HOS_DEVICEREPOSITORY_SERVICE_IMPL_H_ -#define SRC_HOS_DEVICEREPOSITORY_SERVICE_IMPL_H_ +#ifndef SRC_HOS_COSGI_SERVICE_DEVICEREPOSITORY_DEVICEREPOSITORY_SERVICEIMPL_H_ +#define SRC_HOS_COSGI_SERVICE_DEVICEREPOSITORY_DEVICEREPOSITORY_SERVICEIMPL_H_ +#include #include -#include #include #include #include @@ -18,8 +18,7 @@ #include #include #include -#include - +#include #include @@ -32,17 +31,20 @@ namespace XmlRpc { class XmlRpcValue; } namespace hos { - namespace cosgi { - namespace core { - class HOSCoreService; - } - } +namespace cosgi { +namespace service { +namespace core { +class CoreService; +} +} +} } // Service Namespace namespace hos { namespace cosgi { +namespace service { namespace devicerepository { @@ -50,8 +52,7 @@ namespace devicerepository { /** * Device implementation **/ -class DeviceImpl : public Device { -OBSERVABLE_IMPL(DeviceEvent) +class DeviceImpl : public virtual Device, public virtual implementation::Observable { private: std::mutex objMutex; std::string deviceID; @@ -66,13 +67,17 @@ public: /* Public Service Implementations */ - virtual const std::string& getDeviceID() { return deviceID; } - virtual const std::string& getDeviceType() { return deviceType; } - virtual const std::string& getCmdTopic() { return cmdTopic; } - virtual const std::string& getStatusTopic() { return statusTopic; } + virtual const std::string& getDeviceID() override { return deviceID; } + virtual const std::string& getDeviceType() override { return deviceType; } + virtual const std::string& getCmdTopic() override { return cmdTopic; } + virtual const std::string& getStatusTopic() override { return statusTopic; } - virtual const Variant& getCurrentState() { return currentState; } - virtual const Variant& getLastState() { return lastState; } + virtual const Variant& getCurrentState() override { return currentState; } + virtual const Variant& getLastState() override { return lastState; } + + virtual void sendCommand(const Variant cmd) override; + + virtual bool stateChanged() override; /* Internal Stuff */ @@ -86,21 +91,20 @@ public: /** * Implementation of device repository service **/ -class HOSDeviceRepositoryServiceImpl : public HOSDeviceRepositoryService { -OBSERVABLE_IMPL(DeviceEvent) +class DeviceRepositoryServiceImpl; +class DeviceRepositoryServiceImpl : public virtual DeviceRepositoryService, public virtual implementation::Service, public virtual implementation::Observable { private: - typedef std::map> devicesMap_t; - typedef std::map> subscripedTopicMap_t; - std::recursive_mutex serviceMutex; ros::NodeHandle* nodehandle = nullptr; - core::HOSCoreService* coreService = nullptr; + service::core::CoreService* coreService = nullptr; std::string deviceRepositoryPrefix = "/hos/devices/repository"; std::string hosStatusTopic = "/hos/status/updates"; + typedef std::map> devicesMap_t; devicesMap_t devices; + typedef std::map> subscripedTopicMap_t; subscripedTopicMap_t subscripedTopics; ros::Subscriber hosStatusSub; @@ -117,15 +121,12 @@ private: public: /* Initialization */ - void setCoreService(core::HOSCoreService* coreService); + void setCoreService(service::core::CoreService* coreService); /* Public Service Implementations */ - virtual std::shared_ptr getDevice(std::string device_id); - virtual size_t getDevices(std::vector>& devices); - - virtual const char* getServiceName() { return SERVICE_NAME; } - virtual void getServiceVersion(int& major, int& minor); + virtual std::shared_ptr getDevice(std::string device_id) override; + virtual size_t getDevices(std::vector>& devices) override; /* Message Callbacks */ @@ -140,8 +141,9 @@ public: } // namespace devicerepository +} // namespace service } // namespace cosgi } // namespace hos -#endif /* SRC_HOS_DEVICEREPOSITORY_SERVICE_IMPL_H_ */ +#endif /* SRC_HOS_COSGI_SERVICE_DEVICEREPOSITORY_DEVICEREPOSITORY_SERVICEIMPL_H_ */ diff --git a/src/hos_cosgi_launcher/CMakeLists.txt b/src/hos_cosgi_launcher/CMakeLists.txt index e7a809e9..061ef409 100644 --- a/src/hos_cosgi_launcher/CMakeLists.txt +++ b/src/hos_cosgi_launcher/CMakeLists.txt @@ -82,7 +82,7 @@ find_package(APR 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 + INCLUDE_DIRS include/${PROJECT_NAME}/ # LIBRARIES hos_cosgi_launcher CATKIN_DEPENDS hos_celix hos_cosgi_common # DEPENDS system_lib @@ -103,13 +103,13 @@ include_directories( ${catkin_INCLUDE_DIRS} ${APR_INCLUDE_DIR} ${APR_INCLUDE_DIR}/apr-1.0 - include + include/${PROJECT_NAME}/ ) add_executable(hos_cosgi_launcher - src/hos_cosgi_launcher.cpp - src/hos_core_service_impl.cpp + src/launcher.cpp + src/hos/cosgi/service/core/core_serviceimpl.cpp ) target_link_libraries(hos_cosgi_launcher ${catkin_LIBRARIES} diff --git a/src/hos_cosgi_launcher/include/hos_cosgi_launcher/hos_core_service.h b/src/hos_cosgi_launcher/include/hos_cosgi_launcher/hos/cosgi/service/core/core_service.h similarity index 74% rename from src/hos_cosgi_launcher/include/hos_cosgi_launcher/hos_core_service.h rename to src/hos_cosgi_launcher/include/hos_cosgi_launcher/hos/cosgi/service/core/core_service.h index 6b4a5edd..cc106090 100644 --- a/src/hos_cosgi_launcher/include/hos_cosgi_launcher/hos_core_service.h +++ b/src/hos_cosgi_launcher/include/hos_cosgi_launcher/hos/cosgi/service/core/core_service.h @@ -2,8 +2,8 @@ #define SRC_HOS_CORE_SERVICE_H_ -#include -#include +#include +#include // Forward declarations @@ -16,6 +16,7 @@ namespace ros { // Service Namespace namespace hos { namespace cosgi { +namespace service { namespace core { @@ -35,19 +36,16 @@ public: -class HOSCoreService : public COSGI_Service_Interface, public common::IObservable { +class CoreService : public virtual interface::ObservableService { public: static constexpr const char* SERVICE_NAME = "hos_core_service"; - static constexpr int SERVICE_VERSION_MAJOR = 1; - static constexpr int SERVICE_VERSION_MINOR = 0; - virtual ros::NodeHandle* getPublicNodeHandle() = 0; virtual ros::NodeHandle* getPrivateNodeHandle() = 0; virtual void requestShutdown() = 0; }; - } // namespace core +} // namespace service } // namespace cosgi } // namespace hos diff --git a/src/hos_cosgi_launcher/src/hos/cosgi/service/core/core_serviceimpl.cpp b/src/hos_cosgi_launcher/src/hos/cosgi/service/core/core_serviceimpl.cpp new file mode 100644 index 00000000..9569dbcf --- /dev/null +++ b/src/hos_cosgi_launcher/src/hos/cosgi/service/core/core_serviceimpl.cpp @@ -0,0 +1,43 @@ +/* + * hos_core_service_impl.cpp + * + * Created on: 05.04.2015 + * Author: matzman + */ + +#include +#include "core_serviceimpl.h" + +namespace hos { +namespace cosgi{ +namespace service { +namespace core { + +template<> const char* implementation::ServiceInfo::name = service::core::CoreService::SERVICE_NAME; +template<> const int implementation::ServiceInfo::major = 0; +template<> const int implementation::ServiceInfo::minor = 3; + +CoreServiceImpl::CoreServiceImpl(ros::NodeHandle* publicNodeHandle, ros::NodeHandle* privateNodeHandle) + : publicNodeHandle(publicNodeHandle), privateNodeHandle(privateNodeHandle) {} + + +ros::NodeHandle* CoreServiceImpl::getPublicNodeHandle() { + return publicNodeHandle; +} + +ros::NodeHandle* CoreServiceImpl::getPrivateNodeHandle() { + return privateNodeHandle; +} + + +void CoreServiceImpl::requestShutdown() { + ROS_INFO("Received shutdown request"); + ros::shutdown(); +} + + +} // namespace core +} // namespace service +} // namespace cosgi +} // namespace hos + diff --git a/src/hos_cosgi_launcher/src/hos/cosgi/service/core/core_serviceimpl.h b/src/hos_cosgi_launcher/src/hos/cosgi/service/core/core_serviceimpl.h new file mode 100644 index 00000000..c52be660 --- /dev/null +++ b/src/hos_cosgi_launcher/src/hos/cosgi/service/core/core_serviceimpl.h @@ -0,0 +1,42 @@ +/* + * hos_core_service_private.h + * + * Created on: 05.04.2015 + * Author: matzman + */ + +#ifndef SRC_CORE_SERVICEIMPL_H_ +#define SRC_CORE_SERVICEIMPL_H_ + +#include +#include + + +// Service Namespace +namespace hos { +namespace cosgi{ +namespace service { +namespace core { + + +class CoreServiceImpl; +class CoreServiceImpl : public virtual CoreService, public virtual implementation::Service, public virtual implementation::Observable { +private: + ros::NodeHandle* publicNodeHandle; + ros::NodeHandle* privateNodeHandle; + +public: + CoreServiceImpl(ros::NodeHandle* publicNodeHandle, ros::NodeHandle* privateNodeHandle); + + virtual ros::NodeHandle* getPublicNodeHandle(); + virtual ros::NodeHandle* getPrivateNodeHandle(); + virtual void requestShutdown(); +}; + +} // namespace core +} // namespace service +} // namespace cosgi +} // namespace hos + + +#endif /* SRC_CORE_SERVICEIMPL_H_ */ diff --git a/src/hos_cosgi_launcher/src/hos_core_service_impl.cpp b/src/hos_cosgi_launcher/src/hos_core_service_impl.cpp deleted file mode 100644 index b5d81990..00000000 --- a/src/hos_cosgi_launcher/src/hos_core_service_impl.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * hos_core_service_impl.cpp - * - * Created on: 05.04.2015 - * Author: matzman - */ - -#include "hos_core_service_impl.h" -#include - -namespace hos { -namespace cosgi{ -namespace core { - - -HOSCoreServiceImpl::HOSCoreServiceImpl(ros::NodeHandle* publicNodeHandle, ros::NodeHandle* privateNodeHandle) - : publicNodeHandle(publicNodeHandle), privateNodeHandle(privateNodeHandle) {} - - -ros::NodeHandle* HOSCoreServiceImpl::getPublicNodeHandle() { - return publicNodeHandle; -} - -ros::NodeHandle* HOSCoreServiceImpl::getPrivateNodeHandle() { - return privateNodeHandle; -} - - -void HOSCoreServiceImpl::requestShutdown() { - ROS_INFO("Received shutdown request"); - ros::shutdown(); -} - -void HOSCoreServiceImpl::getServiceVersion(int& major, int& minor) { - major = SERVICE_VERSION_MAJOR; - minor = SERVICE_VERSION_MINOR; -} - - -} // namespace core -} // namespace cosgi -} // namespace hos - diff --git a/src/hos_cosgi_launcher/src/hos_core_service_impl.h b/src/hos_cosgi_launcher/src/hos_core_service_impl.h deleted file mode 100644 index 304d5eee..00000000 --- a/src/hos_cosgi_launcher/src/hos_core_service_impl.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * hos_core_service_private.h - * - * Created on: 05.04.2015 - * Author: matzman - */ - -#ifndef SRC_HOS_CORE_SERVICE_IMPL_H_ -#define SRC_HOS_CORE_SERVICE_IMPL_H_ - -#include -#include - - -// Service Namespace -namespace hos { -namespace cosgi{ -namespace core { - - - -class HOSCoreServiceImpl : public HOSCoreService { -OBSERVABLE_IMPL(CoreEvent) -private: - ros::NodeHandle* publicNodeHandle; - ros::NodeHandle* privateNodeHandle; - -public: - HOSCoreServiceImpl(ros::NodeHandle* publicNodeHandle, ros::NodeHandle* privateNodeHandle); - - virtual ros::NodeHandle* getPublicNodeHandle(); - virtual ros::NodeHandle* getPrivateNodeHandle(); - virtual void requestShutdown(); - virtual const char* getServiceName() { return SERVICE_NAME; } - virtual void getServiceVersion(int& major, int& minor); -}; - -} // namespace core -} // namespace cosgi -} // namespace hos - - -#endif /* SRC_HOS_CORE_SERVICE_IMPL_H_ */ diff --git a/src/hos_cosgi_launcher/src/hos_cosgi_launcher.cpp b/src/hos_cosgi_launcher/src/launcher.cpp similarity index 93% rename from src/hos_cosgi_launcher/src/hos_cosgi_launcher.cpp rename to src/hos_cosgi_launcher/src/launcher.cpp index 32040d34..2c32b437 100644 --- a/src/hos_cosgi_launcher/src/hos_cosgi_launcher.cpp +++ b/src/hos_cosgi_launcher/src/launcher.cpp @@ -1,15 +1,14 @@ -#include "hos_core_service_impl.h" - #include #include "ros/ros.h" #include #include + +#include "hos/cosgi/service/core/core_serviceimpl.h" + extern "C" { // celix does not provide C++ ready headers - //#include "hos_celix/celix_errno.h" - #include "hos_celix/framework.h" - //#include "hos_celix/bundle_context.h" - #include "hos_celix/linked_list_iterator.h" + #include "celix/framework.h" + #include "celix/linked_list_iterator.h" } #include #include @@ -18,7 +17,7 @@ extern "C" { // celix does not provide C++ ready headers #include -using namespace hos::cosgi::core; +using namespace hos::cosgi::service::core; std::function signalHandler; @@ -103,9 +102,9 @@ int main(int argc, char **argv) { bundle_getContext(fwBundle, &context); // Create and register hos-core-service - HOSCoreServiceImpl hosCoreService(&rosPublicNodeHandle, &rosPrivateNodeHandle); + CoreServiceImpl hosCoreService(&rosPublicNodeHandle, &rosPrivateNodeHandle); service_registration_pt reg = nullptr; - bundleContext_registerService(context, (char*)HOSCoreService::SERVICE_NAME, static_cast(&hosCoreService), nullptr, ®); + bundleContext_registerService(context, (char*)CoreService::SERVICE_NAME, static_cast(&hosCoreService), nullptr, ®); ROS_INFO("HOS core service registered"); diff --git a/src/hos_cosgi_rulesengine/CMakeLists.txt b/src/hos_cosgi_ruleengine/CMakeLists.txt similarity index 83% rename from src/hos_cosgi_rulesengine/CMakeLists.txt rename to src/hos_cosgi_ruleengine/CMakeLists.txt index 0a86d339..ae95c6db 100644 --- a/src/hos_cosgi_rulesengine/CMakeLists.txt +++ b/src/hos_cosgi_ruleengine/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8.3) -project(hos_cosgi_rulesengine) +project(hos_cosgi_ruleengine) ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) @@ -9,9 +9,11 @@ find_package(catkin REQUIRED COMPONENTS hos_cosgi_common hos_cosgi_devicerepository hos_cosgi_launcher + hos_cosgi_scripting hos_cpp_common hos_libvariant roscpp + hos_cpp_cron ) ## System dependencies are found with CMake's conventions @@ -30,7 +32,6 @@ 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 @@ -88,9 +89,9 @@ find_package(Boost 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_cosgi_rulesengine - CATKIN_DEPENDS hos_celix hos_cosgi_common hos_cosgi_devicerepository hos_cosgi_launcher hos_cpp_common hos_libvariant roscpp + INCLUDE_DIRS include/${PROJECT_NAME}/ +# LIBRARIES hos_cosgi_ruleengine + CATKIN_DEPENDS hos_celix hos_cosgi_common hos_cosgi_devicerepository hos_cosgi_launcher hos_cpp_common hos_libvariant roscpp hos_cpp_cron hos_cosgi_scripting # DEPENDS system_lib ) @@ -109,41 +110,41 @@ include_directories( ${catkin_INCLUDE_DIRS} ${APR_INCLUDE_DIR} ${APR_INCLUDE_DIR}/apr-1.0 - include + include/${PROJECT_NAME}/ ${hos_libvariant_INCLUDE_DIRS}/hos_libvariant ) -set(BUNDLE_SYMBOLICNAME "hos.hos_rulesengine") +set(BUNDLE_SYMBOLICNAME "hos.hos_ruleengine") set(BUNDLE_VERSION "1.0.0") -set(BUNDLE_NAME "hos_rulesengine") +set(BUNDLE_NAME "hos_ruleengine") -bundle(hos_cosgi_rulesengine +bundle(hos_cosgi_ruleengine SOURCES ${PROJECT_SOURCE_DIR}/src/bundle_activator - ${PROJECT_SOURCE_DIR}/src/hos_rulesengine_service_impl - ${PROJECT_SOURCE_DIR}/src/rulesengine/RulePackage - ${PROJECT_SOURCE_DIR}/src/rulesengine/Rule - ${PROJECT_SOURCE_DIR}/src/rulesengine/RuleCondition + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/ruleengine/ruleengine_serviceimpl + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/ruleengine/rule/RulePackage + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/ruleengine/rule/Rule + ${PROJECT_SOURCE_DIR}/src/hos/cosgi/service/ruleengine/rule/RuleCondition ) -target_link_libraries(hos_cosgi_rulesengine +target_link_libraries(hos_cosgi_ruleengine ${catkin_LIBRARIES} ${APR_LIBRARIES} ) ## Declare a cpp library -# add_library(hos_cosgi_rulesengine -# src/${PROJECT_NAME}/hos_cosgi_rulesengine.cpp +# add_library(hos_cosgi_ruleengine +# src/${PROJECT_NAME}/hos_cosgi_ruleengine.cpp # ) ## Declare a cpp executable -# add_executable(hos_cosgi_rulesengine_node src/hos_cosgi_rulesengine_node.cpp) +# add_executable(hos_cosgi_ruleengine_node src/hos_cosgi_ruleengine_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_rulesengine_node hos_cosgi_rulesengine_generate_messages_cpp) +# add_dependencies(hos_cosgi_ruleengine_node hos_cosgi_ruleengine_generate_messages_cpp) ## Specify libraries to link a library or executable target against -# target_link_libraries(hos_cosgi_rulesengine_node +# target_link_libraries(hos_cosgi_ruleengine_node # ${catkin_LIBRARIES} # ) @@ -158,7 +159,7 @@ install(DIRECTORY include/${PROJECT_NAME}/ ) install(FILES - ${CMAKE_BINARY_DIR}/hos_cosgi_rulesengine.zip + ${CMAKE_BINARY_DIR}/hos_cosgi_ruleengine.zip DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/bundles ) @@ -173,7 +174,7 @@ install(FILES # ) ## Mark executables and/or libraries for installation -# install(TARGETS hos_cosgi_rulesengine hos_cosgi_rulesengine_node +# install(TARGETS hos_cosgi_ruleengine hos_cosgi_ruleengine_node # ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} # LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} # RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} @@ -198,7 +199,7 @@ install(FILES ############# ## Add gtest based cpp test target and link libraries -# catkin_add_gtest(${PROJECT_NAME}-test test/test_hos_cosgi_rulesengine.cpp) +# catkin_add_gtest(${PROJECT_NAME}-test test/test_hos_cosgi_ruleengine.cpp) # if(TARGET ${PROJECT_NAME}-test) # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) # endif() diff --git a/src/hos_cosgi_ruleengine/include/hos_cosgi_ruleengine/hos/cosgi/service/ruleengine/ruleengine_service.h b/src/hos_cosgi_ruleengine/include/hos_cosgi_ruleengine/hos/cosgi/service/ruleengine/ruleengine_service.h new file mode 100644 index 00000000..4e0f3519 --- /dev/null +++ b/src/hos_cosgi_ruleengine/include/hos_cosgi_ruleengine/hos/cosgi/service/ruleengine/ruleengine_service.h @@ -0,0 +1,36 @@ +/* + * hos_ruleengine_service.h + * + * Created on: 26.04.2015 + * Author: matzman + */ + +#ifndef INCLUDE_HOS_COSGI_RULEENGINE_HOS_COSGI_SERVICE_RULEENGINE_RULEENGINE_SERVICE_H_ +#define INCLUDE_HOS_COSGI_RULEENGINE_HOS_COSGI_SERVICE_RULEENGINE_RULEENGINE_SERVICE_H_ + + +#include +#include + + +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { + + +class RuleEngineService : public virtual interface::Service { +public: + static constexpr const char* SERVICE_NAME = "hos_ruleengine_service"; +}; + + +} // namespace ruleengine +} // namespace service +} // namespace cosgi +} // namespace hos + + + + +#endif /* INCLUDE_HOS_COSGI_RULEENGINE_HOS_COSGI_SERVICE_RULEENGINE_RULEENGINE_SERVICE_H_ */ diff --git a/src/hos_cosgi_ruleengine/launch/cosgi_ruleengine.launch b/src/hos_cosgi_ruleengine/launch/cosgi_ruleengine.launch new file mode 100644 index 00000000..2d40d40f --- /dev/null +++ b/src/hos_cosgi_ruleengine/launch/cosgi_ruleengine.launch @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/hos_cosgi_rulesengine/notes/notes.txt b/src/hos_cosgi_ruleengine/notes/notes.txt similarity index 100% rename from src/hos_cosgi_rulesengine/notes/notes.txt rename to src/hos_cosgi_ruleengine/notes/notes.txt diff --git a/src/hos_cosgi_rulesengine/notes/rulesengine.ecore b/src/hos_cosgi_ruleengine/notes/rulesengine.ecore similarity index 100% rename from src/hos_cosgi_rulesengine/notes/rulesengine.ecore rename to src/hos_cosgi_ruleengine/notes/rulesengine.ecore diff --git a/src/hos_cosgi_rulesengine/notes/rulesengine.ecore_diagram b/src/hos_cosgi_ruleengine/notes/rulesengine.ecore_diagram similarity index 100% rename from src/hos_cosgi_rulesengine/notes/rulesengine.ecore_diagram rename to src/hos_cosgi_ruleengine/notes/rulesengine.ecore_diagram diff --git a/src/hos_cosgi_rulesexecution_python/package.xml b/src/hos_cosgi_ruleengine/package.xml similarity index 80% rename from src/hos_cosgi_rulesexecution_python/package.xml rename to src/hos_cosgi_ruleengine/package.xml index 83fbfd52..6aa92d5b 100644 --- a/src/hos_cosgi_rulesexecution_python/package.xml +++ b/src/hos_cosgi_ruleengine/package.xml @@ -1,8 +1,8 @@ - hos_cosgi_rulesexecution_python + hos_cosgi_ruleengine 0.0.0 - The hos_cosgi_rulesexecution_python package + The hos_cosgi_ruleengine package @@ -19,7 +19,7 @@ - + @@ -42,16 +42,22 @@ catkin hos_celix hos_cosgi_common + hos_cosgi_devicerepository hos_cosgi_launcher - hos_cosgi_rulesengine + hos_cosgi_scripting hos_cpp_common hos_libvariant + roscpp + hos_cpp_cron hos_celix hos_cosgi_common + hos_cosgi_devicerepository hos_cosgi_launcher - hos_cosgi_rulesengine hos_cpp_common hos_libvariant + roscpp + hos_cpp_cron + hos_cosgi_scripting diff --git a/src/hos_cosgi_rulesengine/src/bundle_activator.cpp b/src/hos_cosgi_ruleengine/src/bundle_activator.cpp similarity index 62% rename from src/hos_cosgi_rulesengine/src/bundle_activator.cpp rename to src/hos_cosgi_ruleengine/src/bundle_activator.cpp index 1b4b6860..97ff0d7e 100644 --- a/src/hos_cosgi_rulesengine/src/bundle_activator.cpp +++ b/src/hos_cosgi_ruleengine/src/bundle_activator.cpp @@ -13,28 +13,28 @@ #include "ros/ros.h" extern "C" { - #include "hos_celix/bundle_activator.h" - #include "hos_celix/bundle_context.h" - #include "hos_celix/service_listener.h" - #include "hos_celix/service_reference.h" - #include "hos_celix/constants.h" + #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_rulesengine_service_impl.h" +#include +#include "hos/cosgi/service/ruleengine/ruleengine_serviceimpl.h" #include #include -using namespace hos::cosgi::rulesengine; -using namespace hos::cosgi::rulesexecution; -using namespace hos::cosgi::devicerepository; -using namespace hos::cosgi::core; +using namespace hos::cosgi::service::ruleengine; +using namespace hos::cosgi::service::scripting; +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; + std::unique_ptr serviceImpl = nullptr; service_registration_pt serviceReg = nullptr; serviceListener myServiceListener; bundle_context_pt bundleContext; @@ -47,20 +47,20 @@ celix_status_t cb_serviceChanged(void* listener, service_event_pt event) { char* serviceName = nullptr; bool checkReg = false; serviceReference_getProperty(event->reference, (char*)OSGI_FRAMEWORK_OBJECTCLASS, &serviceName); - if (serviceName && std::strcmp(serviceName, HOSDeviceRepositoryService::SERVICE_NAME) == 0) { - HOSDeviceRepositoryService *service = nullptr; + 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; - } else if (serviceName && std::strcmp(serviceName, HOSRulesExecutionService::SERVICE_NAME) == 0) { - HOSRulesExecutionService *service = nullptr; + } else if (serviceName && std::strcmp(serviceName, ScriptingService::SERVICE_NAME) == 0) { + ScriptingService *service = nullptr; bundleContext_getService(myUserData->bundleContext, event->reference, (void**)&service); myUserData->serviceImpl->addExecutionBackend(service); checkReg = true; } // Register hos-devicerepository-service if (checkReg && !myUserData->serviceReg && myUserData->serviceImpl->isInitialized()) { - bundleContext_registerService(myUserData->bundleContext, (char*)HOSRulesEngineServiceImpl::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); + bundleContext_registerService(myUserData->bundleContext, (char*)RuleEngineServiceImpl::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); } } else if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) { } @@ -73,7 +73,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData // Create APR memory pool apr_status_t astatus = apr_pool_create(&memoryPool, NULL); if (astatus != APR_SUCCESS) { - ROS_ERROR("RulesEngineService: Could not create APR memory pool (%i).", astatus); + ROS_ERROR("RuleEngineService: Could not create APR memory pool (%i).", astatus); } else { // Create user data UserData* myUserData = (UserData*)apr_palloc(memoryPool, sizeof(UserData)); @@ -82,9 +82,9 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData myUserData->bundleContext = context; *userData = (void*)myUserData; status = CELIX_SUCCESS; - ROS_INFO("RulesEngineService: Bundle successfully created"); + ROS_INFO("RuleEngineService: Bundle successfully created"); } else { - ROS_ERROR("RulesEngineService: Could not create user data struct"); + ROS_ERROR("RuleEngineService: Could not create user data struct"); apr_pool_destroy(memoryPool); } } @@ -100,39 +100,36 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) serviceRegistration_unregister(myUserData->serviceReg); myUserData->serviceReg = nullptr; } - myUserData->serviceImpl.reset(new HOSRulesEngineServiceImpl()); + myUserData->serviceImpl.reset(new RuleEngineServiceImpl()); // Get HOS Core Service service_reference_pt ref = nullptr; - bundleContext_getServiceReference(context, (char*)HOSCoreService::SERVICE_NAME, &ref); - HOSCoreService* coreService = nullptr; + bundleContext_getServiceReference(context, (char*)CoreService::SERVICE_NAME, &ref); + CoreService* coreService = nullptr; bundleContext_getService(context, ref, (void**)&coreService); if (coreService == nullptr) { - ROS_ERROR("RulesEngineService: Could not retrieve HOSCoreService. Are you using hos_cosgi_launcher?"); + ROS_ERROR("RuleEngineService: 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*)HOSDeviceRepositoryService::SERVICE_NAME, &ref2); - HOSDeviceRepositoryService* repoService = 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*)HOSRulesEngineServiceImpl::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); + bundleContext_registerService(context, (char*)RuleEngineServiceImpl::SERVICE_NAME, myUserData->serviceImpl.get(), nullptr, &myUserData->serviceReg); } // Register service listener myUserData->myServiceListener.handle = myUserData; myUserData->myServiceListener.serviceChanged = cb_serviceChanged; - char filter[256]; - std::snprintf(filter, 256, "(objectClass=%s|objectClass=%s)", HOSDeviceRepositoryService::SERVICE_NAME, HOSRulesExecutionService::SERVICE_NAME); - //bundleContext_addServiceListener(context, &myUserData->myServiceListener, filter); bundleContext_addServiceListener(context, &myUserData->myServiceListener, nullptr); - ROS_INFO("RulesEngineService: Bundle successfully started"); + ROS_INFO("RuleEngineService: Bundle successfully started"); } else { - ROS_ERROR("RulesEngineService: Could not start bundle, user data struct is null"); + ROS_ERROR("RuleEngineService: Could not start bundle, user data struct is null"); } return status; } @@ -149,10 +146,10 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) if (myUserData->serviceImpl) { myUserData->serviceImpl.reset(); } - ROS_INFO("RulesEngineService: Bundle successfully stopped"); + ROS_INFO("RuleEngineService: Bundle successfully stopped"); status = CELIX_SUCCESS; } else { - ROS_ERROR("RulesEngineService: Could not stop bundle, user data struct is null"); + ROS_ERROR("RuleEngineService: Could not stop bundle, user data struct is null"); } return status; } @@ -163,13 +160,13 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt contex apr_pool_t* memoryPool = ((UserData*)userData)->memoryPool; if (memoryPool != nullptr) { apr_pool_destroy(memoryPool); - ROS_INFO("RulesEngineService: Bundle successfully destroyed"); + ROS_INFO("RuleEngineService: Bundle successfully destroyed"); } else { - ROS_ERROR("RulesEngineService: Could not destroy bundle, there is no APR memory pool"); + ROS_ERROR("RuleEngineService: Could not destroy bundle, there is no APR memory pool"); } status = CELIX_SUCCESS; } else { - ROS_ERROR("RulesEngineService: Could not destroy bundle, user data struct is null"); + ROS_ERROR("RuleEngineService: Could not destroy bundle, user data struct is null"); } return status; } diff --git a/src/hos_cosgi_rulesengine/src/rulesengine/Rule.cpp b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/Rule.cpp similarity index 65% rename from src/hos_cosgi_rulesengine/src/rulesengine/Rule.cpp rename to src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/Rule.cpp index 3da6bf67..a3c9d324 100644 --- a/src/hos_cosgi_rulesengine/src/rulesengine/Rule.cpp +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/Rule.cpp @@ -7,22 +7,26 @@ #include "Rule.h" + +#include + #include "RuleCondition.h" -#include #include namespace hos { namespace cosgi { -namespace rulesengine { +namespace service { +namespace ruleengine { +namespace rule { -Rule::Rule(RulePackage* parent, std::string name, rulesexecution::HOSRulesExecutionService* executionService) +Rule::Rule(RulePackage* parent, std::string name, scripting::ScriptingService* executionService) : parent(parent), name(name), executionService(executionService) {} Rule::~Rule() {} -std::shared_ptr Rule::createRule(RulePackage* parent, std::string name, rulesexecution::GlobalExecutionContext* gContext, libvariant::Variant raw, rulesexecution::HOSRulesExecutionService* executionService) { +std::shared_ptr Rule::createRule(RulePackage* parent, std::string name, scripting::GlobalScriptContext* gContext, Variant raw, scripting::ScriptingService* executionService) { std::shared_ptr retval; if (raw.IsMap()) { retval = std::make_shared(parent, name, executionService); @@ -33,7 +37,7 @@ std::shared_ptr Rule::createRule(RulePackage* parent, std::string name, ru retval->conditions.push_back(cond); } if (raw.HasPath("body") && raw["body"].IsMap()) { - retval->body = executionService->createRuleBody(retval.get(), gContext, raw["body"]); + retval->body = executionService->createScript(gContext, raw["body"]); } else { ROS_ERROR_STREAM("Could not create rule \"" << name << "\"."); retval.reset(); @@ -46,11 +50,13 @@ std::shared_ptr Rule::createRule(RulePackage* parent, std::string name, ru return retval; } -void Rule::exec(rulesexecution::GlobalExecutionContext* gContext) { +void Rule::exec(scripting::GlobalScriptContext* gContext) { body->exec(gContext); } -} /* namespace rulesengine */ +} /* namespace rule */ +} /* namespace ruleengine */ +} /* namespace service */ } /* namespace cosgi */ } /* namespace hos */ diff --git a/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/Rule.h b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/Rule.h new file mode 100644 index 00000000..a0ab8f82 --- /dev/null +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/Rule.h @@ -0,0 +1,75 @@ +/* + * Rule.h + * + * Created on: 29.04.2015 + * Author: matzman + */ + +#ifndef SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULE_H_ +#define SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULE_H_ + + +#include +#include +#include +#include + + +// Forward declarations +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { +namespace rule { +class RulePackage; +class RuleCondition; +} +} +namespace scripting { +class ScriptingService; +class GlobalScriptContext; +class Script; +} +} +} +} + + +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { +namespace rule { + +using namespace libvariant; + +class Rule { +private: + RulePackage* parent; + std::string name; + std::shared_ptr body; + std::vector> conditions; + scripting::ScriptingService* executionService; +public: + Rule(RulePackage* parent, std::string name, scripting::ScriptingService* executionService); + static std::shared_ptr createRule(RulePackage* parent, std::string name, scripting::GlobalScriptContext* gContext, Variant raw, scripting::ScriptingService* executionService); + virtual ~Rule(); + + RulePackage* getParent() { return parent; } + + virtual void exec(scripting::GlobalScriptContext* gContext); +}; + +class RuleBody { + +}; + + +} /* namespace rule */ +} /* namespace ruleengine */ +} /* namespace service */ +} /* namespace cosgi */ +} /* namespace hos */ + + +#endif /* SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULE_H_ */ diff --git a/src/hos_cosgi_rulesengine/src/rulesengine/RuleCondition.cpp b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RuleCondition.cpp similarity index 65% rename from src/hos_cosgi_rulesengine/src/rulesengine/RuleCondition.cpp rename to src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RuleCondition.cpp index 27d72a0a..18c0c613 100644 --- a/src/hos_cosgi_rulesengine/src/rulesengine/RuleCondition.cpp +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RuleCondition.cpp @@ -9,15 +9,19 @@ namespace hos { namespace cosgi { -namespace rulesengine { +namespace service { +namespace ruleengine { +namespace rule { -std::shared_ptr RuleCondition::createRuleCondition(Rule* parent, libvariant::Variant raw) { +std::shared_ptr RuleCondition::createRuleCondition(Rule* parent, Variant raw) { std::shared_ptr retval; return retval; } -} /* namespace rulesengine */ +} /* namespace rule */ +} /* namespace ruleengine */ +} /* namespace service */ } /* namespace cosgi */ } /* namespace hos */ diff --git a/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RuleCondition.h b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RuleCondition.h new file mode 100644 index 00000000..7e4db473 --- /dev/null +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RuleCondition.h @@ -0,0 +1,125 @@ +/* + * RuleCondition.h + * + * Created on: 29.04.2015 + * Author: matzman + */ + +#ifndef SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULECONDITION_H_ +#define SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULECONDITION_H_ + +#include +#include +#include + + +// Forward declarations +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { +namespace rule { +class Rule; +class ConditionDeviceStatusMsgEvent; +class ConditionDeviceCommandMsgEvent; +class ConditionDeviceStateChangedEvent; +class ConditionSystemEvent; +} +} +} +} +} + + +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { +namespace rule { + +using namespace libvariant; + +class RuleCondition { +public: + enum class Type : int { DeviceStatusMsg, DeviceCommandMsg, DeviceStateChange, TimeEventCondition, SystemEventCondition}; +protected: + Rule* parent; + const Type type; +public: + static std::shared_ptr createRuleCondition(Rule* parent, libvariant::Variant raw); + RuleCondition(Rule* parent, Type type) : parent(parent), type(type) {} +public: + virtual ~RuleCondition() {} + + const Type getType() { return type; } +}; + + +class DeviceMsgCondition : public RuleCondition { +friend class RuleCondition; +protected: + Variant msgValue; + std::string msgPath; + std::string deviceID; + DeviceMsgCondition(Rule* parent, Type type, const Variant msgValue, const std::string msgPath, std::string deviceID) + : RuleCondition(parent, type) {} +}; + + +class DeviceStatusMsgCondition : public DeviceMsgCondition, public common::IObserver { +friend class RuleCondition; +protected: + DeviceStatusMsgCondition(Rule* parent, const Variant msgValue, const std::string msgPath, std::string deviceID) + : DeviceMsgCondition(parent, Type::DeviceStatusMsg, msgValue, msgPath, deviceID) {} +public: + virtual void notificationReceived(common::Observable* o, const std::string key, const ConditionDeviceStatusMsgEvent* e) override; +}; + + + +class DeviceCommandMsgCondition : public DeviceMsgCondition, public common::IObserver { +friend class RuleCondition; +protected: +public: + DeviceCommandMsgCondition(Rule* parent, const Variant msgValue, const std::string msgPath, std::string deviceID) + : DeviceMsgCondition(parent, Type::DeviceCommandMsg, msgValue, msgPath, deviceID) {} + virtual void notificationReceived(common::Observable* o, const std::string key, const ConditionDeviceCommandMsgEvent* e) override; +}; + + + +class DeviceStateChangeCondition : public RuleCondition, public common::IObserver { +friend class RuleCondition; +protected: +public: + DeviceStateChangeCondition(Rule* parent) : RuleCondition(parent, Type::DeviceStateChange) {} + virtual void notificationReceived(common::Observable* o, const std::string key, const ConditionDeviceStateChangedEvent* e) override; +}; + + + +class TimeEventCondition : public RuleCondition { +friend class RuleCondition; +protected: +public: + TimeEventCondition(Rule* parent) : RuleCondition(parent, Type::TimeEventCondition) {} +}; + + + +class SystemEventCondition : public RuleCondition, public common::IObserver { +friend class RuleCondition; +protected: +public: + SystemEventCondition(Rule* parent) : RuleCondition(parent, Type::SystemEventCondition) {} + virtual void notificationReceived(common::Observable* o, const std::string key, const ConditionSystemEvent* e) override; +}; + + +} /* namespace rule */ +} /* namespace ruleengine */ +} /* namespace service */ +} /* namespace cosgi */ +} /* namespace hos */ + +#endif /* SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULECONDITION_H_ */ diff --git a/src/hos_cosgi_rulesengine/src/rulesengine/RulePackage.cpp b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RulePackage.cpp similarity index 80% rename from src/hos_cosgi_rulesengine/src/rulesengine/RulePackage.cpp rename to src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RulePackage.cpp index 820565cc..cdc0c59b 100644 --- a/src/hos_cosgi_rulesengine/src/rulesengine/RulePackage.cpp +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RulePackage.cpp @@ -6,23 +6,27 @@ */ #include "RulePackage.h" -#include "Rule.h" + #include #include #include -#include "../hos_rulesengine_service_impl.h" + +#include "../ruleengine_serviceimpl.h" +#include "Rule.h" namespace hos { namespace cosgi { -namespace rulesengine { +namespace service { +namespace ruleengine { +namespace rule { -RulePackage::RulePackage(HOSRulesEngineServiceImpl* parent, std::string name) +RulePackage::RulePackage(service::ruleengine::RuleEngineServiceImpl* parent, std::string name) : parent(parent), name(name) {} RulePackage::~RulePackage() { } -std::shared_ptr RulePackage::createRulePackage(HOSRulesEngineServiceImpl* parent, std::string name, ::libvariant::Variant raw) { +std::shared_ptr RulePackage::createRulePackage(service::ruleengine::RuleEngineServiceImpl* parent, std::string name, Variant raw) { std::shared_ptr retval; if (raw.IsMap()) { retval = std::make_shared(parent, name); @@ -34,7 +38,7 @@ std::shared_ptr RulePackage::createRulePackage(HOSRulesEngineServic retval->executionService = parent->getExecutionBackend(retval->language); if (retval->executionService) { if (raw.HasPath("globalcontext")) { - retval->globalContext = retval->executionService->createGlobalExecutionContext(retval.get(), raw["globalcontext"]); + retval->globalContext = retval->executionService->createGlobalScriptContext(raw["globalcontext"]); } if (raw.HasPath("rules") && raw["rules"].IsMap()) { for (auto r : raw["rules"].AsMap()) { @@ -68,6 +72,8 @@ size_t RulePackage::getRules(std::vector>& rules) { return retval; } -} /* namespace rulesengine */ +} /* namespace rule */ +} /* namespace ruleengine */ +} /* namespace service */ } /* namespace cosgi */ } /* namespace hos */ diff --git a/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RulePackage.h b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RulePackage.h new file mode 100644 index 00000000..ce94550b --- /dev/null +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/rule/RulePackage.h @@ -0,0 +1,87 @@ +/* + * RulePackage.h + * + * Created on: 29.04.2015 + * Author: matzman + */ + +#ifndef SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULEPACKAGE_H_ +#define SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULEPACKAGE_H_ + + +#include +#include +#include +#include +#include +#include + + +// Forward declarations +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { +class RuleEngineServiceImpl; +namespace rule { +class Rule; +} +} +namespace scripting { +class GlobalScriptContext; +} +} +} +} + + +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { +namespace rule { + +using namespace ::libvariant; + +class RulePackage { +public: + enum class State : int { Error = 0, NoExecService = 1, Ok = 2 }; + +private: + typedef std::map> ruleMap_t; + + std::string name; + std::string language; + State state = State::Error; + ruleMap_t rules; + std::shared_ptr globalContext; + service::ruleengine::RuleEngineServiceImpl* parent; + service::scripting::ScriptingService* executionService = nullptr; + + + bool setState(State state) { + this->state = state; + return true; + } + + +public: + RulePackage(service::ruleengine::RuleEngineServiceImpl* parent, std::string name); + static std::shared_ptr createRulePackage(service::ruleengine::RuleEngineServiceImpl* parent, std::string name, Variant raw); + virtual ~RulePackage(); + + std::shared_ptr getRule(const std::string& name) { return rules[name]; } + size_t getRules(std::vector>& rules); + + service::ruleengine::RuleEngineServiceImpl* getParent() { return parent; } + + State getState() { return state; } +}; + +} /* namespace rule */ +} /* namespace ruleengine */ +} /* namespace service */ +} /* namespace cosgi */ +} /* namespace hos */ + +#endif /* SRC_HOS_COSGI_SERVICE_RULEENGINE_RULE_RULEPACKAGE_H_ */ diff --git a/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/ruleengine_serviceimpl.cpp b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/ruleengine_serviceimpl.cpp new file mode 100644 index 00000000..98166c70 --- /dev/null +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/ruleengine_serviceimpl.cpp @@ -0,0 +1,165 @@ +/* + * hos_ruleengine_service_impl.cpp + * + * Created on: 26.04.2015 + * Author: matzman + */ + +#include "ruleengine_serviceimpl.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rule/RulePackage.h" + + +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { + +template<> const char* implementation::ServiceInfo::name = service::ruleengine::RuleEngineService::SERVICE_NAME; +template<> const int implementation::ServiceInfo::major = 0; +template<> const int implementation::ServiceInfo::minor = 6; + +void RuleEngineServiceImpl::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("RuleEngineService: Found HOSCoreService Version " << major << "." << minor); + if (repoService) { + init(); + } + } +} + +void RuleEngineServiceImpl::setRepoService(devicerepository::DeviceRepositoryService* repoService) { + if (repoService && !this->repoService) { + this->repoService = repoService; + int major = 0, minor = 0; + repoService->getServiceVersion(major, minor); + ROS_INFO_STREAM("RuleEngineService: Found HOSDeviceRepositoryService Version " << major << "." << minor); + if (coreService) { + init(); + } + } +} + +void RuleEngineServiceImpl::init() { + nodehandle->getParam("ruleengine_prefix", ruleEnginePrefix); + XmlRpc::XmlRpcValue rawValue; + nodehandle->getParam(ruleEnginePrefix, rawValue); + schemaLoader.reset(new libvariant::HosSchemaLoader()); + if (rawValue.getType() == XmlRpc::XmlRpcValue::TypeStruct) { + for (auto pkg : rawValue) { + std::string pname = pkg.first; + XmlRpc::XmlRpcValue pRaw = pkg.second; + try { + addRulePkg(pname, pRaw); + ROS_INFO_STREAM("Created rule package " << pname << "."); + } catch (std::exception& e) { + ROS_ERROR_STREAM("Could not create rule package " << pname << ": " << e.what()); + } + } + } + repoService->addObserver(this); + initialized = true; + ROS_INFO_STREAM("RuleEngineService: Initialized and Ready."); +} + +RuleEngineServiceImpl::~RuleEngineServiceImpl() { + repoService->deleteObserver(this); +} + + +void RuleEngineServiceImpl::notificationReceived(interface::Observer::observable_type* o, const devicerepository::DeviceEvent* e) { + switch (e->eventType) { + case devicerepository::DeviceEvent::EventType::STATUS_UPDATED: + { + ConditionDeviceStatusMsgEvent event; + common::Observable::notifyObservers(e->device->getDeviceID(), &event); + if (e->device->stateChanged()) { + ConditionDeviceStateChangedEvent event; + common::Observable::notifyObservers(e->device->getDeviceID(), &event); + } + } + break; + case devicerepository::DeviceEvent::EventType::COMMAND_RECEIVED: + { + ConditionDeviceCommandMsgEvent event; + common::Observable::notifyObservers(e->device->getDeviceID(), &event); + } + break; + default: + break; + } +} + +void RuleEngineServiceImpl::addRulePkg(std::string name) { + std::stringstream ss; + ss << ruleEnginePrefix << "/" << name; + XmlRpc::XmlRpcValue rawValue; + nodehandle->getParam(ss.str(), rawValue); + addRulePkg(name, static_cast(rawValue)); +} + +void RuleEngineServiceImpl::addRulePkg(std::string name, std::string rawValue) { + ::libvariant::Variant s = schemaLoader->GetSchema(std::string("hos:schema://core/configs/rulepackage")); + ::libvariant::Variant m = ::libvariant::Deserialize(rawValue, ::libvariant::SERIALIZE_JSON); + ::libvariant::SchemaResult sr = ::libvariant::SchemaValidate(s, m, schemaLoader.get()); + if (!sr.Error()) { + std::shared_ptr pkg = rule::RulePackage::createRulePackage(this, name, m); + if (pkg) { + if (pkg->getState() == rule::RulePackage::State::Ok) { + rulePkgs.insert({name, pkg}); + } else if (pkg->getState() == rule::RulePackage::State::NoExecService) { + noExecRulePkgs.insert({name, pkg}); + std::cout << "No execution service found for rule package \"" << name << "\"" << std::endl; + } else { + throw std::runtime_error("Unknown state"); + } + } + } else { + throw std::runtime_error(sr.PrettyPrintMessage()); + } +} + +void RuleEngineServiceImpl::removeRulePkg(std::string name) { + rulePkgs.erase(name); +} + +void RuleEngineServiceImpl::addExecutionBackend(scripting::ScriptingService* service) { + if (execServices.find(service->getLanguage()) == execServices.end()) { + execServices.insert({service->getLanguage(), service}); + ROS_INFO_STREAM("RuleEngineService: Added execution service \"" << service->getLanguage() << "\"."); + } +} + + +scripting::ScriptingService* RuleEngineServiceImpl::getExecutionBackend(std::string language) { + auto s = execServices.find(language); + if (s != execServices.end()) { + return s->second; + } + return nullptr; +} + + +} // namespace ruleengine +} // namespace service +} // namespace cosgi +} // namespace hos + + + + + + + diff --git a/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/ruleengine_serviceimpl.h b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/ruleengine_serviceimpl.h new file mode 100644 index 00000000..c5e5f07d --- /dev/null +++ b/src/hos_cosgi_ruleengine/src/hos/cosgi/service/ruleengine/ruleengine_serviceimpl.h @@ -0,0 +1,140 @@ +/* + * hos_ruleengine_service_impl.h + * + * Created on: 26.04.2015 + * Author: matzman + */ + +#ifndef INCLUDE_HOS_COSGI_RULEENGINE_HOS_RULEENGINE_SERVICE_IMPL_H_ +#define INCLUDE_HOS_COSGI_RULEENGINE_HOS_RULEENGINE_SERVICE_IMPL_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +// Forward declarations +namespace XmlRpc { +class XmlRpcValue; +} +namespace hos { +namespace cosgi { +namespace service { +namespace core { +class CoreService; +} +namespace ruleengine { +namespace rule { +class RulePackage; +} +} +} +namespace devicerepository { +class DeviceRepositoryService; +class DeviceEvent; +} +} +} + + + +// Service Namespace +namespace hos { +namespace cosgi { +namespace service { +namespace ruleengine { + + +class ConditionDeviceStatusMsgEvent { + +}; + +class ConditionDeviceCommandMsgEvent { + +}; + +class ConditionDeviceStateChangedEvent { + +}; + +class ConditionSystemEvent { + +}; + +class RuleEngineServiceImpl; +class RuleEngineServiceImpl : public virtual RuleEngineService, + public virtual implementation::Service, + public virtual interface::Observer, + public common::Observable, + public common::Observable, + public common::Observable, + public common::Observable { +private: + typedef std::map> rulePkgMap_t; + typedef std::map execServiceMap_t; + + service::core::CoreService* coreService = nullptr; + devicerepository::DeviceRepositoryService* repoService = nullptr; + ros::NodeHandle* nodehandle = nullptr; + + std::string ruleEnginePrefix = "/hos/rules/ruleengine0"; + + rulePkgMap_t rulePkgs; + rulePkgMap_t noExecRulePkgs; + execServiceMap_t execServices; + + std::unique_ptr schemaLoader; + + bool initialized = false; + + void addRulePkg(std::string name); + void addRulePkg(std::string name, std::string rawValue); + void removeRulePkg(std::string name); + + void init(); + +public: + ~RuleEngineServiceImpl(); + /* Initialization */ + + void setCoreService(service::core::CoreService* coreService); + void setRepoService(devicerepository::DeviceRepositoryService* repoService); + + /* Public Service Implementations */ + + /* Observer Callbacks */ + + virtual void notificationReceived(interface::Observer::observable_type* o, const devicerepository::DeviceEvent* e) override; + + /* Internal Stuff */ + + bool isInitialized() { return initialized; } + + void addExecutionBackend(scripting::ScriptingService* service); + scripting::ScriptingService* getExecutionBackend(std::string language); +}; + + +} // namespace ruleengine +} // namespace service +} // namespace cosgi +} // namespace hos + + + + + +#endif /* INCLUDE_HOS_COSGI_RULEENGINE_HOS_RULEENGINE_SERVICE_IMPL_H_ */ diff --git a/src/hos_cosgi_rulesengine/test/rulepkg01.json b/src/hos_cosgi_ruleengine/test/rulepkg01.json similarity index 100% rename from src/hos_cosgi_rulesengine/test/rulepkg01.json rename to src/hos_cosgi_ruleengine/test/rulepkg01.json diff --git a/src/hos_cosgi_rulesengine/include/hos_cosgi_rulesengine/hos_rulesengine_service.h b/src/hos_cosgi_rulesengine/include/hos_cosgi_rulesengine/hos_rulesengine_service.h deleted file mode 100644 index 113b2394..00000000 --- a/src/hos_cosgi_rulesengine/include/hos_cosgi_rulesengine/hos_rulesengine_service.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * hos_rulesengine_service.h - * - * Created on: 26.04.2015 - * Author: matzman - */ - -#ifndef INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESENGINE_SERVICE_H_ -#define INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESENGINE_SERVICE_H_ - - -#include -#include - - -namespace hos { -namespace cosgi { -namespace rulesengine { - - -class RulesEngineEvent; - - -class HOSRulesEngineService : public COSGI_Service_Interface, public common::IObservable { -public: - static constexpr const char* SERVICE_NAME = "hos_rulesengine_service"; - static constexpr int SERVICE_VERSION_MAJOR = 1; - static constexpr int SERVICE_VERSION_MINOR = 0; -}; - - -} // namespace rulesengine -} // namespace cosgi -} // namespace hos - - - - -#endif /* INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESENGINE_SERVICE_H_ */ diff --git a/src/hos_cosgi_rulesengine/include/hos_cosgi_rulesengine/hos_rulesexecution_service.h b/src/hos_cosgi_rulesengine/include/hos_cosgi_rulesengine/hos_rulesexecution_service.h deleted file mode 100644 index 1d4a3110..00000000 --- a/src/hos_cosgi_rulesengine/include/hos_cosgi_rulesengine/hos_rulesexecution_service.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * hos_rulesexecution_service.h - * - * Created on: 01.05.2015 - * Author: matzman - */ - -#ifndef INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESEXECUTION_SERVICE_H_ -#define INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESEXECUTION_SERVICE_H_ - - -#include -#include -#include - - -// Forward declarations -namespace hos { -namespace cosgi { -namespace rulesengine { -class RulePackage; -class Rule; -} -} -} - - -namespace hos { -namespace cosgi { -namespace rulesexecution { - - -class GlobalExecutionContext : public COSGI_Object_Interface { - -}; - - -class RuleBody : public COSGI_Object_Interface { -public: - virtual void exec(GlobalExecutionContext* gContext) = 0; -}; - - -class HOSRulesExecutionService : public COSGI_Service_Interface { -public: - static constexpr const char* SERVICE_NAME = "hos_rulesexecution_service"; - - virtual std::string getLanguage() = 0; - - virtual std::shared_ptr createGlobalExecutionContext(rulesengine::RulePackage* parent, libvariant::Variant raw) = 0; - virtual std::shared_ptr createRuleBody(rulesengine::Rule* parent, GlobalExecutionContext* gContext, libvariant::Variant raw) = 0; -}; - - -} // namespace rulesengine -} // namespace cosgi -} // namespace hos - - - - -#endif /* INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESEXECUTION_SERVICE_H_ */ diff --git a/src/hos_cosgi_rulesengine/launch/cosgi_rulesengine.launch b/src/hos_cosgi_rulesengine/launch/cosgi_rulesengine.launch deleted file mode 100644 index ff908682..00000000 --- a/src/hos_cosgi_rulesengine/launch/cosgi_rulesengine.launch +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/hos_cosgi_rulesengine/src/hos_rulesengine_service_impl.cpp b/src/hos_cosgi_rulesengine/src/hos_rulesengine_service_impl.cpp deleted file mode 100644 index 48a24139..00000000 --- a/src/hos_cosgi_rulesengine/src/hos_rulesengine_service_impl.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * hos_rulesengine_service_impl.cpp - * - * Created on: 26.04.2015 - * Author: matzman - */ - -#include "hos_rulesengine_service_impl.h" -#include -#include -#include -#include -#include -#include -#include -#include "rulesengine/RulePackage.h" -#include - - -namespace hos { -namespace cosgi { -namespace rulesengine { - -void HOSRulesEngineServiceImpl::setCoreService(core::HOSCoreService* coreService) { - if (coreService && !this->coreService) { - this->coreService = coreService; - this->nodehandle = coreService->getPrivateNodeHandle(); - int major = 0, minor = 0; - coreService->getServiceVersion(major, minor); - ROS_INFO_STREAM("RulesEngineService: Found HOSCoreService Version " << major << "." << minor); - if (repoService) { - init(); - } - } -} - -void HOSRulesEngineServiceImpl::setRepoService(devicerepository::HOSDeviceRepositoryService* repoService) { - if (repoService && !this->repoService) { - this->repoService = repoService; - int major = 0, minor = 0; - repoService->getServiceVersion(major, minor); - ROS_INFO_STREAM("RulesEngineService: Found HOSDeviceRepositoryService Version " << major << "." << minor); - if (coreService) { - init(); - } - } -} - -void HOSRulesEngineServiceImpl::init() { - nodehandle->getParam("rulesengine_prefix", ruleEnginePrefix); - XmlRpc::XmlRpcValue rawValue; - nodehandle->getParam(ruleEnginePrefix, rawValue); - schemaLoader.reset(new libvariant::HosSchemaLoader()); - if (rawValue.getType() == XmlRpc::XmlRpcValue::TypeStruct) { - for (auto pkg : rawValue) { - std::string pname = pkg.first; - XmlRpc::XmlRpcValue pRaw = pkg.second; - try { - addRulePkg(pname, pRaw); - ROS_INFO_STREAM("Created rule package " << pname << "."); - } catch (std::exception& e) { - ROS_ERROR_STREAM("Could not create rule package " << pname << ": " << e.what()); - } - } - } - repoService->addObserver(*this); - initialized = true; - ROS_INFO_STREAM("RulesEngineService: Initialized and Ready."); -} - -HOSRulesEngineServiceImpl::~HOSRulesEngineServiceImpl() { - repoService->deleteObserver(*this); -} - - -void HOSRulesEngineServiceImpl::getServiceVersion(int& major, int& minor) { - major = SERVICE_VERSION_MAJOR; - minor = SERVICE_VERSION_MINOR; -} - - -void HOSRulesEngineServiceImpl::notificationReceived(IObservable* o, const devicerepository::DeviceEvent* e) { - -} - -void HOSRulesEngineServiceImpl::addRulePkg(std::string name) { - std::stringstream ss; - ss << ruleEnginePrefix << "/" << name; - XmlRpc::XmlRpcValue rawValue; - nodehandle->getParam(ss.str(), rawValue); - addRulePkg(name, static_cast(rawValue)); -} - -void HOSRulesEngineServiceImpl::addRulePkg(std::string name, std::string rawValue) { - ::libvariant::Variant s = schemaLoader->GetSchema(std::string("hos:schema://core/configs/rulepackage")); - ::libvariant::Variant m = ::libvariant::Deserialize(rawValue, ::libvariant::SERIALIZE_JSON); - ::libvariant::SchemaResult sr = ::libvariant::SchemaValidate(s, m, schemaLoader.get()); - if (!sr.Error()) { - std::shared_ptr pkg = RulePackage::createRulePackage(this, name, m); - if (pkg) { - if (pkg->getState() == RulePackage::State::Ok) { - rulePkgs.insert({name, pkg}); - } else if (pkg->getState() == RulePackage::State::NoExecService) { - noExecRulePkgs.insert({name, pkg}); - std::cout << "No execution service found for rule package \"" << name << "\"" << std::endl; - } else { - throw std::runtime_error("Unknown state"); - } - } - } else { - throw std::runtime_error(sr.PrettyPrintMessage()); - } -} - -void HOSRulesEngineServiceImpl::removeRulePkg(std::string name) { - rulePkgs.erase(name); -} - -void HOSRulesEngineServiceImpl::addExecutionBackend(rulesexecution::HOSRulesExecutionService* service) { - if (execServices.find(service->getLanguage()) == execServices.end()) { - execServices.insert({service->getLanguage(), service}); - ROS_INFO_STREAM("RulesEngineService: Added execution service \"" << service->getLanguage() << "\"."); - } -} - - -rulesexecution::HOSRulesExecutionService* HOSRulesEngineServiceImpl::getExecutionBackend(std::string language) { - auto s = execServices.find(language); - if (s != execServices.end()) { - return s->second; - } - return nullptr; -} - - -} // namespace rulesengine -} // namespace cosgi -} // namespace hos - - - - - - - diff --git a/src/hos_cosgi_rulesengine/src/hos_rulesengine_service_impl.h b/src/hos_cosgi_rulesengine/src/hos_rulesengine_service_impl.h deleted file mode 100644 index abecf2c7..00000000 --- a/src/hos_cosgi_rulesengine/src/hos_rulesengine_service_impl.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * hos_rulesengine_service_impl.h - * - * Created on: 26.04.2015 - * Author: matzman - */ - -#ifndef INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESENGINE_SERVICE_IMPL_H_ -#define INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESENGINE_SERVICE_IMPL_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include - - -// Forward declarations -namespace XmlRpc { -class XmlRpcValue; -} -namespace hos { -namespace cosgi { -namespace core { -class HOSCoreService; -} -namespace devicerepository { -class HOSDeviceRepositoryService; -class DeviceEvent; -} -namespace rulesengine { -class RulePackage; -} -} -} - - - -// Service Namespace -namespace hos { -namespace cosgi { -namespace rulesengine { - - -class HOSRulesEngineServiceImpl : public HOSRulesEngineService, public common::IObserver { -OBSERVABLE_IMPL(RulesEngineEvent) -private: - typedef std::map> rulePkgMap_t; - typedef std::map execServiceMap_t; - - core::HOSCoreService* coreService = nullptr; - devicerepository::HOSDeviceRepositoryService* repoService = nullptr; - ros::NodeHandle* nodehandle = nullptr; - - std::string ruleEnginePrefix = "/hos/rules/rulesengine0"; - - rulePkgMap_t rulePkgs; - rulePkgMap_t noExecRulePkgs; - execServiceMap_t execServices; - - std::unique_ptr schemaLoader; - - bool initialized = false; - - void addRulePkg(std::string name); - void addRulePkg(std::string name, std::string rawValue); - void removeRulePkg(std::string name); - - void init(); - -public: - ~HOSRulesEngineServiceImpl(); - /* Initialization */ - - void setCoreService(core::HOSCoreService* coreService); - void setRepoService(devicerepository::HOSDeviceRepositoryService* repoService); - - /* Public Service Implementations */ - - virtual const char* getServiceName() { return SERVICE_NAME; } - virtual void getServiceVersion(int& major, int& minor); - - /* Observer Callback */ - - virtual void notificationReceived(IObservable* o, const devicerepository::DeviceEvent* e); - - /* Internal Stuff */ - - bool isInitialized() { return initialized; } - - void addExecutionBackend(rulesexecution::HOSRulesExecutionService* service); - rulesexecution::HOSRulesExecutionService* getExecutionBackend(std::string language); -}; - - -} // namespace rulesengine -} // namespace cosgi -} // namespace hos - - - - - -#endif /* INCLUDE_HOS_COSGI_RULESENGINE_HOS_RULESENGINE_SERVICE_IMPL_H_ */ diff --git a/src/hos_cosgi_rulesengine/src/rulesengine/Rule.h b/src/hos_cosgi_rulesengine/src/rulesengine/Rule.h deleted file mode 100644 index aab5dbd5..00000000 --- a/src/hos_cosgi_rulesengine/src/rulesengine/Rule.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Rule.h - * - * Created on: 29.04.2015 - * Author: matzman - */ - -#ifndef SRC_RULESENGINE_RULE_H_ -#define SRC_RULESENGINE_RULE_H_ - - -#include -#include -#include -#include - - -// Forward declarations -namespace hos { -namespace cosgi { -namespace rulesengine { -class RulePackage; -class Rule; -class RuleCondition; -} -namespace rulesexecution { -class HOSRulesExecutionService; -class GlobalExecutionContext; -class RuleBody; -} -} -} - - -namespace hos { -namespace cosgi { -namespace rulesengine { - - -class Rule { -private: - RulePackage* parent; - std::string name; - std::shared_ptr body; - std::vector> conditions; - rulesexecution::HOSRulesExecutionService* executionService; -public: - Rule(RulePackage* parent, std::string name, rulesexecution::HOSRulesExecutionService* executionService); - static std::shared_ptr createRule(RulePackage* parent, std::string name, rulesexecution::GlobalExecutionContext* gContext, libvariant::Variant raw, rulesexecution::HOSRulesExecutionService* executionService); - virtual ~Rule(); - - RulePackage* getParent() { return parent; } - - virtual void exec(rulesexecution::GlobalExecutionContext* gContext); -}; - -class RuleBody { - -}; - - -} /* namespace rulesengine */ -} /* namespace cosgi */ -} /* namespace hos */ - - -#endif /* SRC_RULESENGINE_RULE_H_ */ diff --git a/src/hos_cosgi_rulesengine/src/rulesengine/RuleCondition.h b/src/hos_cosgi_rulesengine/src/rulesengine/RuleCondition.h deleted file mode 100644 index 48f00401..00000000 --- a/src/hos_cosgi_rulesengine/src/rulesengine/RuleCondition.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * RuleCondition.h - * - * Created on: 29.04.2015 - * Author: matzman - */ - -#ifndef SRC_RULESENGINE_RULECONDITION_H_ -#define SRC_RULESENGINE_RULECONDITION_H_ - -#include -#include - - -// Forward declarations -namespace hos { -namespace cosgi { -namespace rulesengine { -class Rule; -} -} -} - - -namespace hos { -namespace cosgi { -namespace rulesengine { - - - -class RuleCondition { -public: - enum class Type : int { DeviceMsgCondition, DeviceStatusCondition, TimeEventCondition, SystemEventCondition}; -private: - Rule* parent; - const Type type; -public: - static std::shared_ptr createRuleCondition(Rule* parent, libvariant::Variant raw); -public: - RuleCondition(Rule* parent, Type type) : parent(parent), type(type) {} - virtual ~RuleCondition() {} - - const Type getType() { return type; } -}; - - - -class DeviceMsgCondition : public RuleCondition { -friend class RuleCondition; -public: - DeviceMsgCondition(Rule* parent) : RuleCondition(parent, Type::DeviceMsgCondition) {} -}; - - - -class DeviceStatusCondition : public RuleCondition { -friend class RuleCondition; -public: - DeviceStatusCondition(Rule* parent) : RuleCondition(parent, Type::DeviceStatusCondition) {} -}; - - - -class TimeEventCondition : public RuleCondition { -friend class RuleCondition; -public: - TimeEventCondition(Rule* parent) : RuleCondition(parent, Type::TimeEventCondition) {} -}; - - - -class SystemEventCondition : public RuleCondition { -friend class RuleCondition; -public: - SystemEventCondition(Rule* parent) : RuleCondition(parent, Type::SystemEventCondition) {} -}; - - -} /* namespace rulesengine */ -} /* namespace cosgi */ -} /* namespace hos */ - -#endif /* SRC_RULESENGINE_RULECONDITION_H_ */ diff --git a/src/hos_cosgi_rulesengine/src/rulesengine/RulePackage.h b/src/hos_cosgi_rulesengine/src/rulesengine/RulePackage.h deleted file mode 100644 index 2213e1a7..00000000 --- a/src/hos_cosgi_rulesengine/src/rulesengine/RulePackage.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * RulePackage.h - * - * Created on: 29.04.2015 - * Author: matzman - */ - -#ifndef SRC_RULESENGINE_RULEPACKAGE_H_ -#define SRC_RULESENGINE_RULEPACKAGE_H_ - - -#include -#include -#include -#include -#include -#include - - -// Forward declarations -namespace hos { -namespace cosgi { -namespace rulesengine { -class HOSRulesEngineServiceImpl; -class Rule; -} -namespace rulesexecution { -class GlobalExecutionContext; -} -} -} - - -namespace hos { -namespace cosgi { -namespace rulesengine { - -class RulePackage { -public: - enum class State : int { Error = 0, NoExecService = 1, Ok = 2 }; - -private: - typedef std::map> ruleMap_t; - - std::string name; - std::string language; - State state = State::Error; - ruleMap_t rules; - std::shared_ptr globalContext; - HOSRulesEngineServiceImpl* parent; - rulesexecution::HOSRulesExecutionService* executionService = nullptr; - - - bool setState(State state) { - this->state = state; - return true; - } - - -public: - RulePackage(HOSRulesEngineServiceImpl* parent, std::string name); - static std::shared_ptr createRulePackage(HOSRulesEngineServiceImpl* parent, std::string name, ::libvariant::Variant raw); - virtual ~RulePackage(); - - std::shared_ptr getRule(const std::string& name) { return rules[name]; } - size_t getRules(std::vector>& rules); - - HOSRulesEngineServiceImpl* getParent() { return parent; } - - State getState() { return state; } -}; - -} /* namespace rulesengine */ -} /* namespace cosgi */ -} /* namespace hos */ - -#endif /* SRC_RULESENGINE_RULEPACKAGE_H_ */ diff --git a/src/hos_cosgi_rulesexecution_python/src/hos_rulesexecution_python_impl.h b/src/hos_cosgi_rulesexecution_python/src/hos_rulesexecution_python_impl.h deleted file mode 100644 index acb4eee2..00000000 --- a/src/hos_cosgi_rulesexecution_python/src/hos_rulesexecution_python_impl.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * hos_cosgi_rulesexecution_python_impl.h - * - * Created on: 01.05.2015 - * Author: matzman - */ - -#ifndef SRC_HOS_RULESEXECUTION_PYTHON_IMPL_H_ -#define SRC_HOS_RULESEXECUTION_PYTHON_IMPL_H_ - -#include -#include -#include -#include -#include -#include - - -// Forward declarations -namespace hos { -namespace cosgi { -namespace core { -class HOSCoreService; -} -namespace devicerepository { -class HOSDeviceRepositoryService; -class DeviceEvent; -} -namespace rulesexecution { -namespace python { -class HOSRulesExecutionPythonImpl; -} -} -} -} - - -namespace hos { -namespace cosgi { -namespace rulesexecution { -namespace python { - - - -class PyGlobalExecutionContext : public GlobalExecutionContext { -private: - boost::python::object& gContext; - std::string code; -public: - PyGlobalExecutionContext(boost::python::object& gContext, std::string code) - : gContext(gContext), code(code) {} - std::string getCode() { return code; } - boost::python::object& getPyGlobalContext() { return gContext; } -}; - - - -class PyRuleBody : public RuleBody { -private: - std::string code; - HOSRulesExecutionPythonImpl& service; -public: - PyRuleBody(std::string code, HOSRulesExecutionPythonImpl& service) : code(code), service(service) {} - std::string getCode() { return code; } - virtual void exec(GlobalExecutionContext* gContext); -}; - - - -class HOSRulesExecutionPythonImpl : public HOSRulesExecutionService { -private: - core::HOSCoreService* coreService = nullptr;; - devicerepository::HOSDeviceRepositoryService* repoService = nullptr;; - ros::NodeHandle* nodehandle = nullptr; - - boost::python::object pyGlobalScope; - - bool initialized = false; - - void init(); - -public: - static constexpr int SERVICE_VERSION_MAJOR = 1; - static constexpr int SERVICE_VERSION_MINOR = 0; - static constexpr const char* LANGUAGE = "python"; - - /* Initialization */ - - void setCoreService(core::HOSCoreService* coreService); - void setRepoService(devicerepository::HOSDeviceRepositoryService* repoService); - - /* Public Service Implementations */ - - virtual const char* getServiceName() { return SERVICE_NAME; } - virtual void getServiceVersion(int& major, int& minor); - - virtual std::string getLanguage() { return LANGUAGE; } - - virtual std::shared_ptr createGlobalExecutionContext(rulesengine::RulePackage* parent, libvariant::Variant raw); - virtual std::shared_ptr createRuleBody(rulesengine::Rule* parent, GlobalExecutionContext* gContext, libvariant::Variant raw); - - /* Internal Stuff */ - - bool isInitialized() { return initialized; } - - boost::python::object& getPyGlobalScope() { return pyGlobalScope; } -}; - - - -} // namespace python -} // namespace rulesengine -} // namespace cosgi -} // namespace hos - - -#endif /* SRC_HOS_RULESEXECUTION_PYTHON_IMPL_H_ */ diff --git a/src/hos_cosgi_scripting/CMakeLists.txt b/src/hos_cosgi_scripting/CMakeLists.txt new file mode 100644 index 00000000..d5e3ab98 --- /dev/null +++ b/src/hos_cosgi_scripting/CMakeLists.txt @@ -0,0 +1,168 @@ +cmake_minimum_required(VERSION 2.8.3) +project(hos_cosgi_scripting) + +## 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_cosgi_common + hos_libvariant +) + +## 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() + +################################################ +## 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/${PROJECT_NAME}/ +# LIBRARIES hos_cosgi_scripting + CATKIN_DEPENDS hos_cosgi_common hos_libvariant +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +# include_directories(include) +include_directories( + ${catkin_INCLUDE_DIRS} +) + +## Declare a cpp library +# add_library(hos_cosgi_scripting +# src/${PROJECT_NAME}/hos_cosgi_scripting.cpp +# ) + +## Declare a cpp executable +# add_executable(hos_cosgi_scripting_node src/hos_cosgi_scripting_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_scripting_node hos_cosgi_scripting_generate_messages_cpp) + +## Specify libraries to link a library or executable target against +# target_link_libraries(hos_cosgi_scripting_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +## Mark cpp header files for installation +install(DIRECTORY include/${PROJECT_NAME}/ + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} + FILES_MATCHING PATTERN "*.h" +) + +# 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_scripting hos_cosgi_scripting_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_scripting.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_scripting/include/hos_cosgi_scripting/hos/cosgi/service/scripting/scripting_service.h b/src/hos_cosgi_scripting/include/hos_cosgi_scripting/hos/cosgi/service/scripting/scripting_service.h new file mode 100644 index 00000000..83ec1f0d --- /dev/null +++ b/src/hos_cosgi_scripting/include/hos_cosgi_scripting/hos/cosgi/service/scripting/scripting_service.h @@ -0,0 +1,53 @@ +/* + * hos_ruleexecution_service.h + * + * Created on: 01.05.2015 + * Author: matzman + */ + +#ifndef INCLUDE_HOS_COSGI_SCRIPTING_HOS_COSGI_SERVICE_SCRIPTING_SCRIPTING_SERVICE_H_ +#define INCLUDE_HOS_COSGI_SCRIPTING_HOS_COSGI_SERVICE_SCRIPTING_SCRIPTING_SERVICE_H_ + + +#include +#include +#include + + +namespace hos { +namespace cosgi { +namespace service { +namespace scripting { + + +class GlobalScriptContext : public virtual interface::Object { + +}; + + +class Script : public virtual interface::Object { +public: + virtual void exec(GlobalScriptContext* gContext) = 0; +}; + + +class ScriptingService : public virtual interface::Service { +public: + static constexpr const char* SERVICE_NAME = "hos_scripting_service"; + + virtual std::string getLanguage() = 0; + + virtual std::shared_ptr createGlobalScriptContext(libvariant::Variant raw) = 0; + virtual std::shared_ptr