Add support for port related operations 35/91035/1
authorYu Jiung <jiung.yu@samsung.com>
Wed, 5 Oct 2016 10:38:08 +0000 (19:38 +0900)
committerYu Jiung <jiung.yu@samsung.com>
Wed, 5 Oct 2016 10:38:17 +0000 (19:38 +0900)
Change-Id: Ib76d164240374015a0567b98e30d5350a7464cd9
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
interfaces/aspmanager-iface-session.xml
packaging/asp-manager.spec
src/CMakeLists.txt
src/asp-manager-gdbus.c
src/session/asp-session-peer.c
src/session/asp-session.c
src/session/gfsm.c

index 9390d9f..1165e83 100755 (executable)
                        <arg type='u' name='session_id' direction='in'/>
                        <arg type='i' name='error_code' direction='out'/>
                </method>
+               <method name='BoundPort'>
+                       <arg type='a{sv}' name='parameters' direction='in'/>
+                       <arg type='i' name='error_code' direction='out'/>
+               </method>
+               <method name='ReleasePort'>
+                       <arg type='a{sv}' name='parameters' direction='in'/>
+                       <arg type='i' name='error_code' direction='out'/>
+               </method>
 
                <signal name='SessionRequest'>
                        <arg type='a{sv}' name='parameters'/>
index 9dafbd7..36f9579 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       asp-manager
 Summary:    ASP(application service platform) manager
