LCOV - code coverage report
Current view: top level - eq/glx - messagePump.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 17 64 26.6 %
Date: 2016-09-29 05:02:09 Functions: 8 12 66.7 %

          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_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           1 : MessagePump::MessagePump()
      36             : {
      37           1 : }
      38             : 
      39           2 : MessagePump::~MessagePump()
      40             : {
      41           2 : }
      42             : 
      43           9 : void MessagePump::postWakeup()
      44             : {
      45           9 :     _connections.interrupt();
      46           9 : }
      47             : 
      48           2 : void MessagePump::dispatchOne( const uint32_t timeout )
      49             : {
      50           2 :     const co::ConnectionSet::Event event = _connections.select( timeout );
      51           2 :     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           0 :             co::ConnectionPtr connection = _connections.getConnection();
      65             :             const deflect::Connection* dcConnection =
      66           0 :                 dynamic_cast< const deflect::Connection* >( connection.get( ));
      67           0 :             if( dcConnection )
      68           0 :                deflect::EventHandler::processEvents( dcConnection->getProxy( ));
      69             :             else
      70             : #endif
      71           0 :             EventHandler::dispatch();
      72           0 :             break;
      73             :         }
      74             : 
      75             :         case co::ConnectionSet::EVENT_INTERRUPT:
      76           2 :             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           2 : }
      88             : 
      89          19 : void MessagePump::dispatchAll()
      90             : {
      91          19 :     EventHandler::dispatch();
      92             : #ifdef EQUALIZER_USE_DEFLECT
      93          19 :     deflect::EventHandler::processEvents();
      94             : #endif
      95          19 : }
      96             : 
      97           0 : void MessagePump::register_( Display* display )
      98             : {
      99           0 :     if( ++_referenced[ display ] == 1 )
     100           0 :         _connections.addConnection( new X11Connection( display ));
     101           0 : }
     102             : 
     103           0 : void MessagePump::deregister( Display* display )
     104             : {
     105           0 :     if( --_referenced[ display ] == 0 )
     106             :     {
     107           0 :         const co::Connections& connections = _connections.getConnections();
     108           0 :         for( co::Connections::const_iterator i = connections.begin();
     109           0 :              i != connections.end(); ++i )
     110             :         {
     111           0 :             co::ConnectionPtr connection = *i;
     112             :             const X11Connection* x11Connection =
     113           0 :                 dynamic_cast< const X11Connection* >( connection.get( ));
     114           0 :             if( x11Connection && x11Connection->getDisplay() == display )
     115             :             {
     116           0 :                 _connections.removeConnection( connection );
     117           0 :                 break;
     118             :             }
     119           0 :         }
     120           0 :         _referenced.erase( _referenced.find( display ));
     121             :     }
     122           0 : }
     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           0 :         }
     150           0 :         _referenced.erase( _referenced.find( proxy ));
     151             :     }
     152             : #endif
     153           0 : }
     154             : 
     155             : }
     156          42 : }

Generated by: LCOV version 1.11