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;
} RegistryWatch;
/* Simple message passing for the watch thread. Not enough traffic to
* justify a queue.
*/
@ -136,7 +135,6 @@ typedef struct
RegistryWatch watch;
} WatchThreadMessage;
typedef struct
{
GSettingsBackend *owner;
@ -156,14 +154,12 @@ typedef struct
HANDLE message_sent_event, message_received_event;
} WatchThreadState;
#define G_TYPE_REGISTRY_BACKEND (g_registry_backend_get_type ())
#define G_REGISTRY_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
G_TYPE_REGISTRY_BACKEND, GRegistryBackend))
#define G_IS_REGISTRY_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
G_TYPE_REGISTRY_BACKEND))
typedef GSettingsBackendClass GRegistryBackendClass;
typedef struct {
@ -185,21 +181,21 @@ G_DEFINE_TYPE_WITH_CODE (GRegistryBackend,
g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
g_define_type_id, "registry", 90))
/**********************************************************************************
* Utility functions
**********************************************************************************/
#include <stdio.h>
static void
trace (const char *format, ...)
trace (const char *format,
...)
{
#ifdef TRACE
va_list va; va_start (va, format);
vprintf (format, va); fflush (stdout);
va_end (va);
#endif
};
}
/* 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
@ -229,8 +225,7 @@ g_message_win32_error (DWORD result_code,
trace ("(%s)", win32_message);
else
g_message ("%s", win32_message);
};
}
/* 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. */
for (c = path_name + (registry_prefix ? strlen(registry_prefix) : 0); *c != 0; c++)
{
if (*c == '/')
{
*c = '\\';
(*value_name) = c;
}
}
**value_name = 0;
(*value_name)++;
**value_name = 0; (*value_name)++;
return path_name;
};
}
static DWORD
g_variant_get_as_dword (GVariant *variant)
{
switch (g_variant_get_type_string (variant)[0])
{
case 'b': return g_variant_get_boolean (variant);
case 'y': return g_variant_get_byte (variant);
case 'n': return g_variant_get_int16 (variant);
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 ();
case 'b':
return g_variant_get_boolean (variant);
case 'y':
return g_variant_get_byte (variant);
case 'n':
return g_variant_get_int16 (variant);
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;
}
@ -289,14 +294,16 @@ g_variant_get_as_qword (GVariant *variant)
{
switch (g_variant_get_type_string (variant)[0])
{
case 'x': return g_variant_get_int64 (variant);
case 't': return g_variant_get_uint64 (variant);
default: g_warn_if_reached ();
case 'x':
return g_variant_get_int64 (variant);
case 't':
return g_variant_get_uint64 (variant);
default:
g_warn_if_reached ();
}
return 0;
}
static void
handle_read_error (LONG result,
const gchar *path_name,
@ -346,7 +353,6 @@ registry_value_free (RegistryValue value)
value.ptr = NULL;
}
/* 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
* ('key' in registry terms) or a value.
@ -377,8 +383,6 @@ typedef struct
RegistryValue value;
} RegistryCacheItem;
static GNode *
registry_cache_add_item (GNode *parent,
gchar *name,
@ -412,7 +416,6 @@ registry_cache_add_item (GNode *parent,
* well as each parent up to the root.
*/
static void
_ref_down (GNode *node)
{
@ -547,14 +550,15 @@ registry_cache_find_immediate_child (GNode *node,
gchar *name)
{
RegistryCacheSearch search;
search.result = NULL;
search.name = name;
g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, 2,
registry_cache_find_compare, &search);
return search.result;
}
static GNode *
registry_cache_get_node_for_key_recursive (GNode *node,
gchar *key_name,
@ -745,8 +749,7 @@ registry_cache_block_notification (GNode *node)
registry_cache_block_notification (node->parent);
}
static void
registry_cache_destroy_tree (GNode *node,
static void registry_cache_destroy_tree (GNode *node,
WatchThreadState *self);
/***************************************************************************
@ -797,7 +800,6 @@ registry_read (HKEY hpath,
return TRUE;
}
static GVariant *
g_registry_backend_read (GSettingsBackend *backend,
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);
if (error != NULL)
g_message ("gregistrysettingsbackend: error parsing key %s: %s\n",
g_message ("gregistrysettingsbackend: error parsing key %s: %s",
key_name, error->message);
}
}
@ -993,7 +995,7 @@ g_registry_backend_write_one (const char *key_name,
g_free (path_name);
return FALSE;
};
}
/* 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
@ -1326,9 +1328,7 @@ registry_cache_update (GRegistryBackend *self,
trace ("registry cache update complete.\n");
g_free (key_name);
};
}
/***********************************************************************************
* Thread to watch for registry change events
@ -1343,7 +1343,6 @@ registry_watch_key (HKEY hpath, HANDLE event)
event, TRUE);
}
/* One of these is sent down the pipe when something happens in the registry. */
typedef struct
{
@ -1370,11 +1369,10 @@ watch_handler (RegistryEvent *event)
g_free (event->prefix);
g_object_unref (event->self);
g_slice_free (RegistryEvent, event);
return G_SOURCE_REMOVE;
};
return G_SOURCE_REMOVE;
}
static void
_free_watch (WatchThreadState *self,
@ -1515,7 +1513,6 @@ watch_thread_handle_message (WatchThreadState *self)
SetEvent (self->message_received_event);
}
/* Thread which watches for win32 registry events */
static DWORD WINAPI
watch_thread_function (LPVOID parameter)
@ -1723,7 +1720,7 @@ watch_stop_unlocked (GRegistryBackend *self)
trace ("\nwatch thread: %x: all data freed.\n", self);
self->watch = NULL;
};
}
static gboolean
watch_add_notify (GRegistryBackend *self,
@ -1795,8 +1792,7 @@ watch_add_notify (GRegistryBackend *self,
LeaveCriticalSection (watch->message_lock);
return TRUE;
};
}
static void
watch_remove_notify (GRegistryBackend *self,
@ -1824,7 +1820,7 @@ watch_remove_notify (GRegistryBackend *self,
result = WaitForSingleObject (watch->message_received_event, INFINITE);
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)
/* 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))
{
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;
}
@ -1864,11 +1860,10 @@ g_registry_backend_subscribe (GSettingsBackend *backend,
* end in a slash!
*/
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);
/* 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. */
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);
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);
RegCloseKey (hpath);
return;