summaryrefslogblamecommitdiffstats
path: root/src/core/pvsConnectionManager.h
blob: 5f5fccabbfb41ca0d62d2fa4fda931e007e60651 (plain) (tree)





















































































































                                                                                                                                                                                  
/**
  *	The PVSConnection Manager is the heart and core of the PVS. He creates, updates, delivers and deletes the connections.
  *
  */



// TODO:
// make it look good ;-)



#include <QtGui>
#include <iostream>
#include <fstream>
#include <list>
#include <src/core/pvsClient.h>
#include <src/gui/mainWindow.h>
#include <src/core/pvsServer.h>
#ifndef _PVSCONNECTIONMANAGER_H_
#define _PVSCONNECTIONMANAGER_H_
#ifndef RFBCLIENT_H
extern "C"
{
#include <rfb/rfbclient.h>
}
#endif

#define PROFILE
#include <src/util/timeUtil.h>
#include <src/util/consoleLogger.h>
#include "src/net/pvsServiceBroadcast.h"



class PVSConnectionManager; //forward declaration
class PVSClient;
class PVSListenSever;
class MainWindow;

class PVSConnectionManager : public QObject
{
public:
    // singleton getter
    static PVSConnectionManager* getManager();

    ~PVSConnectionManager();

    // PVSServer control/get/set methods
    PVSServer* getServer()
    {
        return &_pvsServer;
    };

    // VNCConnection related static method
    //static void onFBUpdate(rfbClient* client, int x, int y, int w, int h);


    // gui update frequency
    void setUpdateRate(int newRate);


    // PVSConnection control/get/set methods
    std::list<PVSClient*> getConnections()
    {
        return _listClients;
    };
    void onClientNew(PVSClientConnection* newConnection);   // called by the server when a new client connects
    void onClientRemove(PVSClientConnection* removedConnection); // called by the server when a new client disconnects (on its own)
    PVSClient* getClientFromConnection(PVSClientConnection* client);
    PVSClient* getClientFromConnectionId(int id);
    PVSClient* getClientFromVNCConnection(VNCConnection* client);
    PVSClient* getClientFromIp(QString ip);	// returns connection with hostname 'host'
    PVSClient* getClientFromUsername(QString name); // returns connection with username 'name'
    // these methods are called by the PVSServer which forwards the command/etc handling to the CM
    void onCommand(PVSMsg command);
    void onChat(PVSMsg chatMsg);
    void onVncPassword(PVSMsg command);
    void onVncRwPassword(PVSMsg command);
    void onLoginUsername(PVSMsg command);
    void onLoginPassword(PVSMsg command);
    void onVncAllow(PVSMsg command);
    void onVncPort(PVSMsg command);
    void onVncProjection(PVSMsg command);

    void sendEventToClients(QString event, PVSClientConnection* newConnection, QString newClientName);  // informs every connected clients about a new client or a removed client.

    void removeConnection(PVSClient* removedConnection);	// removes and deletes the connection !DOES NOT DISCONNECT DIRECTLY!
    PVSClient* getNewConnection(VNCConnectInfo* newConInfo); // returns a new connection object based on the VNCConnectInfo or NULL

    bool isBusy() { return _busy; }

    QString setNeedPassword(bool enabled);
    QString getSessionName();

protected:
    void timerEvent(QTimerEvent *event);

private:
    // C'Tor
    PVSConnectionManager();	// private due to singleton pattern
    // internal control methods
    bool update(); 		// does the update and cleaning routines and makes sure the framebuffers in the connection objects are up to date
    void loadCommands();

    // Member
    std::list<PVSClient*> _listClients;	// list of all verified clients
    PVSServer _pvsServer; // the server that handles the pvsConnections
    static PVSConnectionManager* singleCM;	// the CM itself
    bool _busy;				// to keep timed calls from starting another update before the old one is thru.
    PVSServiceBroadcast _sdBroadcaster; ///< Service discovery handling

    QString _password; ///< Password required to connect (can be empty)
    bool _needPassword;
    int _timerId;
};

#endif