emergency-calls-manager: Init emergency type database
We so far did this on first access. Let's rather do it explicitly so we notice problems early on startup. Signed-off-by: Guido Günther <agx@sigxcpu.org> Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/790>
This commit is contained in:
@@ -279,8 +279,8 @@ calls_emergency_call_country_data_new (const char *country)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
void
|
||||||
init_hash (void)
|
calls_emergency_call_types_init (void)
|
||||||
{
|
{
|
||||||
if (g_once_init_enter (&by_mcc)) {
|
if (g_once_init_enter (&by_mcc)) {
|
||||||
GHashTable *table = g_hash_table_new_full (g_str_hash,
|
GHashTable *table = g_hash_table_new_full (g_str_hash,
|
||||||
@@ -308,6 +308,13 @@ init_hash (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
calls_emergency_call_types_destroy (void)
|
||||||
|
{
|
||||||
|
g_clear_pointer (&by_mcc, g_hash_table_unref);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
flags_to_string (CallsEmergencyCallTypeFlags flags)
|
flags_to_string (CallsEmergencyCallTypeFlags flags)
|
||||||
{
|
{
|
||||||
@@ -344,7 +351,7 @@ calls_emergency_call_type_get_name (const char *lookup, const char *country_code
|
|||||||
if (country_code == NULL)
|
if (country_code == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
init_hash ();
|
g_assert (by_mcc);
|
||||||
|
|
||||||
match = g_hash_table_lookup (by_mcc, country_code);
|
match = g_hash_table_lookup (by_mcc, country_code);
|
||||||
if (!match)
|
if (!match)
|
||||||
@@ -377,7 +384,7 @@ calls_emergency_call_types_get_numbers_by_country_code (const char *country_code
|
|||||||
if (country_code == NULL)
|
if (country_code == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
init_hash ();
|
g_assert (by_mcc);
|
||||||
|
|
||||||
match = g_hash_table_lookup (by_mcc, country_code);
|
match = g_hash_table_lookup (by_mcc, country_code);
|
||||||
if (!match)
|
if (!match)
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ typedef struct {
|
|||||||
CallsEmergencyCallCountryData *calls_emergency_call_country_data_new (const char *country);
|
CallsEmergencyCallCountryData *calls_emergency_call_country_data_new (const char *country);
|
||||||
void calls_emergency_call_country_data_free (CallsEmergencyCallCountryData *country_data);
|
void calls_emergency_call_country_data_free (CallsEmergencyCallCountryData *country_data);
|
||||||
|
|
||||||
|
void calls_emergency_call_types_init (void);
|
||||||
|
void calls_emergency_call_types_destroy (void);
|
||||||
char *calls_emergency_call_type_get_name (const char *number, const char *country_code);
|
char *calls_emergency_call_type_get_name (const char *number, const char *country_code);
|
||||||
GStrv calls_emergency_call_types_get_numbers_by_country_code (const char *country_code);
|
GStrv calls_emergency_call_types_get_numbers_by_country_code (const char *country_code);
|
||||||
|
|||||||
@@ -207,12 +207,23 @@ calls_emergency_calls_manager_dispose (GObject *object)
|
|||||||
G_OBJECT_CLASS (calls_emergency_calls_manager_parent_class)->dispose (object);
|
G_OBJECT_CLASS (calls_emergency_calls_manager_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
calls_emergency_calls_manager_finalize (GObject *object)
|
||||||
|
{
|
||||||
|
calls_emergency_call_types_destroy ();
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (calls_emergency_calls_manager_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
calls_emergency_calls_manager_class_init (CallsEmergencyCallsManagerClass *klass)
|
calls_emergency_calls_manager_class_init (CallsEmergencyCallsManagerClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
object_class->dispose = calls_emergency_calls_manager_dispose;
|
object_class->dispose = calls_emergency_calls_manager_dispose;
|
||||||
|
object_class->finalize = calls_emergency_calls_manager_finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -220,6 +231,8 @@ calls_emergency_calls_manager_init (CallsEmergencyCallsManager *self)
|
|||||||
{
|
{
|
||||||
CallsManager *manager = calls_manager_get_default ();
|
CallsManager *manager = calls_manager_get_default ();
|
||||||
|
|
||||||
|
calls_emergency_call_types_init ();
|
||||||
|
|
||||||
self->origins = g_object_ref (calls_manager_get_origins (manager));
|
self->origins = g_object_ref (calls_manager_get_origins (manager));
|
||||||
g_signal_connect_object (self->origins,
|
g_signal_connect_object (self->origins,
|
||||||
"items-changed",
|
"items-changed",
|
||||||
|
|||||||
@@ -46,9 +46,15 @@ int
|
|||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
|
gint ret;
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
calls_emergency_call_types_init ();
|
||||||
|
|
||||||
g_test_add_func ("/Calls/EmergencyCallTypes/lookup", test_lookup);
|
g_test_add_func ("/Calls/EmergencyCallTypes/lookup", test_lookup);
|
||||||
|
|
||||||
return g_test_run ();
|
ret = g_test_run ();
|
||||||
|
|
||||||
|
calls_emergency_call_types_destroy ();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user