diff options
author | Nikias Bassen | 2010-01-26 20:38:05 +0100 |
---|---|---|
committer | Martin Szulecki | 2010-01-28 18:10:54 +0100 |
commit | d7844e59f766ee95a04ecf00d1e26aca974e9229 (patch) | |
tree | 1969a14e9fa0e8234b9fbbeedadb6d558d97fb2a | |
parent | 0a19860397f04cca7af8722fda6ffec11bc5072e (diff) | |
download | sbmanager-d7844e59f766ee95a04ecf00d1e26aca974e9229.tar.gz sbmanager-d7844e59f766ee95a04ecf00d1e26aca974e9229.tar.bz2 |
Split out debugging and helper function to utility.c
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/sbmanager.c | 41 | ||||
-rw-r--r-- | src/utility.c | 74 | ||||
-rw-r--r-- | src/utility.h | 37 |
4 files changed, 116 insertions, 38 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index b350a40..fde2b9c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,8 @@ bin_PROGRAMS = sbmanager sbmanager_SOURCES = device.c \ device.h \ + utility.c \ + utility.h \ sbitem.c \ sbitem.h \ sbmanager.c diff --git a/src/sbmanager.c b/src/sbmanager.c index 23707bf..6cb01e5 100644 --- a/src/sbmanager.c +++ b/src/sbmanager.c @@ -41,6 +41,7 @@ #include <clutter-gtk/clutter-gtk.h> #include <gdk-pixbuf/gdk-pixbuf.h> +#include "utility.h" #include "device.h" #include "sbitem.h" @@ -114,44 +115,7 @@ struct timeval last_page_switch; static void gui_page_indicator_group_add(GList *page, int page_index); static void gui_page_align_icons(guint page_num, gboolean animated); -/* debug */ -gboolean debug_app = FALSE; -static void debug_printf(const char *format, ...); - -static void debug_printf(const char *format, ...) -{ - if (debug_app) { - va_list args; - va_start (args, format); - vprintf(format, args); - va_end (args); - } -} - /* helper */ -static gboolean elapsed_ms(struct timeval *tv, guint ms) -{ - struct timeval now; - guint64 v1,v2; - - if (!tv) return FALSE; - - gettimeofday(&now, NULL); - - v1 = now.tv_sec*1000000 + now.tv_usec; - v2 = tv->tv_sec*1000000 + tv->tv_usec; - - if (v1 < v2) { - return TRUE; - } - - if ((v1 - v2)/1000 > ms) { - return TRUE; - } else { - return FALSE; - } -} - static void sbpage_free(GList *sbitems, gpointer data) { if (sbitems) { @@ -1234,6 +1198,7 @@ static gboolean set_icon_state_cb(gpointer user_data) if (sbc) { device_sbs_set_iconstate(sbc, iconstate, &error); device_sbs_free(sbc); + sbc = NULL; plist_free(iconstate); } @@ -1596,7 +1561,7 @@ int main(int argc, char **argv) iphone_set_debug_level(1); continue; } else if (!strcmp(argv[i], "-D") || !strcmp(argv[i], "--debug-app")) { - debug_app = TRUE; + set_debug(TRUE); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { i++; diff --git a/src/utility.c b/src/utility.c new file mode 100644 index 0000000..795fe9a --- /dev/null +++ b/src/utility.c @@ -0,0 +1,74 @@ +/** + * utility.c + * Debugging and helper function implementation. + * + * Copyright (C) 2009-2010 Nikias Bassen <nikias@gmx.li> + * Copyright (C) 2009-2010 Martin Szulecki <opensuse@sukimashita.com> + * + * Licensed under the GNU General Public License Version 2 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 profile. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <sys/time.h> + +#include "utility.h" + +/* debug */ +static gboolean debug_app = FALSE; + +void set_debug(gboolean debug) +{ + debug_app = debug; +} + +void debug_printf(const char *format, ...) +{ + if (debug_app) { + va_list args; + va_start (args, format); + vprintf(format, args); + va_end (args); + } +} + +/* helper */ +gboolean elapsed_ms(struct timeval *tv, guint ms) +{ + struct timeval now; + guint64 v1,v2; + + if (!tv) return FALSE; + + gettimeofday(&now, NULL); + + v1 = now.tv_sec*1000000 + now.tv_usec; + v2 = tv->tv_sec*1000000 + tv->tv_usec; + + if (v1 < v2) { + return TRUE; + } + + if ((v1 - v2)/1000 > ms) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/src/utility.h b/src/utility.h new file mode 100644 index 0000000..cfb3091 --- /dev/null +++ b/src/utility.h @@ -0,0 +1,37 @@ +/** + * utility.h + * Debugging and helper function definitions. + * + * Copyright (C) 2009-2010 Nikias Bassen <nikias@gmx.li> + * Copyright (C) 2009-2010 Martin Szulecki <opensuse@sukimashita.com> + * + * Licensed under the GNU General Public License Version 2 + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 profile. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifndef UTILITY_H +#define UTILITY_H +#include <glib.h> + +/* debug */ +void set_debug(gboolean debug); +void debug_printf(const char *format, ...); + +/* helper */ +gboolean elapsed_ms(struct timeval *tv, guint ms); + +#endif |