Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • scs/ipaaca
  • ramin.yaghoubzadeh/ipaaca
2 results
Show changes
Showing
with 1981 additions and 489 deletions
File moved
--- client.py.sav 2018-12-14 18:30:04.836523913 +0100
+++ client.py 2018-12-14 19:23:13.759468147 +0100
@@ -983,7 +983,7 @@
# sockpairR is used to break out of select() before the timeout, on a
# call to publish() etc.
- rlist = [self._sock, self._sockpairR]
+ rlist = [self._sock, self._sockpairR] if self._sock else [self._sockpairR]
try:
socklist = select.select(rlist, wlist, [], timeout)
except TypeError:
......@@ -3,19 +3,20 @@ cmake_minimum_required (VERSION 2.6)
# project name
project (ipaaca_cpp)
# use C++11 (starting with proto v2 / ipaaca-c++ release 12)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set (CMAKE_CXX_STANDARD 11)
## use C++11 (starting with proto v2 / ipaaca-c++ release 12)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
## use the following line to enable console debug messages in ipaaca
## (this entails a slight slowdown since dynamic log level checks made at the very least)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPAACA_DEBUG_MESSAGES")
# expose the full RSB api in the headers (set only in ipaaca itself)
# !! NOTE: at the moment required in any ipaaca cpp project in Windows !!
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPAACA_EXPOSE_FULL_RSB_API")
## use the following line to enable building mock IUs (FakeIU)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPAACA_BUILD_MOCK_OBJECTS")
# find cmake modules locally too
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules )
#set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../deps/share/rsc0.10/cmake/Modules )
if(WIN32) # Check if we are on Windows
if(MSVC) # Check if we are using the Visual Studio compiler
......@@ -35,58 +36,47 @@ if(WIN32) # Check if we are on Windows
#
#
#
# If you want to compile rsb locally, check out the soa project 'rsb', build it
# and use resolve.sh to pull its libraries into this project.
# On the other hand, if you simply want to use the precompiled rsb from inside
# "rsx" (it works but has no debug info), uncomment the following four lines.
#
include_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSC-0.10.0-win32/include/rsc0.10 )
include_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSB-0.10.2-win32/include/rsb0.10 )
link_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSC-0.10.0-win32/lib )
link_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSB-0.10.2-win32/lib )
set(RSBLIBS rsc0.10 rsb)
set(LIBS ${LIBS} rpcrt4)
#set(Boost_USE_STATIC_LIBS ON)
#set(Boost_USE_MULTITHREADED ON)
#find_package(Boost COMPONENTS date_time program_options system filesystem thread signals regex REQUIRED)
#link_directories(${Boost_LIBRARY_DIRS})
#include_directories(${Boost_INCLUDE_DIRS})
# Using custom Protobuf script (from rsc) because it honors PROTOBUF_ROOT
find_package(ProtocolBuffers REQUIRED)
link_directories(${PROTOBUF_LIBRARY_DIRS})
include_directories(${PROTOBUF_INCLUDE_DIRS})
find_package(Boost COMPONENTS date_time program_options system filesystem thread signals regex REQUIRED)
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
### (First attempts to fix linking problem:)
##list(REMOVE_ITEM Boost_LIBRARIES boost_thread-vc100-mt-gd-1_54)
##set(Boost_LIBRARIES boost_regex-vc100-mt-gd-1_54 boost_date_time-vc100-mt-gd-1_54 boost_program_options-vc100-mt-gd-1_54 boost_filesystem-vc100-mt-gd-1_54 boost_signals-vc100-mt-gd-1_54 boost_system-vc100-mt-gd-1_54)
# Windows linkage hack: overriding the determined libs to remove boost_thread (causes multiple-definition issues)
set(CORRECT_BOOST_LIBS "")
foreach(BLIB ${Boost_LIBRARIES})
#message(STATUS "Boost lib: ${BLIB}")
string(REGEX MATCH "boost_thread[^/]+$" drop_item ${BLIB})
if(drop_item)
message(STATUS "(Windows hack:) Removing boost_thread library from the linkage list.")
else(drop_item)
list(APPEND CORRECT_BOOST_LIBS ${BLIB})
endif(drop_item)
endforeach(BLIB ${Boost_LIBRARIES})
set(Boost_LIBRARIES ${CORRECT_BOOST_LIBS})
#include_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/boost/include/boost-1_54 )
#link_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/boost/lib )
## Windows linkage hack: overriding the determined libs to remove boost_thread (causes multiple-definition issues)
#set(CORRECT_BOOST_LIBS "")
#foreach(BLIB ${Boost_LIBRARIES})
# list(APPEND CORRECT_BOOST_LIBS ${BLIB})
#endforeach(BLIB ${Boost_LIBRARIES})
#set(Boost_LIBRARIES ${CORRECT_BOOST_LIBS})
#include_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSC-0.10.0-win32/include/rsc0.10 )
#include_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSB-0.10.2-win32/include/rsb0.10 )
#include_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/protobuf/include )
#link_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSC-0.10.0-win32/lib )
#link_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/RSB-0.10.2-win32/lib )
#link_directories( ${PROJECT_SOURCE_DIR}/../../../rsx/protobuf/bin )
# Using custom Protobuf script (from rsc) because it honors PROTOBUF_ROOT
#find_package(ProtocolBuffers REQUIRED PATHS "\\Libs\\protobuf")
#link_directories(${PROTOBUF_LIBRARY_DIRS})
#include_directories(${PROTOBUF_INCLUDE_DIRS})
#message(STATUS "############################")
#message(STATUS ${PROTOBUF_INCLUDE_DIRS})
set(PROTOBUF_LIBRARY optimized "C:\\libs\\protobuf\\x64\\lib\\libprotobuf.lib" debug "C:\\libs\\protobuf\\x64\\lib\\libprotobufd.lib")
link_directories( "C:\\libs\\protobuf\\x64\\lib" )
include_directories( "C:\\libs\\protobuf\\x64\\include" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
else()
message(SEND_ERROR "Unsupported compiler! Please build with MSVC (2010).")
message(SEND_ERROR "Unsupported compiler! Please build with MSVC++ 19.x (Visual Studio 2017).")
endif()
else()
#
......@@ -94,7 +84,7 @@ else()
# Setup section for Linux or OS X (using 'rsb' soa project)
#
#
find_package(Boost COMPONENTS system filesystem thread regex signals REQUIRED)
find_package(Boost COMPONENTS system filesystem thread regex REQUIRED)
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
#set(BOOSTLIBS boost_regex-mt boost_date_time-mt boost_program_options-mt boost_thread-mt boost_filesystem-mt boost_signals-mt boost_system-mt)
......@@ -103,12 +93,21 @@ else()
link_directories(${PROTOBUF_LIBRARY_DIRS})
include_directories(${PROTOBUF_INCLUDE_DIRS})
set(PROTOBUF_INPUT_DIRECTORY "${PROJECT_SOURCE_DIR}")
set(PROTOBUF_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/build/ipaaca")
file(MAKE_DIRECTORY ${PROTOBUF_OUTPUT_DIRECTORY})
set(PROTOBUF_ARGUMENTS "--cpp_out=${PROTOBUF_OUTPUT_DIRECTORY}")
execute_process(COMMAND protoc ${PROTOBUF_ARGUMENTS} ipaaca.proto
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../proto/
RESULT_VARIABLE PROTOBUF_RESULT
OUTPUT_VARIABLE PROTOBUF_OUTPUT_VARIABLE)
# change for each new rsb version
if (DEFINED APPLE)
set(RSBLIBS rsc0.11 rsb0.11)
#set(RSBLIBS rsc0.10 rsb.0.10)
else(DEFINED APPLE)
set(RSBLIBS ${PROJECT_SOURCE_DIR}/../../deps/lib/librsc0.11.so ${PROJECT_SOURCE_DIR}/../../deps/lib/librsb0.11.so )
if (DEFINED APPLE)
#set(RSBLIBS rsc0.14 rsb0.14)
#set(RSBLIBS rsc0.10 rsb.0.10)
else(DEFINED APPLE)
#set(RSBLIBS ${PROJECT_SOURCE_DIR}/../../deps/lib/librsc0.14.so ${PROJECT_SOURCE_DIR}/../../deps/lib/librsb0.14.so )
set(LIBS ${LIBS} uuid)
endif(DEFINED APPLE)
# enhance the default search paths (headers, libs ...)
......@@ -122,24 +121,29 @@ else()
endif(DEFINED APPLE)
endif(WIN32)
set(LIBS ${LIBS} ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES})
set(LIBS ${LIBS} ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${RSBLIBS})
if(NOT DEFINED WIN32)
if (DEFINED APPLE)
message(STATUS "No extra pthread flags needed on Mac")
else()
message(STATUS "Adding extra pthread flags for Linux")
# needs -lpthread AND -pthread
set(LIBS ${LIBS} pthread)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
endif(NOT DEFINED WIN32)
# Hide the rsb-induced boost-signals warning (FOR NOW)
set(IPAACA_CXX_DEFINES "${IPAACA_CXX_DEFINES} -DBOOST_SIGNALS_NO_DEPRECATION_WARNING")
#set(IPAACA_CXX_DEFINES "${IPAACA_CXX_DEFINES} -DBOOST_SIGNALS_NO_DEPRECATION_WARNING")
# Compiler defines copied from the old build system
set(IPAACA_CXX_DEFINES "${IPAACA_CXX_DEFINES} -D_BSD_SOURCE -DUSE_AV -DMGC_USE_DOUBLE -DLEDA_PREFIX -D__NO_CAST_TO_LOCAL_TYPE__ -DDBGLVL=0")
## Compiler defines copied from the old build system
#set(IPAACA_CXX_DEFINES "${IPAACA_CXX_DEFINES} -D_DEFAULT_SOURCE -DUSE_AV -DMGC_USE_DOUBLE -DLEDA_PREFIX -D__NO_CAST_TO_LOCAL_TYPE__ -DDBGLVL=0")
# Combine the extra compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_OLD_CODE_CONVENIENCE_FLAGS} ${IPAACA_CXX_DEFINES}")
# add for for each new rsb version
include_directories( ${PROJECT_SOURCE_DIR}/../../deps/include/rsc0.11 )
include_directories( ${PROJECT_SOURCE_DIR}/../../deps/include/rsb0.11 )
#include_directories( ${PROJECT_SOURCE_DIR}/../../deps/include/rsc0.10 )
#include_directories( ${PROJECT_SOURCE_DIR}/../../deps/include/rsb0.10 )
# add include dir for auto-generated headers placed in build/
include_directories( ${PROJECT_SOURCE_DIR}/build )
......@@ -149,13 +153,62 @@ include_directories( ${PROJECT_SOURCE_DIR}/include )
include_directories( ${PROJECT_SOURCE_DIR}/../../deps/include )
link_directories( ${PROJECT_SOURCE_DIR}/../../deps/lib )
###
### Back-ends (will include any and all that are compileable)
###
#
if(WIN32)
if(MSVC)
# fixed configuration for Windows
set(LIBS ${LIBS} "C:\\libs\\mosquitto\\x64\\mosquitto.lib" "C:\\libs\\mosquitto\\x64\\mosquittopp.lib")
link_directories( "C:\\libs\\mosquitto\\x64" )
include_directories( "C:\\libs\\mosquitto\\x64\\include" )
set(BACKEND_SOURCES ${BACKEND_SOURCES} src/ipaaca-backend-mqtt.cc)
endif(MSVC)
else()
# dynamic checks under Unix
# 1: MQTT
find_library(MOSQUITTO_LIB mosquittopp)
if(MOSQUITTO_LIB)
message(STATUS "=== MQTT backend === enabled")
set(LIBS ${LIBS} mosquittopp)
set(BACKEND_SOURCES ${BACKEND_SOURCES} src/ipaaca-backend-mqtt.cc)
else()
message(STATUS "=== MQTT backend === DISABLED (mosquittopp not found)")
endif()
# 2: ROS
set (ROSBASE $ENV{ROS_ROOT}/../..)
find_library(ROSCPP_LIB roscpp PATHS ${ROSBASE})
if(ROSCPP_LIB)
message(STATUS "=== ROS backend === enabled")
include_directories($ENV{ROS_ROOT}/../../include)
link_directories($ENV{ROS_ROOT}/../../lib)
set(LIBS ${LIBS} roscpp roscpp_serialization rosconsole)
set(BACKEND_SOURCES ${BACKEND_SOURCES} src/ipaaca-backend-ros.cc)
else()
message(STATUS "=== ROS backend === DISABLED (roscpp not found)")
endif()
#
# Now make sure that at least one of those backends is available
#
if(NOT BACKEND_SOURCES)
message(SEND_ERROR "\nWill not build IPAACA without any backends!\n")
endif()
endif() # of Unix block
# specify source files for ipaaca (auto-generated ones are in build/ )
set (SOURCE
src/ipaaca.cc
src/ipaaca-config.cc
src/ipaaca-converters.cc
src/ipaaca-backend.cc
src/ipaaca-buffers.cc
src/ipaaca-internal.cc
src/ipaaca-iuinterface.cc
src/ipaaca-initializer.cc
src/ipaaca-iuinterface.cc
src/ipaaca-ius.cc
src/ipaaca-links.cc
src/ipaaca-locking.cc
......@@ -163,43 +216,78 @@ set (SOURCE
src/ipaaca-cmdline-parser.cc
src/ipaaca-string-utils.cc
src/util/notifier.cc
src/b64/b64.cc
build/ipaaca/ipaaca.pb.cc
)
set (SOURCE ${SOURCE} ${BACKEND_SOURCES})
set (JSON_TEST_SOURCE
#set (JSON_TEST_SOURCE
# src/ipaaca.cc
# src/ipaaca-buffers.cc
# src/ipaaca-fake.cc
# src/ipaaca-internal.cc
# src/ipaaca-iuinterface.cc
# src/ipaaca-json.cc # main
# src/ipaaca-locking.cc
# src/ipaaca-links.cc
# src/ipaaca-payload.cc
# src/ipaaca-cmdline-parser.cc
# src/ipaaca-string-utils.cc
# # more stuff going beyond the fake test case
# src/ipaaca-ius.cc
# build/ipaaca/ipaaca.pb.cc
# )
#
set (TESTER_SOURCE
src/ipaaca-tester.cc # main
src/ipaaca.cc
src/ipaaca-config.cc
src/ipaaca-converters.cc
src/ipaaca-backend.cc
src/ipaaca-buffers.cc
src/ipaaca-fake.cc
src/ipaaca-internal.cc
src/ipaaca-initializer.cc
src/ipaaca-iuinterface.cc
src/ipaaca-json.cc # main
src/ipaaca-locking.cc
src/ipaaca-ius.cc
src/ipaaca-links.cc
src/ipaaca-locking.cc
src/ipaaca-payload.cc
src/ipaaca-cmdline-parser.cc
src/ipaaca-string-utils.cc
# more stuff going beyond the fake test case
src/ipaaca-ius.cc
src/util/notifier.cc
src/b64/b64.cc
build/ipaaca/ipaaca.pb.cc
)
set (TESTER_SOURCE ${TESTER_SOURCE} ${BACKEND_SOURCES})
if(WIN32)
if(MSVC)
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "C:/Libs/ipaaca/x64")
endif()
endif()
else()
# this is for building with cmake/soa
set(CMAKE_INSTALL_PREFIX "")
endif()
# compile all files to "ipaaca" shared library
add_library(ipaaca SHARED ${SOURCE})
# and link all the required external libs (found above using find_package etc.)
target_link_libraries(ipaaca ${LIBS})
add_executable (ipaaca-test-json ${JSON_TEST_SOURCE})
target_link_libraries (ipaaca-test-json ${LIBS})
#add_executable (ipaaca-test-json ${JSON_TEST_SOURCE})
#target_link_libraries (ipaaca-test-json ${LIBS})
add_executable (ipaaca-tester-cpp ${TESTER_SOURCE})
target_compile_options (ipaaca-tester-cpp PRIVATE "-DIPAACA_STATIC_BINARY")
target_link_libraries (ipaaca-tester-cpp ${LIBS})
set(DEFAULT_BIN_SUBDIR bin)
set(DEFAULT_LIB_SUBDIR lib)
set(DEFAULT_DATA_SUBDIR share/data)
set(DEFAULT_INCLUDE_SUBDIR include)
set(CMAKE_INSTALL_PREFIX "")
install (
TARGETS ipaaca
TARGETS ipaaca ipaaca-tester-cpp
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
......@@ -214,11 +302,4 @@ install(
DESTINATION include/ipaaca/
)
install (
TARGETS ipaaca-test-json
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
@echo off
md build
cd build
md ipaaca
\Users\ryaghoub\Documents\Develop\repo\protobuf\bin\protoc.exe --proto_path=../../proto ../../proto/ipaaca.proto --cpp_out=build/ipaaca/
cmake .. -DBoost_DEBUG:bool=True -DBOOST_LIBRARYDIR:string=C:\Users\ryaghoub\Downloads\boost_1_57_0__built__boost_subdir_moved_to_stage_include\stage\lib -DBoost_USE_STATIC_LIBS=ON -DBoost_USE_MULTITHREADED=ON -DPROTOBUF_ROOT:string=C:\Users\ryaghoub\Documents\Develop\repo\protobuf
msbuild INSTALL.vcxproj
......@@ -4,4 +4,6 @@ resource.path=${shared.resources}/;
rebuild.list=
publish.resolver=asap.sftp.publish
dist.dir=../../dist
deps.dir=../../deps
test.binary=testipaaca
......@@ -16,13 +16,16 @@
<arg value="../proto/ipaaca.proto" />
<arg value="--cpp_out=build/ipaaca/" />
</exec>
</target>
</target>
<target name="-pre-compilation" depends="-proto-yes,-proto-no" />
<target name="-compilation" depends="-build-setup, -pre-compilation">
<!-- echo message="Using temporary RSBProtocol_DIR=${cmake.base.dir}/rsc_tmp/share/rsbprotocol0.10" / -->
<cmake srcdir="${cmake.base.dir}"
bindir="${build.dir}"
buildtype="Debug">
<generator name="Visual Studio 14 Win64" platform="windows" buildtype="Release" buildargs="ALL_BUILD.vcxproj">
<variable name="CMAKE_INSTALL_PREFIX" type="PATH" value="../${zip.tmp.dir}" />
</generator>
<generator name="Visual Studio 10" platform="windows" buildargs="ALL_BUILD.vcxproj">
<variable name="CMAKE_INSTALL_PREFIX" type="PATH" value="../${zip.tmp.dir}" />
</generator>
......
......@@ -3,7 +3,7 @@
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2013 Sociable Agents Group
* Copyright (c) 2009-2022 Sociable Agents Group
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
......
/**
* `b64.h' - b64
*
* copyright (c) 2014 joseph werle
*/
/*
From https://github.com/littlstar/b64.c/blob/master/LICENSE :
The MIT License (MIT)
Copyright (c) 2014 Little Star Media, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef B64_H
#define B64_H 1
// RYT start
#include <string>
std::string base64_encode(const std::string& bin);
std::string base64_decode(const std::string& b64);
// RYT end
/**
* Memory allocation functions to use. You can define b64_malloc and
* b64_realloc to custom functions if you want.
*/
#ifndef b64_malloc
# define b64_malloc(ptr) malloc(ptr)
#endif
#ifndef b64_realloc
# define b64_realloc(ptr, size) realloc(ptr, size)
#endif
/**
* Base64 index table.
*/
static const char b64_table[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
#ifdef __cplusplus
extern "C" {
#endif
/**
* Encode `unsigned char *' source with `size_t' size.
* Returns a `char *' base64 encoded string.
*/
char *
b64_encode (const unsigned char *, size_t);
/**
* Dencode `char *' source with `size_t' size.
* Returns a `unsigned char *' base64 decoded string.
*/
unsigned char *
b64_decode (const char *, size_t);
/**
* Dencode `char *' source with `size_t' size.
* Returns a `unsigned char *' base64 decoded string + size of decoded string.
*/
unsigned char *
b64_decode_ex (const char *, size_t, size_t *);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-backend.h
*
* \brief Header file for abstract backend participant implementation
* (used in the core library and as a base to derive specific backends).
*
* Users should not include this file directly, but use ipaaca.h
*
* \b Note: This file is only included during compilation of ipaaca,
* for regular use, the full internal API is not exposed.
* Users generally need never touch the internal transport layer.
*
* \author Ramin Yaghoubzadeh Torky (ryaghoubzadeh@uni-bielefeld.de)
* \date January, 2019
*/
#ifndef __ipaaca_backend_mqtt_h_INCLUDED__
#define __ipaaca_backend_mqtt_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
}
// Backend-specific include[s]
#include <mosquittopp.h>
namespace ipaaca {
#define _MQTT_REMOTE_SERVER_MAX_QUEUED_REQUESTS 0
namespace backend {
namespace mqtt {
//
// START of backend-specific implementation
//
// here: MQTT
// helper to encapsulate a wait-until-live mechanism
// you can take this for other backends and adopt the friend class name
class ParticipantCore {
friend class MQTTBackEnd;
protected:
IPAACA_MEMBER_VAR_EXPORT std::condition_variable _condvar;
IPAACA_MEMBER_VAR_EXPORT std::mutex _condvar_mutex;
IPAACA_MEMBER_VAR_EXPORT bool _running;
IPAACA_MEMBER_VAR_EXPORT bool _live;
protected:
IPAACA_HEADER_EXPORT ParticipantCore();
IPAACA_HEADER_EXPORT void signal_live();
IPAACA_HEADER_EXPORT bool wait_live(long timeout_milliseconds = 15000);
};
class MQTTParticipant: public ParticipantCore, public mosqpp::mosquittopp {
public:
typedef std::shared_ptr<MQTTParticipant> ptr;
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _scope;
IPAACA_MEMBER_VAR_EXPORT std::string _client_id;
IPAACA_MEMBER_VAR_EXPORT std::string host;
IPAACA_MEMBER_VAR_EXPORT int port;
IPAACA_MEMBER_VAR_EXPORT int keepalive;
public:
IPAACA_HEADER_EXPORT MQTTParticipant(const MQTTParticipant& orig) = delete; // forbid copy-construction for backend
IPAACA_HEADER_EXPORT inline virtual ~MQTTParticipant() { }
IPAACA_HEADER_EXPORT MQTTParticipant(const std::string& client_id, const std::string& scope, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT void connect_and_background();
IPAACA_HEADER_EXPORT virtual void on_error();
IPAACA_HEADER_EXPORT virtual void on_disconnect(int rc);
IPAACA_HEADER_EXPORT static int get_next_mid();
/* // available mosquittopp callbacks:
virtual void on_connect(int rc) {return;}
virtual void on_disconnect(int rc) {return;}
virtual void on_publish(int mid) {return;}
virtual void on_message(const struct mosquitto_message * message) {return;}
virtual void on_subscribe(int mid, int qos_count, const int * granted_qos) {return;}
virtual void on_unsubscribe(int mid) {return;}
virtual void on_log(int level, const char * str) {return;}
virtual void on_error() {return;}
*/
};
class MQTTInformer: public MQTTParticipant, public Informer {
public:
typedef std::shared_ptr<MQTTInformer> ptr;
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _client_id;
public:
IPAACA_HEADER_EXPORT MQTTInformer(const std::string& client_id, const std::string& scope, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT virtual void on_connect(int rc);
IPAACA_HEADER_EXPORT virtual bool internal_publish(const std::string& wire);
};
class MQTTListener: public MQTTParticipant, public Listener {
public:
typedef std::shared_ptr<MQTTListener> ptr;
public:
IPAACA_HEADER_EXPORT MQTTListener(const std::string& client_id, const std::string& scope, InputBuffer* buffer_ptr, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT virtual void on_connect(int rc);
IPAACA_HEADER_EXPORT virtual void on_subscribe(int mid, int qos_count, const int * granted_qos);
IPAACA_HEADER_EXPORT virtual void on_message(const struct mosquitto_message * message);
};
class MQTTLocalServer: public MQTTParticipant, public LocalServer {
public:
typedef std::shared_ptr<MQTTLocalServer> ptr;
protected:
IPAACA_HEADER_EXPORT void send_result_for_request(const std::string& request_endpoint, const std::string& request_uid, int64_t result);
public:
IPAACA_HEADER_EXPORT MQTTLocalServer(const std::string& client_id, const std::string& scope, ipaaca::OutputBuffer* buffer_ptr, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT virtual void on_connect(int rc);
IPAACA_HEADER_EXPORT virtual void on_subscribe(int mid, int qos_count, const int * granted_qos);
IPAACA_HEADER_EXPORT virtual void on_message(const struct mosquitto_message * message);
};
class MQTTRemoteServer: public MQTTParticipant, public RemoteServer {
public:
typedef std::shared_ptr<RemoteServer> ptr;
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, PendingRequest::ptr> _pending_requests;
IPAACA_MEMBER_VAR_EXPORT ipaaca::Lock _pending_requests_lock;
IPAACA_MEMBER_VAR_EXPORT std::string _remote_end_scope; // this is the actual important scope,
// MQTTParticipant::_scope is repurposed here for receiving replies
IPAACA_MEMBER_VAR_EXPORT std::string _name; // using this (unique) auto-generated name
public:
IPAACA_HEADER_EXPORT MQTTRemoteServer(const std::string& client_id, const std::string& scope, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT int64_t request_remote_payload_update(std::shared_ptr<IUPayloadUpdate> update);
IPAACA_HEADER_EXPORT int64_t request_remote_link_update(std::shared_ptr<IULinkUpdate> update);
IPAACA_HEADER_EXPORT int64_t request_remote_commission(std::shared_ptr<protobuf::IUCommission> update);
IPAACA_HEADER_EXPORT int64_t request_remote_resend_request(std::shared_ptr<protobuf::IUResendRequest> update);
IPAACA_HEADER_EXPORT virtual void on_connect(int rc);
IPAACA_HEADER_EXPORT virtual void on_subscribe(int mid, int qos_count, const int * granted_qos);
IPAACA_HEADER_EXPORT virtual void on_message(const struct mosquitto_message * message);
IPAACA_HEADER_EXPORT PendingRequest::ptr queue_pending_request(Event::ptr request);
IPAACA_HEADER_EXPORT int64_t blocking_call(Event::ptr request);
};
class MQTTBackEnd: public BackEnd
{
public:
typedef std::shared_ptr<MQTTBackEnd> ptr;
friend class BackEndLibrary;
protected:
IPAACA_HEADER_EXPORT MQTTBackEnd();
public:
IPAACA_HEADER_EXPORT static BackEnd::ptr get();
IPAACA_HEADER_EXPORT void teardown();
IPAACA_HEADER_EXPORT Informer::ptr createInformer(const std::string& scope);
IPAACA_HEADER_EXPORT Listener::ptr createListener(const std::string& scope, InputBuffer* buf);
IPAACA_HEADER_EXPORT LocalServer::ptr createLocalServer(const std::string& scope, OutputBuffer* buf);
IPAACA_HEADER_EXPORT RemoteServer::ptr createRemoteServer(const std::string& scope);
IPAACA_HEADER_EXPORT inline std::string make_valid_scope(const std::string& scope) override { return scope; }
};
} // of namespace mqtt
} // of namespace backend
#endif // of __ipaaca_backend_mqtt_h_INCLUDED__
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-backend.h
*
* \brief Header file for abstract backend participant implementation
* (used in the core library and as a base to derive specific backends).
*
* Users should not include this file directly, but use ipaaca.h
*
* \b Note: This file is only included during compilation of ipaaca,
* for regular use, the full internal API is not exposed.
* Users generally need never touch the internal transport layer.
*
* \author Ramin Yaghoubzadeh Torky (ryaghoubzadeh@uni-bielefeld.de)
* \date January, 2019
*/
#ifndef __ipaaca_backend_ros_h_INCLUDED__
#define __ipaaca_backend_ros_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
}
// Backend-specific include[s]
#include "ros/ros.h"
#include "std_msgs/String.h"
namespace ipaaca {
#define _ROS_REMOTE_SERVER_MAX_QUEUED_REQUESTS 0
namespace backend {
namespace ros {
//
// START of backend-specific implementation
//
// here: ROS
// helper to encapsulate a wait-until-live mechanism
// you can take this for other backends and adopt the friend class name
class ParticipantCore {
friend class ROSBackEnd;
protected:
IPAACA_MEMBER_VAR_EXPORT std::condition_variable _condvar;
IPAACA_MEMBER_VAR_EXPORT std::mutex _condvar_mutex;
IPAACA_MEMBER_VAR_EXPORT bool _running;
IPAACA_MEMBER_VAR_EXPORT bool _live;
protected:
IPAACA_HEADER_EXPORT ParticipantCore();
IPAACA_HEADER_EXPORT void signal_live();
IPAACA_HEADER_EXPORT bool wait_live(long timeout_milliseconds = 15000);
};
class ROSParticipant: public ParticipantCore {
public:
typedef std::shared_ptr<ROSParticipant> ptr;
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _scope;
IPAACA_MEMBER_VAR_EXPORT std::string host;
IPAACA_MEMBER_VAR_EXPORT int port;
IPAACA_MEMBER_VAR_EXPORT int keepalive;
protected:
// a pointer; odd, but see the ROSBackEnd constructor & destructor
::ros::NodeHandle* _node_handle;
public:
IPAACA_HEADER_EXPORT ROSParticipant(const ROSParticipant& orig) = delete; // forbid copy-construction for backend
IPAACA_HEADER_EXPORT inline virtual ~ROSParticipant() { }
IPAACA_HEADER_EXPORT ROSParticipant(::ros::NodeHandle* node, const std::string& scope, Config::ptr config = nullptr);
};
class ROSInformer: public ROSParticipant, public Informer {
public:
typedef std::shared_ptr<ROSInformer> ptr;
protected:
::ros::Publisher _ros_pub;
public:
IPAACA_HEADER_EXPORT ROSInformer(::ros::NodeHandle* node, const std::string& scope, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT virtual bool internal_publish(const std::string& wire);
};
class ROSListener: public ROSParticipant, public Listener {
public:
typedef std::shared_ptr<ROSListener> ptr;
protected:
IPAACA_MEMBER_VAR_EXPORT ::ros::Subscriber _ros_sub;
public:
IPAACA_HEADER_EXPORT ROSListener(::ros::NodeHandle* node, const std::string& scope, InputBuffer* buffer_ptr, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT virtual void on_message(const std_msgs::String::ConstPtr& msg);
};
class ROSLocalServer: public ROSParticipant, public LocalServer {
public:
typedef std::shared_ptr<ROSLocalServer> ptr;
protected:
IPAACA_MEMBER_VAR_EXPORT ::ros::Subscriber _ros_sub;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, ::ros::Publisher> _ros_pubs;
protected:
IPAACA_HEADER_EXPORT void send_result_for_request(const std::string& request_endpoint, const std::string& request_uid, int64_t result);
IPAACA_HEADER_EXPORT ::ros::Publisher get_publisher(const std::string& endpoint);
public:
IPAACA_HEADER_EXPORT ROSLocalServer(::ros::NodeHandle* node, const std::string& scope, ipaaca::OutputBuffer* buffer_ptr, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT virtual void on_message(const std_msgs::String::ConstPtr& msg);
};
class ROSRemoteServer: public ROSParticipant, public RemoteServer {
public:
typedef std::shared_ptr<RemoteServer> ptr;
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, PendingRequest::ptr> _pending_requests;
IPAACA_MEMBER_VAR_EXPORT ipaaca::Lock _pending_requests_lock;
IPAACA_MEMBER_VAR_EXPORT std::string _remote_end_scope; // this is the actual important scope,
// ROSParticipant::_scope is repurposed here for receiving replies
IPAACA_MEMBER_VAR_EXPORT std::string _name; // using this (unique) auto-generated name
IPAACA_MEMBER_VAR_EXPORT ::ros::Subscriber _ros_sub;
IPAACA_MEMBER_VAR_EXPORT ::ros::Publisher _ros_pub;
public:
IPAACA_HEADER_EXPORT ROSRemoteServer(::ros::NodeHandle* node, const std::string& scope, Config::ptr config = nullptr);
IPAACA_HEADER_EXPORT int64_t request_remote_payload_update(std::shared_ptr<IUPayloadUpdate> update);
IPAACA_HEADER_EXPORT int64_t request_remote_link_update(std::shared_ptr<IULinkUpdate> update);
IPAACA_HEADER_EXPORT int64_t request_remote_commission(std::shared_ptr<protobuf::IUCommission> update);
IPAACA_HEADER_EXPORT int64_t request_remote_resend_request(std::shared_ptr<protobuf::IUResendRequest> update);
IPAACA_HEADER_EXPORT PendingRequest::ptr queue_pending_request(Event::ptr request);
IPAACA_HEADER_EXPORT int64_t blocking_call(Event::ptr request);
IPAACA_HEADER_EXPORT virtual void on_message(const std_msgs::String::ConstPtr& msg);
};
class ROSBackEnd: public BackEnd
{
public:
typedef std::shared_ptr<ROSBackEnd> ptr;
friend class BackEndLibrary;
protected:
bool _need_init;
char* _cfakename;
::ros::NodeHandle* _node_handle;
::ros::AsyncSpinner* _spinner;
protected:
IPAACA_HEADER_EXPORT ROSBackEnd();
public:
IPAACA_HEADER_EXPORT static BackEnd::ptr get();
IPAACA_HEADER_EXPORT void teardown();
IPAACA_HEADER_EXPORT void init_once();
IPAACA_HEADER_EXPORT Informer::ptr createInformer(const std::string& scope);
IPAACA_HEADER_EXPORT Listener::ptr createListener(const std::string& scope, InputBuffer* buf);
IPAACA_HEADER_EXPORT LocalServer::ptr createLocalServer(const std::string& scope, OutputBuffer* buf);
IPAACA_HEADER_EXPORT RemoteServer::ptr createRemoteServer(const std::string& scope);
IPAACA_HEADER_EXPORT inline std::string make_valid_scope(const std::string& scope) override {
// strip the leading slash for the ROS node name (removing this
// extra rule would lead to a global (non-movable) namespace
if (scope.length() && (scope[0] == '/')) return scope.substr(1);
else return scope;
}
};
} // of namespace ros
} // of namespace backend
#endif // of __ipaaca_backend_ros_h_INCLUDED__
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-backend.h
*
* \brief Header file for abstract backend participant implementation
* (used in the core library and as a base to derive specific backends).
*
* Users should not include this file directly, but use ipaaca.h
*
* \b Note: This file is only included during compilation of ipaaca,
* for regular use, the full internal API is not exposed.
* Users generally need never touch the internal transport layer.
*
* \author Ramin Yaghoubzadeh Torky (ryaghoubzadeh@uni-bielefeld.de)
* \date December, 2018
*/
#ifndef __ipaaca_backend_h_INCLUDED__
#define __ipaaca_backend_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
namespace backend {
#if _WIN32 || _WIN64
inline std::string generate_client_id()
{
// '-' not allowed e.g. in ROS
std::string uuid = ipaaca::generate_uuid_string().substr(0,8);
return uuid;
}
#else
// get simplified basename of the process name from /proc
// (we could also decide to route argv here instead)
inline std::string get_simplified_process_name()
{
std::fstream fs;
fs.open("/proc/self/cmdline", std::fstream::in);
if (!fs.is_open()) {
IPAACA_DEBUG("Could not open /proc/self/cmdline")
return "ipaaca_cpp";
}
std::string line;
std::vector<std::string> tokens;
if (!std::getline(fs, line)) {
IPAACA_DEBUG("Failed to read a line from /proc/self/cmdline")
fs.close();
return "ipaaca_cpp";
}
fs.close();
int cnt = ipaaca::str_split_append(line, tokens, "\000");
if (cnt < 1) {
IPAACA_DEBUG("Failed to get process name from /proc/self/cmdline")
return "ipaaca_cpp";
}
line = tokens[0];
cnt = ipaaca::str_split_wipe(line, tokens, "/");
if (cnt < 1) {
IPAACA_DEBUG("Failed to parse process name in /proc/self/cmdline")
return "ipaaca_cpp";
}
std::string procname;
line = tokens[cnt-1];
for (auto ch: line) {
if ((ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9') || (ch=='_')) {
procname += ch;
} else if (ch=='-' || ch=='.' || ch==' ') {
procname += '_';
}
}
if (procname=="") {
IPAACA_DEBUG("Only unacceptable characters in process name from /proc/self/cmdline")
return "ipaaca_cpp";
} else {
return procname;
}
}
inline std::string generate_client_id()
{
//std::stringstream ss;
//ss << "Process_" << getpid() << "_ClientID_" << ipaaca::generate_uuid_string();
//return ss.str();
std::string uuid = get_simplified_process_name() + "_" + ipaaca::generate_uuid_string().substr(0,8);
return uuid;
}
#endif
/*
* class Scope {
public:
std::string scope_string;
Scope(const std::string& sc): scope_string(sc) {}
Scope(const Scope& scope): scope_string(scope.scope_string) {}
inline operator std::string() const { return scope_string; }
};
*/
// RSB-like wrapper for {wire type; void ref to deserialized obj}
// to avoid modifying the event handling side.
class Event {
public:
typedef std::shared_ptr<Event> ptr;
protected:
std::string _type;
std::shared_ptr<void> _data;
public:
inline Event(const std::string& type, std::shared_ptr<void> data): _type(type), _data(data) { }
inline std::string getType() const { return _type; }
inline std::shared_ptr<void> getData() const { return _data; }
};
class PendingRequest {
/** Encapsulation of a pending remote request with
a facility to keep the requesting thread locked
until the reply or a timeout unlocks it. */
public:
typedef std::shared_ptr<PendingRequest> ptr;
protected:
Event::ptr _pending_request;
std::condition_variable _condvar;
std::mutex _condvar_mutex;
// block var
public:
std::string _request_uid;
int _result;
public:
inline PendingRequest(Event::ptr req) {
std::string uuid = ipaaca::generate_uuid_string();
_request_uid = uuid.substr(0,8);
_pending_request = req;
_result = -1;
}
/// reply_with_result is called by the backend when a remote request reply has been received (and it was a known tracked request)
inline void reply_with_result(int result) {
_result = result;
_condvar.notify_one(); // wake up the waiting thread
};
/// wait_for_reply is called internally by the user thread that attempts to modify remote IUs, it waits until the remote end replies
inline int wait_for_reply(long timeout_milliseconds = 30000) {
std::unique_lock<std::mutex> lock(_condvar_mutex);
// the remote end will set the result >=0 (from the other thread), which suffices to continue
auto success = _condvar.wait_for(lock, std::chrono::milliseconds(timeout_milliseconds), [this]{return this->_result >= 0;});
if (!success) {
IPAACA_ERROR("Request timeout: we did not receive a reply for a remote server request")
// TODO could throw instead
}
return _result;
}
};
//
// Abstract interface
//
class Informer {
public:
typedef std::shared_ptr<Informer> ptr;
protected:
std::string _client_id;
public:
IPAACA_HEADER_EXPORT inline virtual ~Informer() { }
template<typename Data> IPAACA_HEADER_EXPORT inline bool publish(Data d) { return internal_publish(ipaaca::converters::internal_serialize(d)); }
public:
//
// You MUST override these functions in the backend versions:
//
IPAACA_HEADER_EXPORT virtual bool internal_publish(const std::string& wire) { IPAACA_ERROR("Attempt to invoke abstract version of Informer::internal_publish"); throw NotImplementedError(); }
};
/*
IPAACA_HEADER_EXPORT virtual bool publish(ipaaca::IU::ptr) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(ipaaca::Message::ptr) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(ipaaca::IUPayloadUpdate::ptr) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(ipaaca::IULinkUpdate::ptr) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(std::shared_ptr<protobuf::RemoteRequestResult>) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(std::shared_ptr<protobuf::IURetraction>) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(std::shared_ptr<protobuf::IUCommission>) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(std::shared_ptr<protobuf::IUResendRequest>) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(std::shared_ptr<protobuf::IUPayloadUpdateRequest>) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(std::shared_ptr<protobuf::IULinkUpdateRequest>) = 0;
IPAACA_HEADER_EXPORT virtual bool publish(std::shared_ptr<protobuf::IUCommissionRequest>
*/
class Listener {
public:
typedef std::shared_ptr<Listener> ptr;
protected:
ipaaca::InputBuffer* _buffer;
protected:
Listener(ipaaca::InputBuffer* buffer): _buffer(buffer) { }
public:
IPAACA_HEADER_EXPORT inline virtual ~Listener() { }
//inline Listener(const Scope& scope, InputBuffer* buffer_ptr, Config::ptr config = nullptr)) {}
void relay_received_event_to_buffer(Event::ptr event);
void relay_received_event_to_buffer_threaded(Event::ptr event);
};
class LocalServer {
public:
typedef std::shared_ptr<LocalServer> ptr;
protected:
ipaaca::OutputBuffer* _buffer;
protected:
LocalServer(ipaaca::OutputBuffer* buffer): _buffer(buffer) { }
public:
//inline LocalServer(const Scope& scope, ipaaca::OutputBuffer* buffer_ptr, Config::ptr config = nullptr): _buffer(buffer_ptr);
IPAACA_HEADER_EXPORT inline virtual ~LocalServer() { }
//IPAACA_HEADER_EXPORT virtual int64_t attempt_to_apply_remote_payload_update(std::shared_ptr<IUPayloadUpdate> update) = 0;
//IPAACA_HEADER_EXPORT virtual int64_t attempt_to_apply_remote_link_update(std::shared_ptr<IULinkUpdate> update) = 0;
//IPAACA_HEADER_EXPORT virtual int64_t attempt_to_apply_remote_commission(std::shared_ptr<protobuf::IUCommission> update) = 0;
//IPAACA_HEADER_EXPORT virtual int64_t attempt_to_apply_remote_resend_request(std::shared_ptr<protobuf::IUResendRequest> update) = 0;
IPAACA_HEADER_EXPORT int64_t attempt_to_apply_remote_payload_update(std::shared_ptr<IUPayloadUpdate> update);
IPAACA_HEADER_EXPORT int64_t attempt_to_apply_remote_link_update(std::shared_ptr<IULinkUpdate> update);
IPAACA_HEADER_EXPORT int64_t attempt_to_apply_remote_commission(std::shared_ptr<protobuf::IUCommission> update);
IPAACA_HEADER_EXPORT int64_t attempt_to_apply_remote_resend_request(std::shared_ptr<protobuf::IUResendRequest> update);
};
class RemoteServer {
public:
typedef std::shared_ptr<RemoteServer> ptr;
public:
//inline RemoteServer(const Scope& scope, Config::ptr config = nullptr) {
//}
IPAACA_HEADER_EXPORT inline virtual ~RemoteServer() { }
IPAACA_HEADER_EXPORT virtual int64_t request_remote_payload_update(std::shared_ptr<IUPayloadUpdate> update) = 0;
IPAACA_HEADER_EXPORT virtual int64_t request_remote_link_update(std::shared_ptr<IULinkUpdate> update) = 0;
IPAACA_HEADER_EXPORT virtual int64_t request_remote_commission(std::shared_ptr<protobuf::IUCommission> update) = 0;
IPAACA_HEADER_EXPORT virtual int64_t request_remote_resend_request(std::shared_ptr<protobuf::IUResendRequest> update) = 0;
};
class BackEnd {
public:
typedef std::shared_ptr<BackEnd> ptr;
protected:
std::string _backend_name;
public:
BackEnd(std::string backend_name): _backend_name(backend_name) { }
inline std::string name() const { return _backend_name; }
virtual ~BackEnd() {}
virtual void teardown() = 0;
virtual LocalServer::ptr createLocalServer(const std::string& scope, OutputBuffer* buf) = 0;
virtual Informer::ptr createInformer(const std::string& scope) = 0;
virtual RemoteServer::ptr createRemoteServer(const std::string& scope) = 0;
virtual Listener::ptr createListener(const std::string& scope, InputBuffer* buf) = 0;
virtual std::string make_valid_scope(const std::string& scope) = 0;
};
class BackEndLibrary {
public:
typedef std::shared_ptr<BackEndLibrary> ptr;
protected:
std::map<std::string, BackEnd::ptr> _backends;
public:
BackEndLibrary() { }
inline static BackEndLibrary::ptr get() {
static BackEndLibrary::ptr lib;
if (!lib) {
lib = std::make_shared<BackEndLibrary>();
}
return lib;
}
inline bool register_backend(BackEnd::ptr backend) {
if (_backends.count(backend->name())) {
IPAACA_ERROR("Not registering another BackEnd with already known name: " << backend->name())
return false;
} else {
_backends[backend->name()] = backend;
return true;
}
}
inline BackEnd::ptr get_default_backend() {
static BackEnd::ptr _singleton;
if (_singleton) return _singleton;
if (_backends.size() == 0) {
IPAACA_ERROR("No backends are registered inside the library - cannot continue")
throw BackEndNotFoundError();
}
std::string preferred_backend = get_global_config()->get_with_default<std::string>("backend", "");
if (preferred_backend != "") {
if (_backends.count(preferred_backend)) {
_singleton = _backends[preferred_backend];
} else {
IPAACA_ERROR("Failed to initialize the selected BackEnd " << preferred_backend)
throw BackEndNotFoundError();
}
} else {
// just return the first value // FIXME config or clean precedence rule
for (auto kv: _backends) {
IPAACA_WARNING("No 'backend' config found, selecting BackEnd " << kv.second->name())
_singleton = kv.second;
break;
}
}
if (_singleton) return _singleton;
throw BackEndNotFoundError(); // should not be reached; silence warnings
}
};
inline BackEnd::ptr get_default_backend() {
return BackEndLibrary::get()->get_default_backend();
}
} // of namespace backend
#endif
......@@ -3,7 +3,7 @@
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2015 Social Cognitive Systems Group
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
......@@ -38,55 +38,71 @@
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
// Convenience macro to abstract from the bind implementation being used
// and possible future signature changes.
#define IPAACA_BIND_CLASS_HANDLER(fn, inst) std::bind(fn, inst, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
/// store for (local) IUs. TODO Stores need to be unified more
IPAACA_HEADER_EXPORT class IUStore: public std::map<std::string, boost::shared_ptr<IU> >
/// Store for local IUs (used in OutputBuffer)
class IUStore: public std::map<std::string, std::shared_ptr<IU> >
{
};
/// store for RemotePushIUs. TODO Stores need to be unified more
IPAACA_HEADER_EXPORT class RemotePushIUStore: public std::map<std::string, boost::shared_ptr<RemotePushIU> > // TODO genericize to all remote IU types
/// Store for RemotePushIUs (used in InputBuffer)
class RemotePushIUStore: public std::map<std::string, std::shared_ptr<RemotePushIU> >
{
};
typedef std::set<std::string> LinkSet;
typedef std::map<std::string, LinkSet> LinkMap;
IPAACA_HEADER_EXPORT class SmartLinkMap {//{{{
/// Container for IU links that gracefully returns the empty set if required
class SmartLinkMap {//{{{
friend std::ostream& operator<<(std::ostream& os, const SmartLinkMap& obj);
friend class IUInterface;
friend class IU;
friend class IUConverter;
friend class MessageConverter;
friend class ipaaca::converters::IUConverter;
//friend class ipaaca::converters::MessageConverter;
public:
IPAACA_HEADER_EXPORT const LinkSet& get_links(const std::string& key);
IPAACA_HEADER_EXPORT const LinkMap& get_all_links();
protected:
IPAACA_MEMBER_VAR_EXPORT LinkMap _links;
/// The empty link set is returned if undefined links are read for an IU.
IPAACA_MEMBER_VAR_EXPORT static LinkSet empty_link_set;
protected:
IPAACA_HEADER_EXPORT void _add_and_remove_links(const LinkMap& add, const LinkMap& remove);
IPAACA_HEADER_EXPORT void _replace_links(const LinkMap& links);
};//}}}
/// The empty link set is returned if undefined links are read for an IU.
IPAACA_MEMBER_VAR_EXPORT const LinkSet EMPTY_LINK_SET;
IPAACA_HEADER_EXPORT class BufferConfiguration//{{{
/// Configuration object that can be passed to Buffer constructors.
class BufferConfiguration//{{{
{
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _basename;
IPAACA_MEMBER_VAR_EXPORT std::vector<std::string> _category_interests;
IPAACA_MEMBER_VAR_EXPORT std::string _channel;
public:
IPAACA_HEADER_EXPORT inline BufferConfiguration(const std::string basename) { _basename = basename; }
IPAACA_HEADER_EXPORT const std::string get_basename() const { return _basename; }
IPAACA_HEADER_EXPORT const std::vector<std::string> get_category_interests() const { return _category_interests; }
IPAACA_HEADER_EXPORT const std::string get_channel() const { return _channel; }
IPAACA_HEADER_EXPORT inline BufferConfiguration(const std::string& basename): _basename(basename), _channel(__ipaaca_static_option_default_channel) { }
IPAACA_HEADER_EXPORT inline const std::string& get_basename() const { return _basename; }
IPAACA_HEADER_EXPORT inline const std::vector<std::string>& get_category_interests() const { return _category_interests; }
IPAACA_HEADER_EXPORT inline const std::string& get_channel() const { return _channel; }
public:
// setters, initialization helpers
IPAACA_HEADER_EXPORT inline BufferConfiguration& set_basename(const std::string& basename) { _basename = basename; return *this; }
IPAACA_HEADER_EXPORT inline BufferConfiguration& add_category_interest(const std::string& category) { _category_interests.push_back(category); return *this; }
IPAACA_HEADER_EXPORT inline BufferConfiguration& set_channel(const std::string& channel) { _channel = channel; return *this; }
};//}}}
IPAACA_HEADER_EXPORT class BufferConfigurationBuilder: private BufferConfiguration//{{{
/// Builder object for BufferConfiguration, not required for C++ [DEPRECATED]
class BufferConfigurationBuilder: private BufferConfiguration//{{{
{
public:
IPAACA_HEADER_EXPORT inline BufferConfigurationBuilder(const std::string basename):BufferConfiguration(basename) {}
[[deprecated("Use setters in BufferConfiguration instead of the Builder")]]
IPAACA_HEADER_EXPORT inline BufferConfigurationBuilder(const std::string& basename): BufferConfiguration(basename) {}
IPAACA_HEADER_EXPORT inline void set_basename(const std::string& basename)
{
_basename = basename;
......@@ -104,9 +120,20 @@ IPAACA_HEADER_EXPORT class BufferConfigurationBuilder: private BufferConfigurati
};//}}}
IPAACA_HEADER_EXPORT typedef boost::function<void (boost::shared_ptr<IUInterface>, IUEventType, bool)> IUEventHandlerFunction;
/** \brief Type of user-space functions that can be registered on a Buffer to receive IU events.
*
* The signature of these functions is void(shared_ptr<IUInterface> iu, IUEventType evt_type, bool local), where:<br/>
* iu can be used mostly like a locally-generated IU reference (e.g. iu->payload() ...)<br/>
* evt_type is one of IU_ADDED, IU_UPDATED, IU_RETRACTED, IU_DELETED, IU_LINKSUPDATED, IU_COMMITTED, IU_MESSAGE<br/>
* local indicates that a remote change to a local IU (in an OutputBuffer) was effected
*
* See #Buffer::register_handler for examples on how to use your own handlers.
*/
IPAACA_HEADER_EXPORT typedef std::function<void (std::shared_ptr<IUInterface>, IUEventType, bool)> IUEventHandlerFunction;
IPAACA_HEADER_EXPORT class IUEventHandler {//{{{
/** \brief Internal handler type used in Buffer (wraps used-specified IUEventHandlerFunction)
*/
class IUEventHandler {//{{{
protected:
IPAACA_MEMBER_VAR_EXPORT IUEventHandlerFunction _function;
IPAACA_MEMBER_VAR_EXPORT IUEventType _event_mask;
......@@ -120,189 +147,270 @@ IPAACA_HEADER_EXPORT class IUEventHandler {//{{{
public:
IPAACA_HEADER_EXPORT IUEventHandler(IUEventHandlerFunction function, IUEventType event_mask, const std::string& category);
IPAACA_HEADER_EXPORT IUEventHandler(IUEventHandlerFunction function, IUEventType event_mask, const std::set<std::string>& categories);
//void call(Buffer* buffer, const std::string& uid, bool local, IUEventType event_type, const std::string& category);
IPAACA_HEADER_EXPORT void call(Buffer* buffer, boost::shared_ptr<IUInterface> iu, bool local, IUEventType event_type, const std::string& category);
typedef boost::shared_ptr<IUEventHandler> ptr;
IPAACA_HEADER_EXPORT void call(Buffer* buffer, std::shared_ptr<IUInterface> iu, bool local, IUEventType event_type, const std::string& category);
typedef std::shared_ptr<IUEventHandler> ptr;
};//}}}
IPAACA_HEADER_EXPORT class Buffer { //: public boost::enable_shared_from_this<Buffer> {//{{{
friend class IU;
friend class RemotePushIU;
friend class CallbackIUPayloadUpdate;
friend class CallbackIULinkUpdate;
friend class CallbackIUCommission;
friend class CallbackIUResendRequest;
protected:
//Lock _handler_lock;
IPAACA_MEMBER_VAR_EXPORT std::string _uuid;
IPAACA_MEMBER_VAR_EXPORT std::string _basename;
IPAACA_MEMBER_VAR_EXPORT std::string _unique_name;
IPAACA_MEMBER_VAR_EXPORT std::string _id_prefix;
IPAACA_MEMBER_VAR_EXPORT std::string _channel;
IPAACA_MEMBER_VAR_EXPORT std::vector<IUEventHandler::ptr> _event_handlers;
protected:
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _publish_iu_resend(boost::shared_ptr<IU> iu, const std::string& hidden_scope_name) = 0;
/**
* \brief Buffer base class. Derived classes use its handler registration functionality.
*
* \b Note: This class is never instantiated directly (use OutputBuffer and InputBuffer, respectively).
*/
class Buffer {
friend class IU;
friend class RemotePushIU;
/*friend class CallbackIUPayloadUpdate;
friend class CallbackIULinkUpdate;
friend class CallbackIUCommission;
friend class CallbackIUResendRequest;*/
friend class ipaaca::backend::LocalServer;
friend class ipaaca::backend::Listener;
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _uuid;
IPAACA_MEMBER_VAR_EXPORT std::string _basename;
IPAACA_MEMBER_VAR_EXPORT std::string _unique_name;
IPAACA_MEMBER_VAR_EXPORT std::string _id_prefix;
IPAACA_MEMBER_VAR_EXPORT std::string _channel;
IPAACA_MEMBER_VAR_EXPORT std::vector<IUEventHandler::ptr> _event_handlers;
protected:
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _publish_iu_resend(std::shared_ptr<IU> iu, const std::string& hidden_scope_name) = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") = 0;
// IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_resendrequest(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") = 0;
IPAACA_HEADER_EXPORT void _allocate_unique_name(const std::string& basename, const std::string& function);
IPAACA_HEADER_EXPORT inline Buffer(const std::string& basename, const std::string& function) {
_allocate_unique_name(basename, function);
_channel = "default";
}
IPAACA_HEADER_EXPORT void call_iu_event_handlers(boost::shared_ptr<IUInterface> iu, bool local, IUEventType event_type, const std::string& category);
public:
IPAACA_HEADER_EXPORT virtual inline ~Buffer() { }
IPAACA_HEADER_EXPORT inline const std::string& unique_name() { return _unique_name; }
IPAACA_HEADER_EXPORT void register_handler(IUEventHandlerFunction function, IUEventType event_mask, const std::set<std::string>& categories);
IPAACA_HEADER_EXPORT void register_handler(IUEventHandlerFunction function, IUEventType event_mask = IU_ALL_EVENTS, const std::string& category="");
//_IPAACA_ABSTRACT_ virtual void add(boost::shared_ptr<IUInterface> iu) = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual boost::shared_ptr<IUInterface> get(const std::string& iu_uid) = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual std::set<boost::shared_ptr<IUInterface> > get_ius() = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") = 0;
IPAACA_HEADER_EXPORT void _allocate_unique_name(const std::string& basename, const std::string& function);
IPAACA_HEADER_EXPORT inline Buffer(const std::string& basename, const std::string& function) {
_allocate_unique_name(basename, function);
_channel = __ipaaca_static_option_default_channel;
}
IPAACA_HEADER_EXPORT void call_iu_event_handlers(std::shared_ptr<IUInterface> iu, bool local, IUEventType event_type, const std::string& category);
public:
IPAACA_HEADER_EXPORT virtual inline ~Buffer() { }
IPAACA_HEADER_EXPORT inline const std::string& unique_name() { return _unique_name; }
/** \brief Register a user-specified handler for IU events. Unless specified, it triggers for all event types for all category interests of the buffer.
*
* \param function A function [object] that can be converted to #IUEventHandlerFunction (examples below)
* \param event_mask Which event types to relay to the user (default: all)
* \param category The category to filter for (default: do not filter)
*
* \b Examples:
*
* Adding a plain function as a handler:<br/>
* <pre>
* void global_iu_handler(IUInterface::ptr iu, IUEventType type, bool local) { do_something(); }
* ...
* int main() {
* OutputBuffer::ptr outbuf = OutputBuffer::create("mybufname");
* outbuf->register_handler(global_iu_handler);
* ...
* }
* </pre>
*
* Adding a class member as a handler (using macro or std::bind):<br/>
* <pre>
* class MyClass {
* protected:
* void my_internal_iu_handler(IUInterface::ptr iu, #IUEventType type, bool local) { do_something(); }
* InputBuffer::ptr inbuf;
* public:
* MyClass() {
* inbuf = InputBuffer::create("bufname", "categoryInterest");
* // Using the macro may protect you against future code adaptations:
* inbuf->register_handler(IPAACA_BIND_CLASS_HANDLER(&MyClass::my_internal_iu_handler, this));
* // it is currently identical to:
* // inbuf->register_handler(std::bind(&MyClass::my_internal_iu_handler, this, \
* std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
* }
* };
* </pre>
*
* Adding a lambda function as a handler (C++11):<br/>
* <pre>
* inbuf->register_handler([](IUInterface::ptr iu, #IUEventType event_type, bool local) {
* do_something();
* });
* </pre>
*
*/
IPAACA_HEADER_EXPORT void register_handler(IUEventHandlerFunction function, IUEventType event_mask = IU_ALL_EVENTS, const std::string& category="");
/// This version of register_handler takes a set of several category interests instead of just one.
IPAACA_HEADER_EXPORT void register_handler(IUEventHandlerFunction function, IUEventType event_mask, const std::set<std::string>& categories);
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual std::shared_ptr<IUInterface> get(const std::string& iu_uid) = 0;
IPAACA_HEADER_EXPORT _IPAACA_ABSTRACT_ virtual std::set<std::shared_ptr<IUInterface> > get_ius() = 0;
IPAACA_HEADER_EXPORT inline const std::string& channel() { return _channel; }
};
//}}}
IPAACA_HEADER_EXPORT inline const std::string& channel() { return _channel; }
};
//}}}
IPAACA_HEADER_EXPORT class OutputBuffer: public Buffer { //, public boost::enable_shared_from_this<OutputBuffer> {//{{{
friend class IU;
friend class RemotePushIU;
friend class OutputBufferRsbAdaptor;
protected:
protected:
//OutputBufferRsbAdaptor _rsb;
IPAACA_MEMBER_VAR_EXPORT IUStore _iu_store;
IPAACA_MEMBER_VAR_EXPORT Lock _iu_id_counter_lock;
/**
* \brief A buffer to which own IUs can be added to publish them
*
* Use #OutputBuffer::create to obtain a smart pointer to a new output buffer.
*
* Use #OutputBuffer::add to add (= publish) an IU.
*
* Use #OutputBuffer::remove to remove (= retract) an IU.
*
* Use #Buffer::register_handler to register a handler that will respond to remote changes to own published IUs.
*/
class OutputBuffer: public Buffer {
friend class IU;
friend class RemotePushIU;
friend class ipaaca::backend::LocalServer;
protected:
protected:
IPAACA_MEMBER_VAR_EXPORT IUStore _iu_store;
IPAACA_MEMBER_VAR_EXPORT Lock _iu_id_counter_lock;
#ifdef IPAACA_EXPOSE_FULL_RSB_API
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, rsb::Informer<rsb::AnyType>::Ptr> _informer_store;
IPAACA_MEMBER_VAR_EXPORT rsb::patterns::ServerPtr _server;
IPAACA_HEADER_EXPORT rsb::Informer<rsb::AnyType>::Ptr _get_informer(const std::string& category);
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, ipaaca::backend::Informer::ptr> _informer_store;
IPAACA_MEMBER_VAR_EXPORT ipaaca::backend::LocalServer::ptr _server;
IPAACA_HEADER_EXPORT ipaaca::backend::Informer::ptr _get_informer(const std::string& category);
#endif
protected:
// informing functions
IPAACA_HEADER_EXPORT void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT void _publish_iu_resend(boost::shared_ptr<IU> iu, const std::string& hidden_scope_name) _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name) _IPAACA_OVERRIDE_;
//IPAACA_HEADER_EXPORT void _send_iu_resendrequest(IUInterface* iu, revision_t revision, const std::string& writer_name);
// remote access functions
// _remote_update_links(IULinkUpdate)
// _remote_update_payload(IUPayloadUpdate)
// _remote_commit(protobuf::IUCommission)
IPAACA_HEADER_EXPORT void _publish_iu(boost::shared_ptr<IU> iu);
IPAACA_HEADER_EXPORT void _retract_iu(boost::shared_ptr<IU> iu);
protected:
IPAACA_HEADER_EXPORT OutputBuffer(const std::string& basename, const std::string& channel="default");
IPAACA_HEADER_EXPORT void _initialize_server();
public:
IPAACA_HEADER_EXPORT static boost::shared_ptr<OutputBuffer> create(const std::string& basename);
IPAACA_HEADER_EXPORT ~OutputBuffer() {
IPAACA_IMPLEMENT_ME
}
IPAACA_HEADER_EXPORT void add(boost::shared_ptr<IU> iu);
IPAACA_HEADER_EXPORT boost::shared_ptr<IU> remove(const std::string& iu_uid);
IPAACA_HEADER_EXPORT boost::shared_ptr<IU> remove(boost::shared_ptr<IU> iu);
IPAACA_HEADER_EXPORT boost::shared_ptr<IUInterface> get(const std::string& iu_uid) _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT std::set<boost::shared_ptr<IUInterface> > get_ius() _IPAACA_OVERRIDE_;
typedef boost::shared_ptr<OutputBuffer> ptr;
};
//}}}
protected:
IPAACA_HEADER_EXPORT void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT void _publish_iu_resend(std::shared_ptr<IU> iu, const std::string& hidden_scope_name) _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name) _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT void _publish_iu(std::shared_ptr<IU> iu);
/// mark and send IU retraction on own IU (removal from buffer is in remove(IU))
IPAACA_HEADER_EXPORT void _retract_iu(std::shared_ptr<IU> iu);
/// mark and send retraction for all unretracted IUs (without removal, used in ~OutputBuffer)
IPAACA_HEADER_EXPORT void _retract_all_internal();
protected:
/// \b Note: constructor is protected. Use create()
IPAACA_HEADER_EXPORT OutputBuffer(const std::string& basename, const std::string& channel=""); // empty string auto-replaced with __ipaaca_static_option_default_channel
IPAACA_HEADER_EXPORT void _initialize_server();
public:
IPAACA_HEADER_EXPORT static std::shared_ptr<OutputBuffer> create(const std::string& basename);
/// OutputBuffer destructor will retract all IUs that are still live
IPAACA_HEADER_EXPORT ~OutputBuffer();
IPAACA_HEADER_EXPORT void add(std::shared_ptr<IU> iu);
IPAACA_HEADER_EXPORT std::shared_ptr<IU> remove(const std::string& iu_uid);
IPAACA_HEADER_EXPORT std::shared_ptr<IU> remove(std::shared_ptr<IU> iu);
IPAACA_HEADER_EXPORT std::shared_ptr<IUInterface> get(const std::string& iu_uid) _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT std::set<std::shared_ptr<IUInterface> > get_ius() _IPAACA_OVERRIDE_;
typedef std::shared_ptr<OutputBuffer> ptr;
};
//}}}
IPAACA_HEADER_EXPORT class InputBuffer: public Buffer { //, public boost::enable_shared_from_this<InputBuffer> {//{{{
friend class IU;
friend class RemotePushIU;
friend class InputBufferRsbAdaptor;
//InputBufferRsbAdaptor _rsb;
/**
* \brief A buffer in which remote IUs (and changes to them) are received.
*
* Use InputBuffer::create() to obtain a smart pointer to a new input buffer.
*
* Set category interests (IU filter) via the different versions of create().
*
* Use Buffer::register_handler() to register a handler that will respond to relevant remote IUs.
*/
class InputBuffer: public Buffer {
friend class IU;
friend class RemotePushIU;
friend class ipaaca::backend::Listener;
#ifdef IPAACA_EXPOSE_FULL_RSB_API
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, rsb::ListenerPtr> _listener_store;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, rsb::patterns::RemoteServerPtr> _remote_server_store;
IPAACA_MEMBER_VAR_EXPORT RemotePushIUStore _iu_store; // TODO genericize
IPAACA_HEADER_EXPORT rsb::patterns::RemoteServerPtr _get_remote_server(const std::string& unique_server_name);
IPAACA_HEADER_EXPORT rsb::ListenerPtr _create_category_listener_if_needed(const std::string& category);
IPAACA_HEADER_EXPORT void _handle_iu_events(rsb::EventPtr event);
IPAACA_HEADER_EXPORT void _trigger_resend_request(rsb::EventPtr event);
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, ipaaca::backend::Listener::ptr> _listener_store;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, ipaaca::backend::RemoteServer::ptr> _remote_server_store;
IPAACA_MEMBER_VAR_EXPORT RemotePushIUStore _iu_store;
IPAACA_HEADER_EXPORT ipaaca::backend::RemoteServer::ptr _get_remote_server(const std::string& unique_server_name);
IPAACA_HEADER_EXPORT ipaaca::backend::Listener::ptr _create_category_listener_if_needed(const std::string& category);
IPAACA_HEADER_EXPORT void _handle_iu_events(ipaaca::backend::Event::ptr event);
IPAACA_HEADER_EXPORT void _trigger_resend_request(ipaaca::backend::Event::ptr event);
#endif
protected:
IPAACA_HEADER_EXPORT inline void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_link_update() should never be invoked")
}
IPAACA_HEADER_EXPORT inline void _publish_iu_resend(boost::shared_ptr<IU> iu, const std::string& hidden_scope_name) _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_publish_iu_resend() should never be invoked")
}
IPAACA_HEADER_EXPORT inline void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_payload_update() should never be invoked")
}
IPAACA_HEADER_EXPORT inline void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_commission() should never be invoked")
}
/*IPAACA_HEADER_EXPORT inline void _send_iu_resendrequest(IUInterface* iu, revision_t revision, const std::string& writer_name="undef")
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_resendrequest() should never be invoked")
}*/
protected:
IPAACA_HEADER_EXPORT InputBuffer(const BufferConfiguration& bufferconfiguration);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::set<std::string>& category_interests);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::vector<std::string>& category_interests);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3, const std::string& category_interest4);
protected:
IPAACA_HEADER_EXPORT inline void _send_iu_link_update(IUInterface* iu, bool is_delta, revision_t revision, const LinkMap& new_links, const LinkMap& links_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_link_update() should never be invoked")
}
IPAACA_HEADER_EXPORT inline void _publish_iu_resend(std::shared_ptr<IU> iu, const std::string& hidden_scope_name) _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_publish_iu_resend() should never be invoked")
}
IPAACA_HEADER_EXPORT inline void _send_iu_payload_update(IUInterface* iu, bool is_delta, revision_t revision, const std::map<std::string, PayloadDocumentEntry::ptr>& new_items, const std::vector<std::string>& keys_to_remove, const std::string& writer_name="undef") _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_payload_update() should never be invoked")
}
IPAACA_HEADER_EXPORT inline void _send_iu_commission(IUInterface* iu, revision_t revision, const std::string& writer_name="undef") _IPAACA_OVERRIDE_
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_commission() should never be invoked")
}
/*IPAACA_HEADER_EXPORT inline void _send_iu_resendrequest(IUInterface* iu, revision_t revision, const std::string& writer_name="undef")
{
IPAACA_WARNING("(ERROR) InputBuffer::_send_iu_resendrequest() should never be invoked")
}*/
protected:
/// \b Note: all constructors are protected. Use create()
IPAACA_HEADER_EXPORT InputBuffer(const BufferConfiguration& bufferconfiguration);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::set<std::string>& category_interests);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::vector<std::string>& category_interests);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3);
IPAACA_HEADER_EXPORT InputBuffer(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3, const std::string& category_interest4);
IPAACA_MEMBER_VAR_EXPORT bool triggerResend;
IPAACA_MEMBER_VAR_EXPORT bool triggerResend;
public:
IPAACA_HEADER_EXPORT void set_resend(bool resendActive);
IPAACA_HEADER_EXPORT bool get_resend();
IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const BufferConfiguration& bufferconfiguration);
IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::set<std::string>& category_interests);
IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::vector<std::string>& category_interests);
IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1);
IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2);
IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3);
IPAACA_HEADER_EXPORT static boost::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3, const std::string& category_interest4);
IPAACA_HEADER_EXPORT ~InputBuffer() {
IPAACA_IMPLEMENT_ME
}
IPAACA_HEADER_EXPORT boost::shared_ptr<IUInterface> get(const std::string& iu_uid) _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT std::set<boost::shared_ptr<IUInterface> > get_ius() _IPAACA_OVERRIDE_;
typedef boost::shared_ptr<InputBuffer> ptr;
};
//}}}
public:
/// Specify whether old but previously unseen IUs should be requested to be sent to the buffer over a hidden channel.
IPAACA_HEADER_EXPORT void set_resend(bool resendActive);
IPAACA_HEADER_EXPORT bool get_resend();
/// Create InputBuffer according to configuration in BufferConfiguration object
IPAACA_HEADER_EXPORT static std::shared_ptr<InputBuffer> create(const BufferConfiguration& bufferconfiguration);
/// Create InputBuffer from name and set of category interests
IPAACA_HEADER_EXPORT static std::shared_ptr<InputBuffer> create(const std::string& basename, const std::set<std::string>& category_interests);
/// Create InputBuffer from name and vector of category interests
IPAACA_HEADER_EXPORT static std::shared_ptr<InputBuffer> create(const std::string& basename, const std::vector<std::string>& category_interests);
/// Convenience function: create InputBuffer from name and one category interest
IPAACA_HEADER_EXPORT static std::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1);
/// Convenience function: create InputBuffer from name and two category interests [DEPRECATED]
[[deprecated("Use create(string, set<string>) instead")]]
IPAACA_HEADER_EXPORT static std::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2);
/// Convenience function: create InputBuffer from name and three category interests [DEPRECATED]
[[deprecated("Use create(string, set<string>) instead")]]
IPAACA_HEADER_EXPORT static std::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3);
/// Convenience function: create InputBuffer from name and four category interests [DEPRECATED]
[[deprecated("Use create(string, set<string>) instead")]]
IPAACA_HEADER_EXPORT static std::shared_ptr<InputBuffer> create(const std::string& basename, const std::string& category_interest1, const std::string& category_interest2, const std::string& category_interest3, const std::string& category_interest4);
IPAACA_HEADER_EXPORT ~InputBuffer() {
IPAACA_IMPLEMENT_ME
}
IPAACA_HEADER_EXPORT std::shared_ptr<IUInterface> get(const std::string& iu_uid) _IPAACA_OVERRIDE_;
IPAACA_HEADER_EXPORT std::set<std::shared_ptr<IUInterface> > get_ius() _IPAACA_OVERRIDE_;
typedef std::shared_ptr<InputBuffer> ptr;
};
//}}}
IPAACA_HEADER_EXPORT class IUPayloadUpdate {//{{{
public:
IPAACA_MEMBER_VAR_EXPORT std::string uid;
IPAACA_MEMBER_VAR_EXPORT revision_t revision;
IPAACA_MEMBER_VAR_EXPORT std::string writer_name;
IPAACA_MEMBER_VAR_EXPORT bool is_delta;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, PayloadDocumentEntry::ptr> new_items;
IPAACA_MEMBER_VAR_EXPORT std::vector<std::string> keys_to_remove;
friend std::ostream& operator<<(std::ostream& os, const IUPayloadUpdate& obj);
typedef boost::shared_ptr<IUPayloadUpdate> ptr;
};//}}}
/// Internal, transport-independent, representation of payload updates
class IUPayloadUpdate {//{{{
public:
IPAACA_MEMBER_VAR_EXPORT std::string uid;
IPAACA_MEMBER_VAR_EXPORT revision_t revision;
IPAACA_MEMBER_VAR_EXPORT std::string writer_name;
IPAACA_MEMBER_VAR_EXPORT bool is_delta;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, PayloadDocumentEntry::ptr> new_items;
IPAACA_MEMBER_VAR_EXPORT std::vector<std::string> keys_to_remove;
IPAACA_MEMBER_VAR_EXPORT std::string payload_type; // to handle legacy mode
IPAACA_MEMBER_VAR_EXPORT std::string request_uid; // for lightweight back-ends
IPAACA_MEMBER_VAR_EXPORT std::string request_endpoint; // for lightweight back-ends
friend std::ostream& operator<<(std::ostream& os, const IUPayloadUpdate& obj);
typedef std::shared_ptr<IUPayloadUpdate> ptr;
};//}}}
IPAACA_HEADER_EXPORT class IULinkUpdate {//{{{
public:
IPAACA_MEMBER_VAR_EXPORT std::string uid;
IPAACA_MEMBER_VAR_EXPORT revision_t revision;
IPAACA_MEMBER_VAR_EXPORT std::string writer_name;
IPAACA_MEMBER_VAR_EXPORT bool is_delta;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::set<std::string> > new_links;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::set<std::string> > links_to_remove;
friend std::ostream& operator<<(std::ostream& os, const IULinkUpdate& obj);
typedef boost::shared_ptr<IULinkUpdate> ptr;
};//}}}
/// Internal, transport-independent, representation of link updates
class IULinkUpdate {//{{{
public:
IPAACA_MEMBER_VAR_EXPORT std::string uid;
IPAACA_MEMBER_VAR_EXPORT revision_t revision;
IPAACA_MEMBER_VAR_EXPORT std::string writer_name;
IPAACA_MEMBER_VAR_EXPORT bool is_delta;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::set<std::string> > new_links;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::set<std::string> > links_to_remove;
IPAACA_MEMBER_VAR_EXPORT std::string request_uid; // for lightweight back-ends
IPAACA_MEMBER_VAR_EXPORT std::string request_endpoint; // for lightweight back-ends
friend std::ostream& operator<<(std::ostream& os, const IULinkUpdate& obj);
typedef std::shared_ptr<IULinkUpdate> ptr;
};//}}}
#endif
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-cmdline_parser.h
*
* \brief Header file for basic command line parser
*
* Users should not include this file directly, but use ipaaca.h
*
* \author Ramin Yaghoubzadeh (ryaghoubzadeh@uni-bielefeld.de)
* \date February, 2019
*/
#ifndef __ipaaca_cmdline_parser_h_INCLUDED__
#define __ipaaca_cmdline_parser_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
// in ipaaca-cmdline-parser.cc
// additional misc classes ( Command line options )//{{{
/** \brief Command line argument container for CommandLineParser
*
* Contains the results of argument parsing from CommandLineParser::parse()
*
* The parser is preconfigured to handle some standard options:
*
* Option | Function
* --------------------------------|------------------------------------------------------------------------------
* --help | Print list of available options
* --verbose | Set verbose flag
* --character-name <name> | Set character name (legacy)
* --component-name <name> | Set component name (legacy)
* --ipaaca-payload-type <type> | Set default ipaaca payload type (default JSON, set STR for legacy protocol)
* --ipaaca-default-channel <name> | Set default channel name (default 'default')
* --ipaaca-enable-logging <level> | Set console log level, one of NONE, DEBUG, INFO, WARNING, ERROR, CRITICAL
* --rsb-enable-logging <level> | Set rsb (transport) log level
*
*/
class CommandLineOptions {
public:
IPAACA_HEADER_EXPORT inline CommandLineOptions()
{ }
IPAACA_HEADER_EXPORT inline ~CommandLineOptions() {
}
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::string> param_opts;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, bool> param_set;
public:
IPAACA_HEADER_EXPORT void set_option(const std::string& name, bool expect, const char* optarg);
/// Get the option argument or default value (if the option expected an argument)
IPAACA_HEADER_EXPORT std::string get_param(const std::string& o);
/// Check whether option has been set
IPAACA_HEADER_EXPORT bool is_set(const std::string& o);
IPAACA_HEADER_EXPORT void dump();
public:
typedef std::shared_ptr<CommandLineOptions> ptr;
};
/**
* \brief Command line parser for ipaaca programs.
*
* The parser is preconfigured to handle some standard options:
*
* Option | Function
* --------------------------------|------------------------------------------------------------------------------
* --help | Print list of available options
* --verbose | Set verbose flag
* --character-name <name> | Set character name (legacy)
* --component-name <name> | Set component name (legacy)
* --ipaaca-payload-type <type> | Set default ipaaca payload type (default JSON, set STR for legacy protocol)
* --ipaaca-default-channel <name> | Set default channel name (default 'default')
* --ipaaca-enable-logging <level> | Set console log level, one of NONE, DEBUG, INFO, WARNING, ERROR, CRITICAL
* --rsb-enable-logging <level> | Set rsb (transport) log level
*
*/
class CommandLineParser {
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<char, std::string> longopt; // letter->name
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, char> shortopt; // letter->name
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, bool> options; // name / expect_param
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::string> defaults; // for opt params
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, int> set_flag; // for paramless opts
protected:
IPAACA_HEADER_EXPORT CommandLineParser();
IPAACA_MEMBER_VAR_EXPORT bool library_options_handled;
IPAACA_HEADER_EXPORT bool consume_library_option(const std::string& name, bool expect, const char* optarg);
IPAACA_HEADER_EXPORT void ensure_defaults_in( CommandLineOptions::ptr clo );
public:
IPAACA_HEADER_EXPORT inline ~CommandLineParser() { }
/// Create a new parser object reference.
IPAACA_HEADER_EXPORT static inline std::shared_ptr<CommandLineParser> create() {
return std::shared_ptr<CommandLineParser>(new CommandLineParser());
}
IPAACA_HEADER_EXPORT void initialize_parser_defaults();
IPAACA_HEADER_EXPORT void dump_options();
/** \brief Add a user-defined option
*
* \param optname The long option name, e.g. verbose for --verbose
* \param shortn The short option (or \0 for none)
* \param expect_param Whether an argument is expected for the option
* \param defaultv The default string value (unused if expect_param is false)
*/
IPAACA_HEADER_EXPORT void add_option(const std::string& optname, char shortn, bool expect_param, const std::string& defaultv);
/** \brief Parse argument list and return result.
*
* Parse argument list (e.g. from main()) with the parser, consuming the internal options.
* The remaining options are packaged into a CommandLineOptions object.
*/
IPAACA_HEADER_EXPORT CommandLineOptions::ptr parse(int argc, char* const* argv);
public:
typedef std::shared_ptr<CommandLineParser> ptr;
};
//}}}
#endif
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-backend.h
*
* \brief Header file for abstract backend participant implementation
* (used in the core library and as a base to derive specific backends).
*
* Users should not include this file directly, but use ipaaca.h
*
* \b Note: This file is only included during compilation of ipaaca,
* for regular use, the full internal API is not exposed.
* Users generally need never touch the internal transport layer.
*
* \author Ramin Yaghoubzadeh Torky (ryaghoubzadeh@uni-bielefeld.de)
* \date December, 2018
*/
#ifndef __ipaaca_config_h_INCLUDED__
#define __ipaaca_config_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
class Config {
public:
typedef std::shared_ptr<Config> ptr;
protected:
std::map<std::string, std::string> _data;
std::set<std::string> _messages_delivered;
template<typename T> T get_with_default_internal(const std::string& key, T const& default_value, bool warn);
template<typename T> void config_key_not_found(const std::string& key, T const& default_value, bool warn)
{
if (!_messages_delivered.count(key)) {
if (warn) { IPAACA_WARNING("Config: no key '" << key << "', using default value " << default_value) }
else { IPAACA_DEBUG("Config: no key '" << key << "', using default value " << default_value) }
_messages_delivered.insert(key);
}
}
template<typename T> void config_conversion_failed(const std::string& key, T const& default_value)
{
if (!_messages_delivered.count(key)) {
IPAACA_WARNING("Config: failed conversion for key '" << key << "', using default value " << default_value)
_messages_delivered.insert(key);
}
}
bool get_key_and_value(const std::string& line, std::string& key, std::string& value);
public:
inline std::map<std::string, std::string>::const_iterator data_cbegin() const { return _data.begin(); }
inline std::map<std::string, std::string>::const_iterator data_cend() const { return _data.end(); }
void populate_from_global_sources();
void populate_from_environment();
void populate_from_any_conf_files();
void populate_from_conf_file(std::fstream& fs);
template<typename T> T get_with_default(const std::string& key, T const& default_value) {
return get_with_default_internal(key, default_value, false);
}
template<typename T> T get_with_default_and_warning(const std::string& key, T const& default_value) {
return get_with_default_internal(key, default_value, true);
}
//inline std::map<std::string, std::string>::iterator begin() { return std::map<std::string, std::string>::begin(); }
//inline std::map<std::string, std::string>::iterator end() { return std::map<std::string, std::string>::end(); }
};
Config::ptr get_global_config(bool auto_parse_on_demand=true);
#endif
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-internal.h
*
* \brief Header file for internal transport implementation (RSB).
*
* Users should not include this file directly, but use ipaaca.h
*
* \b Note: This file is only included during compilation of ipaaca,
* for regular use, the full internal API is not exposed.
* Users generally need never touch the internal transport layer.
*
* The file provides callback glue from RSB, and wire converters
* for the respective ipaaca classes.
*
* \author Ramin Yaghoubzadeh (ryaghoubzadeh@uni-bielefeld.de)
* \date March, 2015
*/
#ifndef __ipaaca_converters_h_INCLUDED__
#define __ipaaca_converters_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
namespace converters {
// Wrap a serialized inner object and a wire type in a protobuf::TransportLevelWrapper
std::string cooked_message(const std::string& raw_message, ipaaca::protobuf::TransportMessageType msg_type);
// protobuf serialization for all supported types (replaces converter repository)
std::string internal_serialize(std::shared_ptr<ipaaca::IU> iu);
//std::string internal_serialize(std::shared_ptr<ipaaca::Message> msg);
std::string internal_serialize(std::shared_ptr<ipaaca::IUPayloadUpdate> pup);
std::string internal_serialize(std::shared_ptr<ipaaca::IULinkUpdate> lup);
std::string internal_serialize(std::shared_ptr<protobuf::RemoteRequestResult> pb);
std::string internal_serialize(std::shared_ptr<protobuf::IURetraction> pb);
std::string internal_serialize(std::shared_ptr<protobuf::IUCommission> pb);
std::string internal_serialize(std::shared_ptr<protobuf::IUResendRequest> pb);
std::string internal_serialize(std::shared_ptr<protobuf::IUPayloadUpdateRequest> pb);
std::string internal_serialize(std::shared_ptr<protobuf::IULinkUpdateRequest> pb);
std::string internal_serialize(std::shared_ptr<protobuf::IUCommissionRequest> pb);
// deserialization (just switching here instead of the converter registry business)
std::shared_ptr<ipaaca::backend::Event> internal_deserialize(const std::string& wire);
class IUConverter {//{{{
public:
IPAACA_HEADER_EXPORT static std::string serialize(std::shared_ptr<ipaaca::IU> iu); // const rsb::AnnotatedData& data, std::string& wire);
IPAACA_HEADER_EXPORT static std::shared_ptr<ipaaca::IUInterface> deserialize(const std::string& wire);
};//}}}
/*
IPAACA_HEADER_EXPORT class MessageConverter {//{{{
public:
IPAACA_HEADER_EXPORT static std::string serialize(std::shared_ptr<ipaaca::Message> msg); // const rsb::AnnotatedData& data, std::string& wire);
IPAACA_HEADER_EXPORT static std::shared_ptr<ipaaca::RemoteMessage> deserialize(const std::string& wire);
};//}}}
*/
class IUPayloadUpdateConverter {//{{{
public:
IPAACA_HEADER_EXPORT static std::string serialize(std::shared_ptr<ipaaca::IUPayloadUpdate> pup); // const rsb::AnnotatedData& data, std::string& wire);
IPAACA_HEADER_EXPORT static std::shared_ptr<ipaaca::IUPayloadUpdate> deserialize(const std::string& wire);
};//}}}
class IULinkUpdateConverter {//{{{
public:
IPAACA_HEADER_EXPORT static std::string serialize(std::shared_ptr<ipaaca::IULinkUpdate> lup); // const rsb::AnnotatedData& data, std::string& wire);
IPAACA_HEADER_EXPORT static std::shared_ptr<ipaaca::IULinkUpdate> deserialize(const std::string& wire);
};//}}}
} // of namespace converters
#endif // __ipaaca_converters_h_INCLUDED__
......@@ -3,7 +3,7 @@
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2015 Social Cognitive Systems Group
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
......@@ -31,6 +31,17 @@
* Excellence Initiative.
*/
/**
* \file ipaaca-definitions.h
*
* \brief Header file for data and exception types and helper functions.
*
* Users should not include this file directly, but use ipaaca.h
*
* \author Ramin Yaghoubzadeh (ryaghoubzadeh@uni-bielefeld.de)
* \date March, 2015
*/
#ifndef __ipaaca_definitions_h_INCLUDED__
#define __ipaaca_definitions_h_INCLUDED__
......@@ -38,12 +49,9 @@
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
// LAST FIXME LAST
//typedef boost::shared_ptr<rapidjson::Document> JsonDocPtr;
typedef uint32_t revision_t;
/// Type of the IU event. Realized as an integer to enable bit masks for filters.
/// Type of the IU event. Realized as an integer to enable bit masks for filters. One of: IU_ADDED, IU_COMMITTED, IU_DELETED, IU_RETRACTED, IU_UPDATED, IU_LINKSUPDATED, IU_MESSAGE
typedef uint32_t IUEventType;
#define IU_ADDED 1
#define IU_COMMITTED 2
......@@ -52,9 +60,17 @@ typedef uint32_t IUEventType;
#define IU_UPDATED 16
#define IU_LINKSUPDATED 32
#define IU_MESSAGE 64
/// Bit mask for receiving all events
/// Bit mask for receiving all IU events \see IUEventType
#define IU_ALL_EVENTS 127
/// Ipaaca (console) log levels
#define IPAACA_LOG_LEVEL_NONE 0
#define IPAACA_LOG_LEVEL_CRITICAL 1
#define IPAACA_LOG_LEVEL_ERROR 2
#define IPAACA_LOG_LEVEL_WARNING 3
#define IPAACA_LOG_LEVEL_INFO 4
#define IPAACA_LOG_LEVEL_DEBUG 5
/// Convert an int event type to a human-readable string
IPAACA_HEADER_EXPORT inline std::string iu_event_type_to_str(IUEventType type)
{
......@@ -70,8 +86,8 @@ IPAACA_HEADER_EXPORT inline std::string iu_event_type_to_str(IUEventType type)
}
}
/// IU access mode: PUSH means that updates are broadcast; REMOTE means that reads are RPC calls; MESSAGE means a fire-and-forget message
IPAACA_HEADER_EXPORT enum IUAccessMode {
/// IU access mode: PUSH means that updates are broadcast; REMOTE means that reads are RPC calls (currently NOT implemented); MESSAGE means a fire-and-forget message
enum IUAccessMode {
IU_ACCESS_PUSH,
IU_ACCESS_REMOTE,
IU_ACCESS_MESSAGE
......@@ -80,208 +96,4 @@ IPAACA_HEADER_EXPORT enum IUAccessMode {
/// generate a UUID as an ASCII string
IPAACA_HEADER_EXPORT std::string generate_uuid_string();
/*
* Exceptions and errors
*/
IPAACA_HEADER_EXPORT class Exception: public std::exception//{{{
{
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _description;
public:
IPAACA_HEADER_EXPORT inline Exception(const std::string& description=""): _description(description) { }
IPAACA_HEADER_EXPORT inline ~Exception() throw() { }
IPAACA_HEADER_EXPORT const char* what() const throw() {
return _description.c_str();
}
};//}}}
IPAACA_HEADER_EXPORT class Abort: public std::exception//{{{
{
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _description;
public:
IPAACA_HEADER_EXPORT inline Abort(const std::string& description=""): _description(description) { }
IPAACA_HEADER_EXPORT inline ~Abort() throw() { }
IPAACA_HEADER_EXPORT const char* what() const throw() {
return _description.c_str();
}
};//}}}
IPAACA_HEADER_EXPORT class IUNotFoundError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUNotFoundError() throw() { }
IPAACA_HEADER_EXPORT inline IUNotFoundError() { //boost::shared_ptr<IU> iu) {
_description = "IUNotFoundError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUPublishedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUPublishedError() throw() { }
IPAACA_HEADER_EXPORT inline IUPublishedError() { //boost::shared_ptr<IU> iu) {
_description = "IUPublishedError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUCommittedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUCommittedError() throw() { }
IPAACA_HEADER_EXPORT inline IUCommittedError() { //boost::shared_ptr<IU> iu) {
_description = "IUCommittedError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUUpdateFailedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUUpdateFailedError() throw() { }
IPAACA_HEADER_EXPORT inline IUUpdateFailedError() { //boost::shared_ptr<IU> iu) {
_description = "IUUpdateFailedError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUResendRequestFailedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUResendRequestFailedError() throw() { }
IPAACA_HEADER_EXPORT inline IUResendRequestFailedError() { //boost::shared_ptr<IU> iu) {
_description = "IUResendRequestFailedError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUReadOnlyError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUReadOnlyError() throw() { }
IPAACA_HEADER_EXPORT inline IUReadOnlyError() { //boost::shared_ptr<IU> iu) {
_description = "IUReadOnlyError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUAlreadyInABufferError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUAlreadyInABufferError() throw() { }
IPAACA_HEADER_EXPORT inline IUAlreadyInABufferError() { //boost::shared_ptr<IU> iu) {
_description = "IUAlreadyInABufferError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUUnpublishedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUUnpublishedError() throw() { }
IPAACA_HEADER_EXPORT inline IUUnpublishedError() { //boost::shared_ptr<IU> iu) {
_description = "IUUnpublishedError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUAlreadyHasAnUIDError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUAlreadyHasAnUIDError() throw() { }
IPAACA_HEADER_EXPORT inline IUAlreadyHasAnUIDError() { //boost::shared_ptr<IU> iu) {
_description = "IUAlreadyHasAnUIDError";
}
};//}}}
IPAACA_HEADER_EXPORT class IUAlreadyHasAnOwnerNameError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUAlreadyHasAnOwnerNameError() throw() { }
IPAACA_HEADER_EXPORT inline IUAlreadyHasAnOwnerNameError() { //boost::shared_ptr<IU> iu) {
_description = "IUAlreadyHasAnOwnerNameError";
}
};//}}}
IPAACA_HEADER_EXPORT class UUIDGenerationError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~UUIDGenerationError() throw() { }
IPAACA_HEADER_EXPORT inline UUIDGenerationError() { //boost::shared_ptr<IU> iu) {
_description = "UUIDGenerationError";
}
};//}}}
IPAACA_HEADER_EXPORT class NotImplementedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~NotImplementedError() throw() { }
IPAACA_HEADER_EXPORT inline NotImplementedError() { //boost::shared_ptr<IU> iu) {
_description = "NotImplementedError";
}
};//}}}
IPAACA_HEADER_EXPORT class PayloadAddressingError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~PayloadAddressingError() throw() { }
IPAACA_HEADER_EXPORT inline PayloadAddressingError() { //boost::shared_ptr<IU> iu) {
_description = "PayloadAddressingError";
}
};//}}}
IPAACA_HEADER_EXPORT class JsonParsingError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~JsonParsingError() throw() { }
IPAACA_HEADER_EXPORT inline JsonParsingError() { //boost::shared_ptr<IU> iu) {
_description = "JsonParsingError";
}
};//}}}
IPAACA_HEADER_EXPORT class PayloadEntryProxyInvalidatedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~PayloadEntryProxyInvalidatedError() throw() { }
IPAACA_HEADER_EXPORT inline PayloadEntryProxyInvalidatedError() { //boost::shared_ptr<IU> iu) {
_description = "PayloadEntryProxyInvalidatedError";
}
};//}}}
/// Static library initialization
IPAACA_HEADER_EXPORT class Initializer
{
public:
IPAACA_HEADER_EXPORT static void initialize_ipaaca_rsb_if_needed();
IPAACA_HEADER_EXPORT static void initialize_updated_default_config();
IPAACA_HEADER_EXPORT static bool initialized();
IPAACA_HEADER_EXPORT static void dump_current_default_config();
protected:
IPAACA_MEMBER_VAR_EXPORT static bool _initialized;
};
// in ipaaca-cmdline-parser.cc
// additional misc classes ( Command line options )//{{{
IPAACA_HEADER_EXPORT class CommandLineOptions {
public:
IPAACA_HEADER_EXPORT inline CommandLineOptions() { }
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::string> param_opts;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, bool> param_set;
public:
IPAACA_HEADER_EXPORT void set_option(const std::string& name, bool expect, const char* optarg);
IPAACA_HEADER_EXPORT std::string get_param(const std::string& o);
IPAACA_HEADER_EXPORT bool is_set(const std::string& o);
IPAACA_HEADER_EXPORT void dump();
typedef boost::shared_ptr<CommandLineOptions> ptr;
};
class CommandLineParser {
protected:
IPAACA_MEMBER_VAR_EXPORT std::map<char, std::string> longopt; // letter->name
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, char> shortopt; // letter->name
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, bool> options; // name / expect_param
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::string> defaults; // for opt params
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, int> set_flag; // for paramless opts
protected:
IPAACA_HEADER_EXPORT CommandLineParser();
public:
IPAACA_HEADER_EXPORT inline ~CommandLineParser() { }
IPAACA_HEADER_EXPORT static inline boost::shared_ptr<CommandLineParser> create() {
return boost::shared_ptr<CommandLineParser>(new CommandLineParser());
}
IPAACA_HEADER_EXPORT void initialize_parser_defaults();
IPAACA_HEADER_EXPORT void dump_options();
IPAACA_HEADER_EXPORT void add_option(const std::string& optname, char shortn, bool expect_param, const std::string& defaultv);
IPAACA_HEADER_EXPORT void ensure_defaults_in( CommandLineOptions::ptr clo );
IPAACA_HEADER_EXPORT CommandLineOptions::ptr parse(int argc, char* const* argv);
typedef boost::shared_ptr<CommandLineParser> ptr;
};
//}}}
// in ipaaca-string-utils.cc
// additional misc functions ( String splitting / joining )//{{{
IPAACA_HEADER_EXPORT std::string str_join(const std::set<std::string>& set,const std::string& sep);
IPAACA_HEADER_EXPORT std::string str_join(const std::vector<std::string>& vec,const std::string& sep);
IPAACA_HEADER_EXPORT void str_split_wipe(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters );
IPAACA_HEADER_EXPORT void str_split_append(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters );
//}}}
#endif
/*
* This file is part of IPAACA, the
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2022 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
* http://purl.org/net/ipaaca
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*/
/**
* \file ipaaca-errors.h
*
* \brief Header file for all errors and exceptions
*
* Users should not include this file directly, but use ipaaca.h
*
* \author Ramin Yaghoubzadeh (ryaghoubzadeh@uni-bielefeld.de)
* \date February, 2019
*/
#ifndef __ipaaca_errors_h_INCLUDED__
#define __ipaaca_errors_h_INCLUDED__
#ifndef __ipaaca_h_INCLUDED__
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
/**
* Exception with string description
*/
class Exception: public std::exception//{{{
{
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _description;
public:
IPAACA_HEADER_EXPORT inline Exception(const std::string& description=""): _description(description) { }
IPAACA_HEADER_EXPORT inline ~Exception() throw() { }
IPAACA_HEADER_EXPORT const char* what() const throw() {
return _description.c_str();
}
};//}}}
class Abort: public std::exception//{{{
{
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _description;
public:
IPAACA_HEADER_EXPORT inline Abort(const std::string& description=""): _description(description) { }
IPAACA_HEADER_EXPORT inline ~Abort() throw() { }
IPAACA_HEADER_EXPORT const char* what() const throw() {
return _description.c_str();
}
};//}}}
/// BackEnd failed conditions, e.g. limits
class BackEndBadConditionError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~BackEndBadConditionError() throw() { }
IPAACA_HEADER_EXPORT inline BackEndBadConditionError() { //std::shared_ptr<BackEnd> iu) {
_description = "BackEndBadConditionError";
}
};//}}}
/// BackEnd [hard-]failed to connect a participant
class BackEndConnectionFailedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~BackEndConnectionFailedError() throw() { }
IPAACA_HEADER_EXPORT inline BackEndConnectionFailedError() { //std::shared_ptr<BackEnd> iu) {
_description = "BackEndConnectionFailedError";
}
};//}}}
/// BackEnd not found
class BackEndNotFoundError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~BackEndNotFoundError() throw() { }
IPAACA_HEADER_EXPORT inline BackEndNotFoundError() { //std::shared_ptr<BackEnd> iu) {
_description = "BackEndNotFoundError";
}
};//}}}
/// Unknown wire type encountered
class UnhandledWireTypeError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~UnhandledWireTypeError() throw() { }
IPAACA_HEADER_EXPORT inline UnhandledWireTypeError(int wire_type=-1) {
if (wire_type>0) {
_description = "UnhandledWireTypeError (wire type encountered: " + std::to_string(wire_type) + ")";
} else {
_description = "UnhandledWireTypeError (value not provided)";
}
}
};//}}}
/// IU was not found in a buffer
class IUNotFoundError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUNotFoundError() throw() { }
IPAACA_HEADER_EXPORT inline IUNotFoundError() { //std::shared_ptr<IU> iu) {
_description = "IUNotFoundError";
}
};//}}}
/// IU was already published
class IUPublishedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUPublishedError() throw() { }
IPAACA_HEADER_EXPORT inline IUPublishedError() {
_description = "IUPublishedError";
}
};//}}}
/// IU had already been committed to
class IUCommittedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUCommittedError() throw() { }
IPAACA_HEADER_EXPORT inline IUCommittedError() {
_description = "IUCommittedError";
}
};//}}}
/// IU had already been retracted
class IURetractedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IURetractedError() throw() { }
IPAACA_HEADER_EXPORT inline IURetractedError() {
_description = "IURetractedError";
}
};//}}}
/// Remote IU update failed because it had been modified in the mean time
class IUUpdateFailedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUUpdateFailedError() throw() { }
IPAACA_HEADER_EXPORT inline IUUpdateFailedError() {
_description = "IUUpdateFailedError";
}
};//}}}
/// Requested resend of old IU due to malformed channel specification
class IUResendRequestFailedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUResendRequestFailedError() throw() { }
IPAACA_HEADER_EXPORT inline IUResendRequestFailedError() {
_description = "IUResendRequestFailedError";
}
};//}}}
/// Write operation failed because IU had been set read-only
class IUReadOnlyError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUReadOnlyError() throw() { }
IPAACA_HEADER_EXPORT inline IUReadOnlyError() {
_description = "IUReadOnlyError";
}
};//}}}
/// Buffer::add() failed because the IU had been previously placed in another buffer
class IUAlreadyInABufferError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUAlreadyInABufferError() throw() { }
IPAACA_HEADER_EXPORT inline IUAlreadyInABufferError() {
_description = "IUAlreadyInABufferError";
}
};//}}}
/// A request was made that is only valid for an already published IU
class IUUnpublishedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUUnpublishedError() throw() { }
IPAACA_HEADER_EXPORT inline IUUnpublishedError() {
_description = "IUUnpublishedError";
}
};//}}}
/// IU had already been allocated a UID
class IUAlreadyHasAnUIDError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUAlreadyHasAnUIDError() throw() { }
IPAACA_HEADER_EXPORT inline IUAlreadyHasAnUIDError() {
_description = "IUAlreadyHasAnUIDError";
}
};//}}}
/// IU had already been allocated an owner name
class IUAlreadyHasAnOwnerNameError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~IUAlreadyHasAnOwnerNameError() throw() { }
IPAACA_HEADER_EXPORT inline IUAlreadyHasAnOwnerNameError() {
_description = "IUAlreadyHasAnOwnerNameError";
}
};//}}}
/// UID generation failed (Windows only)
class UUIDGenerationError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~UUIDGenerationError() throw() { }
IPAACA_HEADER_EXPORT inline UUIDGenerationError() {
_description = "UUIDGenerationError";
}
};//}}}
/// Not implemented (e.g. invalid request parameters via backend)
class NotImplementedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~NotImplementedError() throw() { }
IPAACA_HEADER_EXPORT inline NotImplementedError() {
_description = "NotImplementedError";
}
};//}}}
/// PayloadEntryProxy requested type conversion failed (including lenient interpretation)
class PayloadTypeConversionError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~PayloadTypeConversionError() throw() { }
IPAACA_HEADER_EXPORT inline PayloadTypeConversionError() {
_description = "PayloadTypeConversionError";
}
};//}}}
/// PayloadEntryProxy was addressed as list when not a list or as map when not a map
class PayloadAddressingError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~PayloadAddressingError() throw() { }
IPAACA_HEADER_EXPORT inline PayloadAddressingError() {
_description = "PayloadAddressingError";
}
};//}}}
/// Malformed json was received for a Payload
class JsonParsingError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~JsonParsingError() throw() { }
IPAACA_HEADER_EXPORT inline JsonParsingError() {
_description = "JsonParsingError";
}
};//}}}
/// PayloadEntryProxy invalidated (unused)
class PayloadEntryProxyInvalidatedError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~PayloadEntryProxyInvalidatedError() throw() { }
IPAACA_HEADER_EXPORT inline PayloadEntryProxyInvalidatedError() {
_description = "PayloadEntryProxyInvalidatedError";
}
};//}}}
/// Iterator over Payload entries was invalidated by an intermediate IU update operation
class PayloadIteratorInvalidError: public Exception//{{{
{
public:
IPAACA_HEADER_EXPORT inline ~PayloadIteratorInvalidError() throw() { }
IPAACA_HEADER_EXPORT inline PayloadIteratorInvalidError() {
_description = "PayloadIteratorInvalidError";
}
};//}}}
#endif