From c6a855363bfc59fbe197bba73bf64b5d920946a1 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 May 2014 12:33:34 +1200 Subject: Completed debug stuff --- Makefile | 7 +++--- bat_tray/bat_tray.c | 46 +++++++++++++++++++++++++++++---------- bat_tray/bat_tray.h | 4 +--- bool.h | 17 +++++++++++++++ common.c | 2 ++ common.h | 1 + config_file.c | 18 ++++++++++++---- config_file.h | 1 + freq_tray/getcore.c | 9 ++++---- freq_tray/getcore.h | 2 ++ freq_tray/getfreq.c | 30 ++++++++++++++++---------- freq_tray/getgov.c | 28 +++++++++++++----------- tray.c | 52 ++++++++++++++++++++++++++++++++++++++------- trayfreq.c | 12 ++++++++++- trayfreq_set/trayfreq_set.c | 48 ++++++++++++++--------------------------- 15 files changed, 187 insertions(+), 90 deletions(-) diff --git a/Makefile b/Makefile index b66f296..44a3eb7 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,7 @@ MAKE = make CC = gcc INSTALL_PATH=/ -DEBUG= - +EXTRA_CFLAGS= GLIB_CFLAGS = -I/usr/include/glib-2.0 \ -I/usr/lib/glib-2.0/include @@ -49,14 +48,14 @@ all: trayfreq trayfreq-set lang ######################################################################## # Make trayfreq-set program for setting governors trayfreq-set: - $(CC) -o trayfreq-set $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) $(DEBUG) + $(CC) -o trayfreq-set $(trayfreq_set_SOURCES) $(trayfreq_set_CFLAGS) $(trayfreq_set_LDFLAGS) $(EXTRA_CFLAGS) ######################################################################## ######################################################################## # Make main trayfreq system tray program trayfreq: - $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) $(DEBUG) + $(CC) -o trayfreq $(trayfreq_SOURCES) $(trayfreq_CFLAGS) $(trayfreq_LDFLAGS) $(EXTRA_CFLAGS) ######################################################################## ######################################################################## diff --git a/bat_tray/bat_tray.c b/bat_tray/bat_tray.c index ea7b3c7..0037ce4 100644 --- a/bat_tray/bat_tray.c +++ b/bat_tray/bat_tray.c @@ -53,21 +53,27 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean switch(get_battery_state()) { case STATE_DISCHARGING: - sprintf(msg, _("Discharging (%i%%)"), get_bat_percent()); + debug("Discharging\n"); + sprintf(msg, _("Discharging (%d%%)"), get_bat_percent()); break; case STATE_CHARGING: - sprintf(msg, _("Charging (%i%%)"), get_bat_percent()); + debug("Charging\n"); + sprintf(msg, _("Charging (%d%%)"), get_bat_percent()); break; + case STATE_CHARGED: + debug("Charged\n"); sprintf(msg, _("Fully charged") ); break; default: + debug("Unknown\n"); sprintf(msg, _("Unknown status") ); break; } + debug("Setting tooltip text to '%s'\n",msg); gtk_tooltip_set_text(tooltip, msg); return TRUE; @@ -84,6 +90,8 @@ static gboolean update_icon(gpointer user_data) unsigned int adjusted_percent; gchar adjusted_percent_string[4]; + + // TO DO: do this with rounding and divisio etc if(percent > 90) adjusted_percent=100; else if(percent > 70) @@ -97,7 +105,8 @@ static gboolean update_icon(gpointer user_data) else adjusted_percent=0; - sprintf(adjusted_percent_string, "%i", adjusted_percent); + debug("Rounded/adjusted percentage: %d\n",adjusted_percent); + sprintf(adjusted_percent_string, "%d", adjusted_percent); switch ( get_battery_state() ) { @@ -112,6 +121,8 @@ static gboolean update_icon(gpointer user_data) icon_file = g_strconcat("/usr/share/trayfreq/traybat-charged.png", NULL); break; } + + debug("Setting tray icon to '%s'\n",icon_file); gtk_status_icon_set_from_file(tray, icon_file); return TRUE; } @@ -125,11 +136,10 @@ void bat_tray_init() _BAT_NUM = get_bat_num(); // Set up battery info filenames/paths - sprintf(CHARGE_VALUE_PATH, "/sys/class/power_supply/BAT%i/capacity", _BAT_NUM); - sprintf(CHARGE_STATE_PATH, "/sys/class/power_supply/BAT%i/status", _BAT_NUM); - // NOT USED : sprintf(CURRENT_PATH, "/sys/class/power_supply/BAT%i/charge_now", _BAT_NUM); - + sprintf(CHARGE_VALUE_PATH, "/sys/class/power_supply/BAT%d/capacity", _BAT_NUM); + sprintf(CHARGE_STATE_PATH, "/sys/class/power_supply/BAT%d/status", _BAT_NUM); + debug("Spawning new status icon\n"); tray = gtk_status_icon_new(); gchar* icon_file = g_strconcat("/usr/share/trayfreq/traybat-charged.png", NULL); gtk_status_icon_set_from_file(tray, icon_file); @@ -141,11 +151,13 @@ void bat_tray_init() void bat_tray_show() { + debug("Showing tray\n"); gtk_status_icon_set_visible(tray, TRUE); } void bat_tray_hide() { + debug("Hiding tray\n"); gtk_status_icon_set_visible(tray, FALSE); } @@ -156,14 +168,23 @@ void bat_tray_hide() int get_battery_state() { if (file_has_line(CHARGE_STATE_PATH, "Discharging")) + { + debug("Battery discharging\n"); return STATE_DISCHARGING; + } if (file_has_line(CHARGE_STATE_PATH, "Full")) + { + debug("Battery full\n"); return STATE_CHARGED; + } if (file_has_line(CHARGE_STATE_PATH, "Charging")) - return STATE_CHARGING; - + { + debug("Battery charging\n"); + return STATE_CHARGING; + } + debug("Fallthrough: unknown status\n"); return STATE_UNKNOWN; } @@ -178,16 +199,19 @@ int get_bat_num() unsigned int i; for(i = 0; i < 3; i++) { - sprintf(file, "/sys/class/power_supply/BAT%i/present", i); - + sprintf(file, "/sys/class/power_supply/BAT%d/present", i); + debug("Attempting to open '%s'\n",file); if( (fd = fopen(file, "r")) ) { + debug("Found battery %d\n",i); if (fgetc(fd) == '1') { + debug("Battery %d is present\n",i); fclose(fd); return i; } } } + debug("Fallthrough: couldn't find battery\n"); return -1; } diff --git a/bat_tray/bat_tray.h b/bat_tray/bat_tray.h index 8992b32..1d4c993 100644 --- a/bat_tray/bat_tray.h +++ b/bat_tray/bat_tray.h @@ -20,9 +20,7 @@ #define BAT_TRAY_H #include - - -// already defined in bat_tray.c : #define gb_percent get_int_value_from_file(CHARGE_VALUE_PATH); +#include "../debug.h" #define STATE_CHARGING 0 #define STATE_DISCHARGING 1 diff --git a/bool.h b/bool.h index 4df8b53..fc6031e 100644 --- a/bool.h +++ b/bool.h @@ -1,3 +1,20 @@ +/************************************************************************ + * This file is part of trayfreq-archlinux. * + * * + * trayfreq-archlinux is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * trayfreq-archlinux is distributed in the hope that it will be useful,* + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with trayfreq-archlinux. If not, see * + * . * + ************************************************************************/ #ifndef BOOL_H #define BOOL_H diff --git a/common.c b/common.c index d4d2869..c0e44ef 100644 --- a/common.c +++ b/common.c @@ -71,8 +71,10 @@ int get_int(const char* string) char* first_num; first_num = strpbrk(string, "0123456789"); + debug("first_num: '%s'\n",first_num); if(first_num) return atoi(first_num); + debug("first_num was 0, returning 1\n"); return 1; } diff --git a/common.h b/common.h index 6bb7a40..9eb7716 100644 --- a/common.h +++ b/common.h @@ -20,6 +20,7 @@ #define COMMON_H #include "bool.h" +#include "debug.h" #include #include #include diff --git a/config_file.c b/config_file.c index 5bfbe65..602eb92 100644 --- a/config_file.c +++ b/config_file.c @@ -21,20 +21,30 @@ gboolean config_open(struct config_file* config_file) { if(config_file->key_file) + { + debug("Freeing config_file->keyfile\n"); g_key_file_free(config_file->key_file); + } + debug("Creating new config_file->key_file\n"); config_file->key_file = g_key_file_new(); - gboolean success = g_key_file_load_from_file(config_file->key_file, config_file->file_name, G_KEY_FILE_NONE, NULL); - return success; + return g_key_file_load_from_file( config_file->key_file, + config_file->file_name, + G_KEY_FILE_NONE, + NULL); } void config_close(struct config_file* config_file) { + debug("Freeing key_file with %s value\n",config_file->key_file == NULL? "NULL":"non-NULL"); g_key_file_free(config_file->key_file); } gchar* config_get_key(struct config_file* config_file, const gchar* group_name, const gchar* key_name) { - return g_key_file_get_value(config_file->key_file, group_name, key_name, NULL); -} \ No newline at end of file + return g_key_file_get_value(config_file->key_file, + group_name, + key_name, + NULL); +} diff --git a/config_file.h b/config_file.h index d8e150b..59c7736 100644 --- a/config_file.h +++ b/config_file.h @@ -19,6 +19,7 @@ #ifndef CONFIG_FILE_H #define CONFIG_FILE_H +#include "debug.h" #include struct config_file diff --git a/freq_tray/getcore.c b/freq_tray/getcore.c index a2ee3d3..44b3940 100644 --- a/freq_tray/getcore.c +++ b/freq_tray/getcore.c @@ -22,17 +22,17 @@ #include #include -int NUMBER_OF_CORES; +unsigned int NUMBER_OF_CORES; -static gboolean core_exists(int core) +static gboolean core_exists(unsigned int core) { FILE* fd; char path[80]; char corestr[4]; - sprintf(corestr, "%i", core); + sprintf(corestr, "%d", core); sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); - + debug("Checking if core %d exists by opening '%s'",core,path); return (gboolean)(fd = fopen(path, "r")); } @@ -40,6 +40,7 @@ void gc_init() { NUMBER_OF_CORES = 0; while(core_exists(++NUMBER_OF_CORES)); + debug("Found %d cores\n",NUMBER_OF_CORES); } diff --git a/freq_tray/getcore.h b/freq_tray/getcore.h index fc1fc8d..43dcd12 100644 --- a/freq_tray/getcore.h +++ b/freq_tray/getcore.h @@ -19,6 +19,8 @@ #ifndef GETCORE_H #define GETCORE_H +#include "../debug.h" + void gc_init(); int gc_number(); diff --git a/freq_tray/getfreq.c b/freq_tray/getfreq.c index 02970b4..4b00775 100644 --- a/freq_tray/getfreq.c +++ b/freq_tray/getfreq.c @@ -31,17 +31,21 @@ int NUMBER_OF_AVAILABLE_FREQUENCIES; void gf_init() { + // TO DO : get rid of magic constants gchar freq_string[500]; int i = 0; int j = 0; for(i = 0; i < gc_number(); ++i) { - memset(freq_string, 0, 500); + memset(freq_string, '\0', 500); // Get available governor freqs. If no governor, try next cpu if (gf_available(i, freq_string, 500) == -1) + { + debug("Couldn't find gov on core %d\n",i); continue; + } /* go through every frequency in freq_string */ j = 0; @@ -49,7 +53,7 @@ void gf_init() gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); while(end_of_curr) { - memset(AVAILABLE_FREQUENCIES[i][j], 0, 13); + memset(AVAILABLE_FREQUENCIES[i][j], '\0', 13); memmove(AVAILABLE_FREQUENCIES[i][j], curr, end_of_curr - curr); curr = end_of_curr+1; @@ -58,6 +62,7 @@ void gf_init() } } NUMBER_OF_AVAILABLE_FREQUENCIES = j; + debug("Found %d frequencies\n",j); } int gf_current(int core) @@ -65,20 +70,21 @@ int gf_current(int core) FILE* fd; char buff[13]; char path[80]; - char corestr[4]; int freq; - sprintf(corestr, "%i", core); - - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", core); if(!(fd = fopen(path, "r"))) - return -1; + { + debug("Couldn't open '%s'\n",path); + return -1; + } fgets(buff, 13, fd); freq = atoi(buff); fclose(fd); + debug("Found freq %d on core %d\n",freq,core); return freq; } @@ -86,14 +92,14 @@ int gf_available(int core, char* out, int size) { FILE* fd; char path[80]; - char corestr[4]; - - sprintf(corestr, "%i", core); - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_available_frequencies", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_frequencies", core); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); @@ -111,6 +117,8 @@ void gf_get_frequency_label(int freq, char* out) sprintf(out, "%.2f GHz", freq/pow(10, i-1)); else sprintf(out, "%.2d MHz", freq/1000); + + debug("Prepared freq label '%s' for freq %d\n",out,freq); } char* gf_freqa(int core, int index) diff --git a/freq_tray/getgov.c b/freq_tray/getgov.c index 8fe44a5..181ad41 100644 --- a/freq_tray/getgov.c +++ b/freq_tray/getgov.c @@ -39,18 +39,18 @@ void gg_init() memset(gov_string, '\0', 500); gg_available(i, gov_string, 500); - /* go through every governor in gov_string */ + // go through every governor in gov_string j = 0; gchar* curr = &gov_string[0]; gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); while(end_of_curr) { - memset(AVAILABLE_GOVERNORS[i][j], '\0', 13); - memmove(AVAILABLE_GOVERNORS[i][j], curr, end_of_curr - curr); + memset(AVAILABLE_GOVERNORS[i][j], '\0', 13); + memmove(AVAILABLE_GOVERNORS[i][j], curr, end_of_curr - curr); - curr = end_of_curr+1; - end_of_curr = g_strstr_len(curr, strlen(curr), " "); - ++j; + curr = end_of_curr+1; + end_of_curr = g_strstr_len(curr, strlen(curr), " "); + ++j; } } NUMBER_OF_AVAILABLE_GOVERNORS = j; @@ -67,14 +67,18 @@ int gg_current(int core, char* out, int size) sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_governor", corestr); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); - - /* remove newline at the end */ + // Chomp gchar* newline = g_strrstr(out, "\n"); *newline = '\0'; + debug("Current gov for core %d is '%s'\n",core,out); + fclose(fd); return 0; } @@ -83,14 +87,14 @@ int gg_available(int core, char* out, int size) { FILE* fd; char path[80]; - char corestr[4]; - sprintf(corestr, "%i", core); - - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_available_governors", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", core); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); diff --git a/tray.c b/tray.c index 378c386..d1c0b75 100644 --- a/tray.c +++ b/tray.c @@ -29,6 +29,7 @@ GtkWidget* checked_menu_item; static void freq_menu_item_toggled(GtkCheckMenuItem* item, gpointer data) { + debug("[checking in]\n"); if(gtk_check_menu_item_get_active(item)) { checked_menu_item = GTK_WIDGET(item); @@ -41,6 +42,7 @@ static void freq_menu_item_toggled(GtkCheckMenuItem* item, gpointer data) static void gov_menu_item_toggled(GtkCheckMenuItem* item, gpointer data) { + debug("[checking in]\n"); if(gtk_check_menu_item_get_active(item)) { checked_menu_item = GTK_WIDGET(item); @@ -64,11 +66,13 @@ static gboolean governor_exists(gchar* governor) static void remove_menu_item(GtkWidget* menu_item, gpointer data) { + debug("Destroying menu_item\n"); gtk_widget_destroy(menu_item); } static void tray_clear_menu() { + debug("Clearing the menu\n"); GtkContainer* cont = GTK_CONTAINER(menu); gtk_container_foreach(cont, remove_menu_item, NULL); menu_items = NULL; @@ -76,6 +80,7 @@ static void tray_clear_menu() static void tray_init_menu() { + debug("Spawning new menu"); menu = gtk_menu_new(); } @@ -93,43 +98,59 @@ static void tray_generate_menu() gint current_frequency = gf_current(0); - /* append the frequencies */ + // Add available frequencies for(i = 0; i < gf_number(); ++i) { memset(label, '\0', 20); gf_get_frequency_label(gf_freqi(0, i), label); + debug("Got freq label '%s', i=%d\n",label,i); GtkWidget* item = gtk_radio_menu_item_new_with_label(menu_items, label); menu_items = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM (item)); if(g_strcmp0(current_governor, "userspace") == 0 && gf_freqi(0, i) == current_frequency) + { + debug("This freq is current freq, ticking radio button\n"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); + } + debug("Setting connection/callback\n"); g_signal_connect(G_OBJECT(item), "toggled", GTK_SIGNAL_FUNC(freq_menu_item_toggled), GINT_TO_POINTER(gf_freqi(0, i))); + + debug("Adding item to menu\n"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); } - /* append the seperator */ + // Add a seperator + debug("Adding separator\n"); GtkWidget* seperator = gtk_separator_menu_item_new(); gtk_menu_append(menu, seperator); - /* append the governors*/ + // Add available governors for(i = 0; i < gg_number(); i++) { if(g_strcmp0(gg_gov(0, i), "userspace") == 0) - continue; + { + debug("Gov is userspace, not adding\n"); + continue; + } GtkWidget* item = gtk_radio_menu_item_new_with_label(menu_items, gg_gov(0, i)); menu_items = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM (item)); if(g_strcmp0(gg_gov(0, i), current_governor) == 0) { + debug("Governor is current one, ticking radio button\n"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); } - + + debug("Adding callback"); g_signal_connect(G_OBJECT(item), "toggled", GTK_SIGNAL_FUNC(gov_menu_item_toggled), gg_gov(0, i)); + + debug("Adding item to menu\n"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); } + debug("Showing menu\n"); gtk_widget_show_all(menu); } @@ -147,6 +168,7 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean switch ( get_battery_state() ) { case STATE_DISCHARGING: + debug("Discharging\n"); if(_DEFAULT_BAT_GOV) { for(i = 0; i < gc_number(); ++i) @@ -156,6 +178,7 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean case STATE_CHARGING: case STATE_FULL: + debug("Charging/Full\n"); if(_DEFAULT_AC_GOV) { for(i = 0; i < gc_number(); ++i) @@ -170,11 +193,13 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean for(i = 0; i < gc_number(); ++i) { + debug("Adding CPU%i's frequency\n",i); memset(label, '\0', sizeof(label)); gf_get_frequency_label(gf_current(i), label); sprintf(msg+strlen(msg), _("CPU%i: %s%s"), i, label, i == gc_number()-1 ? "" : "\n"); } + debug("Setting tooltip text\n"); tray_set_tooltip(msg); gtk_tooltip_set_text(tooltip, tooltip_text); @@ -183,12 +208,14 @@ static gboolean update_tooltip(GtkStatusIcon* status_icon,gint x,gint y,gboolean static void popup_menu(GtkStatusIcon* statuc_icon,guint button,guint activate_time,gpointer data) { + debug("Spawning popup menu\n"); tray_generate_menu(); gtk_menu_popup(GTK_MENU(menu),NULL,NULL,gtk_status_icon_position_menu,tray,button,activate_time); } static gboolean update_icon(gpointer user_data) { + debug("Updating icon\n"); tray_update_icon_percent(); return TRUE; } @@ -210,23 +237,28 @@ void tray_init() if(_DEFAULT_FREQ) { for(i = 0; i < gc_number(); ++i) - { si_freq(atoi(_DEFAULT_FREQ), i); - } } tray = gtk_status_icon_new(); gchar* icon_file = g_strconcat("/usr/share/trayfreq/cpufreq-0.png", NULL); + + debug("Setting icon to '%s'\n",icon_file); gtk_status_icon_set_from_file(tray, icon_file); - gtk_status_icon_set_has_tooltip (tray, TRUE); + gtk_status_icon_set_has_tooltip(tray, TRUE); + + debug("Setting up callbacks\n"); g_signal_connect(G_OBJECT(tray), "query-tooltip", GTK_SIGNAL_FUNC(update_tooltip), NULL); g_signal_connect(G_OBJECT(tray), "popup-menu", GTK_SIGNAL_FUNC(popup_menu), NULL); + + debug("Adding timeout\n"); g_timeout_add(1000, update_icon, NULL); tray_init_menu(); } void tray_set_tooltip(const gchar* msg) { + debug("Setting up toolip var with text '%s'\n",msg); memset(tooltip_text, '\0', TOOLTIP_TEXT_SIZE); memmove(tooltip_text, msg, strlen(msg)); } @@ -255,11 +287,13 @@ void tray_update_icon_percent() } } + debug("Rounded/adjusted bat percentage: %d\n",adjusted_percent); /* convert the int to a string */ gchar adjusted_percent_string[] = {'\0', '\0', '\0', '\0'}; sprintf(adjusted_percent_string, "%i", adjusted_percent); gchar* file = g_strconcat("/usr/share/trayfreq/cpufreq-", adjusted_percent_string, ".png", NULL); + debug("Setting tray icon to '%s'\n",file); gtk_status_icon_set_from_file(tray, file); g_free(file); @@ -267,11 +301,13 @@ void tray_update_icon_percent() void tray_show() { + debug("Showing tray\n"); gtk_status_icon_set_visible(tray, TRUE); } void tray_hide() { + debug("Hiding tray"); gtk_status_icon_set_visible(tray, FALSE); } diff --git a/trayfreq.c b/trayfreq.c index e7c8933..e3b925e 100644 --- a/trayfreq.c +++ b/trayfreq.c @@ -24,6 +24,7 @@ #include "freq_tray/getgov.h" #include "config_file.h" #include "defaults.h" +#include "debug.h" #include #include @@ -43,14 +44,17 @@ void config_init() config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.config", NULL); + // Check if ~/.trayfreq.config exists if( (fd = fopen(config.file_name, "r")) ) { // If file exists, close it, set param to TRUE + debug("Found '%s'\n",config.file_name); fclose(fd); home_config_exists = TRUE; } else { // If file didn't exist, it's not open (don't close it), free filename var, set param to FALSE + debug("Didn't find '%s'\n",config.file_name); g_free(config.file_name); home_config_exists = FALSE; } @@ -62,6 +66,7 @@ void config_init() if(!success) { + debug("Couldn't open '%s' for reading\n",config.file_name); g_warning(_("Failed to open config files!\n")); return; } @@ -100,10 +105,12 @@ int main(int argc, char** argv) setlocale(LC_ALL, ""); bindtextdomain("trayfreq","/usr/share/locale"); textdomain("trayfreq"); + debug("Set gettext up\n"); if(!gtk_init_check(&argc, &argv)) { - g_error(_("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); + debug("Couldn't start gtk\n"); + g_error( _("GTK Error: gtk_init_check returned FALSE.\nBailing.") ); return 1; } config_init(); @@ -116,10 +123,13 @@ int main(int argc, char** argv) // Show battery tray only if we're supposed to if(SHOW_BATTERY) { + debug("Showing battery info this time around\n"); bat_tray_init(); bat_tray_show(); } + debug("Passing control to Gtk\n"); gtk_main(); + debug("Exiting main()\n"); return 0; } diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c index cb5b2c3..0d65138 100644 --- a/trayfreq_set/trayfreq_set.c +++ b/trayfreq_set/trayfreq_set.c @@ -27,6 +27,7 @@ #include "../freq_tray/getfreq.h" #include "../freq_tray/getcore.h" +#include "../debug.h" #define FILE_PATH_STRING_SIZE 100 @@ -54,9 +55,7 @@ char write_str_to_file(const char *file, const char *data, const char *core) // Try to open file and write data to it if ( (fd = fopen(file_path, "w")) != NULL ) { -#ifdef DEBUG - printf("Writing '%s' to '%s'\n",data,file_path); -#endif + debug("Writing '%s' to '%s'\n",data,file_path); fprintf(fd, data); fclose(fd); return 1; @@ -85,10 +84,8 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) { if ( strcmp(argv[arg], "-c") == 0 ) { -#ifdef DEBUG - printf("Found -c with arg '%s'\n",argv[arg+1]); -#endif // Found -c with an arg + debug("Found -c with arg '%s'\n",argv[arg+1]); argsum->present |= ARG_CORE; argsum->core = (char*)(argv[arg+1]); continue; @@ -96,11 +93,8 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) if ( strcmp(argv[arg], "-f") == 0 ) { -#ifdef DEBUG - printf("Found -f with arg '%s'\n",argv[arg+1]); -#endif - // Found -f with an arg + debug("Found -f with arg '%s'\n",argv[arg+1]); argsum->present |= ARG_FREQ; argsum->frequency = (char*)(argv[arg+1]); continue; @@ -108,10 +102,8 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) if ( strcmp(argv[arg], "-g") == 0 ) { -#ifdef DEBUG - printf("Found -g with arg '%s'\n",argv[arg+1]); -#endif // Found -g with an arg + debug("Found -g with arg '%s'\n",argv[arg+1]); argsum->present |= ARG_GOV; argsum->governor = (char*)(argv[arg+1]); //continue; @@ -131,9 +123,7 @@ int main(int argc, char *argv[]) // TO DO: Needs to be #defined textdomain("trayfreq"); -#ifdef DEBUG - printf("Set gettext up\n"); -#endif + debug("Set gettext up\n"); gc_init(); gf_init(); @@ -146,34 +136,28 @@ int main(int argc, char *argv[]) { get_argument_summary(argc, argv, &args); -#ifdef DEBUG - printf("Correct number of command line arguments\n"); - printf("-c: %s -g: %s -f: %s\n", (args.present | ARG_CORE )? "Yes":"No", - (args.present | ARG_GOV )? "Yes":"No", - (args.present | ARG_FREQ )? "Yes":"No" ); - printf("Core: %s\nGov : %s\nFreq: %s\n",args.core,args.governor,args.frequency); -#endif + debug("Correct number of command line arguments\n"); + debug("-c: %s -g: %s -f: %s\n", (args.present | ARG_CORE )? "Yes":"No", + (args.present | ARG_GOV )? "Yes":"No", + (args.present | ARG_FREQ )? "Yes":"No" ); + debug("Core: %s\n",args.core); + debug("Gov : %s\n",args.governor); + debug("Freq: %s\n",args.frequency); if ( args.present == ( ARG_CORE | ARG_GOV ) ) { -#ifdef DEBUG - printf("Changing governor\n"); -#endif + debug("Changing governor\n"); return set_gov(args.governor , args.core); } if ( args.present == ( ARG_CORE | ARG_FREQ ) ) { -#ifdef DEBUG - printf("Changing frequency\n"); -#endif + debug("Changing frequency\n"); return set_gov("userspace", args.core) | set_speed(args.frequency, args.core); } } -#ifdef DEBUG - printf("Fell through, showing command usage\n"); -#endif // Fall through to here if no valid argument combination + debug("Fell through, showing command usage\n"); fprintf(stderr, _("%s {-f frequency|-g governor} -c core\n"), argv[0] ); return 1; } -- cgit v1.1