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