Add api for configure discovery 84/192884/1 accepted/tizen/unified/20181114.191315 submit/tizen/20181112.101253 submit/tizen/20181114.020609 submit/tizen/20181114.021524 submit/tizen_5.0/20181112.102633
authorJihoon Jung <jh8801.jung@samsung.com>
Mon, 12 Nov 2018 08:16:59 +0000 (17:16 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Mon, 12 Nov 2018 08:17:29 +0000 (17:17 +0900)
Change-Id: I2f274ebeb922da2f0ab863c9af947560784f2707

include/net_nfc_client_manager.h
include/nfc_internal.h
src/net_nfc_client_manager.c
src/nfc_manager.c
test/nfc_unit_test.c

index 0beaf45..4d753b7 100755 (executable)
@@ -53,6 +53,8 @@ net_nfc_error_e net_nfc_client_manager_get_server_state(
 net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
                unsigned int *state);
 
+net_nfc_error_e net_nfc_client_manager_configure_discovery_sync(int mode);
+
 bool net_nfc_client_manager_is_activated(void);
 
 /* TODO : move to internal header */
index 883acb7..6ceb15e 100755 (executable)
@@ -63,6 +63,24 @@ typedef enum {
        NFC_SE_POWER_MODE_OFF = 0x02, /**< Power Off */
 } nfc_se_power_type_e;
 
+typedef enum {
+       NFC_DISCOVERY_MODE_STOP = 0x00,
+       NFC_DISCOVERY_MODE_CONFIG_POLLING = 0x01,
+       NFC_DISCOVERY_MODE_CONFIG_LISTENING = 0x02,
+       NFC_DISCOVERY_MODE_CONFIG_P2P = 0x04,
+       NFC_DISCOVERY_MODE_CONFIG_ALL = NFC_DISCOVERY_MODE_CONFIG_POLLING |
+                                       NFC_DISCOVERY_MODE_CONFIG_LISTENING |
+                                       NFC_DISCOVERY_MODE_CONFIG_P2P,
+       NFC_DISCOVERY_MODE_CONFIG_DEFAULT = NFC_DISCOVERY_MODE_CONFIG_LISTENING,
+       NFC_DISCOVERY_MODE_CONFIG = NFC_DISCOVERY_MODE_CONFIG_DEFAULT,
+        NET_NFC_DISCOVERY_MODE_START_LISTENING = NFC_DISCOVERY_MODE_CONFIG_LISTENING,
+       NFC_DISCOVERY_MODE_START_POLLING = NFC_DISCOVERY_MODE_CONFIG_POLLING,
+       NFC_DISCOVERY_MODE_START_ALL = NFC_DISCOVERY_MODE_CONFIG_ALL,
+       NFC_DISCOVERY_MODE_START_DEFAULT = NFC_DISCOVERY_MODE_CONFIG_DEFAULT,
+       NFC_DISCOVERY_MODE_START = NFC_DISCOVERY_MODE_START_DEFAULT,
+       NFC_DISCOVERY_MODE_RESUME = NFC_DISCOVERY_MODE_START
+} nfc_discovery_mode_e;
+
 /**
  * @brief The handle to the Connection Handover message
  * @ingroup CAPI_NETWORK_NFC_HANDOVER_MODULE
@@ -561,6 +579,8 @@ int nfc_se_get_conflict_handlers_internal(const char *package, nfc_card_emulatio
 
 int nfc_se_foreach_registered_handlers(nfc_card_emulation_category_type_e category, nfc_se_registered_handler_cb callback, void *user_data);
 
+int nfc_manager_configure_discovery(int mode);
+
 #ifdef __cplusplus
 }
 #endif
index 03535a3..589b4c6 100755 (executable)
@@ -372,6 +372,36 @@ net_nfc_error_e net_nfc_client_manager_get_server_state_sync(
 
 }
 
+NET_NFC_EXPORT_API
+net_nfc_error_e net_nfc_client_manager_configure_discovery_sync(int mode)
+{
+       net_nfc_error_e out_result = NET_NFC_OK;
+       GError *error = NULL;
+
+       net_nfc_client_manager_init();
+
+       if (manager_proxy == NULL)
+               return NET_NFC_NOT_INITIALIZED;
+
+       /* prevent executing daemon when nfc is off */
+       if (net_nfc_client_manager_is_activated() == false)
+               return NET_NFC_NOT_ACTIVATED;
+
+       if (net_nfc_gdbus_manager_call_configure_discovery_sync(manager_proxy,
+                                       mode,
+                                       &out_result,
+                                       NULL,
+                                       &error) == FALSE) {
+               DEBUG_ERR_MSG("can not call ConfigureDiscovery : %s", error->message);
+
+               out_result = NET_NFC_IPC_FAIL;
+
+               g_error_free(error);
+       }
+
+       return out_result;
+}
+
 net_nfc_error_e net_nfc_client_manager_init(void)
 {
        GError *error = NULL;
index 5ccff0a..be30f8d 100644 (file)
@@ -96,6 +96,24 @@ int nfc_manager_set_activation(bool activation,
        /* LCOV_EXCL_STOP */
 }
 
+int nfc_manager_configure_discovery(int mode)
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       CHECK_SUPPORTED(NFC_FEATURE);
+
+       /* LCOV_EXCL_START */
+       CHECK_INIT();
+       CHECK_ACTIVATED();
+
+       ret = net_nfc_client_manager_configure_discovery_sync(mode);
+
+       return nfc_common_convert_error_code(__func__, ret);
+       /* LCOV_EXCL_STOP */
+}
+
 bool nfc_manager_is_activated(void)
 {
        int ret;
index 4c7609b..fbfef69 100755 (executable)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 
 #include <nfc.h>
+#include <nfc_internal.h>
 
 #define BUFFER_LEN 10
 #define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
@@ -20,9 +21,13 @@ typedef struct {
 tc_table_t tc_table[] = {
        /* manage api*/
        {"NFC Initialize Test", 1},
-       {"NFC Tag NDEF Read", 2},
-       {"NFC Tag NDEF Write", 3},
-       {"NFC Deinitialize Test", 4},
+       {"NFC Configure discovery (CE only) Test", 2},
+       {"NFC Configure discovery (Tag only) Test", 3},
+       {"NFC Tag NDEF Read", 4},
+       {"NFC Tag NDEF Write", 5},
+       {"NFC Deinitialize Test", 6},
+       {"NFC Configure discovery (ALL enable) Test", 7},
+       {"NFC Configure discovery (ALL disable) Test", 8},
 
        /* -----------*/
        {"Finish"               , 0x00ff},
@@ -169,6 +174,20 @@ int test_input_callback(void *data)
                break;
        case 2:
                {
+                       TC_PRT("nfc configure discovery : CE only start");
+                       ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_CONFIG_LISTENING);
+                       TC_PRT("nfc configure discovery : CE only end : %d", ret);
+               }
+               break;
+       case 3:
+               {
+                       TC_PRT("nfc configure discovery : Tag only start");
+                       ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_CONFIG_POLLING);
+                       TC_PRT("nfc configure discovery : Tag only end : %d", ret);
+               }
+               break;
+       case 4:
+               {
                        TC_PRT("Tag read start");
                        nfc_tag_h current_tag = NULL;
                        nfc_manager_get_connected_tag(&current_tag);
@@ -181,7 +200,7 @@ int test_input_callback(void *data)
                        TC_PRT("Tag read end");
                }
                break;
-       case 3:
+       case 5:
                {
                        TC_PRT("Tag write start");
 
@@ -201,7 +220,7 @@ int test_input_callback(void *data)
                        TC_PRT("Tag write end");
                }
                break;
-       case 4:
+       case 6:
                {
                        TC_PRT("nfc deinitialize start");
 
@@ -214,6 +233,20 @@ int test_input_callback(void *data)
                        TC_PRT("nfc deinitialize end");
                }
                break;
+       case 7:
+               {
+                       TC_PRT("nfc configure discovery : All enable start");
+                       ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_RESUME);
+                       TC_PRT("nfc configure discovery : All enable end : %d", ret);
+               }
+               break;
+       case 8:
+               {
+                       TC_PRT("nfc configure discovery : All disable start");
+                       ret = nfc_manager_configure_discovery(NFC_DISCOVERY_MODE_STOP);
+                       TC_PRT("nfc configure discovery : All enable end : %d", ret);
+               }
+               break;
        default:
                tc_usage_print();
                break;