Add API(ethernet cable state) 53/39953/1
authortaesub.kim <taesub.kim@samsung.com>
Wed, 27 May 2015 00:36:11 +0000 (09:36 +0900)
committertaesub.kim <taesub.kim@samsung.com>
Wed, 27 May 2015 00:36:16 +0000 (09:36 +0900)
Change-Id: Idbd0e07bdb682a790d69081f27aff24e2500a067
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
include/common/network-cm-intf.h
packaging/libnet-client.spec
src/include/network-dbus-request.h
src/include/network-internal.h
src/network-cm-intf.c
src/network-dbus-request.c [changed mode: 0755->0644]
src/network-internal.c [changed mode: 0755->0644]
src/network-profile-intf.c [changed mode: 0755->0644]
src/network-signal-handler.c

index e8d5d0d..a112d9d 100644 (file)
@@ -120,6 +120,12 @@ typedef enum
 
        /** Wi-Fi interface Scan Indication Event(WPS scan) */
        NET_EVENT_WPS_SCAN_IND,
+
+       /** Ethernet Cable Attached Event */
+       NET_EVENT_ETHERNET_CABLE_ATTACHED,
+
+       /** Ethernet Cable Detached Event */
+       NET_EVENT_ETHERNET_CABLE_DETACHED,
 } net_event_t;
 
 /**
@@ -1000,6 +1006,44 @@ int net_add_route(const char *ip_addr, const char *interface);
  ******************************************************************************************/
 int net_remove_route(const char *ip_addr, const char *interface);
 
+/*****************************************************************************************/
+/* net_get_ethernet_cable_state API function prototype
+ * int net_get_ethernet_cable_state(int *state);
+ */
+
+/**
+ * \brief  This API returns the ethernet cable status, 1 = Attached, 0 = Deatached.
+ *
+ * \param[out] state - Specifies the State of ethernet cable
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \par Important Notes:
+ *  None
+ *
+ * \par Notes :
+ *  None
+ *
+ * \warning
+ *  None
+ *
+ *
+ * \par Async Response Message:
+ *  None
+ *
+ * \return Return Type (int) \n
+ * - NET_ERR_NONE - indicating that the status of ethernet plug in/out retrieved successfully.\n
+ * - NET_ERR_INVALID_PARAM - indicating that API parameter value is invalid.\n
+ * - NET_ERR_INVALID_OPERATION - indicating that the API failed to retrieve the status of ethernet plug.\n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ *
+******************************************************************************************/
+int net_get_ethernet_cable_state(int *state);
+
 /**
  * \brief      This API is only for Connection CAPI. Don't use this.
  *
index b99a628..eaf01c4 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libnet-client
 Summary:    Network Client library (Shared library)
-Version:    0.1.77_56
+Version:    0.1.77_57
 Release:    0
 Group:      System/Network
 License:    Flora License
index 77ba4cf..94f70eb 100644 (file)
@@ -88,6 +88,7 @@ typedef struct {
 int _net_dbus_scan_request(void);
 int _net_dbus_set_bgscan_mode(net_wifi_background_scan_mode_t mode);
 int _net_dbus_get_state(char* state);
+int _net_dbus_get_ethernet_cable_state(int *state);
 int _net_dbus_set_agent_passphrase(const char *passphrase);
 int _net_dbus_set_agent_wps_pbc(void);
 int _net_dbus_set_agent_wps_pin(const char *wps_pin);
index a14c5d0..a5bc4c1 100644 (file)
@@ -112,6 +112,7 @@ extern "C" {
 #define NETCONFIG_SIGNAL_POWERON_COMPLETED     "PowerOnCompleted"
 #define NETCONFIG_SIGNAL_POWEROFF_COMPLETED    "PowerOffCompleted"
 #define NETCONFIG_SIGNAL_SPECIFIC_SCAN_DONE    "SpecificScanCompleted"
+#define NETCONFIG_SIGNAL_ETHERNET_CABLE_STATE  "EthernetCableState"
 
 #ifdef VITA_FEATURE
 #include <dlog.h>
index 6d7fd96..80b6167 100644 (file)
@@ -771,6 +771,30 @@ EXPORT_API int net_remove_route(const char *ip_addr, const char *interface)
        return Error;
 }
 
+/**
+ * @fn   EXPORT_API int net_get_ethernet_module(int *state)
+ *
+ * This function is to get ethernet plug in/out state.
+ * This is Sync API.
+ *
+ * @return       0 - on success, negative values for errors
+ * @param[in]    int *state - state of ethernet cable
+ * @param[out]   none
+ */
+EXPORT_API int net_get_ethernet_cable_state(int *state)
+{
+       __NETWORK_FUNC_ENTER__;
+       net_err_t Error = NET_ERR_NONE;
+
+       Error = _net_dbus_get_ethernet_cable_state(state);
+
+       if (Error != NET_ERR_NONE)
+               NETWORK_LOG(NETWORK_ERROR, "_net_dbus_get_ethernet_cable_state failed\n");
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 /*****************************************************************************
  *     ConnMan Wi-Fi Client Interface Async Function Definition
  *****************************************************************************/
old mode 100755 (executable)
new mode 100644 (file)
index bb1190a..663c6b9
@@ -1073,6 +1073,37 @@ int _net_dbus_get_state(char* state)
        return Error;
 }
 
