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
36namespace Poco {
37
38
39std::string Environment::get(const std::string& name)
40{
41 return EnvironmentImpl::getImpl(name);
42}
43
44
45std::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
54bool Environment::has(const std::string& name)
55{
56 return EnvironmentImpl::hasImpl(name);
57}
58
59
60void Environment::set(const std::string& name, const std::string& value)
61{
62 EnvironmentImpl::setImpl(name, value);
63}
64
65
66std::string Environment::osName()
67{
68 return EnvironmentImpl::osNameImpl();
69}
70
71
72std::string Environment::osDisplayName()
73{
74 return EnvironmentImpl::osDisplayNameImpl();
75}
76
77
78std::string Environment::osVersion()
79{
80 return EnvironmentImpl::osVersionImpl();
81}
82
83
84std::string Environment::osArchitecture()
85{
86 return EnvironmentImpl::osArchitectureImpl();
87}
88
89
90std::string Environment::nodeName()
91{
92 return EnvironmentImpl::nodeNameImpl();
93}
94
95
96std::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
112void Environment::nodeId(NodeId& id)
113{
114 return EnvironmentImpl::nodeIdImpl(id);
115}
116
117
118unsigned Environment::processorCount()
119{
120 return EnvironmentImpl::processorCountImpl();
121}
122
123
124Poco::UInt32 Environment::libraryVersion()
125{
126 return POCO_VERSION;
127}
128
129Poco::Int32 Environment::os()
130{
131 return POCO_OS;
132}
133
134Poco::Int32 Environment::cpu()
135{
136 return POCO_ARCH;
137}
138
139bool Environment::osFamilyUnix()
140{
141#if defined(POCO_OS_FAMILY_UNIX)
142 return true;
143#else
144 return false;
145#endif
146}
147
148bool Environment::osFamilyWindows()
149{
150#if defined(POCO_OS_FAMILY_WINDOWS)
151 return true;
152#else
153 return false;
154#endif
155}
156
157bool 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