registrybackend: style fixes

This commit is contained in:
Ignacio Casal Quinteiro 2016-01-25 16:01:45 +01:00
parent 3a201128c2
commit a5e819c4c3

View File

@ -118,7 +118,6 @@ typedef struct
GNode *cache_node; GNode *cache_node;
} RegistryWatch; } RegistryWatch;
/* Simple message passing for the watch thread. Not enough traffic to /* Simple message passing for the watch thread. Not enough traffic to
* justify a queue. * justify a queue.
*/ */
@ -136,7 +135,6 @@ typedef struct
RegistryWatch watch; RegistryWatch watch;
} WatchThreadMessage; } WatchThreadMessage;
typedef struct typedef struct
{ {
GSettingsBackend *owner; GSettingsBackend *owner;
@ -156,14 +154,12 @@ typedef struct
HANDLE message_sent_event, message_received_event; HANDLE message_sent_event, message_received_event;
} WatchThreadState; } WatchThreadState;
#define G_TYPE_REGISTRY_BACKEND (g_registry_backend_get_type ()) #define G_TYPE_REGISTRY_BACKEND (g_registry_backend_get_type ())
#define G_REGISTRY_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ #define G_REGISTRY_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
G_TYPE_REGISTRY_BACKEND, GRegistryBackend)) G_TYPE_REGISTRY_BACKEND, GRegistryBackend))
#define G_IS_REGISTRY_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \ #define G_IS_REGISTRY_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
G_TYPE_REGISTRY_BACKEND)) G_TYPE_REGISTRY_BACKEND))
typedef GSettingsBackendClass GRegistryBackendClass; typedef GSettingsBackendClass GRegistryBackendClass;
typedef struct { typedef struct {
@ -185,21 +181,21 @@ G_DEFINE_TYPE_WITH_CODE (GRegistryBackend,
g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME, g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
g_define_type_id, "registry", 90)) g_define_type_id, "registry", 90))
/********************************************************************************** /**********************************************************************************
* Utility functions * Utility functions
**********************************************************************************/ **********************************************************************************/
#include <stdio.h> #include <stdio.h>
static void static void
trace (const char *format, ...) trace (const char *format,
...)
{ {
#ifdef TRACE #ifdef TRACE
va_list va; va_start (va, format); va_list va; va_start (va, format);
vprintf (format, va); fflush (stdout); vprintf (format, va); fflush (stdout);
va_end (va); va_end (va);
#endif #endif
}; }
/* g_message including a windows error message. It is not useful to have an /* g_message including a windows error message. It is not useful to have an
* equivalent function for g_warning because none of the registry errors can * equivalent function for g_warning because none of the registry errors can
@ -229,8 +225,7 @@ g_message_win32_error (DWORD result_code,
trace ("(%s)", win32_message); trace ("(%s)", win32_message);
else else
g_message ("%s", win32_message); g_message ("%s", win32_message);
}; }
/* Make gsettings key into a registry path & value pair. /* Make gsettings key into a registry path & value pair.
* *
@ -257,29 +252,39 @@ parse_key (const gchar *key_name,
/* Prefix is expected to be in registry format (\ separators) so don't escape that. */ /* Prefix is expected to be in registry format (\ separators) so don't escape that. */
for (c = path_name + (registry_prefix ? strlen(registry_prefix) : 0); *c != 0; c++) for (c = path_name + (registry_prefix ? strlen(registry_prefix) : 0); *c != 0; c++)
{
if (*c == '/') if (*c == '/')
{ {
*c = '\\'; *c = '\\';
(*value_name) = c; (*value_name) = c;
} }
}
**value_name = 0;
(*value_name)++;
**value_name = 0; (*value_name)++;
return path_name; return path_name;
}; }
static DWORD static DWORD
g_variant_get_as_dword (GVariant *variant) g_variant_get_as_dword (GVariant *variant)
{ {
switch (g_variant_get_type_string (variant)[0]) switch (g_variant_get_type_string (variant)[0])
{ {
case 'b': return g_variant_get_boolean (variant); case 'b':
case 'y': return g_variant_get_byte (variant); return g_variant_get_boolean (variant);
case 'n': return g_variant_get_int16 (variant); case 'y':
case 'q': return g_variant_get_uint16 (variant); return g_variant_get_byte (variant);
case 'i': return g_variant_get_int32 (variant); case 'n':
case 'u': return g_variant_get_uint32 (variant); return g_variant_get_int16 (variant);
default: g_warn_if_reached (); case 'q':
return g_variant_get_uint16 (variant);
case 'i':
return g_variant_get_int32 (variant);
case 'u':
return g_variant_get_uint32 (variant);
default:
g_warn_if_reached ();
} }
return 0; return 0;
} }
@ -289,14 +294,16 @@ g_variant_get_as_qword (GVariant *variant)
{ {
switch (g_variant_get_type_string (variant)[0]) switch (g_variant_get_type_string (variant)[0])
{ {
case 'x': return g_variant_get_int64 (variant); case 'x':
case 't': return g_variant_get_uint64 (variant); return g_variant_get_int64 (variant);
default: g_warn_if_reached (); case 't':
return g_variant_get_uint64 (variant);
default:
g_warn_if_reached ();
} }
return 0; return 0;
} }
static void static void
handle_read_error (LONG result, handle_read_error (LONG result,
const gchar *path_name, const gchar *path_name,
@ -346,7 +353,6 @@ registry_value_free (RegistryValue value)
value.ptr = NULL; value.ptr = NULL;
} }
/* The registry cache is stored as a tree, for easy traversal. Right now we /* The registry cache is stored as a tree, for easy traversal. Right now we
* don't sort it in a clever way. Each node corresponds to a path element * don't sort it in a clever way. Each node corresponds to a path element
* ('key' in registry terms) or a value. * ('key' in registry terms) or a value.
@ -377,8 +383,6 @@ typedef struct
RegistryValue value; RegistryValue value;
} RegistryCacheItem; } RegistryCacheItem;
static GNode * static GNode *
registry_cache_add_item (GNode *parent, registry_cache_add_item (GNode *parent,
gchar *name, gchar *name,
@ -412,7 +416,6 @@ registry_cache_add_item (GNode *parent,
* well as each parent up to the root. * well as each parent up to the root.
*/ */
static void static void
_ref_down (GNode *node) _ref_down (GNode *node)
{ {
@ -547,14 +550,15 @@ registry_cache_find_immediate_child (GNode *node,
gchar *name) gchar *name)
{ {
RegistryCacheSearch search; RegistryCacheSearch search;
search.result = NULL; search.result = NULL;
search.name = name; search.name = name;
g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, 2, g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, 2,
registry_cache_find_compare, &search); registry_cache_find_compare, &search);
return search.result; return search.result;
} }
static GNode * static GNode *
registry_cache_get_node_for_key_recursive (GNode *node, registry_cache_get_node_for_key_recursive (GNode *node,
gchar *key_name, gchar *key_name,
@ -745,8 +749,7 @@ registry_cache_block_notification (GNode *node)
registry_cache_block_notification (node->parent); registry_cache_block_notification (node->parent);
} }
static void static void registry_cache_destroy_tree (GNode *node,
registry_cache_destroy_tree (GNode *node,
WatchThreadState *self); WatchThreadState *self);
/*************************************************************************** /***************************************************************************
@ -797,7 +800,6 @@ registry_read (HKEY hpath,
return TRUE; return TRUE;
} }
static GVariant * static GVariant *
g_registry_backend_read (GSettingsBackend *backend, g_registry_backend_read (GSettingsBackend *backend,
const gchar *key_name, const gchar *key_name,
@ -863,7 +865,7 @@ g_registry_backend_read (GSettingsBackend *backend,
gsettings_value = g_variant_parse (expected_type, registry_value.ptr, NULL, NULL, &error); gsettings_value = g_variant_parse (expected_type, registry_value.ptr, NULL, NULL, &error);
if (error != NULL) if (error != NULL)
g_message ("gregistrysettingsbackend: error parsing key %s: %s\n", g_message ("gregistrysettingsbackend: error parsing key %s: %s",
key_name, error->message); key_name, error->message);
} }
} }
@ -993,7 +995,7 @@ g_registry_backend_write_one (const char *key_name,
g_free (path_name); g_free (path_name);
return FALSE; return FALSE;
}; }
/* The dconf write policy is to do the write while making out it succeeded, /* The dconf write policy is to do the write while making out it succeeded,
* and then backtrack if it didn't. The registry functions are synchronous so * and then backtrack if it didn't. The registry functions are synchronous so
@ -1326,9 +1328,7 @@ registry_cache_update (GRegistryBackend *self,
trace ("registry cache update complete.\n"); trace ("registry cache update complete.\n");
g_free (key_name); g_free (key_name);
}; }
/*********************************************************************************** /***********************************************************************************
* Thread to watch for registry change events * Thread to watch for registry change events
@ -1343,7 +1343,6 @@ registry_watch_key (HKEY hpath, HANDLE event)
event, TRUE); event, TRUE);
} }
/* One of these is sent down the pipe when something happens in the registry. */ /* One of these is sent down the pipe when something happens in the registry. */
typedef struct typedef struct
{ {
@ -1370,11 +1369,10 @@ watch_handler (RegistryEvent *event)
g_free (event->prefix); g_free (event->prefix);
g_object_unref (event->self); g_object_unref (event->self);
g_slice_free (RegistryEvent, event); g_slice_free (RegistryEvent, event);
return G_SOURCE_REMOVE;
};
return G_SOURCE_REMOVE;
}
static void static void
_free_watch (WatchThreadState *self, _free_watch (WatchThreadState *self,
@ -1515,7 +1513,6 @@ watch_thread_handle_message (WatchThreadState *self)
SetEvent (self->message_received_event); SetEvent (self->message_received_event);
} }
/* Thread which watches for win32 registry events */ /* Thread which watches for win32 registry events */
static DWORD WINAPI static DWORD WINAPI
watch_thread_function (LPVOID parameter) watch_thread_function (LPVOID parameter)
@ -1723,7 +1720,7 @@ watch_stop_unlocked (GRegistryBackend *self)
trace ("\nwatch thread: %x: all data freed.\n", self); trace ("\nwatch thread: %x: all data freed.\n", self);
self->watch = NULL; self->watch = NULL;
}; }
static gboolean static gboolean
watch_add_notify (GRegistryBackend *self, watch_add_notify (GRegistryBackend *self,
@ -1795,8 +1792,7 @@ watch_add_notify (GRegistryBackend *self,
LeaveCriticalSection (watch->message_lock); LeaveCriticalSection (watch->message_lock);
return TRUE; return TRUE;
}; }
static void static void
watch_remove_notify (GRegistryBackend *self, watch_remove_notify (GRegistryBackend *self,
@ -1824,7 +1820,7 @@ watch_remove_notify (GRegistryBackend *self,
result = WaitForSingleObject (watch->message_received_event, INFINITE); result = WaitForSingleObject (watch->message_received_event, INFINITE);
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
g_warning ("unsubscribe from %s: message not acknowledged\n", key_name); g_warning ("unsubscribe from %s: message not acknowledged", key_name);
if (g_atomic_int_get (&watch->watches_remaining) >= MAX_WATCHES) if (g_atomic_int_get (&watch->watches_remaining) >= MAX_WATCHES)
/* Stop it before any new ones can get added and confuse things */ /* Stop it before any new ones can get added and confuse things */
@ -1853,7 +1849,7 @@ g_registry_backend_subscribe (GSettingsBackend *backend,
if (g_atomic_int_dec_and_test (&self->watch->watches_remaining)) if (g_atomic_int_dec_and_test (&self->watch->watches_remaining))
{ {
g_atomic_int_inc (&self->watch->watches_remaining); g_atomic_int_inc (&self->watch->watches_remaining);
g_warning ("subscribe() failed: only %i different paths may be watched.\n", MAX_WATCHES); g_warning ("subscribe() failed: only %i different paths may be watched.", MAX_WATCHES);
return; return;
} }
@ -1864,11 +1860,10 @@ g_registry_backend_subscribe (GSettingsBackend *backend,
* end in a slash! * end in a slash!
*/ */
if (value_name != NULL && *value_name != 0) if (value_name != NULL && *value_name != 0)
g_warning ("subscribe() failed: path must end in a /, got %s\n", key_name); g_warning ("subscribe() failed: path must end in a /, got %s", key_name);
trace ("Subscribing to %s [registry %s / %s] - watch %x\n", key_name, path_name, value_name, self->watch); trace ("Subscribing to %s [registry %s / %s] - watch %x\n", key_name, path_name, value_name, self->watch);
/* Give the caller the benefit of the doubt if the key doesn't exist and create it. The caller /* Give the caller the benefit of the doubt if the key doesn't exist and create it. The caller
* is almost certainly a new g_settings with this path as base path. */ * is almost certainly a new g_settings with this path as base path. */
result = RegCreateKeyExA (HKEY_CURRENT_USER, path_name, 0, NULL, 0, KEY_READ, NULL, &hpath, result = RegCreateKeyExA (HKEY_CURRENT_USER, path_name, 0, NULL, 0, KEY_READ, NULL, &hpath,
@ -1885,7 +1880,7 @@ g_registry_backend_subscribe (GSettingsBackend *backend,
event = CreateEvent (NULL, FALSE, FALSE, NULL); event = CreateEvent (NULL, FALSE, FALSE, NULL);
if (event == NULL) if (event == NULL)
{ {
g_message_win32_error (result, "gregistrybackend: CreateEvent failed.\n"); g_message_win32_error (result, "gregistrybackend: CreateEvent failed.");
g_atomic_int_inc (&self->watch->watches_remaining); g_atomic_int_inc (&self->watch->watches_remaining);
RegCloseKey (hpath); RegCloseKey (hpath);
return; return;