LCOV - code coverage report
Current view: top level - eq/fabric - client.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 37 50 74.0 %
Date: 2017-12-16 05:07:20 Functions: 7 9 77.8 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2015, Stefan Eilemann <eile@eyescale.ch>
       3             :  *                          Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "client.h"
      20             : 
      21             : #include "global.h"
      22             : #include "nodeType.h"
      23             : 
      24             : #include <eq/fabric/commands.h>
      25             : 
      26             : #include <co/commandQueue.h>
      27             : #include <co/connection.h>
      28             : #include <co/connectionDescription.h>
      29             : #include <co/iCommand.h>
      30             : #include <lunchbox/dso.h>
      31             : 
      32             : namespace eq
      33             : {
      34             : namespace fabric
      35             : {
      36             : namespace detail
      37             : {
      38             : class Client
      39             : {
      40             : };
      41             : }
      42             : 
      43           2 : Client::Client()
      44           2 :     : _impl(0)
      45             : {
      46           2 : }
      47             : 
      48           4 : Client::~Client()
      49             : {
      50           2 :     delete _impl;
      51           2 :     LBASSERT(isClosed());
      52           2 : }
      53             : 
      54           2 : bool Client::connectServer(co::NodePtr server)
      55             : {
      56           2 :     if (server->isConnected())
      57           0 :         return true;
      58             : 
      59           2 :     if (!server->getConnectionDescriptions().empty())
      60           0 :         return connect(server);
      61             : 
      62           4 :     co::ConnectionDescriptionPtr connDesc(new co::ConnectionDescription);
      63           2 :     connDesc->port = EQ_DEFAULT_PORT;
      64           2 :     const std::string& globalServer = Global::getServer();
      65           2 :     const char* envServer = getenv("EQ_SERVER");
      66           2 :     std::string address = !globalServer.empty()
      67             :                               ? globalServer
      68           4 :                               : envServer ? envServer : "localhost";
      69           2 :     if (!connDesc->fromString(address))
      70             :     {
      71           0 :         LBWARN << "Can't parse server address " << address << std::endl;
      72           0 :         return false;
      73             :     }
      74           2 :     LBDEBUG << "Connecting server " << connDesc->toString() << std::endl;
      75           2 :     server->addConnectionDescription(connDesc);
      76             : 
      77           2 :     if (connect(server))
      78           0 :         return true;
      79             : 
      80           2 :     server->removeConnectionDescription(connDesc);
      81           2 :     return false;
      82             : }
      83             : 
      84           0 : bool Client::disconnectServer(co::NodePtr server)
      85             : {
      86           0 :     if (!server->isConnected())
      87             :     {
      88           0 :         LBWARN << "Trying to disconnect unconnected server" << std::endl;
      89           0 :         return false;
      90             :     }
      91             : 
      92           0 :     if (disconnect(server))
      93           0 :         return true;
      94             : 
      95           0 :     LBWARN << "Server disconnect failed" << std::endl;
      96           0 :     return false;
      97             : }
      98             : 
      99          40 : void Client::processCommand(const uint32_t timeout)
     100             : {
     101          40 :     co::CommandQueue* queue = getMainThreadQueue();
     102          40 :     LBASSERT(queue);
     103          78 :     co::ICommand command = queue->pop(timeout);
     104          40 :     if (!command.isValid()) // wakeup() or timeout delivers invalid command
     105           2 :         return;
     106             : 
     107          38 :     LBCHECK(command());
     108             : }
     109             : 
     110        1414 : bool Client::dispatchCommand(co::ICommand& command)
     111             : {
     112        1414 :     LBVERB << "dispatch " << command << std::endl;
     113             : 
     114        1426 :     if (command.getCommand() >= co::CMD_NODE_CUSTOM &&
     115          12 :         command.getCommand() < CMD_SERVER_CUSTOM)
     116             :     {
     117          20 :         co::NodePtr node = command.getRemoteNode();
     118          10 :         return node->co::Dispatcher::dispatchCommand(command);
     119             :     }
     120             : 
     121        1404 :     return co::LocalNode::dispatchCommand(command);
     122             : }
     123             : }
     124          60 : }

Generated by: LCOV version 1.11