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); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 72 | // g_key_file_has_key |
| 73 | virtual gboolean KeyFileHasKey(GKeyFile *key_file, |
| 74 | const gchar *group_name, |
| 75 | const gchar *key, |
| 76 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 77 | // g_key_file_load_from_file |
| 78 | virtual gboolean KeyFileLoadFromFile(GKeyFile *key_file, |
| 79 | const gchar *file, |
| 80 | GKeyFileFlags flags, |
| 81 | GError **error); |
| 82 | // g_key_file_new |
| 83 | virtual GKeyFile *KeyFileNew(); |
| 84 | // g_key_file_remove_group |
| 85 | virtual void KeyFileRemoveGroup(GKeyFile *key_file, |
| 86 | const gchar *group_name, |
| 87 | GError **error); |
| 88 | // g_key_file_remove_key |
| 89 | virtual void KeyFileRemoveKey(GKeyFile *key_file, |
| 90 | const gchar *group_name, |
| 91 | const gchar *key, |
| 92 | GError **error); |
| 93 | // g_key_file_set_boolean |
| 94 | virtual void KeyFileSetBoolean(GKeyFile *key_file, |
| 95 | const gchar *group_name, |
| 96 | const gchar *key, |
| 97 | gboolean value); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 98 | // g_key_file_set_comment |
| 99 | virtual gboolean KeyFileSetComment(GKeyFile *key_file, |
| 100 | const gchar *group_name, |
| 101 | const gchar *key, |
| 102 | const gchar *comment, |
| 103 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 104 | // g_key_file_set_integer |
| 105 | virtual void KeyFileSetInteger(GKeyFile *key_file, |
| 106 | const gchar *group_name, |
| 107 | const gchar *key, |
| 108 | gint value); |
| 109 | // g_key_file_set_string |
| 110 | virtual void KeyFileSetString(GKeyFile *key_file, |
| 111 | const gchar *group_name, |
| 112 | const gchar *key, |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 113 | const gchar *value); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 114 | // g_key_file_set_string_list |
| 115 | virtual void KeyFileSetStringList(GKeyFile *key_file, |
| 116 | const gchar *group_name, |
| 117 | const gchar *key, |
| 118 | const gchar * const list[], |
| 119 | gsize length); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 120 | // g_key_file_to_data |
| 121 | virtual gchar *KeyFileToData(GKeyFile *key_file, |
| 122 | gsize *length, |
| 123 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 124 | // g_source_remove |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 125 | virtual gboolean SourceRemove(guint tag); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 126 | // g_spawn_async |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 127 | virtual gboolean SpawnAsync(const gchar *working_directory, |
| 128 | gchar **argv, |
| 129 | gchar **envp, |
| 130 | GSpawnFlags flags, |
| 131 | GSpawnChildSetupFunc child_setup, |
| 132 | gpointer user_data, |
| 133 | GPid *child_pid, |
| 134 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 135 | // g_spawn_close_pid |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 136 | virtual void SpawnClosePID(GPid pid); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 137 | // g_strfreev |
| 138 | virtual void Strfreev(gchar **str_array); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 139 | // g_type_init |
| 140 | virtual void TypeInit(); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | } // namespace shill |
| 144 | |
| 145 | #endif // SHILL_GLIB_H_ |