Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: memconf/config.cc

Issue 2860022: Add api to ibus for retreiving unused config values. (Closed) Base URL: ssh://gitrw.chromium.org/ibus.git
Patch Set: Code review changes Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « memconf/config.h ('k') | src/ibusconfig.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* ibus - The Input Bus 1 /* ibus - The Input Bus
2 * 2 *
3 * Copyright (C) 2008-2010 Red Hat, Inc. 3 * Copyright (C) 2008-2010 Red Hat, Inc.
4 * Copyright (c) 2010, Google Inc. All rights reserved. 4 * Copyright (c) 2010, Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public 7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 24 matching lines...) Expand all
35 IBusError** error); 35 IBusError** error);
36 static gboolean ibus_config_memconf_get_value(IBusConfigService* config, 36 static gboolean ibus_config_memconf_get_value(IBusConfigService* config,
37 const gchar* section, 37 const gchar* section,
38 const gchar* name, 38 const gchar* name,
39 GValue* value, 39 GValue* value,
40 IBusError** error); 40 IBusError** error);
41 static gboolean ibus_config_memconf_unset(IBusConfigService* config, 41 static gboolean ibus_config_memconf_unset(IBusConfigService* config,
42 const gchar* section, 42 const gchar* section,
43 const gchar* name, 43 const gchar* name,
44 IBusError** error); 44 IBusError** error);
45 static gboolean ibus_config_memconf_get_unused(IBusConfigService* config,
46 GValue* unread,
47 GValue* unwritten,
48 IBusError** error);
45 49
46 // Copied from gconf/config.c. 50 // Copied from gconf/config.c.
47 static IBusConfigServiceClass* parent_class = NULL; 51 static IBusConfigServiceClass* parent_class = NULL;
48 52
49 // Copied from gconf/config.c. 53 // Copied from gconf/config.c.
50 GType ibus_config_memconf_get_type() { 54 GType ibus_config_memconf_get_type() {
51 static GType type = 0; 55 static GType type = 0;
52 56
53 static const GTypeInfo type_info = { 57 static const GTypeInfo type_info = {
54 sizeof(IBusConfigMemConfClass), 58 sizeof(IBusConfigMemConfClass),
(...skipping 24 matching lines...) Expand all
79 parent_class = reinterpret_cast<IBusConfigServiceClass*>( 83 parent_class = reinterpret_cast<IBusConfigServiceClass*>(
80 g_type_class_peek_parent(klass)); 84 g_type_class_peek_parent(klass));
81 85
82 IBUS_OBJECT_CLASS(object_class)->destroy 86 IBUS_OBJECT_CLASS(object_class)->destroy
83 = reinterpret_cast<IBusObjectDestroyFunc>(ibus_config_memconf_destroy); 87 = reinterpret_cast<IBusObjectDestroyFunc>(ibus_config_memconf_destroy);
84 IBUS_CONFIG_SERVICE_CLASS(object_class)->set_value 88 IBUS_CONFIG_SERVICE_CLASS(object_class)->set_value
85 = ibus_config_memconf_set_value; 89 = ibus_config_memconf_set_value;
86 IBUS_CONFIG_SERVICE_CLASS(object_class)->get_value 90 IBUS_CONFIG_SERVICE_CLASS(object_class)->get_value
87 = ibus_config_memconf_get_value; 91 = ibus_config_memconf_get_value;
88 IBUS_CONFIG_SERVICE_CLASS(object_class)->unset = ibus_config_memconf_unset; 92 IBUS_CONFIG_SERVICE_CLASS(object_class)->unset = ibus_config_memconf_unset;
93 IBUS_CONFIG_SERVICE_CLASS(object_class)->get_unused
94 = ibus_config_memconf_get_unused;
89 } 95 }
90 96
91 static void ibus_config_memconf_init(IBusConfigMemConf* config) { 97 static void ibus_config_memconf_init(IBusConfigMemConf* config) {
92 config->entries = new std::map<std::string, GValue*>; 98 config->entries = new std::map<std::string, GValue*>;
99 config->unread = new std::set<std::string>;
100 config->unwritten = new std::set<std::string>;
93 } 101 }
94 102
95 static void ibus_config_memconf_destroy(IBusConfigMemConf* config) { 103 static void ibus_config_memconf_destroy(IBusConfigMemConf* config) {
96 if (config) { 104 if (config) {
97 std::map<std::string, GValue*>::iterator iter; 105 std::map<std::string, GValue*>::iterator iter;
98 for (iter = config->entries->begin(); 106 for (iter = config->entries->begin();
99 iter != config->entries->end(); 107 iter != config->entries->end();
100 ++iter) { 108 ++iter) {
101 g_value_unset(iter->second); 109 g_value_unset(iter->second);
102 g_free(iter->second); 110 g_free(iter->second);
103 } 111 }
104 delete config->entries; 112 delete config->entries;
113 delete config->unread;
114 delete config->unwritten;
105 } 115 }
106 IBUS_OBJECT_CLASS(parent_class)->destroy( 116 IBUS_OBJECT_CLASS(parent_class)->destroy(
107 reinterpret_cast<IBusObject*>(config)); 117 reinterpret_cast<IBusObject*>(config));
108 } 118 }
109 119
110 // Remove an entry associated with |key| from the on-memory config database. 120 // Remove an entry associated with |key| from the on-memory config database.
111 static gboolean do_unset(IBusConfigMemConf* memconf, const std::string& key) { 121 static gboolean do_unset(IBusConfigMemConf* memconf, const std::string& key) {
112 std::map<std::string, GValue*>::iterator iter = memconf->entries->find(key); 122 std::map<std::string, GValue*>::iterator iter = memconf->entries->find(key);
113 if (iter != memconf->entries->end()) { 123 if (iter != memconf->entries->end()) {
114 g_value_unset(iter->second); 124 g_value_unset(iter->second);
(...skipping 16 matching lines...) Expand all
131 g_return_val_if_fail(name, FALSE); 141 g_return_val_if_fail(name, FALSE);
132 g_return_val_if_fail(value, FALSE); 142 g_return_val_if_fail(value, FALSE);
133 g_return_val_if_fail(error, FALSE); 143 g_return_val_if_fail(error, FALSE);
134 144
135 const std::string key = std::string(section) + name; 145 const std::string key = std::string(section) + name;
136 IBusConfigMemConf* memconf = reinterpret_cast<IBusConfigMemConf*>(config); 146 IBusConfigMemConf* memconf = reinterpret_cast<IBusConfigMemConf*>(config);
137 147
138 GValue* new_entry = g_new0(GValue, 1); 148 GValue* new_entry = g_new0(GValue, 1);
139 g_value_init(new_entry, G_VALUE_TYPE(value)); 149 g_value_init(new_entry, G_VALUE_TYPE(value));
140 g_value_copy(value, new_entry); 150 g_value_copy(value, new_entry);
141 151
142 do_unset(memconf, key); // remove an existing entry (if any) first. 152 // remove an existing entry (if any) first.
153 if (!do_unset(memconf, key)) {
154 memconf->unread->insert(key);
155 }
143 bool result = memconf->entries->insert(std::make_pair(key, new_entry)).second; 156 bool result = memconf->entries->insert(std::make_pair(key, new_entry)).second;
144 if (!result) { 157 if (!result) {
145 g_value_unset(new_entry); 158 g_value_unset(new_entry);
146 g_free(new_entry); 159 g_free(new_entry);
147 *error = ibus_error_new_from_printf( 160 *error = ibus_error_new_from_printf(
148 DBUS_ERROR_FAILED, "Can not set value [%s->%s]", section, name); 161 DBUS_ERROR_FAILED, "Can not set value [%s->%s]", section, name);
149 } 162 }
150 163
151 // Let ibus-daemon know that a new value is set to ibus-memconf. Note that 164 // Let ibus-daemon know that a new value is set to ibus-memconf. Note that
152 // _config_value_changed_cb() function in bus/ibusimpl.c will handle this RPC. 165 // _config_value_changed_cb() function in bus/ibusimpl.c will handle this RPC.
(...skipping 15 matching lines...) Expand all
168 g_return_val_if_fail(error, FALSE); 181 g_return_val_if_fail(error, FALSE);
169 182
170 const std::string key = std::string(section) + name; 183 const std::string key = std::string(section) + name;
171 IBusConfigMemConf* memconf = reinterpret_cast<IBusConfigMemConf*>(config); 184 IBusConfigMemConf* memconf = reinterpret_cast<IBusConfigMemConf*>(config);
172 185
173 std::map<std::string, GValue*>::const_iterator iter 186 std::map<std::string, GValue*>::const_iterator iter
174 = memconf->entries->find(key); 187 = memconf->entries->find(key);
175 if (iter == memconf->entries->end()) { 188 if (iter == memconf->entries->end()) {
176 *error = ibus_error_new_from_printf( 189 *error = ibus_error_new_from_printf(
177 DBUS_ERROR_FAILED, "Can not get value [%s->%s]", section, name); 190 DBUS_ERROR_FAILED, "Can not get value [%s->%s]", section, name);
191 memconf->unwritten->insert(key);
178 return FALSE; 192 return FALSE;
179 } 193 }
180 194
195 memconf->unread->erase(key);
181 const GValue* entry = iter->second; 196 const GValue* entry = iter->second;
182 g_value_init(value, G_VALUE_TYPE(entry)); 197 g_value_init(value, G_VALUE_TYPE(entry));
183 g_value_copy(entry, value); 198 g_value_copy(entry, value);
184 199
185 // |value| will be g_value_unset() in the super class after the value is sent 200 // |value| will be g_value_unset() in the super class after the value is sent
186 // to ibus-daemon. See src/ibusconfigservice.c for details. 201 // to ibus-daemon. See src/ibusconfigservice.c for details.
187 return TRUE; 202 return TRUE;
188 } 203 }
189 204
190 // Server side implementation of ibus_config_unset_value. 205 // Server side implementation of ibus_config_unset_value.
191 static gboolean ibus_config_memconf_unset(IBusConfigService* config, 206 static gboolean ibus_config_memconf_unset(IBusConfigService* config,
192 const gchar* section, 207 const gchar* section,
193 const gchar* name, 208 const gchar* name,
194 IBusError** error) { 209 IBusError** error) {
195 g_return_val_if_fail(config, FALSE); 210 g_return_val_if_fail(config, FALSE);
196 g_return_val_if_fail(section, FALSE); 211 g_return_val_if_fail(section, FALSE);
197 g_return_val_if_fail(name, FALSE); 212 g_return_val_if_fail(name, FALSE);
198 g_return_val_if_fail(error, FALSE); 213 g_return_val_if_fail(error, FALSE);
199 214
200 const std::string key = std::string(section) + name; 215 const std::string key = std::string(section) + name;
201 IBusConfigMemConf* memconf = reinterpret_cast<IBusConfigMemConf*>(config); 216 IBusConfigMemConf* memconf = reinterpret_cast<IBusConfigMemConf*>(config);
202 217
203 if (!do_unset(memconf, key)) { 218 if (!do_unset(memconf, key)) {
204 *error = ibus_error_new_from_printf( 219 *error = ibus_error_new_from_printf(
205 DBUS_ERROR_FAILED, "Can not unset value [%s->%s]", section, name); 220 DBUS_ERROR_FAILED, "Can not unset value [%s->%s]", section, name);
206 return FALSE; 221 return FALSE;
207 } 222 }
223 memconf->unread->erase(key);
208 224
209 // Note: It is not allowed to call ibus_config_service_value_changed function 225 // Note: It is not allowed to call ibus_config_service_value_changed function
210 // with zero-cleared GValue, so we don't call the function here. 226 // with zero-cleared GValue, so we don't call the function here.
211 // See src/ibusconfigservice.c for details. 227 // See src/ibusconfigservice.c for details.
212 return TRUE; 228 return TRUE;
213 } 229 }
214 230
231 static gboolean ibus_config_memconf_get_unused(IBusConfigService* config,
232 GValue* unread,
233 GValue* unwritten,
234 IBusError** error) {
235 IBusConfigMemConf* memconf = reinterpret_cast<IBusConfigMemConf*>(config);
236
237 {
238 g_value_init(unread, G_TYPE_VALUE_ARRAY);
239 GValueArray* array = g_value_array_new(memconf->unread->size());
240 for (std::set<std::string>::const_iterator current =
241 memconf->unread->begin();
242 current != memconf->unread->end(); ++current) {
243 GValue array_element = {0};
244 g_value_init(&array_element, G_TYPE_STRING);
245 g_value_set_string(&array_element, current->c_str());
246 g_value_array_append(array, &array_element);
247 }
248 g_value_take_boxed(unread, array);
249 }
250
251 {
252 g_value_init(unwritten, G_TYPE_VALUE_ARRAY);
253 GValueArray* array = g_value_array_new(memconf->unwritten->size());
254 for (std::set<std::string>::const_iterator current =
255 memconf->unwritten->begin();
256 current != memconf->unwritten->end(); ++current) {
257 GValue array_element = {0};
258 g_value_init(&array_element, G_TYPE_STRING);
259 g_value_set_string(&array_element, current->c_str());
260 g_value_array_append(array, &array_element);
261 }
262 g_value_take_boxed(unwritten, array);
263 }
264 return TRUE;
265 }
266
215 // Copied from gconf/config.c. 267 // Copied from gconf/config.c.
216 IBusConfigMemConf* ibus_config_memconf_new(IBusConnection* connection) { 268 IBusConfigMemConf* ibus_config_memconf_new(IBusConnection* connection) {
217 IBusConfigMemConf* config = reinterpret_cast<IBusConfigMemConf*>( 269 IBusConfigMemConf* config = reinterpret_cast<IBusConfigMemConf*>(
218 g_object_new(ibus_config_memconf_get_type(), 270 g_object_new(ibus_config_memconf_get_type(),
219 "path", IBUS_PATH_CONFIG, 271 "path", IBUS_PATH_CONFIG,
220 "connection", connection, 272 "connection", connection,
221 NULL)); 273 NULL));
222 return config; 274 return config;
223 } 275 }
224 // TODO(yusukes): Upstream memconf/ code if possible. We might have to rewrite 276 // TODO(yusukes): Upstream memconf/ code if possible. We might have to rewrite
225 // the code to C and have to change the coding style though. 277 // the code to C and have to change the coding style though.
OLDNEW
« no previous file with comments | « memconf/config.h ('k') | src/ibusconfig.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698