Darin Petkov | 36a3ace | 2012-03-06 17:22:14 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 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 | |
Christopher Wiley | 0f3eab3 | 2013-03-21 11:55:41 -0700 | [diff] [blame] | 13 | #include <base/basictypes.h> |
| 14 | |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 15 | namespace shill { |
| 16 | |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 17 | // A GLib abstraction allowing GLib mocking in tests. |
| 18 | class GLib { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 19 | public: |
Christopher Wiley | 0f3eab3 | 2013-03-21 11:55:41 -0700 | [diff] [blame] | 20 | GLib(); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 21 | virtual ~GLib(); |
| 22 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 23 | // Converts GLib's |error| to a string message and frees the GError object. |
| 24 | virtual std::string ConvertErrorToMessage(GError *error); |
| 25 | |
Christopher Wiley | 5447d2e | 2013-03-19 17:46:03 -0700 | [diff] [blame] | 26 | // Thin wrappers around Base64Decode/Encode. Return true on success. |
| 27 | virtual bool B64Decode(const std::string &input, std::string *output); |
| 28 | virtual bool B64Encode(const std::string &input, std::string *output); |
| 29 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 30 | // g_bus_unwatch_name |
| 31 | virtual void BusUnwatchName(guint watcher_id); |
| 32 | // g_bus_watch_name |
| 33 | virtual guint BusWatchName(GBusType bus_type, |
| 34 | const gchar *name, |
| 35 | GBusNameWatcherFlags flags, |
| 36 | GBusNameAppearedCallback name_appeared_handler, |
| 37 | GBusNameVanishedCallback name_vanished_handler, |
| 38 | gpointer user_data, |
| 39 | GDestroyNotify user_data_free_func); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 40 | // g_child_watch_add |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 41 | virtual guint ChildWatchAdd(GPid pid, |
| 42 | GChildWatchFunc function, |
| 43 | gpointer data); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 44 | // g_free |
| 45 | virtual void Free(gpointer mem); |
| 46 | // g_key_file_free |
| 47 | virtual void KeyFileFree(GKeyFile *key_file); |
| 48 | // g_key_file_get_boolean |
| 49 | virtual gboolean KeyFileGetBoolean(GKeyFile *key_file, |
| 50 | const gchar *group_name, |
| 51 | const gchar *key, |
| 52 | GError **error); |
| 53 | // g_key_file_get_groups |
| 54 | virtual gchar **KeyFileGetGroups(GKeyFile *key_file, |
| 55 | gsize *length); |
| 56 | // g_key_file_get_integer |
| 57 | virtual gint KeyFileGetInteger(GKeyFile *key_file, |
| 58 | const gchar *group_name, |
| 59 | const gchar *key, |
| 60 | GError **error); |
| 61 | // g_key_file_get_string |
| 62 | virtual gchar *KeyFileGetString(GKeyFile *key_file, |
| 63 | const gchar *group_name, |
| 64 | const gchar *key, |
| 65 | GError **error); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 66 | // g_key_file_get_string_list |
| 67 | virtual gchar **KeyFileGetStringList(GKeyFile *key_file, |
| 68 | const gchar *group_name, |
| 69 | const gchar *key, |
| 70 | gsize *length, |
| 71 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 72 | // g_key_file_has_group |
| 73 | virtual gboolean KeyFileHasGroup(GKeyFile *key_file, |
| 74 | const gchar *group_name); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 75 | // g_key_file_has_key |
| 76 | virtual gboolean KeyFileHasKey(GKeyFile *key_file, |
| 77 | const gchar *group_name, |
| 78 | const gchar *key, |
| 79 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 80 | // g_key_file_load_from_file |
| 81 | virtual gboolean KeyFileLoadFromFile(GKeyFile *key_file, |
| 82 | const gchar *file, |
| 83 | GKeyFileFlags flags, |
| 84 | GError **error); |
| 85 | // g_key_file_new |
| 86 | virtual GKeyFile *KeyFileNew(); |
| 87 | // g_key_file_remove_group |
| 88 | virtual void KeyFileRemoveGroup(GKeyFile *key_file, |
| 89 | const gchar *group_name, |
| 90 | GError **error); |
| 91 | // g_key_file_remove_key |
| 92 | virtual void KeyFileRemoveKey(GKeyFile *key_file, |
| 93 | const gchar *group_name, |
| 94 | const gchar *key, |
| 95 | GError **error); |
| 96 | // g_key_file_set_boolean |
| 97 | virtual void KeyFileSetBoolean(GKeyFile *key_file, |
| 98 | const gchar *group_name, |
| 99 | const gchar *key, |
| 100 | gboolean value); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 101 | // g_key_file_set_comment |
| 102 | virtual gboolean KeyFileSetComment(GKeyFile *key_file, |
| 103 | const gchar *group_name, |
| 104 | const gchar *key, |
| 105 | const gchar *comment, |
| 106 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 107 | // g_key_file_set_integer |
| 108 | virtual void KeyFileSetInteger(GKeyFile *key_file, |
| 109 | const gchar *group_name, |
| 110 | const gchar *key, |
| 111 | gint value); |
| 112 | // g_key_file_set_string |
| 113 | virtual void KeyFileSetString(GKeyFile *key_file, |
| 114 | const gchar *group_name, |
| 115 | const gchar *key, |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 116 | const gchar *value); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 117 | // g_key_file_set_string_list |
| 118 | virtual void KeyFileSetStringList(GKeyFile *key_file, |
| 119 | const gchar *group_name, |
| 120 | const gchar *key, |
| 121 | const gchar * const list[], |
| 122 | gsize length); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 123 | // g_key_file_to_data |
| 124 | virtual gchar *KeyFileToData(GKeyFile *key_file, |
| 125 | gsize *length, |
| 126 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 127 | // g_source_remove |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 128 | virtual gboolean SourceRemove(guint tag); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 129 | // g_spawn_async |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 130 | virtual gboolean SpawnAsync(const gchar *working_directory, |
| 131 | gchar **argv, |
| 132 | gchar **envp, |
| 133 | GSpawnFlags flags, |
| 134 | GSpawnChildSetupFunc child_setup, |
| 135 | gpointer user_data, |
| 136 | GPid *child_pid, |
| 137 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 138 | // g_spawn_close_pid |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 139 | virtual void SpawnClosePID(GPid pid); |
Darin Petkov | 3c5e4dc | 2012-04-02 14:44:27 +0200 | [diff] [blame] | 140 | // g_spawn_sync |
| 141 | virtual gboolean SpawnSync(const gchar *working_directory, |
| 142 | gchar **argv, |
| 143 | gchar **envp, |
| 144 | GSpawnFlags flags, |
| 145 | GSpawnChildSetupFunc child_setup, |
| 146 | gpointer user_data, |
| 147 | gchar **standard_output, |
| 148 | gchar **standard_error, |
| 149 | gint *exit_status, |
| 150 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 151 | // g_strfreev |
| 152 | virtual void Strfreev(gchar **str_array); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 153 | // g_type_init |
| 154 | virtual void TypeInit(); |
Christopher Wiley | 0f3eab3 | 2013-03-21 11:55:41 -0700 | [diff] [blame] | 155 | |
| 156 | private: |
| 157 | DISALLOW_COPY_AND_ASSIGN(GLib); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | } // namespace shill |
| 161 | |
| 162 | #endif // SHILL_GLIB_H_ |