Browse Source

[5134] Basic example library added.

Tomek Mrugalski 8 years ago
parent
commit
5041d2119b

+ 4 - 0
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) {

+ 12 - 0
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)

+ 73 - 0
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 <config.h>
+#include <hooks/hooks.h>
+#include <fstream>
+
+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<int>(10));
+    handle.setArgument("result", static_cast<int>(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);
+}
+
+}
+}
+