From 907f1db9a197eab354dce2fff1007e6b235ff985 Mon Sep 17 00:00:00 2001 From: Jacek Pielaszkiewicz Date: Mon, 21 Jul 2014 17:09:35 +0200 Subject: [PATCH] Extract common/log, common/dbus, common/config directories and create from them libraries. [Bug/Feature] N/A [Cause] N/A [Solution] 1. The following directories have been extracted (removed): - common/log - common/dbus - common/config 2. In place of the removed source code, security-containers is link with the following libraries: - libLogger - libSimpleDbus - libConfig [Verification] Build, install, run tests Change-Id: I9d0b1627638b401bb88e442dd9681a7943fe0b5d Signed-off-by: Jacek Pielaszkiewicz --- common/config/exception.hpp | 51 --- common/config/fields.hpp | 77 ---- common/config/from-json-visitor.hpp | 143 -------- common/config/is-visitable.hpp | 55 --- common/config/manager.hpp | 77 ---- common/config/to-json-visitor.hpp | 124 ------- common/dbus/connection.cpp | 391 --------------------- common/dbus/connection.hpp | 204 ----------- common/dbus/exception.hpp | 81 ----- common/libvirt/connection.cpp | 2 +- common/libvirt/domain.cpp | 2 +- common/libvirt/helpers.cpp | 2 +- common/libvirt/network.cpp | 2 +- common/log/backend-journal.cpp | 72 ---- common/log/backend-journal.hpp | 52 --- common/log/backend-null.hpp | 53 --- common/log/backend-stderr.cpp | 65 ---- common/log/backend-stderr.hpp | 52 --- common/log/backend.hpp | 55 --- common/log/ccolor.cpp | 44 --- common/log/ccolor.hpp | 56 --- common/log/formatter.cpp | 124 ------- common/log/formatter.hpp | 52 --- common/log/level.cpp | 70 ---- common/log/level.hpp | 58 --- common/log/logger.cpp | 86 ----- common/log/logger.hpp | 87 ----- common/utils/callback-guard.cpp | 2 +- common/utils/environment.cpp | 2 +- common/utils/fs.cpp | 2 +- container-daemon/CMakeLists.txt | 3 +- container-daemon/daemon-connection.cpp | 2 +- container-daemon/daemon.cpp | 2 +- container-daemon/main.cpp | 8 +- container-daemon/runner.cpp | 2 +- packaging/security-containers.spec | 3 + server/CMakeLists.txt | 2 +- server/container-admin.cpp | 2 +- server/container-connection-transport.cpp | 2 +- server/container-connection.cpp | 2 +- server/container.cpp | 3 +- server/containers-manager.cpp | 3 +- server/host-connection.cpp | 2 +- server/input-monitor.cpp | 2 +- server/main.cpp | 8 +- server/network-admin.cpp | 2 +- server/server.cpp | 3 +- tests/unit_tests/CMakeLists.txt | 2 +- tests/unit_tests/config/ut-configuration.cpp | 3 +- tests/unit_tests/dbus/test-server.cpp | 2 +- tests/unit_tests/dbus/ut-connection.cpp | 4 +- tests/unit_tests/log/ut-logger.cpp | 10 +- .../unit_tests/server/ut-container-connection.cpp | 2 +- tests/unit_tests/server/ut-container.cpp | 2 +- tests/unit_tests/server/ut-containers-manager.cpp | 6 +- tests/unit_tests/server/ut-server.cpp | 2 +- tests/unit_tests/ut.cpp | 6 +- tests/unit_tests/utils/scoped-daemon.cpp | 2 +- 58 files changed, 56 insertions(+), 2179 deletions(-) delete mode 100644 common/config/exception.hpp delete mode 100644 common/config/fields.hpp delete mode 100644 common/config/from-json-visitor.hpp delete mode 100644 common/config/is-visitable.hpp delete mode 100644 common/config/manager.hpp delete mode 100644 common/config/to-json-visitor.hpp delete mode 100644 common/dbus/connection.cpp delete mode 100644 common/dbus/connection.hpp delete mode 100644 common/dbus/exception.hpp delete mode 100644 common/log/backend-journal.cpp delete mode 100644 common/log/backend-journal.hpp delete mode 100644 common/log/backend-null.hpp delete mode 100644 common/log/backend-stderr.cpp delete mode 100644 common/log/backend-stderr.hpp delete mode 100644 common/log/backend.hpp delete mode 100644 common/log/ccolor.cpp delete mode 100644 common/log/ccolor.hpp delete mode 100644 common/log/formatter.cpp delete mode 100644 common/log/formatter.hpp delete mode 100644 common/log/level.cpp delete mode 100644 common/log/level.hpp delete mode 100644 common/log/logger.cpp delete mode 100644 common/log/logger.hpp diff --git a/common/config/exception.hpp b/common/config/exception.hpp deleted file mode 100644 index aa644b1..0000000 --- a/common/config/exception.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Lukasz Pawelczyk - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com) - * @brief Exceptions for the configuration - */ - - -#ifndef COMMON_CONFIG_EXCEPTION_HPP -#define COMMON_CONFIG_EXCEPTION_HPP - -#include "base-exception.hpp" - - -namespace security_containers { -namespace config { - - -/** - * Base class for exceptions in configuration. - * Error occured during a config file parsing, - * e.g. syntax error - */ -struct ConfigException: public SecurityContainersException { - - ConfigException(const std::string& error = "") : SecurityContainersException(error) {} -}; - - -} // namespace config -} // namespace security_containers - - -#endif // COMMON_CONFIG_EXCEPTION_HPP diff --git a/common/config/fields.hpp b/common/config/fields.hpp deleted file mode 100644 index db0f26f..0000000 --- a/common/config/fields.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Macros for registering configuration fields - */ - -#ifndef COMMON_CONFIG_FIELDS_HPP -#define COMMON_CONFIG_FIELDS_HPP - -#include -#include - -#if BOOST_PP_VARIADICS != 1 -#error variadic macros not supported -#endif - -/** - * Use this macro to register config fields. - * - * Example: - * struct Foo - * { - * std::string bar; - * std::vector tab; - * - * // SubConfigA must also register config fields - * SubConfigA sub_a; - * - * // SubConfigB must also register config fields - * std::vector tab_sub; - * - * CONFIG_REGISTER - * ( - * bar, - * tab, - * sub_a - * ) - * }; - */ -#define CONFIG_REGISTER(...) \ - template \ - void accept(Visitor v) { \ - GENERATE_ELEMENTS__(__VA_ARGS__) \ - } \ - template \ - void accept(Visitor v) const { \ - GENERATE_ELEMENTS__(__VA_ARGS__) \ - } \ - -#define GENERATE_ELEMENTS__(...) \ - BOOST_PP_LIST_FOR_EACH(GENERATE_ELEMENT__, \ - _, \ - BOOST_PP_VARIADIC_TO_LIST(__VA_ARGS__)) \ - -#define GENERATE_ELEMENT__(r, _, element) \ - v.visit(#element, element); \ - - -#endif // COMMON_CONFIG_FIELDS_HPP diff --git a/common/config/from-json-visitor.hpp b/common/config/from-json-visitor.hpp deleted file mode 100644 index fad9986..0000000 --- a/common/config/from-json-visitor.hpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief JSON visitor - */ - -#ifndef COMMON_CONFIG_FROM_JSON_VISITOR_HPP -#define COMMON_CONFIG_FROM_JSON_VISITOR_HPP - -#include "config/is-visitable.hpp" -#include "config/exception.hpp" - -#include -#include -#include - -namespace security_containers { -namespace config { - -class FromJsonVisitor { -public: - explicit FromJsonVisitor(const std::string& jsonString) - : mObject(nullptr) - { - mObject = json_tokener_parse(jsonString.c_str()); - if (mObject == nullptr) { - throw ConfigException("Json parsing error"); - } - } - - FromJsonVisitor(const FromJsonVisitor& visitor) - : mObject(json_object_get(visitor.mObject)) - { - } - - ~FromJsonVisitor() - { - json_object_put(mObject); - } - - template - void visit(const std::string& name, T& value) - { - json_object* object = nullptr; - if (!json_object_object_get_ex(mObject, name.c_str(), &object)) { - throw ConfigException("Missing field '" + name + "' in json"); - } - fromJsonObject(object, value); - } - -private: - json_object* mObject; - - FromJsonVisitor& operator=(const FromJsonVisitor&) = delete; - - explicit FromJsonVisitor(json_object* object) - : mObject(json_object_get(object)) - { - } - - static void checkType(json_object* object, json_type type) - { - if (type != json_object_get_type(object)) { - throw ConfigException("Invalid field type"); - } - } - - static void fromJsonObject(json_object* object, int& value) - { - checkType(object, json_type_int); - std::int64_t value64 = json_object_get_int64(object); - if (value64 > INT32_MAX || value64 < INT32_MIN) { - throw ConfigException("Value out of range"); - } - value = static_cast(value64); - } - - static void fromJsonObject(json_object* object, std::int64_t& value) - { - checkType(object, json_type_int); - value = json_object_get_int64(object); - } - - static void fromJsonObject(json_object* object, bool& value) - { - checkType(object, json_type_boolean); - value = json_object_get_boolean(object); - } - - static void fromJsonObject(json_object* object, double& value) - { - checkType(object, json_type_double); - value = json_object_get_double(object); - } - - static void fromJsonObject(json_object* object, std::string& value) - { - checkType(object, json_type_string); - value = json_object_get_string(object); - } - - template - static void fromJsonObject(json_object* object, std::vector& value) - { - checkType(object, json_type_array); - int length = json_object_array_length(object); - value.resize(static_cast(length)); - for (int i = 0; i < length; ++i) { - fromJsonObject(json_object_array_get_idx(object, i), value[static_cast(i)]); - } - } - - template::value>::type> - static void fromJsonObject(json_object* object, T& value) - { - checkType(object, json_type_object); - FromJsonVisitor visitor(object); - value.accept(visitor); - } -}; - -} // namespace config -} // namespace security_containers - -#endif // COMMON_CONFIG_FROM_JSON_VISITOR_HPP diff --git a/common/config/is-visitable.hpp b/common/config/is-visitable.hpp deleted file mode 100644 index 0a405c5..0000000 --- a/common/config/is-visitable.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Internal configuration helper - */ - -#ifndef COMMON_CONFIG_IS_VISITABLE_HPP -#define COMMON_CONFIG_IS_VISITABLE_HPP - -#include - -namespace security_containers { -namespace config { - -template -struct isVisitableHelper__ { - struct Visitor {}; - - template static std::true_type - test(decltype(std::declval().template accept(Visitor()))*); - - template static std::false_type - test(...); - - static constexpr bool value = std::is_same(0)), std::true_type>::value; -}; - -/** - * Helper for compile-time checking against existance of template method 'accept'. - */ -template -struct isVisitable : public std::integral_constant::value> {}; - -} // namespace config -} // namespace security_containers - -#endif // COMMON_CONFIG_IS_VISITABLE_HPP diff --git a/common/config/manager.hpp b/common/config/manager.hpp deleted file mode 100644 index 8761267..0000000 --- a/common/config/manager.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Configuration management functions - */ - -#ifndef COMMON_CONFIG_MANAGER_HPP -#define COMMON_CONFIG_MANAGER_HPP - -#include "config/to-json-visitor.hpp" -#include "config/from-json-visitor.hpp" -#include "config/is-visitable.hpp" -#include "utils/fs.hpp" - -namespace security_containers { -namespace config { - -template -void loadFromString(const std::string& jsonString, Config& config) -{ - static_assert(isVisitable::value, "Use CONFIG_REGISTER macro"); - - FromJsonVisitor visitor(jsonString); - config.accept(visitor); -} - -template -std::string saveToString(const Config& config) -{ - static_assert(isVisitable::value, "Use CONFIG_REGISTER macro"); - - ToJsonVisitor visitor; - config.accept(visitor); - return visitor.toString(); -} - -template -void loadFromFile(const std::string& filename, Config& config) -{ - std::string content; - if (!utils::readFileContent(filename, content)) { - throw ConfigException("Could not load " + filename); - } - loadFromString(content, config); -} - -template -void saveToFile(const std::string& filename, const Config& config) -{ - const std::string content = saveToString(config); - if (!utils::saveFileContent(filename, content)) { - throw ConfigException("Could not save " + filename); - } -} - -} // namespace config -} // namespace security_containers - -#endif // COMMON_CONFIG_MANAGER_HPP diff --git a/common/config/to-json-visitor.hpp b/common/config/to-json-visitor.hpp deleted file mode 100644 index 477b1ef..0000000 --- a/common/config/to-json-visitor.hpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief JSON visitor - */ - -#ifndef COMMON_CONFIG_TO_JSON_VISITOR_HPP -#define COMMON_CONFIG_TO_JSON_VISITOR_HPP - -#include "config/is-visitable.hpp" - -#include -#include -#include - -namespace security_containers { -namespace config { - -class ToJsonVisitor { - -public: - ToJsonVisitor() - : mObject(json_object_new_object()) - { - } - - ToJsonVisitor(const ToJsonVisitor& visitor) - : mObject(json_object_get(visitor.mObject)) - { - } - - ~ToJsonVisitor() - { - json_object_put(mObject); - } - - std::string toString() const - { - return json_object_to_json_string(mObject); - } - - template - void visit(const std::string& name, const T& value) - { - json_object_object_add(mObject, name.c_str(), toJsonObject(value)); - } -private: - json_object* mObject; - - ToJsonVisitor& operator=(const ToJsonVisitor&) = delete; - - json_object* detach() - { - json_object* ret = mObject; - mObject = nullptr; - return ret; - } - - static json_object* toJsonObject(int value) - { - return json_object_new_int(value); - } - - static json_object* toJsonObject(std::int64_t value) - { - return json_object_new_int64(value); - } - - static json_object* toJsonObject(bool value) - { - return json_object_new_boolean(value); - } - - static json_object* toJsonObject(double value) - { - return json_object_new_double(value); - } - - static json_object* toJsonObject(const std::string& value) - { - return json_object_new_string(value.c_str()); - } - - template - static json_object* toJsonObject(const std::vector& value) - { - json_object* array = json_object_new_array(); - for (const T& v : value) { - json_object_array_add(array, toJsonObject(v)); - } - return array; - } - - template::value>::type> - static json_object* toJsonObject(const T& value) - { - ToJsonVisitor visitor; - value.accept(visitor); - return visitor.detach(); - } -}; - -} // namespace config -} // namespace security_containers - -#endif // COMMON_CONFIG_TO_JSON_VISITOR_HPP diff --git a/common/dbus/connection.cpp b/common/dbus/connection.cpp deleted file mode 100644 index ef6fc46..0000000 --- a/common/dbus/connection.cpp +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Dbus connection class - */ - -#include "config.hpp" -#include "dbus/connection.hpp" -#include "dbus/exception.hpp" -#include "utils/callback-wrapper.hpp" -#include "utils/scoped-gerror.hpp" -#include "log/logger.hpp" - -using namespace security_containers::utils; - -namespace security_containers { -namespace dbus { - - -namespace { - -const std::string SYSTEM_BUS_ADDRESS = "unix:path=/var/run/dbus/system_bus_socket"; -const std::string INTROSPECT_INTERFACE = "org.freedesktop.DBus.Introspectable"; -const std::string INTROSPECT_METHOD = "Introspect"; - -const int CALL_METHOD_TIMEOUT_MS = 1000; - -class MethodResultBuilderImpl : public MethodResultBuilder { -public: - MethodResultBuilderImpl(GDBusMethodInvocation* invocation) - : mInvocation(invocation), mResultSet(false) {} - ~MethodResultBuilderImpl() - { - if (!mResultSet) { - setError("org.freedesktop.DBus.Error.UnknownMethod", "Not implemented"); - } - } - void set(GVariant* parameters) - { - g_dbus_method_invocation_return_value(mInvocation, parameters); - mResultSet = true; - } - void setVoid() - { - set(NULL); - } - void setError(const std::string& name, const std::string& message) - { - g_dbus_method_invocation_return_dbus_error(mInvocation, name.c_str(), message.c_str()); - mResultSet = true; - } -private: - GDBusMethodInvocation* mInvocation; - bool mResultSet; -}; - -void throwDbusException(const ScopedGError& e) -{ - if (e->domain == g_io_error_quark()) { - if (e->code == G_IO_ERROR_DBUS_ERROR) { - throw DbusCustomException(e->message); - } else { - throw DbusIOException(e->message); - } - } else if (e->domain == g_dbus_error_quark()) { - throw DbusOperationException(e->message); - } else if (e->domain == g_markup_error_quark()) { - throw DbusInvalidArgumentException(e->message); - } else { - throw DbusException(e->message); - } -} - -class AsyncMethodCallResultImpl : public AsyncMethodCallResult { -public: - AsyncMethodCallResultImpl(GVariant* result, const ScopedGError& error) - : mResult(result), mError(error) {} - ~AsyncMethodCallResultImpl() - { - if (mResult) { - g_variant_unref(mResult); - } - } - GVariant* get() - { - if (mError) { - throwDbusException(mError); - } - return mResult; - } -private: - GVariant* mResult; - const ScopedGError& mError; -}; - -} // namespace - -DbusConnection::Pointer DbusConnection::create(const std::string& address) -{ - return Pointer(new DbusConnection(address)); -} - -DbusConnection::Pointer DbusConnection::createSystem() -{ - return create(SYSTEM_BUS_ADDRESS); -} - -DbusConnection::DbusConnection(const std::string& address) - : mConnection(NULL) - , mNameId(0) -{ - ScopedGError error; - const GDBusConnectionFlags flags = - static_cast(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | - G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION); - // TODO: this is possible deadlock if the dbus - // socket exists but there is no dbus-daemon - mConnection = g_dbus_connection_new_for_address_sync(address.c_str(), - flags, - NULL, - NULL, - &error); - if (error) { - error.strip(); - LOGE("Could not connect to " << address << "; " << error); - throwDbusException(error); - } -} - -DbusConnection::~DbusConnection() -{ - if (mNameId) { - g_bus_unown_name(mNameId); - } - g_object_unref(mConnection); - LOGT("Connection deleted"); -} - -void DbusConnection::setName(const std::string& name, - const VoidCallback& onNameAcquired, - const VoidCallback& onNameLost) -{ - mNameId = g_bus_own_name_on_connection(mConnection, - name.c_str(), - G_BUS_NAME_OWNER_FLAGS_NONE, - &DbusConnection::onNameAcquired, - &DbusConnection::onNameLost, - utils::createCallbackWrapper( - NameCallbacks(onNameAcquired, onNameLost), - mGuard.spawn()), - &utils::deleteCallbackWrapper); -} - -void DbusConnection::onNameAcquired(GDBusConnection*, const gchar* name, gpointer userData) -{ - LOGD("Name acquired " << name); - const NameCallbacks& callbacks = utils::getCallbackFromPointer(userData); - if (callbacks.nameAcquired) { - callbacks.nameAcquired(); - } -} - -void DbusConnection::onNameLost(GDBusConnection*, const gchar* name, gpointer userData) -{ - LOGD("Name lost " << name); - const NameCallbacks& callbacks = utils::getCallbackFromPointer(userData); - if (callbacks.nameLost) { - callbacks.nameLost(); - } -} - -void DbusConnection::emitSignal(const std::string& objectPath, - const std::string& interface, - const std::string& name, - GVariant* parameters) -{ - ScopedGError error; - g_dbus_connection_emit_signal(mConnection, - NULL, - objectPath.c_str(), - interface.c_str(), - name.c_str(), - parameters, - &error); - if (error) { - error.strip(); - LOGE("Emit signal failed; " << error); - throwDbusException(error); - } -} - -void DbusConnection::signalSubscribe(const SignalCallback& callback, - const std::string& senderBusName) -{ - g_dbus_connection_signal_subscribe(mConnection, - senderBusName.empty() ? NULL : senderBusName.c_str(), - NULL, - NULL, - NULL, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - &DbusConnection::onSignal, - utils::createCallbackWrapper(callback, mGuard.spawn()), - &utils::deleteCallbackWrapper); -} - -void DbusConnection::onSignal(GDBusConnection*, - const gchar* sender, - const gchar* object, - const gchar* interface, - const gchar* name, - GVariant* parameters, - gpointer userData) -{ - const SignalCallback& callback = utils::getCallbackFromPointer(userData); - - LOGD("Signal: " << sender << "; " << object << "; " << interface << "; " << name); - - if (callback) { - callback(sender, object, interface, name, parameters); - } -} - -std::string DbusConnection::introspect(const std::string& busName, const std::string& objectPath) -{ - GVariantPtr result = DbusConnection::callMethod(busName, - objectPath, - INTROSPECT_INTERFACE, - INTROSPECT_METHOD, - NULL, - "(s)"); - const gchar* xml; - g_variant_get(result.get(), "(&s)", &xml); - return xml; -} - -void DbusConnection::registerObject(const std::string& objectPath, - const std::string& objectDefinitionXml, - const MethodCallCallback& callback) -{ - ScopedGError error; - GDBusNodeInfo* nodeInfo = g_dbus_node_info_new_for_xml(objectDefinitionXml.c_str(), &error); - if (nodeInfo != NULL && (nodeInfo->interfaces == NULL || - nodeInfo->interfaces[0] == NULL || - nodeInfo->interfaces[1] != NULL)) { - g_dbus_node_info_unref(nodeInfo); - g_set_error(&error, - G_MARKUP_ERROR, - G_MARKUP_ERROR_INVALID_CONTENT, - "Expected exactly one interface"); - } - if (error) { - error.strip(); - LOGE("Invalid xml; " << error); - throwDbusException(error); - } - GDBusInterfaceInfo* interfaceInfo = nodeInfo->interfaces[0]; - - GDBusInterfaceVTable vtable; - vtable.method_call = &DbusConnection::onMethodCall; - vtable.get_property = NULL; - vtable.set_property = NULL; - - g_dbus_connection_register_object(mConnection, - objectPath.c_str(), - interfaceInfo, - &vtable, - utils::createCallbackWrapper(callback, mGuard.spawn()), - &utils::deleteCallbackWrapper, - &error); - g_dbus_node_info_unref(nodeInfo); - if (error) { - error.strip(); - LOGE("Register object failed; " << error); - throwDbusException(error); - } -} - -void DbusConnection::onMethodCall(GDBusConnection*, - const gchar*, - const gchar* objectPath, - const gchar* interface, - const gchar* method, - GVariant* parameters, - GDBusMethodInvocation* invocation, - gpointer userData) -{ - const MethodCallCallback& callback = utils::getCallbackFromPointer(userData); - - LOGD("MethodCall: " << objectPath << "; " << interface << "; " << method); - - MethodResultBuilder::Pointer resultBuilder(new MethodResultBuilderImpl(invocation)); - if (callback) { - callback(objectPath, interface, method, parameters, resultBuilder); - } -} - -GVariantPtr DbusConnection::callMethod(const std::string& busName, - const std::string& objectPath, - const std::string& interface, - const std::string& method, - GVariant* parameters, - const std::string& replyType) -{ - ScopedGError error; - GVariant* result = g_dbus_connection_call_sync(mConnection, - busName.c_str(), - objectPath.c_str(), - interface.c_str(), - method.c_str(), - parameters, - replyType.empty() ? NULL - : G_VARIANT_TYPE(replyType.c_str()), - G_DBUS_CALL_FLAGS_NONE, - CALL_METHOD_TIMEOUT_MS, - NULL, - &error); - if (error) { - error.strip(); - LOGE("Call method failed; " << error); - throwDbusException(error); - } - return GVariantPtr(result, g_variant_unref); -} - -void DbusConnection::callMethodAsync(const std::string& busName, - const std::string& objectPath, - const std::string& interface, - const std::string& method, - GVariant* parameters, - const std::string& replyType, - const AsyncMethodCallCallback& callback) -{ - g_dbus_connection_call(mConnection, - busName.c_str(), - objectPath.c_str(), - interface.c_str(), - method.c_str(), - parameters, - replyType.empty() ? NULL - : G_VARIANT_TYPE(replyType.c_str()), - G_DBUS_CALL_FLAGS_NONE, - CALL_METHOD_TIMEOUT_MS, - NULL, - &DbusConnection::onAsyncReady, - utils::createCallbackWrapper(callback, mGuard.spawn())); -} - -void DbusConnection::onAsyncReady(GObject* source, - GAsyncResult* asyncResult, - gpointer userData) -{ - std::unique_ptr - autoDeleteCallback(userData, &utils::deleteCallbackWrapper); - GDBusConnection* connection = reinterpret_cast(source); - const AsyncMethodCallCallback& callback = - utils::getCallbackFromPointer(userData); - - ScopedGError error; - GVariant* result = g_dbus_connection_call_finish(connection, asyncResult, &error); - if (error) { - error.strip(); - LOGE("Call method failed; " << error); - } - AsyncMethodCallResultImpl asyncMethodCallResult(result, error); - if (callback) { - callback(asyncMethodCallResult); - } -} - - -} // namespace dbus -} // namespace security_containers diff --git a/common/dbus/connection.hpp b/common/dbus/connection.hpp deleted file mode 100644 index 9ac87de..0000000 --- a/common/dbus/connection.hpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Dbus connection class - */ - -#ifndef COMMON_DBUS_CONNECTION_HPP -#define COMMON_DBUS_CONNECTION_HPP - -#include "utils/callback-guard.hpp" - -#include -#include -#include -#include - - -namespace security_containers { -namespace dbus { - - -typedef std::unique_ptr GVariantPtr; - -/** - * An interface used to set a result to a method call. - */ -class MethodResultBuilder { -public: - typedef std::shared_ptr Pointer; - - virtual ~MethodResultBuilder() {} - virtual void set(GVariant* parameters) = 0; - virtual void setVoid() = 0; - virtual void setError(const std::string& name, const std::string& message) = 0; -}; - -/** - * An interface used to get result from async response. - */ -class AsyncMethodCallResult { -public: - virtual ~AsyncMethodCallResult() {} - virtual GVariant* get() = 0; // throws DbusException on error -}; - -/** - * Dbus connection. - * Provides a functionality that allows to call dbus methods, - * register dbus interfaces, etc. - * - * TODO divide to interface and implementation header - */ -class DbusConnection { -public: - typedef std::unique_ptr Pointer; - - typedef std::function VoidCallback; - - typedef std::function MethodCallCallback; - - typedef std::function SignalCallback; - - typedef std::function AsyncMethodCallCallback; - - /** - * Creates a connection to the dbus with given address. - */ - static Pointer create(const std::string& address); - - /** - * Creates a connection to the system dbus. - */ - static Pointer createSystem(); - - ~DbusConnection(); - - /** - * Sets a name to the dbus connection. - * It allows other client to call methods using this name. - */ - void setName(const std::string& name, - const VoidCallback& onNameAcquired, - const VoidCallback& onNameLost); - - /** - * Emits dbus signal. - */ - void emitSignal(const std::string& objectPath, - const std::string& interface, - const std::string& name, - GVariant* parameters); - - /** - * Subscribes to a signal. - * Empty sender means subscribe to all signals - */ - void signalSubscribe(const SignalCallback& callback, const std::string& senderBusName); - - /** - * Registers an object with given definition. - * Api calls will be handled by given callback. - */ - void registerObject(const std::string& objectPath, - const std::string& objectDefinitionXml, - const MethodCallCallback& callback); - - /** - * Call a dbus method - */ - GVariantPtr callMethod(const std::string& busName, - const std::string& objectPath, - const std::string& interface, - const std::string& method, - GVariant* parameters, - const std::string& replyType); - - /** - * Async call a dbus method - */ - void callMethodAsync(const std::string& busName, - const std::string& objectPath, - const std::string& interface, - const std::string& method, - GVariant* parameters, - const std::string& replyType, - const AsyncMethodCallCallback& callback); - - /** - * Returns an xml with meta description of specified dbus object. - */ - std::string introspect(const std::string& busName, const std::string& objectPath); - -private: - struct NameCallbacks { - VoidCallback nameAcquired; - VoidCallback nameLost; - - NameCallbacks(const VoidCallback& acquired, const VoidCallback& lost) - : nameAcquired(acquired), nameLost(lost) {} - }; - - utils::CallbackGuard mGuard; - GDBusConnection* mConnection; - guint mNameId; - - DbusConnection(const std::string& address); - - static void onNameAcquired(GDBusConnection* connection, const gchar* name, gpointer userData); - static void onNameLost(GDBusConnection* connection, const gchar* name, gpointer userData); - static void onSignal(GDBusConnection* connection, - const gchar* sender, - const gchar* object, - const gchar* interface, - const gchar* name, - GVariant* parameters, - gpointer userData); - static void onMethodCall(GDBusConnection* connection, - const gchar* sender, - const gchar* objectPath, - const gchar* interface, - const gchar* method, - GVariant* parameters, - GDBusMethodInvocation* invocation, - gpointer userData); - static void onAsyncReady(GObject* source, - GAsyncResult* asyncResult, - gpointer userData); -}; - - -} // namespace dbus -} // namespace security_containers - - -#endif // COMMON_DBUS_CONNECTION_HPP diff --git a/common/dbus/exception.hpp b/common/dbus/exception.hpp deleted file mode 100644 index 32cf87c..0000000 --- a/common/dbus/exception.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Piotr Bartosiewicz - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Dbus exceptions - */ - - -#ifndef COMMON_DBUS_EXCEPTION_HPP -#define COMMON_DBUS_EXCEPTION_HPP - -#include "base-exception.hpp" - - -namespace security_containers { -namespace dbus { - - -/** - * Base class for dbus exceptions - */ -struct DbusException: public SecurityContainersException { - - DbusException(const std::string& error = "") : SecurityContainersException(error) {} -}; - -/** - * Dbus IO exception (connection failed, connection lost, etc) - */ -struct DbusIOException: public DbusException { - - DbusIOException(const std::string& error = "") : DbusException(error) {} -}; - -/** - * Dbus operation failed exception - */ -struct DbusOperationException: public DbusException { - - DbusOperationException(const std::string& error = "") : DbusException(error) {} -}; - -/** - * Dbus custom exception triggered by user logic - */ -struct DbusCustomException: public DbusException { - - DbusCustomException(const std::string& error = "") : DbusException(error) {} -}; - -/** - * Dbus invalid argument exception - */ -struct DbusInvalidArgumentException: public DbusException { - - DbusInvalidArgumentException(const std::string& error = "") : DbusException(error) {} -}; - - -} // namespace dbus -} // namespace security_containers - - -#endif // COMMON_DBUS_EXCEPTION_HPP diff --git a/common/libvirt/connection.cpp b/common/libvirt/connection.cpp index 12c906d..2fdaaa9 100644 --- a/common/libvirt/connection.cpp +++ b/common/libvirt/connection.cpp @@ -23,7 +23,7 @@ */ #include "config.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "libvirt/helpers.hpp" #include "libvirt/connection.hpp" #include "libvirt/exception.hpp" diff --git a/common/libvirt/domain.cpp b/common/libvirt/domain.cpp index 8b6bb98..d9e4217 100644 --- a/common/libvirt/domain.cpp +++ b/common/libvirt/domain.cpp @@ -23,7 +23,7 @@ */ #include "config.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "libvirt/domain.hpp" #include "libvirt/helpers.hpp" #include "libvirt/exception.hpp" diff --git a/common/libvirt/helpers.cpp b/common/libvirt/helpers.cpp index 7948a6a..8b096bb 100644 --- a/common/libvirt/helpers.cpp +++ b/common/libvirt/helpers.cpp @@ -24,7 +24,7 @@ #include "config.hpp" #include "libvirt/helpers.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include #include diff --git a/common/libvirt/network.cpp b/common/libvirt/network.cpp index 5384d9f..486ae63 100644 --- a/common/libvirt/network.cpp +++ b/common/libvirt/network.cpp @@ -24,7 +24,7 @@ #include "config.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "libvirt/network.hpp" #include "libvirt/helpers.hpp" #include "libvirt/exception.hpp" diff --git a/common/log/backend-journal.cpp b/common/log/backend-journal.cpp deleted file mode 100644 index 859d546..0000000 --- a/common/log/backend-journal.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Dariusz Michaluk - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Dariusz Michaluk (d.michaluk@samsung.com) - * @brief Systemd journal backend for logger - */ - -#include "config.hpp" -#include "log/backend-journal.hpp" - -#define SD_JOURNAL_SUPPRESS_LOCATION -#include - -namespace security_containers { -namespace log { - -namespace { - -inline int toJournalPriority(LogLevel logLevel) -{ - switch (logLevel) { - case LogLevel::ERROR: - return LOG_ERR; // 3 - case LogLevel::WARN: - return LOG_WARNING; // 4 - case LogLevel::INFO: - return LOG_INFO; // 6 - case LogLevel::DEBUG: - return LOG_DEBUG; // 7 - case LogLevel::TRACE: - return LOG_DEBUG; // 7 - default: - return LOG_DEBUG; - } -} - -} // namespace - -void SystemdJournalBackend::log(LogLevel logLevel, - const std::string& file, - const unsigned int& line, - const std::string& func, - const std::string& message) -{ - sd_journal_send("PRIORITY=%d", toJournalPriority(logLevel), - "CODE_FILE=%s", file.c_str(), - "CODE_LINE=%d", line, - "CODE_FUNC=%s", func.c_str(), - "MESSAGE=%s", message.c_str(), - NULL); -} - -} // namespace log -} // namespace security_containers - diff --git a/common/log/backend-journal.hpp b/common/log/backend-journal.hpp deleted file mode 100644 index f040d9a..0000000 --- a/common/log/backend-journal.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Dariusz Michaluk - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Dariusz Michaluk (d.michaluk@samsung.com) - * @brief Systemd journal backend for logger - */ - -#ifndef COMMON_LOG_BACKEND_JOURNAL_HPP -#define COMMON_LOG_BACKEND_JOURNAL_HPP - -#include "log/backend.hpp" - - -namespace security_containers { -namespace log { - - -/** - systemd journal logging backend - */ -class SystemdJournalBackend : public LogBackend { -public: - void log(LogLevel logLevel, - const std::string& file, - const unsigned int& line, - const std::string& func, - const std::string& message) override; -}; - - -} // namespace log -} // namespace security_containers - - -#endif // COMMON_LOG_BACKEND_JOURNAL_HPP diff --git a/common/log/backend-null.hpp b/common/log/backend-null.hpp deleted file mode 100644 index 7a26344..0000000 --- a/common/log/backend-null.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Pawel Broda - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Pawel Broda (p.broda@partner.samsung.com) - * @brief Null backend for logger - */ - - -#ifndef COMMON_LOG_BACKEND_NULL_HPP -#define COMMON_LOG_BACKEND_NULL_HPP - -#include "log/backend.hpp" - - -namespace security_containers { -namespace log { - - -/** - Null logging backend - */ -class NullLogger : public LogBackend { -public: - void log(LogLevel /*logLevel*/, - const std::string& /*file*/, - const unsigned int& /*line*/, - const std::string& /*func*/, - const std::string& /*message*/) override {} -}; - - -} // namespace log -} // namespace security_containers - - -#endif // COMMON_LOG_BACKEND_NULL_HPP diff --git a/common/log/backend-stderr.cpp b/common/log/backend-stderr.cpp deleted file mode 100644 index 471106c..0000000 --- a/common/log/backend-stderr.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Pawel Broda - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Pawel Broda (p.broda@partner.samsung.com) - * @brief Stderr backend for logger - */ - -#include "config.hpp" -#include "log/backend-stderr.hpp" -#include "log/formatter.hpp" - -#include - -namespace security_containers { -namespace log { - -void StderrBackend::log(LogLevel logLevel, - const std::string& file, - const unsigned int& line, - const std::string& func, - const std::string& message) -{ - typedef boost::char_separator charSeparator; - typedef boost::tokenizer tokenizer; - - // example log string - // 06:52:35.123 [ERROR] src/util/fs.cpp:43 readFileContent: /file/file.txt is missing - - const std::string logColor = LogFormatter::getConsoleColor(logLevel); - const std::string defaultColor = LogFormatter::getDefaultConsoleColor(); - const std::string header = LogFormatter::getHeader(logLevel, file, line, func); - tokenizer tokens(message, charSeparator("\n")); - for (const auto& messageLine : tokens) { - if (!messageLine.empty()) { - fprintf(stderr, - "%s%s%s%s\n", - logColor.c_str(), - header.c_str(), - messageLine.c_str(), - defaultColor.c_str()); - } - } -} - - -} // namespace log -} // namespace security_containers - diff --git a/common/log/backend-stderr.hpp b/common/log/backend-stderr.hpp deleted file mode 100644 index c60d523..0000000 --- a/common/log/backend-stderr.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Pawel Broda - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Pawel Broda (p.broda@partner.samsung.com) - * @brief Stderr backend for logger - */ - -#ifndef COMMON_LOG_BACKEND_STDERR_HPP -#define COMMON_LOG_BACKEND_STDERR_HPP - -#include "log/backend.hpp" - - -namespace security_containers { -namespace log { - - -/** - Stderr logging backend - */ -class StderrBackend : public LogBackend { -public: - void log(LogLevel logLevel, - const std::string& file, - const unsigned int& line, - const std::string& func, - const std::string& message) override; -}; - - -} // namespace log -} // namespace security_containers - - -#endif // COMMON_LOG_BACKEND_STDERR_HPP diff --git a/common/log/backend.hpp b/common/log/backend.hpp deleted file mode 100644 index adad533..0000000 --- a/common/log/backend.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Pawel Broda - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Pawel Broda (p.broda@partner.samsung.com) - * @brief Logging backend - */ - - -#ifndef COMMON_LOG_BACKEND_HPP -#define COMMON_LOG_BACKEND_HPP - -#include "log/level.hpp" - -#include - -namespace security_containers { -namespace log { - - -/** - Abstract class for logger - */ -class LogBackend { -public: - virtual void log(LogLevel logLevel, - const std::string& file, - const unsigned int& line, - const std::string& func, - const std::string& message) = 0; - virtual ~LogBackend() {} -}; - - -} // namespace log -} // namespace security_containers - - -#endif // COMMON_LOG_BACKEND_HPP diff --git a/common/log/ccolor.cpp b/common/log/ccolor.cpp deleted file mode 100644 index 128f11f..0000000 --- a/common/log/ccolor.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Dariusz Michaluk - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Dariusz Michaluk (d.michaluk@samsung.com) - * @brief Console color for StderrBackend logger - */ - -#include "config.hpp" -#include "log/ccolor.hpp" - -#include - -namespace security_containers { -namespace log { - -std::string getConsoleEscapeSequence(Attributes attr, Color color) -{ - char command[10]; - - // Command is the control command to the terminal - snprintf(command, sizeof(command), "%c[%d;%dm", 0x1B, attr, color); - return std::string(command); -} - -} // namespace log -} // namespace security_containers - diff --git a/common/log/ccolor.hpp b/common/log/ccolor.hpp deleted file mode 100644 index dc37458..0000000 --- a/common/log/ccolor.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Dariusz Michaluk - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Dariusz Michaluk (d.michaluk@samsung.com) - * @brief Console color for StderrBackend logger - */ - -#ifndef COMMON_LOG_CCOLOR_HPP -#define COMMON_LOG_CCOLOR_HPP - -#include - -namespace security_containers { -namespace log { - -enum class Color : unsigned int { - DEFAULT = 0, - BLACK = 90, - RED = 91, - GREEN = 92, - YELLOW = 93, - BLUE = 94, - MAGENTA = 95, - CYAN = 96, - WHITE = 97 -}; - -enum class Attributes : unsigned int { - DEFAULT = 0, - BOLD = 1 -}; - -std::string getConsoleEscapeSequence(Attributes attr, Color color); - -} // namespace log -} // namespace security_containers - -#endif // COMMON_LOG_CCOLOR_HPP - diff --git a/common/log/formatter.cpp b/common/log/formatter.cpp deleted file mode 100644 index 100a8eb..0000000 --- a/common/log/formatter.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Dariusz Michaluk - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Dariusz Michaluk (d.michaluk@samsung.com) - * @brief Helper formatter for logger - */ - -#include "config.hpp" -#include "log/formatter.hpp" -#include "log/ccolor.hpp" - -#include -#include -#include -#include -#include -#include - -namespace security_containers { -namespace log { - -namespace { - -const int TIME_COLUMN_LENGTH = 12; -const int SEVERITY_COLUMN_LENGTH = 8; -const int THREAD_COLUMN_LENGTH = 3; -const int FILE_COLUMN_LENGTH = 60; - -std::atomic gNextThreadId(1); -thread_local unsigned int gThisThreadId(0); - -} // namespace - -unsigned int LogFormatter::getCurrentThread(void) -{ - unsigned int id = gThisThreadId; - if (id == 0) { - gThisThreadId = id = gNextThreadId++; - } - - return id; -} - -std::string LogFormatter::getCurrentTime(void) -{ - char time[TIME_COLUMN_LENGTH + 1]; - struct timeval tv; - gettimeofday(&tv, NULL); - struct tm* tm = localtime(&tv.tv_sec); - snprintf(time, - sizeof(time), - "%02d:%02d:%02d.%03d", - tm->tm_hour, - tm->tm_min, - tm->tm_sec, - int(tv.tv_usec / 1000)); - - return std::string(time); -} - -std::string LogFormatter::getConsoleColor(LogLevel logLevel) -{ - switch (logLevel) { - case LogLevel::ERROR: - return getConsoleEscapeSequence(Attributes::BOLD, Color::RED); - case LogLevel::WARN: - return getConsoleEscapeSequence(Attributes::BOLD, Color::YELLOW); - case LogLevel::INFO: - return getConsoleEscapeSequence(Attributes::BOLD, Color::BLUE); - case LogLevel::DEBUG: - return getConsoleEscapeSequence(Attributes::DEFAULT, Color::GREEN); - case LogLevel::TRACE: - return getConsoleEscapeSequence(Attributes::DEFAULT, Color::BLACK); - default: - return getConsoleEscapeSequence(Attributes::DEFAULT, Color::DEFAULT); - } -} - -std::string LogFormatter::getDefaultConsoleColor(void) -{ - return getConsoleEscapeSequence(Attributes::DEFAULT, Color::DEFAULT); -} - -std::string LogFormatter::stripProjectDir(const std::string& file) -{ - const std::string SOURCE_DIR = PROJECT_SOURCE_DIR "/"; - // it will work until someone use in cmake FILE(GLOB ... RELATIVE ...) - assert(0 == file.compare(0, SOURCE_DIR.size(), SOURCE_DIR)); - return file.substr(SOURCE_DIR.size()); -} - -std::string LogFormatter::getHeader(LogLevel logLevel, - const std::string& file, - const unsigned int& line, - const std::string& func) -{ - std::ostringstream logLine; - logLine << getCurrentTime() << ' ' - << std::left << std::setw(SEVERITY_COLUMN_LENGTH) << '[' + toString(logLevel) + ']' - << std::right << std::setw(THREAD_COLUMN_LENGTH) << getCurrentThread() << ": " - << std::left << std::setw(FILE_COLUMN_LENGTH) - << file + ':' + std::to_string(line) + ' ' + func + ':'; - return logLine.str(); -} - -} // namespace log -} // namespace security_containers diff --git a/common/log/formatter.hpp b/common/log/formatter.hpp deleted file mode 100644 index 7f83ebe..0000000 --- a/common/log/formatter.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Dariusz Michaluk - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Dariusz Michaluk (d.michaluk@samsung.com) - * @brief Helper formatter for logger - */ - -#ifndef COMMON_LOG_FORMATTER_HPP -#define COMMON_LOG_FORMATTER_HPP - -#include "log/level.hpp" - -#include - -namespace security_containers { -namespace log { - -class LogFormatter { -public: - static unsigned int getCurrentThread(void); - static std::string getCurrentTime(void); - static std::string getConsoleColor(LogLevel logLevel); - static std::string getDefaultConsoleColor(void); - static std::string stripProjectDir(const std::string& file); - static std::string getHeader(LogLevel logLevel, - const std::string& file, - const unsigned int& line, - const std::string& func); -}; - -} // namespace log -} // namespace security_containers - -#endif // COMMON_LOG_FORMATTER_HPP - diff --git a/common/log/level.cpp b/common/log/level.cpp deleted file mode 100644 index 3897726..0000000 --- a/common/log/level.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Jan Olszak - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Jan Olszak (j.olszak@samsung.com) - * @brief Functions to handle LogLevel - */ - -#include "config.hpp" - -#include "log/level.hpp" - -#include -#include - -namespace security_containers { -namespace log { - -LogLevel parseLogLevel(const std::string& level) -{ - if (boost::iequals(level, "ERROR")) { - return LogLevel::ERROR; - } else if (boost::iequals(level, "WARN")) { - return LogLevel::WARN; - } else if (boost::iequals(level, "INFO")) { - return LogLevel::INFO; - } else if (boost::iequals(level, "DEBUG")) { - return LogLevel::DEBUG; - } else if (boost::iequals(level, "TRACE")) { - return LogLevel::TRACE; - } else { - throw std::runtime_error("Invalid LogLevel to parse"); - } -} - -std::string toString(const LogLevel logLevel) -{ - switch (logLevel) { - case LogLevel::ERROR: - return "ERROR"; - case LogLevel::WARN: - return "WARN"; - case LogLevel::INFO: - return "INFO"; - case LogLevel::DEBUG: - return "DEBUG"; - case LogLevel::TRACE: - return "TRACE"; - default: - return "UNKNOWN"; - } -} -} // namespace log -} // namespace security_containers diff --git a/common/log/level.hpp b/common/log/level.hpp deleted file mode 100644 index 6a54cda..0000000 --- a/common/log/level.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Dariusz Michaluk (d.michaluk@samsung.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Dariusz Michaluk (d.michaluk@samsung.com) - * @brief LogLevel - */ - -#ifndef COMMON_LOG_LEVEL_HPP -#define COMMON_LOG_LEVEL_HPP - -#include - - -namespace security_containers { -namespace log { - -enum class LogLevel { - TRACE, - DEBUG, - INFO, - WARN, - ERROR -}; - -/** - * @param logLevel LogLevel - * @return std::sting representation of the LogLevel value - */ -std::string toString(const LogLevel logLevel); - -/** - * @param level string representation of log level - * @return parsed LogLevel value - */ -LogLevel parseLogLevel(const std::string& level); - - -} // namespace log -} // namespace security_containers - -#endif // COMMON_LOG_LEVEL_HPP diff --git a/common/log/logger.cpp b/common/log/logger.cpp deleted file mode 100644 index 83298ed..0000000 --- a/common/log/logger.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Pawel Broda - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Pawel Broda (p.broda@partner.samsung.com) - * @brief Logger - */ - -#include "config.hpp" -#include "log/logger.hpp" -#include "log/formatter.hpp" -#include "log/backend-null.hpp" - -#include -#include - -namespace security_containers { -namespace log { - - -namespace { - -volatile LogLevel gLogLevel = LogLevel::DEBUG; -std::unique_ptr gLogBackendPtr(new NullLogger()); -std::mutex gLogMutex; - -} // namespace - -Logger::Logger(LogLevel logLevel, - const std::string& file, - const unsigned int line, - const std::string& func) - : mLogLevel(logLevel), - mFile(LogFormatter::stripProjectDir(file)), - mLine(line), - mFunc(func) -{ - -} - -void Logger::logMessage(const std::string& message) -{ - std::unique_lock lock(gLogMutex); - gLogBackendPtr->log(mLogLevel, mFile, mLine, mFunc, message); -} - -void Logger::setLogLevel(const LogLevel level) -{ - gLogLevel = level; -} - -void Logger::setLogLevel(const std::string& level) -{ - gLogLevel = parseLogLevel(level); -} - -LogLevel Logger::getLogLevel(void) -{ - return gLogLevel; -} - -void Logger::setLogBackend(LogBackend* pBackend) -{ - std::unique_lock lock(gLogMutex); - gLogBackendPtr.reset(pBackend); -} - -} // namespace log -} // namespace security_containers - diff --git a/common/log/logger.hpp b/common/log/logger.hpp deleted file mode 100644 index 45c5f26..0000000 --- a/common/log/logger.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Jan Olszak - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Jan Olszak (j.olszak@samsung.com) - * @brief Logger - */ - - -#ifndef COMMON_LOG_LOGGER_HPP -#define COMMON_LOG_LOGGER_HPP - -#include "log/level.hpp" - -#include -#include - - -namespace security_containers { -namespace log { - -class LogBackend; - -class Logger { -public: - Logger(LogLevel logLevel, - const std::string& file, - const unsigned int line, - const std::string& func); - - void logMessage(const std::string& message); - - static void setLogLevel(const LogLevel level); - static void setLogLevel(const std::string& level); - static LogLevel getLogLevel(void); - static void setLogBackend(LogBackend* pBackend); - -private: - LogLevel mLogLevel; - std::string mFile; - unsigned int mLine; - std::string mFunc; -}; - -} // namespace log -} // namespace security_containers - - -#define LOG(SEVERITY, MESSAGE) \ - do { \ - if (security_containers::log::Logger::getLogLevel() <= \ - security_containers::log::LogLevel::SEVERITY) { \ - std::ostringstream messageStream__; \ - messageStream__ << MESSAGE; \ - security_containers::log::Logger logger(security_containers::log::LogLevel::SEVERITY, \ - __FILE__, \ - __LINE__, \ - __func__); \ - logger.logMessage(messageStream__.str()); \ - } \ - } while(0) - -#define LOGE(MESSAGE) LOG(ERROR, MESSAGE) -#define LOGW(MESSAGE) LOG(WARN, MESSAGE) -#define LOGI(MESSAGE) LOG(INFO, MESSAGE) -#define LOGD(MESSAGE) LOG(DEBUG, MESSAGE) -#define LOGT(MESSAGE) LOG(TRACE, MESSAGE) - - -#endif // COMMON_LOG_LOGGER_HPP - diff --git a/common/utils/callback-guard.cpp b/common/utils/callback-guard.cpp index 3a35098..d8ee57c 100644 --- a/common/utils/callback-guard.cpp +++ b/common/utils/callback-guard.cpp @@ -24,7 +24,7 @@ #include "config.hpp" #include "utils/callback-guard.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include #include diff --git a/common/utils/environment.cpp b/common/utils/environment.cpp index b74983d..70ef27c 100644 --- a/common/utils/environment.cpp +++ b/common/utils/environment.cpp @@ -25,7 +25,7 @@ #include "config.hpp" #include "utils/environment.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include #include diff --git a/common/utils/fs.cpp b/common/utils/fs.cpp index 354e726..d663831 100644 --- a/common/utils/fs.cpp +++ b/common/utils/fs.cpp @@ -23,7 +23,7 @@ */ #include "config.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "utils/fs.hpp" #include "utils/paths.hpp" #include "utils/exception.hpp" diff --git a/container-daemon/CMakeLists.txt b/container-daemon/CMakeLists.txt index 238af6f..c264a38 100644 --- a/container-daemon/CMakeLists.txt +++ b/container-daemon/CMakeLists.txt @@ -31,7 +31,8 @@ ADD_EXECUTABLE(${CONTAINER_DAEMON_CODENAME} ${project_SRCS} ${common_SRCS}) ## Link libraries ############################################################## FIND_PACKAGE (Boost COMPONENTS program_options system filesystem) -PKG_CHECK_MODULES(CONTAINER_DAEMON_DEPS REQUIRED gio-2.0 libsystemd-journal libcap-ng) +PKG_CHECK_MODULES(CONTAINER_DAEMON_DEPS REQUIRED gio-2.0 libsystemd-journal libcap-ng + libLogger libSimpleDbus libConfig) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) INCLUDE_DIRECTORIES(SYSTEM ${CONTAINER_DAEMON_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(${CONTAINER_DAEMON_CODENAME} ${CONTAINER_DAEMON_DEPS_LIBRARIES} ${Boost_LIBRARIES}) diff --git a/container-daemon/daemon-connection.cpp b/container-daemon/daemon-connection.cpp index 0eb6636..7f4d6b7 100644 --- a/container-daemon/daemon-connection.cpp +++ b/container-daemon/daemon-connection.cpp @@ -28,7 +28,7 @@ #include "daemon-dbus-definitions.hpp" #include "exception.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" namespace security_containers { diff --git a/container-daemon/daemon.cpp b/container-daemon/daemon.cpp index d79762f..6848a09 100644 --- a/container-daemon/daemon.cpp +++ b/container-daemon/daemon.cpp @@ -26,7 +26,7 @@ #include "daemon.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" namespace security_containers { diff --git a/container-daemon/main.cpp b/container-daemon/main.cpp index 8dcdbad..fde059a 100644 --- a/container-daemon/main.cpp +++ b/container-daemon/main.cpp @@ -33,15 +33,15 @@ #include "exception.hpp" #include "runner.hpp" -#include "log/logger.hpp" -#include "log/backend-stderr.hpp" -#include "log/backend-journal.hpp" +#include "logger/logger.hpp" +#include "logger/backend-stderr.hpp" +#include "logger/backend-journal.hpp" #include "utils/typeinfo.hpp" #include #include -using namespace security_containers::log; +using namespace logger; using namespace security_containers; namespace po = boost::program_options; diff --git a/container-daemon/runner.cpp b/container-daemon/runner.cpp index 13d3f21..7b5c93f 100644 --- a/container-daemon/runner.cpp +++ b/container-daemon/runner.cpp @@ -27,7 +27,7 @@ #include "runner.hpp" #include "daemon.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "utils/glib-loop.hpp" #include "utils/latch.hpp" diff --git a/packaging/security-containers.spec b/packaging/security-containers.spec index af4751c..f7a1bdb 100644 --- a/packaging/security-containers.spec +++ b/packaging/security-containers.spec @@ -18,6 +18,9 @@ BuildRequires: boost-devel BuildRequires: libvirt-devel BuildRequires: libjson-devel >= 0.10 BuildRequires: libcap-ng-devel +BuildRequires: pkgconfig(libConfig) +BuildRequires: pkgconfig(libLogger) +BuildRequires: pkgconfig(libSimpleDbus) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libsystemd-journal) BuildRequires: pkgconfig(libvirt-glib-1.0) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 1e639cd..3293307 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -30,7 +30,7 @@ ADD_EXECUTABLE(${SERVER_CODENAME} ${project_SRCS} ${common_SRCS}) ## Link libraries ############################################################## FIND_PACKAGE(Boost COMPONENTS program_options system filesystem regex) PKG_CHECK_MODULES(SERVER_DEPS REQUIRED libvirt libvirt-glib-1.0 json gio-2.0 libsystemd-journal - libcap-ng) + libcap-ng libLogger libSimpleDbus libConfig) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) diff --git a/server/container-admin.cpp b/server/container-admin.cpp index b624817..805e9c1 100644 --- a/server/container-admin.cpp +++ b/server/container-admin.cpp @@ -28,7 +28,7 @@ #include "exception.hpp" #include "libvirt/helpers.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "utils/fs.hpp" #include "utils/latch.hpp" #include "utils/callback-wrapper.hpp" diff --git a/server/container-connection-transport.cpp b/server/container-connection-transport.cpp index 9b8848d..b5bcfb5 100644 --- a/server/container-connection-transport.cpp +++ b/server/container-connection-transport.cpp @@ -29,7 +29,7 @@ #include "utils/file-wait.hpp" #include "utils/fs.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include #include diff --git a/server/container-connection.cpp b/server/container-connection.cpp index 0e96bb2..d3098aa 100644 --- a/server/container-connection.cpp +++ b/server/container-connection.cpp @@ -30,7 +30,7 @@ // TODO: Switch to real power-manager dbus defs when they will be implemented in power-manager #include "fake-power-manager-dbus-definitions.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" namespace security_containers { diff --git a/server/container.cpp b/server/container.cpp index 4284fec..6fcaf77 100644 --- a/server/container.cpp +++ b/server/container.cpp @@ -25,8 +25,9 @@ #include "config.hpp" #include "container.hpp" +#include "base-exception.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "utils/paths.hpp" #include "config/manager.hpp" diff --git a/server/containers-manager.cpp b/server/containers-manager.cpp index 012a8f7..90a6cfc 100644 --- a/server/containers-manager.cpp +++ b/server/containers-manager.cpp @@ -32,9 +32,10 @@ #include "exception.hpp" #include "utils/paths.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "config/manager.hpp" #include "dbus/exception.hpp" +#include "utils/fs.hpp" #include #include diff --git a/server/host-connection.cpp b/server/host-connection.cpp index 83ba8f8..ae32de2 100644 --- a/server/host-connection.cpp +++ b/server/host-connection.cpp @@ -28,7 +28,7 @@ #include "host-dbus-definitions.hpp" #include "exception.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" namespace security_containers { diff --git a/server/input-monitor.cpp b/server/input-monitor.cpp index 13025a5..76dff29 100644 --- a/server/input-monitor.cpp +++ b/server/input-monitor.cpp @@ -28,7 +28,7 @@ #include "input-monitor.hpp" #include "exception.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "utils/exception.hpp" #include "utils/fs.hpp" #include "utils/callback-wrapper.hpp" diff --git a/server/main.cpp b/server/main.cpp index d84a850..bf3da84 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -33,15 +33,15 @@ #include "exception.hpp" #include "server.hpp" -#include "log/logger.hpp" -#include "log/backend-stderr.hpp" -#include "log/backend-journal.hpp" +#include "logger/logger.hpp" +#include "logger/backend-stderr.hpp" +#include "logger/backend-journal.hpp" #include "utils/typeinfo.hpp" #include #include -using namespace security_containers::log; +using namespace logger; using namespace security_containers; namespace po = boost::program_options; diff --git a/server/network-admin.cpp b/server/network-admin.cpp index 38f9b07..763dec0 100644 --- a/server/network-admin.cpp +++ b/server/network-admin.cpp @@ -28,7 +28,7 @@ #include "exception.hpp" #include "libvirt/helpers.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "utils/fs.hpp" #include diff --git a/server/server.cpp b/server/server.cpp index c2fae7d..5c3420d 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -29,9 +29,10 @@ #include "exception.hpp" #include "config/manager.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include "utils/glib-loop.hpp" #include "utils/environment.hpp" +#include "utils/fs.hpp" #include #include diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 30d309b..a82075c 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -35,7 +35,7 @@ ADD_EXECUTABLE(${UT_SERVER_CODENAME} ${project_SRCS} ${common_SRCS} ${server_SRC FIND_PACKAGE (Boost COMPONENTS unit_test_framework system filesystem regex) PKG_CHECK_MODULES(UT_SERVER_DEPS REQUIRED libvirt libvirt-glib-1.0 json gio-2.0 - libsystemd-journal libcap-ng) + libsystemd-journal libcap-ng libLogger libSimpleDbus libConfig) INCLUDE_DIRECTORIES(${COMMON_FOLDER} ${SERVER_FOLDER} ${UNIT_TESTS_FOLDER}) INCLUDE_DIRECTORIES(SYSTEM ${UT_SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES}) diff --git a/tests/unit_tests/config/ut-configuration.cpp b/tests/unit_tests/config/ut-configuration.cpp index 5417e5f..7d304db 100644 --- a/tests/unit_tests/config/ut-configuration.cpp +++ b/tests/unit_tests/config/ut-configuration.cpp @@ -28,8 +28,7 @@ #include "config/fields.hpp" #include "config/manager.hpp" -using namespace security_containers; -using namespace security_containers::config; +using namespace config; BOOST_AUTO_TEST_SUITE(ConfigurationSuite) diff --git a/tests/unit_tests/dbus/test-server.cpp b/tests/unit_tests/dbus/test-server.cpp index 3a77390..bdbda8b 100644 --- a/tests/unit_tests/dbus/test-server.cpp +++ b/tests/unit_tests/dbus/test-server.cpp @@ -29,7 +29,7 @@ #include "dbus/connection.hpp" #include "dbus/exception.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" namespace security_containers { diff --git a/tests/unit_tests/dbus/ut-connection.cpp b/tests/unit_tests/dbus/ut-connection.cpp index 21be1e8..18d4f7b 100644 --- a/tests/unit_tests/dbus/ut-connection.cpp +++ b/tests/unit_tests/dbus/ut-connection.cpp @@ -35,7 +35,7 @@ #include "utils/file-wait.hpp" #include "utils/latch.hpp" #include "utils/fs.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include #include @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_SUITE(DbusSuite) using namespace security_containers; using namespace security_containers::utils; -using namespace security_containers::dbus; +using namespace dbus; namespace { diff --git a/tests/unit_tests/log/ut-logger.cpp b/tests/unit_tests/log/ut-logger.cpp index b4aeb5d..e574505 100644 --- a/tests/unit_tests/log/ut-logger.cpp +++ b/tests/unit_tests/log/ut-logger.cpp @@ -25,16 +25,16 @@ #include "config.hpp" #include "ut.hpp" -#include "log/logger.hpp" -#include "log/formatter.hpp" -#include "log/backend.hpp" -#include "log/backend-stderr.hpp" +#include "logger/logger.hpp" +#include "logger/formatter.hpp" +#include "logger/backend.hpp" +#include "logger/backend-stderr.hpp" #include BOOST_AUTO_TEST_SUITE(LogSuite) -using namespace security_containers::log; +using namespace logger; namespace { diff --git a/tests/unit_tests/server/ut-container-connection.cpp b/tests/unit_tests/server/ut-container-connection.cpp index 29dd310..1a2d153 100644 --- a/tests/unit_tests/server/ut-container-connection.cpp +++ b/tests/unit_tests/server/ut-container-connection.cpp @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_SUITE(ContainerConnectionSuite) using namespace security_containers; using namespace security_containers::utils; -using namespace security_containers::dbus; +using namespace dbus; namespace { diff --git a/tests/unit_tests/server/ut-container.cpp b/tests/unit_tests/server/ut-container.cpp index 7b65c95..e636276 100644 --- a/tests/unit_tests/server/ut-container.cpp +++ b/tests/unit_tests/server/ut-container.cpp @@ -40,7 +40,7 @@ using namespace security_containers; -using namespace security_containers::config; +using namespace config; namespace { diff --git a/tests/unit_tests/server/ut-containers-manager.cpp b/tests/unit_tests/server/ut-containers-manager.cpp index b3ce809..e8dc5de 100644 --- a/tests/unit_tests/server/ut-containers-manager.cpp +++ b/tests/unit_tests/server/ut-containers-manager.cpp @@ -52,9 +52,9 @@ #include using namespace security_containers; -using namespace security_containers::config; +using namespace config; using namespace security_containers::utils; -using namespace security_containers::dbus; +using namespace dbus; namespace { @@ -332,7 +332,7 @@ std::function expectedMessage(const std::string& me } struct Fixture { - utils::ScopedGlibLoop mLoop; + security_containers::utils::ScopedGlibLoop mLoop; }; } // namespace diff --git a/tests/unit_tests/server/ut-server.cpp b/tests/unit_tests/server/ut-server.cpp index d7393b7..74bcede 100644 --- a/tests/unit_tests/server/ut-server.cpp +++ b/tests/unit_tests/server/ut-server.cpp @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_SUITE(ServerSuite) using namespace security_containers; -using namespace security_containers::config; +using namespace config; const std::string TEST_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-server/test-daemon.conf"; const std::string BUGGY_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-server/buggy-daemon.conf"; diff --git a/tests/unit_tests/ut.cpp b/tests/unit_tests/ut.cpp index de98558..194dc9e 100644 --- a/tests/unit_tests/ut.cpp +++ b/tests/unit_tests/ut.cpp @@ -25,14 +25,14 @@ #include "config.hpp" -#include "log/logger.hpp" -#include "log/backend-stderr.hpp" +#include "logger/logger.hpp" +#include "logger/backend-stderr.hpp" #include using namespace boost::unit_test; -using namespace security_containers::log; +using namespace logger; test_suite* init_unit_test_suite(int /*argc*/, char** /*argv*/) { diff --git a/tests/unit_tests/utils/scoped-daemon.cpp b/tests/unit_tests/utils/scoped-daemon.cpp index 077e19a..21fea83 100644 --- a/tests/unit_tests/utils/scoped-daemon.cpp +++ b/tests/unit_tests/utils/scoped-daemon.cpp @@ -26,7 +26,7 @@ #include "utils/scoped-daemon.hpp" -#include "log/logger.hpp" +#include "logger/logger.hpp" #include #include -- 2.7.4