summaryrefslogblamecommitdiffstats
path: root/src/pvs.h
blob: 93596d24ced1c4c055e6bbb79b00e096b0613c35 (plain) (tree)





























                                                                               

                                   



















































                                                                                                                         




                                                                                                       












                                                                         





                                                                                                   
















































                                                                                                                           



                                                                     

                         
/*
 # 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"


class PVSServiceDiscovery;
class PVSDiscoveredServer;
class McastConfiguration;
class PVSOutgoingMulticastTransfer;

/**
 *     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:
    void 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);


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);

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?)
    BlankScreen *_blankScreen;///< obhject to blank the screen

    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

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

    QSettings _settings;

    PVSServiceDiscovery *_sdClient;

    PVSChatClient *_chat;

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

    int _timerLockTest;
    int _timerLockDelay;

    McastConfiguration* _masterMcastConfig;
    QHash<quint64, PVSOutgoingMulticastTransfer*> _outgoingTransfers;

    static quint64 generateMcastTransferID();
};
#endif /* PVSCLIENT_H_ */