From: Tomek Mrugalski Date: Thu, 16 Feb 2017 01:15:13 +0000 (+0100) Subject: [5134] Basic example library added. X-Git-Tag: trac5137_base~3^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5041d2119b2385731bc657d34cf612d0c2caf4ba;p=thirdparty%2Fkea.git [5134] Basic example library added. --- diff --git a/src/bin/agent/simple_parser.cc b/src/bin/agent/simple_parser.cc index 9363530aee..de2ed66809 100644 --- a/src/bin/agent/simple_parser.cc +++ b/src/bin/agent/simple_parser.cc @@ -111,6 +111,10 @@ AgentSimpleParser::parse(CtrlAgentCfgContextPtr ctx, isc::data::ConstElementPtr if (hooks) { hooks_parser.parse(hooks); hooks_parser.verifyLibraries(); + + hooks::HookLibsCollection libs; + hooks_parser.getLibraries(libs); + ctx->setLibraries(libs); } if (!check_only) { diff --git a/src/bin/agent/tests/Makefile.am b/src/bin/agent/tests/Makefile.am index 64695e4d0f..56397b053a 100644 --- a/src/bin/agent/tests/Makefile.am +++ b/src/bin/agent/tests/Makefile.am @@ -5,6 +5,8 @@ SHTESTS += ctrl_agent_process_tests.sh noinst_SCRIPTS = ctrl_agent_process_tests.sh +noinst_LTLIBRARIES = libbasic.la + EXTRA_DIST = ctrl_agent_process_tests.sh.in # test using command-line arguments, so use check-local target instead of TESTS @@ -74,6 +76,16 @@ ctrl_agent_unittest_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exception ctrl_agent_unittest_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS) ctrl_agent_unittest_LDADD += $(BOOST_LIBS) $(GTEST_LDADD) + +# The basic callout library - contains standard callouts +libbasic_la_SOURCES = basic_library.cc +libbasic_la_CXXFLAGS = $(AM_CXXFLAGS) +libbasic_la_CPPFLAGS = $(AM_CPPFLAGS) +libbasic_la_LIBADD = $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +libbasic_la_LIBADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +libbasic_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la +libbasic_la_LDFLAGS = -avoid-version -export-dynamic -module -rpath /nowhere + endif noinst_PROGRAMS = $(TESTS) diff --git a/src/bin/agent/tests/basic_library.cc b/src/bin/agent/tests/basic_library.cc new file mode 100644 index 0000000000..f3a44f8506 --- /dev/null +++ b/src/bin/agent/tests/basic_library.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +/// @file +/// @brief Basic callout library +/// +/// This is source of a test library for Control Agent. +/// +/// - Only the "version" framework function is supplied. +/// +/// - hookpt_one callout is supplied. + +#include +#include +#include + +using namespace isc::hooks; +using namespace std; + +namespace { + +extern "C" { + +// Callouts. All return their result through the "result" argument. + +int +context_create(CalloutHandle& handle) { + handle.setContext("result", static_cast(10)); + handle.setArgument("result", static_cast(10)); + return (0); +} + +// First callout adds the passed "integer" argument to the initialized context +// value of 10. (Note that the value set by context_create is accessed through +// context and not the argument, so checking that context is correctly passed +// between callouts in the same library.) + +int +hookpt_one(CalloutHandle& handle) { + int data; + handle.getArgument("integer", data); + + int result; + handle.getArgument("result", result); + + result += data; + handle.setArgument("result", result); + + return (0); +} + +// Framework functions. + +int +version() { + return (KEA_HOOKS_VERSION); +} + +// load() initializes the user library if the main image was statically linked. +int +load(isc::hooks::LibraryHandle&) { +#ifdef USE_STATIC_LINK + hooksStaticLinkInit(); +#endif + return (0); +} + +} +} +