1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "COSOperator.h"
\r
7 #ifdef _IRR_WINDOWS_API_
\r
12 #ifndef _IRR_ANDROID_PLATFORM_
\r
13 #include <sys/types.h>
\r
14 #ifdef _IRR_OSX_PLATFORM_
\r
15 #include <sys/sysctl.h>
\r
20 #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
\r
21 #include "CIrrDeviceLinux.h"
\r
23 #if defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
\r
24 #import <Cocoa/Cocoa.h>
\r
27 #include "fast_atof.h"
\r
32 #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
\r
33 // constructor linux
\r
34 COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceLinux* device)
\r
35 : OperatingSystem(osVersion), IrrDeviceLinux(device)
\r
41 COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVersion)
\r
44 setDebugName("COSOperator");
\r
49 //! returns the current operating system version as string.
\r
50 const core::stringc& COSOperator::getOperatingSystemVersion() const
\r
52 return OperatingSystem;
\r
56 //! copies text to the clipboard
\r
57 void COSOperator::copyToClipboard(const c8 *text) const
\r
59 if (strlen(text)==0)
\r
63 #if defined(_IRR_WINDOWS_API_)
\r
64 if (!OpenClipboard(NULL) || text == 0)
\r
69 core::stringw tempbuffer;
\r
70 core::multibyteToWString(tempbuffer, text);
\r
71 const u32 size = (tempbuffer.size() + 1) * sizeof(wchar_t);
\r
76 clipbuffer = GlobalAlloc(GMEM_MOVEABLE, size);
\r
77 buffer = GlobalLock(clipbuffer);
\r
79 memcpy(buffer, tempbuffer.c_str(), size);
\r
81 GlobalUnlock(clipbuffer);
\r
82 SetClipboardData(CF_UNICODETEXT, clipbuffer);
\r
85 #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
\r
86 NSString *str = nil;
\r
87 NSPasteboard *board = nil;
\r
89 if ((text != NULL) && (strlen(text) > 0))
\r
91 str = [NSString stringWithCString:text encoding:NSUTF8StringEncoding];
\r
92 board = [NSPasteboard generalPasteboard];
\r
93 [board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp];
\r
94 [board setString:str forType:NSStringPboardType];
\r
97 #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
\r
98 if ( IrrDeviceLinux )
\r
99 IrrDeviceLinux->copyToClipboard(text);
\r
104 //! copies text to the primary selection
\r
105 void COSOperator::copyToPrimarySelection(const c8 *text) const
\r
107 if (strlen(text)==0)
\r
110 #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
\r
111 if ( IrrDeviceLinux )
\r
112 IrrDeviceLinux->copyToPrimarySelection(text);
\r
117 //! gets text from the clipboard
\r
118 const c8* COSOperator::getTextFromClipboard() const
\r
120 #if defined(_IRR_WINDOWS_API_)
\r
121 if (!OpenClipboard(NULL))
\r
124 wchar_t * buffer = 0;
\r
126 HANDLE hData = GetClipboardData( CF_UNICODETEXT );
\r
127 buffer = (wchar_t*) GlobalLock( hData );
\r
129 core::wStringToMultibyte(ClipboardBuf, buffer);
\r
131 GlobalUnlock( hData );
\r
134 return ClipboardBuf.c_str();
\r
136 #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
\r
137 NSString* str = nil;
\r
138 NSPasteboard* board = nil;
\r
141 board = [NSPasteboard generalPasteboard];
\r
142 str = [board stringForType:NSStringPboardType];
\r
145 result = (char*)[str cStringUsingEncoding:NSUTF8StringEncoding];
\r
149 #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
\r
150 if ( IrrDeviceLinux )
\r
151 return IrrDeviceLinux->getTextFromClipboard();
\r
161 //! gets text from the primary selection
\r
162 const c8* COSOperator::getTextFromPrimarySelection() const
\r
164 #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
\r
165 if ( IrrDeviceLinux )
\r
166 return IrrDeviceLinux->getTextFromPrimarySelection();
\r
176 bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
\r
178 #if defined(_IRR_WINDOWS_API_)
\r
180 MEMORYSTATUSEX MemoryStatusEx;
\r
181 MemoryStatusEx.dwLength = sizeof(MEMORYSTATUSEX);
\r
184 GlobalMemoryStatusEx(&MemoryStatusEx);
\r
187 *Total = (u32)(MemoryStatusEx.ullTotalPhys>>10);
\r
189 *Avail = (u32)(MemoryStatusEx.ullAvailPhys>>10);
\r
192 #elif defined(_IRR_POSIX_API_) && defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES)
\r
193 long ps = sysconf(_SC_PAGESIZE);
\r
194 long pp = sysconf(_SC_PHYS_PAGES);
\r
195 long ap = sysconf(_SC_AVPHYS_PAGES);
\r
197 if (ps == -1 || (Total && pp == -1) || (Avail && ap == -1))
\r
201 *Total = (u32)((pp>>10)*ps);
\r
203 *Avail = (u32)((ap>>10)*ps);
\r
205 #elif defined(_IRR_OSX_PLATFORM_)
\r
207 int64_t physical_memory;
\r
210 // Get the Physical memory size
\r
212 mib[1] = HW_MEMSIZE;
\r
213 length = sizeof(int64_t);
\r
214 sysctl(mib, 2, &physical_memory, &length, NULL, 0);
\r
217 *Total = (u32)(physical_memory>>10);
\r
219 *Avail = (u32)(physical_memory>>10); // we don't know better
\r
222 // TODO: implement for others
\r