-Version:    0.0.10
+Version:    0.0.11
 Release:    2
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
@@ -64,4 +64,4 @@ cp asp-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/asp-manager.conf
 
 #DBus DAC
 %attr(644,root,root) %{_sysconfdir}/dbus-1/system.d/*
-%attr(644,-,-) %{_datadir}/dbus-1/system-services/*.service 
+%attr(644,-,-) %{_datadir}/dbus-1/system-services/*.service
index a486649..052c8f2 100755 (executable)
@@ -4,11 +4,11 @@ SET(PACKAGE ${PROJECT_NAME})
 SET(INTERFACES "${CMAKE_SOURCE_DIR}/interfaces")
 
 INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(asp_pkgs REQUIRED 
-       glib-2.0 
-       gio-2.0 
+PKG_CHECK_MODULES(asp_pkgs REQUIRED
+       glib-2.0
+       gio-2.0
        gio-unix-2.0
-       dlog 
+       dlog
        nsd-dns-sd
        capi-network-wifi
        vconf
@@ -48,7 +48,7 @@ ADD_CUSTOM_COMMAND(
                        --c-namespace Asp
                        --c-generate-object-manager
                        --generate-docbook generated-code-docs
-                       ${INTERFACES}/aspmanager-iface-service.xml ${INTERFACES}/aspmanager-iface-session.xml 
+                       ${INTERFACES}/aspmanager-iface-service.xml ${INTERFACES}/aspmanager-iface-session.xml
                        COMMENT "Generating GDBus .c/.h")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS} ${SERVICE_SRCS} ${SESSION_SRCS} ${TECH_SRCS} ${CMAKE_SOURCE_DIR}/src/generated-code.c)
index 874a573..94e65d6 100755 (executable)
@@ -765,6 +765,148 @@ out:
        return TRUE;
 }
 
+static gboolean __asp_manager_gdbus_bound_port(AspSession *object,
+               GDBusMethodInvocation *invocation,
+               GVariant *parameters,
+               const gboolean *user_data)
+{
+       __ASP_LOG_FUNC_ENTER__;
+       GVariantIter *iter = NULL;
+       gchar *key = NULL;
+       GVariant *var = NULL;
+       asp_s *asp = NULL;
+
+       const gchar *session_mac = NULL;
+       guint32 session_id = 0;
+       const gchar *ip_address = NULL;
+       gint32 port = 0;
+       gint32 proto = 0;
+       guint8 mac_addr[MAC_LEN] = {0,};
+       gboolean res;
+
+       asp = (asp_s *)user_data;
+       if (!asp) {
+               ASP_LOGE("Failed to get memory for asp structure");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_OPERATION_FAILED);
+               goto out;
+       }
+       DEBUG_PARAMS(parameters);
+
+       g_variant_get(parameters, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
+               if (!g_strcmp0(key, "session_mac"))
+                       g_variant_get(var, "&s", &session_mac);
+               else if (!g_strcmp0(key, "session_id"))
+                       g_variant_get(var, "u", &session_id);
+               else if (!g_strcmp0(key, "ip_address"))
+                       g_variant_get(var, "&s", &ip_address);
+               else if (!g_strcmp0(key, "port"))
+                       g_variant_get(var, "i", &port);
+               else if (!g_strcmp0(key, "proto"))
+                       g_variant_get(var, "i", &proto);
+               else
+                       ;/* Do Nothing */
+       }
+
+       if (session_mac == NULL) {
+               ASP_LOGE("Invalid parameter");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_INVALIED_PARAMS);
+               goto out;
+       }
+
+       if (strlen(session_mac) != 17) {
+               ASP_LOGE("Invalid parameter");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_INVALIED_PARAMS);
+               goto out;
+       }
+       ASP_LOGD("session ID [%u] session mac [%s]", session_id, session_mac);
+
+       macaddr_atoe(session_mac, mac_addr);
+       res = asp_session_bound_port(mac_addr, session_id, ip_address,
+                       port, proto);
+       if (!res) {
+               ASP_LOGE("Operation Failed");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_OPERATION_FAILED);
+               goto out;
+       }
+
+       asp_session_complete_bound_port(object, invocation, ASP_ERROR_NONE);
+
+out:
+       __ASP_LOG_FUNC_EXIT__;
+       return TRUE;
+}
+
+static gboolean __asp_manager_gdbus_release_port(AspSession *object,
+               GDBusMethodInvocation *invocation,
+               GVariant *parameters,
+               const gboolean *user_data)
+{
+       __ASP_LOG_FUNC_ENTER__;
+       GVariantIter *iter = NULL;
+       gchar *key = NULL;
+       GVariant *var = NULL;
+       asp_s *asp = NULL;
+
+       const gchar *session_mac = NULL;
+       guint32 session_id = 0;
+       const gchar *ip_address = NULL;
+       gint32 port = 0;
+       gint32 proto = 0;
+       guint8 mac_addr[MAC_LEN] = {0,};
+       gboolean res = TRUE;
+
+       asp = (asp_s *)user_data;
+       if (!asp) {
+               ASP_LOGE("Failed to get memory for asp structure");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_OPERATION_FAILED);
+               goto out;
+       }
+       DEBUG_PARAMS(parameters);
+
+       g_variant_get(parameters, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
+               if (!g_strcmp0(key, "session_mac"))
+                       g_variant_get(var, "&s", &session_mac);
+               else if (!g_strcmp0(key, "session_id"))
+                       g_variant_get(var, "u", &session_id);
+               else if (!g_strcmp0(key, "ip_address"))
+                       g_variant_get(var, "&s", &ip_address);
+               else if (!g_strcmp0(key, "port"))
+                       g_variant_get(var, "i", &port);
+               else if (!g_strcmp0(key, "proto"))
+                       g_variant_get(var, "i", &proto);
+               else
+                       ;/* Do Nothing */
+       }
+
+       if (session_mac == NULL) {
+               ASP_LOGE("Invalid parameter");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_INVALIED_PARAMS);
+               goto out;
+       }
+
+       if (strlen(session_mac) != 17) {
+               ASP_LOGE("Invalid parameter");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_INVALIED_PARAMS);
+               goto out;
+       }
+       ASP_LOGD("session ID [%u] session mac [%s]", session_id, session_mac);
+
+       macaddr_atoe(session_mac, mac_addr);
+       if (!res) {
+               ASP_LOGE("Operation Failed");
+               ASP_RETURN_SESSION_ERR(invocation, -ASP_ERROR_OPERATION_FAILED);
+               goto out;
+       }
+
+       asp_session_complete_release_port(object, invocation, ASP_ERROR_NONE);
+
+out:
+       __ASP_LOG_FUNC_EXIT__;
+       return TRUE;
+}
+
 static gboolean __asp_manager_gdbus_session_init(asp_s *asp)
 {
        __ASP_LOG_FUNC_ENTER__;
@@ -819,6 +961,18 @@ static gboolean __asp_manager_gdbus_session_init(asp_s *asp)
                        G_CALLBACK(__asp_manager_gdbus_close_session),
                        asp);
 