+int _net_dbus_get_ethernet_cable_state(int *state)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+
+       if(state == NULL) {
+               NETWORK_LOG(NETWORK_ERROR,"Invalid Parameter\n");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
+       message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
+                       NETCONFIG_NETWORK_INTERFACE, "EthernetCableState", NULL, &Error);
+
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to get Ethernet Module State\n");
+               return Error;
+       }
+
+       g_variant_get(message, "(i)", state);
+
+       NETWORK_LOG(NETWORK_LOW, "Ethernet Cable State [%d]\n", *state);
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 static void __net_create_config_reply(GObject *source_object,
                GAsyncResult *res, gpointer user_data)
 {
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index f4e579a..8286a23 100644 (file)
@@ -28,7 +28,10 @@ static __thread net_state_type_t service_state_table[NET_DEVICE_MAX] =
                                                { NET_STATE_TYPE_UNKNOWN, };
 static __thread int net_service_error = NET_ERR_NONE;
 static __thread guint gdbus_conn_subscribe_id_connman_svc = 0;
+static __thread guint gdbus_conn_subscribe_id_connman_state = 0;
+static __thread guint gdbus_conn_subscribe_id_connman_error = 0;
 static __thread guint gdbus_conn_subscribe_id_supplicant = 0;
+static __thread guint gdbus_conn_subscribe_id_netconfig_wifi = 0;
 static __thread guint gdbus_conn_subscribe_id_netconfig = 0;
 
 static int __net_handle_wifi_power_rsp(gboolean value)
@@ -520,6 +523,39 @@ static int __net_handle_scan_done(GVariant *param)
        return NET_ERR_NONE;
 }
 
