1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "COSOperator.h"
7
#ifdef _IRR_WINDOWS_API_
8
#ifndef _IRR_XBOX_PLATFORM_
14
#ifndef _IRR_SOLARIS_PLATFORM_
15
#include <sys/types.h>
16
#include <sys/sysctl.h>
20
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
21
#include "CIrrDeviceLinux.h"
23
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
24
#include "MacOSX/OSXClipboard.h"
30
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
32
COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceLinux* device)
33
: OperatingSystem(osVersion), IrrDeviceLinux(device)
39
COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVersion)
42
setDebugName("COSOperator");
47
//! returns the current operating system version as string.
48
const core::stringc& COSOperator::getOperatingSystemVersion() const
50
return OperatingSystem;
54
//! copies text to the clipboard
55
void COSOperator::copyToClipboard(const c8* text) const
61
#if defined(_IRR_XBOX_PLATFORM_)
62
#elif defined(_IRR_WINDOWS_API_)
63
if (!OpenClipboard(NULL) || text == 0)
71
clipbuffer = GlobalAlloc(GMEM_DDESHARE, strlen(text)+1);
72
buffer = (char*)GlobalLock(clipbuffer);
76
GlobalUnlock(clipbuffer);
77
SetClipboardData(CF_TEXT, clipbuffer);
81
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
83
OSXCopyToClipboard(text);
85
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
87
IrrDeviceLinux->copyToClipboard(text);
94
//! gets text from the clipboard
95
//! \return Returns 0 if no string is in there.
96
const c8* COSOperator::getTextFromClipboard() const
98
#if defined(_IRR_XBOX_PLATFORM_)
100
#elif defined(_IRR_WINDOWS_API_)
101
if (!OpenClipboard(NULL))
106
HANDLE hData = GetClipboardData( CF_TEXT );
107
buffer = (char*)GlobalLock( hData );
108
GlobalUnlock( hData );
112
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
113
return (OSXCopyFromClipboard());
115
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
116
if ( IrrDeviceLinux )
117
return IrrDeviceLinux->getTextFromClipboard();
127
bool COSOperator::getProcessorSpeedMHz(u32* MHz) const
129
#if defined(_IRR_WINDOWS_API_) && !defined(_WIN32_WCE ) && !defined (_IRR_XBOX_PLATFORM_)
133
Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
134
__TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
137
if(Error != ERROR_SUCCESS)
141
DWORD Size = sizeof(Speed);
142
Error = RegQueryValueEx(Key, __TEXT("~MHz"), NULL, NULL, (LPBYTE)&Speed, &Size);
146
if (Error != ERROR_SUCCESS)
150
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
153
#elif defined(_IRR_OSX_PLATFORM_)
154
struct clockinfo CpuClock;
155
size_t Size = sizeof(clockinfo);
157
if (!sysctlbyname("kern.clockrate", &CpuClock, &Size, NULL, 0))
163
// could probably be read from "/proc/cpuinfo" or "/proc/cpufreq"
169
bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
171
#if defined(_IRR_WINDOWS_API_) && !defined (_IRR_XBOX_PLATFORM_)
172
MEMORYSTATUS MemoryStatus;
173
MemoryStatus.dwLength = sizeof(MEMORYSTATUS);
176
GlobalMemoryStatus(&MemoryStatus);
179
*Total = (u32)(MemoryStatus.dwTotalPhys>>10);
181
*Avail = (u32)(MemoryStatus.dwAvailPhys>>10);
183
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
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);
192
if ((ps==-1)||(pp==-1)||(ap==-1))
196
*Total = (u32)((ps*(long long)pp)>>10);
198
*Avail = (u32)((ps*(long long)ap)>>10);
201
// TODO: implement for non-availablity of symbols/features
205
// TODO: implement for OSX