#include "net_nfc_gdbus.h"
#include "net_nfc_server.h"
#include "net_nfc_server_common.h"
+#include "net_nfc_server_phdc.h"
#include "net_nfc_server_vconf.h"
#include "net_nfc_server_manager.h"
#include "net_nfc_server_util.h"
#include "net_nfc_server_system_handler.h"
#include "net_nfc_server_context.h"
+#include "neardal.h"
+
static gboolean use_daemon = FALSE;
static GMainLoop *loop = NULL;
pid_t net_nfc_server_gdbus_get_pid(const char *name)
{
+ GVariant *_ret;
guint pid = 0;
GError *error = NULL;
- GVariant *_ret;
_ret = g_dbus_connection_call_sync(connection,
"org.freedesktop.DBus",
-1,
NULL,
&error);
- if (_ret != NULL) {
+
+ if (_ret != NULL)
+ {
g_variant_get(_ret, "(u)", &pid);
g_variant_unref(_ret);
}
const gchar *name, const gchar *old_owner,
const gchar *new_owner, void *user_data)
{
- if (name == NULL || old_owner == NULL || new_owner == NULL) {
- NFC_ERR("invalid parameter");
+ RET_IF(NULL == name);
+ RET_IF(NULL == old_owner);
+ RET_IF(NULL == new_owner);
- return;
- }
-
- if (strlen(new_owner) == 0) {
- if (net_nfc_server_gdbus_check_client_is_running(old_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);
}
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)
+ 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);
+ g_variant_get(parameters, "(sss)", &name, &old_owner, &new_owner);
- _name_owner_changed((GDBusProxy *)connection,
- name, old_owner, new_owner, user_data);
+ _name_owner_changed((GDBusProxy *)connection, name, old_owner, new_owner, user_data);
}
static void _subscribe_name_owner_changed_event()
{
- if (connection == NULL)
- return;
+ RET_IF(NULL == connection);
/* subscribe signal */
subscribe_id = g_dbus_connection_signal_subscribe(connection,
static void _unsubscribe_name_owner_changed_event()
{
- if (connection == NULL)
- return;
+ RET_IF(NULL == connection);
/* subscribe signal */
- if (subscribe_id > 0) {
+ if (subscribe_id > 0)
g_dbus_connection_signal_unsubscribe(connection, subscribe_id);
- }
}
static void net_nfc_server_gdbus_init(void)
g_object_unref(connection);
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (connection == NULL)
+ if (NULL == connection)
{
NFC_ERR("Can not get connection %s", error->message);
g_error_free (error);
if (net_nfc_server_p2p_init(connection) == FALSE)
{
- NFC_ERR("Can not init tag");
+ NFC_ERR("Can not init p2p");
return;
}
if (net_nfc_server_handover_init(connection) == FALSE)
{
- NFC_ERR("Can not initialize transceive");
+ NFC_ERR("Can not initialize handover");
return;
}
if (net_nfc_server_se_init(connection) == FALSE)
{
- NFC_ERR("Can not init Test");
+ NFC_ERR("Can not init se");
return;
}
if (net_nfc_server_snep_init(connection) == FALSE)
{
- NFC_ERR("Can not init controller thread");
+ NFC_ERR("Can not init snep");
return;
}
if (net_nfc_server_system_handler_init(connection) == FALSE)
{
- NFC_ERR("Can not init controller thread");
+ NFC_ERR("Can not init system handler");
+ return;
+ }
+
+ if (net_nfc_server_phdc_init(connection) == FALSE)
+ {
+ NFC_ERR("Can not init phdc");
return;
}
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();
net_nfc_manager_quit();
}
+static bool net_nfc_neard_nfc_support(void)
+{
+ char **adapters = NULL;
+ int len;
+ errorCode_t err;
+
+ NFC_INFO("checking nfc support");
+ err = neardal_get_adapters(&adapters, &len);
+ if (err != NEARDAL_SUCCESS)
+ return false;
+
+ if (!(len > 0 && adapters != NULL))
+ return false;
+
+ neardal_free_array(&adapters);
+ adapters = NULL;
+ neardal_destroy();
+
+ return true;
+}
int main(int argc, char *argv[])
{
-
- void *handle = NULL;
- guint id = 0;
+ GError *error = NULL;
gboolean use_daemon = FALSE;
GOptionContext *option_context;
- GError *error = NULL;
net_nfc_change_log_tag();
net_nfc_app_util_clean_storage(MESSAGE_STORAGE);
- handle = net_nfc_controller_onload();
- if (handle == NULL)
+ if (net_nfc_neard_nfc_support() == false)
{
- NFC_ERR("load plugin library is failed");
+ NFC_ERR("failed to detect NFC devices");
if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_OFF) != 0)
NFC_ERR("VCONFKEY_NFC_FEATURE set to %d failed", VCONFKEY_NFC_FEATURE_OFF);
if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON) != 0)
NFC_ERR("VCONFKEY_NFC_FEATURE set to %d failed", VCONFKEY_NFC_FEATURE_ON);
- id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- "org.tizen.NetNfcService",
- G_BUS_NAME_OWNER_FLAGS_NONE,
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- NULL,
- NULL);
+ net_nfc_server_vconf_init();
loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
EXIT :
net_nfc_server_vconf_deinit();
- net_nfc_server_controller_deinit();
- net_nfc_server_gdbus_deinit();
-
- if (id)
- g_bus_unown_name(id);
-
- net_nfc_controller_unload(handle);
g_option_context_free(option_context);
return 0;
-}
\ No newline at end of file
+}