Пример #1
0
Future<IClient::Result> ClientWS::callAsync(ConstStrA method, JSON::ConstValue params, JSON::ConstValue context) {
	Synchronized<FastLockR> _(lock);

	if (params == null) {
		params = jsonFactory->array();
	} else if (!params->isArray()) {
		params = JSON::Container(jsonFactory->array()).add(params);
	}

	JSON::Builder bld(jsonFactory);
	natural thisid = idcounter++;
	JSON::Builder::CObject req = bld("id",thisid)
			.container()
			("method",method)
			("params",params);
	if (context != null) {
		req("context",context);
	}



	ConstStrA msg = jsonFactory->toString(*req);
	Future<Result> f;
	sendTextMessage(msg);
	waitingResults.insert(thisid,f.getPromise());

	return f;

}
Пример #2
0
	virtual Future<Response> operator()(const Request &req) const throw() {
		Future<Response> out;
		try {
			WeakRefPtr<IPeer> peer = req.peer;
			if (peer == null) throw CanceledException(THISLOCATION);
			WeakRefPtr<IDispatcher> dispptr(req.dispatcher);
			jsonsrv::RpcRequest oldreq;
			oldreq.args = static_cast<const JSON::Value &>(req.params);
			oldreq.context = static_cast<const JSON::Value &>(req.context);
			oldreq.functionName = req.methodName.getStringA();
			oldreq.httpRequest = peer->getHttpRequest();
			oldreq.id = req.id.getStringA();
			oldreq.idnode = static_cast<const JSON::Value &>(req.id);
			oldreq.jsonFactory = req.json.factory;
			oldreq.serverStub = dispptr->getIfcPtr<jsonsrv::IJsonRpc>();
			JSON::Value oldres = (mptr)(&oldreq);
			out.getPromise().resolve(Response(oldres, oldreq.contextOut, oldreq.logOutput));
		} catch (...) {
			out.getPromise().rejectInCatch();
		}
		return out;
	}
Future<void> WebSocketsClient::onReconnect() {
	Future<void> r;
	queuedMsgs.push(r.getPromise());
	return r;
}