main.c

Go to the documentation of this file.
00001 /*
00002 lkmonitor (Linux Kernel Monitor)
00003 
00004 Application for monitoring and tuning a Linux kernel.
00005 
00006 Copyright (C) 2005-2006  Fernando ApesteguĂ­a
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 */
00022 
00023 /*
00024  * Initial main.c file generated by Glade. Edit as required.
00025  * Glade will not overwrite this file.
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include <gtk/gtk.h>
00033 #include <sys/types.h>
00034 #include <signal.h>
00035 
00036 #include "interface.h"
00037 #include "support.h"
00038 #include "lininfo.h"
00039 #include "update.h"
00040 #include "lkmonitor.h"
00041 
00042 #include <unistd.h>
00043 #include <stdio.h>
00044 #include <glib.h>
00045 
00046 
00047 GtkWidget *window1;
00048 
00049 
00050 
00051 /*Struct definitions*/
00052 
00053 struct cpu_info cpu;
00054 struct mem_info mem;
00055 struct dev_info devs;
00056 struct settings_info settings;
00057 struct stats_info stats;
00058 struct acpi_info acpi;
00059 
00060 pthread_t thread_id;
00061 GThread *gt_collector=NULL;
00062 
00063 gboolean is_icon=FALSE;
00064 gboolean collector_exit=FALSE;
00065 
00071 void
00072 refresh (void* nothing)
00073 {
00074   int page;
00075   GtkNotebook *nb;
00076 
00077  nb = (GtkNotebook *) (lookup_widget (window1, "nb_main"));
00078   //Get current page from the notebook
00079  while(!collector_exit){
00080  if(!is_icon){  
00081          page = (int) gtk_notebook_get_current_page (nb);
00082   switch (page)
00083     {
00084         case 0:
00085                 update_cpu_mhz();
00086                 break;
00087     case 1:
00088       update_mem ();
00089       break;
00090     case 2:
00091          // update_devs();
00092       break;
00093     case 3:
00094         //      update_settings();
00095                 break;
00096         case 4:
00097           update_misc();
00098     }
00099  }
00100         sleep(1);
00101 
00102 }
00103 }
00104 
00110 int
00111 main (int argc, char *argv[])
00112 {
00113         gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
00114                       argc, argv,
00115                       GNOME_PARAM_APP_DATADIR, PACKAGE_DATA_DIR,
00116                       NULL);
00117         
00118 #ifdef ENABLE_NLS
00119   bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
00120   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
00121   textdomain (GETTEXT_PACKAGE);
00122 #endif
00123 
00124 
00125   gdk_threads_init ();
00126         
00127         
00128   gtk_set_locale ();
00129   gtk_init (&argc, &argv);
00130 
00131 
00132   /*
00133    * The following code was added by Glade to create one of each component
00134    * (except popup menus), just so that you see something after building
00135    * the project. Delete any crefresh);omponents that you don't want shown initially.
00136    */
00137   lkmonitor_create_tray_icon();
00138   window1 = create_window1 ();
00139   /*Set some widget properties*/
00140   
00141   lkmonitor_init_widgets(window1);
00142   
00143   gtk_widget_show (window1);
00144   
00145   
00146 
00147   /*First calls for static information*/
00148   update_cpu ();
00149   update_devs();
00150   update_settings();
00151   
00152   if(get_battery_info(&acpi.battery,BATT_INFO)==-1)
00153           get_battery_info(&acpi.battery,BATT_INFO1);
00154   
00155 
00156 gdk_threads_enter ();  //Begin of critial section
00157 
00158 /*Launch thread*/
00159 
00160 gt_collector=g_thread_create((GThreadFunc)refresh,NULL,TRUE,NULL);
00161 if(gt_collector!=NULL)
00162         g_message("Collector thread created");
00163 else
00164         /*Error creating thread*/
00165         g_critical("Could not create thread!");
00166 
00167 
00168 gtk_main ();
00169 
00170 gdk_threads_leave(); //Marks end of critical section
00171 
00172 g_thread_join(gt_collector); /*Wait for collector thread to finish*/
00173 
00174 return 0;
00175 }

Generated on Sat Dec 2 11:27:51 2006 for lkmonitor by  doxygen 1.5.1