diff options
Diffstat (limited to 'src/components/connection_handler')
3 files changed, 38 insertions, 16 deletions
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 01a8970680..aebc612a22 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 @@ -464,6 +464,8 @@ class ConnectionHandlerImpl /** * \brief Invoked when observer's OnServiceStartedCallback is completed + * \param session_key the key of started session passed to + * OnServiceStartedCallback(). * \param result true if observer accepts starting service, false otherwise * \param rejected_params list of rejected parameters' name. Only valid when * result is false. Note that even if result is false, this may be empty. @@ -472,7 +474,9 @@ class ConnectionHandlerImpl * Also it can be invoked before OnServiceStartedCallback() returns. **/ virtual void NotifyServiceStartedResult( - bool result, std::vector<std::string>& rejected_params); + uint32_t session_key, + bool result, + std::vector<std::string>& rejected_params); private: /** @@ -580,8 +584,8 @@ class ConnectionHandlerImpl */ utils::StlMapDeleter<ConnectionList> connection_list_deleter_; - // we need thread-safe queue - utils::MessageQueue<ServiceStartedContext> start_service_context_queue_; + sync_primitives::Lock start_service_context_map_lock_; + std::map<uint32_t, ServiceStartedContext> start_service_context_map_; #ifdef BUILD_TESTS // Methods for test usage diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index d4bf9530dd..daca42d3c2 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -70,7 +70,8 @@ ConnectionHandlerImpl::ConnectionHandlerImpl( , connection_list_lock_() , connection_handler_observer_lock_() , connection_list_deleter_(&connection_list_) - , start_service_context_queue_() {} + , start_service_context_map_lock_() + , start_service_context_map_() {} ConnectionHandlerImpl::~ConnectionHandlerImpl() { LOG4CXX_AUTO_TRACE(logger_); @@ -83,6 +84,9 @@ void ConnectionHandlerImpl::Stop() { RemoveConnection(itr->second->connection_handle()); itr = connection_list_.begin(); } + + sync_primitives::AutoLock auto_lock(start_service_context_map_lock_); + start_service_context_map_.clear(); } void ConnectionHandlerImpl::set_connection_handler_observer( @@ -415,7 +419,10 @@ void ConnectionHandlerImpl::OnSessionStartedCallback( service_type, hash_id, is_protected); - start_service_context_queue_.push(context); + { + sync_primitives::AutoLock auto_lock(start_service_context_map_lock_); + start_service_context_map_[session_key] = context; + } connection_handler_observer_->OnServiceStartedCallback( connection->connection_device_handle(), @@ -436,14 +443,22 @@ void ConnectionHandlerImpl::OnSessionStartedCallback( } void ConnectionHandlerImpl::NotifyServiceStartedResult( - bool result, std::vector<std::string>& rejected_params) { + uint32_t session_key, + bool result, + std::vector<std::string>& rejected_params) { LOG4CXX_AUTO_TRACE(logger_); ServiceStartedContext context; - bool available = start_service_context_queue_.pop(context); - if (!available) { - LOG4CXX_ERROR(logger_, "context for start service not found!"); - return; + { + sync_primitives::AutoLock auto_lock(start_service_context_map_lock_); + std::map<uint32_t, ServiceStartedContext>::iterator it = + start_service_context_map_.find(session_key); + if (it == start_service_context_map_.end()) { + LOG4CXX_ERROR(logger_, "context for start service not found!"); + return; + } + context = it->second; + start_service_context_map_.erase(it); } Connection* connection = NULL; diff --git a/src/components/connection_handler/test/connection_handler_impl_test.cc b/src/components/connection_handler/test/connection_handler_impl_test.cc index 99805b745c..0789660ca1 100644 --- a/src/components/connection_handler/test/connection_handler_impl_test.cc +++ b/src/components/connection_handler/test/connection_handler_impl_test.cc @@ -62,9 +62,9 @@ using ::testing::Return; using ::testing::ReturnRefOfCopy; using ::testing::SaveArg; -// custom action to call a member function with 4 arguments -ACTION_P4(InvokeMemberFuncWithArg2, ptr, memberFunc, a, b) { - (ptr->*memberFunc)(a, b); +// custom action to call a member function with 3 arguments +ACTION_P5(InvokeMemberFuncWithArg3, ptr, memberFunc, a, b, c) { + (ptr->*memberFunc)(a, b, c); } namespace { @@ -1210,9 +1210,10 @@ TEST_F(ConnectionHandlerTest, SessionStarted_WithRpc) { std::vector<std::string> empty; EXPECT_CALL(mock_connection_handler_observer, OnServiceStartedCallback(device_handle_, session_key, kRpc, NULL)) - .WillOnce(InvokeMemberFuncWithArg2( + .WillOnce(InvokeMemberFuncWithArg3( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, + session_key, true, ByRef(empty))); @@ -1246,9 +1247,10 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_SUCCESS) { EXPECT_CALL(mock_connection_handler_observer, OnServiceStartedCallback( device_handle_, session_key, kMobileNav, dummy_params)) - .WillOnce(InvokeMemberFuncWithArg2( + .WillOnce(InvokeMemberFuncWithArg3( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, + session_key, true, ByRef(empty))); @@ -1282,9 +1284,10 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_FAILURE) { EXPECT_CALL(mock_connection_handler_observer, OnServiceStartedCallback( device_handle_, session_key, kMobileNav, dummy_params)) - .WillOnce(InvokeMemberFuncWithArg2( + .WillOnce(InvokeMemberFuncWithArg3( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, + session_key, false, ByRef(empty))); |