goBackground();
}
-void Zone::startAsync(const StartAsyncResultCallback& callback)
-{
- auto startWrapper = [this, callback]() {
- bool succeeded = false;
-
- try {
- start();
- succeeded = true;
- } catch(std::exception& e) {
- LOGE(getId() << ": failed to start: " << e.what());
- }
-
- if (callback) {
- callback(succeeded);
- }
- };
-
- mWorker->addTask(startWrapper);
-}
-
void Zone::stop()
{
Lock lock(mReconnectMutex);
void start();
/**
- * Boot the zone to the background in separate thread. This function immediately exits
- * after zone booting is started in another thread.
- *
- * @param callback Called after starting the zone. Passes bool with result of starting.
- */
- void startAsync(const StartAsyncResultCallback& callback);
-
- /**
* Try to shutdown the zone, if failed, destroy it.
*/
void stop();
LOGT("Start zone " << id);
- auto resultCallback = [this, id, result](bool succeeded) {
- if (succeeded) {
+ auto startAsync = [this, id, result]() {
+ try {
+ ZoneMap::mapped_type zone;
+ {
+ Lock lock(mMutex);
+ zone = mZones.at(id);
+ }
+ zone->start();
focus(id);
result->setVoid();
- } else {
- LOGE("Failed to start zone.");
+ } catch (const std::exception& e) {
+ LOGE(id << ": failed to start: " << e.what());
result->setError(api::ERROR_INTERNAL, "Failed to start zone");
}
};
-
- mZones[id]->startAsync(resultCallback);
+ mWorker->addTask(startAsync);
}
void ZonesManager::handleLockZoneCall(const std::string& id,
// to hold InputMonitor pointer to monitor if zone switching sequence is recognized
std::unique_ptr<InputMonitor> mSwitchingSequenceMonitor;
std::unique_ptr<ProxyCallPolicy> mProxyCallPolicy;
- typedef std::unordered_map<std::string, std::unique_ptr<Zone>> ZoneMap;
+ typedef std::unordered_map<std::string, std::shared_ptr<Zone>> ZoneMap;
ZoneMap mZones; // map of zones, id is the key
bool mDetachOnExit;
BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status);
VsmArrayString keys, values;
status = vsm_get_zone_dbuses(client, &keys, &values);
+ //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),
#include <mutex>
#include <condition_variable>
+//TODO: BOOST_* macros aren't thread-safe. Remove it from callbacks
BOOST_AUTO_TEST_SUITE(DbusSuite)
Latch nameAcquired;
Latch handlerDone;
Latch callDone;
+ std::string strResult;
+ MethodResultBuilder::Pointer deferredResult;
DbusConnection::Pointer conn1 = DbusConnection::create(DBUS_ADDRESS);
DbusConnection::Pointer conn2 = DbusConnection::create(DBUS_ADDRESS);
[] {});
BOOST_REQUIRE(nameAcquired.wait(EVENT_TIMEOUT));
- std::string strResult;
- MethodResultBuilder::Pointer deferredResult;
-
auto handler = [&](const std::string& objectPath,
const std::string& interface,
const std::string& methodName,
{
std::shared_ptr<SendData> sentData(new SendData(34));
std::shared_ptr<SendData> recvData = c.callSync<SendData, SendData>(methodID, sentData, TIMEOUT);
+ BOOST_REQUIRE(recvData);
BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal);
}
{
std::shared_ptr<SendData> sentData(new SendData(56));
std::shared_ptr<SendData> recvData = s.callSync<SendData, SendData>(methodID, peerFD, sentData, TIMEOUT);
+ BOOST_REQUIRE(recvData);
BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal);
}
std::shared_ptr<SendData> sentData(new SendData(56));
std::shared_ptr<SendData> recvData = s.callSync<SendData, SendData>(1, peerFD, sentData);
+ BOOST_REQUIRE(recvData);
BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal);
}
// Test echo with a minimal timeout
std::shared_ptr<LongSendData> sentDataA(new LongSendData(34, SHORT_OPERATION_TIME));
std::shared_ptr<SendData> recvData = c.callSync<LongSendData, SendData>(1, sentDataA, TIMEOUT);
+ BOOST_REQUIRE(recvData);
BOOST_CHECK_EQUAL(recvData->intVal, sentDataA->intVal);
// Test timeout on write