2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "net_nfc_debug_internal.h"
21 #include "net_nfc_util_internal.h"
22 #include "net_nfc_gdbus.h"
23 #include "net_nfc_server.h"
24 #include "net_nfc_server_common.h"
25 #include "net_nfc_server_phdc.h"
26 #include "net_nfc_server_vconf.h"
27 #include "net_nfc_server_manager.h"
28 #include "net_nfc_server_util.h"
29 #include "net_nfc_server_controller.h"
30 #include "net_nfc_server_tag.h"
31 #include "net_nfc_server_ndef.h"
32 #include "net_nfc_server_llcp.h"
33 #include "net_nfc_server_p2p.h"
34 #include "net_nfc_server_transceive.h"
35 #include "net_nfc_server_handover.h"
36 #include "net_nfc_server_se.h"
37 #include "net_nfc_server_snep.h"
38 #include "net_nfc_server_system_handler.h"
39 #include "net_nfc_server_context.h"
43 static gboolean use_daemon = FALSE;
44 static GMainLoop *loop = NULL;
46 static GDBusConnection *connection = NULL;
48 GOptionEntry option_entries[] = {
49 { "daemon", 'd', 0, G_OPTION_ARG_NONE, &use_daemon,
50 "Use Daemon mode", NULL },
54 pid_t net_nfc_server_gdbus_get_pid(const char *name)
60 _ret = g_dbus_connection_call_sync(connection,
61 "org.freedesktop.DBus",
62 "/org/freedesktop/DBus",
63 "org.freedesktop.DBus",
64 "GetConnectionUnixProcessID",
65 g_variant_new("(s)", name),
67 G_DBUS_CALL_FLAGS_NONE,
74 g_variant_get(_ret, "(u)", &pid);
75 g_variant_unref(_ret);
81 void net_nfc_manager_quit()
83 NFC_DBG("net_nfc_manager_quit kill the nfc-manager daemon!!");
86 g_main_loop_quit(loop);
89 static void _adapter_property_changed_cb(char *name, char *property,
90 void *value, void *user_data)
94 if (!g_strcmp0(property, "Powered")) {
95 if ((int *) value == 0)
100 NFC_DBG("power changed %d", powered);
101 if (vconf_set_bool(VCONFKEY_NFC_STATE, powered) != 0)
102 NFC_DBG("vconf_set_bool failed ");
106 static bool net_nfc_neard_nfc_support(void)
108 char **adapters = NULL;
109 neardal_adapter *neard_adapter = NULL;
113 NFC_INFO("checking nfc support");
114 err = neardal_get_adapters(&adapters, &len);
115 if (err != NEARDAL_SUCCESS)
118 if (!(len > 0 && adapters != NULL))
121 err = neardal_get_adapter_properties(adapters[0], &neard_adapter);
122 if (err == NEARDAL_SUCCESS && neard_adapter != NULL) {
123 if (vconf_set_bool(VCONFKEY_NFC_STATE,
124 neard_adapter->powered) != 0)
125 NFC_ERR("VCONFKEY_NFC_STATE set to %d failed",
126 neard_adapter->powered);
128 if (neardal_set_cb_adapter_property_changed(
129 _adapter_property_changed_cb, NULL) != NEARDAL_SUCCESS)
130 NFC_ERR("Failed to register property changed cb");
134 neardal_free_array(&adapters);
137 neardal_free_adapter(neard_adapter);
140 neard_adapter = NULL;
145 int main(int argc, char *argv[])
147 GError *error = NULL;
148 gboolean use_daemon = FALSE;
149 GOptionContext *option_context;
151 net_nfc_change_log_tag();
153 option_context = g_option_context_new("Nfc manager");
154 g_option_context_add_main_entries(option_context, option_entries, NULL);
156 if (g_option_context_parse(option_context, &argc, &argv, &error) == FALSE)
158 NFC_ERR("can not parse option: %s", error->message);
161 g_option_context_free(option_context);
165 NFC_DBG("start nfc manager");
166 NFC_INFO("use_daemon : %d", use_daemon);
168 net_nfc_app_util_clean_storage(MESSAGE_STORAGE);
170 if (net_nfc_neard_nfc_support() == false)
172 NFC_ERR("failed to detect NFC devices");
174 if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_OFF) != 0)
175 NFC_ERR("VCONFKEY_NFC_FEATURE set to %d failed", VCONFKEY_NFC_FEATURE_OFF);
180 if (vconf_set_bool(VCONFKEY_NFC_FEATURE, VCONFKEY_NFC_FEATURE_ON) != 0)
181 NFC_ERR("VCONFKEY_NFC_FEATURE set to %d failed", VCONFKEY_NFC_FEATURE_ON);
183 net_nfc_server_vconf_init();
185 loop = g_main_loop_new(NULL, FALSE);
186 g_main_loop_run(loop);
189 net_nfc_server_vconf_deinit();
191 g_option_context_free(option_context);