blob: a3d321b1645c80d605a9d69a7935efce8b470793 [file] [log] [blame]
Darin Petkovf7897bc2011-06-08 17:13:36 -07001// 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 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
13namespace shill {
14
Darin Petkov3258a812011-06-23 11:28:45 -070015// A GLib abstraction allowing GLib mocking in tests.
16class GLib {
Darin Petkovf7897bc2011-06-08 17:13:36 -070017 public:
Darin Petkov3258a812011-06-23 11:28:45 -070018 virtual ~GLib();
19
Darin Petkov083047b2011-06-23 20:42:48 -070020 // Converts GLib's |error| to a string message and frees the GError object.
21 virtual std::string ConvertErrorToMessage(GError *error);
22
Darin Petkov823c47e2011-06-27 16:15:35 -070023 // 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 Petkov887f2982011-07-14 16:10:17 -070027 // 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 Petkov3258a812011-06-23 11:28:45 -070037 // g_child_watch_add
Darin Petkov92c43902011-06-09 20:46:06 -070038 virtual guint ChildWatchAdd(GPid pid,
39 GChildWatchFunc function,
40 gpointer data);
Darin Petkov083047b2011-06-23 20:42:48 -070041 // 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 Petkovb2841fd2011-06-30 12:54:12 -070063 // 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 Petkov083047b2011-06-23 20:42:48 -070069 // g_key_file_has_group
70 virtual gboolean KeyFileHasGroup(GKeyFile *key_file,
71 const gchar *group_name);
Paul Stewarta41e38d2011-11-11 07:47:29 -080072 // 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 Petkov083047b2011-06-23 20:42:48 -070077 // 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 Stewart5dc40aa2011-10-28 19:43:43 -070098 // 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 Petkov083047b2011-06-23 20:42:48 -0700104 // 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 Stefanoved2c28c2011-11-29 15:37:30 -0800113 const gchar *value);
Darin Petkovb2841fd2011-06-30 12:54:12 -0700114 // 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 Petkov083047b2011-06-23 20:42:48 -0700120 // g_key_file_to_data
121 virtual gchar *KeyFileToData(GKeyFile *key_file,
122 gsize *length,
123 GError **error);
Darin Petkov3258a812011-06-23 11:28:45 -0700124 // g_source_remove
Darin Petkov92c43902011-06-09 20:46:06 -0700125 virtual gboolean SourceRemove(guint tag);
Darin Petkov3258a812011-06-23 11:28:45 -0700126 // g_spawn_async
Darin Petkovf7897bc2011-06-08 17:13:36 -0700127 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 Petkov3258a812011-06-23 11:28:45 -0700135 // g_spawn_close_pid
Darin Petkov92c43902011-06-09 20:46:06 -0700136 virtual void SpawnClosePID(GPid pid);
Darin Petkov083047b2011-06-23 20:42:48 -0700137 // g_strfreev
138 virtual void Strfreev(gchar **str_array);
Darin Petkov887f2982011-07-14 16:10:17 -0700139 // g_type_init
140 virtual void TypeInit();
Darin Petkovf7897bc2011-06-08 17:13:36 -0700141};
142
143} // namespace shill
144
145#endif // SHILL_GLIB_H_