diff options
author | Vladislav Semenyuk <vsemenyuk@luxoft.com> | 2014-06-25 00:46:50 -0700 |
---|---|---|
committer | Vladislav Semenyuk <vsemenyuk@luxoft.com> | 2014-06-25 01:15:52 -0700 |
commit | a3bf1057b9183a78f0ebf3fccf08736b1b1944fe (patch) | |
tree | 45fab48f179ef40393f4dd6d369f6c536cbe6d7d | |
parent | 7e57fd92ab95e8b9e00c15624ee4fbc5fdec091a (diff) | |
download | sdl_core-a3bf1057b9183a78f0ebf3fccf08736b1b1944fe.tar.gz |
APPLINK-7679 SDL should always notificate mobile app about closed session.
APPLINK-7557 Resumption: heartbeattimeout after IgnitionOff on mobile.
APPLINK-7120 SDL: sometimes core is dumped after exiting by "IgnitionOff"
5 files changed, 49 insertions, 19 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index ad97237959..b1da51bb0b 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -1828,8 +1828,10 @@ void ApplicationManagerImpl::UnregisterAllApplications() { MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile( (*it)->app_id(), unregister_reason_); - UnregisterApplication((*it)->app_id(), mobile_apis::Result::INVALID_ENUM, + uint32_t app_id = (*it)->app_id(); + UnregisterApplication(app_id, mobile_apis::Result::INVALID_ENUM, is_ignition_off); + connection_handler_->CloseSession(app_id); it = application_list_.begin(); } if (is_ignition_off) { @@ -1940,7 +1942,7 @@ void ApplicationManagerImpl::Handle(const impl::MessageToMobile& message) { } protocol_handler_->SendMessageToMobileApp(rawMessage, is_final); - LOG4CXX_INFO(logger_, "Message for mobile given away."); + LOG4CXX_INFO(logger_, "Message for mobile given away"); if (close_session) { connection_handler_->CloseSession(message->connection_key()); diff --git a/src/components/connection_handler/src/connection.cc b/src/components/connection_handler/src/connection.cc index 51ea1fb8e5..1176ce0825 100644 --- a/src/components/connection_handler/src/connection.cc +++ b/src/components/connection_handler/src/connection.cc @@ -53,6 +53,7 @@ Connection::Connection(ConnectionHandle connection_handle, : connection_handler_(connection_handler), connection_handle_(connection_handle), connection_device_handle_(connection_device_handle) { + LOG4CXX_TRACE_ENTER(logger_); DCHECK(connection_handler_); heartbeat_monitor_ = new HeartBeatMonitor(heartbeat_timeout, this); @@ -61,12 +62,16 @@ Connection::Connection(ConnectionHandle connection_handle, } Connection::~Connection() { + LOG4CXX_TRACE_ENTER(logger_); + sync_primitives::AutoLock lock(session_map_lock_); session_map_.clear(); heart_beat_monitor_thread_->stop(); delete heart_beat_monitor_thread_; + LOG4CXX_TRACE_EXIT(logger_); } uint32_t Connection::AddNewSession() { + LOG4CXX_TRACE_ENTER(logger_); sync_primitives::AutoLock lock(session_map_lock_); int32_t result = 0; @@ -180,12 +185,11 @@ void Connection::CloseSession(uint8_t session_id) { size = session_map_.size(); } + connection_handler_->CloseSession(connection_handle_, session_id); + //Close connection if it is last session if (1 == size) { - heartbeat_monitor_->RemoveSession(session_id); connection_handler_->CloseConnection(connection_handle_); - } else { - connection_handler_->CloseSession(connection_handle_, session_id); } } diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index ce439931ba..a4bf08516f 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -116,13 +116,21 @@ void ConnectionHandlerImpl::OnDeviceRemoved( // 1. Delete all the connections and sessions of this device // 2. Delete device from a list // 3. Let observer know that device has been deleted. - for (ConnectionListIterator it = connection_list_.begin(); - it != connection_list_.end(); ++it) { - if (device_info.device_handle() == - (*it).second->connection_device_handle()) { - RemoveConnection((*it).first); + + { + sync_primitives::AutoLock lock(connection_list_lock_); + for (ConnectionListIterator it = connection_list_.begin(); + it != connection_list_.end(); ++it) { + if (device_info.device_handle() == + (*it).second->connection_device_handle()) { + ConnectionHandle connection_handle = (*it).first; + // Unlock connection_list to avoid deadlock during connection removing + sync_primitives::AutoUnlock auto_unlock(lock); + RemoveConnection(connection_handle); + } } } + device_list_.erase(device_info.device_handle()); if (connection_handler_observer_) { connection_handler_observer_->RemoveDevice(device_info.device_handle()); @@ -560,7 +568,7 @@ void ConnectionHandlerImpl::CloseSession(ConnectionHandle connection_handle, ConnectionUIDFromHandle(connection_handle); sync_primitives::AutoLock connection_list_lock(connection_list_lock_); - ConnectionListIterator itr = connection_list_.find(connection_id); + ConnectionListIterator itr = connection_list_.find(connection_id); if (connection_list_.end() != itr) { if (0 != connection_handler_observer_) { @@ -640,8 +648,7 @@ void ConnectionHandlerImpl::OnConnectionEnded( uint32_t session_key = KeyFromPair(connection_id, session_it->first); for (ServiceListConstIterator service_it = session_it->second.begin(), end = session_it->second.end(); service_it != end; ++service_it) { - - connection_handler_observer_->OnServiceEndedCallback( + connection_handler_observer_->OnServiceEndedCallback( session_key, static_cast<protocol_handler::ServiceType>(*service_it)); } } diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h index 48016e30b2..e55173992b 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h @@ -478,10 +478,15 @@ class ProtocolHandlerImpl std::map<uint8_t, uint32_t> message_counters_; /** - *\brief map for session last message. + *\brief map for connection last message. */ std::map<uint8_t, uint32_t> sessions_last_message_id_; + /** + *\brief Connections that must be closed after their last messages were sent + */ + std::list<uint32_t> ready_to_close_connections_; + class IncomingDataHandler; std::auto_ptr<IncomingDataHandler> incoming_data_handler_; diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 95335bdc82..95d99cbe83 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -471,6 +471,20 @@ void ProtocolHandlerImpl::OnTMMessageSend(const RawMessagePtr message) { message->data(), message->data_size()); + session_observer_->PairFromKey(message->connection_key(), + &connection_handle, + &sessionID); + + std::list<uint32_t>::iterator connection_it = + std::find(ready_to_close_connections_.begin(), + ready_to_close_connections_.end(), connection_handle); + + if (ready_to_close_connections_.end() != connection_it) { + ready_to_close_connections_.erase(connection_it); + transport_manager_->Disconnect(connection_handle); + return; + } + std::map<uint8_t, uint32_t>::iterator it = sessions_last_message_id_.find(sent_message.session_id()); @@ -482,10 +496,8 @@ void ProtocolHandlerImpl::OnTMMessageSend(const RawMessagePtr message) { ((FRAME_TYPE_CONSECUTIVE == sent_message.frame_type()) && (0 == sent_message.frame_data())))) { - session_observer_->PairFromKey(message->connection_key(), - &connection_handle, - &sessionID); - transport_manager_->Disconnect(connection_handle); + ready_to_close_connections_.push_back(connection_handle); + SendEndSession(connection_handle, sent_message.session_id()); } } @@ -921,7 +933,7 @@ void ProtocolHandlerImpl::Handle( LOG4CXX_INFO_EXT(logger_, "Packet: dataSize " << message->data_size()); HandleMessage(message->connection_key(), message); } else { - LOG4CXX_INFO_EXT(logger_, + LOG4CXX_WARN(logger_, "handleMessagesFromMobileApp() - incorrect or NULL data"); } LOG4CXX_TRACE_EXIT(logger_); |