Merge Windows CPU code from master.
authorCarl Hetherington <cth@carlh.net>
Tue, 23 Jul 2013 16:24:12 +0000 (17:24 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 23 Jul 2013 16:24:12 +0000 (17:24 +0100)
src/lib/cross.cc
src/lib/cross.h
src/lib/film.cc

index 4e3739f57380f78491c547b857908cdf964c4dc7..5ecbedf6eaaf49bcb505a5139236a7e5e41954d9 100644 (file)
@@ -39,6 +39,7 @@ using std::pair;
 using std::list;
 using std::ifstream;
 using std::string;
+using std::wstring;
 using std::make_pair;
 using boost::shared_ptr;
 
@@ -53,12 +54,11 @@ dcpomatic_sleep (int s)
 #endif
 }
 
-/** @return A pair containing CPU model name and the number of processors */
-pair<string, int>
+/** @return A string of CPU information (model name etc.) */
+string
 cpu_info ()
 {
-       pair<string, int> info;
-       info.second = 0;
+       string info;
        
 #ifdef DCPOMATIC_LINUX
        ifstream f ("/proc/cpuinfo");
@@ -68,24 +68,48 @@ cpu_info ()
                if (boost::algorithm::starts_with (l, "model name")) {
                        string::size_type const c = l.find (':');
                        if (c != string::npos) {
-                               info.first = l.substr (c + 2);
+                               info = l.substr (c + 2);
                        }
-               } else if (boost::algorithm::starts_with (l, "processor")) {
-                       ++info.second;
                }
        }
 #endif
 
 #ifdef DCPOMATIC_OSX
-       size_t N = sizeof (info.second);
-       sysctlbyname ("hw.ncpu", &info.second, &N, 0, 0);
        char buffer[64];
-       N = sizeof (buffer);
+       size_t N = sizeof (buffer);
        if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) {
-               info.first = buffer;
+               info = buffer;
        }
 #endif         
 
+#ifdef DCPOMATIC_WINDOWS
+       HKEY key;
+       if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key) != ERROR_SUCCESS) {
+               return info;
+       }
+
+       DWORD type;
+       DWORD data;
+       if (RegQueryValueEx (key, L"ProcessorNameString", 0, &type, 0, &data) != ERROR_SUCCESS) {
+               return info;
+       }
+
+       if (type != REG_SZ) {
+               return info;
+       }
+
+       wstring value (data / sizeof (wchar_t), L'\0');
+       if (RegQueryValueEx (key, L"ProcessorNameString", 0, 0, reinterpret_cast<LPBYTE> (&value[0]), &data) != ERROR_SUCCESS) {
+               RegCloseKey (key);
+               return info;
+       }
+
+       info = string (value.begin(), value.end());
+       
+       RegCloseKey (key);
+
+#endif 
+       
        return info;
 }
 
index a00fee67917c95031a038c7b14fdeec0b8d85f30..58fa821c7276aba3a96fb0a8996b6f224ca3b2e2 100644 (file)
@@ -26,6 +26,6 @@
 class Log;
 
 void dcpomatic_sleep (int);
-extern std::pair<std::string, int> cpu_info ();
+extern std::string cpu_info ();
 extern void run_ffprobe (boost::filesystem::path, boost::filesystem::path, boost::shared_ptr<Log>);
 extern std::list<std::pair<std::string, std::string> > mount_info ();
index b8a26501e5467b9f4052df53ef252daf27339acf..fc06bb0586de95bf4765083463db99d1668abc2b 100644 (file)
@@ -242,8 +242,7 @@ Film::make_dcp ()
 #else
        log()->log ("libdcp built in optimised mode.");
 #endif
-       pair<string, int> const c = cpu_info ();
-       log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
+       log()->log (String::compose ("CPU: %1, %2 processors", cpu_info(), boost::thread::hardware_concurrency ()));
        list<pair<string, string> > const m = mount_info ();
        for (list<pair<string, string> >::const_iterator i = m.begin(); i != m.end(); ++i) {
                log()->log (String::compose ("Mount: %1 %2", i->first, i->second));