From 014f4e74208a68f9edae11e0b3f58c1f1ac794e0 Mon Sep 17 00:00:00 2001
From: Piotr Bartosiewicz
Date: Wed, 23 Jul 2014 16:18:43 +0200
Subject: [PATCH 01/16] Release version 0.1.1
Change-Id: I0fdb371060d86446141700c60958d165cbf44d88
---
packaging/security-containers.spec | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packaging/security-containers.spec b/packaging/security-containers.spec
index 7d7b0a1..f6a77e1 100644
--- a/packaging/security-containers.spec
+++ b/packaging/security-containers.spec
@@ -7,7 +7,7 @@
%define input_event_group video
Name: security-containers
-Version: 0.1.0
+Version: 0.1.1
Release: 0
Source0: %{name}-%{version}.tar.gz
License: Apache-2.0
@@ -16,7 +16,7 @@ Summary: Daemon for managing containers
BuildRequires: cmake
BuildRequires: boost-devel
BuildRequires: libvirt-devel
-BuildRequires: libjson-devel
+BuildRequires: libjson-devel >= 0.10.0
BuildRequires: libcap-ng-devel
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libsystemd-journal)
--
2.7.4
From e785e1bbacccf70374ab14cda57b7059d07cdbff Mon Sep 17 00:00:00 2001
From: Piotr Bartosiewicz
Date: Thu, 24 Jul 2014 10:22:03 +0200
Subject: [PATCH 02/16] Fix dependency problem in spec
[Bug/Feature] Build break
[Cause] Dependency version not match
[Solution] N/A
[Verification] Build with gbs
Change-Id: I0b1a93d293364edea18b15b58cb61fa998674960
---
packaging/security-containers.spec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packaging/security-containers.spec b/packaging/security-containers.spec
index f6a77e1..e639a98 100644
--- a/packaging/security-containers.spec
+++ b/packaging/security-containers.spec
@@ -16,7 +16,7 @@ Summary: Daemon for managing containers
BuildRequires: cmake
BuildRequires: boost-devel
BuildRequires: libvirt-devel
-BuildRequires: libjson-devel >= 0.10.0
+BuildRequires: libjson-devel >= 0.10
BuildRequires: libcap-ng-devel
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libsystemd-journal)
--
2.7.4
From e9617fa11ae5172e3b2cb9338fdcd23476a291be Mon Sep 17 00:00:00 2001
From: Piotr Bartosiewicz
Date: Wed, 23 Jul 2014 12:56:47 +0200
Subject: [PATCH 03/16] Dbus API for sharing containers DBuses
[Bug/Feature] New method on host dbus interface for getting list of
containers dbus addresses and new signals when
containers dbus become available or unavailable.
[Cause] N/A
[Solution] N/A
[Verification] Build, install, run tests
Change-Id: Ib37d47c8e2ffbdca58828c542d7b474e068ca138
---
server/container.cpp | 61 +++++++++---
server/container.hpp | 16 ++++
server/containers-manager.cpp | 25 +++++
server/containers-manager.hpp | 3 +
server/host-connection.cpp | 23 +++++
server/host-connection.hpp | 17 +++-
server/host-dbus-definitions.hpp | 10 ++
tests/unit_tests/server/ut-containers-manager.cpp | 108 +++++++++++++++++++++-
8 files changed, 246 insertions(+), 17 deletions(-)
diff --git a/server/container.cpp b/server/container.cpp
index 0b61d65..4284fec 100644
--- a/server/container.cpp
+++ b/server/container.cpp
@@ -82,7 +82,7 @@ Container::~Container()
// condition on the mReconnectThread.
{
Lock lock(mReconnectMutex);
- mConnection.reset();
+ disconnect();
}
if (mReconnectThread.joinable()) {
@@ -117,7 +117,28 @@ void Container::start()
mConnectionTransport.reset(new ContainerConnectionTransport(mRunMountPoint));
mNetworkAdmin->start();
mAdmin->start();
- mConnection.reset(new ContainerConnection(mConnectionTransport->acquireAddress(),
+ connect();
+
+ // Send to the background only after we're connected,
+ // otherwise it'd take ages.
+ LOGD(getId() << ": DBUS connected, sending to the background");
+ goBackground();
+}
+
+void Container::stop()
+{
+ Lock lock(mReconnectMutex);
+ disconnect();
+ mAdmin->stop();
+ mNetworkAdmin->stop();
+ mConnectionTransport.reset();
+}
+
+void Container::connect()
+{
+ // assume called under reconnect lock
+ mDbusAddress = mConnectionTransport->acquireAddress();
+ mConnection.reset(new ContainerConnection(mDbusAddress,
std::bind(&Container::onNameLostCallback, this)));
if (mNotifyCallback) {
mConnection->setNotifyActiveContainerCallback(mNotifyCallback);
@@ -131,20 +152,28 @@ void Container::start()
if (mProxyCallCallback) {
mConnection->setProxyCallCallback(mProxyCallCallback);
}
+ if (mDbusStateChangedCallback) {
+ mDbusStateChangedCallback(mDbusAddress);
+ }
+}
- // Send to the background only after we're connected,
- // otherwise it'd take ages.
- LOGD(getId() << ": DBUS connected, sending to the background");
- goBackground();
+void Container::disconnect()
+{
+ // assume called under reconnect lock
+ if (mConnection) {
+ mConnection.reset();
+ mDbusAddress.clear();
+ if (mDbusStateChangedCallback) {
+ // notify about invalid dbusAddress for this container
+ mDbusStateChangedCallback(std::string());
+ }
+ }
}
-void Container::stop()
+std::string Container::getDbusAddress()
{
Lock lock(mReconnectMutex);
- mConnection.reset();
- mAdmin->stop();
- mNetworkAdmin->stop();
- mConnectionTransport.reset();
+ return mDbusAddress;
}
void Container::goForeground()
@@ -204,7 +233,7 @@ void Container::reconnectHandler()
{
{
Lock lock(mReconnectMutex);
- mConnection.reset();
+ disconnect();
}
for (int i = 0; i < RECONNECT_RETRIES; ++i) {
@@ -219,8 +248,7 @@ void Container::reconnectHandler()
try {
LOGT(getId() << ": Reconnect try " << i + 1);
- mConnection.reset(new ContainerConnection(mConnectionTransport->acquireAddress(),
- std::bind(&Container::onNameLostCallback, this)));
+ connect();
LOGI(getId() << ": Reconnected");
return;
} catch (SecurityContainersException&) {
@@ -283,6 +311,11 @@ void Container::setProxyCallCallback(const ProxyCallCallback& callback)
}
}
+void Container::setDbusStateChangedCallback(const DbusStateChangedCallback& callback)
+{
+ mDbusStateChangedCallback = callback;
+}
+
void Container::proxyCallAsync(const std::string& busName,
const std::string& objectPath,
const std::string& interface,
diff --git a/server/container.hpp b/server/container.hpp
index dff5d23..c29b860 100644
--- a/server/container.hpp
+++ b/server/container.hpp
@@ -54,6 +54,8 @@ public:
typedef ContainerConnection::FileMoveRequestCallback FileMoveRequestCallback;
typedef ContainerConnection::ProxyCallCallback ProxyCallCallback;
+ typedef std::function DbusStateChangedCallback;
+
/**
* Returns a vector of regexps defining files permitted to be
* send to other containers using file move functionality
@@ -166,6 +168,11 @@ public:
void setFileMoveRequestCallback(const FileMoveRequestCallback& callback);
/**
+ * Register dbus state changed callback
+ */
+ void setDbusStateChangedCallback(const DbusStateChangedCallback& callback);
+
+ /**
* Make a proxy call
*/
void proxyCallAsync(const std::string& busName,
@@ -175,6 +182,11 @@ public:
GVariant* parameters,
const dbus::DbusConnection::AsyncMethodCallCallback& callback);
+ /**
+ * Get a dbus address
+ */
+ std::string getDbusAddress();
+
private:
ContainerConfig mConfig;
std::vector mPermittedToSend;
@@ -189,10 +201,14 @@ private:
DisplayOffCallback mDisplayOffCallback;
FileMoveRequestCallback mFileMoveCallback;
ProxyCallCallback mProxyCallCallback;
+ DbusStateChangedCallback mDbusStateChangedCallback;
+ std::string mDbusAddress;
std::string mRunMountPoint;
void onNameLostCallback();
void reconnectHandler();
+ void connect();
+ void disconnect();
};
diff --git a/server/containers-manager.cpp b/server/containers-manager.cpp
index 7bd22b3..dc6e637 100644
--- a/server/containers-manager.cpp
+++ b/server/containers-manager.cpp
@@ -75,6 +75,9 @@ ContainersManager::ContainersManager(const std::string& managerConfigPath): mDet
mHostConnection.setProxyCallCallback(bind(&ContainersManager::handleProxyCall,
this, HOST_ID, _1, _2, _3, _4, _5, _6, _7));
+ mHostConnection.setGetContainerDbusesCallback(bind(
+ &ContainersManager::handleGetContainerDbuses, this, _1));
+
for (auto& containerConfig : mConfig.containerConfigs) {
std::string containerConfigPath;
@@ -105,6 +108,9 @@ ContainersManager::ContainersManager(const std::string& managerConfigPath): mDet
c->setProxyCallCallback(bind(&ContainersManager::handleProxyCall,
this, id, _1, _2, _3, _4, _5, _6, _7));
+ c->setDbusStateChangedCallback(bind(&ContainersManager::handleDbusStateChanged,
+ this, id, _1));
+
mContainers.insert(ContainerMap::value_type(id, std::move(c)));
}
@@ -391,5 +397,24 @@ void ContainersManager::handleProxyCall(const std::string& caller,
asyncResultCallback);
}
+void ContainersManager::handleGetContainerDbuses(dbus::MethodResultBuilder::Pointer result)
+{
+ std::vector entries;
+ for (auto& container : mContainers) {
+ GVariant* containerId = g_variant_new_string(container.first.c_str());
+ GVariant* dbusAddress = g_variant_new_string(container.second->getDbusAddress().c_str());
+ GVariant* entry = g_variant_new_dict_entry(containerId, dbusAddress);
+ entries.push_back(entry);
+ }
+ GVariant* dict = g_variant_new_array(G_VARIANT_TYPE("{ss}"), entries.data(), entries.size());
+ result->set(g_variant_new("(*)", dict));
+}
+
+void ContainersManager::handleDbusStateChanged(const std::string& containerId,
+ const std::string& dbusAddress)
+{
+ mHostConnection.signalContainerDbusState(containerId, dbusAddress);
+}
+
} // namespace security_containers
diff --git a/server/containers-manager.hpp b/server/containers-manager.hpp
index 4354fdd..8a5c823 100644
--- a/server/containers-manager.hpp
+++ b/server/containers-manager.hpp
@@ -103,6 +103,9 @@ private:
GVariant* parameters,
dbus::MethodResultBuilder::Pointer result);
+ void handleGetContainerDbuses(dbus::MethodResultBuilder::Pointer result);
+ void handleDbusStateChanged(const std::string& containerId, const std::string& dbusAddress);
+
};
diff --git a/server/host-connection.cpp b/server/host-connection.cpp
index 2821202..88ce5a4 100644
--- a/server/host-connection.cpp
+++ b/server/host-connection.cpp
@@ -115,6 +115,11 @@ void HostConnection::setProxyCallCallback(const ProxyCallCallback& callback)
mProxyCallCallback = callback;
}
+void HostConnection::setGetContainerDbusesCallback(const GetContainerDbusesCallback& callback)
+{
+ mGetContainerDbusesCallback = callback;
+}
+
void HostConnection::onMessageCall(const std::string& objectPath,
const std::string& interface,
const std::string& methodName,
@@ -125,6 +130,13 @@ void HostConnection::onMessageCall(const std::string& objectPath,
return;
}
+ if (methodName == hostapi::METHOD_GET_CONTAINER_DBUSES) {
+ if (mGetContainerDbusesCallback) {
+ mGetContainerDbusesCallback(result);
+ }
+ return;
+ }
+
if (methodName == hostapi::METHOD_PROXY_CALL) {
const gchar* target = NULL;
const gchar* targetBusName = NULL;
@@ -151,6 +163,7 @@ void HostConnection::onMessageCall(const std::string& objectPath,
args.get(),
result);
}
+ return;
}
}
@@ -170,5 +183,15 @@ void HostConnection::proxyCallAsync(const std::string& busName,
callback);
}
+void HostConnection::signalContainerDbusState(const std::string& containerId,
+ const std::string& dbusAddress)
+{
+ GVariant* parameters = g_variant_new("(ss)", containerId.c_str(), dbusAddress.c_str());
+ mDbusConnection->emitSignal(hostapi::OBJECT_PATH,
+ hostapi::INTERFACE,
+ hostapi::SIGNAL_CONTAINER_DBUS_STATE,
+ parameters);
+}
+
} // namespace security_containers
diff --git a/server/host-connection.hpp b/server/host-connection.hpp
index 88cb480..3d9c493 100644
--- a/server/host-connection.hpp
+++ b/server/host-connection.hpp
@@ -49,7 +49,11 @@ public:
const std::string& targetInterface,
const std::string& targetMethod,
GVariant* parameters,
- dbus::MethodResultBuilder::Pointer result)> ProxyCallCallback;
+ dbus::MethodResultBuilder::Pointer result
+ )> ProxyCallCallback;
+
+ typedef std::function GetContainerDbusesCallback;
/**
* Register proxy call callback
@@ -57,6 +61,16 @@ public:
void setProxyCallCallback(const ProxyCallCallback& callback);
/**
+ * Register get container dbuses callback
+ */
+ void setGetContainerDbusesCallback(const GetContainerDbusesCallback& callback);
+
+ /**
+ * Send signal describing dbus address state change
+ */
+ void signalContainerDbusState(const std::string& containerId, const std::string& dbusAddress);
+
+ /**
* Make a proxy call
*/
void proxyCallAsync(const std::string& busName,
@@ -73,6 +87,7 @@ private:
bool mNameAcquired;
bool mNameLost;
ProxyCallCallback mProxyCallCallback;
+ GetContainerDbusesCallback mGetContainerDbusesCallback;
void onNameAcquired();
void onNameLost();
diff --git a/server/host-dbus-definitions.hpp b/server/host-dbus-definitions.hpp
index f41da38..4594433 100644
--- a/server/host-dbus-definitions.hpp
+++ b/server/host-dbus-definitions.hpp
@@ -37,6 +37,9 @@ const std::string OBJECT_PATH = "/org/tizen/containers/hos
const std::string INTERFACE = "org.tizen.containers.host.manager";
const std::string METHOD_PROXY_CALL = "ProxyCall";
+const std::string METHOD_GET_CONTAINER_DBUSES = "GetContainerDbuses";
+
+const std::string SIGNAL_CONTAINER_DBUS_STATE = "ContainerDbusState";
const std::string DEFINITION =
""
@@ -50,6 +53,13 @@ const std::string DEFINITION =
" "
" "
" "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
" "
"";
diff --git a/tests/unit_tests/server/ut-containers-manager.cpp b/tests/unit_tests/server/ut-containers-manager.cpp
index 64659ef..43bc15a 100644
--- a/tests/unit_tests/server/ut-containers-manager.cpp
+++ b/tests/unit_tests/server/ut-containers-manager.cpp
@@ -75,10 +75,14 @@ const std::string FILE_CONTENT = "File content\n"
class DbusAccessory {
public:
+ static const int HOST_ID = 0;
+
typedef std::function TestApiMethodCallback;
+ typedef std::map Dbuses;
+
DbusAccessory(int id)
: mId(id),
mClient(DbusConnection::create(acquireAddress())),
@@ -122,7 +126,7 @@ public:
void signalSubscribe(const DbusConnection::SignalCallback& callback)
{
- mClient->signalSubscribe(callback, api::BUS_NAME);
+ mClient->signalSubscribe(callback, isHost() ? hostapi::BUS_NAME : api::BUS_NAME);
}
void emitSignal(const std::string& objectPath,
@@ -218,6 +222,28 @@ public:
g_variant_get(result.get(), "(v)", &unpackedResult);
return GVariantPtr(unpackedResult, g_variant_unref);
}
+
+ Dbuses callMethodGetContainerDbuses() {
+ assert(isHost());
+ Dbuses dbuses;
+ GVariantPtr result = mClient->callMethod(hostapi::BUS_NAME,
+ hostapi::OBJECT_PATH,
+ hostapi::INTERFACE,
+ hostapi::METHOD_GET_CONTAINER_DBUSES,
+ NULL,
+ "(a{ss})");
+ GVariant* array = NULL;
+ g_variant_get(result.get(), "(*)", &array);
+ dbus::GVariantPtr autounref(array, g_variant_unref);
+ size_t count = g_variant_n_children(array);
+ for (size_t n = 0; n < count; ++n) {
+ const char* containerId = NULL;
+ const char* dbusAddress = NULL;
+ g_variant_get_child(array, n, "{&s&s}", &containerId, &dbusAddress);
+ dbuses.insert(Dbuses::value_type(containerId, dbusAddress));
+ }
+ return dbuses;
+ }
private:
const int mId;
DbusConnection::Pointer mClient;
@@ -227,7 +253,7 @@ private:
std::condition_variable mNameCondition;
bool isHost() const {
- return mId == 0;
+ return mId == HOST_ID;
}
std::string acquireAddress() const
@@ -644,5 +670,83 @@ BOOST_AUTO_TEST_CASE(ProxyCallTest)
expectedMessage("Proxy call forbidden"));
}
+namespace {
+ const DbusAccessory::Dbuses EXPECTED_DBUSES_STOPPED = {
+ {"ut-containers-manager-console1-dbus", ""},
+ {"ut-containers-manager-console2-dbus", ""},
+ {"ut-containers-manager-console3-dbus", ""}};
+
+ const DbusAccessory::Dbuses EXPECTED_DBUSES_STARTED = {
+ {"ut-containers-manager-console1-dbus",
+ "unix:path=/tmp/ut-containers-manager/console1-dbus/dbus/system_bus_socket"},
+ {"ut-containers-manager-console2-dbus",
+ "unix:path=/tmp/ut-containers-manager/console2-dbus/dbus/system_bus_socket"},
+ {"ut-containers-manager-console3-dbus",
+ "unix:path=/tmp/ut-containers-manager/console3-dbus/dbus/system_bus_socket"}};
+} // namespace
+
+BOOST_AUTO_TEST_CASE(GetContainerDbusesTest)
+{
+ DbusAccessory host(DbusAccessory::HOST_ID);
+
+ ContainersManager cm(TEST_DBUS_CONFIG_PATH);
+
+ BOOST_CHECK(EXPECTED_DBUSES_STOPPED == host.callMethodGetContainerDbuses());
+
+ cm.startAll();
+
+ BOOST_CHECK(EXPECTED_DBUSES_STARTED == host.callMethodGetContainerDbuses());
+
+ cm.stopAll();
+
+ BOOST_CHECK(EXPECTED_DBUSES_STOPPED == host.callMethodGetContainerDbuses());
+}
+
+BOOST_AUTO_TEST_CASE(ContainerDbusesSignalsTest)
+{
+ DbusAccessory host(DbusAccessory::HOST_ID);
+
+ Latch signalLatch;
+ DbusAccessory::Dbuses collectedDbuses;
+
+ auto onSignal = [&] (const std::string& /*senderBusName*/,
+ const std::string& objectPath,
+ const std::string& interface,
+ const std::string& signalName,
+ GVariant* parameters) {
+ if (objectPath == hostapi::OBJECT_PATH &&
+ interface == hostapi::INTERFACE &&
+ signalName == hostapi::SIGNAL_CONTAINER_DBUS_STATE) {
+
+ const gchar* containerId = NULL;
+ const gchar* dbusAddress = NULL;
+ g_variant_get(parameters, "(&s&s)", &containerId, &dbusAddress);
+
+ collectedDbuses.insert(DbusAccessory::Dbuses::value_type(containerId, dbusAddress));
+ signalLatch.set();
+ }
+ };
+
+ host.signalSubscribe(onSignal);
+
+ {
+ ContainersManager cm(TEST_DBUS_CONFIG_PATH);
+
+ BOOST_CHECK(signalLatch.empty());
+ BOOST_CHECK(collectedDbuses.empty());
+
+ cm.startAll();
+
+ BOOST_CHECK(signalLatch.waitForN(TEST_DBUS_CONNECTION_CONTAINERS_COUNT, EVENT_TIMEOUT));
+ BOOST_CHECK(signalLatch.empty());
+ BOOST_CHECK(EXPECTED_DBUSES_STARTED == collectedDbuses);
+ collectedDbuses.clear();
+ }
+
+ BOOST_CHECK(signalLatch.waitForN(TEST_DBUS_CONNECTION_CONTAINERS_COUNT, EVENT_TIMEOUT));
+ BOOST_CHECK(signalLatch.empty());
+ BOOST_CHECK(EXPECTED_DBUSES_STOPPED == collectedDbuses);
+}
+
BOOST_AUTO_TEST_SUITE_END()
--
2.7.4
From a5c612deb7685dae1fd5aececd81db28d159dd4e Mon Sep 17 00:00:00 2001
From: Jan Olszak
Date: Tue, 22 Jul 2014 17:25:20 +0200
Subject: [PATCH 04/16] API for obtaining container's IDs
[Bug/Feature] D-Bus API for getting the ID of the active container
D-Bus API for getting the IDs of all containers
[Cause] N/A
[Solution] N/A
[Verification] Build, install, run tests
Change-Id: I03081e3dc5e275f9c0d5c6b5a6cacfef38c5adff
---
server/containers-manager.cpp | 28 ++++++++
server/containers-manager.hpp | 2 +
server/host-connection.cpp | 31 +++++++--
server/host-connection.hpp | 16 +++++
server/host-dbus-definitions.hpp | 8 +++
tests/unit_tests/server/ut-containers-manager.cpp | 80 ++++++++++++++++++++++-
6 files changed, 158 insertions(+), 7 deletions(-)
diff --git a/server/containers-manager.cpp b/server/containers-manager.cpp
index dc6e637..b2c4222 100644
--- a/server/containers-manager.cpp
+++ b/server/containers-manager.cpp
@@ -78,6 +78,12 @@ ContainersManager::ContainersManager(const std::string& managerConfigPath): mDet
mHostConnection.setGetContainerDbusesCallback(bind(
&ContainersManager::handleGetContainerDbuses, this, _1));
+ mHostConnection.setGetContainerIdsCallback(bind(&ContainersManager::handleGetContainerIdsCall,
+ this, _1));
+
+ mHostConnection.setGetActiveContainerIdCallback(bind(&ContainersManager::handleGetActiveContainerIdCall,
+ this, _1));
+
for (auto& containerConfig : mConfig.containerConfigs) {
std::string containerConfigPath;
@@ -416,5 +422,27 @@ void ContainersManager::handleDbusStateChanged(const std::string& containerId,
mHostConnection.signalContainerDbusState(containerId, dbusAddress);
}
+void ContainersManager::handleGetContainerIdsCall(dbus::MethodResultBuilder::Pointer result)
+{
+ std::vector containerIds;
+ for(auto& container: mContainers){
+ containerIds.push_back(g_variant_new_string(container.first.c_str()));
+ }
+
+ GVariant* array = g_variant_new_array(G_VARIANT_TYPE("s"),
+ containerIds.data(),
+ containerIds.size());
+ result->set(g_variant_new("(*)", array));
+}
+
+void ContainersManager::handleGetActiveContainerIdCall(dbus::MethodResultBuilder::Pointer result)
+{
+ LOGI("GetActiveContainerId call");
+ if (mContainers[mConfig.foregroundId]->isRunning()){
+ result->set(g_variant_new("(s)", mConfig.foregroundId.c_str()));
+ } else {
+ result->set(g_variant_new("(s)", ""));
+ }
+}
} // namespace security_containers
diff --git a/server/containers-manager.hpp b/server/containers-manager.hpp
index 8a5c823..b685028 100644
--- a/server/containers-manager.hpp
+++ b/server/containers-manager.hpp
@@ -105,6 +105,8 @@ private:
void handleGetContainerDbuses(dbus::MethodResultBuilder::Pointer result);
void handleDbusStateChanged(const std::string& containerId, const std::string& dbusAddress);
+ void handleGetContainerIdsCall(dbus::MethodResultBuilder::Pointer result);
+ void handleGetActiveContainerIdCall(dbus::MethodResultBuilder::Pointer result);
};
diff --git a/server/host-connection.cpp b/server/host-connection.cpp
index 88ce5a4..0d96039 100644
--- a/server/host-connection.cpp
+++ b/server/host-connection.cpp
@@ -65,12 +65,7 @@ HostConnection::HostConnection()
mDbusConnection->registerObject(hostapi::OBJECT_PATH,
hostapi::DEFINITION,
std::bind(&HostConnection::onMessageCall,
- this,
- _1,
- _2,
- _3,
- _4,
- _5));
+ this, _1, _2, _3, _4, _5));
LOGD("Connected");
}
@@ -120,6 +115,16 @@ void HostConnection::setGetContainerDbusesCallback(const GetContainerDbusesCallb
mGetContainerDbusesCallback = callback;
}
+void HostConnection::setGetContainerIdsCallback(const GetContainerIdsCallback& callback)
+{
+ mGetContainerIdsCallback = callback;
+}
+
+void HostConnection::setGetActiveContainerIdCallback(const GetActiveContainerIdCallback& callback)
+{
+ mGetActiveContainerIdCallback = callback;
+}
+
void HostConnection::onMessageCall(const std::string& objectPath,
const std::string& interface,
const std::string& methodName,
@@ -165,6 +170,20 @@ void HostConnection::onMessageCall(const std::string& objectPath,
}
return;
}
+
+ if (methodName == hostapi::METHOD_GET_CONTAINER_ID_LIST){
+ if (mGetContainerIdsCallback){
+ mGetContainerIdsCallback(result);
+ }
+ return;
+ }
+
+ if (methodName == hostapi::METHOD_GET_ACTIVE_CONTAINER_ID){
+ if (mGetActiveContainerIdCallback){
+ mGetActiveContainerIdCallback(result);
+ }
+ return;
+ }
}
void HostConnection::proxyCallAsync(const std::string& busName,
diff --git a/server/host-connection.hpp b/server/host-connection.hpp
index 3d9c493..962fbb9 100644
--- a/server/host-connection.hpp
+++ b/server/host-connection.hpp
@@ -54,6 +54,10 @@ public:
typedef std::function GetContainerDbusesCallback;
+ typedef std::function GetContainerIdsCallback;
+ typedef std::function GetActiveContainerIdCallback;
+
/**
* Register proxy call callback
@@ -71,6 +75,16 @@ public:
void signalContainerDbusState(const std::string& containerId, const std::string& dbusAddress);
/**
+ * Register a callback called to get a list of domain ids
+ */
+ void setGetContainerIdsCallback(const GetContainerIdsCallback& callback);
+
+ /**
+ * Register a callback called to get the active container id
+ */
+ void setGetActiveContainerIdCallback(const GetContainerIdsCallback& callback);
+
+ /**
* Make a proxy call
*/
void proxyCallAsync(const std::string& busName,
@@ -88,6 +102,8 @@ private:
bool mNameLost;
ProxyCallCallback mProxyCallCallback;
GetContainerDbusesCallback mGetContainerDbusesCallback;
+ GetContainerIdsCallback mGetContainerIdsCallback;
+ GetActiveContainerIdCallback mGetActiveContainerIdCallback;
void onNameAcquired();
void onNameLost();
diff --git a/server/host-dbus-definitions.hpp b/server/host-dbus-definitions.hpp
index 4594433..ef30e1a 100644
--- a/server/host-dbus-definitions.hpp
+++ b/server/host-dbus-definitions.hpp
@@ -38,6 +38,8 @@ const std::string INTERFACE = "org.tizen.containers.host
const std::string METHOD_PROXY_CALL = "ProxyCall";
const std::string METHOD_GET_CONTAINER_DBUSES = "GetContainerDbuses";
+const std::string METHOD_GET_CONTAINER_ID_LIST = "GetContainerIds";
+const std::string METHOD_GET_ACTIVE_CONTAINER_ID = "GetActiveContainerId";
const std::string SIGNAL_CONTAINER_DBUS_STATE = "ContainerDbusState";
@@ -56,6 +58,12 @@ const std::string DEFINITION =
" "
" "
" "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
" "
" "
" "
diff --git a/tests/unit_tests/server/ut-containers-manager.cpp b/tests/unit_tests/server/ut-containers-manager.cpp
index 43bc15a..d4708e3 100644
--- a/tests/unit_tests/server/ut-containers-manager.cpp
+++ b/tests/unit_tests/server/ut-containers-manager.cpp
@@ -223,7 +223,8 @@ public:
return GVariantPtr(unpackedResult, g_variant_unref);
}
- Dbuses callMethodGetContainerDbuses() {
+ Dbuses callMethodGetContainerDbuses()
+ {
assert(isHost());
Dbuses dbuses;
GVariantPtr result = mClient->callMethod(hostapi::BUS_NAME,
@@ -244,6 +245,47 @@ public:
}
return dbuses;
}
+
+ std::vector callMethodGetContainerIds()
+ {
+ assert(isHost());
+ GVariantPtr result = mClient->callMethod(hostapi::BUS_NAME,
+ hostapi::OBJECT_PATH,
+ hostapi::INTERFACE,
+ hostapi::METHOD_GET_CONTAINER_ID_LIST,
+ NULL,
+ "(as)");
+
+ GVariant* array = NULL;
+ g_variant_get(result.get(), "(*)", &array);
+
+ size_t arraySize = g_variant_n_children(array);
+ std::vector containerIds;
+ for (size_t i = 0; i < arraySize; ++i) {
+ const char* id = NULL;
+ g_variant_get_child(array, i, "&s", &id);
+ containerIds.push_back(id);
+ }
+
+ g_variant_unref(array);
+ return containerIds;
+ }
+
+ std::string callMethodGetActiveContainerId()
+ {
+ assert(isHost());
+ GVariantPtr result = mClient->callMethod(hostapi::BUS_NAME,
+ hostapi::OBJECT_PATH,
+ hostapi::INTERFACE,
+ hostapi::METHOD_GET_ACTIVE_CONTAINER_ID,
+ NULL,
+ "(s)");
+
+ const char* containerId = NULL;
+ g_variant_get(result.get(), "(&s)", &containerId);
+ return containerId;
+ }
+
private:
const int mId;
DbusConnection::Pointer mClient;
@@ -749,4 +791,40 @@ BOOST_AUTO_TEST_CASE(ContainerDbusesSignalsTest)
}
+BOOST_AUTO_TEST_CASE(GetContainerIdsTest)
+{
+ ContainersManager cm(TEST_DBUS_CONFIG_PATH);
+
+ DbusAccessory dbus(DbusAccessory::HOST_ID);
+
+ std::vector containerIds = {"ut-containers-manager-console1-dbus",
+ "ut-containers-manager-console2-dbus",
+ "ut-containers-manager-console3-dbus"};
+ std::vector returnedIds = dbus.callMethodGetContainerIds();
+
+ BOOST_CHECK(std::is_permutation(returnedIds.begin(),
+ returnedIds.end(),
+ containerIds.begin()));
+}
+
+BOOST_AUTO_TEST_CASE(GetActiveContainerIdTest)
+{
+ ContainersManager cm(TEST_DBUS_CONFIG_PATH);
+ cm.startAll();
+
+ DbusAccessory dbus(DbusAccessory::HOST_ID);
+
+ std::vector containerIds = {"ut-containers-manager-console1-dbus",
+ "ut-containers-manager-console2-dbus",
+ "ut-containers-manager-console3-dbus"};
+
+ for (std::string& containerId: containerIds){
+ cm.focus(containerId);
+ BOOST_CHECK(dbus.callMethodGetActiveContainerId() == containerId);
+ }
+
+ cm.stopAll();
+ BOOST_CHECK(dbus.callMethodGetActiveContainerId() == "");
+}
+
BOOST_AUTO_TEST_SUITE_END()
--
2.7.4
From d880b2a8fda680e6970d2916f06c19b19ac1fed4 Mon Sep 17 00:00:00 2001
From: Piotr Bartosiewicz
Date: Mon, 28 Jul 2014 11:06:13 +0200
Subject: [PATCH 05/16] Fix invalid use of glib loop in unit tests
[Bug/Feature] Memleak in unit tests
[Cause] Glib loop was started twice
[Solution] N/A
[Verification] Build, install, run tests under valgrind
Change-Id: I7407a0211e141143b3828cf1784f3a2a5ac3f5b3
---
server/container-admin.hpp | 1 -
tests/unit_tests/server/ut-input-monitor.cpp | 15 ++++++---------
2 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/server/container-admin.hpp b/server/container-admin.hpp
index a1e0baf..3831a3a 100644
--- a/server/container-admin.hpp
+++ b/server/container-admin.hpp
@@ -35,7 +35,6 @@
#include