Line data Source code
1 :
2 : /* Copyright (c) 2011, Stefan Eilemann <eile@eyescale.ch>
3 : * 2012, 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 "application.h"
20 :
21 : #include "channel.h"
22 : #include "masterConfig.h"
23 : #include "node.h"
24 : #include "pipe.h"
25 : #include "slaveConfig.h"
26 : #include "view.h"
27 : #include "window.h"
28 :
29 : #include <seq/application.h>
30 : #include <eq/client/config.h>
31 : #include <eq/client/init.h>
32 : #include <eq/client/pipe.h>
33 : #include <eq/client/server.h>
34 : #include <eq/fabric/configParams.h>
35 :
36 : namespace seq
37 : {
38 : namespace detail
39 : {
40 :
41 1 : Application::Application( ApplicationPtr app, co::Object* initData )
42 : : _app( app )
43 : , _config( 0 )
44 : , _initData( initData )
45 1 : , _isMaster( false )
46 1 : {}
47 :
48 3 : Application::~Application()
49 : {
50 1 : LBASSERT( !_config );
51 1 : _app = 0;
52 2 : }
53 :
54 1 : Config* Application::getConfig()
55 : {
56 1 : return _config;
57 : }
58 :
59 0 : const Config* Application::getConfig() const
60 : {
61 0 : return _config;
62 : }
63 :
64 1 : bool Application::init()
65 : {
66 1 : _isMaster = true;
67 1 : eq::ServerPtr server = new eq::Server;
68 1 : if( !_app->connectServer( server ))
69 : {
70 0 : LBERROR << "Can't open Equalizer server" << std::endl;
71 0 : exit();
72 0 : return false;
73 : }
74 :
75 2 : const eq::fabric::ConfigParams cp;
76 1 : _config = static_cast< Config* >( server->chooseConfig( cp ));
77 :
78 1 : if( !_config )
79 : {
80 0 : LBERROR << "No matching configuration on Equalizer server" << std::endl;
81 0 : _app->disconnectServer( server );
82 0 : exit();
83 0 : return false;
84 : }
85 :
86 1 : if( !_config->init( ))
87 0 : return false;
88 2 : return true;
89 : }
90 :
91 1 : bool Application::exit()
92 : {
93 1 : bool retVal = true;
94 1 : if( _config )
95 : {
96 1 : eq::ServerPtr server = _config->getServer();
97 :
98 1 : if( !_config->exit( ))
99 0 : retVal = false;
100 :
101 1 : server->releaseConfig( _config );
102 1 : if( !_app->disconnectServer( server ))
103 0 : retVal = false;
104 : }
105 :
106 1 : LBASSERT( !_config );
107 1 : _isMaster = false;
108 1 : return retVal;
109 : }
110 :
111 1 : bool Application::run( co::Object* frameData )
112 : {
113 1 : return _config->run( frameData );
114 : }
115 :
116 1 : eq::Config* Application::createConfig( eq::ServerPtr parent )
117 : {
118 1 : if( isMaster( ))
119 1 : return new MasterConfig( parent );
120 :
121 0 : LBASSERT( !_config );
122 0 : _config = new SlaveConfig( parent );
123 0 : return _config;
124 : }
125 :
126 1 : void Application::releaseConfig( eq::Config* config )
127 : {
128 1 : LBASSERT( config == _config );
129 1 : _config = 0;
130 1 : delete config;
131 1 : }
132 :
133 8 : eq::View* Application::createView( eq::Layout* parent )
134 : {
135 8 : return new View( parent );
136 : }
137 :
138 1 : eq::Node* Application::createNode( eq::Config* parent )
139 : {
140 1 : return new Node( parent );
141 : }
142 :
143 2 : eq::Pipe* Application::createPipe( eq::Node* parent )
144 : {
145 2 : return new Pipe( parent );
146 : }
147 :
148 2 : eq::Window* Application::createWindow( eq::Pipe* parent )
149 : {
150 2 : return new Window( parent );
151 : }
152 :
153 2 : eq::Channel* Application::createChannel( eq::Window* parent )
154 : {
155 2 : return new Channel( parent );
156 : }
157 :
158 : }
159 3 : }
|