1 | /********** |
2 | This library is free software; you can redistribute it and/or modify it under |
3 | the terms of the GNU Lesser General Public License as published by the |
4 | Free Software Foundation; either version 3 of the License, or (at your |
5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) |
6 | |
7 | This library is distributed in the hope that it will be useful, but WITHOUT |
8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
10 | more details. |
11 | |
12 | You should have received a copy of the GNU Lesser General Public License |
13 | along with this library; if not, write to the Free Software Foundation, Inc., |
14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
15 | **********/ |
16 | // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved. |
17 | // Basic Usage Environment: for a simple, non-scripted, console application |
18 | // Implementation |
19 | |
20 | #include "BasicUsageEnvironment.hh" |
21 | #include <stdio.h> |
22 | |
23 | ////////// BasicUsageEnvironment ////////// |
24 | |
25 | #if defined(__WIN32__) || defined(_WIN32) |
26 | extern "C" int initializeWinsockIfNecessary(); |
27 | #endif |
28 | |
29 | BasicUsageEnvironment::BasicUsageEnvironment(TaskScheduler& taskScheduler) |
30 | : BasicUsageEnvironment0(taskScheduler) { |
31 | #if defined(__WIN32__) || defined(_WIN32) |
32 | if (!initializeWinsockIfNecessary()) { |
33 | setResultErrMsg("Failed to initialize 'winsock': " ); |
34 | reportBackgroundError(); |
35 | internalError(); |
36 | } |
37 | #endif |
38 | } |
39 | |
40 | BasicUsageEnvironment::~BasicUsageEnvironment() { |
41 | } |
42 | |
43 | BasicUsageEnvironment* |
44 | BasicUsageEnvironment::createNew(TaskScheduler& taskScheduler) { |
45 | return new BasicUsageEnvironment(taskScheduler); |
46 | } |
47 | |
48 | int BasicUsageEnvironment::getErrno() const { |
49 | #if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_WCE) |
50 | return WSAGetLastError(); |
51 | #else |
52 | return errno; |
53 | #endif |
54 | } |
55 | |
56 | UsageEnvironment& BasicUsageEnvironment::operator<<(char const* str) { |
57 | if (str == NULL) str = "(NULL)" ; // sanity check |
58 | fprintf(stderr, "%s" , str); |
59 | return *this; |
60 | } |
61 | |
62 | UsageEnvironment& BasicUsageEnvironment::operator<<(int i) { |
63 | fprintf(stderr, "%d" , i); |
64 | return *this; |
65 | } |
66 | |
67 | UsageEnvironment& BasicUsageEnvironment::operator<<(unsigned u) { |
68 | fprintf(stderr, "%u" , u); |
69 | return *this; |
70 | } |
71 | |
72 | UsageEnvironment& BasicUsageEnvironment::operator<<(double d) { |
73 | fprintf(stderr, "%f" , d); |
74 | return *this; |
75 | } |
76 | |
77 | UsageEnvironment& BasicUsageEnvironment::operator<<(void* p) { |
78 | fprintf(stderr, "%p" , p); |
79 | return *this; |
80 | } |
81 | |