@@ -84,10 +84,20 @@ JsonAPI::JsonAPI(QString peerAddress, Logger *log, bool localConnection, QObject
8484 ,_noListener(noListener)
8585 ,_peerAddress (std::move(peerAddress))
8686 ,_jsonCB (nullptr )
87+ ,_isServiceAvailable(false )
8788{
8889 Q_INIT_RESOURCE (JSONRPC_schemas);
8990
9091 qRegisterMetaType<Event>(" Event" );
92+
93+ connect (EventHandler::getInstance ().data (), &EventHandler::signalEvent, [=](const Event &event) {
94+ if (event == Event::Quit)
95+ {
96+ _isServiceAvailable = false ;
97+ Info (_log, " JSON-API service stopped" );
98+ }
99+ });
100+
91101 _jsonCB = QSharedPointer<JsonCallbacks>(new JsonCallbacks ( _log, _peerAddress, parent));
92102}
93103
@@ -117,6 +127,9 @@ void JsonAPI::initialize()
117127 // notify the forwarder about a jsonMessageForward request
118128 QObject::connect (this , &JsonAPI::forwardJsonMessage, GlobalSignals::getInstance (), &GlobalSignals::forwardJsonMessage, Qt::UniqueConnection);
119129#endif
130+
131+ Info (_log, " JSON-API service is ready to process requests" );
132+ _isServiceAvailable = true ;
120133}
121134
122135bool JsonAPI::handleInstanceSwitch (quint8 instanceID, bool /* forced*/ )
@@ -183,6 +196,13 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
183196 return ;
184197 }
185198
199+ // Do not further handle requests, if service is not available
200+ if (!_isServiceAvailable)
201+ {
202+ sendErrorReply (" Service Unavailable" , cmd);
203+ return ;
204+ }
205+
186206 if (_noListener)
187207 {
188208 setAuthorization (false );
@@ -330,7 +350,7 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject
330350 return ;
331351 }
332352
333- // Execute the command for each valid instance
353+ // Execute the command for each valid instance; Hyperion is about to quit
334354 for (const auto &instanceId : std::as_const (instanceIds))
335355 {
336356 if (isRunningInstanceRequired == InstanceCmd::MustRun_Yes || _currInstanceIndex == NO_INSTANCE_ID)
0 commit comments