summaryrefslogtreecommitdiffstats
path: root/src/pvs.h
blob: 49c2b4c247d08c1ae8d8e3533bfe20231da39679 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
 #
 # This program is free software distributed under the GPL version 2.
 # See http://openslx.org/COPYING
 #
 # If you have any feedback please consult http://openslx.org/feedback and
 # send your suggestions, praise, or complaints to feedback@openslx.org
 #
 # General information about OpenSLX can be found at http://openslx.org/
 */
#ifndef PVSCLIENT_H_
#define PVSCLIENT_H_

#include <QtCore>
#ifndef __WIN32__
   #include <X11/Xlib.h>
   #include <X11/cursorfont.h>
#endif
#include <signal.h>

#include "setup.h"
#include "src/core/pvsChatClient.h"
#include "src/core/pvsChatMsg.h"
#include "src/net/pvsServerConnection.h"
#include "src/version.h"
#include "src/util/consoleLogger.h"
#include "src/util/clientGUIUtils.h"
#include <QFile>
#include <QTextStream>
#include <QDir>
#include "src/input/inputEventHandler.h"

class PVSServiceDiscovery;
class PVSDiscoveredServer;
class InputEvent;
class McastConfiguration;
class PVSOutgoingMulticastTransfer;
class PVSIncomingMulticastTransfer;

/**
 *     PVSClient
 * base class for the pool video switch client
 */
class PVS: public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.openslx.pvs")

public:
    PVS();
    ~PVS();

    void loadCommands(); ///< not inherited, just named like the virtual methods of other net objects
    void onCommand(PVSMsg cmdMessage); ///< not inherited, just named like the virtual methods of other net objects
    void onLogin(PVSMsg cmdMessage); ///< not inherited, just named like the virtual methods of other net objects
    void onDaemonCommand(PVSMsg cmdMessage); ///< not inherited, just named like the virtual methods of other net objects
    void onMessage(PVSMsg cmdMessage);

    void securityUnlock()
    {
        unlock();
    }
    ; ///< public forward to the unlock method
    void stop(); ///< stop the client

    void setScriptPath(QString path); ///< vnc-start related

    void onConnected(QString name);
    void onDisconnected();

    void connectToHost(PVSDiscoveredServer* server, QString passwd);
    void UpdateChatClients(PVSChatMsg chatCommand);
    void chat_receive(PVSChatMsg msg);

    void guiAddHost(QString host);
    void guiDelHost(QString host);

public Q_SLOTS:
    bool start();
    void quit();
    void chat_send(QString nick_to, QString nick_from, QString msg);
    QString chat_getNickname();
    QStringList chat_getNicknames();
    void fileChanged(const QString& path);
    void pvsConnect(QString host, QString passwd);
    void pvsDisconnect();
    QString isConnected();
    QStringList getAvailableHosts();
    QString getIpByNick(QString nick);

    // Multicast File Transfer
    bool createMulticastTransfer(QString const& objectPath, quint64& transferID, QString& errorReason);
    void cancelOutgoingMulticastTransfer(quint64 transferID);
    void cancelIncomingMulticastTransfer(qulonglong transferID);

    void setConfigValue(QString key, QString value);
    QString getConfigValue(QString key);

Q_SIGNALS:
    void project(QString host, int port, QString passwd, bool fullscreen,
                 bool smoothTransformation, int quality);
    void unproject();
    void chat_receive(QString nick_from, QString nick_to, QString msg);
    void chat_client_add(QString nick);
    void chat_client_remove(QString nick);
    void showMessage(QString title, QString msg, bool useDialog = false);
    void connected(QString host);
    void disconnected();
    void addHost(QString host);
    void delHost(QString host);

    // Multicast File Transfer
    void outgoingMulticastTransferStarted(qulonglong transferID);
    void outgoingMulticastTransferProgress(qulonglong transferID, qulonglong bytes, qulonglong of);
    void outgoingMulticastTransferFinished(qulonglong transferID);
    void outgoingMulticastTransferFailed(qulonglong transferID, QString reason);
    void incomingMulticastTransferNew(qulonglong transferID, QString sender, QString filename, qulonglong size);
    void incomingMulticastTransferStarted(qulonglong transferID);
    void incomingMulticastTransferProgress(qulonglong transferID, qulonglong bytes, qulonglong of);
    void incomingMulticastTransferFinished(qulonglong transferID);
    void incomingMulticastTransferFailed(qulonglong transferID, QString reason);

protected:

    void timerEvent(QTimerEvent *event);

private:

    // own
    bool allowExists(); ///< whether the .allow file exists
    bool getVNCAllow(); ///< whether vnc-connections to this client are allowed
    void readPolicyFiles(); ///< pars the policy files


    // pvs features and related
    bool lock(); ///< lock this client (blankscreen etc)
    bool lock_inputs(); ///< lock this client mouse&keyboard only
    bool unlock(); ///< remove the lock on this client

    bool _locked; ///< are we locked?
    QString _lockMsg; ///<  message to display while we're locked
    bool _vncAllowed; ///< whether vncConnections to this client are allowed (dup?)
    /*#ifndef __WIN32__*/
        BlankScreen *_blankScreen;///< object to blank the screen
    /*#endif*/

    QFileSystemWatcher* _notify; ///< used to get notifies about file changes
    //vnc-server
    QString _vncScriptPath; ///< path to the vnc script file
    QString _vncScriptName; ///< name of the vnc script file
    int _vncPort; ///< port to use for the vnc-server (also gets send to the pvsServer)
    QString _vncPassword; ///< password to use for the vnc-server (also gets send to the pvsServer) - viewonly password
    QString _vncRwPassword; ///< password to use for the vnc-server (also gets send to the pvsServer) - read-write password

    bool gotVNCScript(); ///< whether we got a vnc script
    int bootVNC(); ///< init the password and port, then call the startVNCScript() method
    int startVNCScript(int port, QString pass, QString rwpass); ///< start the vnc server (via script)
    int stopVNCScript(); ///< stop the vnc server (via script)
    static void signalHandler(int signal); //handles posix signals

    void showProc(QString filter); //sends list of user processes to connection manager

    PVSServerConnection* _pvsServerConnection; ///< our tcp connection object to the pvsserver

    PVSServiceDiscovery *_sdClient;

    PVSChatClient *_chat;

    bool _vncRequested; ///< did pvsmgr request our screen?

    int _timerLockTest;
    int _timerLockDelay;
    QString processName;

    // input event handling:
    InputEventHandlerChain _inputEventHandlers;
    bool inputEventsAllowed();
    void handleInputEvent(InputEvent const& evt);
    void initializeInputEventHandling();

    // multicast transfer
    McastConfiguration* _masterMcastConfig;
    QHash<quint64, PVSOutgoingMulticastTransfer*> _outgoingTransfers;
    QHash<quint64, PVSIncomingMulticastTransfer*> _incomingTransfers;

    void loadMcastConfig(QString const& encoded);
    void onIncomingMulticastTransfer(QString const& sender, qulonglong transferID, QString const& basename, qulonglong size, ushort port);
    static quint64 generateMcastTransferID();

private Q_SLOTS:
    // housekeeping
    void outgoingMulticastTransferDelete(qulonglong transferID);
    void incomingMulticastTransferDelete(qulonglong transferID);
    void onIncomingMulticastTransferRetry(QString const& sender, qulonglong transferID);
    void processStartErrorOccured(QProcess::ProcessError error);
    void processStopErrorOccured(QProcess::ProcessError error);

private:
    QSettings _settings;
};
#endif /* PVSCLIENT_H_ */