Line data Source code
1 :
2 : /* Copyright (c) 2005-2013, 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 "init.h"
21 :
22 : #include "global.h"
23 : #include "node.h"
24 : #include "socketConnection.h"
25 :
26 : #include <lunchbox/init.h>
27 : #include <lunchbox/os.h>
28 : #include <lunchbox/pluginRegistry.h>
29 :
30 : namespace co
31 : {
32 : namespace
33 : {
34 20 : static int32_t _checkVersion()
35 : {
36 20 : static std::string version = Version::getString();
37 20 : if( version != Version::getString( ))
38 0 : LBWARN << "Duplicate DSO loading, Collage v" << version
39 0 : << " already loaded while loading v" << Version::getString()
40 0 : << std::endl;
41 20 : return 0;
42 : }
43 :
44 20 : static lunchbox::a_int32_t _initialized( _checkVersion( ));
45 : }
46 :
47 19 : bool _init( const int argc, char** argv )
48 : {
49 19 : if( ++_initialized > 1 ) // not first
50 0 : return true;
51 :
52 19 : if( !lunchbox::init( argc, argv ))
53 0 : return false;
54 :
55 : // init all available plugins
56 19 : lunchbox::PluginRegistry& plugins = Global::getPluginRegistry();
57 19 : plugins.addLunchboxPlugins();
58 19 : plugins.addDirectory( "/opt/local/lib" ); // MacPorts
59 19 : plugins.init();
60 :
61 : #ifdef _WIN32
62 : WORD wsVersion = MAKEWORD( 2, 0 );
63 : WSADATA wsData;
64 : if( WSAStartup( wsVersion, &wsData ) != 0 )
65 : {
66 : LBERROR << "Initialization of Windows Sockets failed"
67 : << lunchbox::sysError << std::endl;
68 : return false;
69 : }
70 : #endif
71 :
72 19 : return true;
73 : }
74 :
75 19 : bool exit()
76 : {
77 19 : if( --_initialized > 0 ) // not last
78 0 : return true;
79 19 : LBASSERT( _initialized == 0 );
80 :
81 : #ifdef _WIN32
82 : if( WSACleanup() != 0 )
83 : {
84 : LBERROR << "Cleanup of Windows Sockets failed"
85 : << lunchbox::sysError << std::endl;
86 : return false;
87 : }
88 : #endif
89 :
90 : // de-initialize registered plugins
91 19 : lunchbox::PluginRegistry& plugins = Global::getPluginRegistry();
92 19 : plugins.exit();
93 :
94 19 : return lunchbox::exit();
95 : }
96 :
97 60 : }
|