From e781e8693f2a9ddb8bce6bd1479b3e657dbbf648 Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Tue, 21 Apr 2015 13:28:19 +0200 Subject: [PATCH] Rename: DispalyOff to SwitchToDefault, ZoneDbusState to ZoneConnectionState (switch to IPC #4) [Feature] Rename: DispalyOff to SwitchToDefault, ZoneDbusState to ZoneConnectionState (with related types and variables) [Cause] Switching from Dbus to IPC [Solution] N/A [Verification] Build, install, run tests Change-Id: Ibc331cd05d0f4b5d62400f449efd996268b91456 --- client/host-dbus-connection.cpp | 10 +- client/host-dbus-connection.hpp | 6 +- client/host-ipc-connection.cpp | 12 +- client/host-ipc-connection.hpp | 6 +- client/vasum-client-impl.cpp | 8 +- client/vasum-client.h | 4 +- common/api/messages.hpp | 4 +- server/configs/templates/default.conf | 2 +- server/host-dbus-connection.cpp | 16 +- server/host-dbus-connection.hpp | 10 +- server/host-dbus-definitions.hpp | 12 +- server/host-ipc-connection.cpp | 12 +- server/host-ipc-connection.hpp | 4 +- server/host-ipc-definitions.hpp | 4 +- server/zone-config.hpp | 4 +- server/zone-connection.cpp | 8 +- server/zone-connection.hpp | 8 +- server/zone.cpp | 40 ++-- server/zone.hpp | 16 +- server/zones-manager.cpp | 26 +-- server/zones-manager.hpp | 9 +- .../ut-client/templates/console-dbus.conf.in | 2 +- tests/unit_tests/client/ut-client.cpp | 28 +-- .../configs/ut-server/templates/default.conf | 2 +- .../configs/ut-zone-admin/templates/buggy.conf | 2 +- .../configs/ut-zone-admin/templates/missing.conf | 2 +- .../ut-zone-admin/templates/test-no-shutdown.conf | 2 +- .../configs/ut-zone-admin/templates/test.conf | 2 +- .../server/configs/ut-zone/templates/buggy.conf | 2 +- .../configs/ut-zone/templates/test-dbus.conf.in | 2 +- .../server/configs/ut-zone/templates/test.conf | 2 +- .../templates/console-dbus.conf.in | 2 +- .../ut-zones-manager/templates/console.conf | 2 +- tests/unit_tests/server/ut-zone-connection.cpp | 12 +- tests/unit_tests/server/ut-zones-manager.cpp | 219 +++++++++++---------- 35 files changed, 251 insertions(+), 251 deletions(-) diff --git a/client/host-dbus-connection.cpp b/client/host-dbus-connection.cpp index 7e511fe..1f375a0 100644 --- a/client/host-dbus-connection.cpp +++ b/client/host-dbus-connection.cpp @@ -170,16 +170,16 @@ void HostDbusConnection::callRevokeDevice(const vasum::api::RevokeDeviceIn& argI mConnection.call(vasum::api::host::METHOD_REVOKE_DEVICE, argIn); } -void HostDbusConnection::callGetZoneDbuses(vasum::api::Dbuses& argOut) +void HostDbusConnection::callGetZoneConnections(vasum::api::Connections& argOut) { - mConnection.call(vasum::api::host::METHOD_GET_ZONE_DBUSES, argOut); + mConnection.call(vasum::api::host::METHOD_GET_ZONE_CONNECTIONS, argOut); } HostDbusConnection::SubscriptionId -HostDbusConnection::subscribeZoneDbusState(const ZoneDbusStateCallback& callback) +HostDbusConnection::subscribeZoneConnectionState(const ZoneConnectionStateCallback& callback) { - return mConnection.signalSubscribe( - vasum::api::host::SIGNAL_ZONE_DBUS_STATE, callback); + return mConnection.signalSubscribe( + vasum::api::host::SIGNAL_ZONE_CONNECTION_STATE, callback); } void HostDbusConnection::unsubscribe(const SubscriptionId& id) diff --git a/client/host-dbus-connection.hpp b/client/host-dbus-connection.hpp index c7cebdb..8785fa0 100644 --- a/client/host-dbus-connection.hpp +++ b/client/host-dbus-connection.hpp @@ -40,7 +40,7 @@ namespace client { class HostDbusConnection { public: typedef unsigned int SubscriptionId; - typedef std::function ZoneDbusStateCallback; + typedef std::function ZoneConnectionStateCallback; HostDbusConnection(); @@ -71,8 +71,8 @@ public: 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 callGetZoneConnections(vasum::api::Connections& argOut); + SubscriptionId subscribeZoneConnectionState(const ZoneConnectionStateCallback& callback); void unsubscribe(const SubscriptionId& id); private: DbusConnection mConnection; diff --git a/client/host-ipc-connection.cpp b/client/host-ipc-connection.cpp index 6a22e6b..adb44eb 100644 --- a/client/host-ipc-connection.cpp +++ b/client/host-ipc-connection.cpp @@ -161,17 +161,17 @@ void HostIPCConnection::callRevokeDevice(const vasum::api::RevokeDeviceIn& argIn mConnection.call(vasum::api::host::METHOD_REVOKE_DEVICE, argIn); } -void HostIPCConnection::callGetZoneDbuses(vasum::api::Dbuses& argOut) +void HostIPCConnection::callGetZoneConnections(vasum::api::Connections& argOut) { - mConnection.call(vasum::api::host::METHOD_GET_ZONE_DBUSES, argOut); + mConnection.call(vasum::api::host::METHOD_GET_ZONE_CONNECTIONS, argOut); } HostIPCConnection::SubscriptionId -HostIPCConnection::subscribeZoneDbusState(const ZoneDbusStateCallback& callback) +HostIPCConnection::subscribeZoneConnectionState(const ZoneConnectionStateCallback& callback) { - mConnection.subscribe( - vasum::api::host::SIGNAL_ZONE_DBUS_STATE, callback); - return vasum::api::host::SIGNAL_ZONE_DBUS_STATE; + mConnection.subscribe( + vasum::api::host::SIGNAL_ZONE_CONNECTION_STATE, callback); + return vasum::api::host::SIGNAL_ZONE_CONNECTION_STATE; } void HostIPCConnection::unsubscribe(const SubscriptionId& id) diff --git a/client/host-ipc-connection.hpp b/client/host-ipc-connection.hpp index 83313e1..216e976 100644 --- a/client/host-ipc-connection.hpp +++ b/client/host-ipc-connection.hpp @@ -38,7 +38,7 @@ namespace client { class HostIPCConnection { public: typedef unsigned int SubscriptionId; - typedef std::function ZoneDbusStateCallback; + typedef std::function ZoneConnectionStateCallback; void createSystem(); void callGetZoneIds(vasum::api::ZoneIds& argOut); @@ -66,8 +66,8 @@ public: 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 callGetZoneConnections(vasum::api::Connections& argOut); + SubscriptionId subscribeZoneConnectionState(const ZoneConnectionStateCallback& callback); void unsubscribe(const SubscriptionId& id); private: diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index 2d85fb0..49b5846 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -258,8 +258,8 @@ VsmStatus Client::vsm_get_zone_dbuses(VsmArrayString* keys, VsmArrayString* valu assert(values); return coverException([&] { - api::Dbuses dbuses; - mHostClient.callGetZoneDbuses(dbuses); + api::Connections dbuses; + mHostClient.callGetZoneConnections(dbuses); convert(dbuses, *keys, *values); }); } @@ -397,7 +397,7 @@ VsmStatus Client::vsm_add_state_callback(VsmZoneDbusStateCallback zoneDbusStateC assert(zoneDbusStateCallback); return coverException([&] { - auto onSigal = [=](const api::DbusState& dbus) + auto onSigal = [=](const api::ConnectionState& dbus) { zoneDbusStateCallback(dbus.first.c_str(), dbus.second.c_str(), @@ -405,7 +405,7 @@ VsmStatus Client::vsm_add_state_callback(VsmZoneDbusStateCallback zoneDbusStateC }; VsmSubscriptionId id; - id = mHostClient.subscribeZoneDbusState(onSigal); + id = mHostClient.subscribeZoneConnectionState(onSigal); if (subscriptionId) { *subscriptionId = id; } diff --git a/client/vasum-client.h b/client/vasum-client.h index c252b32..50ed162 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -293,11 +293,11 @@ void vsm_netdev_free(VsmNetdev netdev); * Zone's D-Bus state change callback function signature. * * @param[in] zoneId affected zone id - * @param[in] dbusAddress new D-Bus address + * @param[in] address new D-Bus address * @param data custom user's data pointer passed to vsm_add_state_callback() function */ typedef void (*VsmZoneDbusStateCallback)(const char* zoneId, - const char* dbusAddress, + const char* address, void* data); /** diff --git a/common/api/messages.hpp b/common/api/messages.hpp index de606c0..ca4cab2 100644 --- a/common/api/messages.hpp +++ b/common/api/messages.hpp @@ -84,13 +84,13 @@ typedef api::StringPair RemoveDeclarationIn; typedef api::StringPair CreateZoneIn; typedef api::StringPair RevokeDeviceIn; typedef api::StringPair DestroyNetDevIn; -typedef api::StringPair DbusState; +typedef api::StringPair ConnectionState; typedef api::StringPair NotifActiveZoneIn; typedef api::StringPair FileMoveRequestIn; typedef api::VectorOfStrings ZoneIds; typedef api::VectorOfStrings Declarations; typedef api::VectorOfStrings NetDevList; -typedef api::VectorOfStringPairs Dbuses; +typedef api::VectorOfStringPairs Connections; typedef api::VectorOfStringPairs GetNetDevAttrs; struct ZoneInfoOut { diff --git a/server/configs/templates/default.conf b/server/configs/templates/default.conf index 697be47..3a99d20 100644 --- a/server/configs/templates/default.conf +++ b/server/configs/templates/default.conf @@ -10,7 +10,7 @@ "vt" : 0, "shutdownTimeout" : 10, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "runMountPoint" : "~NAME~/run", "provisions" : [], "permittedToSend" : [ "/tmp/.*" ], diff --git a/server/host-dbus-connection.cpp b/server/host-dbus-connection.cpp index b3eb19d..76f5bb8 100644 --- a/server/host-dbus-connection.cpp +++ b/server/host-dbus-connection.cpp @@ -112,9 +112,9 @@ void HostDbusConnection::setProxyCallCallback(const ProxyCallCallback& callback) mProxyCallCallback = callback; } -void HostDbusConnection::setGetZoneDbusesCallback(const GetZoneDbusesCallback& callback) +void HostDbusConnection::setGetZoneConnectionsCallback(const GetZoneConnectionsCallback& callback) { - mGetZoneDbusesCallback = callback; + mGetZoneConnectionsCallback = callback; } void HostDbusConnection::setGetZoneIdsCallback(const GetZoneIdsCallback& callback) @@ -264,10 +264,10 @@ void HostDbusConnection::onMessageCall(const std::string& objectPath, return; } - if (methodName == api::host::METHOD_GET_ZONE_DBUSES) { - if (mGetZoneDbusesCallback) { - auto rb = std::make_shared>(result); - mGetZoneDbusesCallback(rb); + if (methodName == api::host::METHOD_GET_ZONE_CONNECTIONS) { + if (mGetZoneConnectionsCallback) { + auto rb = std::make_shared>(result); + mGetZoneConnectionsCallback(rb); } return; } @@ -569,12 +569,12 @@ void HostDbusConnection::proxyCallAsync(const std::string& busName, callback); } -void HostDbusConnection::signalZoneDbusState(const api::DbusState& state) +void HostDbusConnection::signalZoneConnectionState(const api::ConnectionState& state) { 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, + api::host::SIGNAL_ZONE_CONNECTION_STATE, parameters); } diff --git a/server/host-dbus-connection.hpp b/server/host-dbus-connection.hpp index 980b5e9..455437d 100644 --- a/server/host-dbus-connection.hpp +++ b/server/host-dbus-connection.hpp @@ -57,7 +57,7 @@ public: dbus::MethodResultBuilder::Pointer result )> ProxyCallCallback; typedef std::function GetZoneDbusesCallback; + )> GetZoneConnectionsCallback; typedef std::function GetZoneIdsCallback; typedef std::function" " " - " " - " " + " " + " " " " " " " " @@ -196,9 +196,9 @@ const std::string DEFINITION = " " " " " " - " " + " " " " - " " + " " " " " " ""; diff --git a/server/host-ipc-connection.cpp b/server/host-ipc-connection.cpp index bb8d081..817e62f 100644 --- a/server/host-ipc-connection.cpp +++ b/server/host-ipc-connection.cpp @@ -52,11 +52,11 @@ HostIPCConnection::~HostIPCConnection() { } -void HostIPCConnection::setGetZoneDbusesCallback(const Callback::type& callback) +void HostIPCConnection::setGetZoneConnectionsCallback(const Callback::type& callback) { - typedef Callback Callback; + typedef Callback Callback; mService->setMethodHandler( - api::host::METHOD_GET_ZONE_DBUSES, + api::host::METHOD_GET_ZONE_CONNECTIONS, Callback::getCallbackWrapper(callback)); } @@ -263,10 +263,10 @@ void HostIPCConnection::setRevokeDeviceCallback(const Callbacksignal(api::host::SIGNAL_ZONE_DBUS_STATE, - std::make_shared(dbusState)); + mService->signal(api::host::SIGNAL_ZONE_CONNECTION_STATE, + std::make_shared(connectionState)); } } // namespace vasum diff --git a/server/host-ipc-connection.hpp b/server/host-ipc-connection.hpp index e8c1c8d..61c8f4a 100644 --- a/server/host-ipc-connection.hpp +++ b/server/host-ipc-connection.hpp @@ -81,7 +81,7 @@ public: HostIPCConnection(); ~HostIPCConnection(); - void setGetZoneDbusesCallback(const Callback::type& callback); + void setGetZoneConnectionsCallback(const Callback::type& callback); void setGetZoneIdsCallback(const Callback::type& callback); void setGetActiveZoneIdCallback(const Callback::type& callback); void setGetZoneInfoCallback(const Callback::type& callback); @@ -107,7 +107,7 @@ public: void setUnlockZoneCallback(const Callback::type& callback); void setGrantDeviceCallback(const Callback::type& callback); void setRevokeDeviceCallback(const Callback::type& callback); - void signalZoneDbusState(const api::DbusState& dbusState); + void signalZoneConnectionState(const api::ConnectionState& connectionState); private: epoll::ThreadDispatcher mDispatcher; diff --git a/server/host-ipc-definitions.hpp b/server/host-ipc-definitions.hpp index 4cd06e7..b1fca09 100644 --- a/server/host-ipc-definitions.hpp +++ b/server/host-ipc-definitions.hpp @@ -31,7 +31,7 @@ namespace vasum { namespace api { namespace host { -const vasum::ipc::MethodID METHOD_GET_ZONE_DBUSES = 1; +const vasum::ipc::MethodID METHOD_GET_ZONE_CONNECTIONS = 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; @@ -58,7 +58,7 @@ 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; +const vasum::ipc::MethodID SIGNAL_ZONE_CONNECTION_STATE = 27; } // namespace host } // namespace api diff --git a/server/zone-config.hpp b/server/zone-config.hpp index 8d92800..67b5f93 100644 --- a/server/zone-config.hpp +++ b/server/zone-config.hpp @@ -63,7 +63,7 @@ struct ZoneConfig { * Specify, if D-Bus communication with the zone will be enabled. * Setting this value to "false" will make the zone API not work inside the zone. */ - bool enableDbusIntegration; + bool enableZoneConnection; /** * Zone's CFS quota in us when it's in the foreground @@ -106,7 +106,7 @@ struct ZoneConfig { initWithArgs, privilege, // TODO not needed? switchToDefaultAfterTimeout, // TODO move to dynamic and add an API to change - enableDbusIntegration, + enableZoneConnection, cpuQuotaForeground, cpuQuotaBackground, permittedToSend, // TODO move to dynamic and add an API to change diff --git a/server/zone-connection.cpp b/server/zone-connection.cpp index a86886c..56aa547 100644 --- a/server/zone-connection.cpp +++ b/server/zone-connection.cpp @@ -137,9 +137,9 @@ void ZoneConnection::setNotifyActiveZoneCallback( mNotifyActiveZoneCallback = callback; } -void ZoneConnection::setDisplayOffCallback(const DisplayOffCallback& callback) +void ZoneConnection::setSwitchToDefaultCallback(const SwitchToDefaultCallback& callback) { - mDisplayOffCallback = callback; + mSwitchToDefaultCallback = callback; } void ZoneConnection::setFileMoveCallback( @@ -223,8 +223,8 @@ void ZoneConnection::onSignalReceived(const std::string& senderBusName, if (objectPath == fake_power_manager_api::OBJECT_PATH && interface == fake_power_manager_api::INTERFACE) { //power-manager sent us a signal, check it - if (signalName == fake_power_manager_api::SIGNAL_DISPLAY_OFF && mDisplayOffCallback) { - mDisplayOffCallback(); + if (signalName == fake_power_manager_api::SIGNAL_DISPLAY_OFF && mSwitchToDefaultCallback) { + mSwitchToDefaultCallback(); } } } diff --git a/server/zone-connection.hpp b/server/zone-connection.hpp index 8f025b0..441f645 100644 --- a/server/zone-connection.hpp +++ b/server/zone-connection.hpp @@ -39,7 +39,7 @@ class ZoneConnection { public: typedef std::function OnNameLostCallback; - typedef std::function DisplayOffCallback; + typedef std::function SwitchToDefaultCallback; ZoneConnection(const std::string& address, const OnNameLostCallback& callback); ~ZoneConnection(); @@ -71,9 +71,9 @@ public: void setNotifyActiveZoneCallback(const NotifyActiveZoneCallback& callback); /** - * Register callback to handle turning off the display + * Register switch to default request callback */ - void setDisplayOffCallback(const DisplayOffCallback& callback); + void setSwitchToDefaultCallback(const SwitchToDefaultCallback& callback); /* * Register file move request callback @@ -110,7 +110,7 @@ private: bool mNameLost; OnNameLostCallback mOnNameLostCallback; NotifyActiveZoneCallback mNotifyActiveZoneCallback; - DisplayOffCallback mDisplayOffCallback; + SwitchToDefaultCallback mSwitchToDefaultCallback; FileMoveCallback mFileMoveCallback; ProxyCallCallback mProxyCallCallback; diff --git a/server/zone.cpp b/server/zone.cpp index e26da52..2e47f25 100644 --- a/server/zone.cpp +++ b/server/zone.cpp @@ -164,12 +164,12 @@ void Zone::start() Lock lock(mReconnectMutex); updateRequestedState(STATE_RUNNING); mProvision->start(); - if (mConfig.enableDbusIntegration) { + if (mConfig.enableZoneConnection) { mConnectionTransport.reset(new ZoneConnectionTransport(mRunMountPoint)); } mAdmin->start(); - if (mConfig.enableDbusIntegration) { + if (mConfig.enableZoneConnection) { // Increase cpu quota before connect, otherwise it'd take ages. goForeground(); connect(); @@ -196,14 +196,14 @@ void Zone::stop(bool saveState) void Zone::connect() { // assume called under reconnect lock - mDbusAddress = mConnectionTransport->acquireAddress(); - mConnection.reset(new ZoneConnection(mDbusAddress, - std::bind(&Zone::onNameLostCallback, this))); + mConnectionAddress = mConnectionTransport->acquireAddress(); + mConnection.reset(new ZoneConnection(mConnectionAddress, + std::bind(&Zone::onNameLostCallback, this))); if (mNotifyCallback) { mConnection->setNotifyActiveZoneCallback(mNotifyCallback); } - if (mDisplayOffCallback) { - mConnection->setDisplayOffCallback(mDisplayOffCallback); + if (mSwitchToDefaultCallback) { + mConnection->setSwitchToDefaultCallback(mSwitchToDefaultCallback); } if (mFileMoveCallback) { mConnection->setFileMoveCallback(mFileMoveCallback); @@ -211,8 +211,8 @@ void Zone::connect() if (mProxyCallCallback) { mConnection->setProxyCallCallback(mProxyCallCallback); } - if (mDbusStateChangedCallback) { - mDbusStateChangedCallback(mDbusAddress); + if (mConnectionStateChangedCallback) { + mConnectionStateChangedCallback(mConnectionAddress); } } @@ -221,18 +221,18 @@ void Zone::disconnect() // assume called under reconnect lock if (mConnection) { mConnection.reset(); - mDbusAddress.clear(); - if (mDbusStateChangedCallback) { - // notify about invalid dbusAddress for this zone - mDbusStateChangedCallback(std::string()); + mConnectionAddress.clear(); + if (mConnectionStateChangedCallback) { + // notify about invalid address for this zone + mConnectionStateChangedCallback(std::string()); } } } -std::string Zone::getDbusAddress() const +std::string Zone::getConnectionAddress() const { Lock lock(mReconnectMutex); - return mDbusAddress; + return mConnectionAddress; } int Zone::getVT() const @@ -407,13 +407,13 @@ void Zone::sendNotification(const std::string& zone, } } -void Zone::setDisplayOffCallback(const DisplayOffCallback& callback) +void Zone::setSwitchToDefaultCallback(const SwitchToDefaultCallback& callback) { Lock lock(mReconnectMutex); - mDisplayOffCallback = callback; + mSwitchToDefaultCallback = callback; if (mConnection) { - mConnection->setDisplayOffCallback(callback); + mConnection->setSwitchToDefaultCallback(callback); } } @@ -437,9 +437,9 @@ void Zone::setProxyCallCallback(const ProxyCallCallback& callback) } } -void Zone::setDbusStateChangedCallback(const DbusStateChangedCallback& callback) +void Zone::setConnectionStateChangedCallback(const ConnectionStateChangedCallback& callback) { - mDbusStateChangedCallback = callback; + mConnectionStateChangedCallback = callback; } void Zone::proxyCallAsync(const std::string& busName, diff --git a/server/zone.hpp b/server/zone.hpp index 687077f..e7e929a 100644 --- a/server/zone.hpp +++ b/server/zone.hpp @@ -66,11 +66,11 @@ public: ~Zone(); typedef ZoneConnection::NotifyActiveZoneCallback NotifyActiveZoneCallback; - typedef ZoneConnection::DisplayOffCallback DisplayOffCallback; + typedef ZoneConnection::SwitchToDefaultCallback SwitchToDefaultCallback; typedef ZoneConnection::FileMoveCallback FileMoveCallback; typedef ZoneConnection::ProxyCallCallback ProxyCallCallback; - typedef std::function DbusStateChangedCallback; + typedef std::function ConnectionStateChangedCallback; typedef std::function StartAsyncResultCallback; /** @@ -189,7 +189,7 @@ public: /** * Register callback used when switching to default zone. */ - void setDisplayOffCallback(const DisplayOffCallback& callback); + void setSwitchToDefaultCallback(const SwitchToDefaultCallback& callback); /** * Register proxy call callback @@ -215,7 +215,7 @@ public: /** * Register dbus state changed callback */ - void setDbusStateChangedCallback(const DbusStateChangedCallback& callback); + void setConnectionStateChangedCallback(const ConnectionStateChangedCallback& callback); /** * Make a proxy call @@ -230,7 +230,7 @@ public: /** * Get a dbus address */ - std::string getDbusAddress() const; + std::string getConnectionAddress() const; /** * Get id of VT @@ -328,11 +328,11 @@ private: std::unique_ptr mProvision; mutable std::recursive_mutex mReconnectMutex; NotifyActiveZoneCallback mNotifyCallback; - DisplayOffCallback mDisplayOffCallback; + SwitchToDefaultCallback mSwitchToDefaultCallback; FileMoveCallback mFileMoveCallback; ProxyCallCallback mProxyCallCallback; - DbusStateChangedCallback mDbusStateChangedCallback; - std::string mDbusAddress; + ConnectionStateChangedCallback mConnectionStateChangedCallback; + std::string mConnectionAddress; std::string mRunMountPoint; std::string mRootPath; std::string mDbPath; diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 11589bd..1b6edf3 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -132,8 +132,8 @@ ZonesManager::ZonesManager(const std::string& configPath) this, HOST_ID, _1, _2, _3, _4, _5, _6, _7)); #endif - mHostConnection.setGetZoneDbusesCallback(bind(&ZonesManager::handleGetZoneDbusesCall, - this, _1)); + mHostConnection.setGetZoneConnectionsCallback(bind(&ZonesManager::handleGetZoneConnectionsCall, + this, _1)); mHostConnection.setGetZoneIdsCallback(bind(&ZonesManager::handleGetZoneIdsCall, this, _1)); @@ -319,7 +319,7 @@ void ZonesManager::insertZone(const std::string& zoneId, const std::string& zone zone->setNotifyActiveZoneCallback(bind(&ZonesManager::handleNotifyActiveZoneCall, this, zoneId, _1, _2, _3)); - zone->setDisplayOffCallback(bind(&ZonesManager::handleDisplayOffCall, + zone->setSwitchToDefaultCallback(bind(&ZonesManager::handleSwitchToDefaultCall, this, zoneId)); zone->setFileMoveCallback(bind(&ZonesManager::handleFileMoveCall, @@ -328,8 +328,8 @@ void ZonesManager::insertZone(const std::string& zoneId, const std::string& zone zone->setProxyCallCallback(bind(&ZonesManager::handleProxyCall, this, zoneId, _1, _2, _3, _4, _5, _6, _7)); - zone->setDbusStateChangedCallback(bind(&ZonesManager::handleDbusStateChanged, - this, zoneId, _1)); + zone->setConnectionStateChangedCallback(bind(&ZonesManager::handleConnectionStateChanged, + this, zoneId, _1)); mZones.push_back(std::move(zone)); @@ -578,7 +578,7 @@ void ZonesManager::handleNotifyActiveZoneCall(const std::string& caller, } } -void ZonesManager::handleDisplayOffCall(const std::string& /*caller*/) +void ZonesManager::handleSwitchToDefaultCall(const std::string& /*caller*/) { // get config of currently set zone and switch if switchToDefaultAfterTimeout is true Lock lock(mMutex); @@ -750,21 +750,21 @@ void ZonesManager::handleProxyCall(const std::string& caller, asyncResultCallback); } -void ZonesManager::handleGetZoneDbusesCall(api::MethodResultBuilder::Pointer result) +void ZonesManager::handleGetZoneConnectionsCall(api::MethodResultBuilder::Pointer result) { Lock lock(mMutex); - auto dbuses = std::make_shared(); + auto connections = std::make_shared(); for (auto& zone : mZones) { - dbuses->values.push_back({zone->getId(), zone->getDbusAddress()}); + connections->values.push_back({zone->getId(), zone->getConnectionAddress()}); } - result->set(dbuses); + result->set(connections); } -void ZonesManager::handleDbusStateChanged(const std::string& zoneId , - const std::string& dbusAddress) +void ZonesManager::handleConnectionStateChanged(const std::string& zoneId , + const std::string& address) { - mHostConnection.signalZoneDbusState({zoneId, dbusAddress}); + mHostConnection.signalZoneConnectionState({zoneId, address}); } void ZonesManager::handleGetZoneIdsCall(api::MethodResultBuilder::Pointer result) diff --git a/server/zones-manager.hpp b/server/zones-manager.hpp index 84285f3..31c90cd 100644 --- a/server/zones-manager.hpp +++ b/server/zones-manager.hpp @@ -160,7 +160,7 @@ private: const std::string& appliaction, const std::string& message, api::MethodResultBuilder::Pointer result); - void handleDisplayOffCall(const std::string& caller); + void handleSwitchToDefaultCall(const std::string& caller); void handleFileMoveCall(const std::string& srcZoneId, const std::string& dstZoneId, const std::string& path, @@ -173,10 +173,9 @@ private: const std::string& targetMethod, GVariant* parameters, dbus::MethodResultBuilder::Pointer result); - void handleGetZoneDbusesCall(api::MethodResultBuilder::Pointer result); - - void handleDbusStateChanged(const std::string& zoneId, - const std::string& dbusAddress); + void handleGetZoneConnectionsCall(api::MethodResultBuilder::Pointer result); + void handleConnectionStateChanged(const std::string& zoneId, + const std::string& address); // Host's handlers -------------------------------------------------------- void handleGetZoneIdsCall(api::MethodResultBuilder::Pointer result); void handleGetActiveZoneIdCall(api::MethodResultBuilder::Pointer result); diff --git a/tests/unit_tests/client/configs/ut-client/templates/console-dbus.conf.in b/tests/unit_tests/client/configs/ut-client/templates/console-dbus.conf.in index 7df03e4..3481c09 100644 --- a/tests/unit_tests/client/configs/ut-client/templates/console-dbus.conf.in +++ b/tests/unit_tests/client/configs/ut-client/templates/console-dbus.conf.in @@ -7,7 +7,7 @@ "privilege" : 20, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : true, + "enableZoneConnection" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/client/ut-client.cpp b/tests/unit_tests/client/ut-client.cpp index 40372f4..d53238f 100644 --- a/tests/unit_tests/client/ut-client.cpp +++ b/tests/unit_tests/client/ut-client.cpp @@ -88,7 +88,7 @@ struct Fixture { }; const int EVENT_TIMEOUT = 5000; ///< ms -const std::map EXPECTED_DBUSES_STARTED = { +const std::map EXPECTED_CONNECTIONS = { { "zone1", "unix:path=/tmp/ut-run/zone1/dbus/system_bus_socket" @@ -157,12 +157,12 @@ BOOST_AUTO_TEST_CASE(NotRunningServer) VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect_custom(client, - EXPECTED_DBUSES_STARTED.begin()->second.c_str()); + EXPECTED_CONNECTIONS.begin()->second.c_str()); BOOST_CHECK_EQUAL(VSMCLIENT_IO_ERROR, status); vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(GetZoneDbuses) +BOOST_AUTO_TEST_CASE(GetZoneConnections) { VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect(client); @@ -172,14 +172,14 @@ BOOST_AUTO_TEST_CASE(GetZoneDbuses) //TODO: Clean up if BOOST_REQUIRE_EQUAL fail (remove client). Same in other client tests. BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(getArrayStringLength(keys, EXPECTED_DBUSES_STARTED.size() + 1u), - EXPECTED_DBUSES_STARTED.size()); - BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1u), - EXPECTED_DBUSES_STARTED.size()); + BOOST_CHECK_EQUAL(getArrayStringLength(keys, EXPECTED_CONNECTIONS.size() + 1u), + EXPECTED_CONNECTIONS.size()); + BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_CONNECTIONS.size() + 1u), + EXPECTED_CONNECTIONS.size()); std::map zones; convertDictToMap(keys, values, zones); - BOOST_CHECK(zones == EXPECTED_DBUSES_STARTED); + BOOST_CHECK(zones == EXPECTED_CONNECTIONS); vsm_array_string_free(keys); vsm_array_string_free(values); vsm_client_free(client); @@ -193,14 +193,14 @@ BOOST_AUTO_TEST_CASE(GetZoneIds) VsmArrayString values; status = vsm_get_zone_ids(client, &values); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1u), - EXPECTED_DBUSES_STARTED.size()); + BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_CONNECTIONS.size() + 1u), + EXPECTED_CONNECTIONS.size()); std::set zones; convertArrayToSet(values, zones); for (const auto& zone : zones) { - BOOST_CHECK(EXPECTED_DBUSES_STARTED.find(zone) != EXPECTED_DBUSES_STARTED.cend()); + BOOST_CHECK(EXPECTED_CONNECTIONS.find(zone) != EXPECTED_CONNECTIONS.cend()); } vsm_array_string_free(values); vsm_client_free(client); @@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(FileMoveRequest) const std::string secondZone = "fake_zone"; VsmClient client = vsm_client_create(); - VsmStatus status = vsm_connect_custom(client, EXPECTED_DBUSES_STARTED.begin()->second.c_str()); + VsmStatus status = vsm_connect_custom(client, EXPECTED_CONNECTIONS.begin()->second.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); status = vsm_file_move_request(client, secondZone.c_str(), path.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_CUSTOM_ERROR, status); @@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(Notification) CallbackData callbackData; std::map clients; - for (const auto& it : EXPECTED_DBUSES_STARTED) { + for (const auto& it : EXPECTED_CONNECTIONS) { VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect_custom(client, it.second.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); @@ -398,7 +398,7 @@ BOOST_AUTO_TEST_CASE(GetZoneIdByPidTestMultiple) BOOST_CHECK(ids.count("host") == 1); - for (const auto& dbus : EXPECTED_DBUSES_STARTED) { + for (const auto& dbus : EXPECTED_CONNECTIONS) { BOOST_CHECK(ids.count(dbus.first) == 1); } } diff --git a/tests/unit_tests/server/configs/ut-server/templates/default.conf b/tests/unit_tests/server/configs/ut-server/templates/default.conf index b637d72..d07ecc6 100644 --- a/tests/unit_tests/server/configs/ut-server/templates/default.conf +++ b/tests/unit_tests/server/configs/ut-server/templates/default.conf @@ -7,7 +7,7 @@ "privilege" : 20, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zone-admin/templates/buggy.conf b/tests/unit_tests/server/configs/ut-zone-admin/templates/buggy.conf index c40ab33..c3b07fe 100644 --- a/tests/unit_tests/server/configs/ut-zone-admin/templates/buggy.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/templates/buggy.conf @@ -7,7 +7,7 @@ "privilege" : 10, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zone-admin/templates/missing.conf b/tests/unit_tests/server/configs/ut-zone-admin/templates/missing.conf index 99e893d..7e20d62 100644 --- a/tests/unit_tests/server/configs/ut-zone-admin/templates/missing.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/templates/missing.conf @@ -7,7 +7,7 @@ "privilege" : 10, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zone-admin/templates/test-no-shutdown.conf b/tests/unit_tests/server/configs/ut-zone-admin/templates/test-no-shutdown.conf index 363c7df..4aa7bd2 100644 --- a/tests/unit_tests/server/configs/ut-zone-admin/templates/test-no-shutdown.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/templates/test-no-shutdown.conf @@ -7,7 +7,7 @@ "privilege" : 10, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zone-admin/templates/test.conf b/tests/unit_tests/server/configs/ut-zone-admin/templates/test.conf index df787df..5083c0e 100644 --- a/tests/unit_tests/server/configs/ut-zone-admin/templates/test.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/templates/test.conf @@ -7,7 +7,7 @@ "privilege" : 10, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zone/templates/buggy.conf b/tests/unit_tests/server/configs/ut-zone/templates/buggy.conf index 91a9f7f..1e71ece 100644 --- a/tests/unit_tests/server/configs/ut-zone/templates/buggy.conf +++ b/tests/unit_tests/server/configs/ut-zone/templates/buggy.conf @@ -7,7 +7,7 @@ "privilege" : 10, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zone/templates/test-dbus.conf.in b/tests/unit_tests/server/configs/ut-zone/templates/test-dbus.conf.in index 7d71f2d..da02e3b 100644 --- a/tests/unit_tests/server/configs/ut-zone/templates/test-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-zone/templates/test-dbus.conf.in @@ -7,7 +7,7 @@ "privilege" : 10, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : true, + "enableZoneConnection" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zone/templates/test.conf b/tests/unit_tests/server/configs/ut-zone/templates/test.conf index a58f932..7827fe3 100644 --- a/tests/unit_tests/server/configs/ut-zone/templates/test.conf +++ b/tests/unit_tests/server/configs/ut-zone/templates/test.conf @@ -7,7 +7,7 @@ "privilege" : 10, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zones-manager/templates/console-dbus.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/templates/console-dbus.conf.in index 7df03e4..3481c09 100644 --- a/tests/unit_tests/server/configs/ut-zones-manager/templates/console-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/templates/console-dbus.conf.in @@ -7,7 +7,7 @@ "privilege" : 20, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : true, + "enableZoneConnection" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/configs/ut-zones-manager/templates/console.conf b/tests/unit_tests/server/configs/ut-zones-manager/templates/console.conf index 5d5509b..d9f69ec 100644 --- a/tests/unit_tests/server/configs/ut-zones-manager/templates/console.conf +++ b/tests/unit_tests/server/configs/ut-zones-manager/templates/console.conf @@ -7,7 +7,7 @@ "privilege" : 20, "vt" : -1, "switchToDefaultAfterTimeout" : true, - "enableDbusIntegration" : false, + "enableZoneConnection" : false, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, "shutdownTimeout" : 10, diff --git a/tests/unit_tests/server/ut-zone-connection.cpp b/tests/unit_tests/server/ut-zone-connection.cpp index 5f2c63b..c374c81 100644 --- a/tests/unit_tests/server/ut-zone-connection.cpp +++ b/tests/unit_tests/server/ut-zone-connection.cpp @@ -196,18 +196,18 @@ BOOST_AUTO_TEST_CASE(SignalNotificationApi) BOOST_CHECK(signalEmitted.wait(EVENT_TIMEOUT)); } -BOOST_AUTO_TEST_CASE(SignalDisplayOffApi) +BOOST_AUTO_TEST_CASE(SignalSwitchToDefaultApi) { - Latch displayOffCalled; + Latch switchToDefaultCalled; ZoneConnection connection(acquireAddress(), nullptr); DbusConnection::Pointer client = DbusConnection::create(acquireAddress()); auto callback = [&]() { - displayOffCalled.set(); + switchToDefaultCalled.set(); }; - connection.setDisplayOffCallback(callback); + connection.setSwitchToDefaultCallback(callback); client->emitSignal(fake_power_manager_api::OBJECT_PATH, fake_power_manager_api::INTERFACE, @@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(SignalDisplayOffApi) nullptr); // timeout should occur, since no name is set to client - BOOST_CHECK(!displayOffCalled.wait(EVENT_TIMEOUT)); + BOOST_CHECK(!switchToDefaultCalled.wait(EVENT_TIMEOUT)); DbusNameSetter setter; @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(SignalDisplayOffApi) nullptr); // now signal should be delivered correctly - BOOST_CHECK(displayOffCalled.wait(EVENT_TIMEOUT)); + BOOST_CHECK(switchToDefaultCalled.wait(EVENT_TIMEOUT)); } diff --git a/tests/unit_tests/server/ut-zones-manager.cpp b/tests/unit_tests/server/ut-zones-manager.cpp index 12a3dbe..5a9693f 100644 --- a/tests/unit_tests/server/ut-zones-manager.cpp +++ b/tests/unit_tests/server/ut-zones-manager.cpp @@ -82,7 +82,7 @@ const std::string FILE_CONTENT = "File content\n" const std::string NON_EXISTANT_ZONE_ID = "NON_EXISTANT_ZONE_ID"; const std::string ZONES_PATH = "/tmp/ut-zones"; // the same as in daemon.conf const std::string SIMPLE_TEMPLATE = "console"; -const std::string DBUS_TEMPLATE = "console-dbus"; +const std::string ZONE_ACCESS_TEMPLATE = "console-dbus"; #ifdef DBUS_CONNECTION /** @@ -110,9 +110,9 @@ public: )> TestApiMethodCallback; typedef std::function VoidResultCallback; typedef std::function SignalCallback; + const std::string& address)> SignalCallback; - typedef std::map Dbuses; + typedef std::map Connections; DbusAccessory() : mId(0), @@ -168,7 +168,7 @@ public: mClient->signalSubscribe(callback, isHost() ? api::host::BUS_NAME : api::zone::BUS_NAME); } - void subscribeZoneDbusState(const SignalCallback& callback) { + void subscribeZoneConnectionState(const SignalCallback& callback) { assert(isHost()); auto onSignal = [callback] (const std::string& /*senderBusName*/, const std::string& objectPath, @@ -177,12 +177,12 @@ public: GVariant* parameters) { if (objectPath == api::host::OBJECT_PATH && interface == api::host::INTERFACE && - signalName == api::host::SIGNAL_ZONE_DBUS_STATE) { + signalName == api::host::SIGNAL_ZONE_CONNECTION_STATE) { const gchar* zoneId = NULL; - const gchar* dbusAddress = NULL; - g_variant_get(parameters, "(&s&s)", &zoneId, &dbusAddress); - callback(zoneId, dbusAddress); + const gchar* address = NULL; + g_variant_get(parameters, "(&s&s)", &zoneId, &address); + callback(zoneId, address); } }; mClient->signalSubscribe(onSignal, api::host::BUS_NAME); @@ -285,14 +285,14 @@ public: return GVariantPtr(unpackedResult, g_variant_unref); } - Dbuses callMethodGetZoneDbuses() + Connections callMethodGetZoneConnections() { assert(isHost()); - Dbuses dbuses; + Connections connections; GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_GET_ZONE_DBUSES, + api::host::METHOD_GET_ZONE_CONNECTIONS, NULL, "(a(ss))"); GVariant* array = NULL; @@ -301,11 +301,11 @@ public: size_t count = g_variant_n_children(array); for (size_t n = 0; n < count; ++n) { const char* zoneId = NULL; - const char* dbusAddress = NULL; - g_variant_get_child(array, n, "(&s&s)", &zoneId, &dbusAddress); - dbuses.insert(Dbuses::value_type(zoneId, dbusAddress)); + const char* address = NULL; + g_variant_get_child(array, n, "(&s&s)", &zoneId, &address); + connections.insert(Connections::value_type(zoneId, address)); } - return dbuses; + return connections; } std::vector callMethodGetZoneIds() @@ -502,9 +502,9 @@ public: )> TestApiMethodCallback; typedef std::function VoidResultCallback; typedef std::function SignalCallback; + const std::string& address)> SignalCallback; - typedef std::map Dbuses; + typedef std::map Connections; HostIPCAccessory() : mClient(mDispatcher.getPoll(), HOST_IPC_SOCKET) @@ -512,23 +512,24 @@ public: mClient.start(); } - void subscribeZoneDbusState(const SignalCallback& callback) + void subscribeZoneConnectionState(const SignalCallback& callback) { - auto callbackWrapper = [callback] (const ipc::PeerID, std::shared_ptr& data) { + auto callbackWrapper = [callback] (const ipc::PeerID, std::shared_ptr& data) { callback(data->first, data->second); }; - mClient.setSignalHandler(api::host::SIGNAL_ZONE_DBUS_STATE, callbackWrapper); + mClient.setSignalHandler(api::host::SIGNAL_ZONE_CONNECTION_STATE, + callbackWrapper); } - Dbuses callMethodGetZoneDbuses() + Connections callMethodGetZoneConnections() { - const auto out = mClient.callSync(api::host::METHOD_GET_ZONE_DBUSES, - std::make_shared()); - Dbuses dbuses; + const auto out = mClient.callSync(api::host::METHOD_GET_ZONE_CONNECTIONS, + std::make_shared()); + Connections connections; for (const auto& dbus : out->values) { - dbuses.insert(Dbuses::value_type(dbus.first, dbus.second)); + connections.insert(Connections::value_type(dbus.first, dbus.second)); } - return dbuses; + return connections; } std::vector callMethodGetZoneIds() @@ -629,7 +630,7 @@ public: MethodResultBuilder::Pointer result )> TestApiMethodCallback; - typedef std::map Dbuses; + typedef std::map Connections; ZoneDbusAccessory(int id) : mId(id), @@ -891,17 +892,17 @@ BOOST_AUTO_TEST_CASE(Focus) BOOST_AUTO_TEST_CASE(NotifyActiveZone) { ZonesManager cm(TEST_CONFIG_PATH); - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); cm.restoreAll(); Latch signalReceivedLatch; std::map> signalReceivedSourcesMap; - std::map> dbuses; + std::map> connections; for (int i = 1; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { - dbuses[i] = std::unique_ptr(new ZoneAccessory(i)); + connections[i] = std::unique_ptr(new ZoneAccessory(i)); } auto handler = [](Latch& latch, @@ -930,16 +931,16 @@ BOOST_AUTO_TEST_CASE(NotifyActiveZone) using namespace std::placeholders; for (int i = 1; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { - dbuses[i]->signalSubscribe(std::bind(handler, + connections[i]->signalSubscribe(std::bind(handler, std::ref(signalReceivedLatch), std::ref(signalReceivedSourcesMap[i]), _1, _2, _3, _4, _5)); } - for (auto& dbus : dbuses) { + for (auto& dbus : connections) { dbus.second->callMethodNotify(); } - BOOST_REQUIRE(signalReceivedLatch.waitForN(dbuses.size() - 1u, EVENT_TIMEOUT)); + BOOST_REQUIRE(signalReceivedLatch.waitForN(connections.size() - 1u, EVENT_TIMEOUT)); BOOST_REQUIRE(signalReceivedLatch.empty()); //check if there are no signals that was received more than once @@ -949,21 +950,21 @@ BOOST_AUTO_TEST_CASE(NotifyActiveZone) source), 1); } //check if all signals was received by active zone - BOOST_CHECK_EQUAL(signalReceivedSourcesMap[1].size(), dbuses.size() - 1); + BOOST_CHECK_EQUAL(signalReceivedSourcesMap[1].size(), connections.size() - 1); //check if no signals was received by inactive zone - for (size_t i = 2; i <= dbuses.size(); ++i) { + for (size_t i = 2; i <= connections.size(); ++i) { BOOST_CHECK(signalReceivedSourcesMap[i].empty()); } - dbuses.clear(); + connections.clear(); } -BOOST_AUTO_TEST_CASE(DisplayOff) +BOOST_AUTO_TEST_CASE(SwitchToDefault) { ZonesManager cm(TEST_CONFIG_PATH); - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); cm.restoreAll(); std::vector> clients; @@ -998,9 +999,9 @@ BOOST_AUTO_TEST_CASE(DisplayOff) BOOST_AUTO_TEST_CASE(MoveFile) { ZonesManager cm(TEST_CONFIG_PATH); - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); cm.restoreAll(); Latch notificationLatch; @@ -1008,9 +1009,9 @@ BOOST_AUTO_TEST_CASE(MoveFile) std::string notificationPath; std::string notificationRetcode; - std::map> dbuses; + std::map> connections; for (int i = 1; i <= 2; ++i) { - dbuses[i] = std::unique_ptr(new ZoneAccessory(i)); + connections[i] = std::unique_ptr(new ZoneAccessory(i)); } auto handler = [&](const std::string& /*senderBusName*/, @@ -1037,7 +1038,7 @@ BOOST_AUTO_TEST_CASE(MoveFile) }; // subscribe the second (destination) zone for notifications - dbuses.at(2)->signalSubscribe(handler); + connections.at(2)->signalSubscribe(handler); const std::string TMP = "/tmp/ut-zones"; const std::string NO_PATH = "path_doesnt_matter_here"; @@ -1049,28 +1050,28 @@ BOOST_AUTO_TEST_CASE(MoveFile) const std::string ZONE2PATH = TMP + "/" + ZONE2 + TMP; // sending to a non existing zone - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(BUGGY_ZONE, NO_PATH), + BOOST_CHECK_EQUAL(connections.at(1)->callMethodMove(BUGGY_ZONE, NO_PATH), api::zone::FILE_MOVE_DESTINATION_NOT_FOUND); BOOST_CHECK(notificationLatch.empty()); // sending to self - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE1, NO_PATH), + BOOST_CHECK_EQUAL(connections.at(1)->callMethodMove(ZONE1, NO_PATH), api::zone::FILE_MOVE_WRONG_DESTINATION); BOOST_CHECK(notificationLatch.empty()); // no permission to send - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, "/etc/secret1"), + BOOST_CHECK_EQUAL(connections.at(1)->callMethodMove(ZONE2, "/etc/secret1"), api::zone::FILE_MOVE_NO_PERMISSIONS_SEND); BOOST_CHECK(notificationLatch.empty()); // no permission to receive // TODO uncomment this after adding an api to change 'permittedTo*' config - //BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, "/etc/secret2"), + //BOOST_CHECK_EQUAL(connections.at(1)->callMethodMove(ZONE2, "/etc/secret2"), // api::zone::FILE_MOVE_NO_PERMISSIONS_RECEIVE); //BOOST_CHECK(notificationLatch.empty()); // non existing file - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, BUGGY_PATH), + BOOST_CHECK_EQUAL(connections.at(1)->callMethodMove(ZONE2, BUGGY_PATH), api::zone::FILE_MOVE_FAILED); BOOST_CHECK(notificationLatch.empty()); @@ -1083,7 +1084,7 @@ BOOST_AUTO_TEST_CASE(MoveFile) BOOST_REQUIRE(fs::create_directories(ZONE2PATH, ec)); BOOST_REQUIRE(utils::saveFileContent(ZONE1PATH + "/file", FILE_CONTENT)); - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, TMP + "/file"), + BOOST_CHECK_EQUAL(connections.at(1)->callMethodMove(ZONE2, TMP + "/file"), api::zone::FILE_MOVE_SUCCEEDED); BOOST_REQUIRE(notificationLatch.wait(EVENT_TIMEOUT)); BOOST_REQUIRE(notificationLatch.empty()); @@ -1100,9 +1101,9 @@ BOOST_AUTO_TEST_CASE(MoveFile) BOOST_AUTO_TEST_CASE(AllowSwitchToDefault) { ZonesManager cm(TEST_CONFIG_PATH); - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); cm.restoreAll(); std::vector> clients; @@ -1150,18 +1151,18 @@ BOOST_AUTO_TEST_CASE(AllowSwitchToDefault) BOOST_AUTO_TEST_CASE(ProxyCall) { ZonesManager cm(TEST_CONFIG_PATH); - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); cm.restoreAll(); - std::map> dbuses; - dbuses[0] = std::unique_ptr(new HostAccessory()); + std::map> connections; + connections[0] = std::unique_ptr(new HostAccessory()); for (int i = 1; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { - dbuses[i] = std::unique_ptr(new ZoneAccessory(i)); + connections[i] = std::unique_ptr(new ZoneAccessory(i)); } - for (auto& dbus : dbuses) { + for (auto& dbus : connections) { dbus.second->setName(testapi::BUS_NAME); const int id = dbus.first; @@ -1178,58 +1179,58 @@ BOOST_AUTO_TEST_CASE(ProxyCall) // host -> zone2 BOOST_CHECK_EQUAL("reply from 2: param1", - dbuses.at(0)->testApiProxyCall("zone2", + connections.at(0)->testApiProxyCall("zone2", "param1")); // host -> host BOOST_CHECK_EQUAL("reply from 0: param2", - dbuses.at(0)->testApiProxyCall("host", + connections.at(0)->testApiProxyCall("host", "param2")); // zone1 -> host BOOST_CHECK_EQUAL("reply from 0: param3", - dbuses.at(1)->testApiProxyCall("host", + connections.at(1)->testApiProxyCall("host", "param3")); // zone1 -> zone2 BOOST_CHECK_EQUAL("reply from 2: param4", - dbuses.at(1)->testApiProxyCall("zone2", + connections.at(1)->testApiProxyCall("zone2", "param4")); // zone2 -> zone2 BOOST_CHECK_EQUAL("reply from 2: param5", - dbuses.at(2)->testApiProxyCall("zone2", + connections.at(2)->testApiProxyCall("zone2", "param5")); // host -> unknown - BOOST_CHECK_EXCEPTION(dbuses.at(0)->testApiProxyCall("unknown", "param"), + BOOST_CHECK_EXCEPTION(connections.at(0)->testApiProxyCall("unknown", "param"), DbusCustomException, WhatEquals("Unknown proxy call target")); // forwarding error - BOOST_CHECK_EXCEPTION(dbuses.at(0)->testApiProxyCall("host", ""), + BOOST_CHECK_EXCEPTION(connections.at(0)->testApiProxyCall("host", ""), DbusCustomException, WhatEquals("Test error")); // forbidden call - BOOST_CHECK_EXCEPTION(dbuses.at(0)->proxyCall("host", - "org.fake", - "/a/b", - "c.d", - "foo", - g_variant_new("(s)", "arg")), + BOOST_CHECK_EXCEPTION(connections.at(0)->proxyCall("host", + "org.fake", + "/a/b", + "c.d", + "foo", + g_variant_new("(s)", "arg")), DbusCustomException, WhatEquals("Proxy call forbidden")); } #endif // DBUS_CONNECTION namespace { - const HostAccessory::Dbuses EXPECTED_DBUSES_NONE = { + const HostAccessory::Connections EXPECTED_CONNECTIONS_NONE = { {"zone1", ""}, {"zone2", ""}, {"zone3", ""}}; - const HostAccessory::Dbuses EXPECTED_DBUSES_ALL = { + const HostAccessory::Connections EXPECTED_CONNECTIONS_ALL = { {"zone1", "unix:path=/tmp/ut-run/zone1/dbus/system_bus_socket"}, {"zone2", @@ -1238,22 +1239,22 @@ namespace { "unix:path=/tmp/ut-run/zone3/dbus/system_bus_socket"}}; } // namespace -BOOST_AUTO_TEST_CASE(GetZoneDbuses) +BOOST_AUTO_TEST_CASE(GetZoneConnections) { ZonesManager cm(TEST_CONFIG_PATH); HostAccessory host; - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); - BOOST_CHECK(EXPECTED_DBUSES_NONE == host.callMethodGetZoneDbuses()); + BOOST_CHECK(EXPECTED_CONNECTIONS_NONE == host.callMethodGetZoneConnections()); cm.restoreAll(); - BOOST_CHECK(EXPECTED_DBUSES_ALL == host.callMethodGetZoneDbuses()); + BOOST_CHECK(EXPECTED_CONNECTIONS_ALL == host.callMethodGetZoneConnections()); cm.shutdownAll(); - BOOST_CHECK(EXPECTED_DBUSES_NONE == host.callMethodGetZoneDbuses()); + BOOST_CHECK(EXPECTED_CONNECTIONS_NONE == host.callMethodGetZoneConnections()); } -BOOST_AUTO_TEST_CASE(GetZoneDbusesNoDbus) +BOOST_AUTO_TEST_CASE(GetZoneConnectionsNoDbus) { ZonesManager cm(TEST_CONFIG_PATH); HostAccessory host; @@ -1261,43 +1262,43 @@ BOOST_AUTO_TEST_CASE(GetZoneDbusesNoDbus) cm.createZone("zone2", SIMPLE_TEMPLATE); cm.createZone("zone3", SIMPLE_TEMPLATE); - BOOST_CHECK(EXPECTED_DBUSES_NONE == host.callMethodGetZoneDbuses()); + BOOST_CHECK(EXPECTED_CONNECTIONS_NONE == host.callMethodGetZoneConnections()); cm.restoreAll(); - BOOST_CHECK(EXPECTED_DBUSES_NONE == host.callMethodGetZoneDbuses()); + BOOST_CHECK(EXPECTED_CONNECTIONS_NONE == host.callMethodGetZoneConnections()); cm.shutdownAll(); - BOOST_CHECK(EXPECTED_DBUSES_NONE == host.callMethodGetZoneDbuses()); + BOOST_CHECK(EXPECTED_CONNECTIONS_NONE == host.callMethodGetZoneConnections()); } -BOOST_AUTO_TEST_CASE(ZoneDbusesSignals) +BOOST_AUTO_TEST_CASE(ZoneConnectionsSignals) { Latch signalLatch; - HostAccessory::Dbuses collectedDbuses; - std::mutex collectedDbusesMutex; + HostAccessory::Connections collectedConnections; + std::mutex collectedConnectionsMutex; - auto onSignal = [&] (const std::string& zoneId, const std::string& dbusAddress) { - std::unique_lock lock(collectedDbusesMutex); - collectedDbuses.insert(HostAccessory::Dbuses::value_type(zoneId, dbusAddress)); + auto onSignal = [&] (const std::string& zoneId, const std::string& address) { + std::unique_lock lock(collectedConnectionsMutex); + collectedConnections.insert(HostAccessory::Connections::value_type(zoneId, address)); signalLatch.set(); }; { ZonesManager cm(TEST_CONFIG_PATH); HostAccessory host; - host.subscribeZoneDbusState(onSignal); - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + host.subscribeZoneConnectionState(onSignal); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); BOOST_CHECK(signalLatch.empty()); - BOOST_CHECK(collectedDbuses.empty()); + BOOST_CHECK(collectedConnections.empty()); cm.restoreAll(); BOOST_REQUIRE(signalLatch.waitForN(TEST_DBUS_CONNECTION_ZONES_COUNT, EVENT_TIMEOUT)); BOOST_CHECK(signalLatch.empty()); - std::unique_lock lock(collectedDbusesMutex); - BOOST_CHECK(EXPECTED_DBUSES_ALL == collectedDbuses); - collectedDbuses.clear(); + std::unique_lock lock(collectedConnectionsMutex); + BOOST_CHECK(EXPECTED_CONNECTIONS_ALL == collectedConnections); + collectedConnections.clear(); } } @@ -1544,8 +1545,8 @@ BOOST_AUTO_TEST_CASE(StartShutdownZone) const std::string zone2 = "zone2"; ZonesManager cm(TEST_CONFIG_PATH); - cm.createZone(zone1, DBUS_TEMPLATE); - cm.createZone(zone2, DBUS_TEMPLATE); + cm.createZone(zone1, ZONE_ACCESS_TEMPLATE); + cm.createZone(zone2, ZONE_ACCESS_TEMPLATE); Latch callDone; auto resultCallback = [&]() { @@ -1581,9 +1582,9 @@ BOOST_AUTO_TEST_CASE(StartShutdownZone) BOOST_AUTO_TEST_CASE(LockUnlockZone) { ZonesManager cm(TEST_CONFIG_PATH); - cm.createZone("zone1", DBUS_TEMPLATE); - cm.createZone("zone2", DBUS_TEMPLATE); - cm.createZone("zone3", DBUS_TEMPLATE); + cm.createZone("zone1", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone2", ZONE_ACCESS_TEMPLATE); + cm.createZone("zone3", ZONE_ACCESS_TEMPLATE); cm.restoreAll(); HostAccessory host; -- 2.7.4