summaryrefslogtreecommitdiff
path: root/x11/ipc/server/ocopserver.h
blob: 3e08d5b5bba7424da4ac6b1035a438c9653b70af (plain)
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

#ifndef OPIE_OCOP_SERVER_H
#define OPIE_OCOP_SERVER_H

#include <sys/un.h>

#include <qvaluelist.h>
#include <qobject.h>
#include <qmap.h>
#include <qstring.h>
#include <qsocketnotifier.h>

#include "../common/ocoppacket.h"
#include "ocopclient.h"
/**
 * This is the main server
 * It starts the socket
 * takes care of the receiving and sending
 */
class OCopServer : public QObject {
    Q_OBJECT
public:
    OCopServer();
    ~OCopServer();

    QStringList channels();
    bool isChannelRegistered(const QCString& )const;

private slots:
    void errorOnServer();// error on Server
    void newOnServer();// accept to be taken
    void newOnClient(int fd ); // new package received

private:
    /* replace fd with a special class in future
     * to even work on Windoze aye aye
     */
    /**
     * add a channel with a fd
     * if the channel is not present
     * then it'll be created
     * if it's present we will ad the fd
     */
    void addChannel( const QCString& channel,
                     int fd );
    void delChannel( const QCString& channel,
                     int fd );

    /**
     * fd was closed
     */
    void deregisterClient( int fd );

    /**
     * fd popped up
     */
    void registerClient( int fd );

private:
    void init();
private slots:
    void initSocket();
private:
    int accept();
    void isRegistered( const QCString& channel, int );
    void dispatch( const OCOPPacket&, int sourceFD );
    void call( const OCOPPacket&, int sourceFD );
    QValueList<int> clients(const QCString& channel );
    /*
     * All clients
     * They include a fd and a QSocketNotifier
     */
    QMap<int, OCOPClient> m_clients;

    /*
     * The channels avilable
     */
    QMap<QCString, QValueList<int> > m_channels;

    /*
     * a notifier for our server
     * if new stuff is arriving
     */
    QSocketNotifier* m_server;

    /*
     * error
     */
    QSocketNotifier* m_serverError;
    int m_serverfd;
    struct sockaddr_un m_address;
    unsigned int m_adrlaenge;
};

#endif