summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Nosach <ANosach@luxoft.com>2016-04-12 14:46:27 +0300
committerArtem Nosach <ANosach@luxoft.com>2016-04-12 14:49:00 +0300
commit7bdff297260e317481492cce8722f84db7e5c560 (patch)
tree16b9140b6db13985a0cd48e58e6e6fa9d91e95af
parent3575ecd9c61204ae24d7a173af0431540c611764 (diff)
downloadsdl_core-7bdff297260e317481492cce8722f84db7e5c560.tar.gz
Merge common transport functionality
Related-issues: APPLINK-22713, APPLINK-22716
-rw-r--r--src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h43
-rw-r--r--src/components/transport_manager/include/transport_manager/transport_manager_impl.h106
-rw-r--r--src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc289
-rw-r--r--src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc490
-rw-r--r--src/components/transport_manager/src/transport_manager_default.cc47
-rw-r--r--src/components/transport_manager/src/transport_manager_impl.cc501
6 files changed, 722 insertions, 754 deletions
diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h b/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h
index ab0c5cbf85..dad5e1d931 100644
--- a/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h
+++ b/src/components/transport_manager/include/transport_manager/transport_adapter/threaded_socket_connection.h
@@ -35,13 +35,14 @@
#ifndef SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_THREADED_SOCKET_CONNECTION_H_
#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TRANSPORT_ADAPTER_THREADED_SOCKET_CONNECTION_H_
-#include <poll.h>
#include <queue>
#include "transport_manager/transport_adapter/connection.h"
#include "protocol/common.h"
#include "utils/threads/thread_delegate.h"
#include "utils/lock.h"
+#include "utils/socket.h"
+#include "utils/atomic_object.h"
using ::transport_manager::transport_adapter::Connection;
@@ -55,7 +56,8 @@ class TransportAdapterController;
/**
* @brief Class responsible for communication over sockets.
*/
-class ThreadedSocketConnection : public Connection {
+class ThreadedSocketConnection : public Connection,
+ public utils::TcpConnectionEventHandler {
public:
/**
* @brief Send data frame.
@@ -81,18 +83,21 @@ class ThreadedSocketConnection : public Connection {
TransportAdapter::Error Start();
/**
- * @brief Checks is queue with frames to send empty or not.
- *
- * @return Information about queue is empty or not.
+ * @brief Set variable that hold socket No. Takes the ownership.
*/
- bool IsFramesToSendQueueEmpty() const;
+ void SetSocket(utils::TcpSocketConnection& socket_connection);
- /**
- * @brief Set variable that hold socket No.
- */
- void set_socket(int socket) {
- socket_ = socket;
- }
+ // Implementation of the TcpConnectionEventHandler
+
+ void OnError(int error) OVERRIDE;
+
+ void OnData(const uint8_t* const buffer, std::size_t buffer_size) OVERRIDE;
+
+ void OnCanWrite() OVERRIDE;
+
+ void OnClose() OVERRIDE;
+
+ // End of implementation
protected:
/**
@@ -145,14 +150,12 @@ class ThreadedSocketConnection : public Connection {
ThreadedSocketConnection* connection_;
};
- int read_fd_;
- int write_fd_;
void threadMain();
void Transmit();
void Finalize();
- TransportAdapter::Error Notify() const;
+ TransportAdapter::Error Notify();
bool Receive();
- bool Send();
+ void Send();
void Abort();
TransportAdapterController* controller_;
@@ -163,9 +166,11 @@ class ThreadedSocketConnection : public Connection {
FrameQueue frames_to_send_;
mutable sync_primitives::Lock frames_to_send_mutex_;
- int socket_;
- bool terminate_flag_;
- bool unexpected_disconnect_;
+ utils::TcpSocketConnection socket_connection_;
+
+ sync_primitives::atomic_bool terminate_flag_;
+ sync_primitives::atomic_bool unexpected_disconnect_;
+
const DeviceUID device_uid_;
const ApplicationHandle app_handle_;
threads::Thread* thread_;
diff --git a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h
index bcd80c118f..2d40a91048 100644
--- a/src/components/transport_manager/include/transport_manager/transport_manager_impl.h
+++ b/src/components/transport_manager/include/transport_manager/transport_manager_impl.h
@@ -43,16 +43,16 @@
#include "utils/timer.h"
#include "utils/timer_task_impl.h"
#include "utils/rwlock.h"
-
#include "transport_manager/transport_manager.h"
#include "transport_manager/transport_manager_listener.h"
#include "transport_manager/transport_adapter/transport_adapter_listener_impl.h"
#include "protocol/common.h"
+#include "utils/threads/message_loop_thread.h"
+#include "transport_manager/transport_adapter/transport_adapter_event.h"
+
#ifdef TELEMETRY_MONITOR
#include "transport_manager/telemetry_observer.h"
#endif // TELEMETRY_MONITOR
-#include "utils/threads/message_loop_thread.h"
-#include "transport_manager/transport_adapter/transport_adapter_event.h"
#include "telemetry_monitor/telemetry_observable.h"
namespace transport_manager {
@@ -66,8 +66,8 @@ typedef utils::SharedPtr<timer::Timer> TimerSPtr;
/**
* @brief Implementation of transport manager.s
*/
-class TransportManagerImpl
- : public TransportManager,
+class TransportManagerImpl:
+ public TransportManager,
public RawMessageLoopThread::Handler
#ifdef TELEMETRY_MONITOR
,
@@ -96,11 +96,10 @@ class TransportManagerImpl
ConnectionInternal(TransportManagerImpl* transport_manager,
TransportAdapter* transport_adapter,
- const ConnectionUID id,
+ const ConnectionUID& id,
const DeviceUID& dev_id,
const ApplicationHandle& app_id,
- const DeviceHandle device_handle);
-
+ const DeviceHandle& device_handle);
void DisconnectFailedRoutine();
};
@@ -121,14 +120,14 @@ class TransportManagerImpl
* Reinitializes transport manager
* @return Error code
*/
- virtual int Reinit() OVERRIDE;
+ virtual int Reinit();
/**
* @brief Start scanning for new devices.
*
* @return Code error.
**/
- int SearchDevices() OVERRIDE;
+ virtual int SearchDevices();
/**
* @brief Connect to all applications discovered on device.
@@ -137,7 +136,7 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int ConnectDevice(const DeviceHandle device_id) OVERRIDE;
+ virtual int ConnectDevice(const DeviceHandle& device_id);
/**
* @brief Disconnect from all applications connected on device.
@@ -146,7 +145,7 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int DisconnectDevice(const DeviceHandle device_id) OVERRIDE;
+ virtual int DisconnectDevice(const DeviceHandle& device_id);
/**
* @brief Disconnect from applications connected on device by connection
@@ -156,14 +155,14 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int Disconnect(const ConnectionUID connection_id) OVERRIDE;
+ virtual int Disconnect(const ConnectionUID& connection_id);
/**
* @brief Disconnect and clear all unreceived data.
*
* @param connection Connection unique identifier.
*/
- int DisconnectForce(const ConnectionUID connection_id) OVERRIDE;
+ virtual int DisconnectForce(const ConnectionUID& connection_id);
/**
* @brief Post new message in queue for massages destined to device.
*
@@ -171,8 +170,8 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int SendMessageToDevice(
- const protocol_handler::RawMessagePtr message) OVERRIDE;
+ virtual int SendMessageToDevice(
+ const protocol_handler::RawMessagePtr message);
/**
* @brief Post event in the event queue.
@@ -181,7 +180,7 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int ReceiveEventFromDevice(const TransportAdapterEvent& event) OVERRIDE;
+ virtual int ReceiveEventFromDevice(const TransportAdapterEvent& event);
/**
* @brief Post listener to the container of transport manager listeners.
@@ -190,9 +189,9 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int AddEventListener(TransportManagerListener* listener) OVERRIDE;
+ virtual int AddEventListener(TransportManagerListener* listener);
- int Stop() OVERRIDE;
+ virtual int Stop();
/**
* @brief Add device adapter to the container of device adapters.
@@ -201,8 +200,8 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int AddTransportAdapter(
- transport_adapter::TransportAdapter* transport_adapter) OVERRIDE;
+ virtual int AddTransportAdapter(
+ transport_adapter::TransportAdapter* transport_adapter);
/**
* @brief Remove device from the container that hold devices.
@@ -211,7 +210,7 @@ class TransportManagerImpl
*
* @return Code error.
**/
- int RemoveDevice(const DeviceHandle device) OVERRIDE;
+ virtual int RemoveDevice(const DeviceHandle& device);
/**
* @brief Turns on or off visibility of SDL to mobile devices
@@ -220,7 +219,7 @@ class TransportManagerImpl
*
* @return Code error.
*/
- int Visibility(const bool& on_off) const OVERRIDE;
+ virtual int Visibility(const bool& on_off) const;
/**
* @brief Updates total device list with info from specific transport adapter.
@@ -243,6 +242,7 @@ class TransportManagerImpl
TransportManagerImpl();
protected:
+#if defined(SDL_CPP11)
template <class Proc, class... Args>
void RaiseEvent(Proc proc, Args... args) {
for (TransportManagerListenerList::iterator it =
@@ -252,6 +252,64 @@ class TransportManagerImpl
((*it)->*proc)(args...);
}
}
+#else
+ template <class Proc>
+ void RaiseEvent(Proc proc) {
+ for (TransportManagerListenerList::iterator it =
+ transport_manager_listener_.begin();
+ it != transport_manager_listener_.end();
+ ++it) {
+ ((*it)->*proc)();
+ }
+ }
+
+ template <class Proc, class Arg1>
+ void RaiseEvent(Proc proc, const Arg1& arg1) {
+ for (TransportManagerListenerList::iterator it =
+ transport_manager_listener_.begin();
+ it != transport_manager_listener_.end();
+ ++it) {
+ ((*it)->*proc)(arg1);
+ }
+ }
+
+ template <class Proc, class Arg1, class Arg2>
+ void RaiseEvent(Proc proc, const Arg1& arg1, const Arg2& arg2) {
+ for (TransportManagerListenerList::iterator it =
+ transport_manager_listener_.begin();
+ it != transport_manager_listener_.end();
+ ++it) {
+ ((*it)->*proc)(arg1, arg2);
+ }
+ }
+
+ template <class Proc, class Arg1, class Arg2, class Arg3>
+ void RaiseEvent(Proc proc,
+ const Arg1& arg1,
+ const Arg2& arg2,
+ const Arg3& arg3) {
+ for (TransportManagerListenerList::iterator it =
+ transport_manager_listener_.begin();
+ it != transport_manager_listener_.end();
+ ++it) {
+ ((*it)->*proc)(arg1, arg2, arg3);
+ }
+ }
+
+ template <class Proc, class Arg1, class Arg2, class Arg3, class Arg4>
+ void RaiseEvent(Proc proc,
+ const Arg1& arg1,
+ const Arg2& arg2,
+ const Arg3& arg3,
+ const Arg4& arg4) {
+ for (TransportManagerListenerList::iterator it =
+ transport_manager_listener_.begin();
+ it != transport_manager_listener_.end();
+ ++it) {
+ ((*it)->*proc)(arg1, arg2, arg3, arg4);
+ }
+ }
+#endif // SDL_CPP11
/**
* @brief Put massage in the container of massages.
@@ -354,7 +412,7 @@ class TransportManagerImpl
void AddConnection(const ConnectionInternal& c);
void RemoveConnection(uint32_t id);
- ConnectionInternal* GetConnection(const ConnectionUID id);
+ ConnectionInternal* GetConnection(const ConnectionUID& id);
ConnectionInternal* GetConnection(const DeviceUID& device,
const ApplicationHandle& application);
diff --git a/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc b/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc
index 65afdf4fc0..369157353f 100644
--- a/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc
+++ b/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc
@@ -29,35 +29,29 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "transport_manager/transport_adapter/threaded_socket_connection.h"
-#include <algorithm>
-#include <errno.h>
-#include <fcntl.h>
-#include <memory.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
+#include "transport_manager/transport_adapter/transport_adapter_controller.h"
#include "utils/logger.h"
#include "utils/threads/thread.h"
-#include "transport_manager/transport_adapter/threaded_socket_connection.h"
-#include "transport_manager/transport_adapter/transport_adapter_controller.h"
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
namespace transport_manager {
namespace transport_adapter {
-CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
+////////////////////////////////////////////////////////////////////////////////
+/// SocketConnectionDelegate:
+////////////////////////////////////////////////////////////////////////////////
ThreadedSocketConnection::ThreadedSocketConnection(
const DeviceUID& device_id,
const ApplicationHandle& app_handle,
TransportAdapterController* controller)
- : read_fd_(-1)
- , write_fd_(-1)
- , controller_(controller)
+ : controller_(controller)
, frames_to_send_()
, frames_to_send_mutex_()
- , socket_(-1)
+ , socket_connection_()
, terminate_flag_(false)
, unexpected_disconnect_(false)
, device_uid_(device_id)
@@ -69,115 +63,86 @@ ThreadedSocketConnection::ThreadedSocketConnection(
}
ThreadedSocketConnection::~ThreadedSocketConnection() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
Disconnect();
thread_->join();
delete thread_->delegate();
threads::DeleteThread(thread_);
-
- if (-1 != read_fd_) {
- close(read_fd_);
- }
- if (-1 != write_fd_) {
- close(write_fd_);
- }
}
void ThreadedSocketConnection::Abort() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
unexpected_disconnect_ = true;
terminate_flag_ = true;
}
-TransportAdapter::Error ThreadedSocketConnection::Start() {
- LOG4CXX_AUTO_TRACE(logger_);
- int fds[2];
- const int pipe_ret = pipe(fds);
- if (0 == pipe_ret) {
- LOG4CXX_DEBUG(logger_, "pipe created");
- read_fd_ = fds[0];
- write_fd_ = fds[1];
- } else {
- LOG4CXX_ERROR(logger_, "pipe creation failed");
- return TransportAdapter::FAIL;
- }
- const int fcntl_ret =
- fcntl(read_fd_, F_SETFL, fcntl(read_fd_, F_GETFL) | O_NONBLOCK);
- if (0 != fcntl_ret) {
- LOG4CXX_ERROR(logger_, "fcntl failed");
- return TransportAdapter::FAIL;
- }
+void ThreadedSocketConnection::SetSocket(
+ utils::TcpSocketConnection& socket_connection) {
+ socket_connection_ = socket_connection;
+ socket_connection_.SetEventHandler(this);
+}
+TransportAdapter::Error ThreadedSocketConnection::Start() {
+ LOGGER_AUTO_TRACE(logger_);
if (!thread_->start()) {
- LOG4CXX_ERROR(logger_, "thread creation failed");
+ LOGGER_ERROR(logger_, "thread creation failed");
return TransportAdapter::FAIL;
}
- LOG4CXX_INFO(logger_, "thread created");
+ LOGGER_INFO(logger_, "thread created");
return TransportAdapter::OK;
}
void ThreadedSocketConnection::Finalize() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
if (unexpected_disconnect_) {
- LOG4CXX_DEBUG(logger_, "unexpected_disconnect");
+ LOGGER_DEBUG(logger_, "unexpected_disconnect");
controller_->ConnectionAborted(
device_handle(), application_handle(), CommunicationError());
} else {
- LOG4CXX_DEBUG(logger_, "not unexpected_disconnect");
+ LOGGER_DEBUG(logger_, "not unexpected_disconnect");
controller_->ConnectionFinished(device_handle(), application_handle());
}
- close(socket_);
+ socket_connection_.Close();
}
-TransportAdapter::Error ThreadedSocketConnection::Notify() const {
- LOG4CXX_AUTO_TRACE(logger_);
- if (-1 == write_fd_) {
- LOG4CXX_ERROR_WITH_ERRNO(
- logger_, "Failed to wake up connection thread for connection " << this);
- LOG4CXX_TRACE(logger_, "exit with TransportAdapter::BAD_STATE");
- return TransportAdapter::BAD_STATE;
- }
- uint8_t c = 0;
- if (1 != write(write_fd_, &c, 1)) {
- LOG4CXX_ERROR_WITH_ERRNO(
- logger_, "Failed to wake up connection thread for connection " << this);
- return TransportAdapter::FAIL;
- }
- return TransportAdapter::OK;
+TransportAdapter::Error ThreadedSocketConnection::Notify() {
+ LOGGER_AUTO_TRACE(logger_);
+ return socket_connection_.Notify() ? TransportAdapter::OK
+ : TransportAdapter::FAIL;
}
TransportAdapter::Error ThreadedSocketConnection::SendData(
::protocol_handler::RawMessagePtr message) {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
sync_primitives::AutoLock auto_lock(frames_to_send_mutex_);
frames_to_send_.push(message);
return Notify();
}
TransportAdapter::Error ThreadedSocketConnection::Disconnect() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
terminate_flag_ = true;
return Notify();
}
void ThreadedSocketConnection::threadMain() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
controller_->ConnectionCreated(this, device_uid_, app_handle_);
ConnectError* connect_error = NULL;
if (!Establish(&connect_error)) {
- LOG4CXX_ERROR(logger_, "Connection Establish failed");
+ LOGGER_ERROR(logger_, "Connection Establish failed");
delete connect_error;
}
- LOG4CXX_DEBUG(logger_, "Connection established");
+ LOGGER_DEBUG(logger_, "Connection established");
controller_->ConnectDone(device_handle(), application_handle());
while (!terminate_flag_) {
Transmit();
}
- LOG4CXX_DEBUG(logger_, "Connection is to finalize");
+ LOGGER_DEBUG(logger_, "Connection is to finalize");
Finalize();
sync_primitives::AutoLock auto_lock(frames_to_send_mutex_);
while (!frames_to_send_.empty()) {
- LOG4CXX_INFO(logger_, "removing message");
+ LOGGER_INFO(logger_, "removing message");
::protocol_handler::RawMessagePtr message = frames_to_send_.front();
frames_to_send_.pop();
controller_->DataSendFailed(
@@ -185,169 +150,87 @@ void ThreadedSocketConnection::threadMain() {
}
}
-bool ThreadedSocketConnection::IsFramesToSendQueueEmpty() const {
- // Check Frames queue is empty or not
- sync_primitives::AutoLock auto_lock(frames_to_send_mutex_);
- return frames_to_send_.empty();
-}
-
void ThreadedSocketConnection::Transmit() {
- LOG4CXX_AUTO_TRACE(logger_);
-
- const nfds_t kPollFdsSize = 2;
- pollfd poll_fds[kPollFdsSize];
- poll_fds[0].fd = socket_;
-
- const bool is_queue_empty_on_poll = IsFramesToSendQueueEmpty();
-
- poll_fds[0].events =
- POLLIN | POLLPRI | (is_queue_empty_on_poll ? 0 : POLLOUT);
- poll_fds[1].fd = read_fd_;
- poll_fds[1].events = POLLIN | POLLPRI;
-
- LOG4CXX_DEBUG(logger_, "poll " << this);
- if (-1 == poll(poll_fds, kPollFdsSize, -1)) {
- LOG4CXX_ERROR_WITH_ERRNO(logger_, "poll failed for connection " << this);
- Abort();
- return;
- }
- LOG4CXX_DEBUG(logger_,
- "poll is ok " << this << " revents0: " << std::hex
- << poll_fds[0].revents << " revents1:" << std::hex
- << poll_fds[1].revents);
- // error check
- if (0 != (poll_fds[1].revents & (POLLERR | POLLHUP | POLLNVAL))) {
- LOG4CXX_ERROR(logger_,
- "Notification pipe for connection " << this << " terminated");
- Abort();
- return;
- }
-
- if (poll_fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
- LOG4CXX_WARN(logger_, "Connection " << this << " terminated");
- Abort();
- return;
- }
-
- // clear notifications
- char buffer[256];
- ssize_t bytes_read = -1;
- do {
- bytes_read = read(read_fd_, buffer, sizeof(buffer));
- } while (bytes_read > 0);
- if ((bytes_read < 0) && (EAGAIN != errno)) {
- LOG4CXX_ERROR_WITH_ERRNO(logger_, "Failed to clear notification pipe");
- LOG4CXX_ERROR_WITH_ERRNO(logger_, "poll failed for connection " << this);
- Abort();
- return;
- }
-
- const bool is_queue_empty = IsFramesToSendQueueEmpty();
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_, "Waiting for connection events. " << this);
+ socket_connection_.Wait();
- // Send data if possible
- if (!is_queue_empty && (poll_fds[0].revents | POLLOUT)) {
- LOG4CXX_DEBUG(logger_, "frames_to_send_ not empty() ");
-
- // send data
- const bool send_ok = Send();
- if (!send_ok) {
- LOG4CXX_ERROR(logger_, "Send() failed ");
- Abort();
- return;
- }
- }
-
- // receive data
- if (poll_fds[0].revents & (POLLIN | POLLPRI)) {
- const bool receive_ok = Receive();
- if (!receive_ok) {
- LOG4CXX_ERROR(logger_, "Receive() failed ");
- Abort();
- return;
- }
- }
+ LOGGER_DEBUG(logger_, "Waited for connection events: " << this);
}
-bool ThreadedSocketConnection::Receive() {
- LOG4CXX_AUTO_TRACE(logger_);
- uint8_t buffer[4096];
- ssize_t bytes_read = -1;
-
- do {
- bytes_read = recv(socket_, buffer, sizeof(buffer), MSG_DONTWAIT);
-
- if (bytes_read > 0) {
- LOG4CXX_DEBUG(logger_,
- "Received " << bytes_read << " bytes for connection "
- << this);
- ::protocol_handler::RawMessagePtr frame(
- new protocol_handler::RawMessage(0, 0, buffer, bytes_read));
- controller_->DataReceiveDone(
- device_handle(), application_handle(), frame);
- } else if (bytes_read < 0) {
- if (EAGAIN != errno && EWOULDBLOCK != errno) {
- LOG4CXX_ERROR_WITH_ERRNO(logger_,
- "recv() failed for connection " << this);
- return false;
- }
- } else {
- LOG4CXX_WARN(logger_, "Connection " << this << " closed by remote peer");
- return false;
- }
- } while (bytes_read > 0);
-
- return true;
-}
-
-bool ThreadedSocketConnection::Send() {
- LOG4CXX_AUTO_TRACE(logger_);
- FrameQueue frames_to_send_local;
-
+void ThreadedSocketConnection::Send() {
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_, "Trying to send data if available");
+ FrameQueue frames_to_send;
{
sync_primitives::AutoLock auto_lock(frames_to_send_mutex_);
- std::swap(frames_to_send_local, frames_to_send_);
+ std::swap(frames_to_send, frames_to_send_);
}
size_t offset = 0;
- while (!frames_to_send_local.empty()) {
- LOG4CXX_INFO(logger_, "frames_to_send is not empty");
- ::protocol_handler::RawMessagePtr frame = frames_to_send_local.front();
- const ssize_t bytes_sent =
- ::send(socket_, frame->data() + offset, frame->data_size() - offset, 0);
-
+ while (!frames_to_send.empty()) {
+ ::protocol_handler::RawMessagePtr frame = frames_to_send.front();
+ std::size_t bytes_sent = 0u;
+ const bool sent = socket_connection_.Send(
+ frame->data() + offset, frame->data_size() - offset, bytes_sent);
+ if (!sent) {
+ LOGGER_ERROR(logger_, "Send failed for connection " << this);
+ frames_to_send.pop();
+ offset = 0;
+ controller_->DataSendFailed(
+ device_handle(), application_handle(), frame, DataSendError());
+ Abort();
+ return;
+ }
if (bytes_sent >= 0) {
- LOG4CXX_DEBUG(logger_, "bytes_sent >= 0");
offset += bytes_sent;
if (offset == frame->data_size()) {
- frames_to_send_local.pop();
+ frames_to_send.pop();
offset = 0;
controller_->DataSendDone(device_handle(), application_handle(), frame);
}
- } else {
- LOG4CXX_DEBUG(logger_, "bytes_sent < 0");
- LOG4CXX_ERROR_WITH_ERRNO(logger_, "Send failed for connection " << this);
- frames_to_send_local.pop();
- offset = 0;
- controller_->DataSendFailed(
- device_handle(), application_handle(), frame, DataSendError());
}
}
+}
- return true;
+void ThreadedSocketConnection::OnError(int error) {
+ LOGGER_ERROR(logger_, "Connection error: " << error);
+ Abort();
}
+void ThreadedSocketConnection::OnData(const uint8_t* const buffer,
+ std::size_t buffer_size) {
+ protocol_handler::RawMessagePtr frame(
+ new protocol_handler::RawMessage(0, 0, buffer, buffer_size));
+ controller_->DataReceiveDone(device_handle(), application_handle(), frame);
+}
+
+void ThreadedSocketConnection::OnCanWrite() {
+ LOGGER_DEBUG(logger_, "OnCanWrite event. Trying to send data.");
+ Send();
+}
+
+void ThreadedSocketConnection::OnClose() {
+ LOGGER_DEBUG(logger_, "Connection has been closed");
+ Abort();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// SocketConnectionDelegate::SocketConnectionDelegate
+////////////////////////////////////////////////////////////////////////////////
+
ThreadedSocketConnection::SocketConnectionDelegate::SocketConnectionDelegate(
ThreadedSocketConnection* connection)
: connection_(connection) {}
void ThreadedSocketConnection::SocketConnectionDelegate::threadMain() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
DCHECK(connection_);
connection_->threadMain();
}
void ThreadedSocketConnection::SocketConnectionDelegate::exitThreadMain() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
}
} // namespace transport_adapter
diff --git a/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc b/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc
index 5b561e63b6..e05f2440b1 100644
--- a/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc
+++ b/src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc
@@ -43,8 +43,10 @@
namespace transport_manager {
namespace transport_adapter {
-CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportAdapterImpl")
+
namespace {
+#ifdef SDL_CPP11
DeviceTypes devicesType = {
std::make_pair(AOA, std::string("USB_AOA")),
std::make_pair(PASA_AOA, std::string("USB_AOA")),
@@ -52,6 +54,20 @@ DeviceTypes devicesType = {
std::make_pair(BLUETOOTH, std::string("BLUETOOTH")),
std::make_pair(PASA_BLUETOOTH, std::string("BLUETOOTH")),
std::make_pair(TCP, std::string("WIFI"))};
+#else
+DeviceTypes create_map() {
+ DeviceTypes devicesType;
+ devicesType.insert(std::make_pair(AOA, std::string("USB_AOA")));
+ devicesType.insert(std::make_pair(PASA_AOA, std::string("USB_AOA")));
+ devicesType.insert(std::make_pair(MME, std::string("USB_IOS")));
+ devicesType.insert(std::make_pair(BLUETOOTH, std::string("BLUETOOTH")));
+ devicesType.insert(std::make_pair(PASA_BLUETOOTH, std::string("BLUETOOTH")));
+ devicesType.insert(std::make_pair(TCP, std::string("WIFI")));
+
+ return devicesType;
+}
+DeviceTypes devicesType = create_map();
+#endif // SDL_CPP11
}
TransportAdapterImpl::TransportAdapterImpl(
@@ -80,52 +96,53 @@ TransportAdapterImpl::~TransportAdapterImpl() {
Terminate();
if (device_scanner_) {
- LOG4CXX_DEBUG(logger_, "Deleting device_scanner_ " << device_scanner_);
+ LOGGER_DEBUG(logger_, "Deleting device_scanner_ " << device_scanner_);
delete device_scanner_;
- LOG4CXX_DEBUG(logger_, "device_scanner_ deleted.");
+ LOGGER_DEBUG(logger_, "device_scanner_ deleted.");
}
if (server_connection_factory_) {
- LOG4CXX_DEBUG(logger_,
- "Deleting server_connection_factory "
- << server_connection_factory_);
+ LOGGER_DEBUG(logger_,
+ "Deleting server_connection_factory "
+ << server_connection_factory_);
delete server_connection_factory_;
- LOG4CXX_DEBUG(logger_, "server_connection_factory deleted.");
+ LOGGER_DEBUG(logger_, "server_connection_factory deleted.");
}
if (client_connection_listener_) {
- LOG4CXX_DEBUG(logger_,
- "Deleting client_connection_listener_ "
- << client_connection_listener_);
+ LOGGER_DEBUG(logger_,
+ "Deleting client_connection_listener_ "
+ << client_connection_listener_);
delete client_connection_listener_;
- LOG4CXX_DEBUG(logger_, "client_connection_listener_ deleted.");
+ LOGGER_DEBUG(logger_, "client_connection_listener_ deleted.");
}
}
void TransportAdapterImpl::Terminate() {
if (device_scanner_) {
device_scanner_->Terminate();
- LOG4CXX_DEBUG(logger_,
- "device_scanner_ " << device_scanner_ << " terminated.");
+ LOGGER_DEBUG(logger_,
+ "device_scanner_ " << device_scanner_ << " terminated.");
}
if (server_connection_factory_) {
server_connection_factory_->Terminate();
- LOG4CXX_DEBUG(logger_,
- "server_connection_factory " << server_connection_factory_
- << " terminated.");
+ LOGGER_DEBUG(logger_,
+ "server_connection_factory " << server_connection_factory_
+ << " terminated.");
}
if (client_connection_listener_) {
client_connection_listener_->Terminate();
- LOG4CXX_DEBUG(logger_,
- "client_connection_listener_ " << client_connection_listener_
- << " terminated.");
+ LOGGER_DEBUG(logger_,
+ "client_connection_listener_ " << client_connection_listener_
+ << " terminated.");
}
ConnectionMap connections;
- connections_lock_.AcquireForWriting();
- std::swap(connections, connections_);
- connections_lock_.Release();
+ {
+ sync_primitives::AutoWriteLock lock(connections_lock_);
+ std::swap(connections, connections_);
+ }
connections.clear();
- LOG4CXX_DEBUG(logger_, "Connections deleted");
+ LOGGER_DEBUG(logger_, "Connections deleted");
DeviceMap devices;
devices_mutex_.Acquire();
@@ -133,11 +150,11 @@ void TransportAdapterImpl::Terminate() {
devices_mutex_.Release();
devices.clear();
- LOG4CXX_DEBUG(logger_, "Devices deleted");
+ LOGGER_DEBUG(logger_, "Devices deleted");
}
TransportAdapter::Error TransportAdapterImpl::Init() {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
Error error = OK;
@@ -155,125 +172,126 @@ TransportAdapter::Error TransportAdapterImpl::Init() {
if (profile::Profile::instance()->use_last_state()) {
if (!Restore()) {
- LOG4CXX_WARN(logger_, "could not restore transport adapter state");
+ LOGGER_WARN(logger_, "could not restore transport adapter state");
error = FAIL;
}
}
- LOG4CXX_TRACE(logger_, "exit with error: " << error);
+ LOGGER_TRACE(logger_, "exit with error: " << error);
return error;
}
TransportAdapter::Error TransportAdapterImpl::SearchDevices() {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
if (device_scanner_ == NULL) {
- LOG4CXX_TRACE(logger_, "exit with NOT_SUPPORTED");
+ LOGGER_TRACE(logger_, "exit with NOT_SUPPORTED");
return NOT_SUPPORTED;
} else if (!device_scanner_->IsInitialised()) {
- LOG4CXX_TRACE(logger_, "exit with BAD_STATE");
+ LOGGER_TRACE(logger_, "exit with BAD_STATE");
return BAD_STATE;
}
TransportAdapter::Error er = device_scanner_->Scan();
- LOG4CXX_TRACE(logger_, "exit with error: " << er);
+ LOGGER_TRACE(logger_, "exit with error: " << er);
return er;
}
TransportAdapter::Error TransportAdapterImpl::Connect(
const DeviceUID& device_id, const ApplicationHandle& app_handle) {
- LOG4CXX_TRACE(logger_,
- "enter. DeviceUID " << device_id << " ApplicationHandle "
- << app_handle);
+ LOGGER_TRACE(logger_,
+ "enter. DeviceUID " << device_id << " ApplicationHandle "
+ << app_handle);
if (server_connection_factory_ == 0) {
- LOG4CXX_TRACE(logger_, "exit with NOT_SUPPORTED");
+ LOGGER_TRACE(logger_, "exit with NOT_SUPPORTED");
return NOT_SUPPORTED;
}
if (!server_connection_factory_->IsInitialised()) {
- LOG4CXX_TRACE(logger_, "exit with BAD_STATE");
+ LOGGER_TRACE(logger_, "exit with BAD_STATE");
return BAD_STATE;
}
- connections_lock_.AcquireForWriting();
- const bool already_exists =
- connections_.end() !=
- connections_.find(std::make_pair(device_id, app_handle));
- if (!already_exists) {
- ConnectionInfo& info = connections_[std::make_pair(device_id, app_handle)];
- info.app_handle = app_handle;
- info.device_id = device_id;
- info.state = ConnectionInfo::NEW;
- }
- connections_lock_.Release();
- if (already_exists) {
- LOG4CXX_TRACE(logger_, "exit with ALREADY_EXISTS");
- return ALREADY_EXISTS;
+ {
+ sync_primitives::AutoWriteLock lock(connections_lock_);
+ const bool already_exists =
+ connections_.end() !=
+ connections_.find(std::make_pair(device_id, app_handle));
+ if (!already_exists) {
+ ConnectionInfo& info =
+ connections_[std::make_pair(device_id, app_handle)];
+ info.app_handle = app_handle;
+ info.device_id = device_id;
+ info.state = ConnectionInfo::NEW;
+ } else {
+ LOGGER_TRACE(logger_, "exit with ALREADY_EXISTS");
+ return ALREADY_EXISTS;
+ }
}
const TransportAdapter::Error err =
server_connection_factory_->CreateConnection(device_id, app_handle);
if (TransportAdapter::OK != err) {
- connections_lock_.AcquireForWriting();
+ sync_primitives::AutoWriteLock lock(connections_lock_);
connections_.erase(std::make_pair(device_id, app_handle));
- connections_lock_.Release();
}
- LOG4CXX_TRACE(logger_, "exit with error: " << err);
+ LOGGER_TRACE(logger_, "exit with error: " << err);
return err;
}
TransportAdapter::Error TransportAdapterImpl::ConnectDevice(
const DeviceUID& device_handle) {
- LOG4CXX_TRACE(logger_, "enter with device_handle: " << &device_handle);
+ LOGGER_TRACE(logger_, "enter with device_handle: " << &device_handle);
DeviceSptr device = FindDevice(device_handle);
if (device) {
TransportAdapter::Error err = ConnectDevice(device);
- LOG4CXX_TRACE(logger_, "exit with error: " << err);
+ LOGGER_TRACE(logger_, "exit with error: " << err);
return err;
} else {
- LOG4CXX_TRACE(logger_, "exit with BAD_PARAM");
+ LOGGER_TRACE(logger_, "exit with BAD_PARAM");
return BAD_PARAM;
}
}
TransportAdapter::Error TransportAdapterImpl::Disconnect(
const DeviceUID& device_id, const ApplicationHandle& app_handle) {
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_id
- << ", device_id: " << &device_id);
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_id
+ << ", device_id: " << &device_id);
if (!initialised_) {
- LOG4CXX_TRACE(logger_, "exit with BAD_STATE");
+ LOGGER_TRACE(logger_, "exit with BAD_STATE");
return BAD_STATE;
}
ConnectionSPtr connection = FindEstablishedConnection(device_id, app_handle);
if (connection) {
TransportAdapter::Error err = connection->Disconnect();
- LOG4CXX_TRACE(logger_, "exit with error: " << err);
+ LOGGER_TRACE(logger_, "exit with error: " << err);
return err;
} else {
- LOG4CXX_TRACE(logger_, "exit with BAD_PARAM");
+ LOGGER_TRACE(logger_, "exit with BAD_PARAM");
return BAD_PARAM;
}
}
TransportAdapter::Error TransportAdapterImpl::DisconnectDevice(
const DeviceUID& device_id) {
- LOG4CXX_TRACE(logger_, "enter. device_id: " << &device_id);
+ LOGGER_TRACE(logger_, "enter. device_id: " << &device_id);
if (!initialised_) {
- LOG4CXX_TRACE(logger_, "exit with BAD_STATE");
+ LOGGER_TRACE(logger_, "exit with BAD_STATE");
return BAD_STATE;
}
Error error = OK;
std::vector<ConnectionInfo> to_disconnect;
- connections_lock_.AcquireForReading();
- for (ConnectionMap::const_iterator i = connections_.begin();
- i != connections_.end();
- ++i) {
- ConnectionInfo info = i->second;
- if (info.device_id == device_id &&
- info.state != ConnectionInfo::FINALISING) {
- to_disconnect.push_back(info);
+ {
+ sync_primitives::AutoReadLock lock(connections_lock_);
+ for (ConnectionMap::const_iterator i = connections_.begin();
+ i != connections_.end();
+ ++i) {
+ ConnectionInfo info = i->second;
+ if (info.device_id == device_id &&
+ info.state != ConnectionInfo::FINALISING) {
+ to_disconnect.push_back(info);
+ }
}
}
- connections_lock_.Release();
for (std::vector<ConnectionInfo>::const_iterator j = to_disconnect.begin();
j != to_disconnect.end();
@@ -281,7 +299,7 @@ TransportAdapter::Error TransportAdapterImpl::DisconnectDevice(
ConnectionInfo info = *j;
if (OK != info.connection->Disconnect()) {
error = FAIL;
- LOG4CXX_ERROR(logger_, "Error on disconnect " << error);
+ LOGGER_ERROR(logger_, "Error on disconnect " << error);
}
}
@@ -292,48 +310,48 @@ TransportAdapter::Error TransportAdapterImpl::SendData(
const DeviceUID& device_id,
const ApplicationHandle& app_handle,
const ::protocol_handler::RawMessagePtr data) {
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_id << ", app_handle: "
- << &app_handle << ", data: " << data);
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_id << ", app_handle: "
+ << &app_handle << ", data: " << data);
if (!initialised_) {
- LOG4CXX_TRACE(logger_, "exit with BAD_STATE");
+ LOGGER_TRACE(logger_, "exit with BAD_STATE");
return BAD_STATE;
}
ConnectionSPtr connection = FindEstablishedConnection(device_id, app_handle);
if (connection) {
TransportAdapter::Error err = connection->SendData(data);
- LOG4CXX_TRACE(logger_, "exit with error: " << err);
+ LOGGER_TRACE(logger_, "exit with error: " << err);
return err;
} else {
- LOG4CXX_TRACE(logger_, "exit with BAD_PARAM");
+ LOGGER_TRACE(logger_, "exit with BAD_PARAM");
return BAD_PARAM;
}
}
TransportAdapter::Error TransportAdapterImpl::StartClientListening() {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
if (client_connection_listener_ == 0) {
- LOG4CXX_TRACE(logger_, "exit with NOT_SUPPORTED");
+ LOGGER_TRACE(logger_, "exit with NOT_SUPPORTED");
return NOT_SUPPORTED;
}
if (!client_connection_listener_->IsInitialised()) {
- LOG4CXX_TRACE(logger_, "exit with BAD_STATE");
+ LOGGER_TRACE(logger_, "exit with BAD_STATE");
return BAD_STATE;
}
TransportAdapter::Error err = client_connection_listener_->StartListening();
- LOG4CXX_TRACE(logger_, "exit with error: " << err);
+ LOGGER_TRACE(logger_, "exit with error: " << err);
return err;
}
TransportAdapter::Error TransportAdapterImpl::StopClientListening() {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
if (client_connection_listener_ == 0) {
- LOG4CXX_TRACE(logger_, "exit with NOT_SUPPORTED");
+ LOGGER_TRACE(logger_, "exit with NOT_SUPPORTED");
return NOT_SUPPORTED;
}
if (!client_connection_listener_->IsInitialised()) {
- LOG4CXX_TRACE(logger_, "exit with BAD_STATE");
+ LOGGER_TRACE(logger_, "exit with BAD_STATE");
return BAD_STATE;
}
TransportAdapter::Error err = client_connection_listener_->StopListening();
@@ -341,25 +359,25 @@ TransportAdapter::Error TransportAdapterImpl::StopClientListening() {
for (DeviceMap::iterator it = devices_.begin(); it != devices_.end(); ++it) {
it->second->Stop();
}
- LOG4CXX_TRACE(logger_, "exit with error: " << err);
+ LOGGER_TRACE(logger_, "exit with error: " << err);
return err;
}
DeviceList TransportAdapterImpl::GetDeviceList() const {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
DeviceList devices;
sync_primitives::AutoLock locker(devices_mutex_);
for (DeviceMap::const_iterator it = devices_.begin(); it != devices_.end();
++it) {
devices.push_back(it->first);
}
- LOG4CXX_TRACE(logger_,
- "exit with DeviceList. It's' size = " << devices.size());
+ LOGGER_TRACE(logger_,
+ "exit with DeviceList. It's' size = " << devices.size());
return devices;
}
DeviceSptr TransportAdapterImpl::AddDevice(DeviceSptr device) {
- LOG4CXX_TRACE(logger_, "enter. device: " << device);
+ LOGGER_TRACE(logger_, "enter. device: " << device);
DeviceSptr existing_device;
bool same_device_found = false;
devices_mutex_.Acquire();
@@ -368,7 +386,7 @@ DeviceSptr TransportAdapterImpl::AddDevice(DeviceSptr device) {
existing_device = i->second;
if (device->IsSameAs(existing_device.get())) {
same_device_found = true;
- LOG4CXX_DEBUG(logger_, "device " << device << "already exists");
+ LOGGER_DEBUG(logger_, "device " << device << "already exists");
break;
}
}
@@ -377,7 +395,7 @@ DeviceSptr TransportAdapterImpl::AddDevice(DeviceSptr device) {
}
devices_mutex_.Release();
if (same_device_found) {
- LOG4CXX_TRACE(logger_, "exit with TRUE. Condition: same_device_found");
+ LOGGER_TRACE(logger_, "exit with TRUE. Condition: same_device_found");
return existing_device;
} else {
for (TransportAdapterListenerList::iterator it = listeners_.begin();
@@ -388,13 +406,13 @@ DeviceSptr TransportAdapterImpl::AddDevice(DeviceSptr device) {
if (ToBeAutoConnected(device)) {
ConnectDevice(device);
}
- LOG4CXX_TRACE(logger_, "exit with DeviceSptr " << device);
+ LOGGER_TRACE(logger_, "exit with DeviceSptr " << device);
return device;
}
}
void TransportAdapterImpl::SearchDeviceDone(const DeviceVector& devices) {
- LOG4CXX_TRACE(logger_, "enter. devices: " << &devices);
+ LOGGER_TRACE(logger_, "enter. devices: " << &devices);
DeviceMap new_devices;
for (DeviceVector::const_iterator it = devices.begin(); it != devices.end();
++it) {
@@ -408,33 +426,34 @@ void TransportAdapterImpl::SearchDeviceDone(const DeviceVector& devices) {
if (device->IsSameAs(existing_device.get())) {
existing_device->set_keep_on_disconnect(true);
device_found = true;
- LOG4CXX_DEBUG(logger_, "device found. DeviceSptr" << it->second);
+ LOGGER_DEBUG(logger_, "device found. DeviceSptr" << it->second);
break;
}
}
devices_mutex_.Release();
if (!device_found) {
- LOG4CXX_INFO(logger_,
- "Adding new device " << device->unique_device_id() << " (\""
- << device->name() << "\")");
+ LOGGER_INFO(logger_,
+ "Adding new device " << device->unique_device_id() << " (\""
+ << device->name() << "\")");
}
device->set_keep_on_disconnect(true);
new_devices[device->unique_device_id()] = device;
}
- connections_lock_.AcquireForReading();
std::set<DeviceUID> connected_devices;
- for (ConnectionMap::const_iterator it = connections_.begin();
- it != connections_.end();
- ++it) {
- const ConnectionInfo& info = it->second;
- if (info.state != ConnectionInfo::FINALISING) {
- connected_devices.insert(info.device_id);
+ {
+ sync_primitives::AutoReadLock lock(connections_lock_);
+ for (ConnectionMap::const_iterator it = connections_.begin();
+ it != connections_.end();
+ ++it) {
+ const ConnectionInfo& info = it->second;
+ if (info.state != ConnectionInfo::FINALISING) {
+ connected_devices.insert(info.device_id);
+ }
}
}
- connections_lock_.Release();
DeviceMap all_devices = new_devices;
devices_mutex_.Acquire();
@@ -465,7 +484,7 @@ void TransportAdapterImpl::SearchDeviceDone(const DeviceVector& devices) {
ConnectDevice(device);
}
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::ApplicationListUpdated(
@@ -475,40 +494,40 @@ void TransportAdapterImpl::ApplicationListUpdated(
}
void TransportAdapterImpl::FindNewApplicationsRequest() {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
for (TransportAdapterListenerList::iterator i = listeners_.begin();
i != listeners_.end();
++i) {
TransportAdapterListener* listener = *i;
listener->OnFindNewApplicationsRequest(this);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::SearchDeviceFailed(const SearchDeviceError& error) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
for (TransportAdapterListenerList::iterator it = listeners_.begin();
it != listeners_.end();
++it) {
(*it)->OnSearchDeviceFailed(this, error);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
bool TransportAdapterImpl::IsSearchDevicesSupported() const {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
return device_scanner_ != 0;
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
bool TransportAdapterImpl::IsServerOriginatedConnectSupported() const {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
return server_connection_factory_ != 0;
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
bool TransportAdapterImpl::IsClientOriginatedConnectSupported() const {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
return client_connection_listener_ != 0;
}
@@ -516,25 +535,24 @@ void TransportAdapterImpl::ConnectionCreated(
ConnectionSPtr connection,
const DeviceUID& device_id,
const ApplicationHandle& app_handle) {
- LOG4CXX_TRACE(logger_,
- "enter connection:" << connection
- << ", device_id: " << &device_id
- << ", app_handle: " << &app_handle);
- connections_lock_.AcquireForReading();
+ LOGGER_TRACE(logger_,
+ "enter connection:" << connection
+ << ", device_id: " << &device_id
+ << ", app_handle: " << &app_handle);
+ sync_primitives::AutoReadLock lock(connections_lock_);
ConnectionInfo& info = connections_[std::make_pair(device_id, app_handle)];
info.app_handle = app_handle;
info.device_id = device_id;
info.connection = connection;
info.state = ConnectionInfo::NEW;
- connections_lock_.Release();
}
void TransportAdapterImpl::DeviceDisconnected(
const DeviceUID& device_handle, const DisconnectDeviceError& error) {
const DeviceUID device_uid = device_handle;
- LOG4CXX_TRACE(logger_,
- "enter. device_handle: " << &device_uid
- << ", error: " << &error);
+ LOGGER_TRACE(logger_,
+ "enter. device_handle: " << &device_uid
+ << ", error: " << &error);
ApplicationList app_list = GetApplicationList(device_uid);
for (ApplicationList::const_iterator i = app_list.begin();
i != app_list.end();
@@ -556,17 +574,18 @@ void TransportAdapterImpl::DeviceDisconnected(
listener->OnDisconnectDeviceDone(this, device_uid);
}
- connections_lock_.AcquireForWriting();
- for (ApplicationList::const_iterator i = app_list.begin();
- i != app_list.end();
- ++i) {
- ApplicationHandle app_handle = *i;
- connections_.erase(std::make_pair(device_uid, app_handle));
+ {
+ sync_primitives::AutoWriteLock lock(connections_lock_);
+ for (ApplicationList::const_iterator i = app_list.begin();
+ i != app_list.end();
+ ++i) {
+ ApplicationHandle app_handle = *i;
+ connections_.erase(std::make_pair(device_uid, app_handle));
+ }
}
- connections_lock_.Release();
RemoveDevice(device_uid);
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
bool TransportAdapterImpl::IsSingleApplication(
@@ -578,9 +597,9 @@ bool TransportAdapterImpl::IsSingleApplication(
const DeviceUID& current_device_id = it->first.first;
const ApplicationHandle& current_app_handle = it->first.second;
if (current_device_id == device_uid && current_app_handle != app_uid) {
- LOG4CXX_DEBUG(logger_,
- "break. Condition: current_device_id == device_id && "
- "current_app_handle != app_handle");
+ LOGGER_DEBUG(logger_,
+ "break. Condition: current_device_id == device_id && "
+ "current_app_handle != app_handle");
return false;
}
@@ -592,12 +611,12 @@ void TransportAdapterImpl::DisconnectDone(const DeviceUID& device_handle,
const ApplicationHandle& app_handle) {
const DeviceUID device_uid = device_handle;
const ApplicationHandle app_uid = app_handle;
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_uid
- << ", app_handle: " << &app_uid);
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_uid
+ << ", app_handle: " << &app_uid);
DeviceSptr device = FindDevice(device_handle);
if (!device) {
- LOG4CXX_WARN(logger_, "Device: uid " << &device_uid << " not found");
+ LOGGER_WARN(logger_, "Device: uid " << &device_uid << " not found");
return;
}
@@ -613,65 +632,65 @@ void TransportAdapterImpl::DisconnectDone(const DeviceUID& device_handle,
listener->OnDisconnectDeviceDone(this, device_uid);
}
}
- connections_lock_.AcquireForWriting();
- connections_.erase(std::make_pair(device_uid, app_uid));
- connections_lock_.Release();
+
+ {
+ sync_primitives::AutoWriteLock lock(connections_lock_);
+ connections_.erase(std::make_pair(device_uid, app_uid));
+ }
if (device_disconnected) {
RemoveDevice(device_uid);
}
Store();
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::DataReceiveDone(
const DeviceUID& device_id,
const ApplicationHandle& app_handle,
::protocol_handler::RawMessagePtr message) {
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_id
- << ", app_handle: " << &app_handle
- << ", message: " << message);
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_id << ", app_handle: "
+ << &app_handle << ", message: " << message);
#ifdef TELEMETRY_MONITOR
if (metric_observer_) {
metric_observer_->StartRawMsg(message.get());
}
#endif // TELEMETRY_MONITOR
-
for (TransportAdapterListenerList::iterator it = listeners_.begin();
it != listeners_.end();
++it) {
(*it)->OnDataReceiveDone(this, device_id, app_handle, message);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::DataReceiveFailed(
const DeviceUID& device_id,
const ApplicationHandle& app_handle,
const DataReceiveError& error) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
for (TransportAdapterListenerList::iterator it = listeners_.begin();
it != listeners_.end();
++it) {
(*it)->OnDataReceiveFailed(this, device_id, app_handle, error);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::DataSendDone(
const DeviceUID& device_id,
const ApplicationHandle& app_handle,
::protocol_handler::RawMessagePtr message) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
for (TransportAdapterListenerList::iterator it = listeners_.begin();
it != listeners_.end();
++it) {
(*it)->OnDataSendDone(this, device_id, app_handle, message);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::DataSendFailed(
@@ -679,43 +698,44 @@ void TransportAdapterImpl::DataSendFailed(
const ApplicationHandle& app_handle,
::protocol_handler::RawMessagePtr message,
const DataSendError& error) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
for (TransportAdapterListenerList::iterator it = listeners_.begin();
it != listeners_.end();
++it) {
(*it)->OnDataSendFailed(this, device_id, app_handle, message, error);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
DeviceSptr TransportAdapterImpl::FindDevice(const DeviceUID& device_id) const {
- LOG4CXX_TRACE(logger_, "enter. device_id: " << &device_id);
+ LOGGER_TRACE(logger_, "enter. device_id: " << &device_id);
DeviceSptr ret;
sync_primitives::AutoLock locker(devices_mutex_);
- LOG4CXX_DEBUG(logger_, "devices_.size() = " << devices_.size());
+ LOGGER_DEBUG(logger_, "devices_.size() = " << devices_.size());
DeviceMap::const_iterator it = devices_.find(device_id);
if (it != devices_.end()) {
ret = it->second;
} else {
- LOG4CXX_WARN(logger_, "Device " << device_id << " not found.");
+ LOGGER_WARN(logger_, "Device " << device_id << " not found.");
}
- LOG4CXX_TRACE(logger_, "exit with DeviceSptr: " << ret);
+ LOGGER_TRACE(logger_, "exit with DeviceSptr: " << ret);
return ret;
}
void TransportAdapterImpl::ConnectDone(const DeviceUID& device_id,
const ApplicationHandle& app_handle) {
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_id
- << ", app_handle: " << &app_handle);
- connections_lock_.AcquireForReading();
- ConnectionMap::iterator it_conn =
- connections_.find(std::make_pair(device_id, app_handle));
- if (it_conn != connections_.end()) {
- ConnectionInfo& info = it_conn->second;
- info.state = ConnectionInfo::ESTABLISHED;
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_id
+ << ", app_handle: " << &app_handle);
+ {
+ sync_primitives::AutoReadLock lock(connections_lock_);
+ ConnectionMap::iterator it_conn =
+ connections_.find(std::make_pair(device_id, app_handle));
+ if (it_conn != connections_.end()) {
+ ConnectionInfo& info = it_conn->second;
+ info.state = ConnectionInfo::ESTABLISHED;
+ }
}
- connections_lock_.Release();
for (TransportAdapterListenerList::iterator it = listeners_.begin();
it != listeners_.end();
@@ -724,7 +744,7 @@ void TransportAdapterImpl::ConnectDone(const DeviceUID& device_id,
}
Store();
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::ConnectFailed(const DeviceUID& device_handle,
@@ -732,38 +752,40 @@ void TransportAdapterImpl::ConnectFailed(const DeviceUID& device_handle,
const ConnectError& error) {
const DeviceUID device_uid = device_handle;
const ApplicationHandle app_uid = app_handle;
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_uid << ", app_handle: "
- << &app_uid << ", error: " << &error);
- connections_lock_.AcquireForWriting();
- connections_.erase(std::make_pair(device_uid, app_uid));
- connections_lock_.Release();
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_uid << ", app_handle: "
+ << &app_uid << ", error: " << &error);
+ {
+ sync_primitives::AutoWriteLock lock(connections_lock_);
+ connections_.erase(std::make_pair(device_uid, app_uid));
+ }
+
for (TransportAdapterListenerList::iterator it = listeners_.begin();
it != listeners_.end();
++it) {
(*it)->OnConnectFailed(this, device_uid, app_uid, error);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportAdapterImpl::AddListener(TransportAdapterListener* listener) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
listeners_.push_back(listener);
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
ApplicationList TransportAdapterImpl::GetApplicationList(
const DeviceUID& device_id) const {
- LOG4CXX_TRACE(logger_, "enter. device_id: " << &device_id);
+ LOGGER_TRACE(logger_, "enter. device_id: " << &device_id);
DeviceSptr device = FindDevice(device_id);
if (device.valid()) {
ApplicationList lst = device->GetApplicationList();
- LOG4CXX_TRACE(logger_,
- "exit with ApplicationList. It's size = "
- << lst.size() << " Condition: device.valid()");
+ LOGGER_TRACE(logger_,
+ "exit with ApplicationList. It's size = "
+ << lst.size() << " Condition: device.valid()");
return lst;
}
- LOG4CXX_TRACE(
+ LOGGER_TRACE(
logger_,
"exit with empty ApplicationList. Condition: NOT device.valid()");
return ApplicationList();
@@ -771,17 +793,16 @@ ApplicationList TransportAdapterImpl::GetApplicationList(
void TransportAdapterImpl::ConnectionFinished(
const DeviceUID& device_id, const ApplicationHandle& app_handle) {
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_id
- << ", app_handle: " << &app_handle);
- connections_lock_.AcquireForReading();
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_id
+ << ", app_handle: " << &app_handle);
+ sync_primitives::AutoReadLock lock(connections_lock_);
ConnectionMap::iterator it =
connections_.find(std::make_pair(device_id, app_handle));
if (it != connections_.end()) {
ConnectionInfo& info = it->second;
info.state = ConnectionInfo::FINALISING;
}
- connections_lock_.Release();
}
void TransportAdapterImpl::ConnectionAborted(
@@ -797,32 +818,32 @@ void TransportAdapterImpl::ConnectionAborted(
}
bool TransportAdapterImpl::IsInitialised() const {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
if (!initialised_) {
- LOG4CXX_TRACE(logger_, "exit with FALSE. Condition: !initialised_");
+ LOGGER_TRACE(logger_, "exit with FALSE. Condition: !initialised_");
return false;
}
if (device_scanner_ && !device_scanner_->IsInitialised()) {
- LOG4CXX_TRACE(logger_,
- "exit with FALSE. Condition: device_scanner_ && "
- "!device_scanner_->IsInitialised()");
+ LOGGER_TRACE(logger_,
+ "exit with FALSE. Condition: device_scanner_ && "
+ "!device_scanner_->IsInitialised()");
return false;
}
if (server_connection_factory_ &&
!server_connection_factory_->IsInitialised()) {
- LOG4CXX_TRACE(logger_,
- "exit with FALSE. Condition: server_connection_factory_ && "
- "!server_connection_factory_->IsInitialised()");
+ LOGGER_TRACE(logger_,
+ "exit with FALSE. Condition: server_connection_factory_ && "
+ "!server_connection_factory_->IsInitialised()");
return false;
}
if (client_connection_listener_ &&
!client_connection_listener_->IsInitialised()) {
- LOG4CXX_TRACE(logger_,
- "exit with FALSE. Condition: client_connection_listener_ && "
- "!client_connection_listener_->IsInitialised()");
+ LOGGER_TRACE(logger_,
+ "exit with FALSE. Condition: client_connection_listener_ && "
+ "!client_connection_listener_->IsInitialised()");
return false;
}
- LOG4CXX_TRACE(logger_, "exit with TRUE");
+ LOGGER_TRACE(logger_, "exit with TRUE");
return true;
}
@@ -867,68 +888,69 @@ bool TransportAdapterImpl::ToBeAutoDisconnected(DeviceSptr device) const {
ConnectionSPtr TransportAdapterImpl::FindEstablishedConnection(
const DeviceUID& device_id, const ApplicationHandle& app_handle) const {
- LOG4CXX_TRACE(logger_,
- "enter. device_id: " << &device_id
- << ", app_handle: " << &app_handle);
+ LOGGER_TRACE(logger_,
+ "enter. device_id: " << &device_id
+ << ", app_handle: " << &app_handle);
ConnectionSPtr connection;
- connections_lock_.AcquireForReading();
- ConnectionMap::const_iterator it =
- connections_.find(std::make_pair(device_id, app_handle));
- if (it != connections_.end()) {
- const ConnectionInfo& info = it->second;
- if (info.state == ConnectionInfo::ESTABLISHED) {
- connection = info.connection;
+ {
+ sync_primitives::AutoReadLock lock(connections_lock_);
+ ConnectionMap::const_iterator it =
+ connections_.find(std::make_pair(device_id, app_handle));
+ if (it != connections_.end()) {
+ const ConnectionInfo& info = it->second;
+ if (info.state == ConnectionInfo::ESTABLISHED) {
+ connection = info.connection;
+ }
}
}
- connections_lock_.Release();
- LOG4CXX_TRACE(logger_, "exit with Connection: " << connection);
+ LOGGER_TRACE(logger_, "exit with Connection: " << connection);
return connection;
}
TransportAdapter::Error TransportAdapterImpl::ConnectDevice(DeviceSptr device) {
- LOG4CXX_TRACE(logger_, "enter. device: " << device);
+ LOGGER_TRACE(logger_, "enter. device: " << device);
DeviceUID device_id = device->unique_device_id();
ApplicationList app_list = device->GetApplicationList();
- LOG4CXX_INFO(logger_,
- "Device " << device->name() << " has " << app_list.size()
- << " applications.");
+ LOGGER_INFO(logger_,
+ "Device " << device->name() << " has " << app_list.size()
+ << " applications.");
bool errors_occurred = false;
for (ApplicationList::iterator it = app_list.begin(); it != app_list.end();
++it) {
const ApplicationHandle app_handle = *it;
- LOG4CXX_DEBUG(logger_,
- "Attempt to connect device " << device_id << ", channel "
- << app_handle);
+ LOGGER_DEBUG(logger_,
+ "Attempt to connect device " << device_id << ", channel "
+ << app_handle);
const Error error = Connect(device_id, app_handle);
switch (error) {
case OK:
- LOG4CXX_DEBUG(logger_, "error = OK");
+ LOGGER_DEBUG(logger_, "error = OK");
break;
case ALREADY_EXISTS:
- LOG4CXX_DEBUG(logger_, "error = ALREADY_EXISTS");
+ LOGGER_DEBUG(logger_, "error = ALREADY_EXISTS");
break;
default:
- LOG4CXX_ERROR(logger_,
- "Connect to device " << device_id << ", channel "
- << app_handle
- << " failed with error " << error);
+ LOGGER_ERROR(logger_,
+ "Connect to device " << device_id << ", channel "
+ << app_handle << " failed with error "
+ << error);
errors_occurred = true;
- LOG4CXX_DEBUG(logger_, "switch (error), default case");
+ LOGGER_DEBUG(logger_, "switch (error), default case");
break;
}
}
if (errors_occurred) {
- LOG4CXX_TRACE(logger_, "exit with error:FAIL");
+ LOGGER_TRACE(logger_, "exit with error:FAIL");
return FAIL;
} else {
- LOG4CXX_TRACE(logger_, "exit with error:OK");
+ LOGGER_TRACE(logger_, "exit with error:OK");
return OK;
}
}
void TransportAdapterImpl::RemoveDevice(const DeviceUID& device_handle) {
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_DEBUG(logger_, "Device_handle: " << &device_handle);
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_, "Device_handle: " << &device_handle);
sync_primitives::AutoLock locker(devices_mutex_);
DeviceMap::iterator i = devices_.find(device_handle);
if (i != devices_.end()) {
diff --git a/src/components/transport_manager/src/transport_manager_default.cc b/src/components/transport_manager/src/transport_manager_default.cc
index 6f78158236..f35a962c59 100644
--- a/src/components/transport_manager/src/transport_manager_default.cc
+++ b/src/components/transport_manager/src/transport_manager_default.cc
@@ -51,51 +51,46 @@ namespace transport_manager {
CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
int TransportManagerDefault::Init(resumption::LastState& last_state) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
if (E_SUCCESS != TransportManagerImpl::Init(last_state)) {
- LOG4CXX_TRACE(logger_,
- "exit with E_TM_IS_NOT_INITIALIZED. Condition: E_SUCCESS != "
- "TransportManagerImpl::Init()");
+ LOGGER_TRACE(logger_,
+ "exit with E_TM_IS_NOT_INITIALIZED. Condition: E_SUCCESS != "
+ "TransportManagerImpl::Init()");
return E_TM_IS_NOT_INITIALIZED;
}
+ transport_adapter::TransportAdapterImpl* ta;
-#ifdef BLUETOOTH_SUPPORT
- transport_adapter::TransportAdapterImpl* ta_bluetooth =
- new transport_adapter::BluetoothTransportAdapter(last_state);
+#if defined(USB_SUPPORT)
+ ta = new transport_adapter::UsbAoaAdapter(last_state);
#ifdef TELEMETRY_MONITOR
if (metric_observer_) {
- ta_bluetooth->SetTelemetryObserver(metric_observer_);
+ ta->SetTelemetryObserver(metric_observer_);
}
#endif // TELEMETRY_MONITOR
- AddTransportAdapter(ta_bluetooth);
- ta_bluetooth = NULL;
-#endif
+ AddTransportAdapter(ta);
+#endif // USB_SUPPORT
- const uint16_t port =
+ uint16_t port =
profile::Profile::instance()->transport_manager_tcp_adapter_port();
- transport_adapter::TransportAdapterImpl* ta_tcp =
- new transport_adapter::TcpTransportAdapter(port, last_state);
+ ta = new transport_adapter::TcpTransportAdapter(port, last_state);
#ifdef TELEMETRY_MONITOR
if (metric_observer_) {
- ta_tcp->SetTelemetryObserver(metric_observer_);
+ ta->SetTelemetryObserver(metric_observer_);
}
#endif // TELEMETRY_MONITOR
- AddTransportAdapter(ta_tcp);
- ta_tcp = NULL;
+ AddTransportAdapter(ta);
-#if defined(USB_SUPPORT)
- transport_adapter::TransportAdapterImpl* ta_usb =
- new transport_adapter::UsbAoaAdapter(last_state);
-#ifdef TELEMETRY_MONITOR
+#ifdef BLUETOOTH_SUPPORT
+ ta = new transport_adapter::BluetoothTransportAdapter(last_state);
+#ifdef TIME_TESTER
if (metric_observer_) {
- ta_usb->SetTelemetryObserver(metric_observer_);
+ ta->SetTelemetryObserver(metric_observer_);
}
#endif // TELEMETRY_MONITOR
- AddTransportAdapter(ta_usb);
- ta_usb = NULL;
-#endif // USB_SUPPORT
+ AddTransportAdapter(ta);
+#endif // TELEMETRY_MONITOR
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
diff --git a/src/components/transport_manager/src/transport_manager_impl.cc b/src/components/transport_manager/src/transport_manager_impl.cc
index 00b78014dc..44254135b9 100644
--- a/src/components/transport_manager/src/transport_manager_impl.cc
+++ b/src/components/transport_manager/src/transport_manager_impl.cc
@@ -40,6 +40,7 @@
#include <limits>
#include <functional>
#include <sstream>
+#include <iterator>
#include "utils/macro.h"
#include "utils/logger.h"
@@ -60,12 +61,12 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
TransportManagerImpl::Connection TransportManagerImpl::convert(
const TransportManagerImpl::ConnectionInternal& p) {
- LOG4CXX_TRACE(logger_, "enter. ConnectionInternal: " << &p);
+ LOGGER_TRACE(logger_, "enter. ConnectionInternal: " << &p);
TransportManagerImpl::Connection c;
c.application = p.application;
c.device = p.device;
c.id = p.id;
- LOG4CXX_TRACE(
+ LOGGER_TRACE(
logger_,
"exit with TransportManagerImpl::Connection. It's ConnectionUID = "
<< c.id);
@@ -82,11 +83,11 @@ TransportManagerImpl::TransportManagerImpl()
connection_id_counter_(0)
, message_queue_("TM MessageQueue", this)
, event_queue_("TM EventQueue", this) {
- LOG4CXX_TRACE(logger_, "TransportManager has created");
+ LOGGER_TRACE(logger_, "TransportManager has created");
}
TransportManagerImpl::~TransportManagerImpl() {
- LOG4CXX_DEBUG(logger_, "TransportManager object destroying");
+ LOGGER_DEBUG(logger_, "TransportManager object destroying");
message_queue_.Shutdown();
event_queue_.Shutdown();
@@ -104,67 +105,67 @@ TransportManagerImpl::~TransportManagerImpl() {
delete it->second;
}
- LOG4CXX_INFO(logger_, "TransportManager object destroyed");
+ LOGGER_INFO(logger_, "TransportManager object destroyed");
}
-int TransportManagerImpl::ConnectDevice(const DeviceHandle device_handle) {
- LOG4CXX_TRACE(logger_, "enter. DeviceHandle: " << &device_handle);
+int TransportManagerImpl::ConnectDevice(const DeviceHandle& device_handle) {
+ LOGGER_TRACE(logger_, "enter. DeviceHandle: " << &device_handle);
if (!this->is_initialized_) {
- LOG4CXX_ERROR(logger_, "TransportManager is not initialized.");
- LOG4CXX_TRACE(
+ LOGGER_ERROR(logger_, "TransportManager is not initialized.");
+ LOGGER_TRACE(
logger_,
"exit with E_TM_IS_NOT_INITIALIZED. Condition: !this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
DeviceUID device_id = converter_.HandleToUid(device_handle);
- LOG4CXX_DEBUG(logger_, "Convert handle to id:" << device_id);
+ LOGGER_DEBUG(logger_, "Convert handle to id " << device_id);
sync_primitives::AutoReadLock lock(device_to_adapter_map_lock_);
DeviceToAdapterMap::iterator it = device_to_adapter_map_.find(device_id);
if (it == device_to_adapter_map_.end()) {
- LOG4CXX_ERROR(logger_, "No device adapter found by id " << device_id);
- LOG4CXX_TRACE(logger_, "exit with E_INVALID_HANDLE. Condition: NULL == ta");
+ LOGGER_ERROR(logger_, "No device adapter found by id " << device_id);
+ LOGGER_TRACE(logger_, "exit with E_INVALID_HANDLE. Condition: NULL == ta");
return E_INVALID_HANDLE;
}
transport_adapter::TransportAdapter* ta = it->second;
TransportAdapter::Error ta_error = ta->ConnectDevice(device_id);
int err = (TransportAdapter::OK == ta_error) ? E_SUCCESS : E_INTERNAL_ERROR;
- LOG4CXX_TRACE(logger_, "exit with error: " << err);
+ LOGGER_TRACE(logger_, "exit with error: " << err);
return err;
}
-int TransportManagerImpl::DisconnectDevice(const DeviceHandle device_handle) {
- LOG4CXX_TRACE(logger_, "enter. DeviceHandle: " << &device_handle);
+int TransportManagerImpl::DisconnectDevice(const DeviceHandle& device_handle) {
+ LOGGER_TRACE(logger_, "enter. DeviceHandle: " << &device_handle);
if (!this->is_initialized_) {
- LOG4CXX_ERROR(logger_, "TransportManager is not initialized.");
- LOG4CXX_TRACE(
+ LOGGER_ERROR(logger_, "TransportManager is not initialized.");
+ LOGGER_TRACE(
logger_,
"exit with E_TM_IS_NOT_INITIALIZED. Condition: !this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
DeviceUID device_id = converter_.HandleToUid(device_handle);
- LOG4CXX_DEBUG(logger_, "Convert handle to id:" << device_id);
+ LOGGER_DEBUG(logger_, "Convert handle to id" << device_id);
sync_primitives::AutoReadLock lock(device_to_adapter_map_lock_);
DeviceToAdapterMap::iterator it = device_to_adapter_map_.find(device_id);
if (it == device_to_adapter_map_.end()) {
- LOG4CXX_WARN(logger_, "No device adapter found by id " << device_id);
- LOG4CXX_TRACE(logger_, "exit with E_INVALID_HANDLE. Condition: NULL == ta");
+ LOGGER_WARN(logger_, "No device adapter found by id " << device_id);
+ LOGGER_TRACE(logger_, "exit with E_INVALID_HANDLE. Condition: NULL == ta");
return E_INVALID_HANDLE;
}
transport_adapter::TransportAdapter* ta = it->second;
ta->DisconnectDevice(device_id);
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
-int TransportManagerImpl::Disconnect(const ConnectionUID cid) {
- LOG4CXX_TRACE(logger_, "enter. ConnectionUID: " << &cid);
+int TransportManagerImpl::Disconnect(const ConnectionUID& cid) {
+ LOGGER_TRACE(logger_, "enter. ConnectionUID: " << &cid);
if (!this->is_initialized_) {
- LOG4CXX_ERROR(logger_, "TransportManager is not initialized.");
- LOG4CXX_TRACE(
+ LOGGER_ERROR(logger_, "TransportManager is not initialized.");
+ LOGGER_TRACE(
logger_,
"exit with E_TM_IS_NOT_INITIALIZED. Condition: !this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
@@ -173,11 +174,11 @@ int TransportManagerImpl::Disconnect(const ConnectionUID cid) {
sync_primitives::AutoReadLock lock(connections_lock_);
ConnectionInternal* connection = GetConnection(cid);
if (NULL == connection) {
- LOG4CXX_ERROR(
+ LOGGER_ERROR(
logger_,
"TransportManagerImpl::Disconnect: Connection does not exist.");
- LOG4CXX_TRACE(logger_,
- "exit with E_INVALID_HANDLE. Condition: NULL == connection");
+ LOGGER_TRACE(logger_,
+ "exit with E_INVALID_HANDLE. Condition: NULL == connection");
return E_INVALID_HANDLE;
}
@@ -208,44 +209,44 @@ int TransportManagerImpl::Disconnect(const ConnectionUID cid) {
connection->application);
}
*/
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
-int TransportManagerImpl::DisconnectForce(const ConnectionUID cid) {
- LOG4CXX_TRACE(logger_, "enter ConnectionUID: " << &cid);
+int TransportManagerImpl::DisconnectForce(const ConnectionUID& cid) {
+ LOGGER_TRACE(logger_, "enter ConnectionUID: " << &cid);
if (false == this->is_initialized_) {
- LOG4CXX_ERROR(logger_, "TransportManager is not initialized.");
- LOG4CXX_TRACE(logger_,
- "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
- "this->is_initialized_");
+ LOGGER_ERROR(logger_, "TransportManager is not initialized.");
+ LOGGER_TRACE(logger_,
+ "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
+ "this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
sync_primitives::AutoReadLock lock(connections_lock_);
const ConnectionInternal* connection = GetConnection(cid);
if (NULL == connection) {
- LOG4CXX_ERROR(
+ LOGGER_ERROR(
logger_,
"TransportManagerImpl::DisconnectForce: Connection does not exist.");
- LOG4CXX_TRACE(logger_,
- "exit with E_INVALID_HANDLE. Condition: NULL == connection");
+ LOGGER_TRACE(logger_,
+ "exit with E_INVALID_HANDLE. Condition: NULL == connection");
return E_INVALID_HANDLE;
}
connection->transport_adapter->Disconnect(connection->device,
connection->application);
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
int TransportManagerImpl::AddEventListener(TransportManagerListener* listener) {
- LOG4CXX_TRACE(logger_, "enter. TransportManagerListener: " << listener);
+ LOGGER_TRACE(logger_, "enter. TransportManagerListener: " << listener);
transport_manager_listener_.push_back(listener);
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
void TransportManagerImpl::DisconnectAllDevices() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
sync_primitives::AutoReadLock lock(device_list_lock_);
for (DeviceInfoList::iterator i = device_list_.begin();
i != device_list_.end();
@@ -256,7 +257,7 @@ void TransportManagerImpl::DisconnectAllDevices() {
}
void TransportManagerImpl::TerminateAllAdapters() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
for (std::vector<TransportAdapter*>::iterator i = transport_adapters_.begin();
i != transport_adapters_.end();
++i) {
@@ -265,7 +266,7 @@ void TransportManagerImpl::TerminateAllAdapters() {
}
int TransportManagerImpl::InitAllAdapters() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
for (std::vector<TransportAdapter*>::iterator i = transport_adapters_.begin();
i != transport_adapters_.end();
++i) {
@@ -277,9 +278,9 @@ int TransportManagerImpl::InitAllAdapters() {
}
int TransportManagerImpl::Stop() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
if (!is_initialized_) {
- LOG4CXX_WARN(logger_, "TransportManager is not initialized_");
+ LOGGER_WARN(logger_, "TransportManager is not initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
@@ -295,15 +296,14 @@ int TransportManagerImpl::Stop() {
int TransportManagerImpl::SendMessageToDevice(
const ::protocol_handler::RawMessagePtr message) {
- LOG4CXX_TRACE(logger_, "enter. RawMessageSptr: " << message);
- LOG4CXX_INFO(logger_,
- "Send message to device called with arguments "
- << message.get());
+ LOGGER_TRACE(logger_, "enter. RawMessageSptr: " << message);
+ LOGGER_INFO(logger_,
+ "Send message to device called with arguments " << message.get());
if (false == this->is_initialized_) {
- LOG4CXX_ERROR(logger_, "TM is not initialized.");
- LOG4CXX_TRACE(logger_,
- "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
- "this->is_initialized_");
+ LOGGER_ERROR(logger_, "TM is not initialized.");
+ LOGGER_TRACE(logger_,
+ "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
+ "this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
@@ -312,21 +312,21 @@ int TransportManagerImpl::SendMessageToDevice(
const ConnectionInternal* connection =
GetConnection(message->connection_key());
if (NULL == connection) {
- LOG4CXX_ERROR(logger_,
- "Connection with id " << message->connection_key()
- << " does not exist.");
- LOG4CXX_TRACE(
- logger_, "exit with E_INVALID_HANDLE. Condition: NULL == connection");
+ LOGGER_ERROR(logger_,
+ "Connection with id " << message->connection_key()
+ << " does not exist.");
+ LOGGER_TRACE(logger_,
+ "exit with E_INVALID_HANDLE. Condition: NULL == connection");
return E_INVALID_HANDLE;
}
- if (connection->shut_down) {
- LOG4CXX_ERROR(
+ if (connection->shutDown) {
+ LOGGER_ERROR(
logger_,
"TransportManagerImpl::Disconnect: Connection is to shut down.");
- LOG4CXX_TRACE(logger_,
- "exit with E_CONNECTION_IS_TO_SHUTDOWN. Condition: "
- "connection->shutDown");
+ LOGGER_TRACE(logger_,
+ "exit with E_CONNECTION_IS_TO_SHUTDOWN. Condition: "
+ "connection->shutDown");
return E_CONNECTION_IS_TO_SHUTDOWN;
}
}
@@ -336,52 +336,52 @@ int TransportManagerImpl::SendMessageToDevice(
}
#endif // TELEMETRY_MONITOR
this->PostMessage(message);
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
int TransportManagerImpl::ReceiveEventFromDevice(
const TransportAdapterEvent& event) {
- LOG4CXX_TRACE(logger_, "enter. TransportAdapterEvent: " << &event);
+ LOGGER_TRACE(logger_, "enter. TransportAdapterEvent: " << &event);
if (!is_initialized_) {
- LOG4CXX_ERROR(logger_, "TM is not initialized.");
- LOG4CXX_TRACE(logger_,
- "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
- "this->is_initialized_");
+ LOGGER_ERROR(logger_, "TM is not initialized.");
+ LOGGER_TRACE(logger_,
+ "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
+ "this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
this->PostEvent(event);
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
-int TransportManagerImpl::RemoveDevice(const DeviceHandle device_handle) {
- LOG4CXX_TRACE(logger_, "enter. DeviceHandle: " << &device_handle);
+int TransportManagerImpl::RemoveDevice(const DeviceHandle& device_handle) {
+ LOGGER_TRACE(logger_, "enter. DeviceHandle: " << &device_handle);
DeviceUID device_id = converter_.HandleToUid(device_handle);
if (false == this->is_initialized_) {
- LOG4CXX_ERROR(logger_, "TM is not initialized.");
- LOG4CXX_TRACE(logger_,
- "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
- "this->is_initialized_");
+ LOGGER_ERROR(logger_, "TM is not initialized.");
+ LOGGER_TRACE(logger_,
+ "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
+ "this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
sync_primitives::AutoWriteLock lock(device_to_adapter_map_lock_);
device_to_adapter_map_.erase(device_id);
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
int TransportManagerImpl::AddTransportAdapter(
transport_adapter::TransportAdapter* transport_adapter) {
- LOG4CXX_TRACE(logger_, "enter. TransportAdapter: " << transport_adapter);
+ LOGGER_TRACE(logger_, "enter. TransportAdapter: " << transport_adapter);
if (transport_adapter_listeners_.find(transport_adapter) !=
transport_adapter_listeners_.end()) {
- LOG4CXX_ERROR(logger_, "Adapter already exists.");
- LOG4CXX_TRACE(logger_,
- "exit with E_ADAPTER_EXISTS. Condition: "
- "transport_adapter_listeners_.find(transport_adapter) != "
- "transport_adapter_listeners_.end()");
+ LOGGER_ERROR(logger_, "Adapter already exists.");
+ LOGGER_TRACE(logger_,
+ "exit with E_ADAPTER_EXISTS. Condition: "
+ "transport_adapter_listeners_.find(transport_adapter) != "
+ "transport_adapter_listeners_.end()");
return E_ADAPTER_EXISTS;
}
transport_adapter_listeners_[transport_adapter] =
@@ -393,21 +393,21 @@ int TransportManagerImpl::AddTransportAdapter(
transport_adapter->Init() == TransportAdapter::OK) {
transport_adapters_.push_back(transport_adapter);
}
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
int TransportManagerImpl::SearchDevices() {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
if (!this->is_initialized_) {
- LOG4CXX_ERROR(logger_, "TM is not initialized");
- LOG4CXX_TRACE(
+ LOGGER_ERROR(logger_, "TM is not initialized");
+ LOGGER_TRACE(
logger_,
"exit with E_TM_IS_NOT_INITIALIZED. Condition: !this->is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
- LOG4CXX_INFO(logger_, "Search device called");
+ LOGGER_INFO(logger_, "Search device called");
bool success_occurred = false;
@@ -415,33 +415,32 @@ int TransportManagerImpl::SearchDevices() {
transport_adapters_.begin();
it != transport_adapters_.end();
++it) {
- LOG4CXX_DEBUG(logger_, "Iterating over transport adapters");
+ LOGGER_DEBUG(logger_, "Iterating over transport adapters");
TransportAdapter::Error scanResult = (*it)->SearchDevices();
if (transport_adapter::TransportAdapter::OK == scanResult) {
success_occurred = true;
} else {
- LOG4CXX_ERROR(logger_,
- "Transport Adapter search failed "
- << *it << "[" << (*it)->GetDeviceType() << "]");
+ LOGGER_ERROR(logger_,
+ "Transport Adapter search failed "
+ << *it << "[" << (*it)->GetDeviceType() << "]");
switch (scanResult) {
case transport_adapter::TransportAdapter::NOT_SUPPORTED: {
- LOG4CXX_ERROR(logger_,
- "Search feature is not supported "
- << *it << "[" << (*it)->GetDeviceType() << "]");
- LOG4CXX_DEBUG(logger_,
- "scanResult = TransportAdapter::NOT_SUPPORTED");
+ LOGGER_ERROR(logger_,
+ "Search feature is not supported "
+ << *it << "[" << (*it)->GetDeviceType() << "]");
+ LOGGER_DEBUG(logger_, "scanResult = TransportAdapter::NOT_SUPPORTED");
break;
}
case transport_adapter::TransportAdapter::BAD_STATE: {
- LOG4CXX_ERROR(logger_,
- "Transport Adapter has bad state "
- << *it << "[" << (*it)->GetDeviceType() << "]");
- LOG4CXX_DEBUG(logger_, "scanResult = TransportAdapter::BAD_STATE");
+ LOGGER_ERROR(logger_,
+ "Transport Adapter has bad state "
+ << *it << "[" << (*it)->GetDeviceType() << "]");
+ LOGGER_DEBUG(logger_, "scanResult = TransportAdapter::BAD_STATE");
break;
}
default: {
- LOG4CXX_ERROR(logger_, "Invalid scan result");
- LOG4CXX_DEBUG(logger_, "scanResult = default switch case");
+ LOGGER_ERROR(logger_, "Invalid scan result");
+ LOGGER_DEBUG(logger_, "scanResult = default switch case");
return E_ADAPTERS_FAIL;
}
}
@@ -451,28 +450,26 @@ int TransportManagerImpl::SearchDevices() {
(success_occurred || transport_adapters_.empty()) ? E_SUCCESS
: E_ADAPTERS_FAIL;
if (transport_adapter_search == E_SUCCESS) {
- LOG4CXX_TRACE(logger_,
- "exit with E_SUCCESS. Condition: success_occured || "
- "transport_adapters_.empty()");
+ LOGGER_TRACE(logger_,
+ "exit with E_SUCCESS. Condition: success_occured || "
+ "transport_adapters_.empty()");
} else {
- LOG4CXX_TRACE(logger_,
- "exit with E_ADAPTERS_FAIL. Condition: success_occured || "
- "transport_adapters_.empty()");
+ LOGGER_TRACE(logger_,
+ "exit with E_ADAPTERS_FAIL. Condition: success_occured || "
+ "transport_adapters_.empty()");
}
return transport_adapter_search;
}
int TransportManagerImpl::Init(resumption::LastState& last_state) {
- // Last state requred to initialize Transport adapters
- UNUSED(last_state);
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
is_initialized_ = true;
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
int TransportManagerImpl::Reinit() {
- LOG4CXX_AUTO_TRACE(logger_);
+ LOGGER_AUTO_TRACE(logger_);
DisconnectAllDevices();
TerminateAllAdapters();
int ret = InitAllAdapters();
@@ -480,15 +477,15 @@ int TransportManagerImpl::Reinit() {
}
int TransportManagerImpl::Visibility(const bool& on_off) const {
- LOG4CXX_TRACE(logger_, "enter. On_off: " << &on_off);
+ LOGGER_TRACE(logger_, "enter. On_off: " << &on_off);
TransportAdapter::Error ret;
- LOG4CXX_DEBUG(logger_, "Visibility change requested to " << on_off);
+ LOGGER_DEBUG(logger_, "Visibility change requested to " << on_off);
if (!is_initialized_) {
- LOG4CXX_ERROR(logger_, "TM is not initialized");
- LOG4CXX_TRACE(logger_,
- "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
- "is_initialized_");
+ LOGGER_ERROR(logger_, "TM is not initialized");
+ LOGGER_TRACE(logger_,
+ "exit with E_TM_IS_NOT_INITIALIZED. Condition: false == "
+ "is_initialized_");
return E_TM_IS_NOT_INITIALIZED;
}
@@ -502,17 +499,17 @@ int TransportManagerImpl::Visibility(const bool& on_off) const {
ret = (*it)->StopClientListening();
}
if (TransportAdapter::Error::NOT_SUPPORTED == ret) {
- LOG4CXX_DEBUG(logger_,
- "Visibility change is not supported for adapter "
- << *it << "[" << (*it)->GetDeviceType() << "]");
+ LOGGER_DEBUG(logger_,
+ "Visibility change is not supported for adapter "
+ << *it << "[" << (*it)->GetDeviceType() << "]");
}
}
- LOG4CXX_TRACE(logger_, "exit with E_SUCCESS");
+ LOGGER_TRACE(logger_, "exit with E_SUCCESS");
return E_SUCCESS;
}
void TransportManagerImpl::UpdateDeviceList(TransportAdapter* ta) {
- LOG4CXX_TRACE(logger_, "enter. TransportAdapter: " << ta);
+ LOGGER_TRACE(logger_, "enter. TransportAdapter: " << ta);
std::set<DeviceInfo> old_devices;
std::set<DeviceInfo> new_devices;
{
@@ -562,32 +559,32 @@ void TransportManagerImpl::UpdateDeviceList(TransportAdapter* ta) {
++it) {
RaiseEvent(&TransportManagerListener::OnDeviceRemoved, *it);
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportManagerImpl::PostMessage(
const ::protocol_handler::RawMessagePtr message) {
- LOG4CXX_TRACE(logger_, "enter. RawMessageSptr: " << message);
+ LOGGER_TRACE(logger_, "enter. RawMessageSptr: " << message);
message_queue_.PostMessage(message);
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportManagerImpl::PostEvent(const TransportAdapterEvent& event) {
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_DEBUG(logger_, "TransportAdapterEvent: " << &event);
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_, "TransportAdapterEvent: " << &event);
event_queue_.PostMessage(event);
}
void TransportManagerImpl::AddConnection(const ConnectionInternal& c) {
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_DEBUG(logger_, "ConnectionInternal: " << &c);
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_, "ConnectionInternal: " << &c);
sync_primitives::AutoWriteLock lock(connections_lock_);
connections_.push_back(c);
}
void TransportManagerImpl::RemoveConnection(uint32_t id) {
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_DEBUG(logger_, "Id: " << id);
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_, "Id: " << id);
sync_primitives::AutoWriteLock lock(connections_lock_);
for (std::vector<ConnectionInternal>::iterator it = connections_.begin();
it != connections_.end();
@@ -600,14 +597,14 @@ void TransportManagerImpl::RemoveConnection(uint32_t id) {
}
TransportManagerImpl::ConnectionInternal* TransportManagerImpl::GetConnection(
- const ConnectionUID id) {
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_DEBUG(logger_, "ConnectionUID: " << &id);
+ const ConnectionUID& id) {
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_, "ConnectionUID: " << &id);
for (std::vector<ConnectionInternal>::iterator it = connections_.begin();
it != connections_.end();
++it) {
if (it->id == id) {
- LOG4CXX_DEBUG(logger_, "ConnectionInternal. It's address: " << &*it);
+ LOGGER_DEBUG(logger_, "ConnectionInternal. It's address: " << &*it);
return &*it;
}
}
@@ -616,15 +613,15 @@ TransportManagerImpl::ConnectionInternal* TransportManagerImpl::GetConnection(
TransportManagerImpl::ConnectionInternal* TransportManagerImpl::GetConnection(
const DeviceUID& device, const ApplicationHandle& application) {
- LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_DEBUG(logger_,
- "DeviceUID: " << &device
- << "ApplicationHandle: " << &application);
+ LOGGER_AUTO_TRACE(logger_);
+ LOGGER_DEBUG(logger_,
+ "DeviceUID: " << &device
+ << "ApplicationHandle: " << &application);
for (std::vector<ConnectionInternal>::iterator it = connections_.begin();
it != connections_.end();
++it) {
if (it->device == device && it->application == application) {
- LOG4CXX_DEBUG(logger_, "ConnectionInternal. It's address: " << &*it);
+ LOGGER_DEBUG(logger_, "ConnectionInternal. It's address: " << &*it);
return &*it;
}
}
@@ -632,15 +629,16 @@ TransportManagerImpl::ConnectionInternal* TransportManagerImpl::GetConnection(
}
void TransportManagerImpl::OnDeviceListUpdated(TransportAdapter* ta) {
- LOG4CXX_TRACE(logger_, "enter. TransportAdapter: " << ta);
+ LOGGER_TRACE(logger_, "enter. TransportAdapter: " << ta);
const DeviceList device_list = ta->GetDeviceList();
- LOG4CXX_DEBUG(logger_, "DEVICE_LIST_UPDATED " << device_list.size());
+ LOGGER_DEBUG(logger_, "DEVICE_LIST_UPDATED " << device_list.size());
for (DeviceList::const_iterator it = device_list.begin();
it != device_list.end();
++it) {
- device_to_adapter_map_lock_.AcquireForWriting();
- device_to_adapter_map_.insert(std::make_pair(*it, ta));
- device_to_adapter_map_lock_.Release();
+ {
+ sync_primitives::AutoWriteLock lock(device_to_adapter_map_lock_);
+ device_to_adapter_map_.insert(std::make_pair(*it, ta));
+ }
DeviceHandle device_handle = converter_.UidToHandle(*it);
DeviceInfo info(
device_handle, *it, ta->DeviceName(*it), ta->GetConnectionType());
@@ -648,40 +646,43 @@ void TransportManagerImpl::OnDeviceListUpdated(TransportAdapter* ta) {
}
UpdateDeviceList(ta);
std::vector<DeviceInfo> device_infos;
- device_list_lock_.AcquireForReading();
- for (DeviceInfoList::const_iterator it = device_list_.begin();
- it != device_list_.end();
- ++it) {
- device_infos.push_back(it->second);
+
+ {
+ sync_primitives::AutoReadLock lock(device_list_lock_);
+ for (DeviceInfoList::const_iterator it = device_list_.begin();
+ it != device_list_.end();
+ ++it) {
+ device_infos.push_back(it->second);
+ }
}
- device_list_lock_.Release();
+
RaiseEvent(&TransportManagerListener::OnDeviceListUpdated, device_infos);
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
void TransportManagerImpl::Handle(TransportAdapterEvent event) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
switch (event.event_type) {
case TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_DONE: {
RaiseEvent(&TransportManagerListener::OnScanDevicesFinished);
- LOG4CXX_DEBUG(logger_, "event_type = ON_SEARCH_DONE");
+ LOGGER_DEBUG(logger_, "event_type = ON_SEARCH_DONE");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_FAIL: {
// error happened in real search process (external error)
RaiseEvent(&TransportManagerListener::OnScanDevicesFailed,
*static_cast<SearchDeviceError*>(event.event_error.get()));
- LOG4CXX_DEBUG(logger_, "event_type = ON_SEARCH_FAIL");
+ LOGGER_DEBUG(logger_, "event_type = ON_SEARCH_FAIL");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_DEVICE_LIST_UPDATED: {
OnDeviceListUpdated(event.transport_adapter);
- LOG4CXX_DEBUG(logger_, "event_type = ON_DEVICE_LIST_UPDATED");
+ LOGGER_DEBUG(logger_, "event_type = ON_DEVICE_LIST_UPDATED");
break;
}
case TransportAdapterListenerImpl::ON_FIND_NEW_APPLICATIONS_REQUEST: {
RaiseEvent(&TransportManagerListener::OnFindNewApplicationsRequest);
- LOG4CXX_DEBUG(logger_, "event_type = ON_FIND_NEW_APPLICATIONS_REQUEST");
+ LOGGER_DEBUG(logger_, "event_type = ON_FIND_NEW_APPLICATIONS_REQUEST");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_DONE: {
@@ -700,7 +701,7 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
event.transport_adapter->DeviceName(event.device_uid),
event.transport_adapter->GetConnectionType()),
connection_id_counter_);
- LOG4CXX_DEBUG(logger_, "event_type = ON_CONNECT_DONE");
+ LOGGER_DEBUG(logger_, "event_type = ON_CONNECT_DONE");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_CONNECT_FAIL: {
@@ -711,26 +712,25 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
event.transport_adapter->DeviceName(event.device_uid),
event.transport_adapter->GetConnectionType()),
ConnectError());
- LOG4CXX_DEBUG(logger_, "event_type = ON_CONNECT_FAIL");
+ LOGGER_DEBUG(logger_, "event_type = ON_CONNECT_FAIL");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_DONE: {
- connections_lock_.AcquireForReading();
- ConnectionInternal* connection =
- GetConnection(event.device_uid, event.application_id);
- if (NULL == connection) {
- LOG4CXX_ERROR(logger_, "Connection not found");
- LOG4CXX_DEBUG(logger_,
- "event_type = ON_DISCONNECT_DONE && NULL == connection");
- connections_lock_.Release();
- break;
+ ConnectionUID id = 0;
+ {
+ sync_primitives::AutoReadLock lock(connections_lock_);
+ ConnectionInternal* connection =
+ GetConnection(event.device_uid, event.application_id);
+ if (!connection) {
+ LOGGER_DEBUG(logger_,
+ "event_type = ON_DISCONNECT_DONE && NULL == connection");
+ break;
+ }
+ id = connection->id;
}
- const ConnectionUID id = connection->id;
- connections_lock_.Release();
-
RaiseEvent(&TransportManagerListener::OnConnectionClosed, id);
RemoveConnection(id);
- LOG4CXX_DEBUG(logger_, "event_type = ON_DISCONNECT_DONE");
+ LOGGER_DEBUG(logger_, "event_type = ON_DISCONNECT_DONE");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_DISCONNECT_FAIL: {
@@ -739,7 +739,7 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
RaiseEvent(&TransportManagerListener::OnDisconnectFailed,
device_handle,
DisconnectDeviceError());
- LOG4CXX_DEBUG(logger_, "event_type = ON_DISCONNECT_FAIL");
+ LOGGER_DEBUG(logger_, "event_type = ON_DISCONNECT_FAIL");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_DONE: {
@@ -752,21 +752,21 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
ConnectionInternal* connection =
GetConnection(event.device_uid, event.application_id);
if (connection == NULL) {
- LOG4CXX_ERROR(logger_,
- "Connection ('" << event.device_uid << ", "
- << event.application_id << ") not found");
- LOG4CXX_DEBUG(
+ LOGGER_ERROR(logger_,
+ "Connection ('" << event.device_uid << ", "
+ << event.application_id << ") not found");
+ LOGGER_DEBUG(
logger_,
"event_type = ON_SEND_DONE. Condition: NULL == connection");
break;
}
RaiseEvent(&TransportManagerListener::OnTMMessageSend, event.event_data);
- if (connection->shut_down && --connection->messages_count == 0) {
- connection->timer->Stop();
+ if (connection->shutDown && --connection->messages_count == 0) {
+ connection->timer->stop();
connection->transport_adapter->Disconnect(connection->device,
connection->application);
}
- LOG4CXX_DEBUG(logger_, "event_type = ON_SEND_DONE");
+ LOGGER_DEBUG(logger_, "event_type = ON_SEND_DONE");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_SEND_FAIL: {
@@ -780,11 +780,11 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
ConnectionInternal* connection =
GetConnection(event.device_uid, event.application_id);
if (connection == NULL) {
- LOG4CXX_ERROR(logger_,
- "Connection ('" << event.device_uid << ", "
- << event.application_id
- << ") not found");
- LOG4CXX_DEBUG(
+ LOGGER_ERROR(logger_,
+ "Connection ('" << event.device_uid << ", "
+ << event.application_id
+ << ") not found");
+ LOGGER_DEBUG(
logger_,
"event_type = ON_SEND_FAIL. Condition: NULL == connection");
break;
@@ -793,15 +793,15 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
// TODO(YK): start timer here to wait before notify caller
// and remove unsent messages
- LOG4CXX_ERROR(logger_, "Transport adapter failed to send data");
+ LOGGER_ERROR(logger_, "Transport adapter failed to send data");
// TODO(YK): potential error case -> thread unsafe
// update of message content
if (event.event_data.valid()) {
event.event_data->set_waiting(true);
} else {
- LOG4CXX_DEBUG(logger_, "Data is invalid");
+ LOGGER_DEBUG(logger_, "Data is invalid");
}
- LOG4CXX_DEBUG(logger_, "eevent_type = ON_SEND_FAIL");
+ LOGGER_DEBUG(logger_, "eevent_type = ON_SEND_FAIL");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_DONE: {
@@ -810,11 +810,11 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
ConnectionInternal* connection =
GetConnection(event.device_uid, event.application_id);
if (connection == NULL) {
- LOG4CXX_ERROR(logger_,
- "Connection ('" << event.device_uid << ", "
- << event.application_id
- << ") not found");
- LOG4CXX_DEBUG(
+ LOGGER_ERROR(logger_,
+ "Connection ('" << event.device_uid << ", "
+ << event.application_id
+ << ") not found");
+ LOGGER_DEBUG(
logger_,
"event_type = ON_RECEIVED_DONE. Condition: NULL == connection");
break;
@@ -828,70 +828,75 @@ void TransportManagerImpl::Handle(TransportAdapterEvent event) {
#endif // TELEMETRY_MONITOR
RaiseEvent(&TransportManagerListener::OnTMMessageReceived,
event.event_data);
- LOG4CXX_DEBUG(logger_, "event_type = ON_RECEIVED_DONE");
+ LOGGER_DEBUG(logger_, "event_type = ON_RECEIVED_DONE");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_RECEIVED_FAIL: {
- LOG4CXX_DEBUG(logger_, "Event ON_RECEIVED_FAIL");
- connections_lock_.AcquireForReading();
- ConnectionInternal* connection =
- GetConnection(event.device_uid, event.application_id);
- if (connection == NULL) {
- LOG4CXX_ERROR(logger_,
- "Connection ('" << event.device_uid << ", "
- << event.application_id << ") not found");
- connections_lock_.Release();
- break;
+ LOGGER_DEBUG(logger_, "Event ON_RECEIVED_FAIL");
+ ConnectionUID connection_id = 0;
+ {
+ sync_primitives::AutoReadLock lock(connections_lock_);
+ ConnectionInternal* connection =
+ GetConnection(event.device_uid, event.application_id);
+ if (!connection) {
+ LOGGER_ERROR(logger_,
+ "Connection ('" << event.device_uid << ", "
+ << event.application_id
+ << ") not found");
+ break;
+ }
+ connection_id = connection->id;
}
- connections_lock_.Release();
-
RaiseEvent(&TransportManagerListener::OnTMMessageReceiveFailed,
+ connection_id,
*static_cast<DataReceiveError*>(event.event_error.get()));
- LOG4CXX_DEBUG(logger_, "event_type = ON_RECEIVED_FAIL");
+ LOGGER_DEBUG(logger_, "event_type = ON_RECEIVED_FAIL");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::ON_COMMUNICATION_ERROR: {
- LOG4CXX_DEBUG(logger_, "event_type = ON_COMMUNICATION_ERROR");
+ LOGGER_DEBUG(logger_, "event_type = ON_COMMUNICATION_ERROR");
break;
}
case TransportAdapterListenerImpl::EventTypeEnum::
ON_UNEXPECTED_DISCONNECT: {
- connections_lock_.AcquireForReading();
- ConnectionInternal* connection =
- GetConnection(event.device_uid, event.application_id);
- if (connection) {
- const ConnectionUID id = connection->id;
- connections_lock_.Release();
- RaiseEvent(&TransportManagerListener::OnUnexpectedDisconnect,
- id,
- *static_cast<CommunicationError*>(event.event_error.get()));
- RemoveConnection(id);
- } else {
- connections_lock_.Release();
- LOG4CXX_ERROR(logger_,
- "Connection ('" << event.device_uid << ", "
- << event.application_id << ") not found");
+ ConnectionUID connection_id = 0;
+ {
+ sync_primitives::AutoReadLock lock(connections_lock_);
+ ConnectionInternal* connection =
+ GetConnection(event.device_uid, event.application_id);
+ if (!connection) {
+ LOGGER_ERROR(logger_,
+ "Connection ('" << event.device_uid << ", "
+ << event.application_id
+ << ") not found");
+ break;
+ }
+ connection_id = connection->id;
}
- LOG4CXX_DEBUG(logger_, "eevent_type = ON_UNEXPECTED_DISCONNECT");
+ RaiseEvent(&TransportManagerListener::OnUnexpectedDisconnect,
+ connection_id,
+ *static_cast<CommunicationError*>(event.event_error.get()));
+ RemoveConnection(connection_id);
+ LOGGER_DEBUG(logger_, "eevent_type = ON_UNEXPECTED_DISCONNECT");
break;
}
} // switch
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
#ifdef TELEMETRY_MONITOR
-void TransportManagerImpl::SetTelemetryObserver(TMTelemetryObserver* observer) {
+void TransportManagerImpl::SetTimeMetricObserver(TMMetricObserver* observer) {
metric_observer_ = observer;
}
#endif // TELEMETRY_MONITOR
void TransportManagerImpl::Handle(::protocol_handler::RawMessagePtr msg) {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
sync_primitives::AutoReadLock lock(connections_lock_);
ConnectionInternal* connection = GetConnection(msg->connection_key());
if (connection == NULL) {
- LOG4CXX_WARN(logger_,
- "Connection " << msg->connection_key() << " not found");
+ LOGGER_WARN(logger_,
+ "Connection " << msg->connection_key() << " not found");
RaiseEvent(&TransportManagerListener::OnTMMessageSendFailed,
DataSendTimeoutError(),
msg);
@@ -899,14 +904,14 @@ void TransportManagerImpl::Handle(::protocol_handler::RawMessagePtr msg) {
}
TransportAdapter* transport_adapter = connection->transport_adapter;
- LOG4CXX_DEBUG(logger_,
- "Got adapter " << transport_adapter << "["
- << transport_adapter->GetDeviceType() << "]"
- << " by session id " << msg->connection_key());
+ LOGGER_DEBUG(logger_,
+ "Got adapter " << transport_adapter << "["
+ << transport_adapter->GetDeviceType() << "]"
+ << " by session id " << msg->connection_key());
if (NULL == transport_adapter) {
std::string error_text = "Transport adapter is not found";
- LOG4CXX_ERROR(logger_, error_text);
+ LOGGER_ERROR(logger_, error_text);
RaiseEvent(&TransportManagerListener::OnTMMessageSendFailed,
DataSendError(error_text),
msg);
@@ -914,30 +919,30 @@ void TransportManagerImpl::Handle(::protocol_handler::RawMessagePtr msg) {
if (TransportAdapter::OK ==
transport_adapter->SendData(
connection->device, connection->application, msg)) {
- LOG4CXX_TRACE(logger_, "Data sent to adapter");
+ LOGGER_TRACE(logger_, "Data sent to adapter");
} else {
- LOG4CXX_ERROR(logger_, "Data sent error");
+ LOGGER_ERROR(logger_, "Data sent error");
RaiseEvent(&TransportManagerListener::OnTMMessageSendFailed,
DataSendError("Send failed"),
msg);
}
}
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
TransportManagerImpl::ConnectionInternal::ConnectionInternal(
TransportManagerImpl* transport_manager,
TransportAdapter* transport_adapter,
- const ConnectionUID id,
+ const ConnectionUID& id,
const DeviceUID& dev_id,
const ApplicationHandle& app_id,
- const DeviceHandle device_handle)
+ const DeviceHandle& device_handle)
: transport_manager(transport_manager)
, transport_adapter(transport_adapter)
, timer(utils::MakeShared<timer::Timer>(
- "TM DiscRoutine",
- new ::timer::TimerTaskImpl<ConnectionInternal>(
- this, &ConnectionInternal::DisconnectFailedRoutine)))
+ "TM DiscRoutine",
+ new ::timer::TimerTaskImpl<ConnectionInternal>(
+ this, &ConnectionInternal::DisconnectFailedRoutine)))
, shut_down(false)
, device_handle_(device_handle)
, messages_count(0) {
@@ -947,13 +952,13 @@ TransportManagerImpl::ConnectionInternal::ConnectionInternal(
}
void TransportManagerImpl::ConnectionInternal::DisconnectFailedRoutine() {
- LOG4CXX_TRACE(logger_, "enter");
+ LOGGER_TRACE(logger_, "enter");
transport_manager->RaiseEvent(&TransportManagerListener::OnDisconnectFailed,
device_handle_,
DisconnectDeviceError());
shut_down = false;
timer->Stop();
- LOG4CXX_TRACE(logger_, "exit");
+ LOGGER_TRACE(logger_, "exit");
}
} // namespace transport_manager