diff options
author | Kozoriz <kozorizandriy@gmail.com> | 2016-02-29 10:29:49 +0200 |
---|---|---|
committer | Kozoriz <kozorizandriy@gmail.com> | 2016-03-04 10:11:18 +0200 |
commit | 6b1559b8659ec8d20777c29a714797fa3b649804 (patch) | |
tree | 42e95002eb429f52964f0c88f2fa0b0991ee841a | |
parent | b14ac4915707bb39a24f4de8a27e497b21aa7032 (diff) | |
download | sdl_core-6b1559b8659ec8d20777c29a714797fa3b649804.tar.gz |
Remove HMIMessageHandler singleton
Correctives in src and tests for class
Related to : APPLINK-21440
9 files changed, 153 insertions, 30 deletions
diff --git a/src/components/hmi_message_handler/CMakeLists.txt b/src/components/hmi_message_handler/CMakeLists.txt index 953e1a03ba..aa10729458 100644 --- a/src/components/hmi_message_handler/CMakeLists.txt +++ b/src/components/hmi_message_handler/CMakeLists.txt @@ -35,7 +35,6 @@ include_directories ( ${COMPONENTS_DIR}/utils/include/ ${COMPONENTS_DIR}/smart_objects/include/ ${COMPONENTS_DIR}/formatters/include/ - ${COMPONENTS_DIR}/config_profile/include/ ${COMPONENTS_DIR}/media_manager/include/ ${COMPONENTS_DIR}/protocol_handler/include ${JSONCPP_INCLUDE_DIRECTORY} diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h index 3e06c65085..217075e89f 100644 --- a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h +++ b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Ford Motor Company + * Copyright (c) 2016, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,7 @@ #include "hmi_message_handler/hmi_message_sender.h" #include "hmi_message_handler/hmi_message_observer.h" +#include "hmi_message_handler/hmi_message_handler_settings.h" namespace hmi_message_handler { @@ -49,6 +50,12 @@ class HMIMessageHandler : public HMIMessageObserver, public HMIMessageSender { virtual ~HMIMessageHandler() {} virtual void AddHMIMessageAdapter(HMIMessageAdapter* adapter) = 0; virtual void RemoveHMIMessageAdapter(HMIMessageAdapter* adapter) = 0; + + /** + * \brief Hmi message handler settings getter + * \return pointer to hmi message handler settings class + */ + virtual const HMIMessageHandlerSettings& get_settings() const = 0; }; } // namespace hmi_message_handler diff --git a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h index f1f58eaf2e..2f235aa968 100644 --- a/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h +++ b/src/components/hmi_message_handler/include/hmi_message_handler/hmi_message_handler_impl.h @@ -36,12 +36,12 @@ #include <set> #include "hmi_message_handler/hmi_message_adapter.h" #include "hmi_message_handler/hmi_message_handler.h" +#include "hmi_message_handler/hmi_message_handler_settings.h" #include "utils/macro.h" #include "utils/message_queue.h" #include "utils/prioritized_queue.h" #include "utils/threads/message_loop_thread.h" #include "utils/threads/thread.h" -#include "utils/singleton.h" namespace hmi_message_handler { @@ -82,9 +82,10 @@ class FromHMIThreadImpl; class HMIMessageHandlerImpl : public HMIMessageHandler, public impl::FromHmiQueue::Handler, - public impl::ToHmiQueue::Handler, - public utils::Singleton<HMIMessageHandlerImpl> { + public impl::ToHmiQueue::Handler { public: + explicit HMIMessageHandlerImpl(const HMIMessageHandlerSettings& settings); + ~HMIMessageHandlerImpl(); void OnMessageReceived(MessageSharedPointer message); void SendMessageToHMI(MessageSharedPointer message); @@ -93,6 +94,8 @@ class HMIMessageHandlerImpl void AddHMIMessageAdapter(HMIMessageAdapter* adapter); void RemoveHMIMessageAdapter(HMIMessageAdapter* adapter); + virtual const HMIMessageHandlerSettings& get_settings() const OVERRIDE; + #ifdef BUILD_TESTS std::set<HMIMessageAdapter*> message_adapters() const { return message_adapters_; @@ -104,9 +107,6 @@ class HMIMessageHandlerImpl #endif // BUILD_TESTS private: - HMIMessageHandlerImpl(); - - // threads::MessageLoopThread<*>::Handler implementations // CALLED ON messages_from_hmi_ THREAD! @@ -114,7 +114,7 @@ class HMIMessageHandlerImpl // CALLED ON messages_to_hmi_ THREAD! virtual void Handle(const impl::MessageToHmi message) OVERRIDE; private: - + const HMIMessageHandlerSettings& settings_; HMIMessageObserver* observer_; mutable sync_primitives::Lock observer_locker_; std::set<HMIMessageAdapter*> message_adapters_; @@ -127,7 +127,6 @@ class HMIMessageHandlerImpl impl::FromHmiQueue messages_from_hmi_; DISALLOW_COPY_AND_ASSIGN(HMIMessageHandlerImpl); - FRIEND_BASE_SINGLETON_CLASS(HMIMessageHandlerImpl); }; } // namespace hmi_message_handler diff --git a/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc b/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc index c6d8cf4a50..4081facb4e 100644 --- a/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc +++ b/src/components/hmi_message_handler/src/hmi_message_handler_impl.cc @@ -31,21 +31,22 @@ */ #include "hmi_message_handler/hmi_message_handler_impl.h" -#include "config_profile/profile.h" #include "utils/logger.h" namespace hmi_message_handler { CREATE_LOGGERPTR_GLOBAL(logger_, "HMIMessageHandler") -HMIMessageHandlerImpl::HMIMessageHandlerImpl() - : observer_(NULL), - messages_to_hmi_("HMH ToHMI", this, - threads::ThreadOptions( - profile::Profile::instance()->thread_min_stack_size())), - messages_from_hmi_("HMH FromHMI", this, - threads::ThreadOptions( - profile::Profile::instance()->thread_min_stack_size())) { +HMIMessageHandlerImpl::HMIMessageHandlerImpl( + const HMIMessageHandlerSettings& settings) + : settings_(settings) + , observer_(NULL) + , messages_to_hmi_("HMH ToHMI", this, + threads::ThreadOptions( + get_settings().thread_min_stack_size())) + , messages_from_hmi_("HMH FromHMI", this, + threads::ThreadOptions( + get_settings().thread_min_stack_size())){ } HMIMessageHandlerImpl::~HMIMessageHandlerImpl() { @@ -106,6 +107,10 @@ void HMIMessageHandlerImpl::RemoveHMIMessageAdapter( message_adapters_.erase(adapter); } +const HMIMessageHandlerSettings& HMIMessageHandlerImpl::get_settings() const { + return settings_; +} + void HMIMessageHandlerImpl::Handle(const impl::MessageFromHmi message) { LOG4CXX_INFO(logger_, "Received message from hmi"); sync_primitives::AutoLock lock(observer_locker_); diff --git a/src/components/hmi_message_handler/src/messagebroker_adapter.cc b/src/components/hmi_message_handler/src/messagebroker_adapter.cc index ea7cdb696a..260682101c 100644 --- a/src/components/hmi_message_handler/src/messagebroker_adapter.cc +++ b/src/components/hmi_message_handler/src/messagebroker_adapter.cc @@ -33,7 +33,6 @@ #include <string> #include "hmi_message_handler/messagebroker_adapter.h" -#include "config_profile/profile.h" #include "utils/logger.h" namespace hmi_message_handler { diff --git a/src/components/hmi_message_handler/test/hmi_message_adapter_test.cc b/src/components/hmi_message_handler/test/hmi_message_adapter_test.cc index 4a0bf6bb71..67e1c9eff8 100644 --- a/src/components/hmi_message_handler/test/hmi_message_adapter_test.cc +++ b/src/components/hmi_message_handler/test/hmi_message_adapter_test.cc @@ -36,27 +36,33 @@ #include "hmi_message_handler/hmi_message_handler_impl.h" #include "hmi_message_handler/mock_hmi_message_adapter_impl.h" +#include "hmi_message_handler/mock_hmi_message_handler_settings.h" namespace test { namespace components { namespace hmi_message_handler_test { +using ::testing::ReturnRef; using hmi_message_handler::HMIMessageHandlerImpl; typedef utils::SharedPtr<MockHMIMessageAdapterImpl> MockHMIMessageAdapterImplSPtr; TEST(HMIMessageAdapterImplTest, Handler_CorrectPointer_CorrectReturnedPointer) { - HMIMessageHandler* message_handler = HMIMessageHandlerImpl::instance(); + testing::NiceMock<MockHMIMessageHandlerSettings> mock_hmi_message_handler_settings; + const uint64_t stack_size =1000u; + ON_CALL(mock_hmi_message_handler_settings, thread_min_stack_size()) + .WillByDefault(ReturnRef(stack_size)); + HMIMessageHandler* message_handler = new hmi_message_handler::HMIMessageHandlerImpl( + mock_hmi_message_handler_settings);; + MockHMIMessageAdapterImplSPtr message_adapter_impl = utils::MakeShared<MockHMIMessageAdapterImpl>(message_handler); EXPECT_EQ(message_handler, message_adapter_impl->get_handler()); message_handler = NULL; - if (HMIMessageHandlerImpl::exists()) { - HMIMessageHandlerImpl::destroy(); - } + delete message_handler; } TEST(HMIMessageAdapterImplTest, Handler_NULLPointer_CorrectReturnedPointer) { diff --git a/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc b/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc index 85e1d9bd7e..78169ebc37 100644 --- a/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc +++ b/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc @@ -30,18 +30,19 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "application_manager/message.h" -#include "config_profile/profile.h" #include "hmi_message_handler/hmi_message_handler_impl.h" #include "hmi_message_handler/messagebroker_adapter.h" #include "hmi_message_handler/mock_hmi_message_observer.h" +#include "hmi_message_handler/mock_hmi_message_handler_settings.h" #include "utils/make_shared.h" namespace test { namespace components { namespace hmi_message_handler_test { +using ::testing::ReturnRef; class HMIMessageHandlerImplTest : public ::testing::Test { public: HMIMessageHandlerImplTest() @@ -53,15 +54,20 @@ class HMIMessageHandlerImplTest : public ::testing::Test { hmi_message_handler::MessageBrokerAdapter* mb_adapter_; hmi_message_handler::HMIMessageHandlerImpl* hmi_handler_; hmi_message_handler::MockHMIMessageObserver* mock_hmi_message_observer_; + testing::NiceMock<MockHMIMessageHandlerSettings> mock_hmi_message_handler_settings; + const uint64_t stack_size =1000u; virtual void SetUp() OVERRIDE { - hmi_handler_ = hmi_message_handler::HMIMessageHandlerImpl::instance(); + ON_CALL(mock_hmi_message_handler_settings, thread_min_stack_size()) + .WillByDefault(ReturnRef(stack_size)); + hmi_handler_ = new hmi_message_handler::HMIMessageHandlerImpl( + mock_hmi_message_handler_settings); ASSERT_TRUE(NULL != hmi_handler_); mb_adapter_ = new hmi_message_handler::MessageBrokerAdapter( hmi_handler_, "localhost", 22); ASSERT_TRUE(NULL != mb_adapter_); mock_hmi_message_observer_ = - hmi_message_handler::MockHMIMessageObserver::instance(); + new hmi_message_handler::MockHMIMessageObserver(); ASSERT_TRUE(NULL != mock_hmi_message_observer_); hmi_handler_->set_message_observer(mock_hmi_message_observer_); EXPECT_TRUE(NULL != hmi_handler_->observer()); @@ -69,8 +75,8 @@ class HMIMessageHandlerImplTest : public ::testing::Test { virtual void TearDown() OVERRIDE { hmi_handler_->set_message_observer(NULL); - hmi_message_handler::MockHMIMessageObserver::destroy(); - hmi_message_handler::HMIMessageHandlerImpl::destroy(); + delete mock_hmi_message_observer_; + delete hmi_handler_; delete mb_adapter_; } }; diff --git a/src/components/include/hmi_message_handler/hmi_message_handler_settings.h b/src/components/include/hmi_message_handler/hmi_message_handler_settings.h new file mode 100644 index 0000000000..5386869555 --- /dev/null +++ b/src/components/include/hmi_message_handler/hmi_message_handler_settings.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_HMI_MESSAGE_HANDLER_SETTINGS_H_ +#define SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_HMI_MESSAGE_HANDLER_SETTINGS_H_ + +#include <stdint.h> + +namespace hmi_message_handler { +/** + * \class HMIMessageHandlerSettings + * \brief Interface for hmi message handler component settings. + */ +class HMIMessageHandlerSettings { + public: + virtual ~HMIMessageHandlerSettings() {} + + virtual const uint64_t& thread_min_stack_size() const = 0; +}; +} // namespace hmi_message_handler +#endif // SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_HMI_MESSAGE_HANDLER_SETTINGS_H_ diff --git a/src/components/include/test/hmi_message_handler/mock_hmi_message_handler_settings.h b/src/components/include/test/hmi_message_handler/mock_hmi_message_handler_settings.h new file mode 100644 index 0000000000..a3f73ac965 --- /dev/null +++ b/src/components/include/test/hmi_message_handler/mock_hmi_message_handler_settings.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_MOCK_HMI_MESSAGE_HANDLER_SETTINGS_H_ +#define SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_MOCK_HMI_MESSAGE_HANDLER_SETTINGS_H_ + +#include <stdint.h> +#include "gmock/gmock.h" +#include "hmi_message_handler/hmi_message_handler_settings.h" + +namespace test { +namespace components { +namespace hmi_message_handler_test { + +class MockHMIMessageHandlerSettings + : public ::hmi_message_handler::HMIMessageHandlerSettings { + public: + MOCK_CONST_METHOD0(thread_min_stack_size, const uint64_t&()); +}; +} // namespace hmi_message_handler_test +} // namespace components +} // namespace test +#endif // SRC_COMPONENTS_INCLUDE_HMI_MESSAGE_HANDLER_MOCK_HMI_MESSAGE_HANDLER_SETTINGS_H_ |