LCOV - code coverage report
Current view: top level - co - eventConnection.cpp (source / functions) Hit Total Coverage
Test: Collage Lines: 36 38 94.7 %
Date: 2018-01-09 16:37:03 Functions: 10 10 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2016, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This file is part of Collage <https://github.com/Eyescale/Collage>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #include "eventConnection.h"
      21             : #include "pipeConnection.h"
      22             : 
      23             : #include <lunchbox/scopedMutex.h>
      24             : 
      25             : namespace co
      26             : {
      27          54 : EventConnection::EventConnection()
      28             : #ifdef _WIN32
      29             :     : _event(CreateEvent(0, TRUE, FALSE, 0))
      30             : 
      31             : #else
      32          54 :     : _connection(new PipeConnection)
      33         108 :     , _set(false)
      34             : #endif
      35             : {
      36          54 : }
      37             : 
      38         156 : EventConnection::~EventConnection()
      39             : {
      40          52 :     _close();
      41             : 
      42             : #ifdef _WIN32
      43             :     if (_event)
      44             :         CloseHandle(_event);
      45             : #endif
      46         104 : }
      47             : 
      48          54 : bool EventConnection::connect()
      49             : {
      50          54 :     if (!isClosed())
      51           0 :         return false;
      52             : 
      53          54 :     _setState(STATE_CONNECTING);
      54             : 
      55             : #ifndef _WIN32
      56          54 :     LBCHECK(_connection->connect());
      57          54 :     _set = false;
      58             : #endif
      59             : 
      60          54 :     _setState(STATE_CONNECTED);
      61          53 :     return true;
      62             : }
      63             : 
      64         104 : void EventConnection::_close()
      65             : {
      66             : #ifndef _WIN32
      67         104 :     _connection->close();
      68             : #endif
      69         104 :     _setState(STATE_CLOSED);
      70         104 : }
      71             : 
      72         371 : void EventConnection::set()
      73             : {
      74             : #ifdef _WIN32
      75             :     SetEvent(_event);
      76             : #else
      77         708 :     lunchbox::ScopedWrite mutex(_lock);
      78         371 :     if (_set)
      79          34 :         return;
      80             : 
      81         337 :     const char c = 42;
      82         337 :     _connection->acceptSync()->send(&c, 1, true);
      83         337 :     _set = true;
      84             : #endif
      85             : }
      86         289 : void EventConnection::reset()
      87             : {
      88             : #ifdef _WIN32
      89             :     ResetEvent(_event);
      90             : #else
      91         578 :     lunchbox::ScopedWrite mutex(_lock);
      92         289 :     if (!_set)
      93           0 :         return;
      94             : 
      95         289 :     _buffer.setSize(0);
      96         289 :     _connection->recvNB(&_buffer, 1);
      97             : 
      98         578 :     BufferPtr buffer;
      99         289 :     _connection->recvSync(buffer);
     100         289 :     _set = false;
     101             : #endif
     102             : }
     103             : 
     104         188 : Connection::Notifier EventConnection::getNotifier() const
     105             : {
     106             : #ifdef _WIN32
     107             :     return _event;
     108             : #else
     109         188 :     return _connection->getNotifier();
     110             : #endif
     111             : }
     112          63 : }

Generated by: LCOV version 1.11