2016-01-06 07:18:56 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Poco/Runnable.h>
|
|
|
|
|
2016-11-24 08:56:06 -06:00
|
|
|
#include "Protocol.hpp"
|
|
|
|
#include "Session.hpp"
|
2016-10-29 20:15:00 -05:00
|
|
|
#include "MessageQueue.hpp"
|
2016-01-06 07:18:56 -06:00
|
|
|
#include "Util.hpp"
|
|
|
|
|
2016-01-28 12:16:32 -06:00
|
|
|
/// This thread handles incoming messages on a given kit instance.
|
2016-10-29 20:15:00 -05:00
|
|
|
class QueueHandler : public Poco::Runnable
|
2016-01-06 07:18:56 -06:00
|
|
|
{
|
|
|
|
public:
|
2016-04-01 10:33:08 -05:00
|
|
|
QueueHandler(std::shared_ptr<MessageQueue> queue,
|
2016-12-12 18:53:58 -06:00
|
|
|
const std::shared_ptr<Session>& session,
|
2016-01-06 07:38:21 -06:00
|
|
|
const std::string& name):
|
2016-08-18 01:18:54 -05:00
|
|
|
_queue(std::move(queue)),
|
2016-01-06 07:38:21 -06:00
|
|
|
_session(session),
|
|
|
|
_name(name)
|
2016-01-06 07:18:56 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void run() override
|
|
|
|
{
|
2016-04-07 02:55:57 -05:00
|
|
|
Util::setThreadName(_name);
|
2016-02-29 06:25:12 -06:00
|
|
|
|
2018-01-14 19:39:06 -06:00
|
|
|
LOG_DBG("Thread started.");
|
2016-01-06 07:18:56 -06:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
2016-04-01 10:33:08 -05:00
|
|
|
const auto input = _queue->get();
|
2016-03-27 13:51:54 -05:00
|
|
|
if (LOOLProtocol::getFirstToken(input) == "eof")
|
2016-01-06 12:59:15 -06:00
|
|
|
{
|
2018-01-14 19:39:06 -06:00
|
|
|
LOG_INF("Received EOF. Finishing.");
|
2016-01-06 07:18:56 -06:00
|
|
|
break;
|
2016-01-06 12:59:15 -06:00
|
|
|
}
|
|
|
|
|
2016-03-26 21:56:10 -05:00
|
|
|
if (!_session->handleInput(input.data(), input.size()))
|
2016-01-06 12:59:15 -06:00
|
|
|
{
|
2018-01-14 19:39:06 -06:00
|
|
|
LOG_INF("Socket handler flagged for finishing.");
|
2016-01-06 07:18:56 -06:00
|
|
|
break;
|
2016-01-06 12:59:15 -06:00
|
|
|
}
|
2016-01-06 07:18:56 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& exc)
|
|
|
|
{
|
2018-01-14 19:39:06 -06:00
|
|
|
LOG_ERR("QueueHandler::run: Exception: " << exc.what());
|
2016-01-06 07:18:56 -06:00
|
|
|
}
|
|
|
|
|
2018-01-14 19:39:06 -06:00
|
|
|
LOG_DBG("Thread finished.");
|
2016-01-06 07:18:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-04-01 10:33:08 -05:00
|
|
|
std::shared_ptr<MessageQueue> _queue;
|
2016-12-12 18:53:58 -06:00
|
|
|
std::shared_ptr<Session> _session;
|
2016-01-06 07:38:21 -06:00
|
|
|
const std::string _name;
|
2016-01-06 07:18:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|