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