blob: deb34963696b0820b4e2b7dc9c9324323f030862 [file] [log] [blame]
Darin Petkov36a3ace2012-03-06 17:22:14 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkovf7897bc2011-06-08 17:13:36 -07002// 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 Petkov083047b2011-06-23 20:42:48 -07008#include <string>
9
Darin Petkov887f2982011-07-14 16:10:17 -070010#include <gio/gio.h>
Darin Petkov3258a812011-06-23 11:28:45 -070011#include <glib.h>
Darin Petkovf7897bc2011-06-08 17:13:36 -070012
Christopher Wiley0f3eab32013-03-21 11:55:41 -070013#include <base/basictypes.h>
14
Darin Petkovf7897bc2011-06-08 17:13:36 -070015namespace shill {
16
Darin Petkov3258a812011-06-23 11:28:45 -070017// A GLib abstraction allowing GLib mocking in tests.
18class GLib {
Darin Petkovf7897bc2011-06-08 17:13:36 -070019 public:
Christopher Wiley0f3eab32013-03-21 11:55:41 -070020 GLib();
Darin Petkov3258a812011-06-23 11:28:45 -070021 virtual ~GLib();
22
Darin Petkov083047b2011-06-23 20:42:48 -070023 // Converts GLib's |error| to a string message and frees the GError object.
24 virtual std::string ConvertErrorToMessage(GError *error);
25
Christopher Wiley5447d2e2013-03-19 17:46:03 -070026 // 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 Petkov887f2982011-07-14 16:10:17 -070030 // 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 Petkov3258a812011-06-23 11:28:45 -070040 // g_child_watch_add
Darin Petkov92c43902011-06-09 20:46:06 -070041 virtual guint ChildWatchAdd(GPid pid,
42 GChildWatchFunc function,
43 gpointer data);
Darin Petkov083047b2011-06-23 20:42:48 -070044 // 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 Petkovb2841fd2011-06-30 12:54:12 -070066 // 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 Petkov083047b2011-06-23 20:42:48 -070072 // g_key_file_has_group
73 virtual gboolean KeyFileHasGroup(GKeyFile *key_file,
74 const gchar *group_name);
Paul Stewarta41e38d2011-11-11 07:47:29 -080075 // 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 Petkov083047b2011-06-23 20:42:48 -070080 // 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 Stewart5dc40aa2011-10-28 19:43:43 -0700101 // 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 Petkov083047b2011-06-23 20:42:48 -0700107 // 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 Stefanoved2c28c2011-11-29 15:37:30 -0800116 const gchar *value);
Darin Petkovb2841fd2011-06-30 12:54:12 -0700117 // 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 Petkov083047b2011-06-23 20:42:48 -0700123 // g_key_file_to_data
124 virtual gchar *KeyFileToData(GKeyFile *key_file,
125 gsize *length,
126 GError **error);
Darin Petkov3258a812011-06-23 11:28:45 -0700127 // g_source_remove
Darin Petkov92c43902011-06-09 20:46:06 -0700128 virtual gboolean SourceRemove(guint tag);
Darin Petkov3258a812011-06-23 11:28:45 -0700129 // g_spawn_async
Darin Petkovf7897bc2011-06-08 17:13:36 -0700130 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 Petkov3258a812011-06-23 11:28:45 -0700138 // g_spawn_close_pid
Darin Petkov92c43902011-06-09 20:46:06 -0700139 virtual void SpawnClosePID(GPid pid);
Darin Petkov3c5e4dc2012-04-02 14:44:27 +0200140 // 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 Petkov083047b2011-06-23 20:42:48 -0700151 // g_strfreev
152 virtual void Strfreev(gchar **str_array);
Darin Petkov887f2982011-07-14 16:10:17 -0700153 // g_type_init
154 virtual void TypeInit();
Christopher Wiley0f3eab32013-03-21 11:55:41 -0700155
156 private:
157 DISALLOW_COPY_AND_ASSIGN(GLib);
Darin Petkovf7897bc2011-06-08 17:13:36 -0700158};
159
160} // namespace shill
161
162#endif // SHILL_GLIB_H_