Le 16 mai 06 à 08:47, Sašo Kiselkov a écrit :

Alright, I've integrated David's changes,

Nice. The code is better now, thanks David.

but I'm not sure I did it
right for platforms other than Linux and unsupported platforms. Could
somebody please check it?

It works but not that well on Linux ppc. I was expecting it :-)
I attached a patch to add Linux ppc support. I was surprised and it's somewhat a shame, but it seems /proc/cpuinfo isn't standardized, it varies with the architecture you are running the system on. 'cpu MHz' is 'clock' and 'model name' is 'cpu' on my Mac mini.
In this pach, I updated also ETMachineInfo to have the correct spacing between value and unit in the About window. 1.4 GHz and not 1.4GHz

Here are links to screenshots 'before' and 'after'. It seems the code isn't failing correctly in the first case, I think ETMachineInfo should always check the return of the concrete category implementation, in order to have for example 'CPU: Unknown', not 'CPU: ' when the system is installed on an unsupported architecture.
'CPU' in About window should probably renamed 'Processor' and 'CPU MHz' just 'Speed'. This would be more user-friendly.


I hope the issue addressed by the patch doesn't arise with BSD, well just supposing the related system call doesn't return idiosyncratic results like /proc/cpuinfo on Linux.

For 'Machine: ', we could either display 'PowerPC' or I could add code to parse the model name. On my test system, /proc/cpuinfo provides a field 'detected as: 237 (Mac mini)'. I could extract 'Mac mini' portion, but I'm not sure it's worth the pain if there is no equivalent support for branded PC machines. However that would mean, overriding +[ETMachineInfo machineType] in ETMachineInfo_Linux without the possibility to call the default code since we use an category.
Well, perhaps it's time to add some official code in Étoilé to call methods overriden by category. Another option, probably better would be to switch to a simple class cluster.

Things I changed on David's code:

- reformatted it to GNU style. It's not like Etoile has a particular
bias towards it, but I do, and since the rest of EtoileMenuServer is
in it, I'd like to keep things consistent.

I have no problem with EtoileMenuServer sticking to GNU style (at least until we have time to spend on updating indenting style). But any new modules should avoid it.
Well, it's true the coding guidelines aren't yet official, but they will soon.

- changed the makefile definitions to compile all source files (since
all of the EtoileMenuServer project is managed by ProjectManager and
that doesn't allow to conditionally change the source file list
depending on the platform), but instead protected the code by using
ifdef's (i.e. FreeBSD code doesn't get compiled unless you are running
FreeBSD).

Looks like a step backward but a minor one. Hopes ProjectManager will catch up on this one.

