This is a series of patches to add support to Mono for building against the Android NDK [0]. Android runs the Linux kernel, but moves many things around compared to a "normal" desktop Linux distro.
These patches are based against the mono-2-6 branch. This first patch patches eglib so that messages produced by g_print(), g_printerr(), and g_log() are sent to the Android message log: * src/glib.h: Rebase g_return_if_fail(), g_return_val_if_fail() in terms of g_critical() instead of printf, and turn g_printerr() into an actual function instead of a macro. * src/goutput.c: Add Android support, sending g_print(), g_printerr(), and g_log() messages to the Android system log. Permission to commit? - Jon [0] http://developer.android.com/sdk/ndk/index.html
Index: eglib/src/goutput.c =================================================================== --- eglib/src/goutput.c (revision 155735) +++ eglib/src/goutput.c (working copy) @@ -31,16 +31,61 @@ /* The current fatal levels, error is always fatal */ static GLogLevelFlags fatal = G_LOG_LEVEL_ERROR; +#if PLATFORM_ANDROID +#include <android/log.h> + +static android_LogPriority +to_android_priority (GLogLevelFlags log_level) +{ + switch (log_level & G_LOG_LEVEL_MASK) + { + case G_LOG_LEVEL_ERROR: return ANDROID_LOG_FATAL; + case G_LOG_LEVEL_CRITICAL: return ANDROID_LOG_ERROR; + case G_LOG_LEVEL_WARNING: return ANDROID_LOG_WARN; + case G_LOG_LEVEL_MESSAGE: return ANDROID_LOG_INFO; + case G_LOG_LEVEL_INFO: return ANDROID_LOG_DEBUG; + case G_LOG_LEVEL_DEBUG: return ANDROID_LOG_VERBOSE; + } + return ANDROID_LOG_UNKNOWN; +} + +static void +out_vfprintf (FILE *ignore, const gchar *format, va_list args) +{ + __android_log_vprint (ANDROID_LOG_ERROR, "mono", format, args); +} +#else +static void +out_vfprintf (FILE *file, const gchar *format, va_list args) +{ + vfprintf (file, format, args); +} +#endif + void g_print (const gchar *format, ...) { va_list args; va_start (args, format); - vprintf (format, args); + + out_vfprintf (stdout, format, args); + va_end (args); } +void +g_printerr (const gchar *format, ...) +{ + va_list args; + + va_start (args, format); + + out_vfprintf (stderr, format, args); + + va_end (args); +} + GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask) { @@ -68,10 +113,18 @@ char *msg; vasprintf (&msg, format, args); +#if PLATFORM_ANDROID + __android_log_print (to_android_priority (log_level), + "mono", "%s%s%s", + log_domain != NULL ? log_domain : "", + log_domain != NULL ? ": " : "", + msg); +#else printf ("%s%s%s", log_domain != NULL ? log_domain : "", log_domain != NULL ? ": " : "", msg); +#endif free (msg); if (log_level & fatal){ fflush (stdout); Index: eglib/src/glib.h =================================================================== --- eglib/src/glib.h (revision 155735) +++ eglib/src/glib.h (working copy) @@ -151,8 +151,8 @@ /* * Precondition macros */ -#define g_return_if_fail(x) G_STMT_START { if (!(x)) { printf ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return; } } G_STMT_END -#define g_return_val_if_fail(x,e) G_STMT_START { if (!(x)) { printf ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return (e); } } G_STMT_END +#define g_return_if_fail(x) G_STMT_START { if (!(x)) { g_critical ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return; } } G_STMT_END +#define g_return_val_if_fail(x,e) G_STMT_START { if (!(x)) { g_critical ("%s:%d: assertion '%s' failed", __FILE__, __LINE__, #x); return (e); } } G_STMT_END /* * Hashtables @@ -497,6 +497,7 @@ } GLogLevelFlags; void g_print (const gchar *format, ...); +void g_printerr (const gchar *format, ...); GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask); GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain, GLogLevelFlags fatal_mask); void g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args); @@ -508,17 +509,13 @@ #define g_warning(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, __VA_ARGS__) #define g_message(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, __VA_ARGS__) #define g_debug(format, ...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, __VA_ARGS__) - -#define g_printerr(format, ...) fprintf (stderr, format, __VA_ARGS__) -#else +#else /* HAVE_C99_SUPPORT */ #define g_error(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __VA_ARGS__) #define g_critical(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__) #define g_warning(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__) #define g_message(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__) #define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__) - -#define g_printerr(...) fprintf (stderr, __VA_ARGS__) -#endif +#endif /* ndef HAVE_C99_SUPPORT */ #define g_log_set_handler(a,b,c,d) /* * Conversions Index: eglib/ChangeLog =================================================================== --- eglib/ChangeLog (revision 155735) +++ eglib/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2010-04-19 Jonathan Pryor <jpr...@novell.com> + + * src/glib.h: Rebase g_return_if_fail(), g_return_val_if_fail() in + terms of g_critical() instead of printf, and turn g_printerr() into + an actual function instead of a macro. + * src/goutput.c: Add Android support, sending g_print(), g_printerr(), + and g_log() messages to the Android system log. + 2009-12-03 Zoltan Varga <var...@gmail.com> * src/gmisc-unix.c (g_get_user_name): Avoid returning NULL if the env
_______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list