void ServiceDirectoryClient::onSDEventConnected(qi::Future<SignalLink> future, qi::Promise<void> promise, bool isAdd) { if (promise.future().isFinished()) { return; } if (future.hasError()) { qi::Future<void> fdc = onSocketDisconnected(future.error()); fdc.connect(&qi::Promise<void>::setError, promise, future.error()); return; } bool ready = false; { boost::mutex::scoped_lock lock(_mutex); if (isAdd) _addSignalLink = future.value(); else _removeSignalLink = future.value(); ready = _addSignalLink && _removeSignalLink; } if (ready) { promise.setValue(0); connected(); } }
void log(const qi::LogLevel, const qi::Clock::time_point, const qi::SystemClock::time_point, const char*, const char*, const char*, const char*, int) { start.future().wait(); if (++count == MAX) finished.setValue(0); }
TEST(QiApplicationSession, defaultConnect) { ASSERT_FALSE(_app->session()->isConnected()); _app->start(); ASSERT_TRUE(_app->session()->isConnected()); ASSERT_EQ(_url, _app->session()->url()); ASSERT_FALSE(_stopped); _sd.close(); _sync.future().wait(); ASSERT_TRUE(_stopped); EXPECT_THROW(_app->session()->connect("ftp://invalidurl:42"), qi::FutureUserException); ASSERT_FALSE(_app->session()->isConnected()); }
TEST(Test, Recurse) { payload = qi::Promise<bool>(); TestSessionPair p1; TestSessionPair p2(p1); qi::DynamicObjectBuilder ob1, ob2; ob1.advertiseMethod("onFire1", &onFire1); ob2.advertiseMethod("onFire2", &onFire2); qi::AnyObject oserver1(ob1.object()), oserver2(ob2.object()); unsigned int nbServices = TestMode::getTestMode() == TestMode::Mode_Nightmare ? 2 : 1; // Two objects with a fire event and a onFire method. ASSERT_NO_THROW(p1.server()->registerService("coin1", oserver1).hasValue(2000)); ASSERT_NO_THROW(p2.server()->registerService("coin2", oserver2).hasValue(2000)); EXPECT_EQ(nbServices, p1.server()->services(qi::Session::ServiceLocality_Local).value().size()); EXPECT_EQ(nbServices, p2.server()->services(qi::Session::ServiceLocality_Local).value().size()); oclient1 = p2.client()->service("coin1"); oclient2 = p1.client()->service("coin2"); #ifdef WIN32 int niter = 1000; #else int niter = 1000; #endif if (TestMode::getTestMode() == TestMode::Mode_SSL) { niter /= 100; } if (getenv("VALGRIND")) { std::cerr << "Valgrind detected, reducing iteration count" << std::endl; niter = 50; } oclient1.call<void>("onFire1", niter); ASSERT_NO_THROW(payload.future().hasValue(2000)); oclient1.reset(); oclient2.reset(); }