Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_GLIB_H_ |
| 6 | #define SHILL_GLIB_H_ |
| 7 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 10 | #include <gio/gio.h> |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 11 | #include <glib.h> |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 12 | |
| 13 | namespace shill { |
| 14 | |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 15 | // A GLib abstraction allowing GLib mocking in tests. |
| 16 | class GLib { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 17 | public: |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 18 | virtual ~GLib(); |
| 19 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 20 | // Converts GLib's |error| to a string message and frees the GError object. |
| 21 | virtual std::string ConvertErrorToMessage(GError *error); |
| 22 | |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 23 | // g_base64_decode |
| 24 | virtual guchar *Base64Decode(const gchar *text, gsize *out_len); |
| 25 | // g_base64_encode |
| 26 | virtual gchar *Base64Encode(const guchar *data, gsize len); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 27 | // g_bus_unwatch_name |
| 28 | virtual void BusUnwatchName(guint watcher_id); |
| 29 | // g_bus_watch_name |
| 30 | virtual guint BusWatchName(GBusType bus_type, |
| 31 | const gchar *name, |
| 32 | GBusNameWatcherFlags flags, |
| 33 | GBusNameAppearedCallback name_appeared_handler, |
| 34 | GBusNameVanishedCallback name_vanished_handler, |
| 35 | gpointer user_data, |
| 36 | GDestroyNotify user_data_free_func); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 37 | // g_child_watch_add |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 38 | virtual guint ChildWatchAdd(GPid pid, |
| 39 | GChildWatchFunc function, |
| 40 | gpointer data); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 41 | // g_free |
| 42 | virtual void Free(gpointer mem); |
| 43 | // g_key_file_free |
| 44 | virtual void KeyFileFree(GKeyFile *key_file); |
| 45 | // g_key_file_get_boolean |
| 46 | virtual gboolean KeyFileGetBoolean(GKeyFile *key_file, |
| 47 | const gchar *group_name, |
| 48 | const gchar *key, |
| 49 | GError **error); |
| 50 | // g_key_file_get_groups |
| 51 | virtual gchar **KeyFileGetGroups(GKeyFile *key_file, |
| 52 | gsize *length); |
| 53 | // g_key_file_get_integer |
| 54 | virtual gint KeyFileGetInteger(GKeyFile *key_file, |
| 55 | const gchar *group_name, |
| 56 | const gchar *key, |
| 57 | GError **error); |
| 58 | // g_key_file_get_string |
| 59 | virtual gchar *KeyFileGetString(GKeyFile *key_file, |
| 60 | const gchar *group_name, |
| 61 | const gchar *key, |
| 62 | GError **error); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 63 | // g_key_file_get_string_list |
| 64 | virtual gchar **KeyFileGetStringList(GKeyFile *key_file, |
| 65 | const gchar *group_name, |
| 66 | const gchar *key, |
| 67 | gsize *length, |
| 68 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 69 | // g_key_file_has_group |
| 70 | virtual gboolean KeyFileHasGroup(GKeyFile *key_file, |
| 71 | const gchar *group_name); |
| 72 | // g_key_file_load_from_file |
| 73 | virtual gboolean KeyFileLoadFromFile(GKeyFile *key_file, |
| 74 | const gchar *file, |
| 75 | GKeyFileFlags flags, |
| 76 | GError **error); |
| 77 | // g_key_file_new |
| 78 | virtual GKeyFile *KeyFileNew(); |
| 79 | // g_key_file_remove_group |
| 80 | virtual void KeyFileRemoveGroup(GKeyFile *key_file, |
| 81 | const gchar *group_name, |
| 82 | GError **error); |
| 83 | // g_key_file_remove_key |
| 84 | virtual void KeyFileRemoveKey(GKeyFile *key_file, |
| 85 | const gchar *group_name, |
| 86 | const gchar *key, |
| 87 | GError **error); |
| 88 | // g_key_file_set_boolean |
| 89 | virtual void KeyFileSetBoolean(GKeyFile *key_file, |
| 90 | const gchar *group_name, |
| 91 | const gchar *key, |
| 92 | gboolean value); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 93 | // g_key_file_set_comment |
| 94 | virtual gboolean KeyFileSetComment(GKeyFile *key_file, |
| 95 | const gchar *group_name, |
| 96 | const gchar *key, |
| 97 | const gchar *comment, |
| 98 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 99 | // g_key_file_set_integer |
| 100 | virtual void KeyFileSetInteger(GKeyFile *key_file, |
| 101 | const gchar *group_name, |
| 102 | const gchar *key, |
| 103 | gint value); |
| 104 | // g_key_file_set_string |
| 105 | virtual void KeyFileSetString(GKeyFile *key_file, |
| 106 | const gchar *group_name, |
| 107 | const gchar *key, |
| 108 | const gchar *string); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 109 | // g_key_file_set_string_list |
| 110 | virtual void KeyFileSetStringList(GKeyFile *key_file, |
| 111 | const gchar *group_name, |
| 112 | const gchar *key, |
| 113 | const gchar * const list[], |
| 114 | gsize length); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 115 | // g_key_file_to_data |
| 116 | virtual gchar *KeyFileToData(GKeyFile *key_file, |
| 117 | gsize *length, |
| 118 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 119 | // g_source_remove |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 120 | virtual gboolean SourceRemove(guint tag); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 121 | // g_spawn_async |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 122 | virtual gboolean SpawnAsync(const gchar *working_directory, |
| 123 | gchar **argv, |
| 124 | gchar **envp, |
| 125 | GSpawnFlags flags, |
| 126 | GSpawnChildSetupFunc child_setup, |
| 127 | gpointer user_data, |
| 128 | GPid *child_pid, |
| 129 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 130 | // g_spawn_close_pid |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 131 | virtual void SpawnClosePID(GPid pid); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 132 | // g_strfreev |
| 133 | virtual void Strfreev(gchar **str_array); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 134 | // g_type_init |
| 135 | virtual void TypeInit(); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | } // namespace shill |
| 139 | |
| 140 | #endif // SHILL_GLIB_H_ |