- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
/* ... */
/**************************************************************************************
  cpu_information () parse /proc/cpuinfo to get information about CPU 
 **************************************************************************************/
int cpu_information (data* user_data, int pos)
{
  FILE *cpufp/* /proc/cpuinfo */ /*, *sysfs_max_cpu_freq_fp  /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq */;
   
  char* ch = (char*)malloc (MAXLEN);
  char* line = (char*)malloc (MAXLEN);
  char* buf = (char*)malloc (MAXLEN);
  
  GtkTreeIter iter[2];
  // int y = 0;
  if ((cpufp = fopen(CPU_INFORMATION_FILE, "r")) == NULL)
    printf ("%s\n", "Error opening /proc/cpuinfo");
  while (fgets (ch, MAXLEN, cpufp) != NULL) 
  {
    if (!strncmp (ch, "processor", 9)) 
    {
      sscanf (ch, "%*s %*s %s", line);
      strcpy (buf, "CPU");
      gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[0],NULL, pos, 0, buf, 1, line, -1);
    } else if (!strncmp(ch, "vendor_id", 9))
    {
      sscanf(ch,"%*s %*s %s", line);
      strcpy (buf, "Processor type:");
      gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1); 
    } else if (!strncmp(ch, "model name", 10))
    {
      strcpy(buf, "Model name");
      ch[strlen(ch)-1] = '\0'; //delete '\n' symbol from the end of string
      gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, &ch[13], -1);
    } else if (!strncmp(ch, "cpu MHz", 7))
    {
      int curr_cpu_freq;
      sscanf(ch, "%*s %*s %*s %d\n", &curr_cpu_freq);
      sprintf(line, "%d", curr_cpu_freq);
      strcpy (buf, "Current Processor Speed in MHz");
      gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line,-1);
      /*
	 Begin parsing /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq 
	 
      sprintf (sysfs_max_cpu_freq_path, SYSFS_CPU_MAX_FREQ_FORMAT_STRING, y);
      if ((sysfs_max_cpu_freq_fp = fopen (sysfs_max_cpu_freq_path, "r")) == NULL) {
    	  printf("%s %s\n", "Error opening",  sysfs_max_cpu_freq_path);
      }
      while (fgets (line, MAXLEN, sysfs_max_cpu_freq_fp) != NULL)
      {
	sscanf (line, "%d", &max_cpu_freq);
	sprintf (line, "%d", max_cpu_freq/1000);
	strcpy (buf, "Max Processor Speed in MHz");
	gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[2],&iter[1], pos, 0, buf, 1, line,-1);
      }
      y++;
      
	 End parsing 
       
      fclose (sysfs_max_cpu_freq_fp);*/
    }  else if (!strncmp(ch, "cache size", 10))
    {
      sscanf(ch, "%*s %*s %*s %s", line);
      strcpy (buf, "Processor cache size");
      strcat (line, " KB");
      gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
    } else if (!strncmp(ch, "bogomips", 8)) 
    {
      sscanf(ch, "%*s %*s %s", line);
      strcpy (buf, "Processor speed in Bogomips");
      gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
      cpu_temperature (user_data,&iter[0], pos); //get CPU temperature.
    }
    pos++;
  }
  free (buf);
  free (line);
  free (ch);
  //free (sysfs_max_cpu_freq_path);
  fclose (cpufp);
  return 0;
}
/* ... */