2015-03-04 17:14:04 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2015-03-09 03:01:30 -05:00
|
|
|
#ifndef INCLUDED_LOOLSESSION_HPP
|
|
|
|
#define INCLUDED_LOOLSESSION_HPP
|
|
|
|
|
2015-03-09 10:33:53 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-03-04 17:14:04 -06:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.h>
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
|
|
|
|
|
|
|
#include <Poco/Net/WebSocket.h>
|
2015-03-17 18:56:15 -05:00
|
|
|
#include <Poco/Buffer.h>
|
2015-03-04 17:14:04 -06:00
|
|
|
#include <Poco/StringTokenizer.h>
|
2015-03-17 18:56:15 -05:00
|
|
|
#include <Poco/Types.h>
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-03-12 18:34:42 -05:00
|
|
|
#include "TileCache.hpp"
|
|
|
|
|
|
|
|
class LOOLSession
|
2015-03-04 17:14:04 -06:00
|
|
|
{
|
2015-03-12 18:34:42 -05:00
|
|
|
public:
|
2015-03-17 18:56:15 -05:00
|
|
|
LOOLSession(Poco::Net::WebSocket& ws, LibreOfficeKit *loKit = nullptr);
|
2015-03-09 03:01:30 -05:00
|
|
|
~LOOLSession();
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-03-07 05:23:46 -06:00
|
|
|
bool handleInput(char *buffer, int length);
|
2015-03-12 18:34:42 -05:00
|
|
|
bool haveSeparateProcess() const;
|
2015-03-17 18:56:15 -05:00
|
|
|
bool toChildProcess() const;
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-03-04 17:14:04 -06:00
|
|
|
void sendTextFrame(std::string text);
|
|
|
|
void sendBinaryFrame(const char *buffer, int length);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
|
|
|
private:
|
2015-03-17 18:56:15 -05:00
|
|
|
bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
|
|
|
bool getStatus(const char *buffer, int length);
|
2015-03-04 17:14:04 -06:00
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
void forkOff();
|
|
|
|
void forwardRequest(const char *buffer, int length);
|
2015-03-09 10:33:53 -05:00
|
|
|
|
2015-03-12 09:18:35 -05:00
|
|
|
std::string _docURL;
|
|
|
|
|
2015-03-17 18:56:15 -05:00
|
|
|
bool isChildProcess() const;
|
|
|
|
|
|
|
|
// Fields common to parent and child:
|
|
|
|
|
|
|
|
// In the parent process, the websocket to the LOOL client or the
|
|
|
|
// child process. In a child process, the websocket to the
|
|
|
|
// parent.
|
2015-03-04 17:14:04 -06:00
|
|
|
Poco::Net::WebSocket& _ws;
|
2015-03-12 18:34:42 -05:00
|
|
|
|
|
|
|
std::unique_ptr<TileCache> _tileCache;
|
2015-03-17 18:56:15 -05:00
|
|
|
|
|
|
|
// Whether this session is to a LOOL client or to a child process
|
|
|
|
bool _toChildProcess;
|
|
|
|
|
|
|
|
// Parent only:
|
|
|
|
|
|
|
|
// In sessions to LOOL clients only:
|
|
|
|
|
|
|
|
// This points to the other websocket to the child process handling the
|
|
|
|
// document in question, if any. (If haveSeparateProcess() is true
|
|
|
|
// and the child process has started and completed its handshake
|
|
|
|
// with the parent process). In the session to the child process,
|
|
|
|
// this points to the websocket to the LOOL client.
|
|
|
|
Poco::Net::WebSocket *_peerWs;
|
|
|
|
|
|
|
|
// The id of the child process
|
|
|
|
Poco::UInt64 _childId;
|
|
|
|
|
|
|
|
// Buffer for requests to be forwarded to the child process once
|
|
|
|
// it has completed its handshake.
|
|
|
|
std::vector<Poco::Buffer<char>*> _backLog;
|
|
|
|
|
|
|
|
// Map from child ids to the corresponding client session
|
|
|
|
static std::map<Poco::UInt64, LOOLSession*> _childToClient;
|
|
|
|
|
|
|
|
// Child only:
|
|
|
|
LibreOfficeKit *_loKit;
|
|
|
|
LibreOfficeKitDocument *_loKitDocument;
|
2015-03-04 17:14:04 -06:00
|
|
|
};
|
|
|
|
|
2015-03-09 03:01:30 -05:00
|
|
|
#endif
|
|
|
|
|
2015-03-04 17:14:04 -06:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|