/home/fernape/Projects/lkmonitor/src/main.c

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

Generated on Tue Apr 1 22:52:52 2008 for lkmonitor by  doxygen 1.5.1