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 | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 10 | #include <glib.h> |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 11 | |
| 12 | namespace shill { |
| 13 | |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 14 | // A GLib abstraction allowing GLib mocking in tests. |
| 15 | class GLib { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 16 | public: |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 17 | virtual ~GLib(); |
| 18 | |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 19 | // Converts GLib's |error| to a string message and frees the GError object. |
| 20 | virtual std::string ConvertErrorToMessage(GError *error); |
| 21 | |
Darin Petkov | 823c47e | 2011-06-27 16:15:35 -0700 | [diff] [blame] | 22 | // g_base64_decode |
| 23 | virtual guchar *Base64Decode(const gchar *text, gsize *out_len); |
| 24 | // g_base64_encode |
| 25 | virtual gchar *Base64Encode(const guchar *data, gsize len); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 26 | // g_child_watch_add |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 27 | virtual guint ChildWatchAdd(GPid pid, |
| 28 | GChildWatchFunc function, |
| 29 | gpointer data); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 30 | // g_free |
| 31 | virtual void Free(gpointer mem); |
| 32 | // g_key_file_free |
| 33 | virtual void KeyFileFree(GKeyFile *key_file); |
| 34 | // g_key_file_get_boolean |
| 35 | virtual gboolean KeyFileGetBoolean(GKeyFile *key_file, |
| 36 | const gchar *group_name, |
| 37 | const gchar *key, |
| 38 | GError **error); |
| 39 | // g_key_file_get_groups |
| 40 | virtual gchar **KeyFileGetGroups(GKeyFile *key_file, |
| 41 | gsize *length); |
| 42 | // g_key_file_get_integer |
| 43 | virtual gint KeyFileGetInteger(GKeyFile *key_file, |
| 44 | const gchar *group_name, |
| 45 | const gchar *key, |
| 46 | GError **error); |
| 47 | // g_key_file_get_string |
| 48 | virtual gchar *KeyFileGetString(GKeyFile *key_file, |
| 49 | const gchar *group_name, |
| 50 | const gchar *key, |
| 51 | GError **error); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 52 | // g_key_file_get_string_list |
| 53 | virtual gchar **KeyFileGetStringList(GKeyFile *key_file, |
| 54 | const gchar *group_name, |
| 55 | const gchar *key, |
| 56 | gsize *length, |
| 57 | GError **error); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 58 | // g_key_file_has_group |
| 59 | virtual gboolean KeyFileHasGroup(GKeyFile *key_file, |
| 60 | const gchar *group_name); |
| 61 | // g_key_file_load_from_file |
| 62 | virtual gboolean KeyFileLoadFromFile(GKeyFile *key_file, |
| 63 | const gchar *file, |
| 64 | GKeyFileFlags flags, |
| 65 | GError **error); |
| 66 | // g_key_file_new |
| 67 | virtual GKeyFile *KeyFileNew(); |
| 68 | // g_key_file_remove_group |
| 69 | virtual void KeyFileRemoveGroup(GKeyFile *key_file, |
| 70 | const gchar *group_name, |
| 71 | GError **error); |
| 72 | // g_key_file_remove_key |
| 73 | virtual void KeyFileRemoveKey(GKeyFile *key_file, |
| 74 | const gchar *group_name, |
| 75 | const gchar *key, |
| 76 | GError **error); |
| 77 | // g_key_file_set_boolean |
| 78 | virtual void KeyFileSetBoolean(GKeyFile *key_file, |
| 79 | const gchar *group_name, |
| 80 | const gchar *key, |
| 81 | gboolean value); |
| 82 | // g_key_file_set_integer |
| 83 | virtual void KeyFileSetInteger(GKeyFile *key_file, |
| 84 | const gchar *group_name, |
| 85 | const gchar *key, |
| 86 | gint value); |
| 87 | // g_key_file_set_string |
| 88 | virtual void KeyFileSetString(GKeyFile *key_file, |
| 89 | const gchar *group_name, |
| 90 | const gchar *key, |
| 91 | const gchar *string); |
Darin Petkov | b2841fd | 2011-06-30 12:54:12 -0700 | [diff] [blame] | 92 | // g_key_file_set_string_list |
| 93 | virtual void KeyFileSetStringList(GKeyFile *key_file, |
| 94 | const gchar *group_name, |
| 95 | const gchar *key, |
| 96 | const gchar * const list[], |
| 97 | gsize length); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 98 | // g_key_file_to_data |
| 99 | virtual gchar *KeyFileToData(GKeyFile *key_file, |
| 100 | gsize *length, |
| 101 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 102 | // g_source_remove |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 103 | virtual gboolean SourceRemove(guint tag); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 104 | // g_spawn_async |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 105 | virtual gboolean SpawnAsync(const gchar *working_directory, |
| 106 | gchar **argv, |
| 107 | gchar **envp, |
| 108 | GSpawnFlags flags, |
| 109 | GSpawnChildSetupFunc child_setup, |
| 110 | gpointer user_data, |
| 111 | GPid *child_pid, |
| 112 | GError **error); |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 113 | // g_spawn_close_pid |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 114 | virtual void SpawnClosePID(GPid pid); |
Darin Petkov | 083047b | 2011-06-23 20:42:48 -0700 | [diff] [blame] | 115 | // g_strfreev |
| 116 | virtual void Strfreev(gchar **str_array); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | } // namespace shill |
| 120 | |
| 121 | #endif // SHILL_GLIB_H_ |