Move DBus introspection into init function 83/194783/1
authorYu <jiung.yu@samsung.com>
Fri, 7 Dec 2018 07:02:03 +0000 (16:02 +0900)
committerYu <jiung.yu@samsung.com>
Fri, 7 Dec 2018 07:17:40 +0000 (16:17 +0900)
Description: It's hard to match introspection and
related handler function if it is placed far from
function codes. So, I moved it into initialize function.

Change-Id: Ia693c31cd0530f4de272d7c1edb4f7c8adcb02f4
Signed-off-by: Yu Jiung <jiung.yu@samsung.com>
src/inm-gdbus.c

index 002e0fb1be99c62d912fb0b0e55a17861b4725f2..ae7cb1bdb3c096371f735a0cc92e32a0da9c2699 100644 (file)
@@ -111,157 +111,6 @@ typedef enum {
        CONNECTED,
 } tech_state_e;
 
-static const gchar inm_manager_introspection_xml[] = {
-               "<node>"
-               "<interface name='net.inm_manager'>"
-               "<method name='GetStatistics'>"
-               "<arg type='i' name='connection_type' direction='in'/>"
-               "<arg type='i' name='statistics_type' direction='in'/>"
-               "<arg type='t' name='val' direction='out'/>"
-               "</method>"
-               "<method name='ResetStatistics'>"
-               "<arg type='i' name='connection_type' direction='in'/>"
-               "<arg type='i' name='statistics_type' direction='in'/>"
-               "</method>"
-               "<method name='GetCurrentConnection'>"
-               "<arg type='o' name='object_path' direction='out'/>"
-               "<arg type='a{sv}' name='connection' direction='out'/>"
-               "</method>"
-               "<method name='GetConnections'>"
-               "<arg type='a(oa{sv})' name='connections' direction='out'/>"
-               "</method>"
-               "<method name='GetEthernetCableState'>"
-                       "<arg type='b' name='ethernet_cable_state' direction='out'/>"
-                       "</method>"
-               "<method name='GetWifiModuleState'>"
-                       "<arg type='b' name='wifi_module_state' direction='out'/>"
-                       "</method>"
-               "<method name='GetIpConflictState'>"
-                       "<arg type='b' name='ip_conflict_state' direction='out'/>"
-                       "</method>"
-               "<method name='GetIpConflictDetect'>"
-                       "<arg type='b' name='ip_conflict_detect' direction='out'/>"
-                       "</method>"
-               "<method name='SetIpConflictDetect'>"
-                       "<arg type='b' name='ip_conflict_detect' direction='in'/>"
-                       "</method>"
-               "<method name='GetTcpdumpState'>"
-                       "<arg type='b' name='tcpdump_state' direction='out'/>"
-                       "</method>"
-               "<method name='SetTcpdumpState'>"
-                       "<arg type='b' name='tcpdump_state' direction='in'/>"
-                       "</method>"
-               "<method name='GetCellularState'>"
-                       "<arg type='i' name='cellular_state' direction='out'/>"
-                       "</method>"
-               "<method name='GetWifiState'>"
-                       "<arg type='i' name='wifi_state' direction='out'/>"
-                       "</method>"
-               "<method name='GetEthernetState'>"
-                       "<arg type='i' name='ethernet_state' direction='out'/>"
-                       "</method>"
-               "<method name='GetCongestionLevel'>"
-                       "<arg type='i' name='congestion_level' direction='out'/>"
-                       "</method>"
-               "<method name='GetRetryTxRate'>"
-                       "<arg type='i' name='retry_tx_rate' direction='out'/>"
-                       "</method>"
-               "<method name='GetChannelInterference'>"
-                       "<arg type='d' name='channel_interference' direction='out'/>"
-                       "</method>"
-               "<method name='StartArping'>"
-                       "<arg type='s' name='target_ip' direction='in'/>"
-                       "<arg type='i' name='timeout' direction='in'/>"
-                       "</method>"
-               "<method name='StopArping'>"
-                       "<arg type='s' name='target_ip' direction='in'/>"
-                       "</method>"
-               "<method name='StartCheckGateway'>"
-                       "</method>"
-               "<method name='StopCheckGateway'>"
-                       "</method>"
-               "<method name='AddReacherUrl'>"
-                       "<arg type='s' name='url' direction='in'/>"
-                       "</method>"
-               "<method name='RemoveReacherUrl'>"
-                       "<arg type='s' name='url' direction='in'/>"
-                       "</method>"
-               "<method name='StartReacher'>"
-                       "<arg type='i' name='type' direction='in'/>"
-                       "</method>"
-               "<method name='StopReacher'>"
-                       "<arg type='i' name='type' direction='in'/>"
-                       "</method>"
-               "<method name='ReacherIsRunning'>"
-                       "<arg type='b' name='is_running' direction='out'/>"
-                       "</method>"
-               "<signal name='IpConflicted'>"
-               "</signal>"
-               "<signal name='ConnectionsChanged'>"
-               "<arg type='aoao' name='connections'/>"
-               "</signal>"
-               "<signal name='ArpingResult'>"
-               "<arg type='a{sv}' name='ArpingInfo'/>"
-               "</signal>"
-               "<signal name='CheckGatewayResult'>"
-               "<arg type='a{sv}' name='CheckGatewayInfo'/>"
-               "</signal>"
-               "<signal name='ReachingResult'>"
-               "<arg type='a{sv}' name='ReachingInfo'/>"
-               "</signal>"
-               "</interface>"
-               "</node>"
-};
-
-static const gchar inm_wifi_introspection_xml[] = {
-       "<node>"
-               "<interface name='net.inm_manager.wifi'>"
-                       "<method name='GetScanState'>"
-                               "<arg type='b' name='scan_state' direction='out'/>"
-                       "</method>"
-               "</interface>"
-       "</node>"
-};
-
-
-static const gchar inm_conn_introspection_xml[] = {
-       "<node>"
-               "<interface name='net.inm_manager.conn'>"
-                       "<method name='GetAll'>"
-                       "<arg type='a{sv}' name='connection' direction='out'/>"
-                       "</method>"
-                       "<property type='s' name='Id' access='read'/>"
-                       "<property type='s' name='Name' access='read'/>"
-                       "<property type='s' name='Type' access='read'/>"
-                       "<property type='s' name='IfaceName' access='read'/>"
-                       "<property type='s' name='Ipv4State' access='read'/>"
-                       "<property type='s' name='Ipv6State' access='read'/>"
-                       "<property type='a{sv}' name='Ip' access='read'/>"
-                       "<property type='a{sv}' name='Dns' access='read'/>"
-                       "<property type='s' name='Essid' access='read'/>"
-                       "<property type='s' name='RawSsid' access='read'/>"
-                       "<property type='s' name='Bssid' access='read'/>"
-                       "<property type='i' name='Rssi' access='read'/>"
-                       "<property type='i' name='Frequency' access='read'/>"
-                       "<property type='i' name='MaxSpeed' access='read'/>"
-                       "<property type='b' name='Favorite' access='read'/>"
-                       "<property type='b' name='Passpoint' access='read'/>"
-                       "<property type='s' name='SecurityType' access='read'/>"
-                       "<property type='s' name='EncryptionType' access='read'/>"
-                       "<property type='b' name='PassphraseRequired' access='read'/>"
-                       "<property type='b' name='WpsSupported' access='read'/>"
-                       "<property type='s' name='EapPassphrase' access='read'/>"
-                       "<property type='s' name='EapCaCert' access='read'/>"
-                       "<property type='s' name='EapClientCert' access='read'/>"
-                       "<property type='s' name='EapPrivateKey' access='read'/>"
-                       "<property type='s' name='EapType' access='read'/>"
-                       "<property type='s' name='EapAuthType' access='read'/>"
-                       "<property type='s' name='DisconnectReason' access='read'/>"
-                       "<property type='s' name='AssocStatus' access='read'/>"
-                       "<property type='s' name='Vsie' access='read'/>"
-               "</interface>"
-       "</node>"
-};
 
 static gdbus_mon_s *g_p_gdbus_mon = NULL;
 
