Line data Source code
1 :
2 : /* Copyright (c) 2005-2016, 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 "dataOStream.h"
23 : #include "global.h"
24 : #include "node.h"
25 : #include "socketConnection.h"
26 :
27 : #include <lunchbox/init.h>
28 : #include <lunchbox/os.h>
29 :
30 : namespace co
31 : {
32 : namespace
33 : {
34 21 : static int32_t _checkVersion()
35 : {
36 21 : static std::string version = Version::getString();
37 21 : 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 21 : return 0;
42 : }
43 :
44 21 : static lunchbox::a_int32_t _initialized(_checkVersion());
45 : }
46 :
47 20 : bool _init(const int argc, char** argv)
48 : {
49 20 : if (++_initialized > 1) // not first
50 0 : return true;
51 :
52 20 : if (!lunchbox::init(argc, argv))
53 0 : return false;
54 :
55 : #ifdef _WIN32
56 : WORD wsVersion = MAKEWORD(2, 0);
57 : WSADATA wsData;
58 : if (WSAStartup(wsVersion, &wsData) != 0)
59 : {
60 : LBERROR << "Initialization of Windows Sockets failed"
61 : << lunchbox::sysError << std::endl;
62 : return false;
63 : }
64 : #endif
65 :
66 20 : return true;
67 : }
68 :
69 20 : bool exit()
70 : {
71 20 : if (--_initialized > 0) // not last
72 0 : return true;
73 20 : LBASSERT(_initialized == 0);
74 :
75 : #ifdef _WIN32
76 : if (WSACleanup() != 0)
77 : {
78 : LBERROR << "Cleanup of Windows Sockets failed" << lunchbox::sysError
79 : << std::endl;
80 : return false;
81 : }
82 : #endif
83 :
84 20 : LBDEBUG << DataOStream::printStatistics << std::endl;
85 20 : DataOStream::clearStatistics();
86 20 : return lunchbox::exit();
87 : }
88 63 : }
|