+static int __net_handle_ethernet_cable_state_rsp(GVariant *param)
+{
+       GVariantIter *iter = NULL;
+       GVariant *value = NULL;
+       const char *key = NULL;
+       const gchar *sig_value = NULL;
+
+       g_variant_get(param, "(a{sv})", &iter);
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (g_strcmp0(key, "key") == 0) {
+                       sig_value = g_variant_get_string(value, NULL);
+                       NETWORK_LOG(NETWORK_LOW, "Check Ethernet Monitor Result: %s",
+                                               sig_value);
+               }
+       }
+       g_variant_iter_free(iter);
+
+       net_event_info_t event_data;
+       if(g_strcmp0(sig_value, "ATTACHED") == 0) {
+                       event_data.Event = NET_EVENT_ETHERNET_CABLE_ATTACHED;
+                       event_data.Error = NET_ERR_NONE;
+       } else {
+                       event_data.Event = NET_EVENT_ETHERNET_CABLE_DETACHED;
+                       event_data.Error = NET_ERR_NONE;
+       }
+       event_data.Datalength = 0;
+       event_data.Data = NULL;
+
+       _net_client_callback(&event_data);
+       return NET_ERR_NONE;
+}
+
 static void __net_connman_service_signal_filter(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
@@ -565,6 +601,14 @@ static void __net_netconfig_signal_filter(GDBusConnection *conn,
                __net_handle_wifi_specific_scan_rsp(param);
 }
 
+static void __net_netconfig_network_signal_filter(GDBusConnection *conn,
+               const gchar *name, const gchar *path, const gchar *interface,
+               const gchar *sig, GVariant *param, gpointer user_data)
+{
+       if (g_strcmp0(sig, NETCONFIG_SIGNAL_ETHERNET_CABLE_STATE) == 0)
+               __net_handle_ethernet_cable_state_rsp(param);
+}
+
 /*****************************************************************************
  *     Global Functions
  *****************************************************************************/
@@ -587,6 +631,8 @@ int _net_deregister_signal(void)
        g_dbus_connection_signal_unsubscribe(connection,
                                gdbus_conn_subscribe_id_supplicant);
        g_dbus_connection_signal_unsubscribe(connection,
+                               gdbus_conn_subscribe_id_netconfig_wifi);
+       g_dbus_connection_signal_unsubscribe(connection,
                                gdbus_conn_subscribe_id_netconfig);
 
        Error = _net_dbus_close_gdbus_call();
@@ -601,6 +647,45 @@ int _net_deregister_signal(void)
        return Error;
 }
 
+int _net_subscribe_signal_wifi(void)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       GDBusConnection *connection;
+       net_err_t Error = NET_ERR_NONE;
+
+       connection = _net_dbus_get_gdbus_conn();
+       if (connection == NULL) {
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_UNKNOWN;
+       }
+
+       /* Create net-config service connection */
+       gdbus_conn_subscribe_id_netconfig_wifi = g_dbus_connection_signal_subscribe(
+                                               connection,
+                                               NETCONFIG_SERVICE,
+                                               NETCONFIG_WIFI_INTERFACE,
+                                               NULL,
+                                               NETCONFIG_WIFI_PATH,
+                                               NULL,
+                                               G_DBUS_SIGNAL_FLAGS_NONE,
+                                               __net_netconfig_signal_filter,
+                                               NULL,
+                                               NULL);
+
+       if (gdbus_conn_subscribe_id_supplicant == 0 ||
+               gdbus_conn_subscribe_id_netconfig_wifi == 0) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed register signals "
+                               "supplicant(%d), netconfig_wifi(%d)",
+                               gdbus_conn_subscribe_id_supplicant,
+                               gdbus_conn_subscribe_id_netconfig_wifi);
+               Error = NET_ERR_NOT_SUPPORTED;
+       }
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int _net_register_signal(void)
 {
        __NETWORK_FUNC_ENTER__;
@@ -659,7 +744,30 @@ int _net_register_signal(void)
                                                NULL,
                                                NULL);
 
-       NETWORK_LOG(NETWORK_LOW, "Successfully register signals\n");
+       /* Create net-config service connection for network */
+       gdbus_conn_subscribe_id_netconfig = g_dbus_connection_signal_subscribe(
+                                               connection,
+                                               NETCONFIG_SERVICE,
+                                               NETCONFIG_NETWORK_INTERFACE,
+                                               NULL,
+                                               NETCONFIG_NETWORK_PATH,
+                                               NULL,
+                                               G_DBUS_SIGNAL_FLAGS_NONE,
+                                               __net_netconfig_network_signal_filter,
+                                               NULL,
+                                               NULL);
+
+       if (gdbus_conn_subscribe_id_connman_state == 0 ||
+               gdbus_conn_subscribe_id_connman_error == 0 ||
+               gdbus_conn_subscribe_id_netconfig == 0) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed register signals "
+                               "connman_state(%d), connman_error(%d), netconfig(%d)",
+                               gdbus_conn_subscribe_id_connman_state,
+                               gdbus_conn_subscribe_id_connman_error,
+                               gdbus_conn_subscribe_id_netconfig);
+               Error = NET_ERR_NOT_SUPPORTED;
+       }
+
 
        __NETWORK_FUNC_EXIT__;
        return Error;