2015-12-12 12:50:12 -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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_MASTERPROCESSSESSION_HPP
|
|
|
|
#define INCLUDED_MASTERPROCESSSESSION_HPP
|
|
|
|
|
2016-03-22 13:27:38 -05:00
|
|
|
#include <time.h>
|
|
|
|
|
2015-12-12 12:50:12 -06:00
|
|
|
#include <Poco/Random.h>
|
|
|
|
|
|
|
|
#include "LOOLSession.hpp"
|
2016-04-01 10:33:08 -05:00
|
|
|
#include "MessageQueue.hpp"
|
2015-12-12 12:50:12 -06:00
|
|
|
#include "TileCache.hpp"
|
|
|
|
|
2016-03-23 11:55:28 -05:00
|
|
|
class DocumentBroker;
|
|
|
|
|
2015-12-12 12:50:12 -06:00
|
|
|
class MasterProcessSession final : public LOOLSession, public std::enable_shared_from_this<MasterProcessSession>
|
|
|
|
{
|
2016-03-22 11:41:14 -05:00
|
|
|
public:
|
2015-12-27 21:47:39 -06:00
|
|
|
MasterProcessSession(const std::string& id,
|
|
|
|
const Kind kind,
|
2016-03-10 21:33:03 -06:00
|
|
|
std::shared_ptr<Poco::Net::WebSocket> ws,
|
2016-04-01 10:33:08 -05:00
|
|
|
std::shared_ptr<DocumentBroker> docBroker,
|
|
|
|
std::shared_ptr<BasicTileQueue> queue);
|
2015-12-12 12:50:12 -06:00
|
|
|
virtual ~MasterProcessSession();
|
|
|
|
|
2016-01-07 01:35:24 -06:00
|
|
|
virtual bool getStatus(const char *buffer, int length) override;
|
2015-12-12 12:50:12 -06:00
|
|
|
|
2016-01-07 01:35:24 -06:00
|
|
|
virtual bool getCommandValues(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
|
2015-12-12 12:50:12 -06:00
|
|
|
|
|
|
|
virtual bool getPartPageRectangles(const char *buffer, int length) override;
|
|
|
|
|
2016-01-21 08:26:34 -06:00
|
|
|
virtual void disconnect(const std::string& reason = "") override;
|
|
|
|
virtual bool handleDisconnect(Poco::StringTokenizer& tokens) override;
|
|
|
|
|
2015-12-12 12:50:12 -06: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 getSaveAs();
|
|
|
|
|
2016-03-12 18:29:17 -06:00
|
|
|
std::shared_ptr<DocumentBroker> getDocumentBroker() const { return _docBroker; }
|
2016-03-10 21:33:03 -06:00
|
|
|
|
2016-04-01 10:33:08 -05:00
|
|
|
std::shared_ptr<BasicTileQueue> getQueue() const { return _queue; }
|
|
|
|
|
2016-03-23 11:55:28 -05:00
|
|
|
void setEditLock(const bool value) { _bEditLock = value; }
|
|
|
|
|
|
|
|
bool isEditLocked() const { return _bEditLock; }
|
|
|
|
|
|
|
|
public:
|
2016-03-12 08:07:33 -06:00
|
|
|
// Sessions to pre-spawned child processes that have connected but are not yet assigned a
|
|
|
|
// document to work on.
|
|
|
|
static std::map<std::string, std::shared_ptr<MasterProcessSession>> AvailableChildSessions;
|
|
|
|
static std::mutex AvailableChildSessionMutex;
|
|
|
|
static std::condition_variable AvailableChildSessionCV;
|
|
|
|
|
2016-04-06 02:28:04 -05:00
|
|
|
time_t _lastUserInteractionTime;
|
2016-03-25 11:10:16 -05:00
|
|
|
time_t _idleSaveTime;
|
|
|
|
time_t _autoSaveTime;
|
2016-03-22 13:27:38 -05:00
|
|
|
|
2016-04-04 13:39:54 -05:00
|
|
|
// Raise this flag on ToClient from ToPrisoner to let ToClient know of load failures
|
|
|
|
bool _bLoadError = false;
|
|
|
|
|
2015-12-12 12:50:12 -06:00
|
|
|
protected:
|
|
|
|
bool invalidateTiles(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
|
|
|
|
virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
|
|
|
|
|
2016-01-07 01:35:24 -06:00
|
|
|
virtual void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
|
2015-12-12 12:50:12 -06:00
|
|
|
|
2016-01-14 06:00:04 -06:00
|
|
|
virtual void sendCombinedTiles(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
|
|
|
|
|
2016-01-07 01:35:24 -06:00
|
|
|
virtual void sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
|
2015-12-12 12:50:12 -06:00
|
|
|
|
2016-03-22 11:41:14 -05:00
|
|
|
private:
|
2015-12-12 12:50:12 -06:00
|
|
|
void dispatchChild();
|
|
|
|
void forwardToPeer(const char *buffer, int length);
|
|
|
|
|
|
|
|
// If _kind==ToPrisoner and the child process has started and completed its handshake with the
|
|
|
|
// parent process: Points to the WebSocketSession for the child process handling the document in
|
|
|
|
// question, if any.
|
|
|
|
|
|
|
|
// In the session to the child process, points to the LOOLSession for the LOOL client. This will
|
|
|
|
// obvious have to be rethought when we add collaboration and there can be several LOOL clients
|
|
|
|
// per document being edited (i.e., per child process).
|
|
|
|
std::weak_ptr<MasterProcessSession> _peer;
|
|
|
|
|
2016-01-03 13:52:32 -06:00
|
|
|
static
|
|
|
|
Poco::Path getJailPath(const std::string& childId);
|
|
|
|
|
2015-12-25 12:51:32 -06:00
|
|
|
virtual bool _handleInput(const char *buffer, int length) override;
|
|
|
|
|
2015-12-12 12:50:12 -06:00
|
|
|
int _curPart;
|
|
|
|
int _loadPart;
|
|
|
|
/// Kind::ToClient instances store URLs of completed 'save as' documents.
|
|
|
|
MessageQueue _saveAsQueue;
|
2016-03-12 18:29:17 -06:00
|
|
|
std::shared_ptr<DocumentBroker> _docBroker;
|
2016-04-01 10:33:08 -05:00
|
|
|
std::shared_ptr<BasicTileQueue> _queue;
|
2016-03-23 11:55:28 -05:00
|
|
|
|
|
|
|
// If this document holds the edit lock.
|
|
|
|
// An edit lock will only allow the current session to make edits,
|
|
|
|
// while other session opening the same document can only see
|
|
|
|
bool _bEditLock = false;
|
2015-12-12 12:50:12 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-03-18 09:09:15 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|