#include "mcc_tz_utils.h"
#include "logging.h"
#include "internal_time_utils.h"
#include "clock_dbus.h"
#include "codec.h"
#include <cityinfo.h>
#include <stdio.h>
#include <string.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <stdlib.h>
#include <ctype.h>
Functions | |
int | mcc_tz_is_tz_name_in_country_tz_list (const char *tz_name) |
static void | mcc_tz_correct_tz_choice (int found_tz_count, char **tz_name) |
static int | mcc_tz_find_tz_in_country_tz_list (struct tm *utc_tm, int dst, int gmtoff, char **tz_name) |
void | mcc_tz_guess_tz_for_country_by_dst_and_offset (struct tm *utc_tm, int dst, int gmtoff, char **tz_name) |
static int | mcc_tz_parse_mcc_mapping_line (const char *line, char **country) |
static gboolean | mcc_tz_find_country_by_mcc (int mcc, char **found_country) |
static gboolean | mcc_tz_get_tz_if_only_for_country (const char **found_tz) |
static gint | tz_name_compare (gconstpointer iterTZName, gconstpointer searchingTZName) |
static void | mcc_tz_prepend_tz_name_if_not_dup (const char *tz_name) |
static gboolean | mcc_tz_searching_tz_by_country_name (const Cityinfo *city, gpointer data) |
static void | mcc_tz_create_tz_name_list_by_country_name (const char *country_name) |
static void | mcc_tz_destroy_country_tz_name_list (void) |
static void | mcc_tz_update_country_tz_name_list (void) |
static void | mcc_tz_set_tz_from_mcc (void) |
static void | mcc_tz_handle_network_timeinfo_reply (DBusMessage *msg) |
static void | mcc_tz_network_timeinfo_reply_dbus_cb (DBusPendingCall *pending_call, void *data) |
static void | mcc_tz_check_if_network_timeinfo_available (void) |
void | mcc_tz_handle_registration_status_reply (DBusMessage *msg) |
static void | mcc_tz_registration_status_reply_dbus_cb (DBusPendingCall *pending_call, void *data) |
static void | mcc_tz_add_registration_change_match (void) |
static void | mcc_tz_remove_registration_change_match (void) |
void | mcc_tz_setup_timezone_from_mcc_if_required (void) |
int | mcc_tz_utils_init (DBusConnection *server_system_bus, GetAutosyncEnabled server_get_autosync_enabled, HandleCsdNetTimeChange server_handle_csd_net_time_change, SetOperatorTz server_set_operator_tz) |
void | mcc_tz_utils_quit (void) |
Copyright (C) 2008 Nokia. All rights reserved.
int mcc_tz_is_tz_name_in_country_tz_list | ( | const char * | tz_name | ) |
Checks if given timezone name is in timezone list for currnt country
tz_name | timezone name for searching |
Referenced by handle_csd_net_time_change().
static void mcc_tz_correct_tz_choice | ( | int | found_tz_count, | |
char ** | tz_name | |||
) | [static] |
Performs set of filters for found timezone (refer to mcc_tz_find_tz_in_country_tz_list and mcc_tz_guess_tz_for_country_by_dst_and_offset). See log strings in the function to understand what each filter is doing.
found_tz_count | count of similar timezones returned by mcc_tz_find_tz_in_country_tz_list | |
tz_name | Not changed if filters allow timezone, NULL otherwise |
Referenced by mcc_tz_guess_tz_for_country_by_dst_and_offset().
static int mcc_tz_find_tz_in_country_tz_list | ( | struct tm * | utc_tm, | |
int | dst, | |||
int | gmtoff, | |||
char ** | tz_name | |||
) | [static] |
Searches for tz in country tz list generated by current mcc which has the same DST and GMT offset as requested in given UTC time. Returns first found timezone name (in tz_name) and number of found timezones.
utc_tm | UTC time to search in | |
dst | DST for searching timezone in given UTC time | |
gmtoff | GMT offset for searching timezone in given UTC time | |
tz_name | name of first found timezone for requested parameters or NULL if not found It shall not be freed since it is pointer to string contained in country_tz_name_list Also the user must dup this string if it is needed in next mainloop cycle since the list might be updated in-between. |
Referenced by mcc_tz_guess_tz_for_country_by_dst_and_offset().
void mcc_tz_guess_tz_for_country_by_dst_and_offset | ( | struct tm * | utc_tm, | |
int | dst, | |||
int | gmtoff, | |||
char ** | tz_name | |||
) |
Guesses named timezone for current country which has the same DST and GMT offset as requested in given UTC time. Returns first found name in tz_name or NULL if not found.
utc_tm | UTC time to search in | |
dst | DST for searching timezone in given UTC time | |
gmtoff | GMT offset for searching timezone in given UTC time | |
tz_name | name of found timezone for requested parameters or NULL if not found It shall not be freed since it is pointer to string contained in country_tz_name_list Also the user must dup this string if it is needed in next mainloop cycle since the list might be updated in-between. |
Referenced by handle_csd_net_time_change().
static int mcc_tz_parse_mcc_mapping_line | ( | const char * | line, | |
char ** | country | |||
) | [static] |
Parse line from /usr/share/operator-wizard/mcc_mapping to extract MCC and country name.
line | line from /usr/share/operator-wizard/mcc_mapping to parse | |
country | NULL if fails, country name (localizable) if OK |
Referenced by mcc_tz_find_country_by_mcc().
static gboolean mcc_tz_find_country_by_mcc | ( | int | mcc, | |
char ** | found_country | |||
) | [static] |
Map MCC to country name using /usr/share/operator-wizard/mcc_mapping Allocates memory to return country name. Caller is responsible to free the memory.
mcc | MCC to find | |
found_country | NULL if fails, country name (localizable) if OK |
Referenced by mcc_tz_update_country_tz_name_list().
static gboolean mcc_tz_get_tz_if_only_for_country | ( | const char ** | found_tz | ) | [static] |
Wrapper above country_tz_name_list to check if only TZ was found for country. If only timezone found, memory is NOT allocated to returm its name. This memory must NOT be freed by caller.
found_tz | NULL if not found or multiple timezones found, timezone name otherwise |
Referenced by mcc_tz_set_tz_from_mcc().
static gint tz_name_compare | ( | gconstpointer | iterTZName, | |
gconstpointer | searchingTZName | |||
) | [static] |
Custom compare function used to find time zone name in country_tz_name_list
iterTZName | TZ Name in iterator | |
searchingTZName | TZ Name to find |
Referenced by mcc_tz_prepend_tz_name_if_not_dup().
static void mcc_tz_prepend_tz_name_if_not_dup | ( | const char * | tz_name | ) | [static] |
Prepend tz_name to list of tz names for country if not a dup. The list is stored in country_tz_name_list
tz_name | TZ name to prepend to country_tz_name_list if not a dup |
Referenced by mcc_tz_searching_tz_by_country_name().
static gboolean mcc_tz_searching_tz_by_country_name | ( | const Cityinfo * | city, | |
gpointer | data | |||
) | [static] |
Helper function used to fill timezone name list for the named country. Refer to cityinfo API for details about helper functions for cityinfo_foreach algorithm
city | Entry in city info db | |
data | Country name for searching |
Referenced by mcc_tz_create_tz_name_list_by_country_name().
static void mcc_tz_create_tz_name_list_by_country_name | ( | const char * | country_name | ) | [static] |
Create list of tz names for country. The list is stored in country_tz_name_list
Referenced by mcc_tz_update_country_tz_name_list().
static void mcc_tz_destroy_country_tz_name_list | ( | void | ) | [static] |
Destroys list of tz names for contry.
Referenced by mcc_tz_update_country_tz_name_list(), and mcc_tz_utils_quit().
static void mcc_tz_update_country_tz_name_list | ( | void | ) | [static] |
Updates list of tz names for country determined by MCC (mcc_cache). The list is stored in country_tz_name_list
Referenced by mcc_tz_handle_registration_status_reply().
static void mcc_tz_set_tz_from_mcc | ( | void | ) | [static] |
Change current timezone to found by MCC if MCC can be definitely mapped to timezone It used cached value of MCC (mcc_cache).
Referenced by mcc_tz_handle_network_timeinfo_reply().
static void mcc_tz_handle_network_timeinfo_reply | ( | DBusMessage * | msg | ) | [static] |
Handle reply on get time info request to CSD. If autoupdate is off - do nothing. If autoupdate is on and NITZ supported by network, it parse reply and set network time. If autoupdate is on and NITZ does not supported by network, it makes attempt to correct timezone at least using cached MCC
msg | D-Bus reply on get time info request to CSD |
Referenced by mcc_tz_network_timeinfo_reply_dbus_cb().
static void mcc_tz_network_timeinfo_reply_dbus_cb | ( | DBusPendingCall * | pending_call, | |
void * | data | |||
) | [static] |
Callback to catch reply on get time info request to CSD. Refer to D-Bus API for details
pending_call | D-Bus object to catch reply | |
data | Not used |
Referenced by mcc_tz_check_if_network_timeinfo_available().
static void mcc_tz_check_if_network_timeinfo_available | ( | void | ) | [static] |
Sends get time info request to CSD. Reply is catched by mcc_tz_network_timeinfo_reply_dbus_cb callback
Referenced by mcc_tz_handle_registration_status_reply().
void mcc_tz_handle_registration_status_reply | ( | DBusMessage * | msg | ) |
Handle reply on get registration status request to CSD. If registered in home or roaming network and received MCC is not equal to cached one, launch network time update attempt, since country (and timezone probably) is changed.
msg | D-Bus reply on get registration status request to CSD |
Referenced by mcc_tz_registration_status_reply_dbus_cb(), and server_filter().
static void mcc_tz_registration_status_reply_dbus_cb | ( | DBusPendingCall * | pending_call, | |
void * | data | |||
) | [static] |
Callback to catch reply on get registration status request to CSD. Refer to D-Bus API for details
pending_call | D-Bus object to catch reply | |
data | Not used |
Referenced by mcc_tz_setup_timezone_from_mcc_if_required().
static void mcc_tz_add_registration_change_match | ( | void | ) | [static] |
Add tracking of registration status change signal to system bus if it was not added before
Referenced by mcc_tz_setup_timezone_from_mcc_if_required().
static void mcc_tz_remove_registration_change_match | ( | void | ) | [static] |
Remove tracking of registration status change signal from system bus if it was added before
Referenced by mcc_tz_setup_timezone_from_mcc_if_required(), and mcc_tz_utils_quit().
void mcc_tz_setup_timezone_from_mcc_if_required | ( | void | ) |
If autoupdate is on, it sends get registration status request to CSD. It launches procedure to update time if device is registered in network. Reply is catched by mcc_tz_registration_status_reply_dbus_cb callback.
Also the method asks D-Bus to notify about registration status change signal if time autoupdate is on and remove this tracking if time autoupdate is off. The signal is handled by server_filter (refer to mcc_tz_init also).
Referenced by mcc_tz_utils_init(), and server_set_autosync_cb().
int mcc_tz_utils_init | ( | DBusConnection * | server_system_bus, | |
GetAutosyncEnabled | server_get_autosync_enabled, | |||
HandleCsdNetTimeChange | server_handle_csd_net_time_change, | |||
SetOperatorTz | server_set_operator_tz | |||
) |
Fuction to init mcc_tz module
server_system_bus | pointer to system DBUS | |
server_get_autosync_enabled | pointer to function to get autosync_enabled value | |
server_handle_csd_net_time_change | pointer to function to handle time info message from csd | |
server_set_operator_tz | pointer to function to set operator timezone |
Referenced by server_init().
void mcc_tz_utils_quit | ( | void | ) |
Fuction to free resources allocated by mcc_tz module
Referenced by server_quit().