LCOV - code coverage report
Current view: top level - eq/server - startLocalServer.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 43 54 79.6 %
Date: 2014-06-18 Functions: 8 9 88.9 %

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

Generated by: LCOV version 1.10