@@ -1683,6 +1532,151 @@ void inm_gdbus_emit_connections_changed(GVariant *signal_args)
        __INM_FUNC_EXIT__;
 }
 
+
+
+static void __init_daemon_introspection()
+{
+       const gchar inm_manager_introspection_xml[] = {
+                       "<node>"
+                       "<interface name='net.inm_manager'>"
+                       "<method name='GetStatistics'>"
+                       "<arg type='i' name='connection_type' direction='in'/>"
+                       "<arg type='i' name='statistics_type' direction='in'/>"
+                       "<arg type='t' name='val' direction='out'/>"
+                       "</method>"
+                       "<method name='ResetStatistics'>"
+                       "<arg type='i' name='connection_type' direction='in'/>"
+                       "<arg type='i' name='statistics_type' direction='in'/>"
+                       "</method>"
+                       "<method name='GetCurrentConnection'>"
+                       "<arg type='o' name='object_path' direction='out'/>"
+                       "<arg type='a{sv}' name='connection' direction='out'/>"
+                       "</method>"
+                       "<method name='GetConnections'>"
+                       "<arg type='a(oa{sv})' name='connections' direction='out'/>"
+                       "</method>"
+                       "<method name='GetEthernetCableState'>"
+                               "<arg type='b' name='ethernet_cable_state' direction='out'/>"
+                               "</method>"
+                       "<method name='GetWifiModuleState'>"
+                               "<arg type='b' name='wifi_module_state' direction='out'/>"
+                               "</method>"
+                       "<method name='GetIpConflictState'>"
+                               "<arg type='b' name='ip_conflict_state' direction='out'/>"
+                               "</method>"
+                       "<method name='GetIpConflictDetect'>"
+                               "<arg type='b' name='ip_conflict_detect' direction='out'/>"
+                               "</method>"
+                       "<method name='SetIpConflictDetect'>"
+                               "<arg type='b' name='ip_conflict_detect' direction='in'/>"
+                               "</method>"
+                       "<method name='GetTcpdumpState'>"
+                               "<arg type='b' name='tcpdump_state' direction='out'/>"
+                               "</method>"
+                       "<method name='SetTcpdumpState'>"
+                               "<arg type='b' name='tcpdump_state' direction='in'/>"
+                               "</method>"
+                       "<method name='GetCellularState'>"
+                               "<arg type='i' name='cellular_state' direction='out'/>"
+                               "</method>"
+                       "<method name='GetWifiState'>"
+                               "<arg type='i' name='wifi_state' direction='out'/>"
+                               "</method>"
+                       "<method name='GetEthernetState'>"
+                               "<arg type='i' name='ethernet_state' direction='out'/>"
+                               "</method>"
+                       "<method name='GetCongestionLevel'>"
+                               "<arg type='i' name='congestion_level' direction='out'/>"
+                               "</method>"
+                       "<method name='GetRetryTxRate'>"
+                               "<arg type='i' name='retry_tx_rate' direction='out'/>"
+                               "</method>"
+                       "<method name='GetChannelInterference'>"
+                               "<arg type='d' name='channel_interference' direction='out'/>"
+                               "</method>"
+                       "<method name='StartArping'>"
+                               "<arg type='s' name='target_ip' direction='in'/>"
+                               "<arg type='i' name='timeout' direction='in'/>"
+                               "</method>"
+                       "<method name='StopArping'>"
+                               "<arg type='s' name='target_ip' direction='in'/>"
+                               "</method>"
+                       "<method name='StartCheckGateway'>"
+                               "</method>"
+                       "<method name='StopCheckGateway'>"
+                               "</method>"
+                       "<method name='AddReacherUrl'>"
+                               "<arg type='s' name='url' direction='in'/>"
+                               "</method>"
+                       "<method name='RemoveReacherUrl'>"
+                               "<arg type='s' name='url' direction='in'/>"
+                               "</method>"
+                       "<method name='StartReacher'>"
+                               "<arg type='i' name='type' direction='in'/>"
+                               "</method>"
+                       "<method name='StopReacher'>"
+                               "<arg type='i' name='type' direction='in'/>"
+                               "</method>"
+                       "<method name='ReacherIsRunning'>"
+                               "<arg type='b' name='is_running' direction='out'/>"
+                               "</method>"
+                       "<signal name='IpConflicted'>"
+                       "</signal>"
+                       "<signal name='ConnectionsChanged'>"
+                       "<arg type='aoao' name='connections'/>"
+                       "</signal>"
+                       "<signal name='ArpingResult'>"
+                       "<arg type='a{sv}' name='ArpingInfo'/>"
+                       "</signal>"
+                       "<signal name='CheckGatewayResult'>"
+                       "<arg type='a{sv}' name='CheckGatewayInfo'/>"
+                       "</signal>"
+                       "<signal name='ReachingResult'>"
+                       "<arg type='a{sv}' name='ReachingInfo'/>"
+                       "</signal>"
+                       "</interface>"
+                       "</node>"
+       };
+
+       g_p_gdbus_mon->daemon_introspection =
+                       g_dbus_node_info_new_for_xml(inm_manager_introspection_xml, NULL);
+}
+
+
+static inline void __handle_conn_get_all(gpointer user_data,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation)
+{
+       GVariant *arg = NULL;
+       int ret = 0;
+
+       __INM_FUNC_ENTER__;
+       ret = inm_connman_get_connection(user_data, &arg);
+       if (ret != 0) {
+               INM_LOGE("Failed to get connection");
+               __dbus_return_err(INM_MANAGER_ERROR_OPERATION_FAILED, invocation);
+               __INM_FUNC_EXIT__;
+               return;
+       }
+
+       g_dbus_method_invocation_return_value(invocation, arg);
+       __INM_FUNC_EXIT__;
+
+}
+
+static void __conn_method_call(GDBusConnection *connection,
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       if (g_strcmp0(method_name, "GetAll") == 0)
+               __handle_conn_get_all(user_data, parameters, invocation);
+}
+
 static inline void __emit_conn_signal(const gchar *property,
                gchar *path,
                GVariant *signal_args)
