2016-05-16 06:37:02 -05: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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_CLIENTSSESSION_HPP
|
|
|
|
#define INCLUDED_CLIENTSSESSION_HPP
|
|
|
|
|
|
|
|
#include "LOOLSession.hpp"
|
|
|
|
#include "MessageQueue.hpp"
|
|
|
|
|
|
|
|
class DocumentBroker;
|
|
|
|
class PrisonerSession;
|
|
|
|
|
2016-09-16 01:56:35 -05:00
|
|
|
/// Represents a session to a LOOL client, in the WSD process.
|
2016-05-16 21:48:33 -05:00
|
|
|
class ClientSession final : public LOOLSession, public std::enable_shared_from_this<ClientSession>
|
2016-05-16 06:37:02 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 19:49:36 -05:00
|
|
|
ClientSession(const std::string& id,
|
|
|
|
std::shared_ptr<Poco::Net::WebSocket> ws,
|
|
|
|
std::shared_ptr<DocumentBroker> docBroker,
|
2016-07-10 23:50:25 -05:00
|
|
|
bool isReadOnly = false);
|
2016-05-16 06:37:02 -05:00
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
virtual ~ClientSession();
|
|
|
|
|
2016-07-10 23:50:25 -05:00
|
|
|
bool isReadOnly() const { return _isReadOnly; }
|
2016-05-16 17:22:41 -05:00
|
|
|
|
2016-05-16 21:48:33 -05:00
|
|
|
void setPeer(const std::shared_ptr<PrisonerSession>& peer) { _peer = peer; }
|
|
|
|
bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
|
2016-05-16 17:22:41 -05:00
|
|
|
|
2016-08-29 13:08:01 -05:00
|
|
|
void setUserName(const std::string& userName) { _userName = userName; }
|
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
/**
|
|
|
|
* Return the URL of the saved-as document when it's ready. If called
|
|
|
|
* before it's ready, the call blocks till then.
|
|
|
|
*/
|
|
|
|
std::string getSaveAsUrl()
|
|
|
|
{
|
|
|
|
const auto payload = _saveAsQueue.get();
|
|
|
|
return std::string(payload.data(), payload.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSaveAsUrl(const std::string& url)
|
|
|
|
{
|
|
|
|
_saveAsQueue.put(url);
|
|
|
|
}
|
|
|
|
|
2016-05-16 18:37:11 -05:00
|
|
|
bool isLoadFailed() const { return _loadFailed; }
|
|
|
|
void setLoadFailed(const std::string& reason)
|
|
|
|
{
|
|
|
|
Log::warn("Document load failed: " + reason);
|
|
|
|
_loadFailed = true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:03:45 -05:00
|
|
|
std::shared_ptr<DocumentBroker> getDocumentBroker() const { return _docBroker; }
|
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
private:
|
|
|
|
|
|
|
|
virtual bool _handleInput(const char *buffer, int length) override;
|
2016-05-16 06:37:02 -05:00
|
|
|
|
2016-05-16 18:11:34 -05:00
|
|
|
bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
|
2016-05-16 18:30:03 -05:00
|
|
|
bool getStatus(const char *buffer, int length);
|
|
|
|
bool getCommandValues(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool getPartPageRectangles(const char *buffer, int length);
|
2016-05-16 18:20:35 -05:00
|
|
|
|
2016-05-20 18:25:38 -05:00
|
|
|
bool sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool sendCombinedTiles(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
2016-05-16 18:20:35 -05:00
|
|
|
|
2016-05-16 06:37:02 -05:00
|
|
|
private:
|
|
|
|
|
2016-05-16 20:03:45 -05:00
|
|
|
std::shared_ptr<DocumentBroker> _docBroker;
|
|
|
|
|
2016-07-10 23:50:25 -05:00
|
|
|
// Whether the session is opened as readonly
|
|
|
|
bool _isReadOnly;
|
|
|
|
|
2016-05-16 22:02:05 -05:00
|
|
|
/// Our peer that connects us to the child.
|
2016-05-16 18:05:22 -05:00
|
|
|
std::weak_ptr<PrisonerSession> _peer;
|
2016-05-16 06:37:02 -05:00
|
|
|
|
2016-05-16 18:05:22 -05:00
|
|
|
/// Store URLs of completed 'save as' documents.
|
|
|
|
MessageQueue _saveAsQueue;
|
2016-05-16 06:37:02 -05:00
|
|
|
|
2016-05-16 18:37:11 -05:00
|
|
|
/// Marks if document loading failed.
|
|
|
|
bool _loadFailed;
|
2016-05-16 20:03:45 -05:00
|
|
|
int _loadPart;
|
2016-05-16 06:37:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|