From f93b8129e0803f8c8374bbda05bc6630e67c63cd Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Thu, 9 Apr 2015 10:33:31 +0200 Subject: [PATCH] Host to host communication through IPC (switch to IPC #2) [Feature] Using IPC for host to host communication [Cause] Switching from Dbus to IPC [Solution] Using IPC in host and client [Verification] run ClientSuite tests with Valgrind Change-Id: I45bda31482fbf0a6a1dab7d14cc407bfd73a96c1 --- CMakeLists.txt | 2 + client/CMakeLists.txt | 19 +- client/host-ipc-connection.cpp | 183 ++++++++++++++ client/host-ipc-connection.hpp | 80 ++++++ client/ipc-connection.cpp | 47 ++++ client/ipc-connection.hpp | 90 +++++++ client/vasum-client-impl.cpp | 11 +- client/vasum-client-impl.hpp | 18 +- common/ipc/service.cpp | 14 +- ...ost-connection.cpp => host-dbus-connection.cpp} | 81 +++--- ...ost-connection.hpp => host-dbus-connection.hpp} | 17 +- server/host-ipc-connection.cpp | 272 +++++++++++++++++++++ server/host-ipc-connection.hpp | 119 +++++++++ server/host-ipc-definitions.hpp | 68 ++++++ server/zones-manager.cpp | 12 +- server/zones-manager.hpp | 11 +- 16 files changed, 977 insertions(+), 67 deletions(-) create mode 100644 client/host-ipc-connection.cpp create mode 100644 client/host-ipc-connection.hpp create mode 100644 client/ipc-connection.cpp create mode 100644 client/ipc-connection.hpp rename server/{host-connection.cpp => host-dbus-connection.cpp} (83%) rename server/{host-connection.hpp => host-dbus-connection.hpp} (97%) create mode 100644 server/host-ipc-connection.cpp create mode 100644 server/host-ipc-connection.hpp create mode 100644 server/host-ipc-definitions.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 743860b..e7f7aff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,8 @@ ADD_DEFINITIONS(-DVASUM_USER="${VASUM_USER}") ADD_DEFINITIONS(-DINPUT_EVENT_GROUP="${INPUT_EVENT_GROUP}") ADD_DEFINITIONS(-DDISK_GROUP="${DISK_GROUP}") ADD_DEFINITIONS(-DTTY_GROUP="${TTY_GROUP}") +ADD_DEFINITIONS(-DHOST_IPC_SOCKET="/var/run/vasum-ipc.socket") +#ADD_DEFINITIONS(-DDBUS_CONNECTION) ## Python packages directory ################################################### IF(NOT DEFINED PYTHON_SITELIB) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 7198610..0ebbf75 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -25,7 +25,17 @@ FILE(GLOB common_SRCS ${COMMON_FOLDER}/utils/callback-guard.hpp ${COMMON_FOLDER}/utils/glib-loop.cpp ${COMMON_FOLDER}/utils/glib-loop.hpp ${COMMON_FOLDER}/base-exception.hpp - ${COMMON_FOLDER}/base-exception.cpp) + ${COMMON_FOLDER}/base-exception.cpp + ${COMMON_FOLDER}/utils/eventfd.hpp + ${COMMON_FOLDER}/utils/eventfd.cpp + ${COMMON_FOLDER}/utils/fd-utils.hpp + ${COMMON_FOLDER}/utils/fd-utils.cpp + ${COMMON_FOLDER}/epoll/*.hpp + ${COMMON_FOLDER}/epoll/*.cpp + ${COMMON_FOLDER}/ipc/*.hpp + ${COMMON_FOLDER}/ipc/*.cpp + ${COMMON_FOLDER}/ipc/internals/*.hpp + ${COMMON_FOLDER}/ipc/internals/*.cpp) SET(_LIB_VERSION_ "0.0.1") SET(_LIB_SOVERSION_ "0") @@ -44,11 +54,12 @@ SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY VERSION ${_LIB_VERSION_}) ## Link libraries ############################################################## -PKG_CHECK_MODULES(LIB_DEPS REQUIRED gio-2.0 libSimpleDbus libLogger libConfig) -INCLUDE_DIRECTORIES(SYSTEM ${LIB_DEPS_INCLUDE_DIRS}) +FIND_PACKAGE(Boost COMPONENTS system filesystem) +PKG_CHECK_MODULES(LIB_DEPS REQUIRED gio-2.0 libSimpleDbus libLogger libConfig libsystemd-daemon) +INCLUDE_DIRECTORIES(SYSTEM ${LIB_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) INCLUDE_DIRECTORIES(${SERVER_FOLDER}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIB_DEPS_LIBRARIES}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIB_DEPS_LIBRARIES} ${Boost_LIBRARIES}) ## Generate the pc file ######################################################## CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY) diff --git a/client/host-ipc-connection.cpp b/client/host-ipc-connection.cpp new file mode 100644 index 0000000..6a22e6b --- /dev/null +++ b/client/host-ipc-connection.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 Mateusz Malicki (m.malicki2@samsung.com) + * @brief HostIPCConnection class + */ + +#include +#include "host-ipc-connection.hpp" +#include +#include + +namespace vasum { +namespace client { + +void HostIPCConnection::createSystem() +{ + mConnection.createSystem(); +} + +void HostIPCConnection::callGetZoneIds(vasum::api::ZoneIds& argOut) +{ + mConnection.call(vasum::api::host::METHOD_GET_ZONE_ID_LIST, argOut); +} + +void HostIPCConnection::callGetActiveZoneId(vasum::api::ZoneId& argOut) +{ + mConnection.call(vasum::api::host::METHOD_GET_ACTIVE_ZONE_ID, argOut); +} + +void HostIPCConnection::callSetActiveZone(const vasum::api::ZoneId& argIn) +{ + mConnection.call(vasum::api::host::METHOD_SET_ACTIVE_ZONE, argIn); +} + +void HostIPCConnection::callGetZoneInfo(const vasum::api::ZoneId& argIn, vasum::api::ZoneInfoOut& argOut) +{ + mConnection.call(vasum::api::host::METHOD_GET_ZONE_INFO, argIn, argOut); +} + +void HostIPCConnection::callSetNetdevAttrs(const vasum::api::SetNetDevAttrsIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_SET_NETDEV_ATTRS, argIn); +} + +void HostIPCConnection::callGetNetdevAttrs(const vasum::api::GetNetDevAttrsIn& argIn, vasum::api::GetNetDevAttrs& argOut) +{ + mConnection.call(vasum::api::host::METHOD_GET_NETDEV_ATTRS, argIn, argOut); +} + +void HostIPCConnection::callGetNetdevList(const vasum::api::ZoneId& argIn, vasum::api::NetDevList& argOut) +{ + mConnection.call(vasum::api::host::METHOD_GET_NETDEV_LIST, argIn, argOut); +} + +void HostIPCConnection::callCreateNetdevVeth(const vasum::api::CreateNetDevVethIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_CREATE_NETDEV_VETH, argIn); +} + +void HostIPCConnection::callCreateNetdevMacvlan(const vasum::api::CreateNetDevMacvlanIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_CREATE_NETDEV_MACVLAN, argIn); +} + +void HostIPCConnection::callCreateNetdevPhys(const vasum::api::CreateNetDevPhysIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_CREATE_NETDEV_PHYS, argIn); +} + +void HostIPCConnection::callDestroyNetdev(const vasum::api::DestroyNetDevIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_DESTROY_NETDEV, argIn); +} + +void HostIPCConnection::callDeleteNetdevIpAddress(const vasum::api::DeleteNetdevIpAddressIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_DELETE_NETDEV_IP_ADDRESS, argIn); +} + +void HostIPCConnection::callDeclareFile(const vasum::api::DeclareFileIn& argIn, vasum::api::Declaration& argOut) +{ + mConnection.call(vasum::api::host::METHOD_DECLARE_FILE, argIn, argOut); +} + +void HostIPCConnection::callDeclareMount(const vasum::api::DeclareMountIn& argIn, vasum::api::Declaration& argOut) +{ + mConnection.call(vasum::api::host::METHOD_DECLARE_MOUNT, argIn, argOut); +} + +void HostIPCConnection::callDeclareLink(const vasum::api::DeclareLinkIn& argIn, vasum::api::Declaration& argOut) +{ + mConnection.call(vasum::api::host::METHOD_DECLARE_LINK, argIn, argOut); +} + +void HostIPCConnection::callGetDeclarations(const vasum::api::ZoneId& argIn, vasum::api::Declarations& argOut) +{ + mConnection.call(vasum::api::host::METHOD_GET_DECLARATIONS, argIn, argOut); +} + +void HostIPCConnection::callRemoveDeclaration(const vasum::api::RemoveDeclarationIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_REMOVE_DECLARATION, argIn); +} + +void HostIPCConnection::callCreateZone(const vasum::api::CreateZoneIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_CREATE_ZONE, argIn); +} + +void HostIPCConnection::callDestroyZone(const vasum::api::ZoneId& argIn) +{ + mConnection.call(vasum::api::host::METHOD_DESTROY_ZONE, argIn); +} + +void HostIPCConnection::callShutdownZone(const vasum::api::ZoneId& argIn) +{ + mConnection.call(vasum::api::host::METHOD_SHUTDOWN_ZONE, argIn); +} + +void HostIPCConnection::callStartZone(const vasum::api::ZoneId& argIn) +{ + mConnection.call(vasum::api::host::METHOD_START_ZONE, argIn); +} + +void HostIPCConnection::callLockZone(const vasum::api::ZoneId& argIn) +{ + mConnection.call(vasum::api::host::METHOD_LOCK_ZONE, argIn); +} + +void HostIPCConnection::callUnlockZone(const vasum::api::ZoneId& argIn) +{ + mConnection.call(vasum::api::host::METHOD_UNLOCK_ZONE, argIn); +} + +void HostIPCConnection::callGrantDevice(const vasum::api::GrantDeviceIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_GRANT_DEVICE, argIn); +} + +void HostIPCConnection::callRevokeDevice(const vasum::api::RevokeDeviceIn& argIn) +{ + mConnection.call(vasum::api::host::METHOD_REVOKE_DEVICE, argIn); +} + +void HostIPCConnection::callGetZoneDbuses(vasum::api::Dbuses& argOut) +{ + mConnection.call(vasum::api::host::METHOD_GET_ZONE_DBUSES, argOut); +} + +HostIPCConnection::SubscriptionId +HostIPCConnection::subscribeZoneDbusState(const ZoneDbusStateCallback& callback) +{ + mConnection.subscribe( + vasum::api::host::SIGNAL_ZONE_DBUS_STATE, callback); + return vasum::api::host::SIGNAL_ZONE_DBUS_STATE; +} + +void HostIPCConnection::unsubscribe(const SubscriptionId& id) +{ + mConnection.unsubscribe(id); +} + +} // namespace client +} // namespace vasum diff --git a/client/host-ipc-connection.hpp b/client/host-ipc-connection.hpp new file mode 100644 index 0000000..83313e1 --- /dev/null +++ b/client/host-ipc-connection.hpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 Mateusz Malicki (m.malicki2@samsung.com) + * @brief HostIPCConnection class + */ + +#ifndef VASUM_CLIENT_HOST_IPC_CONNECTION_HPP +#define VASUM_CLIENT_HOST_IPC_CONNECTION_HPP + +#include "ipc-connection.hpp" +#include + +namespace vasum { +namespace client { + +/** + * HostIPCConnection is used for communication with the vasum's server from host through ipc + */ +class HostIPCConnection { +public: + typedef unsigned int SubscriptionId; + typedef std::function ZoneDbusStateCallback; + void createSystem(); + + void callGetZoneIds(vasum::api::ZoneIds& argOut); + void callGetActiveZoneId(vasum::api::ZoneId& argOut); + void callSetActiveZone(const vasum::api::ZoneId& argIn); + void callGetZoneInfo(const vasum::api::ZoneId& argIn, vasum::api::ZoneInfoOut& argOut); + void callSetNetdevAttrs(const vasum::api::SetNetDevAttrsIn& argIn); + void callGetNetdevAttrs(const vasum::api::GetNetDevAttrsIn& argIn, vasum::api::GetNetDevAttrs& argOut); + void callGetNetdevList(const vasum::api::ZoneId& argIn, vasum::api::NetDevList& argOut); + void callCreateNetdevVeth(const vasum::api::CreateNetDevVethIn& argIn); + void callCreateNetdevMacvlan(const vasum::api::CreateNetDevMacvlanIn& argIn); + void callCreateNetdevPhys(const vasum::api::CreateNetDevPhysIn& argIn); + void callDestroyNetdev(const vasum::api::DestroyNetDevIn& argIn); + void callDeleteNetdevIpAddress(const vasum::api::DeleteNetdevIpAddressIn& argIn); + void callDeclareFile(const vasum::api::DeclareFileIn& argIn, vasum::api::Declaration& argOut); + void callDeclareMount(const vasum::api::DeclareMountIn& argIn, vasum::api::Declaration& argOut); + void callDeclareLink(const vasum::api::DeclareLinkIn& argIn, vasum::api::Declaration& argOut); + void callGetDeclarations(const vasum::api::ZoneId& argIn, vasum::api::Declarations& argOut); + void callRemoveDeclaration(const vasum::api::RemoveDeclarationIn& argIn); + void callCreateZone(const vasum::api::CreateZoneIn& argIn); + void callDestroyZone(const vasum::api::ZoneId& argIn); + void callShutdownZone(const vasum::api::ZoneId& argIn); + void callStartZone(const vasum::api::ZoneId& argIn); + void callLockZone(const vasum::api::ZoneId& argIn); + void callUnlockZone(const vasum::api::ZoneId& argIn); + void callGrantDevice(const vasum::api::GrantDeviceIn& argIn); + void callRevokeDevice(const vasum::api::RevokeDeviceIn& argIn); + void callGetZoneDbuses(vasum::api::Dbuses& argOut); + SubscriptionId subscribeZoneDbusState(const ZoneDbusStateCallback& callback); + void unsubscribe(const SubscriptionId& id); + +private: + IPCConnection mConnection; +}; + +} // namespace client +} // namespace vasum + +#endif /* VASUM_CLIENT_HOST_IPC_CONNECTION_HPP */ diff --git a/client/ipc-connection.cpp b/client/ipc-connection.cpp new file mode 100644 index 0000000..04954bc --- /dev/null +++ b/client/ipc-connection.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 Mateusz Malicki (m.malicki2@samsung.com) + * @brief IPCConnection class + */ + +#include +#include "ipc-connection.hpp" + +namespace { + +const std::string SOCKET_PATH = HOST_IPC_SOCKET; + +} // namespace + +vasum::client::IPCConnection::IPCConnection() +{ +} + +vasum::client::IPCConnection::~IPCConnection() +{ +} + +void vasum::client::IPCConnection::createSystem() +{ + mClient.reset(new ipc::Client(mDispatcher.getPoll(), SOCKET_PATH)); + mClient->start(); +} diff --git a/client/ipc-connection.hpp b/client/ipc-connection.hpp new file mode 100644 index 0000000..1cb4d10 --- /dev/null +++ b/client/ipc-connection.hpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 Mateusz Malicki (m.malicki2@samsung.com) + * @brief IPCConnection class + */ + +#ifndef VASUM_CLIENT_IPC_CONNECTION_HPP +#define VASUM_CLIENT_IPC_CONNECTION_HPP + +#include +#include +#include +#include +#include +#include + +namespace vasum { +namespace client { + +/** + * IPCConnection class + */ +class IPCConnection { +public: + IPCConnection(); + virtual ~IPCConnection(); + + void createSystem(); + + template + typename std::enable_if::value>::type + call(const ipc::MethodID method, const ArgIn& argIn, ArgOut& argOut, unsigned int timeout = 50000) { + auto out = mClient->callSync(method, std::make_shared(argIn), timeout); + argOut = *out; + } + + template + typename std::enable_if::value>::type + call(const ipc::MethodID method, ArgOut& argOut, unsigned int timeout = 50000) { + vasum::api::Void argIn; + call(method, argIn, argOut, timeout); + } + + template + typename std::enable_if::value>::type + call(const ipc::MethodID method, ArgIn& argIn, unsigned int timeout = 50000) { + vasum::api::Void argOut; + call(method, argIn, argOut, timeout); + } + + template + void subscribe(const ipc::MethodID signal, const Callback& callback) { + auto callbackWrapper = [callback] (const ipc::PeerID, std::shared_ptr& data) { + callback(*data); + }; + mClient->setSignalHandler(signal, callbackWrapper); + } + + void unsubscribe(const ipc::MethodID signal) { + mClient->removeMethod(signal); + } + +private: + epoll::ThreadDispatcher mDispatcher; + std::unique_ptr mClient; +}; + +} // namespace client +} // namespace vasum + +#endif /* VASUM_CLIENT_IPC_CONNECTION_HPP */ diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index 41a0030..2d85fb0 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -28,6 +28,7 @@ #include "utils.hpp" #include "exception.hpp" #include "host-dbus-connection.hpp" +#include "host-ipc-connection.hpp" #include "zone-dbus-connection.hpp" #include @@ -182,7 +183,7 @@ Client::~Client() noexcept { } -VsmStatus Client::coverException(const function worker) noexcept +VsmStatus Client::coverException(const function& worker) noexcept { try { worker(); @@ -218,7 +219,11 @@ VsmStatus Client::createSystem() noexcept return coverException([&] { shared_ptr connection(dbus::DbusConnection::createSystem().release()); +#ifdef DBUS_CONNECTION mHostClient.create(connection); +#else + mHostClient.createSystem(); +#endif mZoneClient.create(connection); }); } @@ -228,7 +233,11 @@ VsmStatus Client::create(const string& address) noexcept return coverException([&] { shared_ptr connection(dbus::DbusConnection::create(address).release()); +#ifdef DBUS_CONNECTION mHostClient.create(connection); +#else + mHostClient.createSystem(); +#endif mZoneClient.create(connection); }); } diff --git a/client/vasum-client-impl.hpp b/client/vasum-client-impl.hpp index 634b801..9e8118c 100644 --- a/client/vasum-client-impl.hpp +++ b/client/vasum-client-impl.hpp @@ -27,8 +27,11 @@ #define VASUM_CLIENT_IMPL_HPP #include "vasum-client.h" - +#ifdef DBUS_CONNECTION #include "host-dbus-connection.hpp" +#else +#include "host-ipc-connection.hpp" +#endif #include "zone-dbus-connection.hpp" #include @@ -321,6 +324,12 @@ public: */ static VsmStatus vsm_stop_glib_loop() noexcept; private: +#ifdef DBUS_CONNECTION + typedef vasum::client::HostDbusConnection HostConnection; +#else + typedef vasum::client::HostIPCConnection HostConnection; +#endif + typedef vasum::client::ZoneDbusConnection ZoneConnection; struct Status { Status(); Status(VsmStatus status, const std::string& msg = ""); @@ -329,10 +338,11 @@ private: }; Status mStatus; - vasum::client::HostDbusConnection mHostClient; - vasum::client::ZoneDbusConnection mZoneClient; - VsmStatus coverException(const std::function worker) noexcept; + HostConnection mHostClient; + ZoneConnection mZoneClient; + + VsmStatus coverException(const std::function& worker) noexcept; VsmStatus vsm_netdev_get_ip_addr(const char* zone, const char* netdevId, int type, diff --git a/common/ipc/service.cpp b/common/ipc/service.cpp index 849ce3c..d4e1b88 100644 --- a/common/ipc/service.cpp +++ b/common/ipc/service.cpp @@ -100,13 +100,17 @@ void Service::handle(const FileDescriptor fd, const epoll::Events pollEvents) return; } - if (pollEvents & EPOLLIN) { - mProcessor.handleInput(fd); - return; // because handleInput will handle RDHUP - } - if ((pollEvents & EPOLLHUP) || (pollEvents & EPOLLRDHUP)) { + //IN, HUP, RDHUP are set when client is disconnecting but there is 0 bytes to read, so + //assume that if IN and HUP or RDHUP are set then input data is garbage. + //Assumption is harmless because handleInput processes all message data. mProcessor.handleLostConnection(fd); + return; + } + + if (pollEvents & EPOLLIN) { + //Process all message data + mProcessor.handleInput(fd); } } diff --git a/server/host-connection.cpp b/server/host-dbus-connection.cpp similarity index 83% rename from server/host-connection.cpp rename to server/host-dbus-connection.cpp index 1bdd790..b3eb19d 100644 --- a/server/host-connection.cpp +++ b/server/host-dbus-connection.cpp @@ -24,7 +24,7 @@ #include "config.hpp" -#include "host-connection.hpp" +#include "host-dbus-connection.hpp" #include "host-dbus-definitions.hpp" #include "exception.hpp" #include "api/dbus-method-result-builder.hpp" @@ -45,7 +45,7 @@ const unsigned int NAME_ACQUIRED_TIMEOUT = 5 * 1000; } // namespace -HostConnection::HostConnection() +HostDbusConnection::HostDbusConnection() : mNameAcquired(false) , mNameLost(false) { @@ -54,8 +54,8 @@ HostConnection::HostConnection() LOGT("Setting DBUS name"); mDbusConnection->setName(api::host::BUS_NAME, - std::bind(&HostConnection::onNameAcquired, this), - std::bind(&HostConnection::onNameLost, this)); + std::bind(&HostDbusConnection::onNameAcquired, this), + std::bind(&HostDbusConnection::onNameLost, this)); if (!waitForName(NAME_ACQUIRED_TIMEOUT)) { LOGE("Could not acquire dbus name: " << api::host::BUS_NAME); @@ -66,17 +66,17 @@ HostConnection::HostConnection() using namespace std::placeholders; mDbusConnection->registerObject(api::host::OBJECT_PATH, api::host::DEFINITION, - std::bind(&HostConnection::onMessageCall, + std::bind(&HostDbusConnection::onMessageCall, this, _1, _2, _3, _4, _5)); LOGD("Connected"); } -HostConnection::~HostConnection() +HostDbusConnection::~HostDbusConnection() { } -bool HostConnection::waitForName(const unsigned int timeoutMs) +bool HostDbusConnection::waitForName(const unsigned int timeoutMs) { std::unique_lock lock(mNameMutex); mNameCondition.wait_for(lock, @@ -88,14 +88,14 @@ bool HostConnection::waitForName(const unsigned int timeoutMs) return mNameAcquired; } -void HostConnection::onNameAcquired() +void HostDbusConnection::onNameAcquired() { std::unique_lock lock(mNameMutex); mNameAcquired = true; mNameCondition.notify_one(); } -void HostConnection::onNameLost() +void HostDbusConnection::onNameLost() { std::unique_lock lock(mNameMutex); mNameLost = true; @@ -107,143 +107,143 @@ void HostConnection::onNameLost() } } -void HostConnection::setProxyCallCallback(const ProxyCallCallback& callback) +void HostDbusConnection::setProxyCallCallback(const ProxyCallCallback& callback) { mProxyCallCallback = callback; } -void HostConnection::setGetZoneDbusesCallback(const GetZoneDbusesCallback& callback) +void HostDbusConnection::setGetZoneDbusesCallback(const GetZoneDbusesCallback& callback) { mGetZoneDbusesCallback = callback; } -void HostConnection::setGetZoneIdsCallback(const GetZoneIdsCallback& callback) +void HostDbusConnection::setGetZoneIdsCallback(const GetZoneIdsCallback& callback) { mGetZoneIdsCallback = callback; } -void HostConnection::setGetActiveZoneIdCallback(const GetActiveZoneIdCallback& callback) +void HostDbusConnection::setGetActiveZoneIdCallback(const GetActiveZoneIdCallback& callback) { mGetActiveZoneIdCallback = callback; } -void HostConnection::setGetZoneInfoCallback(const GetZoneInfoCallback& callback) +void HostDbusConnection::setGetZoneInfoCallback(const GetZoneInfoCallback& callback) { mGetZoneInfoCallback = callback; } -void HostConnection::setSetNetdevAttrsCallback(const SetNetdevAttrsCallback& callback) +void HostDbusConnection::setSetNetdevAttrsCallback(const SetNetdevAttrsCallback& callback) { mSetNetdevAttrsCallback = callback; } -void HostConnection::setGetNetdevAttrsCallback(const GetNetdevAttrsCallback& callback) +void HostDbusConnection::setGetNetdevAttrsCallback(const GetNetdevAttrsCallback& callback) { mGetNetdevAttrsCallback = callback; } -void HostConnection::setGetNetdevListCallback(const GetNetdevListCallback& callback) +void HostDbusConnection::setGetNetdevListCallback(const GetNetdevListCallback& callback) { mGetNetdevListCallback = callback; } -void HostConnection::setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback) +void HostDbusConnection::setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback) { mCreateNetdevVethCallback = callback; } -void HostConnection::setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback) +void HostDbusConnection::setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback) { mCreateNetdevMacvlanCallback = callback; } -void HostConnection::setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback) +void HostDbusConnection::setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback) { mCreateNetdevPhysCallback = callback; } -void HostConnection::setDestroyNetdevCallback(const DestroyNetdevCallback& callback) +void HostDbusConnection::setDestroyNetdevCallback(const DestroyNetdevCallback& callback) { mDestroyNetdevCallback = callback; } -void HostConnection::setDeleleNetdevIpAddressCallback(const DeleteNetdevIpAddressCallback& callback) +void HostDbusConnection::setDeleteNetdevIpAddressCallback(const DeleteNetdevIpAddressCallback& callback) { mDeleteNetdevIpAddressCallback = callback; } -void HostConnection::setDeclareFileCallback(const DeclareFileCallback& callback) +void HostDbusConnection::setDeclareFileCallback(const DeclareFileCallback& callback) { mDeclareFileCallback = callback; } -void HostConnection::setDeclareMountCallback(const DeclareMountCallback& callback) +void HostDbusConnection::setDeclareMountCallback(const DeclareMountCallback& callback) { mDeclareMountCallback = callback; } -void HostConnection::setDeclareLinkCallback(const DeclareLinkCallback& callback) +void HostDbusConnection::setDeclareLinkCallback(const DeclareLinkCallback& callback) { mDeclareLinkCallback = callback; } -void HostConnection::setGetDeclarationsCallback(const GetDeclarationsCallback& callback) +void HostDbusConnection::setGetDeclarationsCallback(const GetDeclarationsCallback& callback) { mGetDeclarationsCallback = callback; } -void HostConnection::setRemoveDeclarationCallback(const RemoveDeclarationCallback& callback) +void HostDbusConnection::setRemoveDeclarationCallback(const RemoveDeclarationCallback& callback) { mRemoveDeclarationCallback = callback; } -void HostConnection::setSetActiveZoneCallback(const SetActiveZoneCallback& callback) +void HostDbusConnection::setSetActiveZoneCallback(const SetActiveZoneCallback& callback) { mSetActiveZoneCallback = callback; } -void HostConnection::setCreateZoneCallback(const CreateZoneCallback& callback) +void HostDbusConnection::setCreateZoneCallback(const CreateZoneCallback& callback) { mCreateZoneCallback = callback; } -void HostConnection::setDestroyZoneCallback(const DestroyZoneCallback& callback) +void HostDbusConnection::setDestroyZoneCallback(const DestroyZoneCallback& callback) { mDestroyZoneCallback = callback; } -void HostConnection::setShutdownZoneCallback(const ShutdownZoneCallback& callback) +void HostDbusConnection::setShutdownZoneCallback(const ShutdownZoneCallback& callback) { mShutdownZoneCallback = callback; } -void HostConnection::setStartZoneCallback(const StartZoneCallback& callback) +void HostDbusConnection::setStartZoneCallback(const StartZoneCallback& callback) { mStartZoneCallback = callback; } -void HostConnection::setLockZoneCallback(const LockZoneCallback& callback) +void HostDbusConnection::setLockZoneCallback(const LockZoneCallback& callback) { mLockZoneCallback = callback; } -void HostConnection::setUnlockZoneCallback(const UnlockZoneCallback& callback) +void HostDbusConnection::setUnlockZoneCallback(const UnlockZoneCallback& callback) { mUnlockZoneCallback = callback; } -void HostConnection::setGrantDeviceCallback(const GrantDeviceCallback& callback) +void HostDbusConnection::setGrantDeviceCallback(const GrantDeviceCallback& callback) { mGrantDeviceCallback = callback; } -void HostConnection::setRevokeDeviceCallback(const RevokeDeviceCallback& callback) +void HostDbusConnection::setRevokeDeviceCallback(const RevokeDeviceCallback& callback) { mRevokeDeviceCallback = callback; } -void HostConnection::onMessageCall(const std::string& objectPath, +void HostDbusConnection::onMessageCall(const std::string& objectPath, const std::string& interface, const std::string& methodName, GVariant* parameters, @@ -553,7 +553,7 @@ void HostConnection::onMessageCall(const std::string& objectPath, } } -void HostConnection::proxyCallAsync(const std::string& busName, +void HostDbusConnection::proxyCallAsync(const std::string& busName, const std::string& objectPath, const std::string& interface, const std::string& method, @@ -569,10 +569,9 @@ void HostConnection::proxyCallAsync(const std::string& busName, callback); } -void HostConnection::signalZoneDbusState(const std::string& zoneId, - const std::string& dbusAddress) +void HostDbusConnection::signalZoneDbusState(const api::DbusState& state) { - GVariant* parameters = g_variant_new("(ss)", zoneId.c_str(), dbusAddress.c_str()); + GVariant* parameters = g_variant_new("(ss)", state.first.c_str(), state.second.c_str()); mDbusConnection->emitSignal(api::host::OBJECT_PATH, api::host::INTERFACE, api::host::SIGNAL_ZONE_DBUS_STATE, diff --git a/server/host-connection.hpp b/server/host-dbus-connection.hpp similarity index 97% rename from server/host-connection.hpp rename to server/host-dbus-connection.hpp index 4ad07c8..980b5e9 100644 --- a/server/host-connection.hpp +++ b/server/host-dbus-connection.hpp @@ -23,13 +23,14 @@ */ -#ifndef SERVER_HOST_CONNECTION_HPP -#define SERVER_HOST_CONNECTION_HPP +#ifndef SERVER_HOST_DBUS_CONNECTION_HPP +#define SERVER_HOST_DBUS_CONNECTION_HPP #include "dbus/connection.hpp" #include "api/method-result-builder.hpp" #include "api/messages.hpp" +#include #include #include #include @@ -39,11 +40,11 @@ namespace vasum { -class HostConnection { +class HostDbusConnection { public: - HostConnection(); - ~HostConnection(); + HostDbusConnection(); + ~HostDbusConnection(); // ------------- API -------------- @@ -144,7 +145,7 @@ public: /** * Send signal describing dbus address state change */ - void signalZoneDbusState(const std::string& zoneId, const std::string& dbusAddress); + void signalZoneDbusState(const api::DbusState& state); /** * Register a callback called to get a list of zone ids @@ -199,7 +200,7 @@ public: /** * Register a callback called to remove ip address from netdev */ - void setDeleleNetdevIpAddressCallback(const DeleteNetdevIpAddressCallback& callback); + void setDeleteNetdevIpAddressCallback(const DeleteNetdevIpAddressCallback& callback); /** * Register a callback called to declare file @@ -330,4 +331,4 @@ private: } // namespace vasum -#endif // SERVER_HOST_CONNECTION_HPP +#endif // SERVER_HOST_DBUS_CONNECTION_HPP diff --git a/server/host-ipc-connection.cpp b/server/host-ipc-connection.cpp new file mode 100644 index 0000000..bb8d081 --- /dev/null +++ b/server/host-ipc-connection.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 Mateusz Malicki (m.malicki2@samsung.com) + * @brief HostIPCConnection class + */ + +#include "config.hpp" + +#include "host-ipc-connection.hpp" +#include "host-ipc-definitions.hpp" +#include "exception.hpp" +#include "logger/logger.hpp" + +namespace vasum { + +namespace { + +const std::string SOCKET_PATH = HOST_IPC_SOCKET; + +} // namespace + + +HostIPCConnection::HostIPCConnection() +{ + LOGT("Connecting to host IPC socket"); + mService.reset(new ipc::Service(mDispatcher.getPoll(), SOCKET_PATH)); + + LOGT("Starting IPC"); + mService->start(); + LOGD("Connected"); +} + +HostIPCConnection::~HostIPCConnection() +{ +} + +void HostIPCConnection::setGetZoneDbusesCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GET_ZONE_DBUSES, + Callback::getCallbackWrapper(callback)); + +} + +void HostIPCConnection::setGetZoneIdsCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GET_ZONE_ID_LIST, + Callback::getCallbackWrapper(callback)); + +} + +void HostIPCConnection::setGetActiveZoneIdCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GET_ACTIVE_ZONE_ID, + Callback::getCallbackWrapper(callback)); + +} + +void HostIPCConnection::setGetZoneInfoCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GET_ZONE_INFO, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setSetNetdevAttrsCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_SET_NETDEV_ATTRS, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setGetNetdevAttrsCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GET_NETDEV_ATTRS, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setGetNetdevListCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GET_NETDEV_LIST, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setCreateNetdevVethCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_CREATE_NETDEV_VETH, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setCreateNetdevMacvlanCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_CREATE_NETDEV_MACVLAN, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setCreateNetdevPhysCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_CREATE_NETDEV_PHYS, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setDestroyNetdevCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_DESTROY_NETDEV, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setDeleteNetdevIpAddressCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_DELETE_NETDEV_IP_ADDRESS, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setDeclareFileCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_DECLARE_FILE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setDeclareMountCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_DECLARE_MOUNT, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setDeclareLinkCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_DECLARE_LINK, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setGetDeclarationsCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GET_DECLARATIONS, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setRemoveDeclarationCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_REMOVE_DECLARATION, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setSetActiveZoneCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_SET_ACTIVE_ZONE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setCreateZoneCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_CREATE_ZONE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setDestroyZoneCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_DESTROY_ZONE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setShutdownZoneCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_SHUTDOWN_ZONE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setStartZoneCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_START_ZONE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setLockZoneCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_LOCK_ZONE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setUnlockZoneCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_UNLOCK_ZONE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setGrantDeviceCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_GRANT_DEVICE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::setRevokeDeviceCallback(const Callback::type& callback) +{ + typedef Callback Callback; + mService->setMethodHandler( + api::host::METHOD_REVOKE_DEVICE, + Callback::getCallbackWrapper(callback)); +} + +void HostIPCConnection::signalZoneDbusState(const api::DbusState& dbusState) +{ + mService->signal(api::host::SIGNAL_ZONE_DBUS_STATE, + std::make_shared(dbusState)); +} + +} // namespace vasum diff --git a/server/host-ipc-connection.hpp b/server/host-ipc-connection.hpp new file mode 100644 index 0000000..e8c1c8d --- /dev/null +++ b/server/host-ipc-connection.hpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 Mateusz Malicki (m.malicki2@samsung.com) + * @brief HostIPCConnection class + */ + + +#ifndef SERVER_HOST_IPC_CONNECTION_HPP +#define SERVER_HOST_IPC_CONNECTION_HPP + +#include "api/messages.hpp" +#include "api/method-result-builder.hpp" +#include "api/ipc-method-result-builder.hpp" +#include "epoll/thread-dispatcher.hpp" +#include "ipc/service.hpp" + +#include + +namespace vasum { + + + +class HostIPCConnection { +public: + template + class Callback { + public: + typedef typename std::remove_cv::type in; + typedef ArgOut out; + typedef std::function type; + + static typename ipc::MethodHandler::type + getCallbackWrapper(const type& callback) { + return [callback](const ipc::PeerID, + const std::shared_ptr& argIn, + ipc::MethodResult::Pointer&& argOut) + { + auto rb = std::make_shared(argOut); + callback(*argIn, rb); + }; + } + }; + + template + class Callback::value, api::Void>::type> { + public: + typedef api::Void in; + typedef ArgOut out; + typedef std::function type; + + static typename ipc::MethodHandler::type + getCallbackWrapper(const type& callback) { + return [callback](const ipc::PeerID, + const std::shared_ptr& /* argIn */, + ipc::MethodResult::Pointer&& argOut) + { + auto rb = std::make_shared(argOut); + callback(rb); + }; + } + }; + + HostIPCConnection(); + ~HostIPCConnection(); + + void setGetZoneDbusesCallback(const Callback::type& callback); + void setGetZoneIdsCallback(const Callback::type& callback); + void setGetActiveZoneIdCallback(const Callback::type& callback); + void setGetZoneInfoCallback(const Callback::type& callback); + void setSetNetdevAttrsCallback(const Callback::type& callback); + void setGetNetdevAttrsCallback(const Callback::type& callback); + void setGetNetdevListCallback(const Callback::type& callback); + void setCreateNetdevVethCallback(const Callback::type& callback); + void setCreateNetdevMacvlanCallback(const Callback::type& callback); + void setCreateNetdevPhysCallback(const Callback::type& callback); + void setDestroyNetdevCallback(const Callback::type& callback); + void setDeleteNetdevIpAddressCallback(const Callback::type& callback); + void setDeclareFileCallback(const Callback::type& callback); + void setDeclareMountCallback(const Callback::type& callback); + void setDeclareLinkCallback(const Callback::type& callback); + void setGetDeclarationsCallback(const Callback::type& callback); + void setRemoveDeclarationCallback(const Callback::type& callback); + void setSetActiveZoneCallback(const Callback::type& callback); + void setCreateZoneCallback(const Callback::type& callback); + void setDestroyZoneCallback(const Callback::type& callback); + void setShutdownZoneCallback(const Callback::type& callback); + void setStartZoneCallback(const Callback::type& callback); + void setLockZoneCallback(const Callback::type& callback); + void setUnlockZoneCallback(const Callback::type& callback); + void setGrantDeviceCallback(const Callback::type& callback); + void setRevokeDeviceCallback(const Callback::type& callback); + void signalZoneDbusState(const api::DbusState& dbusState); + +private: + epoll::ThreadDispatcher mDispatcher; + std::unique_ptr mService; +}; + +} // namespace vasum + +#endif // SERVER_HOST_IPC_CONNECTION_HPP diff --git a/server/host-ipc-definitions.hpp b/server/host-ipc-definitions.hpp new file mode 100644 index 0000000..4cd06e7 --- /dev/null +++ b/server/host-ipc-definitions.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 Mateusz Malicki (m.malicki2@samsung.com) + * @brief Host ipc api definitions + */ + +#ifndef SERVER_HOST_IPC_DEFINITIONS_HPP +#define SERVER_HOST_IPC_DEFINITIONS_HPP + +#include "ipc/types.hpp" + +namespace vasum { +namespace api { +namespace host { + +const vasum::ipc::MethodID METHOD_GET_ZONE_DBUSES = 1; +const vasum::ipc::MethodID METHOD_GET_ZONE_ID_LIST = 2; +const vasum::ipc::MethodID METHOD_GET_ACTIVE_ZONE_ID = 3; +const vasum::ipc::MethodID METHOD_GET_ZONE_INFO = 4; +const vasum::ipc::MethodID METHOD_SET_NETDEV_ATTRS = 5; +const vasum::ipc::MethodID METHOD_GET_NETDEV_ATTRS = 6; +const vasum::ipc::MethodID METHOD_GET_NETDEV_LIST = 7; +const vasum::ipc::MethodID METHOD_CREATE_NETDEV_VETH = 8; +const vasum::ipc::MethodID METHOD_CREATE_NETDEV_MACVLAN = 9; +const vasum::ipc::MethodID METHOD_CREATE_NETDEV_PHYS = 10; +const vasum::ipc::MethodID METHOD_DELETE_NETDEV_IP_ADDRESS = 11; +const vasum::ipc::MethodID METHOD_DESTROY_NETDEV = 12; +const vasum::ipc::MethodID METHOD_DECLARE_FILE = 13; +const vasum::ipc::MethodID METHOD_DECLARE_MOUNT = 14; +const vasum::ipc::MethodID METHOD_DECLARE_LINK = 15; +const vasum::ipc::MethodID METHOD_GET_DECLARATIONS = 16; +const vasum::ipc::MethodID METHOD_REMOVE_DECLARATION = 17; +const vasum::ipc::MethodID METHOD_SET_ACTIVE_ZONE = 18; +const vasum::ipc::MethodID METHOD_CREATE_ZONE = 19; +const vasum::ipc::MethodID METHOD_DESTROY_ZONE = 20; +const vasum::ipc::MethodID METHOD_SHUTDOWN_ZONE = 21; +const vasum::ipc::MethodID METHOD_START_ZONE = 22; +const vasum::ipc::MethodID METHOD_LOCK_ZONE = 23; +const vasum::ipc::MethodID METHOD_UNLOCK_ZONE = 24; +const vasum::ipc::MethodID METHOD_GRANT_DEVICE = 25; +const vasum::ipc::MethodID METHOD_REVOKE_DEVICE = 26; + +const vasum::ipc::MethodID SIGNAL_ZONE_DBUS_STATE = 27; + +} // namespace host +} // namespace api +} // namespace vasum + + +#endif // SERVER_HOST_IPC_DEFINITIONS_HPP diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index d3e802b..11589bd 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -127,8 +127,10 @@ ZonesManager::ZonesManager(const std::string& configPath) mProxyCallPolicy.reset(new ProxyCallPolicy(mConfig.proxyCallRules)); using namespace std::placeholders; +#ifdef DBUS_CONNECTION mHostConnection.setProxyCallCallback(bind(&ZonesManager::handleProxyCall, this, HOST_ID, _1, _2, _3, _4, _5, _6, _7)); +#endif mHostConnection.setGetZoneDbusesCallback(bind(&ZonesManager::handleGetZoneDbusesCall, this, _1)); @@ -163,7 +165,7 @@ ZonesManager::ZonesManager(const std::string& configPath) mHostConnection.setDestroyNetdevCallback(bind(&ZonesManager::handleDestroyNetdevCall, this, _1, _2)); - mHostConnection.setDeleleNetdevIpAddressCallback(bind(&ZonesManager::handleDeleteNetdevIpAddressCall, + mHostConnection.setDeleteNetdevIpAddressCallback(bind(&ZonesManager::handleDeleteNetdevIpAddressCall, this, _1, _2)); mHostConnection.setDeclareFileCallback(bind(&ZonesManager::handleDeclareFileCall, @@ -717,12 +719,16 @@ void ZonesManager::handleProxyCall(const std::string& caller, }; if (target == HOST_ID) { +#ifdef DBUS_CONNECTION mHostConnection.proxyCallAsync(targetBusName, targetObjectPath, targetInterface, targetMethod, parameters, asyncResultCallback); +#else + result->setError(api::ERROR_INVALID_ID, "Unsupported proxy call target"); +#endif return; } @@ -755,10 +761,10 @@ void ZonesManager::handleGetZoneDbusesCall(api::MethodResultBuilder::Pointer res result->set(dbuses); } -void ZonesManager::handleDbusStateChanged(const std::string& zoneId, +void ZonesManager::handleDbusStateChanged(const std::string& zoneId , const std::string& dbusAddress) { - mHostConnection.signalZoneDbusState(zoneId, dbusAddress); + mHostConnection.signalZoneDbusState({zoneId, dbusAddress}); } void ZonesManager::handleGetZoneIdsCall(api::MethodResultBuilder::Pointer result) diff --git a/server/zones-manager.hpp b/server/zones-manager.hpp index f789595..84285f3 100644 --- a/server/zones-manager.hpp +++ b/server/zones-manager.hpp @@ -28,7 +28,11 @@ #include "zone.hpp" #include "zones-manager-config.hpp" -#include "host-connection.hpp" +#ifdef DBUS_CONNECTION +#include "host-dbus-connection.hpp" +#else +#include "host-ipc-connection.hpp" +#endif #include "input-monitor.hpp" #include "proxy-call-policy.hpp" #include "utils/worker.hpp" @@ -114,6 +118,11 @@ public: private: typedef std::recursive_mutex Mutex; typedef std::unique_lock Lock; +#ifdef DBUS_CONNECTION + typedef HostDbusConnection HostConnection; +#else + typedef HostIPCConnection HostConnection; +#endif utils::Worker::Pointer mWorker; Mutex mMutex; // used to protect mZones -- 2.7.4