1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#include "qjsontypedrpc_p.h"
4#include <QtCore/QtGlobal>
5
6QT_BEGIN_NAMESPACE
7
8namespace QJsonRpc {
9void TypedResponse::addOnCloseAction(const OnCloseAction &act)
10{
11 switch (m_status) {
12 case Status::Started:
13 m_onCloseActions.append(t: act);
14 break;
15 case Status::Invalid:
16 qCWarning(QTypedJson::jsonRpcLog)
17 << "addOnCloseAction called on moved QJsonTypedResponse" << idToString(v: m_id);
18 Q_ASSERT(false);
19 Q_FALLTHROUGH();
20 case Status::SentSuccess:
21 case Status::SentError:
22 act(m_status, m_id, *m_typedRpc);
23 break;
24 }
25}
26
27void TypedResponse::doOnCloseActions()
28{
29 m_typedRpc->doOnCloseAction(m_status, m_id);
30 for (const auto &a : m_onCloseActions) {
31 a(m_status, m_id, *m_typedRpc);
32 }
33 m_onCloseActions.clear();
34}
35
36void TypedResponse::sendErrorResponse(int code, const QByteArray &message)
37{
38 sendErrorResponse<std::optional<int>>(code, message, data: std::optional<int>());
39}
40
41void TypedRpc::installOnCloseAction(const TypedResponse::OnCloseAction &closeAction)
42{
43 m_onCloseAction = closeAction;
44}
45
46TypedResponse::OnCloseAction TypedRpc::onCloseAction()
47{
48 return m_onCloseAction;
49}
50
51void TypedRpc::doOnCloseAction(TypedResponse::Status status, const IdType &id)
52{
53 if (m_onCloseAction)
54 m_onCloseAction(status, id, *this);
55}
56
57} // namespace QJsonRpc
58
59QT_END_NAMESPACE
60

source code of qtlanguageserver/src/jsonrpc/qjsontypedrpc.cpp