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 "eventHandler.h"
21 : #include "X11Connection.h"
22 :
23 : #ifdef EQUALIZER_USE_DISPLAYCLUSTER
24 : # include "../dc/connection.h"
25 : # include "../dc/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 15 : MessagePump::MessagePump()
36 : {
37 15 : }
38 :
39 30 : MessagePump::~MessagePump()
40 : {
41 30 : }
42 :
43 233 : void MessagePump::postWakeup()
44 : {
45 233 : _connections.interrupt();
46 233 : }
47 :
48 2658 : void MessagePump::dispatchOne( const uint32_t timeout )
49 : {
50 2658 : const co::ConnectionSet::Event event = _connections.select( timeout );
51 2658 : 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_DISPLAYCLUSTER
64 : co::ConnectionPtr connection = _connections.getConnection();
65 : const dc::Connection* dcConnection =
66 : dynamic_cast< const dc::Connection* >( connection.get( ));
67 : if( dcConnection )
68 : dc::EventHandler::processEvents( dcConnection->getProxy( ));
69 : else
70 : #endif
71 2590 : EventHandler::dispatch();
72 2590 : break;
73 : }
74 :
75 : case co::ConnectionSet::EVENT_INTERRUPT:
76 68 : 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 2658 : }
88 :
89 3026 : void MessagePump::dispatchAll()
90 : {
91 3026 : EventHandler::dispatch();
92 : #ifdef EQUALIZER_USE_DISPLAYCLUSTER
93 : dc::EventHandler::processEvents();
94 : #endif
95 3026 : }
96 :
97 15 : void MessagePump::register_( Display* display )
98 : {
99 15 : if( ++_referenced[ display ] == 1 )
100 15 : _connections.addConnection( new X11Connection( display ));
101 15 : }
102 :
103 15 : void MessagePump::deregister( Display* display )
104 : {
105 15 : if( --_referenced[ display ] == 0 )
106 : {
107 15 : const co::Connections& connections = _connections.getConnections();
108 45 : for( co::Connections::const_iterator i = connections.begin();
109 30 : i != connections.end(); ++i )
110 : {
111 15 : co::ConnectionPtr connection = *i;
112 : const X11Connection* x11Connection =
113 15 : dynamic_cast< const X11Connection* >( connection.get( ));
114 15 : if( x11Connection && x11Connection->getDisplay() == display )
115 : {
116 15 : _connections.removeConnection( connection );
117 15 : break;
118 : }
119 0 : }
120 15 : _referenced.erase( _referenced.find( display ));
121 : }
122 15 : }
123 :
124 0 : void MessagePump::register_( dc::Proxy* dcProxy LB_UNUSED )
125 : {
126 : #ifdef EQUALIZER_USE_DISPLAYCLUSTER
127 : if( ++_referenced[ dcProxy ] == 1 )
128 : _connections.addConnection( new dc::Connection( dcProxy ));
129 : #endif
130 0 : }
131 :
132 0 : void MessagePump::deregister( dc::Proxy* dcProxy LB_UNUSED )
133 : {
134 : #ifdef EQUALIZER_USE_DISPLAYCLUSTER
135 : if( --_referenced[ dcProxy ] == 0 )
136 : {
137 : const co::Connections& connections = _connections.getConnections();
138 : for( co::Connections::const_iterator i = connections.begin();
139 : i != connections.end(); ++i )
140 : {
141 : co::ConnectionPtr connection = *i;
142 : const dc::Connection* dcConnection =
143 : dynamic_cast< const dc::Connection* >( connection.get( ));
144 : if( dcConnection && dcConnection->getProxy() == dcProxy )
145 : {
146 : _connections.removeConnection( connection );
147 : break;
148 : }
149 : }
150 : _referenced.erase( _referenced.find( dcProxy ));
151 : }
152 : #endif
153 0 : }
154 :
155 : }
156 36 : }
|