static GMainLoop *loop = NULL;
static GDBusConnection *connection = NULL;
-static guint subscribe_id;
GOptionEntry option_entries[] = {
{ "daemon", 'd', 0, G_OPTION_ARG_NONE, &use_daemon,
return pid;
}
-static void _name_owner_changed(GDBusProxy *proxy,
- const gchar *name, const gchar *old_owner,
- const gchar *new_owner, void *user_data)
-{
- RET_IF(NULL == name);
- RET_IF(NULL == old_owner);
- RET_IF(NULL == new_owner);
-
- if (strlen(new_owner) == 0)
- {
- if (net_nfc_server_gdbus_check_client_is_running(old_owner))
- {
- /* unregister service */
- net_nfc_server_llcp_unregister_services(old_owner);
-
- /* remove client context */
- net_nfc_server_gdbus_cleanup_client_context(old_owner);
- }
- }
-}
-
-static void _on_name_owner_changed(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- gchar *name;
- gchar *old_owner;
- gchar *new_owner;
-
- g_variant_get(parameters, "(sss)", &name, &old_owner, &new_owner);
-
- _name_owner_changed((GDBusProxy *)connection, name, old_owner, new_owner, user_data);
-}
-
-static void _subscribe_name_owner_changed_event()
-{
- RET_IF(NULL == connection);
-
- /* subscribe signal */
- subscribe_id = g_dbus_connection_signal_subscribe(connection,
- "org.freedesktop.DBus", /* bus name */
- "org.freedesktop.DBus", /* interface */
- "NameOwnerChanged", /* member */
- "/org/freedesktop/DBus", /* path */
- NULL, /* arg0 */
- G_DBUS_SIGNAL_FLAGS_NONE,
- _on_name_owner_changed,
- NULL, NULL);
-}
-
-static void _unsubscribe_name_owner_changed_event()
-{
- RET_IF(NULL == connection);
-
- /* subscribe signal */
- if (subscribe_id > 0)
- g_dbus_connection_signal_unsubscribe(connection, subscribe_id);
-}
-
-static void net_nfc_server_gdbus_init(void)
-{
- GError *error = NULL;
-
- if (connection)
- g_object_unref(connection);
-
- connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (NULL == connection)
- {
- NFC_ERR("Can not get connection %s", error->message);
- g_error_free (error);
- return;
- }
-
- net_nfc_server_gdbus_init_client_context();
-
- if (net_nfc_server_manager_init(connection) == FALSE)
- {
- NFC_ERR("Can not init manager");
- return;
- }
-
- if (net_nfc_server_tag_init(connection) == FALSE)
- {
- NFC_ERR("Can not init tag");
- return;
- }
-
- if (net_nfc_server_ndef_init(connection) == FALSE)
- {
- NFC_ERR("Can not init ndef");
- return;
- }
-
- if (net_nfc_server_llcp_init(connection) == FALSE)
- {
- NFC_ERR("Can not init llcp");
- return;
- }
-
- if (net_nfc_server_p2p_init(connection) == FALSE)
- {
- NFC_ERR("Can not init p2p");
- return;
- }
-
- if (net_nfc_server_transceive_init(connection) == FALSE)
- {
- NFC_ERR("Can not initialize transceive");
- return;
- }
-
- if (net_nfc_server_handover_init(connection) == FALSE)
- {
- NFC_ERR("Can not initialize handover");
- return;
- }
-
- if (net_nfc_server_se_init(connection) == FALSE)
- {
- NFC_ERR("Can not init se");
- return;
- }
-
- if (net_nfc_server_snep_init(connection) == FALSE)
- {
- NFC_ERR("Can not init snep");
- return;
- }
-
- if (net_nfc_server_system_handler_init(connection) == FALSE)
- {
- NFC_ERR("Can not init system handler");
- return;
- }
-
- if (net_nfc_server_phdc_init(connection) == FALSE)
- {
- NFC_ERR("Can not init phdc");
- return;
- }
-
- if (net_nfc_server_controller_thread_init() == FALSE)
- {
- NFC_ERR("Can not init controller thread");
- return;
- }
-
- _subscribe_name_owner_changed_event();
-}
-
-static void net_nfc_server_gdbus_deinit(void)
-{
- _unsubscribe_name_owner_changed_event();
-
- net_nfc_server_manager_deinit();
- net_nfc_server_tag_deinit();
- net_nfc_server_ndef_deinit();
- net_nfc_server_llcp_deinit();
- net_nfc_server_transceive_deinit();
- net_nfc_server_handover_deinit();
- net_nfc_server_se_deinit();
- net_nfc_server_snep_deinit();
- net_nfc_server_system_handler_deinit();
- net_nfc_server_phdc_deinit();
- net_nfc_server_gdbus_deinit_client_context();
-
- net_nfc_server_controller_thread_deinit();
-
- if (connection)
- {
- g_object_unref(connection);
- connection = NULL;
- }
-}
-
void net_nfc_manager_quit()
{
NFC_DBG("net_nfc_manager_quit kill the nfc-manager daemon!!");
g_main_loop_quit(loop);
}
-static void on_bus_acquired(GDBusConnection *connection, const gchar *path,
- gpointer user_data)
-{
- gint state;
-
- NFC_DBG("bus path : %s", path);
-
- net_nfc_server_gdbus_init();
-
- net_nfc_server_controller_init();
-
- if (vconf_get_bool(VCONFKEY_NFC_STATE, &state) != 0)
- {
- NFC_DBG("VCONFKEY_NFC_STATE is not exist");
- net_nfc_manager_quit();
-
- return;
- }
-
- net_nfc_server_vconf_init();
-
- if (state == 1)
- net_nfc_server_manager_set_active(TRUE);
-#ifndef ESE_ALWAYS_ON
- else if (use_daemon == TRUE)
- net_nfc_server_controller_deinit();
-#endif
-}
-
-static void on_name_acquired(GDBusConnection *connection, const gchar *name,
- gpointer user_data)
-{
- NFC_INFO("name : %s", name);
-}
-
-static void on_name_lost(GDBusConnection *connnection, const gchar *name,
- gpointer user_data)
-{
- NFC_INFO("name : %s", name);
-
- net_nfc_manager_quit();
-}
-
static void _adapter_property_changed_cb(char *name, char *property,
void *value, void *user_data)
{