From: Nikita Vaganov Date: Wed, 19 Mar 2014 05:56:23 +0000 (+0400) Subject: Transport adapter last state is stored when application is either X-Git-Tag: 3.5~205 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e5ca3df8d67c07808d363b9f48459227d2fb38f;p=profile%2Fivi%2Fsmartdevicelink.git Transport adapter last state is stored when application is either connected or disconnected Only established connections are stored Signed-off-by: Justin Dickow Conflicts: src/appMain/smartDeviceLink.ini --- diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt index e91ab4d..a326933 100644 --- a/src/appMain/CMakeLists.txt +++ b/src/appMain/CMakeLists.txt @@ -77,6 +77,7 @@ include_directories ( ../components/smart_objects/include/ ../components/media_manager/include/ ../components/policies/include/ + ../components/resumption/include/ ../thirdPartyLibs/MessageBroker/include ../thirdPartyLibs/encryption/include ${CMAKE_SOURCE_DIR}/src/components/ diff --git a/src/appMain/life_cycle.cc b/src/appMain/life_cycle.cc index 687cc33..ca0859d 100644 --- a/src/appMain/life_cycle.cc +++ b/src/appMain/life_cycle.cc @@ -35,6 +35,7 @@ #include "./life_cycle.h" #include "utils/signals.h" #include "config_profile/profile.h" +#include "resumption/last_state.h" using threads::Thread; @@ -245,6 +246,9 @@ bool LifeCycle::InitMessageSystem() { #endif // QT_HMI void LifeCycle::StopComponents() { + LOG4CXX_INFO(logger_, "Destroying Last State"); + resumption::LastState::destroy(); + hmi_handler_->set_message_observer(NULL); connection_handler_->set_connection_handler_observer(NULL); protocol_handler_->RemoveProtocolObserver(app_manager_); diff --git a/src/appMain/smartDeviceLink.ini b/src/appMain/smartDeviceLink.ini index c7bdc5f..d228058 100644 --- a/src/appMain/smartDeviceLink.ini +++ b/src/appMain/smartDeviceLink.ini @@ -39,6 +39,8 @@ AppRequestsTimeScale = 10 PendingRequestsAmount = 1000 HeartBeatTimeout = 0 SupportedDiagModes = 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x09, 0x0A, 0x18, 0x19, 0x22, 0x3E +SystemFilesPath = /tmp/fs/mp/images/ivsu_cache +UseLastState = true [MEDIA MANAGER] EnableRedecoding = false diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index db4a0d5..aae7290 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -602,6 +602,16 @@ void Profile::UpdateValues() { (void) ReadIntValue(&heart_beat_timeout_, kDefaultHeartBeatTimeout, kMainSection, "HeartBeatTimeout"); + + *value = '\0'; + if ((0 != ini_read_value(config_file_name_.c_str(), + "MAIN", "UseLastState", value)) + && ('\0' != *value)) { + if (0 == strcmp("true", value)) { + use_last_state_ = true; + } + LOG4CXX_INFO(logger_, "Set UseLastState to " << value); + } } bool Profile::ReadValue(bool* value, const char* const pSection, diff --git a/src/components/resumption/include/resumption/last_state.h b/src/components/resumption/include/resumption/last_state.h index 18469e2..4380542 100644 --- a/src/components/resumption/include/resumption/last_state.h +++ b/src/components/resumption/include/resumption/last_state.h @@ -1,5 +1,5 @@ -/** - * 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 @@ -48,27 +48,26 @@ class LastState : public utils::Singleton { */ Json::Value dictionary; - private: - - /** - * @brief File to save Dictionary - */ + private: +/** + * @brief File to save Dictionary + */ static const std::string filename; - - /** - * @brief Saving dictionary to filesystem as Json - */ +/** + * @brief Saving dictionary to filesystem + */ void SaveToFileSystem(); - - /** - * @brief Load dictionary from filesystem as Json - */ +/** + * @brief Load dictionary from filesystem + */ void LoadFromFileSystem(); - - /** +/** * @brief Private default constructor */ LastState(); +/** + * @brief Private destructor + */ ~LastState(); diff --git a/src/components/resumption/src/last_state.cc b/src/components/resumption/src/last_state.cc index 97b13a7..ebf4ce8 100644 --- a/src/components/resumption/src/last_state.cc +++ b/src/components/resumption/src/last_state.cc @@ -35,6 +35,8 @@ namespace resumption { +const std::string LastState::filename = "LastState.dat"; + void LastState::SaveToFileSystem() { const std::string& str = dictionary.toStyledString(); const std::vector char_vector_pdata( @@ -61,5 +63,4 @@ LastState::~LastState() { SaveToFileSystem(); } -const std::string LastState::filename = "TM.dat"; } diff --git a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h index 664a5c8..ac22931 100644 --- a/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h +++ b/src/components/transport_manager/include/transport_manager/transport_adapter/transport_adapter_impl.h @@ -393,7 +393,6 @@ class TransportAdapterImpl : public TransportAdapter, */ virtual bool ToBeAutoConnected(DeviceSptr device) const; - private: /** * @brief Find connection that has state - ESTABLISHED. * @@ -403,7 +402,9 @@ class TransportAdapterImpl : public TransportAdapter, * @return ConnectionSptr smart pointer to the connection. */ ConnectionSptr FindEstablishedConnection(const DeviceUID& device_handle, - const ApplicationHandle& app_handle); + const ApplicationHandle& app_handle) const; + + private: /** * @brief Connect to all applications discovered on device * @param device Pointer to device diff --git a/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc b/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc index 917ad24..39db272 100644 --- a/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc +++ b/src/components/transport_manager/src/bluetooth/bluetooth_transport_adapter.cc @@ -86,19 +86,23 @@ void BluetoothTransportAdapter::Store() const { ApplicationList app_ids = bluetooth_device->GetApplicationList(); for (ApplicationList::const_iterator j = app_ids.begin(); j != app_ids.end(); ++j) { ApplicationHandle app_handle = *j; - uint8_t rfcomm_channel; - bluetooth_device->GetRfcommChannel(app_handle, &rfcomm_channel); - Json::Value application_dictionary; - char rfcomm_channel_record[4]; - sprintf(rfcomm_channel_record, "%ud", rfcomm_channel); - application_dictionary["rfcomm_channel"] = std::string(rfcomm_channel_record); - applications_dictionary.append(application_dictionary); + if (FindEstablishedConnection(bluetooth_device->name(), app_handle)) { + uint8_t rfcomm_channel; + bluetooth_device->GetRfcommChannel(app_handle, &rfcomm_channel); + Json::Value application_dictionary; + char rfcomm_channel_record[4]; + sprintf(rfcomm_channel_record, "%u", rfcomm_channel); + application_dictionary["rfcomm_channel"] = std::string(rfcomm_channel_record); + applications_dictionary.append(application_dictionary); + } + } + if (!applications_dictionary.empty()) { + device_dictionary["applications"] = applications_dictionary; + devices_dictionary.append(device_dictionary); } - device_dictionary["applications"] = applications_dictionary; - devices_dictionary.append(device_dictionary); } bluetooth_adapter_dictionary["devices"] = devices_dictionary; - resumption::LastState::instance()->dictionary["BluetoothAdapter"] = + resumption::LastState::instance()->dictionary["TransportManager"]["BluetoothAdapter"] = bluetooth_adapter_dictionary; LOG4CXX_TRACE_EXIT(logger_); } @@ -107,7 +111,7 @@ bool BluetoothTransportAdapter::Restore() { LOG4CXX_TRACE_ENTER(logger_); bool errors_occured = false; const Json::Value bluetooth_adapter_dictionary = - resumption::LastState::instance()->dictionary["BluetoothAdapter"]; + resumption::LastState::instance()->dictionary["TransportManager"]["BluetoothAdapter"]; const Json::Value devices_dictionary = bluetooth_adapter_dictionary["devices"]; for (Json::Value::const_iterator i = devices_dictionary.begin(); i != devices_dictionary.end(); ++i) { diff --git a/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc b/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc index d09b78d..4aa52fb 100644 --- a/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc +++ b/src/components/transport_manager/src/tcp/tcp_transport_adapter.cc @@ -93,20 +93,24 @@ void TcpTransportAdapter::Store() const { ApplicationList app_ids = tcp_device->GetApplicationList(); for (ApplicationList::const_iterator j = app_ids.begin(); j != app_ids.end(); ++j) { ApplicationHandle app_handle = *j; - int port = tcp_device->GetApplicationPort(app_handle); - if (port != -1) { // don't want to store incoming applications - Json::Value application_dictionary; - char port_record[12]; - sprintf(port_record, "%d", port); - application_dictionary["port"] = std::string(port_record); - applications_dictionary.append(application_dictionary); + if (FindEstablishedConnection(tcp_device->name(), app_handle)) { + int port = tcp_device->GetApplicationPort(app_handle); + if (port != -1) { // don't want to store incoming applications + Json::Value application_dictionary; + char port_record[12]; + sprintf(port_record, "%d", port); + application_dictionary["port"] = std::string(port_record); + applications_dictionary.append(application_dictionary); + } } } - device_dictionary["applications"] = applications_dictionary; - devices_dictionary.append(device_dictionary); + if (!applications_dictionary.empty()) { + device_dictionary["applications"] = applications_dictionary; + devices_dictionary.append(device_dictionary); + } } tcp_adapter_dictionary["devices"] = devices_dictionary; - resumption::LastState::instance()->dictionary["TcpAdapter"] = + resumption::LastState::instance()->dictionary["TransportManager"]["TcpAdapter"] = tcp_adapter_dictionary; LOG4CXX_TRACE_EXIT(logger_); } @@ -115,7 +119,7 @@ bool TcpTransportAdapter::Restore() { LOG4CXX_TRACE_ENTER(logger_); bool errors_occured = false; const Json::Value tcp_adapter_dictionary = - resumption::LastState::instance()->dictionary["TcpAdapter"]; + resumption::LastState::instance()->dictionary["TransportManager"]["TcpAdapter"]; const Json::Value devices_dictionary = tcp_adapter_dictionary["devices"]; for (Json::Value::const_iterator i = devices_dictionary.begin(); i != devices_dictionary.end(); ++i) { 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 6149670..ff7dae1 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 @@ -418,6 +418,8 @@ void TransportAdapterImpl::DisconnectDone(const DeviceUID& device_id, } pthread_mutex_unlock(&devices_mutex_); } + + Store(); } void TransportAdapterImpl::DataReceiveDone(const DeviceUID& device_id, @@ -483,6 +485,8 @@ void TransportAdapterImpl::ConnectDone(const DeviceUID& device_id, for (TransportAdapterListenerList::iterator it = listeners_.begin(); it != listeners_.end(); ++it) (*it)->OnConnectDone(this, device_id, app_handle); + + Store(); } void TransportAdapterImpl::ConnectFailed(const DeviceUID& device_id, @@ -569,13 +573,13 @@ bool TransportAdapterImpl::ToBeAutoConnected(DeviceSptr device) const { } ConnectionSptr TransportAdapterImpl::FindEstablishedConnection( - const DeviceUID& device_id, const ApplicationHandle& app_handle) { + const DeviceUID& device_id, const ApplicationHandle& app_handle) const { ConnectionSptr connection; pthread_mutex_lock(&connections_mutex_); - ConnectionMap::iterator it = + ConnectionMap::const_iterator it = connections_.find(std::make_pair(device_id, app_handle)); if (it != connections_.end()) { - ConnectionInfo& info = it->second; + const ConnectionInfo& info = it->second; if (info.state == ConnectionInfo::ESTABLISHED) connection = info.connection; } pthread_mutex_unlock(&connections_mutex_);