aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/COSOperator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/COSOperator.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/COSOperator.cpp212
1 files changed, 212 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/COSOperator.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/COSOperator.cpp
new file mode 100644
index 0000000..0899d1d
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/COSOperator.cpp
@@ -0,0 +1,212 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#include "COSOperator.h"
6
7#ifdef _IRR_WINDOWS_API_
8#ifndef _IRR_XBOX_PLATFORM_
9#include <windows.h>
10#endif
11#else
12#include <string.h>
13#include <unistd.h>
14#ifndef _IRR_SOLARIS_PLATFORM_
15#include <sys/types.h>
16#include <sys/sysctl.h>
17#endif
18#endif
19
20#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
21#include "CIrrDeviceLinux.h"
22#endif
23#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
24#include "MacOSX/OSXClipboard.h"
25#endif
26
27namespace irr
28{
29
30#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
31// constructor linux
32 COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceLinux* device)
33: OperatingSystem(osVersion), IrrDeviceLinux(device)
34{
35}
36#endif
37
38// constructor
39COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVersion)
40{
41 #ifdef _DEBUG
42 setDebugName("COSOperator");
43 #endif
44}
45
46
47//! returns the current operating system version as string.
48const core::stringc& COSOperator::getOperatingSystemVersion() const
49{
50 return OperatingSystem;
51}
52
53
54//! copies text to the clipboard
55void COSOperator::copyToClipboard(const c8* text) const
56{
57 if (strlen(text)==0)
58 return;
59
60// Windows version
61#if defined(_IRR_XBOX_PLATFORM_)
62#elif defined(_IRR_WINDOWS_API_)
63 if (!OpenClipboard(NULL) || text == 0)
64 return;
65
66 EmptyClipboard();
67
68 HGLOBAL clipbuffer;
69 char * buffer;
70
71 clipbuffer = GlobalAlloc(GMEM_DDESHARE, strlen(text)+1);
72 buffer = (char*)GlobalLock(clipbuffer);
73
74 strcpy(buffer, text);
75
76 GlobalUnlock(clipbuffer);
77 SetClipboardData(CF_TEXT, clipbuffer);
78 CloseClipboard();
79
80// MacOSX version
81#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
82
83 OSXCopyToClipboard(text);
84
85#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
86 if ( IrrDeviceLinux )
87 IrrDeviceLinux->copyToClipboard(text);
88#else
89
90#endif
91}
92
93
94//! gets text from the clipboard
95//! \return Returns 0 if no string is in there.
96const c8* COSOperator::getTextFromClipboard() const
97{
98#if defined(_IRR_XBOX_PLATFORM_)
99 return 0;
100#elif defined(_IRR_WINDOWS_API_)
101 if (!OpenClipboard(NULL))
102 return 0;
103
104 char * buffer = 0;
105
106 HANDLE hData = GetClipboardData( CF_TEXT );
107 buffer = (char*)GlobalLock( hData );
108 GlobalUnlock( hData );
109 CloseClipboard();
110 return buffer;
111
112#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
113 return (OSXCopyFromClipboard());
114
115#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
116 if ( IrrDeviceLinux )
117 return IrrDeviceLinux->getTextFromClipboard();
118 return 0;
119
120#else
121
122 return 0;
123#endif
124}
125
126
127bool COSOperator::getProcessorSpeedMHz(u32* MHz) const
128{
129#if defined(_IRR_WINDOWS_API_) && !defined(_WIN32_WCE ) && !defined (_IRR_XBOX_PLATFORM_)
130 LONG Error;
131
132 HKEY Key;
133 Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
134 __TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
135 0, KEY_READ, &Key);
136
137 if(Error != ERROR_SUCCESS)
138 return false;
139
140 DWORD Speed = 0;
141 DWORD Size = sizeof(Speed);
142 Error = RegQueryValueEx(Key, __TEXT("~MHz"), NULL, NULL, (LPBYTE)&Speed, &Size);
143
144 RegCloseKey(Key);
145
146 if (Error != ERROR_SUCCESS)
147 return false;
148 else if (MHz)
149 *MHz = Speed;
150 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
151 return true;
152
153#elif defined(_IRR_OSX_PLATFORM_)
154 struct clockinfo CpuClock;
155 size_t Size = sizeof(clockinfo);
156
157 if (!sysctlbyname("kern.clockrate", &CpuClock, &Size, NULL, 0))
158 return false;
159 else if (MHz)
160 *MHz = CpuClock.hz;
161 return true;
162#else
163 // could probably be read from "/proc/cpuinfo" or "/proc/cpufreq"
164
165 return false;
166#endif
167}
168
169bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
170{
171#if defined(_IRR_WINDOWS_API_) && !defined (_IRR_XBOX_PLATFORM_)
172 MEMORYSTATUS MemoryStatus;
173 MemoryStatus.dwLength = sizeof(MEMORYSTATUS);
174
175 // cannot fail
176 GlobalMemoryStatus(&MemoryStatus);
177
178 if (Total)
179 *Total = (u32)(MemoryStatus.dwTotalPhys>>10);
180 if (Avail)
181 *Avail = (u32)(MemoryStatus.dwAvailPhys>>10);
182
183 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
184 return true;
185
186#elif defined(_IRR_POSIX_API_) && !defined(__FreeBSD__)
187#if defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)
188 long ps = sysconf(_SC_PAGESIZE);
189 long pp = sysconf(_SC_PHYS_PAGES);
190 long ap = sysconf(_SC_AVPHYS_PAGES);
191
192 if ((ps==-1)||(pp==-1)||(ap==-1))
193 return false;
194
195 if (Total)
196 *Total = (u32)((ps*(long long)pp)>>10);
197 if (Avail)
198 *Avail = (u32)((ps*(long long)ap)>>10);
199 return true;
200#else
201 // TODO: implement for non-availablity of symbols/features
202 return false;
203#endif
204#else
205 // TODO: implement for OSX
206 return false;
207#endif
208}
209
210
211} // end namespace
212