summaryrefslogtreecommitdiff
path: root/src/components/connection_handler
diff options
context:
space:
mode:
authorfronneburg <fronneburg@xevo.com>2018-04-18 14:30:41 -0700
committerfronneburg <fronneburg@xevo.com>2018-04-19 14:05:19 -0700
commit87cd3ea8aa30d9a5635b5fa2aea11696bdd75016 (patch)
tree636ef1f7ffe02d178b94a43bedd10989a4ea7281 /src/components/connection_handler
parentc9a7e92cd50a791c096634a62d5fd9dbad2ea0e9 (diff)
downloadsdl_core-87cd3ea8aa30d9a5635b5fa2aea11696bdd75016.tar.gz
alignment and style check
Diffstat (limited to 'src/components/connection_handler')
-rw-r--r--src/components/connection_handler/include/connection_handler/connection.h26
-rw-r--r--src/components/connection_handler/include/connection_handler/connection_handler_impl.h20
-rw-r--r--src/components/connection_handler/src/connection.cc93
-rw-r--r--src/components/connection_handler/src/connection_handler_impl.cc255
-rw-r--r--src/components/connection_handler/test/connection_test.cc9
-rw-r--r--src/components/connection_handler/test/heart_beat_monitor_test.cc41
6 files changed, 282 insertions, 162 deletions
diff --git a/src/components/connection_handler/include/connection_handler/connection.h b/src/components/connection_handler/include/connection_handler/connection.h
index df50f8899c..2b5ba3e82d 100644
--- a/src/components/connection_handler/include/connection_handler/connection.h
+++ b/src/components/connection_handler/include/connection_handler/connection.h
@@ -171,7 +171,8 @@ class Connection {
* @param connection_handle Connection Handle for the session
* @return new session id or 0 in case of issues
*/
- uint32_t AddNewSession(const transport_manager::ConnectionUID connection_handle);
+ uint32_t AddNewSession(
+ const transport_manager::ConnectionUID connection_handle);
/**
* @brief Removes session from connection
@@ -189,8 +190,8 @@ class Connection {
* @return TRUE on success, otherwise FALSE
*/
DEPRECATED bool AddNewService(uint8_t session_id,
- protocol_handler::ServiceType service_type,
- const bool is_protected);
+ protocol_handler::ServiceType service_type,
+ const bool is_protected);
/**
* @brief Adds uprotected service to session or
@@ -216,12 +217,14 @@ class Connection {
/**
* @brief Removes secondary service from session
- * @param secondary_connection_handle connection identifying services to be removed
+ * @param secondary_connection_handle connection identifying services to be
+ * removed
* \param removed_services_list Returned: List of service types removed
* @return the session ID associated with the services removed
*/
- uint8_t RemoveSecondaryServices(transport_manager::ConnectionUID secondary_connection_handle,
- std::list<protocol_handler::ServiceType>& removed_services_list);
+ uint8_t RemoveSecondaryServices(
+ transport_manager::ConnectionUID secondary_connection_handle,
+ std::list<protocol_handler::ServiceType>& removed_services_list);
#ifdef ENABLE_SECURITY
/**
@@ -252,9 +255,10 @@ class Connection {
const protocol_handler::ServiceType& service_type);
#endif // ENABLE_SECURITY
+
/**
* @brief Returns map of sessions which have been opened in
- * current connection.
+ * current connection.
*/
const SessionMap session_map() const;
@@ -323,18 +327,18 @@ class Connection {
bool ProtocolVersion(uint8_t session_id, uint8_t& protocol_version);
/**
- * @brief Returns the primary connection handle associated with this connection
+ * @brief Returns the primary connection handle associated with this
+ * connection
* @return ConnectionHandle
*/
ConnectionHandle primary_connection_handle() const;
/**
* \brief Sets the primary connection handle
- * \param primary_connection_handle the primary connection handle to
+ * \param primary_connection_handle the primary connection handle to
* associate with this connection
*/
- void SetPrimaryConnectionHandle(
- ConnectionHandle primary_connection_handle);
+ void SetPrimaryConnectionHandle(ConnectionHandle primary_connection_handle);
private:
/**
diff --git a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h
index 16ee314ee4..592b8d9cfd 100644
--- a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h
+++ b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h
@@ -538,11 +538,12 @@ class ConnectionHandlerImpl
/**
* \brief Associate a secondary transport ID with a session
* \param session_id the session ID
- * \param connection_id the new secondary connection ID to associate with the session
+ * \param connection_id the new secondary connection ID to associate with the
+ * session
* \return the SessionTransports (newly) associated with the session
**/
SessionTransports SetSecondaryTransportID(
- uint8_t session_id,
+ uint8_t session_id,
transport_manager::ConnectionUID secondary_transport_id) OVERRIDE;
/**
@@ -550,7 +551,8 @@ class ConnectionHandlerImpl
* \param session_id the session ID
* \return the SessionTransports associated with the session
**/
- const SessionTransports GetSessionTransports(uint8_t session_id) const OVERRIDE;
+ const SessionTransports GetSessionTransports(
+ uint8_t session_id) const OVERRIDE;
/**
* \brief Invoked when observer's OnServiceStartedCallback is completed
@@ -575,18 +577,20 @@ class ConnectionHandlerImpl
* \param sessionid session ID taken from Register Secondary Transport frame
**/
bool OnSecondaryTransportStarted(
- transport_manager::ConnectionUID &primary_connection_handle,
+ transport_manager::ConnectionUID& primary_connection_handle,
const transport_manager::ConnectionUID secondary_connection_handle,
const uint8_t session_id) OVERRIDE;
/**
* \brief Called when secondary transport shuts down
* \param primary_connection_handle Identifier of primary connection
- * \param secondary_connection_handle Identifier of secondary connection transport
+ * \param secondary_connection_handle Identifier of secondary connection
+ * transport
**/
void OnSecondaryTransportEnded(
const transport_manager::ConnectionUID primary_connection_handle,
- const transport_manager::ConnectionUID secondary_connection_handle) OVERRIDE;
+ const transport_manager::ConnectionUID secondary_connection_handle)
+ OVERRIDE;
private:
/**
@@ -600,7 +604,7 @@ class ConnectionHandlerImpl
void OnConnectionEnded(const transport_manager::ConnectionUID connection_id);
const uint8_t GetSessionIdFromSecondaryTransport(
- transport_manager::ConnectionUID secondary_transport_id) const;
+ transport_manager::ConnectionUID secondary_transport_id) const;
const ConnectionHandlerSettings& settings_;
/**
@@ -649,7 +653,7 @@ class ConnectionHandlerImpl
/**
* @brief connection object as it's being closed
*/
- Connection *ending_connection_;
+ Connection* ending_connection_;
#ifdef BUILD_TESTS
// Methods for test usage
diff --git a/src/components/connection_handler/src/connection.cc b/src/components/connection_handler/src/connection.cc
index 0729e00a64..0952279143 100644
--- a/src/components/connection_handler/src/connection.cc
+++ b/src/components/connection_handler/src/connection.cc
@@ -101,13 +101,20 @@ Connection::~Connection() {
// Before clearing out the session_map_, we must remove all sessions
// associated with this Connection from the SessionConnectionMap.
- NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor = connection_handler_->session_connection_map();
- SessionConnectionMap& session_connection_map = session_connection_map_accessor.GetData();
+ NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor =
+ connection_handler_->session_connection_map();
+ SessionConnectionMap& session_connection_map =
+ session_connection_map_accessor.GetData();
sync_primitives::AutoLock lock(session_map_lock_);
SessionMap::iterator session_it = session_map_.begin();
while (session_it != session_map_.end()) {
- LOG4CXX_INFO(logger_, "Removed Session ID " << static_cast<int>(session_it->first) << " from Session/Connection Map in Connection Destructor");
- SessionConnectionMap::iterator itr = session_connection_map.find(session_it->first);
+ LOG4CXX_INFO(
+ logger_,
+ "Removed Session ID "
+ << static_cast<int>(session_it->first)
+ << " from Session/Connection Map in Connection Destructor");
+ SessionConnectionMap::iterator itr =
+ session_connection_map.find(session_it->first);
if (session_connection_map.end() != itr) {
session_connection_map.erase(session_it->first);
}
@@ -131,7 +138,7 @@ uint32_t findGap(const std::map<unsigned char, T>& map) {
}
} // namespace
-DEPRECATED uint32_t Connection::AddNewSession(){
+DEPRECATED uint32_t Connection::AddNewSession() {
return AddNewSession(0);
}
@@ -139,40 +146,54 @@ uint32_t Connection::AddNewSession(
const transport_manager::ConnectionUID connection_handle) {
LOG4CXX_AUTO_TRACE(logger_);
- // Even though we have our own SessionMap, we use the Connection Handler's SessionConnectionMap to generate a
- // session ID. We want to make sure that session IDs are globally unique, and not only unique within a Connection.
- NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor = connection_handler_->session_connection_map();
- SessionConnectionMap& session_connection_map = session_connection_map_accessor.GetData();
+ // Even though we have our own SessionMap, we use the Connection Handler's
+ // SessionConnectionMap to generate a session ID. We want to make sure that
+ // session IDs are globally unique, and not only unique within a Connection.
+ NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor =
+ connection_handler_->session_connection_map();
+ SessionConnectionMap& session_connection_map =
+ session_connection_map_accessor.GetData();
const uint32_t session_id = findGap(session_connection_map);
if (session_id > 0) {
- LOG4CXX_INFO(logger_, "New session ID " << session_id << " and Connection Id " << static_cast<int>(connection_handle) << " added to Session/Connection Map");
+ LOG4CXX_INFO(logger_,
+ "New session ID " << session_id << " and Connection Id "
+ << static_cast<int>(connection_handle)
+ << " added to Session/Connection Map");
SessionTransports st;
st.primary_transport = connection_handle;
st.secondary_transport = 0;
session_connection_map[session_id] = st;
- // NESTED LOCK: make sure to never lock the ConnectionHandler's SessionConnectedMap inside of the "session_map_lock_"
+ // NESTED LOCK: make sure to never lock the ConnectionHandler's
+ // SessionConnectedMap inside of the "session_map_lock_"
sync_primitives::AutoLock lock(session_map_lock_);
Session& new_session = session_map_[session_id];
new_session.protocol_version = ::protocol_handler::PROTOCOL_VERSION_2;
- new_session.service_list.push_back(Service(protocol_handler::kRpc, connection_handle));
- new_session.service_list.push_back(Service(protocol_handler::kBulk, connection_handle));
+ new_session.service_list.push_back(
+ Service(protocol_handler::kRpc, connection_handle));
+ new_session.service_list.push_back(
+ Service(protocol_handler::kBulk, connection_handle));
} else {
- LOG4CXX_WARN(logger_, "Session/Connection Map could not create a new session ID!!!");
+ LOG4CXX_WARN(logger_,
+ "Session/Connection Map could not create a new session ID!!!");
}
return session_id;
}
uint32_t Connection::RemoveSession(uint8_t session_id) {
- NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor = connection_handler_->session_connection_map();
- SessionConnectionMap& session_connection_map = session_connection_map_accessor.GetData();
+ NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor =
+ connection_handler_->session_connection_map();
+ SessionConnectionMap& session_connection_map =
+ session_connection_map_accessor.GetData();
SessionConnectionMap::iterator itr = session_connection_map.find(session_id);
if (session_connection_map.end() == itr) {
LOG4CXX_WARN(logger_, "Session not found in Session/Connection Map!");
return 0;
} else {
- LOG4CXX_INFO(logger_, "Removed Session ID " << static_cast<int>(session_id) << " from Session/Connection Map");
+ LOG4CXX_INFO(logger_,
+ "Removed Session ID " << static_cast<int>(session_id)
+ << " from Session/Connection Map");
session_connection_map.erase(session_id);
// Again, a NESTED lock, but it follows the rules.
@@ -189,9 +210,10 @@ uint32_t Connection::RemoveSession(uint8_t session_id) {
return session_id;
}
-DEPRECATED bool Connection::AddNewService(uint8_t session_id,
- protocol_handler::ServiceType service_type,
- const bool request_protection) {
+DEPRECATED bool Connection::AddNewService(
+ uint8_t session_id,
+ protocol_handler::ServiceType service_type,
+ const bool request_protection) {
return AddNewService(session_id, service_type, request_protection, 0);
}
@@ -304,14 +326,17 @@ bool Connection::RemoveService(uint8_t session_id,
return true;
}
-uint8_t Connection::RemoveSecondaryServices(transport_manager::ConnectionUID secondary_connection_handle,
- std::list<protocol_handler::ServiceType>& removed_services_list) {
+uint8_t Connection::RemoveSecondaryServices(
+ transport_manager::ConnectionUID secondary_connection_handle,
+ std::list<protocol_handler::ServiceType>& removed_services_list) {
LOG4CXX_AUTO_TRACE(logger_);
uint8_t found_session_id = 0;
sync_primitives::AutoLock lock(session_map_lock_);
- LOG4CXX_INFO(logger_, "RemoveSecondaryServices looking for services on Connection ID " << static_cast<int>(secondary_connection_handle));
+ LOG4CXX_INFO(logger_,
+ "RemoveSecondaryServices looking for services on Connection ID "
+ << static_cast<int>(secondary_connection_handle));
// Walk the SessionMap in the primary connection, and for each
// Session, we walk its ServiceList, looking for all the services
@@ -319,22 +344,27 @@ uint8_t Connection::RemoveSecondaryServices(transport_manager::ConnectionUID sec
for (SessionMap::iterator session_it = session_map_.begin();
session_map_.end() != session_it;
++session_it) {
-
- LOG4CXX_INFO(logger_, "RemoveSecondaryServices found session ID " << static_cast<int>(session_it->first));
+ LOG4CXX_INFO(logger_,
+ "RemoveSecondaryServices found session ID "
+ << static_cast<int>(session_it->first));
// Now, for each session, walk the its ServiceList, looking for services
// that were using secondary)_connection_handle. If we find such a service,
// set session_found and break out of the outer loop.
ServiceList& service_list = session_it->second.service_list;
ServiceList::iterator service_it = service_list.begin();
- for ( ; service_it != service_list.end() ; ) {
- LOG4CXX_INFO(logger_, "RemoveSecondaryServices found service ID " << static_cast<int>(service_it->service_type));
+ for (; service_it != service_list.end();) {
+ LOG4CXX_INFO(logger_,
+ "RemoveSecondaryServices found service ID "
+ << static_cast<int>(service_it->service_type));
if (service_it->connection_id == secondary_connection_handle) {
found_session_id = session_it->first;
- LOG4CXX_INFO(logger_, "RemoveSecondaryServices removing Service " <<
- static_cast<int>(service_it->service_type) <<
- " in session " << static_cast<int>(found_session_id));
+ LOG4CXX_INFO(logger_,
+ "RemoveSecondaryServices removing Service "
+ << static_cast<int>(service_it->service_type)
+ << " in session "
+ << static_cast<int>(found_session_id));
removed_services_list.push_back(service_it->service_type);
service_it = service_list.erase(service_it);
@@ -343,7 +373,8 @@ uint8_t Connection::RemoveSecondaryServices(transport_manager::ConnectionUID sec
}
}
- // If we found a session that had services running on the secondary connection, we're done.
+ // If we found a session that had services running on the secondary
+ // connection, we're done.
if (found_session_id != 0) {
break;
}
diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc
index 5b9c3e892c..a84841c34a 100644
--- a/src/components/connection_handler/src/connection_handler_impl.cc
+++ b/src/components/connection_handler/src/connection_handler_impl.cc
@@ -372,7 +372,8 @@ uint32_t ConnectionHandlerImpl::OnSessionStartedCallback(
*hash_id = KeyFromPair(connection_handle, new_session_id);
}
} else { // Could be create new service or protected exists one
- if (!connection->AddNewService(session_id, service_type, is_protected, connection_handle)) {
+ if (!connection->AddNewService(
+ session_id, service_type, is_protected, connection_handle)) {
LOG4CXX_ERROR(logger_,
"Couldn't establish "
#ifdef ENABLE_SECURITY
@@ -416,19 +417,26 @@ void ConnectionHandlerImpl::OnSessionStartedCallback(
std::vector<std::string> rejected_params;
- // In case this is a Session running on a Secondary Transport, we need to
+ // In case this is a Session running on a Secondary Transport, we need to
// find the Sessions's primary transport. In this case, "connection_handle"
// reflects the secondary transport, which we need for the various callbacks,
// so they can send appropriate Ack or NAK messages on the correct transport.
- transport_manager::ConnectionUID primary_connection_handle = connection_handle;
+ transport_manager::ConnectionUID primary_connection_handle =
+ connection_handle;
if (session_id != 0) {
SessionTransports st = GetSessionTransports(session_id);
if (st.primary_transport == 0) {
- LOG4CXX_WARN(logger_, "OnSessionStartedCallback could not find Session in the Session/Connection Map!");
+ LOG4CXX_WARN(logger_,
+ "OnSessionStartedCallback could not find Session in the "
+ "Session/Connection Map!");
} else {
- LOG4CXX_INFO(logger_, "OnSessionStartedCallback found session " << static_cast<int>(session_id) <<
- " with primary connection " << static_cast<int>(st.primary_transport) <<
- " and secondary connection " << static_cast<int>(st.secondary_transport));
+ LOG4CXX_INFO(logger_,
+ "OnSessionStartedCallback found session "
+ << static_cast<int>(session_id)
+ << " with primary connection "
+ << static_cast<int>(st.primary_transport)
+ << " and secondary connection "
+ << static_cast<int>(st.secondary_transport));
primary_connection_handle = st.primary_transport;
}
}
@@ -448,7 +456,8 @@ void ConnectionHandlerImpl::OnSessionStartedCallback(
}
#endif // ENABLE_SECURITY
sync_primitives::AutoReadLock lock(connection_list_lock_);
- ConnectionList::iterator it = connection_list_.find(primary_connection_handle);
+ ConnectionList::iterator it =
+ connection_list_.find(primary_connection_handle);
if (connection_list_.end() == it) {
LOG4CXX_ERROR(logger_, "Unknown connection!");
protocol_handler_->NotifySessionStarted(context, rejected_params);
@@ -463,15 +472,18 @@ void ConnectionHandlerImpl::OnSessionStartedCallback(
#endif // ENABLE_SECURITY
if ((0 == session_id) && (protocol_handler::kRpc == service_type)) {
- context.new_session_id_ = connection->AddNewSession(primary_connection_handle);
+ context.new_session_id_ =
+ connection->AddNewSession(primary_connection_handle);
if (0 == context.new_session_id_) {
LOG4CXX_ERROR(logger_, "Couldn't start new session!");
protocol_handler_->NotifySessionStarted(context, rejected_params);
return;
}
- context.hash_id_ = KeyFromPair(primary_connection_handle, context.new_session_id_);
+ context.hash_id_ =
+ KeyFromPair(primary_connection_handle, context.new_session_id_);
} else { // Could be create new service or protected exists one
- if (!connection->AddNewService(session_id, service_type, is_protected, connection_handle)) {
+ if (!connection->AddNewService(
+ session_id, service_type, is_protected, connection_handle)) {
LOG4CXX_ERROR(logger_,
"Couldn't establish "
#ifdef ENABLE_SECURITY
@@ -539,7 +551,8 @@ void ConnectionHandlerImpl::NotifyServiceStartedResult(
Connection* connection = NULL;
{
sync_primitives::AutoReadLock lock(connection_list_lock_);
- ConnectionList::iterator it = connection_list_.find(context.primary_connection_id_);
+ ConnectionList::iterator it =
+ connection_list_.find(context.primary_connection_id_);
if (connection_list_.end() == it) {
LOG4CXX_ERROR(logger_, "connection not found");
return;
@@ -572,17 +585,24 @@ void ConnectionHandlerImpl::OnApplicationFloodCallBack(
uint8_t session_id = 0;
PairFromKey(connection_key, &connection_handle, &session_id);
- // In case this is a Session running on a Secondary Transport, "connection_handle"
- // will reflect the active (secondary) transport. To close the conneciton and its
- // sessions properly, we need to find the Sessions's primary transport/connection.
+ // In case this is a Session running on a Secondary Transport,
+ // "connection_handle" will reflect the active (secondary) transport.
+ // To close the conneciton and its sessions properly, we need to find
+ // the Sessions's primary transport/connection.
if (session_id != 0) {
SessionTransports st = GetSessionTransports(session_id);
if (st.primary_transport == 0) {
- LOG4CXX_WARN(logger_, "OnApplicationFloodCallBack could not find Session in the Session/Connection Map!");
+ LOG4CXX_WARN(logger_,
+ "OnApplicationFloodCallBack could not find Session in the "
+ "Session/Connection Map!");
} else {
- LOG4CXX_INFO(logger_, "OnApplicationFloodCallBack found session " << static_cast<int>(session_id) <<
- " with primary connection " << static_cast<int>(st.primary_transport) <<
- " and secondary connection " << static_cast<int>(st.secondary_transport));
+ LOG4CXX_INFO(logger_,
+ "OnApplicationFloodCallBack found session "
+ << static_cast<int>(session_id)
+ << " with primary connection "
+ << static_cast<int>(st.primary_transport)
+ << " and secondary connection "
+ << static_cast<int>(st.secondary_transport));
connection_handle = st.primary_transport;
}
}
@@ -604,17 +624,24 @@ void ConnectionHandlerImpl::OnMalformedMessageCallback(
uint8_t session_id = 0;
PairFromKey(connection_key, &connection_handle, &session_id);
- // In case this is a Session running on a Secondary Transport, "connection_handle"
- // will reflect the active (secondary) transport. To close the conneciton and its
- // sessions properly, we need to find the Sessions's primary transport/connection.
+ // In case this is a Session running on a Secondary Transport,
+ // "connection_handle" will reflect the active (secondary) transport.
+ // To close the conneciton and its sessions properly, we need to find
+ // the Sessions's primary transport/connection.
if (session_id != 0) {
SessionTransports st = GetSessionTransports(session_id);
if (st.primary_transport == 0) {
- LOG4CXX_WARN(logger_, "OnMalformedMessageCallback could not find Session in the Session/Connection Map!");
+ LOG4CXX_WARN(logger_,
+ "OnMalformedMessageCallback could not find Session in the "
+ "Session/Connection Map!");
} else {
- LOG4CXX_INFO(logger_, "OnMalformedMessageCallback found session " << static_cast<int>(session_id) <<
- " with primary connection " << static_cast<int>(st.primary_transport) <<
- " and secondary connection " << static_cast<int>(st.secondary_transport));
+ LOG4CXX_INFO(logger_,
+ "OnMalformedMessageCallback found session "
+ << static_cast<int>(session_id)
+ << " with primary connection "
+ << static_cast<int>(st.primary_transport)
+ << " and secondary connection "
+ << static_cast<int>(st.secondary_transport));
connection_handle = st.primary_transport;
}
}
@@ -641,25 +668,33 @@ uint32_t ConnectionHandlerImpl::OnSessionEndedCallback(
const protocol_handler::ServiceType& service_type) {
LOG4CXX_AUTO_TRACE(logger_);
- // In case this is a Session running on a Secondary Transport, we need to
+ // In case this is a Session running on a Secondary Transport, we need to
// find the Sessions's primary transport. In this case, "connection_handle"
// reflects the secondary transport, which we need for the various callbacks,
// so they can send appropriate Ack or NAK messages on the correct transport.
- transport_manager::ConnectionUID primary_connection_handle = connection_handle;
+ transport_manager::ConnectionUID primary_connection_handle =
+ connection_handle;
if (session_id != 0) {
SessionTransports st = GetSessionTransports(session_id);
if (st.primary_transport == 0) {
- LOG4CXX_WARN(logger_, "OnSessionEndedCallback could not find Session in the Session/Connection Map!");
+ LOG4CXX_WARN(logger_,
+ "OnSessionEndedCallback could not find Session in the "
+ "Session/Connection Map!");
} else {
- LOG4CXX_INFO(logger_, "OnSessionEndedCallback found session " << static_cast<int>(session_id) <<
- " with primary connection " << static_cast<int>(st.primary_transport) <<
- " and secondary connection " << static_cast<int>(st.secondary_transport));
+ LOG4CXX_INFO(logger_,
+ "OnSessionEndedCallback found session "
+ << static_cast<int>(session_id)
+ << " with primary connection "
+ << static_cast<int>(st.primary_transport)
+ << " and secondary connection "
+ << static_cast<int>(st.secondary_transport));
primary_connection_handle = st.primary_transport;
}
}
connection_list_lock_.AcquireForReading();
- ConnectionList::iterator it = connection_list_.find(primary_connection_handle);
+ ConnectionList::iterator it =
+ connection_list_.find(primary_connection_handle);
if (connection_list_.end() == it) {
LOG4CXX_WARN(logger_, "Unknown connection!");
connection_list_lock_.Release();
@@ -669,7 +704,8 @@ uint32_t ConnectionHandlerImpl::OnSessionEndedCallback(
connection_list_lock_.Release();
Connection* connection = connection_item.second;
- const uint32_t session_key = KeyFromPair(primary_connection_handle, session_id);
+ const uint32_t session_key =
+ KeyFromPair(primary_connection_handle, session_id);
if (protocol_handler::kRpc == service_type) {
LOG4CXX_INFO(logger_,
@@ -713,7 +749,7 @@ uint32_t ConnectionHandlerImpl::OnSessionEndedCallback(
}
bool ConnectionHandlerImpl::OnSecondaryTransportStarted(
- transport_manager::ConnectionUID &primary_connection_handle,
+ transport_manager::ConnectionUID& primary_connection_handle,
const transport_manager::ConnectionUID secondary_connection_handle,
const uint8_t session_id) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -740,10 +776,12 @@ bool ConnectionHandlerImpl::OnSecondaryTransportStarted(
}
// Add the secondary transport connection ID to the SessionConnectionMap
- SessionTransports st = SetSecondaryTransportID(session_id, secondary_connection_handle);
+ SessionTransports st =
+ SetSecondaryTransportID(session_id, secondary_connection_handle);
primary_connection_handle = st.primary_transport;
if (st.secondary_transport != secondary_connection_handle) {
- LOG4CXX_WARN(logger_, "Failed setting the session's secondary transport ID");
+ LOG4CXX_WARN(logger_,
+ "Failed setting the session's secondary transport ID");
return false;
}
@@ -754,7 +792,9 @@ bool ConnectionHandlerImpl::OnSecondaryTransportStarted(
sync_primitives::AutoReadLock read_lock(connection_handler_observer_lock_);
if (connection_handler_observer_) {
- LOG4CXX_TRACE(logger_, "Calling Connection Handler Observer's OnSecondaryTransportStartedCallback");
+ LOG4CXX_TRACE(logger_,
+ "Calling Connection Handler Observer's "
+ "OnSecondaryTransportStartedCallback");
connection_handler_observer_->OnSecondaryTransportStartedCallback(
device_handle, session_key);
}
@@ -768,49 +808,58 @@ void ConnectionHandlerImpl::OnSecondaryTransportEnded(
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_INFO(logger_,
- "Secondary Transport: " << static_cast<int32_t>(secondary_connection_handle) <<
- " ended. Cleaning up services from primary connection ID " << static_cast<int32_t>(primary_connection_handle));
+ "Secondary Transport: "
+ << static_cast<int32_t>(secondary_connection_handle)
+ << " ended. Cleaning up services from primary connection ID "
+ << static_cast<int32_t>(primary_connection_handle));
connection_list_lock_.AcquireForReading();
- ConnectionList::iterator itr = connection_list_.find(primary_connection_handle);
+ ConnectionList::iterator itr =
+ connection_list_.find(primary_connection_handle);
if (connection_list_.end() == itr) {
LOG4CXX_ERROR(logger_, "Primary Connection not found!");
connection_list_lock_.Release();
return;
}
- Connection *connection = itr->second;
+ Connection* connection = itr->second;
connection_list_lock_.Release();
if (connection != NULL) {
std::list<protocol_handler::ServiceType> removed_services_list;
- uint8_t session_id = connection->RemoveSecondaryServices(secondary_connection_handle, removed_services_list);
+ uint8_t session_id = connection->RemoveSecondaryServices(
+ secondary_connection_handle, removed_services_list);
if (session_id == 0) {
- // The secondary services have already been removed from the primary connection, so we
- // find the session associated with this secondary transport in the SessionConnectionMap
- session_id = GetSessionIdFromSecondaryTransport(secondary_connection_handle);
+ // The secondary services have already been removed from the primary
+ // connection, so we find the session associated with this secondary
+ // transport in the SessionConnectionMap
+ session_id =
+ GetSessionIdFromSecondaryTransport(secondary_connection_handle);
}
if (session_id != 0) {
-
{
- sync_primitives::AutoReadLock read_lock(connection_handler_observer_lock_);
+ sync_primitives::AutoReadLock read_lock(
+ connection_handler_observer_lock_);
if (connection_handler_observer_) {
const uint32_t session_key =
KeyFromPair(primary_connection_handle, session_id);
- // Walk the returned list of services and call the ServiceEnded callback for each
- std::list<protocol_handler::ServiceType>::const_iterator it = removed_services_list.begin();
- for ( ; removed_services_list.end() != it; ++it) {
+ // Walk the returned list of services and call the ServiceEnded
+ // callback for each
+ std::list<protocol_handler::ServiceType>::const_iterator it =
+ removed_services_list.begin();
+ for (; removed_services_list.end() != it; ++it) {
connection_handler_observer_->OnServiceEndedCallback(
- session_key, *it, CloseSessionReason::kCommon);
+ session_key, *it, CloseSessionReason::kCommon);
}
connection_handler_observer_->OnSecondaryTransportEndedCallback(
- session_key);
+ session_key);
}
}
- // Clear the secondary connection from the Session/Connection map entry associated with this session
+ // Clear the secondary connection from the Session/Connection map entry
+ // associated with this session
SetSecondaryTransportID(session_id, 0);
}
}
@@ -823,11 +872,9 @@ std::string ConnectionHandlerImpl::connection_type(
std::string connection_type;
sync_primitives::AutoReadLock lock(connection_list_lock_);
- ConnectionList::const_iterator it =
- connection_list_.find(connection_handle);
+ ConnectionList::const_iterator it = connection_list_.find(connection_handle);
if (connection_list_.end() == it) {
- LOG4CXX_WARN(logger_,
- "Unknown connection " << connection_handle);
+ LOG4CXX_WARN(logger_, "Unknown connection " << connection_handle);
} else {
DeviceHandle device_handle = it->second->connection_device_handle();
DeviceMap::const_iterator it = device_list_.find(device_handle);
@@ -946,32 +993,44 @@ DevicesDiscoveryStarter& ConnectionHandlerImpl::get_device_discovery_starter() {
return *this;
}
-NonConstDataAccessor<SessionConnectionMap> ConnectionHandlerImpl::session_connection_map() {
- return NonConstDataAccessor<SessionConnectionMap>(session_connection_map_, session_connection_map_lock_);
+NonConstDataAccessor<SessionConnectionMap>
+ConnectionHandlerImpl::session_connection_map() {
+ return NonConstDataAccessor<SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_);
}
SessionTransports ConnectionHandlerImpl::SetSecondaryTransportID(
- uint8_t session_id,
+ uint8_t session_id,
transport_manager::ConnectionUID secondary_transport_id) {
SessionTransports st;
- NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor = session_connection_map();
- SessionConnectionMap& session_connection_map = session_connection_map_accessor.GetData();
+ NonConstDataAccessor<SessionConnectionMap> session_connection_map_accessor =
+ session_connection_map();
+ SessionConnectionMap& session_connection_map =
+ session_connection_map_accessor.GetData();
SessionConnectionMap::iterator it = session_connection_map.find(session_id);
if (session_connection_map.end() == it) {
- LOG4CXX_WARN(logger_, "SetSecondaryTransportID: session ID " << static_cast<int>(session_id) << " not found in Session/Connection map");
+ LOG4CXX_WARN(logger_,
+ "SetSecondaryTransportID: session ID "
+ << static_cast<int>(session_id)
+ << " not found in Session/Connection map");
st.primary_transport = 0;
st.secondary_transport = 0;
} else {
st = it->second;
- // The only time we overwrite an existing entry in the map is if the new secondary transport ID
- // is 0xFFFFFFFF, which effectively DISABLES the secondary transport feature for the session,
- // or if the new secondary transport ID is 0, which means a secondary transport has shut down
- if (st.secondary_transport != 0 && secondary_transport_id != 0xFFFFFFFF && secondary_transport_id != 0) {
- LOG4CXX_WARN(logger_, "SetSecondaryTransportID: session ID " << static_cast<int>(session_id) <<
- " already has a secondary connection " << static_cast<int>(st.secondary_transport) <<
- " in the Session/Connection map");
+ // The only time we overwrite an existing entry in the map is if the new
+ // secondary transport ID is 0xFFFFFFFF, which effectively DISABLES the
+ // secondary transport feature for the session, or if the new secondary
+ // transport ID is 0, which means a secondary transport has shut down
+ if (st.secondary_transport != 0 && secondary_transport_id != 0xFFFFFFFF &&
+ secondary_transport_id != 0) {
+ LOG4CXX_WARN(logger_,
+ "SetSecondaryTransportID: session ID "
+ << static_cast<int>(session_id)
+ << " already has a secondary connection "
+ << static_cast<int>(st.secondary_transport)
+ << " in the Session/Connection map");
} else {
st.secondary_transport = secondary_transport_id;
session_connection_map[session_id] = st;
@@ -981,10 +1040,12 @@ SessionTransports ConnectionHandlerImpl::SetSecondaryTransportID(
return st;
}
-const SessionTransports ConnectionHandlerImpl::GetSessionTransports(uint8_t session_id) const {
+const SessionTransports ConnectionHandlerImpl::GetSessionTransports(
+ uint8_t session_id) const {
SessionTransports st;
sync_primitives::AutoLock auto_lock(session_connection_map_lock_);
- SessionConnectionMap::const_iterator it = session_connection_map_.find(session_id);
+ SessionConnectionMap::const_iterator it =
+ session_connection_map_.find(session_id);
if (session_connection_map_.end() == it) {
st.primary_transport = 0;
st.secondary_transport = 0;
@@ -999,19 +1060,19 @@ const uint8_t ConnectionHandlerImpl::GetSessionIdFromSecondaryTransport(
transport_manager::ConnectionUID secondary_transport_id) const {
sync_primitives::AutoLock auto_lock(session_connection_map_lock_);
SessionConnectionMap::const_iterator it = session_connection_map_.begin();
- for ( ; session_connection_map_.end() != it ; it++) {
+ for (; session_connection_map_.end() != it; it++) {
SessionTransports st = it->second;
if (st.secondary_transport == secondary_transport_id) {
return it->first;
}
}
- LOG4CXX_ERROR(logger_, "Could not find secondary transport ID " <<
- static_cast<int>(secondary_transport_id) <<
- " in the Session/Connection map");
+ LOG4CXX_ERROR(logger_,
+ "Could not find secondary transport ID "
+ << static_cast<int>(secondary_transport_id)
+ << " in the Session/Connection map");
return 0;
}
-
struct CompareMAC {
explicit CompareMAC(const std::string& mac) : mac_(mac) {}
@@ -1389,17 +1450,27 @@ void ConnectionHandlerImpl::SendEndService(uint32_t key, uint8_t service_type) {
uint32_t connection_handle = 0;
uint8_t session_id = 0;
PairFromKey(key, &connection_handle, &session_id);
-
- // If the service is running on a secondary transport, we need to retrieve that transport from the SessionConnection Map
+
+ // If the service is running on a secondary transport, we need to retrieve
+ // that transport from the SessionConnection Map
SessionTransports st = GetSessionTransports(session_id);
if (st.primary_transport == 0) {
- LOG4CXX_WARN(logger_, "SendEndService could not find Session in the Session/Connection Map!");
+ LOG4CXX_WARN(logger_,
+ "SendEndService could not find Session in the "
+ "Session/Connection Map!");
} else {
- LOG4CXX_INFO(logger_, "SendEndService found session " << static_cast<int>(session_id) <<
- " with primary connection " << static_cast<int>(st.primary_transport) <<
- " and secondary connection " << static_cast<int>(st.secondary_transport));
-
- protocol_handler_->SendEndService(st.primary_transport, st.secondary_transport, session_id, service_type);
+ LOG4CXX_INFO(logger_,
+ "SendEndService found session "
+ << static_cast<int>(session_id)
+ << " with primary connection "
+ << static_cast<int>(st.primary_transport)
+ << " and secondary connection "
+ << static_cast<int>(st.secondary_transport));
+
+ protocol_handler_->SendEndService(st.primary_transport,
+ st.secondary_transport,
+ session_id,
+ service_type);
}
}
}
@@ -1467,8 +1538,9 @@ void ConnectionHandlerImpl::OnConnectionEnded(
sync_primitives::AutoReadLock read_lock(connection_handler_observer_lock_);
if (connection_handler_observer_ && connection.get() != NULL) {
- // We have to remember the Connection object we just removed from connection_list_, because
- // we will need to retrieve the protocol version from it inside of OnServiceEndedCallback
+ // We have to remember the Connection object we just removed from
+ // connection_list_, because we will need to retrieve the protocol
+ // version from it inside of OnServiceEndedCallback
ending_connection_ = connection.get();
const SessionMap session_map = connection->session_map();
@@ -1489,7 +1561,8 @@ void ConnectionHandlerImpl::OnConnectionEnded(
ending_connection_ = NULL;
}
- ConnectionHandle primary_connection_handle = connection->primary_connection_handle();
+ ConnectionHandle primary_connection_handle =
+ connection->primary_connection_handle();
if (primary_connection_handle != 0) {
OnSecondaryTransportEnded(primary_connection_handle, connection_id);
}
@@ -1532,7 +1605,9 @@ bool ConnectionHandlerImpl::ProtocolVersionUsed(
ConnectionList::const_iterator it = connection_list_.find(connection_id);
if (connection_list_.end() != it) {
return it->second->ProtocolVersion(session_id, protocol_version);
- } else if (ending_connection_ && static_cast<uint32_t>(ending_connection_->connection_handle()) == connection_id) {
+ } else if (ending_connection_ &&
+ static_cast<uint32_t>(ending_connection_->connection_handle()) ==
+ connection_id) {
return ending_connection_->ProtocolVersion(session_id, protocol_version);
}
LOG4CXX_WARN(logger_, "Connection not found !");
diff --git a/src/components/connection_handler/test/connection_test.cc b/src/components/connection_handler/test/connection_test.cc
index 02c7a7c8d2..fb70c2b3c1 100644
--- a/src/components/connection_handler/test/connection_test.cc
+++ b/src/components/connection_handler/test/connection_test.cc
@@ -509,20 +509,19 @@ TEST_F(ConnectionTest, RemoveSession_VerifySessionConnectionMapRemoved) {
TEST_F(ConnectionTest, SecondarySessionTest) {
StartSession();
AddNewService(
- kRpc, PROTECTION_OFF, EXPECT_RETURN_FALSE, EXPECT_SERVICE_EXISTS);
+ kRpc, PROTECTION_OFF, EXPECT_RETURN_FALSE, EXPECT_SERVICE_EXISTS);
const ConnectionHandle connectionHandle = 0;
const DeviceHandle device_handle = 0u;
const uint32_t heart_beat = 0u;
Connection* secondary_connection = new Connection(
- connectionHandle, device_handle, connection_handler_, heart_beat);
+ connectionHandle, device_handle, connection_handler_, heart_beat);
secondary_connection->SetPrimaryConnectionHandle(kDefaultConnectionHandle);
connection_handler::ConnectionHandle expected_primary_connection_handle =
kDefaultConnectionHandle;
- EXPECT_EQ(
- secondary_connection->primary_connection_handle(),
- expected_primary_connection_handle);
+ EXPECT_EQ(secondary_connection->primary_connection_handle(),
+ expected_primary_connection_handle);
AddNewSecondaryService(kAudio);
AddNewSecondaryService(kMobileNav);
diff --git a/src/components/connection_handler/test/heart_beat_monitor_test.cc b/src/components/connection_handler/test/heart_beat_monitor_test.cc
index 5436ee4c6a..c1385e7d04 100644
--- a/src/components/connection_handler/test/heart_beat_monitor_test.cc
+++ b/src/components/connection_handler/test/heart_beat_monitor_test.cc
@@ -69,7 +69,6 @@ class HeartBeatMonitorTest : public testing::Test {
connection_handler::SessionConnectionMap session_connection_map_;
::sync_primitives::Lock session_connection_map_lock_;
-
virtual void SetUp() {
conn = new connection_handler::Connection(
kConnectionHandle, 0, &connection_handler_mock, kTimeout);
@@ -86,8 +85,9 @@ ACTION_P2(RemoveSession, conn, session_id) {
TEST_F(HeartBeatMonitorTest, TimerNotStarted) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
// Whithout StartHeartBeat nothing to be call
EXPECT_CALL(connection_handler_mock, CloseSession(_, _)).Times(0);
@@ -99,8 +99,9 @@ TEST_F(HeartBeatMonitorTest, TimerNotStarted) {
TEST_F(HeartBeatMonitorTest, TimerNotElapsed) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
EXPECT_CALL(connection_handler_mock, SendHeartBeat(_, _)).Times(0);
EXPECT_CALL(connection_handler_mock, CloseSession(_, _)).Times(0);
@@ -112,8 +113,9 @@ TEST_F(HeartBeatMonitorTest, TimerNotElapsed) {
TEST_F(HeartBeatMonitorTest, TimerElapsed) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
const uint32_t session = conn->AddNewSession(kDefaultConnectionHandle);
@@ -139,8 +141,9 @@ TEST_F(HeartBeatMonitorTest, TimerElapsed) {
TEST_F(HeartBeatMonitorTest, KeptAlive) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
EXPECT_CALL(connection_handler_mock, CloseSession(_, _)).Times(0);
EXPECT_CALL(connection_handler_mock, CloseConnection(_)).Times(0);
@@ -159,8 +162,9 @@ TEST_F(HeartBeatMonitorTest, KeptAlive) {
TEST_F(HeartBeatMonitorTest, NotKeptAlive) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
const uint32_t session = conn->AddNewSession(kDefaultConnectionHandle);
@@ -193,8 +197,9 @@ TEST_F(HeartBeatMonitorTest, NotKeptAlive) {
TEST_F(HeartBeatMonitorTest, TwoSessionsElapsed) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
const uint32_t kSession1 = conn->AddNewSession(kDefaultConnectionHandle);
const uint32_t kSession2 = conn->AddNewSession(kDefaultConnectionHandle);
@@ -229,8 +234,9 @@ TEST_F(HeartBeatMonitorTest, TwoSessionsElapsed) {
TEST_F(HeartBeatMonitorTest, IncreaseHeartBeatTimeout) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
const uint32_t kSession = conn->AddNewSession(kDefaultConnectionHandle);
@@ -245,8 +251,9 @@ TEST_F(HeartBeatMonitorTest, IncreaseHeartBeatTimeout) {
TEST_F(HeartBeatMonitorTest, DecreaseHeartBeatTimeout) {
ON_CALL(connection_handler_mock, session_connection_map())
- .WillByDefault(Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
- session_connection_map_, session_connection_map_lock_)));
+ .WillByDefault(
+ Return(NonConstDataAccessor<connection_handler::SessionConnectionMap>(
+ session_connection_map_, session_connection_map_lock_)));
const uint32_t kSession = conn->AddNewSession(kDefaultConnectionHandle);