- made memory sizes of up to MB rounded to integer values (so it
doesn't spit out (511.65MB, but instead 512MB).

Nice.

As for the FreeBSD < 5 yes or no discussion I'm for no - FreeBSD 4 is
really old.

Neither am I.

Index: ETMachineInfo_Linux.m
===================================================================
--- ETMachineInfo_Linux.m	(revision 825)
+++ ETMachineInfo_Linux.m	(working copy)
@@ -27,11 +27,30 @@
 #import <sys/stat.h>
 
 #import <Foundation/NSArray.h>
+#import <Foundation/NSCharacterSet.h>
 #import <Foundation/NSFileManager.h>
 #import <Foundation/NSString.h>
 
+/* A dictionary mapping cpu reference identifiers to cpu commercial names. */
+static NSDictionary *cpuNames = nil;
+
+
 @implementation ETMachineInfo (Linux)
 
++ (void) initialize
+{
+    if (self == [ETMachineInfo class])
+      {
+        cpuNames = [NSDictionary dictionaryWithObjectsAndKeys:
+          /* PowerPC cpus
+          NOTE: 750GX, 750FX, 970FX, 970MP are taken in account by trimming the suffix. */
+          @"G3", @"740", @"G3", @"745", @"G3", @"750", @"G3", @"755",
+          @"G4", @"7400", @"G4", @"7410", @"G4", @"7450", @"G4", @"7447", 
+            @"G4", @"7457", @"G4", @"7448",
+          @"G5", @"970", nil];
+      }
+}
+
 + (unsigned long long) realMemory
 {
   // The size of /proc/kcore on Linux gives the total memory
@@ -50,7 +69,7 @@
 
   while ((line = [e nextObject]) != nil)
     {
-      if ([line hasPrefix: @"cpu MHz"])
+      if ([line hasPrefix: @"cpu MHz"]) /* For x86 architecture */
         {
            NSArray * comps = [line componentsSeparatedByString: @":"];
 
@@ -59,6 +78,23 @@
                return [[comps objectAtIndex: 1] intValue];
              }
         }
+      else if ([line hasPrefix: @"clock"]) /* For ppc architecture */
+        {
+           NSArray * comps = [line componentsSeparatedByString: @":"];
+
+          /* Example /proc/cpuinfo on a Mac mini:
+             clock           : 1416.666661MHz */
+
+           if ([comps count] > 1)
+             {
+               NSCharacterSet *letterSet = [NSCharacterSet letterCharacterSet];
+               NSString *cpuSpeed = [comps objectAtIndex: 1];
+
+               cpuSpeed = [cpuSpeed stringByTrimmingCharactersInSet: letterSet];
+
+               return [cpuSpeed intValue];
+             }
+        }
     }
 
   return 0;
@@ -74,7 +110,7 @@
 
   while ((line = [e nextObject]) != nil)
     {
-      if ([line hasPrefix: @"model name"])
+      if ([line hasPrefix: @"model name"]) /* For x86 architecture */
         {
           NSArray * comps = [line componentsSeparatedByString: @":"];
 
@@ -83,6 +119,28 @@
               return [[comps objectAtIndex: 1] stringByTrimmingSpaces];
             }
         }
+      else if ([line hasPrefix: @"cpu"]) /* For ppc architecture */
+        {
+          NSArray * comps = [line componentsSeparatedByString: @":"];
+
+          /* Example /proc/cpuinfo on a Mac mini:
+             cpu             : 7447A, altivec supported */
+
+          if ([comps count] > 1)
+            {
+              NSString *cpuIdentifier = [comps objectAtIndex: 1];
+              NSString *cpuName;
+              NSCharacterSet *letterSet = [NSCharacterSet letterCharacterSet];
+
+              cpuIdentifier = [[cpuIdentifier componentsSeparatedByString: @","] objectAtIndex: 0];
+              cpuName = [cpuNames objectForKey: 
+                  [[cpuIdentifier stringByTrimmingCharactersInSet: letterSet]  stringByTrimmingSpaces]];
+              cpuName = [NSString stringWithFormat: 
+                  @"PowerPC %@ (%@)", cpuName, cpuIdentifier];
+
+              return cpuName;
+            }
+        }
     }
 
   return nil;
Index: ETMachineInfo.m
===================================================================
--- ETMachineInfo.m	(revision 825)
+++ ETMachineInfo.m	(working copy)
@@ -80,24 +80,24 @@
     {
       if (prefix >= 0)
         {
-          return [NSString stringWithFormat:@"%d%c%@", my_round (value),
+          return [NSString stringWithFormat:@"%d %c%@", my_round (value),
             UnitPrefixes[prefix], unit];
         }
       else
         {
-          return [NSString stringWithFormat:@"%d%@", my_round (value), unit];
+          return [NSString stringWithFormat:@"%d %@", my_round (value), unit];
         }
     }
   else
     {
       if (prefix >= 0)
         {
-          return [NSString stringWithFormat:@"%#3.2f%c%@", value,
+          return [NSString stringWithFormat:@"%#3.2f %c%@", value,
             UnitPrefixes[prefix], unit];
         }
       else
         {
-          return [NSString stringWithFormat:@"%#3.2f%@", value, unit];
+          return [NSString stringWithFormat:@"%#3.2f %@", value, unit];
         }
     }
 }

Thanks,
Quentin.

--
Quentin Mathé

_______________________________________________
Etoile-dev mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-dev

Reply via email to