1 | // |
2 | // Environment.cpp |
3 | // |
4 | // Library: Foundation |
5 | // Package: Core |
6 | // Module: Environment |
7 | // |
8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Environment.h" |
16 | #include "Poco/Version.h" |
17 | #include <cstdlib> |
18 | #include <cstdio> // sprintf() |
19 | |
20 | |
21 | #if defined(POCO_OS_FAMILY_VMS) |
22 | #include "Environment_VMS.cpp" |
23 | #elif defined(POCO_VXWORKS) |
24 | #include "Environment_VX.cpp" |
25 | #elif defined(POCO_OS_FAMILY_UNIX) |
26 | #include "Environment_UNIX.cpp" |
27 | #elif defined(POCO_OS_FAMILY_WINDOWS) |
28 | #if defined(_WIN32_WCE) |
29 | #include "Environment_WINCE.cpp" |
30 | #else |
31 | #include "Environment_WIN32.cpp" |
32 | #endif |
33 | #endif |
34 | |
35 | |
36 | namespace Poco { |
37 | |
38 | |
39 | std::string Environment::get(const std::string& name) |
40 | { |
41 | return EnvironmentImpl::getImpl(name); |
42 | } |
43 | |
44 | |
45 | std::string Environment::get(const std::string& name, const std::string& defaultValue) |
46 | { |
47 | if (has(name)) |
48 | return get(name); |
49 | else |
50 | return defaultValue; |
51 | } |
52 | |
53 | |
54 | bool Environment::has(const std::string& name) |
55 | { |
56 | return EnvironmentImpl::hasImpl(name); |
57 | } |
58 | |
59 | |
60 | void Environment::set(const std::string& name, const std::string& value) |
61 | { |
62 | EnvironmentImpl::setImpl(name, value); |
63 | } |
64 | |
65 | |
66 | std::string Environment::osName() |
67 | { |
68 | return EnvironmentImpl::osNameImpl(); |
69 | } |
70 | |
71 | |
72 | std::string Environment::osDisplayName() |
73 | { |
74 | return EnvironmentImpl::osDisplayNameImpl(); |
75 | } |
76 | |
77 | |
78 | std::string Environment::osVersion() |
79 | { |
80 | return EnvironmentImpl::osVersionImpl(); |
81 | } |
82 | |
83 | |
84 | std::string Environment::osArchitecture() |
85 | { |
86 | return EnvironmentImpl::osArchitectureImpl(); |
87 | } |
88 | |
89 | |
90 | std::string Environment::nodeName() |
91 | { |
92 | return EnvironmentImpl::nodeNameImpl(); |
93 | } |
94 | |
95 | |
96 | std::string Environment::nodeId() |
97 | { |
98 | NodeId id; |
99 | nodeId(id); |
100 | char result[18]; |
101 | std::sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x" , |
102 | id[0], |
103 | id[1], |
104 | id[2], |
105 | id[3], |
106 | id[4], |
107 | id[5]); |
108 | return std::string(result); |
109 | } |
110 | |
111 | |
112 | void Environment::nodeId(NodeId& id) |
113 | { |
114 | return EnvironmentImpl::nodeIdImpl(id); |
115 | } |
116 | |
117 | |
118 | unsigned Environment::processorCount() |
119 | { |
120 | return EnvironmentImpl::processorCountImpl(); |
121 | } |
122 | |
123 | |
124 | Poco::UInt32 Environment::libraryVersion() |
125 | { |
126 | return POCO_VERSION; |
127 | } |
128 | |
129 | Poco::Int32 Environment::os() |
130 | { |
131 | return POCO_OS; |
132 | } |
133 | |
134 | Poco::Int32 Environment::cpu() |
135 | { |
136 | return POCO_ARCH; |
137 | } |
138 | |
139 | bool Environment::osFamilyUnix() |
140 | { |
141 | #if defined(POCO_OS_FAMILY_UNIX) |
142 | return true; |
143 | #else |
144 | return false; |
145 | #endif |
146 | } |
147 | |
148 | bool Environment::osFamilyWindows() |
149 | { |
150 | #if defined(POCO_OS_FAMILY_WINDOWS) |
151 | return true; |
152 | #else |
153 | return false; |
154 | #endif |
155 | } |
156 | |
157 | bool Environment::osFamilyVms() |
158 | { |
159 | #if defined(POCO_OS_FAMILY_VMS) |
160 | return true; |
161 | #else |
162 | return false; |
163 | #endif |
164 | } |
165 | |
166 | } // namespace Poco |
167 | |