Add logging to debugproxy 85/185685/1
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Fri, 20 Jul 2018 09:05:28 +0000 (11:05 +0200)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Wed, 1 Aug 2018 12:47:03 +0000 (14:47 +0200)
Change-Id: I2086948c9784c18d452c281372c221ee119ab2c4
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
log/log.c
log/log.h
simulatordaemon/debugproxy/CMakeLists.txt
simulatordaemon/debugproxy/inc/forwarding.h
simulatordaemon/debugproxy/src/DebugproxySocket.cpp
simulatordaemon/debugproxy/src/ProxySession.cpp

index 59b5ce8..c0fa4bb 100644 (file)
--- a/log/log.c
+++ b/log/log.c
@@ -123,6 +123,8 @@ const char *getModuleLevelString(ModuleLevel module_level)
                return "OSA_LIB";
        case MODULE_CLIENT_TA:
                return "CLIENT_TA";
+       case MODULE_DEBUGPROXY:
+               return "DEBUGPROXY";
        default:
                return "TA_SDK";
        }
index 15c8148..7032f38 100644 (file)
--- a/log/log.h
+++ b/log/log.h
@@ -57,6 +57,7 @@ typedef enum {
        MODULE_SSF_LIB = 0x20,
        MODULE_OSA_LIB = 0x40,
        MODULE_CLIENT_TA = 0x80,
+       MODULE_DEBUGPROXY = 0x100,
        MODULE_ALL = 0xFFFFFFF,
 } ModuleLevel;
 
index dfb44ce..32c7503 100644 (file)
 # @brief   CMakeLists for tef-simulator daemon debugproxy
 #
 
+PKG_CHECK_MODULES(DEBUGPROXY_DEPS REQUIRED
+    dlog
+)
+
 SET(DEBUGPROXY_SOURCES
         ${DEBUGPROXY_PATH}/src/AsyncEvent.cpp
         ${DEBUGPROXY_PATH}/src/DebugproxySocket.cpp
@@ -31,10 +35,17 @@ ADD_EXECUTABLE(${TARGET_TEF_SIMULATOR_DEBUGPROXY}
 INCLUDE_DIRECTORIES(
         ${DEBUGPROXY_PATH}/inc
         ${TEF_SIMULATOR_INCLUDE_PATH}/include
+        ${LOG_PATH}
     )
 
+LINK_DIRECTORIES(
+    ${LOG_PATH}
+)
+
 TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DEBUGPROXY}
     boost_system boost_signals boost_coroutine
+    ${TARGET_TEF_SIMULATOR_LOG}
+    ${DEBUGPROXY_DEPS_LIBRARIES}
     )
 
 INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_DEBUGPROXY} DESTINATION ${BIN_DIR})
index c07858d..433c2a8 100644 (file)
@@ -2,6 +2,7 @@
 #define __FORWARDING_H__
 
 #include <memory>
+#include <log.h>
 #include <boost/asio.hpp>
 #include "AsyncEvent.h"
 
@@ -27,7 +28,7 @@ void forward(socket_ptr<T> from,
                                *to, boost::asio::buffer(data, len), yield);
                }
        } catch (std::exception &e) {
-               /* TODO - logging */
+               LOGD(MODULE_DEBUGPROXY, "Stopped forwarding sockets: %s", e.what());
                connection_end->set();
        }
 }
index 6e2cc8f..dcacf9a 100644 (file)
@@ -7,6 +7,7 @@
 #include <boost/system/system_error.hpp>
 
 #include <config.h>
+#include <log.h>
 
 #include "common.h"
 #include "DebugproxySocket.h"
@@ -21,6 +22,7 @@ DebugproxySocket::DebugproxySocket(boost::asio::io_service &io)
 
 void DebugproxySocket::start_accept()
 {
+       LOGD(MODULE_DEBUGPROXY, "Listening on %s", DEBUGPROXY_SOCK_PATH);
        boost::asio::spawn(this->io, boost::bind(&DebugproxySocket::async_accept,
                                                 this, _1));
 }
@@ -37,8 +39,8 @@ void DebugproxySocket::async_accept(yield_ctx yield)
                                        return this->handle_connection(sock, yield);
                                });
                }
-       } catch (boost::system::system_error &e) {
-               /* TODO - log */
+       } catch (std::exception &e) {
+               LOGE(MODULE_DEBUGPROXY, "Failed to accept new connection: %s", e.what());
                this->quit_event->set();
        }
 }
@@ -49,7 +51,7 @@ void DebugproxySocket::handle_connection(const std::shared_ptr<local_sock> local
        try {
                ProxySession session(local_sock, this->quit_event);
                session.async_session(yield);
-       } catch (boost::system::system_error &e) {
-               /* TODO - log */
+       } catch (std::exception &e) {
+               LOGE(MODULE_DEBUGPROXY, "Forwarding session ended: %s", e.what());
        }
 }
index 377de35..ab4ee95 100644 (file)
@@ -1,6 +1,8 @@
 #include <memory>
 #include <boost/bind.hpp>
 #include <boost/asio/deadline_timer.hpp>
+
+#include <log.h>
 #include "ProxySession.h"
 #include "forwarding.h"
 #include "common.h"
@@ -29,6 +31,7 @@ uint32_t ProxySession::read_forwarded_port(yield_ctx yield)
        uint32_t target_port[1];
        boost::asio::async_read(
                *this->local_socket, boost::asio::buffer(target_port), yield);
+       LOGD(MODULE_DEBUGPROXY, "(%p) Received port number: %d", this, target_port[0]);
        return target_port[0];
 }
 
@@ -51,6 +54,7 @@ void ProxySession::setup_port_socket(int port, yield_ctx yield)
                        if (!acceptor)
                                return;
                        acceptor->cancel();
+                       LOGI(MODULE_DEBUGPROXY, "(%p) Timed out waiting for a port connection", this);
        };
        boost::asio::spawn(this->io(), stop_at_timeout);
        port_acceptor->async_accept(*this->port_socket, yield);
@@ -58,6 +62,7 @@ void ProxySession::setup_port_socket(int port, yield_ctx yield)
 
 std::shared_ptr<AsyncEvent> ProxySession::start_forwarding()
 {
+       LOGD(MODULE_DEBUGPROXY, "(%p) Two-way forwarding started", this);
        auto connection_lost_event = std::make_shared<AsyncEvent>(this->io());
        boost::asio::spawn(
                this->io(),
@@ -74,6 +79,7 @@ std::shared_ptr<AsyncEvent> ProxySession::start_forwarding()
 
 void ProxySession::async_session(yield_ctx yield)
 {
+       LOGD(MODULE_DEBUGPROXY, "Started forwarding session: %p", this);
        uint32_t target_port = this->read_forwarded_port(yield);
        this->setup_port_socket(target_port, yield);
        auto connection_lost_event = this->start_forwarding();
@@ -82,6 +88,7 @@ void ProxySession::async_session(yield_ctx yield)
                                           connection_lost_event},
                         this->io());
        events.wait_on_any(yield);
+       LOGD(MODULE_DEBUGPROXY, "(%p) Received session end event", this);
 }
 
 template <typename T>