@@ -1744,6 +1738,51 @@ void inm_gdbus_emit_conn_dns_changed(gchar *path, GVariant *signal_args)
        __emit_conn_signal("Dns", path, signal_args);
 }
 
+static void __init_conn_introspection()
+{
+       const gchar inm_conn_introspection_xml[] = {
+               "<node>"
+                       "<interface name='net.inm_manager.conn'>"
+                               "<method name='GetAll'>"
+                               "<arg type='a{sv}' name='connection' direction='out'/>"
+                               "</method>"
+                               "<property type='s' name='Id' access='read'/>"
+                               "<property type='s' name='Name' access='read'/>"
+                               "<property type='s' name='Type' access='read'/>"
+                               "<property type='s' name='IfaceName' access='read'/>"
+                               "<property type='s' name='Ipv4State' access='read'/>"
+                               "<property type='s' name='Ipv6State' access='read'/>"
+                               "<property type='a{sv}' name='Ip' access='read'/>"
+                               "<property type='a{sv}' name='Dns' access='read'/>"
+                               "<property type='s' name='Essid' access='read'/>"
+                               "<property type='s' name='RawSsid' access='read'/>"
+                               "<property type='s' name='Bssid' access='read'/>"
+                               "<property type='i' name='Rssi' access='read'/>"
+                               "<property type='i' name='Frequency' access='read'/>"
+                               "<property type='i' name='MaxSpeed' access='read'/>"
+                               "<property type='b' name='Favorite' access='read'/>"
+                               "<property type='b' name='Passpoint' access='read'/>"
+                               "<property type='s' name='SecurityType' access='read'/>"
+                               "<property type='s' name='EncryptionType' access='read'/>"
+                               "<property type='b' name='PassphraseRequired' access='read'/>"
+                               "<property type='b' name='WpsSupported' access='read'/>"
+                               "<property type='s' name='EapPassphrase' access='read'/>"
+                               "<property type='s' name='EapCaCert' access='read'/>"
+                               "<property type='s' name='EapClientCert' access='read'/>"
+                               "<property type='s' name='EapPrivateKey' access='read'/>"
+                               "<property type='s' name='EapType' access='read'/>"
+                               "<property type='s' name='EapAuthType' access='read'/>"
+                               "<property type='s' name='DisconnectReason' access='read'/>"
+                               "<property type='s' name='AssocStatus' access='read'/>"
+                               "<property type='s' name='Vsie' access='read'/>"
+                       "</interface>"
+               "</node>"
+       };
+
+       g_p_gdbus_mon->conn_introspection =
+                       g_dbus_node_info_new_for_xml(inm_conn_introspection_xml, NULL);
+}
+
 void inm_gdbus_emit_wifi_scanning_changed(gboolean scanning)
 {
        GError *error = NULL;
@@ -1817,38 +1856,19 @@ static void __wifi_method_call(GDBusConnection *connection,
                __handle_get_scan_state(parameters, invocation);
 }
 
-static inline void __handle_conn_get_all(gpointer user_data,
-               GVariant *parameters,
-               GDBusMethodInvocation *invocation)
+static void __init_wifi_introspection()
 {
-       GVariant *arg = NULL;
-       int ret = 0;
-
-       __INM_FUNC_ENTER__;
-       ret = inm_connman_get_connection(user_data, &arg);
-       if (ret != 0) {
-               INM_LOGE("Failed to get connection");
-               __dbus_return_err(INM_MANAGER_ERROR_OPERATION_FAILED, invocation);
-               __INM_FUNC_EXIT__;
-               return;
-       }
-
-       g_dbus_method_invocation_return_value(invocation, arg);
-       __INM_FUNC_EXIT__;
-
-}
-
-static void __conn_method_call(GDBusConnection *connection,
-               const gchar *sender,
-               const gchar *object_path,
-               const gchar *interface_name,
-               const gchar *method_name,
-               GVariant *parameters,
-               GDBusMethodInvocation *invocation,
-               gpointer user_data)
-{
-       if (g_strcmp0(method_name, "GetAll") == 0)
-               __handle_conn_get_all(user_data, parameters, invocation);
+       const gchar inm_wifi_introspection_xml[] = {
+               "<node>"
+                       "<interface name='net.inm_manager.wifi'>"
+                               "<method name='GetScanState'>"
+                                       "<arg type='b' name='scan_state' direction='out'/>"
+                               "</method>"
+                       "</interface>"
+               "</node>"
+       };
+       g_p_gdbus_mon->wifi_introspection =
+                       g_dbus_node_info_new_for_xml(inm_wifi_introspection_xml, NULL);
 }
 
 GDBusInterfaceVTable __daemon_iface_vtbl = {
@@ -1967,6 +1987,64 @@ int inm_gdbus_register_wifi_iface()
        return 0;
 }
 
+static inline int __init_introspection()
+{
+
+       __init_daemon_introspection();
+       if (!g_p_gdbus_mon->daemon_introspection) {
+               INM_LOGE("No daemon introspection\n");
+               return -1;
+       }
+
+       __init_wifi_introspection();
+       if (!g_p_gdbus_mon->wifi_introspection) {
+               INM_LOGE("No wifi introspection\n");
+               if (g_p_gdbus_mon->daemon_introspection) {
+                       g_dbus_node_info_unref(g_p_gdbus_mon->daemon_introspection);
+                       g_p_gdbus_mon->daemon_introspection = NULL;
+               }
+               return -1;
+       }
+
+       __init_conn_introspection();
+       if (!g_p_gdbus_mon->conn_introspection) {
+               INM_LOGE("No conn introspection\n");
+               if (g_p_gdbus_mon->daemon_introspection) {
+                       g_dbus_node_info_unref(g_p_gdbus_mon->daemon_introspection);
+                       g_p_gdbus_mon->daemon_introspection = NULL;
+               }
+
+               if (g_p_gdbus_mon->wifi_introspection) {
+                       g_dbus_node_info_unref(g_p_gdbus_mon->wifi_introspection);
+                       g_p_gdbus_mon->wifi_introspection = NULL;
+               }
+               return -1;
+       }
+
+       return 0;
+}
+
+void __deinit_introspection()
+{
+       if (!g_p_gdbus_mon)
+               return;
+
+       if (g_p_gdbus_mon->daemon_introspection)
+               g_dbus_node_info_unref(g_p_gdbus_mon->daemon_introspection);
+
+       if (g_p_gdbus_mon->wifi_introspection)
+               g_dbus_node_info_unref(g_p_gdbus_mon->wifi_introspection);
+
+       if (g_p_gdbus_mon->conn_introspection)
+               g_dbus_node_info_unref(g_p_gdbus_mon->conn_introspection);
+
+       g_p_gdbus_mon->daemon_introspection = NULL;
+       g_p_gdbus_mon->wifi_introspection = NULL;
+       g_p_gdbus_mon->conn_introspection = NULL;
+}
+
+
+
 int inm_gdbus_ping(gchar *bus_name, gchar *object_name)
 {
        GVariant *reply = NULL;
@@ -2466,6 +2544,7 @@ int inm_gdbus_unset_stc_manager_bus_watching_callback()
        return 0;
 }
 
+
 static void __on_bus_acquired(GDBusConnection *connection,
                const gchar *name,
                gpointer user_data)
@@ -2503,70 +2582,6 @@ static void __on_name_lost(GDBusConnection *connection,
                g_p_gdbus_mon->name_lost_cb();
 }
 
-int __init_introspection()
-{
-       if (!g_p_gdbus_mon)
-               return - 1;
-
-       g_p_gdbus_mon->daemon_introspection =
-                       g_dbus_node_info_new_for_xml(inm_manager_introspection_xml, NULL);
-
-       if (!g_p_gdbus_mon->daemon_introspection) {
-               INM_LOGE("No daemon introspection\n");
-               return -1;
-       }
-
-       g_p_gdbus_mon->wifi_introspection =
-                       g_dbus_node_info_new_for_xml(inm_wifi_introspection_xml, NULL);
-
-       if (!g_p_gdbus_mon->wifi_introspection) {
-               INM_LOGE("No wifi introspection\n");
-               if (g_p_gdbus_mon->daemon_introspection) {
-                       g_dbus_node_info_unref(g_p_gdbus_mon->daemon_introspection);
-                       g_p_gdbus_mon->daemon_introspection = NULL;
-               }
-               return -1;
-       }
-
-       g_p_gdbus_mon->conn_introspection =
-                       g_dbus_node_info_new_for_xml(inm_conn_introspection_xml, NULL);
-
-       if (!g_p_gdbus_mon->conn_introspection) {
-               INM_LOGE("No conn introspection\n");
-               if (g_p_gdbus_mon->daemon_introspection) {
-                       g_dbus_node_info_unref(g_p_gdbus_mon->daemon_introspection);
-                       g_p_gdbus_mon->daemon_introspection = NULL;
-               }
-
-               if (g_p_gdbus_mon->wifi_introspection) {
-                       g_dbus_node_info_unref(g_p_gdbus_mon->wifi_introspection);
-                       g_p_gdbus_mon->wifi_introspection = NULL;
-               }
-               return -1;
-       }
-
-       return 0;
-}
-
-void __deinit_introspection()
-{
-       if (!g_p_gdbus_mon)
-               return;
-
-       if (g_p_gdbus_mon->daemon_introspection)
-               g_dbus_node_info_unref(g_p_gdbus_mon->daemon_introspection);
-
-       if (g_p_gdbus_mon->wifi_introspection)
-               g_dbus_node_info_unref(g_p_gdbus_mon->wifi_introspection);
-
-       if (g_p_gdbus_mon->conn_introspection)
-               g_dbus_node_info_unref(g_p_gdbus_mon->conn_introspection);
-
-       g_p_gdbus_mon->daemon_introspection = NULL;
-       g_p_gdbus_mon->wifi_introspection = NULL;
-       g_p_gdbus_mon->conn_introspection = NULL;
-}
-
 int inm_gdbus_init(bus_aquired_callback bus_acquired_cb,
                                  name_lost_callback name_lost_cb)
 {