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
|
||||
init_hash (void)
|
||||
void
|
||||
calls_emergency_call_types_init (void)
|
||||
{
|
||||
if (g_once_init_enter (&by_mcc)) {
|
||||
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 *
|
||||
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)
|
||||
return NULL;
|
||||
|
||||
init_hash ();
|
||||
g_assert (by_mcc);
|
||||
|
||||
match = g_hash_table_lookup (by_mcc, country_code);
|
||||
if (!match)
|
||||
@@ -377,7 +384,7 @@ calls_emergency_call_types_get_numbers_by_country_code (const char *country_code
|
||||
if (country_code == NULL)
|
||||
return NULL;
|
||||
|
||||
init_hash ();
|
||||
g_assert (by_mcc);
|
||||
|
||||
match = g_hash_table_lookup (by_mcc, country_code);
|
||||
if (!match)
|
||||
|
||||
@@ -50,6 +50,7 @@ typedef struct {
|
||||
CallsEmergencyCallCountryData *calls_emergency_call_country_data_new (const char *country);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
calls_emergency_calls_manager_class_init (CallsEmergencyCallsManagerClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->dispose = calls_emergency_calls_manager_dispose;
|
||||
object_class->finalize = calls_emergency_calls_manager_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -220,6 +231,8 @@ calls_emergency_calls_manager_init (CallsEmergencyCallsManager *self)
|
||||
{
|
||||
CallsManager *manager = calls_manager_get_default ();
|
||||
|
||||
calls_emergency_call_types_init ();
|
||||
|
||||
self->origins = g_object_ref (calls_manager_get_origins (manager));
|
||||
g_signal_connect_object (self->origins,
|
||||
"items-changed",
|
||||
|
||||
Reference in New Issue
Block a user