summaryrefslogblamecommitdiffstats
path: root/src/pvs.h
blob: e6e91edf1312bc4d4ebed28e94d8fce83f460941 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                               

                           








                                        


                      
                                        
 

                          
                 

                                   
                                   







































                                                                                                                         
                 



                                                                    


                                                  
                        


                                      


                                                                                                       
                                                                
 


                                                    












                                                                         




                                                                                                   
                                                                                                                



                                                                                                   
 






                                        











                                                                                   
                                                             
 












                                                                                                                           
                                                                                       
 

                                                                                              







                                                           
                        
 
                            
                                               
                              

                                                 

                         

                                                                     
                                                                     
 
                                                 
                                                                                                                                          
                                             
 


                                                                
                                                                
                                                                                        

                                                                

        
                         

                         
/*
 # 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>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#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 pvsConnect(QString host, QString passwd);
    void pvsDisconnect();
    QString isConnected();
    bool isRestricted();
    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 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?)
    BlankScreen *_blankScreen;///< object to blank the screen

    //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_ */