LCOV - code coverage report
Current view: top level - eq/server - localServer.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 45 57 78.9 %
Date: 2017-12-16 05:07:20 Functions: 10 11 90.9 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2007-2017, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                          Cedric Stalder <cedric.stalder@gmail.com>
       4             :  *                          Daniel Nachbaur <danielnachbaur@gmail.com>
       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 "localServer.h"
      21             : 
      22             : #include "server.h"
      23             : 
      24             : #include "global.h"
      25             : #include "loader.h"
      26             : 
      27             : #include <co/node.h>
      28             : 
      29             : #define CONFIG \
      30             :     "server{ config{ appNode{ pipe {                            \
      31             :     window { viewport [ .25 .25 .5 .5 ] channel { name \"channel\" }}}}    \
      32             :     compound { channel \"channel\" wall { }}}}"
      33             : 
      34             : namespace eq
      35             : {
      36             : namespace server
      37             : {
      38             : namespace
      39             : {
      40             : class ServerThread : public lunchbox::Thread
      41             : {
      42             : public:
      43          20 :     ServerThread() {}
      44          20 :     virtual ~ServerThread() {}
      45           2 :     bool start(eq::server::ServerPtr server)
      46             :     {
      47           2 :         LBASSERT(!_server);
      48           2 :         _server = server;
      49           2 :         return Thread::start();
      50             :     }
      51             : 
      52           4 :     eq::server::ServerPtr getServer() { return _server; }
      53             : protected:
      54           2 :     void run() final
      55             :     {
      56           2 :         _server->run();
      57           2 :         _server->close();
      58           2 :         _server->deleteConfigs();
      59             : 
      60           2 :         LBASSERTINFO(_server->getRefCount() == 1,
      61             :                      "Server thread done, still referenced by "
      62             :                          << _server->getRefCount());
      63           2 :         _server = 0;
      64           2 :         eq::server::Global::clear();
      65           2 :     }
      66             : 
      67             : private:
      68             :     eq::server::ServerPtr _server;
      69             : };
      70             : 
      71          20 : static ServerThread _serverThread;
      72             : }
      73             : 
      74           2 : bool startLocalServer(const std::string& config)
      75             : {
      76           2 :     if (_serverThread.isRunning())
      77             :     {
      78           0 :         LBWARN << "Only one app-local server per process allowed" << std::endl;
      79           0 :         return false;
      80             :     }
      81             : 
      82           4 :     eq::server::Loader loader;
      83           4 :     eq::server::ServerPtr server;
      84             : 
      85           4 :     if (config.length() > 3 &&
      86           2 :         config.compare(config.size() - 4, 4, ".eqc") == 0)
      87             :     {
      88           0 :         server = loader.loadFile(config);
      89             :     }
      90             :     else
      91             :     {
      92             : #ifdef EQUALIZER_USE_HWSD
      93           2 :         server = new eq::server::Server; // configured upon Server::chooseConfig
      94             : #else
      95             :         server = loader.parseServer(CONFIG);
      96             : #endif
      97             :     }
      98             : 
      99           2 :     if (!server)
     100             :     {
     101           0 :         LBERROR << "Failed to load configuration" << std::endl;
     102           0 :         return false;
     103             :     }
     104             : 
     105           2 :     eq::server::Loader::addOutputCompounds(server);
     106           2 :     eq::server::Loader::addDestinationViews(server);
     107           2 :     eq::server::Loader::addDefaultObserver(server);
     108           2 :     eq::server::Loader::convertTo11(server);
     109           2 :     eq::server::Loader::convertTo12(server);
     110             :     // TODO: ref count is 2 since config holds ServerPtr
     111             :     // LBASSERTINFO( server->getRefCount() == 1, server );
     112             : 
     113           2 :     if (!server->listen())
     114             :     {
     115           0 :         LBERROR << "Failed to setup server listener" << std::endl;
     116           0 :         return false;
     117             :     }
     118             : 
     119           2 :     if (!_serverThread.start(server))
     120             :     {
     121           0 :         LBERROR << "Failed to start server thread" << std::endl;
     122           0 :         return false;
     123             :     }
     124             : 
     125           2 :     return true;
     126             : }
     127             : 
     128           2 : co::ConnectionPtr connectLocalServer()
     129             : {
     130           2 :     if (!_serverThread.getServer())
     131           0 :         return nullptr;
     132             : 
     133           4 :     co::ConnectionDescriptionPtr desc = new co::ConnectionDescription;
     134           2 :     desc->type = co::CONNECTIONTYPE_PIPE;
     135           4 :     co::ConnectionPtr connection = co::Connection::create(desc);
     136           2 :     if (!connection->connect())
     137             :     {
     138           0 :         LBERROR << "Failed to set up server connection" << std::endl;
     139           0 :         return nullptr;
     140             :     }
     141             : 
     142           4 :     co::ConnectionPtr sibling = connection->acceptSync();
     143             : 
     144           2 :     _serverThread.getServer()->addConnection(sibling);
     145             : 
     146           2 :     return connection;
     147             : }
     148             : 
     149           2 : void joinLocalServer()
     150             : {
     151           2 :     _serverThread.join();
     152           2 : }
     153             : }
     154          60 : }

Generated by: LCOV version 1.11