+       g_signal_connect(
+                       session,
+                       "handle-bound-port",
+                       G_CALLBACK(__asp_manager_gdbus_bound_port),
+                       asp);
+
+       g_signal_connect(
+                       session,
+                       "handle-release-port",
+                       G_CALLBACK(__asp_manager_gdbus_release_port),
+                       asp);
+
        /* Export the object (@manager takes its own reference to @object) */
        g_dbus_object_manager_server_export(asp->obj_mgr, G_DBUS_OBJECT_SKELETON(object));
        g_object_unref(object);
index a74ac1d..d7ad90c 100644 (file)
@@ -977,9 +977,9 @@ int _asp_sess_peer_fsm_log_func(const char *format, ...)
 {
        gchar buffer[256];
        va_list args;
-       va_start (args, format);
-       g_vsnprintf (buffer, 255, format, args);
-       va_end (args);
+       va_start(args, format);
+       g_vsnprintf(buffer, 255, format, args);
+       va_end(args);
 
        ASP_LOGD("%s", buffer);
 
index f139655..35b1949 100644 (file)
@@ -925,7 +925,7 @@ void asp_session_recv_req(GSocketAddress *sock_addr, gpointer p_msg)
                return;
        }
 
-       if(session->over_p2p && session->sock_addr == NULL) {
+       if (session->over_p2p && session->sock_addr == NULL) {
                ASP_LOGD("IpAssigned signal isn't yet received, discard event");
                return;
        }
@@ -1704,9 +1704,9 @@ int _asp_session_fsm_log_func(const char *format, ...)
 {
        gchar buffer[256];
        va_list args;
-       va_start (args, format);
-       g_vsnprintf (buffer, 255, format, args);
-       va_end (args);
+       va_start(args, format);
+       g_vsnprintf(buffer, 255, format, args);
+       va_end(args);
 
        ASP_LOGD("%s", buffer);
 
@@ -2445,11 +2445,10 @@ gfsm_state_id_t _state_group_formation_completed_reaction_ip_assigned(
        ASP_LOGD("peer IP %s", p_ip_assigned_param->peer_ip_addr);
        _store_peer_ip_addr(session, p_ip_assigned_param->peer_ip_addr,
                            p_ip_assigned_param->length);
-       if (session->asp_role == ASP_ROLE_SEEKER) {
+       if (session->asp_role == ASP_ROLE_SEEKER)
                ret_state = SESSION_STATE_REQUEST_SESSION_SENT;
-       } else {
+       else
                ret_state = SESSION_STATE_REQUEST_SESSION_RECEIVED;
-       }
 
        return ret_state;
 }
@@ -2526,7 +2525,7 @@ void _state_request_session_sent_entry_action(void *p_context_data)
 
        asp_session_s *session = (asp_session_s *)p_context_data;
 
-       if(!session->over_p2p)
+       if (!session->over_p2p)
                _call_connect_status_cb(0, session->session_mac, session->session_id,
                                ASP_SESSION_CONNECT_STATUS_SESSION_REQUEST_SENT);
 }
@@ -2588,8 +2587,8 @@ void _state_request_session_received_entry_action(void *p_context_data)
        asp_session_s *session = (asp_session_s *)p_context_data;
        g_assert(session);
        if (session->over_p2p && session->confirmed &&
-                       session->asp_role == ASP_ROLE_ADVERTIZER ) {
-               /* TODO: Set Session should done after this  event*/
+                       session->asp_role == ASP_ROLE_ADVERTIZER) {
+               /* TODO: Set Session should done after this  event */
        } else {
                /* session_request_cb */
                /* what is user data ? */
index ff353e4..8dd6a1c 100644 (file)
@@ -308,7 +308,7 @@ void gfsm_process_event(gfsm_context_s *p_context, gfsm_event_s *p_event)
        gfsm_s *p_fsm;
 
        ASP_LOGD("process event");
-       if(p_context == NULL)
+       if (p_context == NULL)
                ASP_LOGD("context is NULL");
        assert(p_context && p_event);