diff options
Diffstat (limited to 'src/components/time_tester')
9 files changed, 345 insertions, 294 deletions
diff --git a/src/components/time_tester/CMakeLists.txt b/src/components/time_tester/CMakeLists.txt index df84bffb12..f9044e81ab 100644 --- a/src/components/time_tester/CMakeLists.txt +++ b/src/components/time_tester/CMakeLists.txt @@ -1,29 +1,63 @@ +# 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. + + +set(TIME_TESTER_SRC_DIR ${COMPONENTS_DIR}/time_tester/src) + include_directories ( - ./include/time_tester - ../utils/include/ - ../protocol_handler/include/ - ../connection_handler/include/ - ../transport_manager/include/ - ../application_manager/include/ - ../hmi_message_handler/include/ - ../formatters/include/ - ../media_manager/include/ - ../smart_objects/include/ - ../config_profile/include/ + include/time_tester + ${COMPONENTS_DIR}/utils/include/ + ${COMPONENTS_DIR}/protocol_handler/include/ + ${COMPONENTS_DIR}/connection_handler/include/ + ${COMPONENTS_DIR}/transport_manager/include/ + ${COMPONENTS_DIR}/application_manager/include/ + ${COMPONENTS_DIR}/policy/src/policy/include/ + ${COMPONENTS_DIR}/hmi_message_handler/include/ + ${COMPONENTS_DIR}/formatters/include/ + ${COMPONENTS_DIR}/media_manager/include/ + ${COMPONENTS_DIR}/smart_objects/include/ + ${COMPONENTS_DIR}/config_profile/include/ ${JSONCPP_INCLUDE_DIRECTORY} ${CMAKE_BINARY_DIR}/src/components/ ${LOG4CXX_INCLUDE_DIRECTORY} ) set (SOURCES - ./src/metric_wrapper.cc - ./src/time_manager.cc - ./src/application_manager_observer.cc - ./src/transport_manager_observer.cc - ./src/protocol_handler_observer.cc - ./src/application_manager_metric.cc - ./src/transport_manager_metric.cc - ./src/protocol_handler_metric.cc + ${TIME_TESTER_SRC_DIR}/metric_wrapper.cc + ${TIME_TESTER_SRC_DIR}/time_manager.cc + ${TIME_TESTER_SRC_DIR}/application_manager_observer.cc + ${TIME_TESTER_SRC_DIR}/transport_manager_observer.cc + ${TIME_TESTER_SRC_DIR}/protocol_handler_observer.cc + ${TIME_TESTER_SRC_DIR}/application_manager_metric.cc + ${TIME_TESTER_SRC_DIR}/transport_manager_metric.cc + ${TIME_TESTER_SRC_DIR}/protocol_handler_metric.cc ) add_library("TimeTester" ${SOURCES}) diff --git a/src/components/time_tester/include/time_tester/application_manager_observer.h b/src/components/time_tester/include/time_tester/application_manager_observer.h index 8331682ecd..9c224f8920 100644 --- a/src/components/time_tester/include/time_tester/application_manager_observer.h +++ b/src/components/time_tester/include/time_tester/application_manager_observer.h @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_OBSERVER_H_ #define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_OBSERVER_H_ diff --git a/src/components/time_tester/include/time_tester/json_keys.h b/src/components/time_tester/include/time_tester/json_keys.h index d1ace3f9d4..532202067f 100644 --- a/src/components/time_tester/include/time_tester/json_keys.h +++ b/src/components/time_tester/include/time_tester/json_keys.h @@ -1,4 +1,4 @@ -/** +/* * * Copyright (c) 2014, Ford Motor Company * All rights reserved. diff --git a/src/components/time_tester/include/time_tester/protocol_handler_observer.h b/src/components/time_tester/include/time_tester/protocol_handler_observer.h index 780e9992f2..4c962cfc84 100644 --- a/src/components/time_tester/include/time_tester/protocol_handler_observer.h +++ b/src/components/time_tester/include/time_tester/protocol_handler_observer.h @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_OBSERVER_H_ #define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_OBSERVER_H_ diff --git a/src/components/time_tester/include/time_tester/time_manager.h b/src/components/time_tester/include/time_tester/time_manager.h index 66dd97595b..dc56d3682c 100644 --- a/src/components/time_tester/include/time_tester/time_manager.h +++ b/src/components/time_tester/include/time_tester/time_manager.h @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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_TIME_MANAGER_INCLUDE_TIME_MANAGER_MEDIA_MANAGER_H_ #define SRC_COMPONENTS_TIME_MANAGER_INCLUDE_TIME_MANAGER_MEDIA_MANAGER_H_ @@ -50,6 +50,8 @@ namespace time_tester { +using ::utils::MessageQueue; + class TimeManager { public: TimeManager(); @@ -64,25 +66,27 @@ class TimeManager { explicit Streamer(TimeManager* const server); ~Streamer(); void threadMain() OVERRIDE; - bool exitThreadMain() OVERRIDE; + void exitThreadMain() OVERRIDE; bool IsReady() const; void Start(); void Stop(); bool Send(const std::string &msg); - volatile bool is_client_connected_; - private: + void PushMessage(utils::SharedPtr<MetricWrapper> metric); + volatile bool is_client_connected_; + private: + void ShutDownAndCloseSocket(int32_t socket_fd); TimeManager* const server_; - int32_t new_socket_fd_; + int32_t server_socket_fd_; + int32_t client_socket_fd_; volatile bool stop_flag_; + MessageQueue<utils::SharedPtr<MetricWrapper> > messages_; DISALLOW_COPY_AND_ASSIGN(Streamer); }; int16_t port_; std::string ip_; - int32_t socket_fd_; bool is_ready_; threads::Thread* thread_; - MessageQueue<utils::SharedPtr<MetricWrapper> > messages_; Streamer* streamer_; ApplicationManagerObserver app_observer; TransportManagerObserver tm_observer; diff --git a/src/components/time_tester/include/time_tester/transport_manager_observer.h b/src/components/time_tester/include/time_tester/transport_manager_observer.h index ee83888329..bd46ba0822 100644 --- a/src/components/time_tester/include/time_tester/transport_manager_observer.h +++ b/src/components/time_tester/include/time_tester/transport_manager_observer.h @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_OBSERVER_H_ #define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_OBSERVER_H_ diff --git a/src/components/time_tester/src/application_manager_observer.cc b/src/components/time_tester/src/application_manager_observer.cc index 67d7268da7..c0d87a0551 100644 --- a/src/components/time_tester/src/application_manager_observer.cc +++ b/src/components/time_tester/src/application_manager_observer.cc @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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. + */ #include "application_manager_observer.h" #include "utils/shared_ptr.h" #include "time_manager.h" diff --git a/src/components/time_tester/src/time_manager.cc b/src/components/time_tester/src/time_manager.cc index 6cabe3ad14..db389dbda0 100644 --- a/src/components/time_tester/src/time_manager.cc +++ b/src/components/time_tester/src/time_manager.cc @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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. + */ #include "time_manager.h" @@ -50,50 +50,44 @@ namespace time_tester { CREATE_LOGGERPTR_GLOBAL(logger_, "TimeManager") TimeManager::TimeManager(): - socket_fd_(0), thread_(NULL), - messages_(), streamer_(NULL), app_observer(this), tm_observer(this), ph_observer(this) { ip_ = profile::Profile::instance()->server_address(); port_ = profile::Profile::instance()->time_testing_port(); + streamer_ = new Streamer(this); + thread_ = threads::CreateThread("TimeManager", streamer_ ); } TimeManager::~TimeManager() { - LOG4CXX_INFO(logger_, "Destroing TimeManager"); Stop(); } void TimeManager::Init(protocol_handler::ProtocolHandlerImpl* ph) { + LOG4CXX_AUTO_TRACE(logger_); DCHECK(ph); - if (!thread_) { - streamer_ = new Streamer(this); - thread_ = threads::CreateThread("TimeManager", streamer_ ); - application_manager::ApplicationManagerImpl::instance()->SetTimeMetricObserver(&app_observer); - transport_manager::TransportManagerDefault::instance()->SetTimeMetricObserver(&tm_observer); - ph->SetTimeMetricObserver(&ph_observer); - thread_->startWithOptions(threads::ThreadOptions()); - LOG4CXX_INFO(logger_, "Create and start sending thread"); - } + if (!ph) { + LOG4CXX_DEBUG(logger_, "ProtocolHandler poiner is NULL"); + return; + } + + application_manager::ApplicationManagerImpl::instance()->SetTimeMetricObserver(&app_observer); + transport_manager::TransportManagerDefault::instance()->SetTimeMetricObserver(&tm_observer); + ph->SetTimeMetricObserver(&ph_observer); + thread_->start(threads::ThreadOptions()); } void TimeManager::Stop() { - if (thread_) { - thread_->stop(); - thread_ = NULL; - if (socket_fd_ != -1) { - ::close(socket_fd_); - } - } - messages_.Reset(); - LOG4CXX_INFO(logger_, "TimeManager stopped"); + LOG4CXX_AUTO_TRACE(logger_); + threads::DeleteThread(thread_); + thread_ = NULL; } void TimeManager::SendMetric(utils::SharedPtr<MetricWrapper> metric) { if ((NULL != streamer_ )&& streamer_->is_client_connected_) { - messages_.push(metric); + streamer_->PushMessage(metric); } } @@ -101,7 +95,8 @@ TimeManager::Streamer::Streamer( TimeManager* const server) : is_client_connected_(false), server_(server), - new_socket_fd_(0), + server_socket_fd_(0), + client_socket_fd_(0), stop_flag_(false) { } @@ -110,54 +105,55 @@ TimeManager::Streamer::~Streamer() { } void TimeManager::Streamer::threadMain() { - LOG4CXX_INFO(logger_, "Streamer::threadMain"); + LOG4CXX_AUTO_TRACE(logger_); Start(); - while (!stop_flag_) { - new_socket_fd_ = accept(server_->socket_fd_, NULL, NULL); - if (0 > new_socket_fd_) { + LOG4CXX_INFO(logger_, "Server socket is listening "); + client_socket_fd_ = accept(server_socket_fd_, NULL, NULL); + if (0 > client_socket_fd_) { LOG4CXX_ERROR(logger_, "Cant open socket . Socket is busy "); Stop(); break; } + LOG4CXX_INFO(logger_, "Client connected"); is_client_connected_ = true; while (is_client_connected_) { - while (!server_->messages_.empty()) { - utils::SharedPtr<MetricWrapper> metric = server_->messages_.pop(); + while (!messages_.empty()) { + utils::SharedPtr<MetricWrapper> metric = messages_.pop(); is_client_connected_ = Send(metric->GetStyledString()); } if (!IsReady()) { LOG4CXX_INFO(logger_, "Client disconnected."); - Stop(); break; } - server_->messages_.wait(); + messages_.wait(); } } } -bool TimeManager::Streamer::exitThreadMain() { - LOG4CXX_INFO(logger_, "Streamer::exitThreadMain"); - stop_flag_ = true; +void TimeManager::Streamer::exitThreadMain() { + LOG4CXX_AUTO_TRACE(logger_); Stop(); - server_->messages_.Shutdown(); - return false; + messages_.Shutdown(); } void TimeManager::Streamer::Start() { - server_->socket_fd_ = socket(AF_INET, SOCK_STREAM, 0); + LOG4CXX_AUTO_TRACE(logger_); + server_socket_fd_ = socket(AF_INET, SOCK_STREAM, 0); - if (0 >= server_->socket_fd_) { + if (0 >= server_socket_fd_) { LOG4CXX_ERROR_EXT(logger_, "Server open error"); return; + } else { + LOG4CXX_DEBUG(logger_, "Server socket : " << server_socket_fd_); } int32_t optval = 1; - if (-1 == setsockopt(server_->socket_fd_, SOL_SOCKET, SO_REUSEADDR, + if (-1 == setsockopt(server_socket_fd_, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)) { LOG4CXX_ERROR_EXT(logger_, "Unable to set sockopt"); return; @@ -168,37 +164,49 @@ void TimeManager::Streamer::Start() { serv_addr_.sin_family = AF_INET; serv_addr_.sin_port = htons(server_->port_); - if (-1 == bind(server_->socket_fd_, + if (-1 == bind(server_socket_fd_, reinterpret_cast<struct sockaddr*>(&serv_addr_), sizeof(serv_addr_))) { LOG4CXX_ERROR(logger_, "Unable to bind server " << server_->ip_.c_str() << ':' << server_->port_); return; } - if (-1 == listen(server_->socket_fd_, 1)) { + if (-1 == listen(server_socket_fd_, 1)) { LOG4CXX_ERROR(logger_, "Streamer listen error " << strerror(errno) ); return; } - LOG4CXX_INFO(logger_, "Streamer is listetning for connections"); } -void TimeManager::Streamer::Stop() { - LOG4CXX_INFO(logger_, "SocketStreamerAdapter::Streamer::stop"); - if (!new_socket_fd_) { - return; - } - - if (-1 == shutdown(new_socket_fd_, SHUT_RDWR)) { - LOG4CXX_ERROR(logger_, "Unable to shutdown socket"); - return; +void TimeManager::Streamer::ShutDownAndCloseSocket(int32_t socket_fd) { + LOG4CXX_AUTO_TRACE(logger_); + if (0 < socket_fd){ + LOG4CXX_INFO(logger_, "Shutdown socket"); + if (-1 == ::shutdown(socket_fd, SHUT_RDWR)) { + LOG4CXX_ERROR(logger_, "Unable to shutdown socket"); + } + if (-1 == close(socket_fd)) { + LOG4CXX_ERROR(logger_, "Unable to close socket"); + } + } else { + LOG4CXX_WARN(logger_, "Socket in not connected: " << socket_fd); } +} - if (-1 == close(new_socket_fd_)) { - LOG4CXX_ERROR(logger_, "Unable to close socket"); +void TimeManager::Streamer::Stop() { + LOG4CXX_AUTO_TRACE(logger_); + if (stop_flag_) { + LOG4CXX_WARN(logger_, "Already Stopped"); return; } + stop_flag_ = true; + messages_.Reset(); + LOG4CXX_WARN(logger_, "Stop server_socket_fd_"); + ShutDownAndCloseSocket(server_socket_fd_); + server_socket_fd_ = -1; - new_socket_fd_ = -1; + LOG4CXX_WARN(logger_, "Stop client_socket_fd_"); + ShutDownAndCloseSocket(client_socket_fd_); + client_socket_fd_ = -1; is_client_connected_ = false; } @@ -206,12 +214,12 @@ bool TimeManager::Streamer::IsReady() const { bool result = true; fd_set fds; FD_ZERO(&fds); - FD_SET(new_socket_fd_, &fds); - TimevalStruct tv; + FD_SET(client_socket_fd_, &fds); + TimevalStruct tv = {0, 0}; tv.tv_sec = 5; // set a 5 second timeout tv.tv_usec = 0; - const int retval = select(new_socket_fd_ + 1, 0, &fds, 0, &tv); + const int retval = select(client_socket_fd_ + 1, 0, &fds, 0, &tv); if (-1 == retval) { LOG4CXX_ERROR_EXT(logger_, "An error occurred"); @@ -225,16 +233,21 @@ bool TimeManager::Streamer::IsReady() const { } bool TimeManager::Streamer::Send(const std::string& msg) { + LOG4CXX_AUTO_TRACE(logger_); if (!IsReady()) { LOG4CXX_ERROR_EXT(logger_, " Socket is not ready"); return false; } - if (-1 == ::send(new_socket_fd_, msg.c_str(), + if (-1 == ::send(client_socket_fd_, msg.c_str(), msg.size(), MSG_NOSIGNAL)) { LOG4CXX_ERROR_EXT(logger_, " Unable to send"); return false; } return true; } + +void TimeManager::Streamer::PushMessage(utils::SharedPtr<MetricWrapper> metric) { + messages_.push(metric); +} } // namespace time_tester diff --git a/src/components/time_tester/src/transport_manager_observer.cc b/src/components/time_tester/src/transport_manager_observer.cc index 41cb30126a..6c63a576e7 100644 --- a/src/components/time_tester/src/transport_manager_observer.cc +++ b/src/components/time_tester/src/transport_manager_observer.cc @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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. + */ #include "transport_manager_observer.h" #include <time.h> |