Line data Source code
1 :
2 : /* Copyright (c) 2007-2012, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include "messagePump.h"
19 :
20 : #include "X11Connection.h"
21 : #include "eventHandler.h"
22 :
23 : #ifdef EQUALIZER_USE_DEFLECT
24 : #include "../deflect/connection.h"
25 : #include "../deflect/eventHandler.h"
26 : #endif
27 :
28 : #include <lunchbox/debug.h>
29 : #include <lunchbox/log.h>
30 :
31 : namespace eq
32 : {
33 : namespace glx
34 : {
35 2 : MessagePump::MessagePump()
36 : {
37 2 : }
38 :
39 4 : MessagePump::~MessagePump()
40 : {
41 4 : }
42 :
43 47 : void MessagePump::postWakeup()
44 : {
45 47 : _connections.interrupt();
46 47 : }
47 :
48 6942 : void MessagePump::dispatchOne(const uint32_t timeout)
49 : {
50 6942 : const co::ConnectionSet::Event event = _connections.select(timeout);
51 6942 : switch (event)
52 : {
53 : case co::ConnectionSet::EVENT_DISCONNECT:
54 : {
55 0 : co::ConnectionPtr connection = _connections.getConnection();
56 0 : _connections.removeConnection(connection);
57 0 : LBERROR << "Display connection shut down" << std::endl;
58 0 : break;
59 : }
60 :
61 : case co::ConnectionSet::EVENT_DATA:
62 : {
63 : #ifdef EQUALIZER_USE_DEFLECT
64 13860 : co::ConnectionPtr connection = _connections.getConnection();
65 : const deflect::Connection* dcConnection =
66 6930 : dynamic_cast<const deflect::Connection*>(connection.get());
67 6930 : if (dcConnection)
68 0 : deflect::EventHandler::processEvents(dcConnection->getProxy());
69 : else
70 : #endif
71 6930 : EventHandler::dispatch();
72 6930 : break;
73 : }
74 :
75 : case co::ConnectionSet::EVENT_INTERRUPT:
76 12 : break;
77 :
78 : case co::ConnectionSet::EVENT_CONNECT:
79 : case co::ConnectionSet::EVENT_ERROR:
80 : default:
81 0 : LBWARN << "Error during select" << std::endl;
82 0 : break;
83 :
84 : case co::ConnectionSet::EVENT_TIMEOUT:
85 0 : break;
86 : }
87 6942 : }
88 :
89 7014 : void MessagePump::dispatchAll()
90 : {
91 7014 : EventHandler::dispatch();
92 : #ifdef EQUALIZER_USE_DEFLECT
93 7014 : deflect::EventHandler::processEvents();
94 : #endif
95 7014 : }
96 :
97 2 : void MessagePump::register_(Display* display)
98 : {
99 2 : if (++_referenced[display] == 1)
100 2 : _connections.addConnection(new X11Connection(display));
101 2 : }
102 :
103 2 : void MessagePump::deregister(Display* display)
104 : {
105 2 : if (--_referenced[display] == 0)
106 : {
107 2 : const co::Connections& connections = _connections.getConnections();
108 6 : for (co::Connections::const_iterator i = connections.begin();
109 4 : i != connections.end(); ++i)
110 : {
111 2 : co::ConnectionPtr connection = *i;
112 : const X11Connection* x11Connection =
113 2 : dynamic_cast<const X11Connection*>(connection.get());
114 2 : if (x11Connection && x11Connection->getDisplay() == display)
115 : {
116 2 : _connections.removeConnection(connection);
117 2 : break;
118 : }
119 : }
120 2 : _referenced.erase(_referenced.find(display));
121 : }
122 2 : }
123 :
124 0 : void MessagePump::register_(deflect::Proxy* proxy LB_UNUSED)
125 : {
126 : #ifdef EQUALIZER_USE_DEFLECT
127 0 : if (++_referenced[proxy] == 1)
128 0 : _connections.addConnection(new deflect::Connection(proxy));
129 : #endif
130 0 : }
131 :
132 0 : void MessagePump::deregister(deflect::Proxy* proxy LB_UNUSED)
133 : {
134 : #ifdef EQUALIZER_USE_DEFLECT
135 0 : if (--_referenced[proxy] == 0)
136 : {
137 0 : const co::Connections& connections = _connections.getConnections();
138 0 : for (co::Connections::const_iterator i = connections.begin();
139 0 : i != connections.end(); ++i)
140 : {
141 0 : co::ConnectionPtr connection = *i;
142 : const deflect::Connection* dcConnection =
143 0 : dynamic_cast<const deflect::Connection*>(connection.get());
144 0 : if (dcConnection && dcConnection->getProxy() == proxy)
145 : {
146 0 : _connections.removeConnection(connection);
147 0 : break;
148 : }
149 : }
150 0 : _referenced.erase(_referenced.find(proxy));
151 : }
152 : #endif
153 0 : }
154 : }
155 30 : }
|