summaryrefslogtreecommitdiffstats
path: root/src/core/pvsConnectionManager.h
blob: 5f5fccabbfb41ca0d62d2fa4fda931e007e60651 (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
/**
  *	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