#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include "utils/logger.h"
#include "transport_manager/transport_adapter/threaded_socket_connection.h"
#include "transport_manager/transport_adapter/transport_adapter_controller.h"
namespace transport_manager {
namespace transport_adapter {
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportAdapterImpl")
+
ThreadedSocketConnection::ThreadedSocketConnection(
const DeviceUID& device_id, const ApplicationHandle& app_handle,
TransportAdapterController* controller)
}
// receive data
- if (0 != (poll_fds[0].revents & (POLLIN | POLLPRI))) {
+ if (0 != poll_fds[0].revents & (POLLIN | POLLPRI)) {
const bool receive_ok = Receive();
if (!receive_ok) {
LOG4CXX_INFO(logger_, "Receive() failed (#" << pthread_self() << ")");
-/**
- * \file transport_adapter_impl.cc
- * \brief TransportAdapterImpl class source file.
- * Copyright (c) 2013, Ford Motor Company
+/*
+ * Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "config_profile/profile.h"
+#include "utils/logger.h"
+
#include "transport_manager/transport_adapter/transport_adapter_impl.h"
#include "transport_manager/transport_adapter/transport_adapter_listener.h"
#include "transport_manager/transport_adapter/device_scanner.h"
#include "transport_manager/transport_adapter/client_connection_listener.h"
namespace transport_manager {
-
namespace transport_adapter {
-log4cxx::LoggerPtr logger_ =
- log4cxx::LoggerPtr(log4cxx::Logger::getLogger("TransportManager"));
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportAdapterImpl")
TransportAdapterImpl::TransportAdapterImpl(
DeviceScanner* device_scanner,
pthread_mutex_unlock(&connections_mutex_);
}
+void TransportAdapterImpl::DeviceDisconnected(const DeviceUID& device_handle,
+ const DisconnectDeviceError& error) {
+
+ ApplicationList app_list = GetApplicationList(device_handle);
+ for (ApplicationList::const_iterator i = app_list.begin(); i != app_list.end(); ++i) {
+ ApplicationHandle app_handle = *i;
+ for (TransportAdapterListenerList::iterator it = listeners_.begin(); it != listeners_.end(); ++it) {
+ TransportAdapterListener* listener = *it;
+ listener->OnUnexpectedDisconnect(this, device_handle, app_handle, CommunicationError());
+ }
+ }
+
+ pthread_mutex_lock(&connections_mutex_);
+ for (TransportAdapterListenerList::iterator it = listeners_.begin(); it != listeners_.end(); ++it) {
+ TransportAdapterListener* listener = *it;
+ listener->OnDisconnectDeviceDone(this, device_handle);
+ }
+ for (ApplicationList::const_iterator i = app_list.begin(); i != app_list.end(); ++i) {
+ ApplicationHandle app_handle = *i;
+ connections_.erase(std::make_pair(device_handle, app_handle));
+ }
+ pthread_mutex_unlock(&connections_mutex_);
+
+ RemoveDevice(device_handle);
+}
+
void TransportAdapterImpl::DisconnectDone(const DeviceUID& device_id,
const ApplicationHandle& app_handle) {
bool device_disconnected = true;
pthread_mutex_unlock(&connections_mutex_);
if (device_disconnected) {
- pthread_mutex_lock(&devices_mutex_);
- DeviceMap::iterator it = devices_.find(device_id); //ykazakov: there is no erase for const iterator for QNX
- if (it != devices_.end()) {
- DeviceSptr device = it->second;
- if (!device->keep_on_disconnect()) {
- devices_.erase(it);
- for (TransportAdapterListenerList::iterator it = listeners_.begin();
- it != listeners_.end(); ++it) {
- (*it)->OnDeviceListUpdated(this);
- }
- }
- }
- pthread_mutex_unlock(&devices_mutex_);
+ RemoveDevice(device_id);
}
Store();
return errors_occured ? OK : FAIL;
}
+void TransportAdapterImpl::RemoveDevice(const DeviceUID& device_handle) {
+ pthread_mutex_lock(&devices_mutex_);
+ DeviceMap::iterator i = devices_.find(device_handle); //ykazakov: there is no erase for const iterator on QNX
+ if (i != devices_.end()) {
+ DeviceSptr device = i->second;
+ if (!device->keep_on_disconnect()) {
+ devices_.erase(i);
+ for (TransportAdapterListenerList::iterator it = listeners_.begin(); it != listeners_.end(); ++it) {
+ TransportAdapterListener* listener = *it;
+ listener->OnDeviceListUpdated(this);
+ }
+ }
+ }
+ pthread_mutex_unlock(&devices_mutex_);
+}
+
} // namespace transport_adapter
} // namespace transport_manager