From 253f9a224e8e78182b3e5f26c422002a3b581c2c Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Thu, 10 Mar 2016 10:59:30 +0200 Subject: TimeTester refatctoring. Removed singletone using from TimeTester. TimeTester renamed -> TelemetryMonitor. All files and directories corrected. Tests corrected, all works. Disabled 2 tests(task created). Related to : APPLINK-21915 --- src/components/telemetry_monitor/CMakeLists.txt | 69 +++++ .../telemetry_monitor/application_manager_metric.h | 54 ++++ .../application_manager_observer.h | 55 ++++ .../include/telemetry_monitor/json_keys.h | 52 ++++ .../include/telemetry_monitor/metric_wrapper.h | 59 +++++ .../telemetry_monitor/protocol_handler_metric.h | 50 ++++ .../telemetry_monitor/protocol_handler_observer.h | 56 ++++ .../include/telemetry_monitor/telemetry_monitor.h | 105 ++++++++ .../telemetry_monitor/transport_manager_metric.h | 48 ++++ .../telemetry_monitor/transport_manager_observer.h | 54 ++++ .../src/application_manager_metric.cc | 55 ++++ .../src/application_manager_observer.cc | 49 ++++ .../telemetry_monitor/src/metric_wrapper.cc | 78 ++++++ .../src/protocol_handler_metric.cc | 51 ++++ .../src/protocol_handler_observer.cc | 73 ++++++ .../telemetry_monitor/src/telemetry_monitor.cc | 288 +++++++++++++++++++++ .../src/transport_manager_metric.cc | 51 ++++ .../src/transport_manager_observer.cc | 63 +++++ .../telemetry_monitor/test/CMakeLists.txt | 87 +++++++ .../test/application_manager_metric_test.cc | 118 +++++++++ .../test/application_manager_observer_test.cc | 59 +++++ .../telemetry_monitor/mock_telemetry_monitor.h | 58 +++++ .../telemetry_monitor/test/log4cxx.properties | 19 ++ .../telemetry_monitor/test/metric_wrapper_test.cc | 82 ++++++ .../test/protocol_handler_metric_test.cc | 119 +++++++++ .../test/protocol_handler_observer_test.cc | 81 ++++++ .../test/telemetry_monitor_test.cc | 106 ++++++++ .../test/transport_manager_metric_test.cc | 110 ++++++++ .../test/transport_manager_observer_test.cc | 58 +++++ 29 files changed, 2207 insertions(+) create mode 100644 src/components/telemetry_monitor/CMakeLists.txt create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/json_keys.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h create mode 100644 src/components/telemetry_monitor/src/application_manager_metric.cc create mode 100644 src/components/telemetry_monitor/src/application_manager_observer.cc create mode 100644 src/components/telemetry_monitor/src/metric_wrapper.cc create mode 100644 src/components/telemetry_monitor/src/protocol_handler_metric.cc create mode 100644 src/components/telemetry_monitor/src/protocol_handler_observer.cc create mode 100644 src/components/telemetry_monitor/src/telemetry_monitor.cc create mode 100644 src/components/telemetry_monitor/src/transport_manager_metric.cc create mode 100644 src/components/telemetry_monitor/src/transport_manager_observer.cc create mode 100644 src/components/telemetry_monitor/test/CMakeLists.txt create mode 100644 src/components/telemetry_monitor/test/application_manager_metric_test.cc create mode 100644 src/components/telemetry_monitor/test/application_manager_observer_test.cc create mode 100644 src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h create mode 100644 src/components/telemetry_monitor/test/log4cxx.properties create mode 100644 src/components/telemetry_monitor/test/metric_wrapper_test.cc create mode 100644 src/components/telemetry_monitor/test/protocol_handler_metric_test.cc create mode 100644 src/components/telemetry_monitor/test/protocol_handler_observer_test.cc create mode 100644 src/components/telemetry_monitor/test/telemetry_monitor_test.cc create mode 100644 src/components/telemetry_monitor/test/transport_manager_metric_test.cc create mode 100644 src/components/telemetry_monitor/test/transport_manager_observer_test.cc (limited to 'src/components/telemetry_monitor') diff --git a/src/components/telemetry_monitor/CMakeLists.txt b/src/components/telemetry_monitor/CMakeLists.txt new file mode 100644 index 0000000000..8ce8d19f85 --- /dev/null +++ b/src/components/telemetry_monitor/CMakeLists.txt @@ -0,0 +1,69 @@ +# Copyright (c) 2016, 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(TELEMETRY_MONITOR_SRC_DIR ${COMPONENTS_DIR}/telemetry_monitor/src) + +include_directories ( + include + ${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 + ${TELEMETRY_MONITOR_SRC_DIR}/metric_wrapper.cc + ${TELEMETRY_MONITOR_SRC_DIR}/telemetry_monitor.cc + ${TELEMETRY_MONITOR_SRC_DIR}/application_manager_observer.cc + ${TELEMETRY_MONITOR_SRC_DIR}/transport_manager_observer.cc + ${TELEMETRY_MONITOR_SRC_DIR}/protocol_handler_observer.cc + ${TELEMETRY_MONITOR_SRC_DIR}/application_manager_metric.cc + ${TELEMETRY_MONITOR_SRC_DIR}/transport_manager_metric.cc + ${TELEMETRY_MONITOR_SRC_DIR}/protocol_handler_metric.cc +) + +add_library("TelemetryMonitor" ${SOURCES}) +target_link_libraries("TelemetryMonitor" ${LIBRARIES}) +add_dependencies("TelemetryMonitor" HMI_API MOBILE_API) + +if(BUILD_TESTS) + add_subdirectory(test) +endif() diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h new file mode 100644 index 0000000000..df568e7ebd --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h @@ -0,0 +1,54 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ + +#include + +#include "telemetry_monitor/metric_wrapper.h" +#include "telemetry_monitor/application_manager_observer.h" + + +namespace telemetry_monitor { + +class ApplicationManagerObserver; + +class ApplicationManagerMetricWrapper: public MetricWrapper { + + public: + utils::SharedPtr message_metric; + virtual Json::Value GetJsonMetric(); +}; + +} +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h new file mode 100644 index 0000000000..995aad1085 --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h @@ -0,0 +1,55 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_OBSERVER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_OBSERVER_H_ + +#include "utils/message_queue.h" +#include "application_manager/telemetry_observer.h" +#include "telemetry_monitor/application_manager_metric.h" + + +namespace telemetry_monitor { + +class TelemetryMonitor; + +class ApplicationManagerObserver: public application_manager::AMTelemetryObserver { + public: + explicit ApplicationManagerObserver(TelemetryMonitor* telemetry_monitor); + virtual void OnMessage(utils::SharedPtr metric); + + private: + TelemetryMonitor* telemetry_monitor_; +}; + +} +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_OBSERVER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/json_keys.h b/src/components/telemetry_monitor/include/telemetry_monitor/json_keys.h new file mode 100644 index 0000000000..f5aba07721 --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/json_keys.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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_JSON_KEYS_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_JSON_KEYS_H_ + +namespace telemetry_monitor { + namespace strings { + const char logger[] = "logger"; + const char begin[] = "begin"; + const char end[] = "end"; + const char data_size[] = "data_size"; + const char message_id[] = "message_id"; + const char session_id[] = "session_id"; + const char correlation_id[] = "correlation_id"; + const char connection_key[] = "connection_key"; + const char stime[] = "stime"; + const char utime[] = "utime"; + const char memory[] = "RAM"; + } +} +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_JSON_KEYS_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h new file mode 100644 index 0000000000..66a0dc74f3 --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h @@ -0,0 +1,59 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_H_ + +#include +#include "utils/resource_usage.h" +#include "json/json.h" + +namespace telemetry_monitor { + +class MetricWrapper { + utils::ResourseUsage* resources; + public: + MetricWrapper(); + /* + * @brief get current cpu and memory info and store it as member + */ + bool grabResources(); + virtual std::string GetStyledString(); + virtual Json::Value GetJsonMetric(); + virtual ~MetricWrapper(); + protected: + void Clear(); +}; + + +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.h b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.h new file mode 100644 index 0000000000..d3c27ba55b --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_H_ + +#include +#include "utils/shared_ptr.h" +#include "telemetry_monitor/metric_wrapper.h" +#include "protocol_handler_observer.h" + +namespace telemetry_monitor { + +class ProtocolHandlerMecticWrapper: public MetricWrapper { + + public: + utils::SharedPtr message_metric; + virtual Json::Value GetJsonMetric(); +}; +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h new file mode 100644 index 0000000000..c9f6a7f07f --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h @@ -0,0 +1,56 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_OBSERVER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_OBSERVER_H_ + +#include "protocol_handler/telemetry_observer.h" +#include "utils/message_queue.h" + +namespace telemetry_monitor { + +class TelemetryMonitor; + +class ProtocolHandlerObserver: public protocol_handler::PHTelemetryObserver { + public: + explicit ProtocolHandlerObserver(TelemetryMonitor* telemetry_monitor); + + virtual void StartMessageProcess(uint32_t message_id, const TimevalStruct& start_time); + + virtual void EndMessageProcess(utils::SharedPtr m); + + private: + TelemetryMonitor* telemetry_monitor_; + std::map time_starts; +}; +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_OBSERVER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h b/src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h new file mode 100644 index 0000000000..316f687b46 --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h @@ -0,0 +1,105 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_H_ + +#include + +#include "utils/shared_ptr.h" +#include "utils/message_queue.h" +#include "utils/threads/thread.h" +#include "utils/threads/thread_delegate.h" +#include "telemetry_monitor/metric_wrapper.h" +#include "telemetry_monitor/application_manager_observer.h" +#include "application_manager/application_manager_impl.h" +#include "telemetry_monitor/transport_manager_observer.h" +#include "transport_manager/transport_manager_impl.h" +#include "protocol_handler_observer.h" +#include "protocol_handler/protocol_handler_impl.h" + +namespace telemetry_monitor { + +using ::utils::MessageQueue; + +class Streamer : public threads::ThreadDelegate { + public: + explicit Streamer(TelemetryMonitor* const server); + ~Streamer(); + void threadMain() OVERRIDE; + void exitThreadMain() OVERRIDE; + + virtual void PushMessage(utils::SharedPtr metric); + volatile bool is_client_connected_; + private: + void Start(); + void Stop(); + bool IsReady() const; + bool Send(const std::string &msg); + void ShutDownAndCloseSocket(int32_t socket_fd); + TelemetryMonitor* const kserver_; + int32_t server_socket_fd_; + int32_t client_socket_fd_; + volatile bool stop_flag_; + MessageQueue > messages_; + DISALLOW_COPY_AND_ASSIGN(Streamer); +}; + +class TelemetryMonitor { + public: + TelemetryMonitor(const std::string& server_address, uint16_t port); + virtual ~TelemetryMonitor(); + virtual void Init( + TelemetryObservable* protocol_handler, + TelemetryObservable* app_manager, + TelemetryObservable* transport_manager); + virtual void Stop(); + virtual void Start(); + virtual void SendMetric(utils::SharedPtr metric); + void set_streamer(Streamer* streamer); + const std::string& ip() const; + int16_t port() const; + + private: + std::string server_address_; + int16_t port_; + bool is_ready_; + threads::Thread* thread_; + Streamer* streamer_; + ApplicationManagerObserver app_observer; + TransportManagerObserver tm_observer; + ProtocolHandlerObserver ph_observer; + + DISALLOW_COPY_AND_ASSIGN(TelemetryMonitor); +}; +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h new file mode 100644 index 0000000000..1e6cb501bc --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h @@ -0,0 +1,48 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_H_ + +#include +#include "telemetry_monitor/metric_wrapper.h" +#include "telemetry_monitor/transport_manager_observer.h" + +namespace telemetry_monitor { + +class TransportManagerMecticWrapper: public MetricWrapper { + public: + utils::SharedPtr message_metric; + virtual Json::Value GetJsonMetric(); +}; +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h new file mode 100644 index 0000000000..9390ecd209 --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h @@ -0,0 +1,54 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_OBSERVER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_OBSERVER_H_ + +#include "transport_manager/telemetry_observer.h" +#include "utils/message_queue.h" +#include "utils/date_time.h" + +namespace telemetry_monitor { + +class TelemetryMonitor; + +class TransportManagerObserver: public transport_manager::TMTelemetryObserver { + public: + explicit TransportManagerObserver(TelemetryMonitor* telemetry_monitor); + virtual void StartRawMsg(const protocol_handler::RawMessage* ptr); + virtual void StopRawMsg(const protocol_handler::RawMessage* ptr); + private: + TelemetryMonitor* telemetry_monitor_; + std::map time_starts; +}; +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_OBSERVER_H_ diff --git a/src/components/telemetry_monitor/src/application_manager_metric.cc b/src/components/telemetry_monitor/src/application_manager_metric.cc new file mode 100644 index 0000000000..0af9570c41 --- /dev/null +++ b/src/components/telemetry_monitor/src/application_manager_metric.cc @@ -0,0 +1,55 @@ +/* + * 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 "telemetry_monitor/application_manager_metric.h" +#include "telemetry_monitor/json_keys.h" +#include "application_manager/smart_object_keys.h" +#include "utils/convert_utils.h" + +namespace telemetry_monitor { + +Json::Value ApplicationManagerMetricWrapper::GetJsonMetric() { + Json::Value result = MetricWrapper::GetJsonMetric(); + result[strings::logger] = "ApplicationManager"; + result[strings::begin] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); + result[strings::end] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); + const NsSmartDeviceLink::NsSmartObjects::SmartObject& params = + message_metric->message->getElement(application_manager::strings::params); + result[strings::correlation_id] = utils::ConvertInt64ToLongLongInt( + params[application_manager::strings::correlation_id].asInt()); + result[strings::connection_key] = utils::ConvertInt64ToLongLongInt( + params[application_manager::strings::connection_key].asInt()); + return result; +} +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/application_manager_observer.cc b/src/components/telemetry_monitor/src/application_manager_observer.cc new file mode 100644 index 0000000000..47570497cf --- /dev/null +++ b/src/components/telemetry_monitor/src/application_manager_observer.cc @@ -0,0 +1,49 @@ +/* + * 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 "telemetry_monitor/application_manager_observer.h" +#include "utils/shared_ptr.h" +#include "telemetry_monitor/telemetry_monitor.h" +#include "telemetry_monitor/application_manager_metric.h" + +namespace telemetry_monitor { + +ApplicationManagerObserver::ApplicationManagerObserver(TelemetryMonitor* telemetry_monitor): + telemetry_monitor_(telemetry_monitor) { +} + +void ApplicationManagerObserver::OnMessage(utils::SharedPtr metric) { + ApplicationManagerMetricWrapper* m = new ApplicationManagerMetricWrapper(); + m->message_metric = metric; + m->grabResources(); + telemetry_monitor_->SendMetric(m); +} +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/metric_wrapper.cc b/src/components/telemetry_monitor/src/metric_wrapper.cc new file mode 100644 index 0000000000..2803921501 --- /dev/null +++ b/src/components/telemetry_monitor/src/metric_wrapper.cc @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015, 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 "telemetry_monitor/metric_wrapper.h" +#include "telemetry_monitor/json_keys.h" + +namespace telemetry_monitor { + + MetricWrapper::MetricWrapper(): + resources(NULL) { + } + +bool MetricWrapper::grabResources() { + Clear(); + resources = utils::Resources::getCurrentResourseUsage(); + if (NULL != resources) { + return true; + } else { + return false; + } + flush(std::cout); +} + +std::string MetricWrapper::GetStyledString() { + return GetJsonMetric().toStyledString(); +} + +Json::Value MetricWrapper::GetJsonMetric() { + Json::Value result; + if (resources) { + result[strings::stime] = resources->stime; + result[strings::utime] = resources->utime; + result[strings::memory] = resources->memory; + } + return result; +} + +void MetricWrapper::Clear() { + if (NULL != resources) { + delete resources; + resources = NULL; + } +} + +MetricWrapper::~MetricWrapper() { + Clear(); +} + +} diff --git a/src/components/telemetry_monitor/src/protocol_handler_metric.cc b/src/components/telemetry_monitor/src/protocol_handler_metric.cc new file mode 100644 index 0000000000..35beb3e1f7 --- /dev/null +++ b/src/components/telemetry_monitor/src/protocol_handler_metric.cc @@ -0,0 +1,51 @@ +/* + * 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 "telemetry_monitor/protocol_handler_metric.h" +#include "json/json.h" +#include "telemetry_monitor/json_keys.h" + +namespace telemetry_monitor { + +Json::Value ProtocolHandlerMecticWrapper::GetJsonMetric() { + Json::Value result = MetricWrapper::GetJsonMetric(); + result[strings::logger] = "ProtocolHandler"; + result[strings::begin] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); + result[strings::end] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); + result[strings::message_id] = message_metric->message_id; + result[strings::connection_key] = message_metric->connection_key; + return result; +} + +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/protocol_handler_observer.cc b/src/components/telemetry_monitor/src/protocol_handler_observer.cc new file mode 100644 index 0000000000..c65e20121f --- /dev/null +++ b/src/components/telemetry_monitor/src/protocol_handler_observer.cc @@ -0,0 +1,73 @@ +/* + * 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 "utils/date_time.h" +#include "telemetry_monitor/protocol_handler_observer.h" +#include "telemetry_monitor/protocol_handler_metric.h" +#include "telemetry_monitor/telemetry_monitor.h" + +namespace telemetry_monitor { + +CREATE_LOGGERPTR_GLOBAL(logger_, "TelemetryMonitor") + +ProtocolHandlerObserver::ProtocolHandlerObserver(TelemetryMonitor *telemetry_monitor): + telemetry_monitor_(telemetry_monitor) { +} + +void ProtocolHandlerObserver::StartMessageProcess(uint32_t message_id, + const TimevalStruct &start_time) { + if (message_id == 0) { + return; + } + if (time_starts.find(message_id) != time_starts.end()) { + LOG4CXX_DEBUG(logger_, "Already waiting for stop processing for Message ID: " + << message_id); + return; + } + time_starts[message_id] = start_time; +} + +void ProtocolHandlerObserver::EndMessageProcess(utils::SharedPtr m) { + uint32_t message_id = m->message_id; + std::map::const_iterator it = time_starts.find(message_id); + if (it == time_starts.end()) { + LOG4CXX_WARN(logger_, "Cant find start time for message" << message_id); + return; + } + m->begin = time_starts[message_id]; + m->end = date_time::DateTime::getCurrentTime(); + ProtocolHandlerMecticWrapper* metric = new ProtocolHandlerMecticWrapper(); + metric->message_metric = m; + metric->grabResources(); + telemetry_monitor_->SendMetric(metric); +} +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/telemetry_monitor.cc b/src/components/telemetry_monitor/src/telemetry_monitor.cc new file mode 100644 index 0000000000..7a697cb309 --- /dev/null +++ b/src/components/telemetry_monitor/src/telemetry_monitor.cc @@ -0,0 +1,288 @@ +/* + * 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 "telemetry_monitor/telemetry_monitor.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "transport_manager/transport_manager_default.h" +#include "utils/resource_usage.h" +#include "telemetry_monitor/telemetry_observable.h" + +namespace telemetry_monitor { + +CREATE_LOGGERPTR_GLOBAL(logger_, "TelemetryMonitor") + +TelemetryMonitor::TelemetryMonitor(const std::string& server_address, + uint16_t port): + server_address_(server_address), + port_(port), + thread_(NULL), + streamer_(NULL), + app_observer(this), + tm_observer(this), + ph_observer(this) { + +} + +void TelemetryMonitor::Start() { + streamer_ = new Streamer(this); + thread_ = threads::CreateThread("TelemetryMonitor", streamer_ ); +} + +void TelemetryMonitor::set_streamer(Streamer* streamer) { + LOG4CXX_AUTO_TRACE(logger_); + if (thread_ && !thread_->is_running()) { + thread_->set_delegate(streamer); + if (streamer_) { + delete streamer_; + } + streamer_ = streamer; + } else { + LOG4CXX_ERROR(logger_, "Unable to replace streamer if it is active"); + } +} + +const std::string& TelemetryMonitor::ip() const { + return server_address_; +} + +int16_t TelemetryMonitor::port() const { + return port_; +} + +TelemetryMonitor::~TelemetryMonitor() { + Stop(); +} + +void TelemetryMonitor::Init( + TelemetryObservable* + protocol_handler, + TelemetryObservable* + app_manager, + TelemetryObservable* + transport_manager) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(streamer_); + + app_manager->SetTelemetryObserver(&app_observer); + transport_manager->SetTelemetryObserver(&tm_observer); + protocol_handler->SetTelemetryObserver(&ph_observer); + + DCHECK_OR_RETURN_VOID(thread_); + thread_->start(threads::ThreadOptions()); +} + +void TelemetryMonitor::Stop() { + LOG4CXX_AUTO_TRACE(logger_); + if (thread_) { + thread_->stop(); + thread_->join(); + threads::DeleteThread(thread_); + } + thread_ = NULL; +} + +void TelemetryMonitor::SendMetric(utils::SharedPtr metric) { + if ((NULL != streamer_ )&& streamer_->is_client_connected_) { + streamer_->PushMessage(metric); + } +} + +Streamer::Streamer(TelemetryMonitor* const server) + : is_client_connected_(false), + kserver_(server), + server_socket_fd_(0), + client_socket_fd_(0), + stop_flag_(false) { +} + +Streamer::~Streamer() { + Stop(); +} + +void Streamer::threadMain() { + LOG4CXX_AUTO_TRACE(logger_); + + Start(); + while (!stop_flag_) { + 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 (!messages_.empty()) { + utils::SharedPtr metric; + if (!messages_.pop(metric)) { + continue; + } + is_client_connected_ = Send(metric->GetStyledString()); + } + + if (!IsReady()) { + LOG4CXX_INFO(logger_, "Client disconnected."); + break; + } + + messages_.wait(); + } + } +} + +void Streamer::exitThreadMain() { + LOG4CXX_AUTO_TRACE(logger_); + Stop(); + messages_.Shutdown(); +} + +void Streamer::Start() { + LOG4CXX_AUTO_TRACE(logger_); + server_socket_fd_ = socket(AF_INET, SOCK_STREAM, 0); + + if (0 >= server_socket_fd_) { + LOG4CXX_ERROR(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, + &optval, sizeof optval)) { + LOG4CXX_ERROR(logger_, "Unable to set sockopt"); + return; + } + + sockaddr_in serv_addr_ = { 0 }; + serv_addr_.sin_addr.s_addr = inet_addr(kserver_->ip().c_str()); + serv_addr_.sin_family = AF_INET; + serv_addr_.sin_port = htons(kserver_->port()); + + if (-1 == bind(server_socket_fd_, + reinterpret_cast(&serv_addr_), + sizeof(serv_addr_))) { + LOG4CXX_ERROR(logger_, "Unable to bind server " + << kserver_->ip().c_str() << ':' << kserver_->port()); + return; + } + if (-1 == listen(server_socket_fd_, 1)) { + LOG4CXX_ERROR(logger_, "Streamer listen error " << strerror(errno) ); + return; + } +} + +void 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); + } +} + +void 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; + + LOG4CXX_WARN(logger_, "Stop client_socket_fd_"); + ShutDownAndCloseSocket(client_socket_fd_); + client_socket_fd_ = -1; + is_client_connected_ = false; +} + +bool Streamer::IsReady() const { + bool result = true; + fd_set fds; + FD_ZERO(&fds); + 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(client_socket_fd_ + 1, 0, &fds, 0, &tv); + + if (-1 == retval) { + LOG4CXX_ERROR(logger_, "An error occurred"); + result = false; + } else if (0 == retval) { + LOG4CXX_ERROR(logger_, "The timeout expired"); + result = false; + } + + return result; +} + +bool Streamer::Send(const std::string& msg) { + LOG4CXX_AUTO_TRACE(logger_); + if (!IsReady()) { + LOG4CXX_ERROR(logger_, " Socket is not ready"); + return false; + } + + if (-1 == ::send(client_socket_fd_, msg.c_str(), + msg.size(), MSG_NOSIGNAL)) { + LOG4CXX_ERROR(logger_, " Unable to send"); + return false; + } + return true; +} + +void Streamer::PushMessage(utils::SharedPtr metric) { + messages_.push(metric); +} +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/transport_manager_metric.cc b/src/components/telemetry_monitor/src/transport_manager_metric.cc new file mode 100644 index 0000000000..2e62a63797 --- /dev/null +++ b/src/components/telemetry_monitor/src/transport_manager_metric.cc @@ -0,0 +1,51 @@ +/* + * 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 "telemetry_monitor/transport_manager_metric.h" +#include "json/json.h" +#include "telemetry_monitor/json_keys.h" +#include "application_manager/smart_object_keys.h" + +namespace telemetry_monitor { + +Json::Value TransportManagerMecticWrapper::GetJsonMetric() { + Json::Value result = MetricWrapper::GetJsonMetric(); + result[strings::logger] = "TransportManager"; + result[strings::begin] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); + result[strings::end] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); + result[strings::data_size] = static_cast(message_metric->data_size); + return result; +} + +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/transport_manager_observer.cc b/src/components/telemetry_monitor/src/transport_manager_observer.cc new file mode 100644 index 0000000000..b74bc55b55 --- /dev/null +++ b/src/components/telemetry_monitor/src/transport_manager_observer.cc @@ -0,0 +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. + */ +#include "telemetry_monitor/transport_manager_observer.h" + +#include + +#include "telemetry_monitor/transport_manager_metric.h" +#include "telemetry_monitor/telemetry_monitor.h" + +namespace telemetry_monitor { + +TransportManagerObserver::TransportManagerObserver(TelemetryMonitor* telemetry_monitor): + telemetry_monitor_ (telemetry_monitor) { +} + +void TransportManagerObserver::StartRawMsg(const protocol_handler::RawMessage* ptr) { + time_starts[ptr] = date_time::DateTime::getCurrentTime(); +} + +void TransportManagerObserver::StopRawMsg(const protocol_handler::RawMessage* ptr) { + std::map::const_iterator it; + it = time_starts.find(ptr); + if (it != time_starts.end()) { + TransportManagerMecticWrapper* m = new TransportManagerMecticWrapper(); + m->message_metric = new transport_manager::TMTelemetryObserver::MessageMetric(); + m->message_metric->begin = it->second; + m->message_metric->end = date_time::DateTime::getCurrentTime(); + m->message_metric->data_size = ptr->data_size(); + m->grabResources(); + telemetry_monitor_->SendMetric(m); + } +} + +} //namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/test/CMakeLists.txt b/src/components/telemetry_monitor/test/CMakeLists.txt new file mode 100644 index 0000000000..f574621828 --- /dev/null +++ b/src/components/telemetry_monitor/test/CMakeLists.txt @@ -0,0 +1,87 @@ +# Copyright (c) 2015, 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. + +if(BUILD_TESTS) + +include_directories( + include + ${GMOCK_INCLUDE_DIRECTORY} + ${COMPONENTS_DIR}/telemetry_monitor/include + ${COMPONENTS_DIR}/utils/include + ${COMPONENTS_DIR}/protocol_handler/include + ${COMPONENTS_DIR}/application_manager/include +) + + +set(testSources + metric_wrapper_test.cc + telemetry_monitor_test.cc + protocol_handler_metric_test.cc + protocol_handler_observer_test.cc + transport_manager_metric_test.cc + transport_manager_observer_test.cc + application_manager_metric_test.cc + application_manager_observer_test.cc +) + +set(testLibraries + gmock + TelemetryMonitor + jsoncpp + Utils + MediaManager + ProtocolHandler + v4_protocol_v1_2_no_extra + SmartObjects + ProtocolLibrary + ConfigProfile + ApplicationManager + MessageHelper + Resumption + jsoncpp + transport_manager + MediaManager + ProtocolHandler + connectionHandler +) + +if (BUILD_USB_SUPPORT) + list(APPEND testLibraries Libusb-1.0.16) +endif() + +if (BUILD_BT_SUPPORT) + list(APPEND testLibraries bluetooth) +endif() + +file(COPY log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +create_test("telemetry_monitor_test" "${testSources}" "${testLibraries}") + +endif() diff --git a/src/components/telemetry_monitor/test/application_manager_metric_test.cc b/src/components/telemetry_monitor/test/application_manager_metric_test.cc new file mode 100644 index 0000000000..0ec23ccda0 --- /dev/null +++ b/src/components/telemetry_monitor/test/application_manager_metric_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/json_keys.h" +#include "utils/resource_usage.h" +#include "application_manager/smart_object_keys.h" +#include "telemetry_monitor/application_manager_metric.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace ::telemetry_monitor; + +TEST(ApplicationManagerMetricWrapper, grabResources) { + ApplicationManagerMetricWrapper metric_test; + EXPECT_TRUE(metric_test.grabResources()); +} + +TEST(ApplicationManagerMetricWrapper, GetJsonMetric) { + ApplicationManagerMetricWrapper metric_test; + + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + + TimevalStruct end_time; + end_time.tv_sec = 10; + end_time.tv_usec = 0; + metric_test.message_metric = new application_manager::AMTelemetryObserver::MessageMetric(); + metric_test.message_metric->begin = start_time; + metric_test.message_metric->end = end_time; + NsSmartDeviceLink::NsSmartObjects::SmartObject obj; + obj["params"][application_manager::strings::correlation_id] = 11; + obj["params"][application_manager::strings::connection_key] = 12; + metric_test.message_metric->message = new NsSmartDeviceLink::NsSmartObjects::SmartObject(obj); + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_EQ("null\n", jvalue[telemetry_monitor::strings::stime].toStyledString()); + EXPECT_EQ("null\n", jvalue[telemetry_monitor::strings::utime].toStyledString()); + EXPECT_EQ("null\n", jvalue[telemetry_monitor::strings::memory].toStyledString()); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[telemetry_monitor::strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[telemetry_monitor::strings::end].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::correlation_id].asInt(), jvalue[telemetry_monitor::strings::correlation_id].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::connection_key].asInt(), jvalue[telemetry_monitor::strings::connection_key].asInt()); +} + +TEST(ApplicationManagerMetricWrapper, GetJsonMetricWithGrabResources) { + ApplicationManagerMetricWrapper metric_test; + utils::ResourseUsage* resources = utils::Resources::getCurrentResourseUsage(); + EXPECT_TRUE(metric_test.grabResources()); + + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + + TimevalStruct end_time; + end_time.tv_sec = 10; + end_time.tv_usec = 0; + + metric_test.message_metric = new application_manager::AMTelemetryObserver::MessageMetric(); + metric_test.message_metric->begin = start_time; + metric_test.message_metric->end = end_time; + NsSmartDeviceLink::NsSmartObjects::SmartObject obj; + obj["params"][application_manager::strings::correlation_id] = 11; + obj["params"][application_manager::strings::connection_key] = 12; + metric_test.message_metric->message = new NsSmartDeviceLink::NsSmartObjects::SmartObject(obj); + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[telemetry_monitor::strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[telemetry_monitor::strings::end].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::correlation_id].asInt(), jvalue[telemetry_monitor::strings::correlation_id].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::connection_key].asInt(), jvalue[telemetry_monitor::strings::connection_key].asInt()); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[telemetry_monitor::strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[telemetry_monitor::strings::end].asInt64()); + + EXPECT_NEAR(resources->stime, jvalue[telemetry_monitor::strings::stime].asInt(),1); + EXPECT_NEAR(resources->utime, jvalue[telemetry_monitor::strings::utime].asInt(),1); + EXPECT_EQ(resources->memory, jvalue[telemetry_monitor::strings::memory].asInt()); + + delete resources; +} + +} // namespace telemetry_monitor +} // namespace components +} // namespace test diff --git a/src/components/telemetry_monitor/test/application_manager_observer_test.cc b/src/components/telemetry_monitor/test/application_manager_observer_test.cc new file mode 100644 index 0000000000..9ca0850c15 --- /dev/null +++ b/src/components/telemetry_monitor/test/application_manager_observer_test.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/mock_telemetry_monitor.h" +#include "application_manager/telemetry_observer.h" +#include "telemetry_monitor/application_manager_metric.h" +#include "telemetry_monitor/application_manager_observer.h" +#include "utils/shared_ptr.h" +#include "telemetry_monitor/telemetry_monitor.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace telemetry_monitor; +using ::testing::_; + +TEST(ApplicationManagerObserver, CallOnMessage) { + MockTelemetryMonitor mock_telemetry_monitor; + ApplicationManagerObserver app_observer(&mock_telemetry_monitor); + typedef application_manager::AMTelemetryObserver::MessageMetric AMMetric; + utils::SharedPtr ptr = application_manager::AMTelemetryObserver::MessageMetricSharedPtr(); + EXPECT_CALL(mock_telemetry_monitor, SendMetric(_)); + app_observer.OnMessage(ptr); +} + +} // namespace telemetry_monitor +} // namespace components +} // namespace test diff --git a/src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h b/src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h new file mode 100644 index 0000000000..2d849a634c --- /dev/null +++ b/src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016, 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_TRANSPORT_MANAGER_TEST_INCLUDE_MOCK_TELEMETRY_MONITOR_H_ +#define SRC_COMPONENTS_TRANSPORT_MANAGER_TEST_INCLUDE_MOCK_TELEMETRY_MONITOR_H_ + +#include +#include "gmock/gmock.h" +#include "telemetry_monitor/telemetry_monitor.h" +#include "telemetry_monitor/metric_wrapper.h" +#include "utils/shared_ptr.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +class MockTelemetryMonitor: public telemetry_monitor::TelemetryMonitor { + public: + MockTelemetryMonitor():telemetry_monitor::TelemetryMonitor("",0u){} + MOCK_METHOD1(Init, void(protocol_handler::ProtocolHandlerImpl* ph)); + MOCK_METHOD0(Stop, void()); + MOCK_METHOD0(Start, void()); + MOCK_METHOD1(SendMetric, + void(utils::SharedPtr metric)); +}; +} // namespace transport_manager_test +} // namespace components +} // namespace test +#endif // SRC_COMPONENTS_TRANSPORT_MANAGER_TEST_INCLUDE_MOCK_TELEMETRY_MONITOR_H_ diff --git a/src/components/telemetry_monitor/test/log4cxx.properties b/src/components/telemetry_monitor/test/log4cxx.properties new file mode 100644 index 0000000000..68adbfa7f3 --- /dev/null +++ b/src/components/telemetry_monitor/test/log4cxx.properties @@ -0,0 +1,19 @@ +# Only ERROR and FATAL messages are logged to console +log4j.appender.Console=org.apache.log4j.ConsoleAppender +log4j.appender.Console.ImmediateFlush=true +log4j.appender.Console.layout=org.apache.log4j.PatternLayout +log4j.appender.Console.layout.ConversionPattern=%-5p [%d{dd MMM yyyy HH:mm:ss,SSS}][%c] %m%n +log4j.appender.Console.Threshold=DEBUG + +# Log for all SmartDeviceLinkCore messages +log4j.appender.SmartDeviceLinkCoreLogFile=org.apache.log4j.FileAppender +log4j.appender.SmartDeviceLinkCoreLogFile.File=SmartDeviceLinkCore.log +log4j.appender.SmartDeviceLinkCoreLogFile.append=true +log4j.appender.SmartDeviceLinkCoreLogFile.DatePattern='.' yyyy-MM-dd HH-mm +log4j.appender.SmartDeviceLinkCoreLogFile.ImmediateFlush=true +log4j.appender.SmartDeviceLinkCoreLogFile.layout=org.apache.log4j.PatternLayout +log4j.appender.SmartDeviceLinkCoreLogFile.layout.ConversionPattern=%-5p [%d{dd MMM yyyy HH:mm:ss,SSS}][%c] %F:%L %M: %m%n + + +# All SmartDeviceLinkCore logs +log4j.rootLogger=ALL, Console, SmartDeviceLinkCoreLogFile diff --git a/src/components/telemetry_monitor/test/metric_wrapper_test.cc b/src/components/telemetry_monitor/test/metric_wrapper_test.cc new file mode 100644 index 0000000000..08b9747742 --- /dev/null +++ b/src/components/telemetry_monitor/test/metric_wrapper_test.cc @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/metric_wrapper.h" +#include "telemetry_monitor/json_keys.h" +#include "json/json.h" +#include "utils/resource_usage.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace ::telemetry_monitor; + +TEST(MetricWrapper, grabResources) { + MetricWrapper metric_test; + EXPECT_TRUE(metric_test.grabResources()); +} + +TEST(MetricWrapper, GetJsonMetricWithoutGrab) { + MetricWrapper metric_test; + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_EQ("null\n", jvalue[strings::stime].toStyledString()); + EXPECT_EQ("null\n", jvalue[strings::utime].toStyledString()); + EXPECT_EQ("null\n", jvalue[strings::memory].toStyledString()); +} + +TEST(MetricWrapper, GetJsonMetricWithGrabResources) { + MetricWrapper metric_test; + utils::ResourseUsage* resources = utils::Resources::getCurrentResourseUsage(); + EXPECT_TRUE(resources != NULL); + EXPECT_TRUE(metric_test.grabResources()); + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_TRUE(jvalue[strings::stime].isInt()); + EXPECT_TRUE(jvalue[strings::utime].isInt()); + EXPECT_TRUE(jvalue[strings::memory].isInt()); + EXPECT_NE("null/n", jvalue[strings::stime].toStyledString()); + EXPECT_NE("null/n", jvalue[strings::utime].toStyledString()); + EXPECT_NE("null/n", jvalue[strings::memory].toStyledString()); + + EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(),1); + EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(),1); + EXPECT_EQ(resources->memory, jvalue[strings::memory].asInt()); + + delete resources; +} + +} // namespace telemetry_monitor +} // namespace components +} // namespace test diff --git a/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc b/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc new file mode 100644 index 0000000000..d74244a97f --- /dev/null +++ b/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/json_keys.h" +#include "json/json.h" +#include "utils/resource_usage.h" +#include "telemetry_monitor/protocol_handler_metric.h" +#include "protocol_handler/telemetry_observer.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace ::telemetry_monitor; + +TEST(ProtocolHandlerMetricTest, grabResources) { + ProtocolHandlerMecticWrapper metric_test; + EXPECT_TRUE(metric_test.grabResources()); +} + +TEST(ProtocolHandlerMetricTest, GetJsonMetric) { + ProtocolHandlerMecticWrapper metric_test; + + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + + TimevalStruct end_time; + end_time.tv_sec = 10; + end_time.tv_usec = 0; + metric_test.message_metric = new protocol_handler::PHTelemetryObserver::MessageMetric(); + metric_test.message_metric->begin = start_time; + metric_test.message_metric->end = end_time; + metric_test.message_metric->message_id = 5; + metric_test.message_metric->connection_key = 2; + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_EQ("\"ProtocolHandler\"\n", jvalue[strings::logger].toStyledString()); + EXPECT_EQ("null\n", jvalue[strings::stime].toStyledString()); + EXPECT_EQ("null\n", jvalue[strings::utime].toStyledString()); + EXPECT_EQ("null\n", jvalue[strings::memory].toStyledString()); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(5, jvalue[strings::message_id].asInt64()); + EXPECT_EQ(2, jvalue[strings::connection_key].asInt()); +} + +TEST(ProtocolHandlerMetricTest, GetJsonMetricWithGrabResources) { + ProtocolHandlerMecticWrapper metric_test; + utils::ResourseUsage* resources = utils::Resources::getCurrentResourseUsage(); + EXPECT_TRUE(resources != NULL); + EXPECT_TRUE(metric_test.grabResources()); + + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + + TimevalStruct end_time; + end_time.tv_sec = 10; + end_time.tv_usec = 0; + metric_test.message_metric = new protocol_handler::PHTelemetryObserver::MessageMetric(); + metric_test.message_metric->begin = start_time; + metric_test.message_metric->end = end_time; + metric_test.message_metric->message_id = 5; + metric_test.message_metric->connection_key = 2; + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_TRUE(jvalue[strings::stime].isInt()); + EXPECT_TRUE(jvalue[strings::utime].isInt()); + EXPECT_TRUE(jvalue[strings::memory].isInt()); + EXPECT_NE("null/n", jvalue[strings::stime].toStyledString()); + EXPECT_NE("null/n", jvalue[strings::utime].toStyledString()); + EXPECT_NE("null/n", jvalue[strings::memory].toStyledString()); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(5, jvalue[strings::message_id].asInt64()); + EXPECT_EQ(2, jvalue[strings::connection_key].asInt()); + + EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(),1); + EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(),1); + EXPECT_EQ(resources->memory, jvalue[strings::memory].asInt()); + delete resources; +} + +} // namespace telemetry_monitor +} // namespace components +} // namespace test diff --git a/src/components/telemetry_monitor/test/protocol_handler_observer_test.cc b/src/components/telemetry_monitor/test/protocol_handler_observer_test.cc new file mode 100644 index 0000000000..784e809da6 --- /dev/null +++ b/src/components/telemetry_monitor/test/protocol_handler_observer_test.cc @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/telemetry_monitor.h" +#include "telemetry_monitor/mock_telemetry_monitor.h" +#include "protocol_handler/telemetry_observer.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace telemetry_monitor; +using ::testing::_; + +TEST(ProtocolHandlerObserverTest, MessageProcess) { + MockTelemetryMonitor mock_telemetry_monitor; + + ProtocolHandlerObserver pr_handler(&mock_telemetry_monitor); + uint32_t message_id = 1; + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + pr_handler.StartMessageProcess(message_id, start_time); + + typedef protocol_handler::PHTelemetryObserver::MessageMetric MetricType; + utils::SharedPtr message_metric = new MetricType(); + message_metric->message_id = 1; + EXPECT_CALL(mock_telemetry_monitor, SendMetric(_)); + pr_handler.EndMessageProcess(message_metric); +} + +TEST(ProtocolHandlerObserverTest, MessageProcessWithZeroMessageId) { + MockTelemetryMonitor mock_telemetry_monitor; + + ProtocolHandlerObserver pr_handler(&mock_telemetry_monitor); + uint32_t message_id = 0; + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + pr_handler.StartMessageProcess(message_id, start_time); + + typedef protocol_handler::PHTelemetryObserver::MessageMetric MetricType; + utils::SharedPtr message_metric = new MetricType(); + message_metric->message_id = 0; + EXPECT_CALL(mock_telemetry_monitor, SendMetric(_)).Times(0); + pr_handler.EndMessageProcess(message_metric); +} + +} // namespace telemetry_monitor_test +} // namespace components +} // namespace test diff --git a/src/components/telemetry_monitor/test/telemetry_monitor_test.cc b/src/components/telemetry_monitor/test/telemetry_monitor_test.cc new file mode 100644 index 0000000000..14c7fe4cd5 --- /dev/null +++ b/src/components/telemetry_monitor/test/telemetry_monitor_test.cc @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/telemetry_monitor.h" +#include "protocol_handler/telemetry_observer.h" +#include "protocol_handler/protocol_handler.h" +#include "protocol_handler//mock_protocol_handler.h" +#include "protocol_handler/mock_session_observer.h" +#include "protocol_handler/mock_protocol_handler_settings.h" +#include "connection_handler/mock_connection_handler.h" +#include "transport_manager/transport_manager_mock.h" +#include "telemetry_monitor/mock_telemetry_observable.h" + + +using testing::Return; +using testing::_; + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace telemetry_monitor; + +class StreamerMock : public Streamer { + public: + StreamerMock(TelemetryMonitor* const server) + : Streamer(server) { + is_client_connected_ = true; + } + MOCK_METHOD1(PushMessage,void(utils::SharedPtr metric)); +}; + +TEST(TelemetryMonitorTest, MessageProcess) { + const std::string& server_address = "server_address"; + const uint16_t port = 12345; + MockTelemetryObservable am_observeble; + + transport_manager_test::MockTransportManager transport_manager_mock; + testing::NiceMock + connection_handler_mock; + testing::NiceMock< + ::test::components::protocol_handler_test::MockProtocolHandlerSettings> + protocol_handler_settings_mock; + ::test::components::protocol_handler_test::MockSessionObserver + session_observer_mock; + + const size_t init_value = 1000u; + ON_CALL(protocol_handler_settings_mock, maximum_payload_size()) + .WillByDefault(Return(init_value)); + ON_CALL(protocol_handler_settings_mock, message_frequency_time()) + .WillByDefault(Return(init_value)); + ON_CALL(protocol_handler_settings_mock, malformed_message_filtering()) + .WillByDefault(Return(init_value)); + ON_CALL(protocol_handler_settings_mock, multiframe_waiting_timeout()) + .WillByDefault(Return(init_value)); + protocol_handler::ProtocolHandlerImpl protocol_handler_mock( + protocol_handler_settings_mock, session_observer_mock, + connection_handler_mock, transport_manager_mock); + + EXPECT_CALL(am_observeble, SetTelemetryObserver(_)); + EXPECT_CALL(transport_manager_mock, SetTelemetryObserver(_)); + telemetry_monitor::TelemetryMonitor telemetry_monitor(server_address, port); + StreamerMock streamer_mock(&telemetry_monitor); + telemetry_monitor.Start(); + + telemetry_monitor.set_streamer(&streamer_mock); + telemetry_monitor.Init(&protocol_handler_mock, &am_observeble, + &transport_manager_mock); + utils::SharedPtr test_metric; + EXPECT_CALL(streamer_mock, PushMessage(test_metric)); + telemetry_monitor.SendMetric(test_metric); +} + +} // namespace telemetry_monitor +} // namespace components +} // namespace test diff --git a/src/components/telemetry_monitor/test/transport_manager_metric_test.cc b/src/components/telemetry_monitor/test/transport_manager_metric_test.cc new file mode 100644 index 0000000000..53d4ed1ba4 --- /dev/null +++ b/src/components/telemetry_monitor/test/transport_manager_metric_test.cc @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/json_keys.h" +#include "json/json.h" +#include "utils/resource_usage.h" +#include "telemetry_monitor/transport_manager_metric.h" +#include "protocol_handler/telemetry_observer.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace ::telemetry_monitor; + +TEST(TransportManagerMetricWrapper, grabResources) { + TransportManagerMecticWrapper metric_test; + EXPECT_TRUE(metric_test.grabResources()); +} + +TEST(TransportManagerMetricWrapper, GetJsonMetric) { + TransportManagerMecticWrapper metric_test; + + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + + TimevalStruct end_time; + end_time.tv_sec = 10; + end_time.tv_usec = 0; + metric_test.message_metric = new transport_manager::TMTelemetryObserver::MessageMetric(); + metric_test.message_metric->begin = start_time; + metric_test.message_metric->end = end_time; + metric_test.message_metric->data_size = 1000; + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_EQ("null\n", jvalue[strings::stime].toStyledString()); + EXPECT_EQ("null\n", jvalue[strings::utime].toStyledString()); + EXPECT_EQ("null\n", jvalue[strings::memory].toStyledString()); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(1000, jvalue[strings::data_size].asInt()); +} + +TEST(TransportManagerMetricWrapper, GetJsonMetricWithGrabResources) { + TransportManagerMecticWrapper metric_test; + utils::ResourseUsage* resources = utils::Resources::getCurrentResourseUsage(); + EXPECT_TRUE(resources != NULL); + EXPECT_TRUE(metric_test.grabResources()); + + TimevalStruct start_time; + start_time.tv_sec = 1; + start_time.tv_usec = 0; + + TimevalStruct end_time; + end_time.tv_sec = 10; + end_time.tv_usec = 0; + metric_test.message_metric = new transport_manager::TMTelemetryObserver::MessageMetric(); + metric_test.message_metric->begin = start_time; + metric_test.message_metric->end = end_time; + + metric_test.message_metric->data_size = 1000; + Json::Value jvalue = metric_test.GetJsonMetric(); + + EXPECT_EQ("\"TransportManager\"\n", jvalue[strings::logger].toStyledString()); + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(1000, jvalue[strings::data_size].asInt()); + + EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(),1); + EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(),1); + EXPECT_EQ(resources->memory, jvalue[strings::memory].asInt()); + + delete resources; +} + +} // namespace telemetry_monitor +} // namespace components +} // namespace test diff --git a/src/components/telemetry_monitor/test/transport_manager_observer_test.cc b/src/components/telemetry_monitor/test/transport_manager_observer_test.cc new file mode 100644 index 0000000000..eba786ef70 --- /dev/null +++ b/src/components/telemetry_monitor/test/transport_manager_observer_test.cc @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, 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 "gtest/gtest.h" +#include "telemetry_monitor/mock_telemetry_monitor.h" +#include "protocol_handler/telemetry_observer.h" +#include "telemetry_monitor/transport_manager_metric.h" +#include "telemetry_monitor/transport_manager_observer.h" + +namespace test { +namespace components { +namespace telemetry_monitor_test { + +using namespace telemetry_monitor; +using ::testing::_; + +TEST(TransportManagerObserverTest, MessageProcess) { + MockTelemetryMonitor mock_telemetry_monitor; + TransportManagerObserver tr_observer(&mock_telemetry_monitor); + protocol_handler::RawMessage* ptr = new ::protocol_handler::RawMessage(0, 0, NULL, 0); + tr_observer.StartRawMsg(ptr); + EXPECT_CALL(mock_telemetry_monitor, SendMetric(_)); + tr_observer.StopRawMsg(ptr); + delete ptr; +} + +} // namespace telemetry_monitor +} // namespace components +} // namespace test -- cgit v1.2.1 From 08503f46dd3b829fde82ff1408933f367191466a Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Wed, 16 Mar 2016 10:54:41 +0200 Subject: Changes after review Renamed h && cc file names in telemetry_monitor. Corrected header-guards. Corrected commented code in gmock. Created TODO and tasks for them. --- src/components/telemetry_monitor/CMakeLists.txt | 6 +-- .../telemetry_monitor/application_manager_metric.h | 54 --------------------- .../application_manager_metric_wrapper.h | 54 +++++++++++++++++++++ .../application_manager_observer.h | 2 +- .../include/telemetry_monitor/metric_wrapper.h | 6 +-- .../telemetry_monitor/protocol_handler_metric.h | 50 -------------------- .../protocol_handler_metric_wrapper.h | 50 ++++++++++++++++++++ .../telemetry_monitor/transport_manager_metric.h | 48 ------------------- .../transport_manager_metric_wrapper.h | 48 +++++++++++++++++++ .../src/application_manager_metric.cc | 55 ---------------------- .../src/application_manager_metric_wrapper.cc | 55 ++++++++++++++++++++++ .../src/application_manager_observer.cc | 2 +- .../src/protocol_handler_metric.cc | 51 -------------------- .../src/protocol_handler_metric_wrapper.cc | 51 ++++++++++++++++++++ .../src/protocol_handler_observer.cc | 2 +- .../src/transport_manager_metric.cc | 51 -------------------- .../src/transport_manager_metric_wrapper.cc | 51 ++++++++++++++++++++ .../src/transport_manager_observer.cc | 2 +- .../test/application_manager_metric_test.cc | 2 +- .../test/application_manager_observer_test.cc | 2 +- .../test/protocol_handler_metric_test.cc | 2 +- .../test/transport_manager_metric_test.cc | 2 +- .../test/transport_manager_observer_test.cc | 2 +- 23 files changed, 324 insertions(+), 324 deletions(-) delete mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h delete mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.h delete mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h create mode 100644 src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h delete mode 100644 src/components/telemetry_monitor/src/application_manager_metric.cc create mode 100644 src/components/telemetry_monitor/src/application_manager_metric_wrapper.cc delete mode 100644 src/components/telemetry_monitor/src/protocol_handler_metric.cc create mode 100644 src/components/telemetry_monitor/src/protocol_handler_metric_wrapper.cc delete mode 100644 src/components/telemetry_monitor/src/transport_manager_metric.cc create mode 100644 src/components/telemetry_monitor/src/transport_manager_metric_wrapper.cc (limited to 'src/components/telemetry_monitor') diff --git a/src/components/telemetry_monitor/CMakeLists.txt b/src/components/telemetry_monitor/CMakeLists.txt index 8ce8d19f85..a70a6e18b7 100644 --- a/src/components/telemetry_monitor/CMakeLists.txt +++ b/src/components/telemetry_monitor/CMakeLists.txt @@ -55,9 +55,9 @@ set(SOURCES ${TELEMETRY_MONITOR_SRC_DIR}/application_manager_observer.cc ${TELEMETRY_MONITOR_SRC_DIR}/transport_manager_observer.cc ${TELEMETRY_MONITOR_SRC_DIR}/protocol_handler_observer.cc - ${TELEMETRY_MONITOR_SRC_DIR}/application_manager_metric.cc - ${TELEMETRY_MONITOR_SRC_DIR}/transport_manager_metric.cc - ${TELEMETRY_MONITOR_SRC_DIR}/protocol_handler_metric.cc + ${TELEMETRY_MONITOR_SRC_DIR}/application_manager_metric_wrapper.cc + ${TELEMETRY_MONITOR_SRC_DIR}/transport_manager_metric_wrapper.cc + ${TELEMETRY_MONITOR_SRC_DIR}/protocol_handler_metric_wrapper.cc ) add_library("TelemetryMonitor" ${SOURCES}) diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h deleted file mode 100644 index df568e7ebd..0000000000 --- a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ -#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ - -#include - -#include "telemetry_monitor/metric_wrapper.h" -#include "telemetry_monitor/application_manager_observer.h" - - -namespace telemetry_monitor { - -class ApplicationManagerObserver; - -class ApplicationManagerMetricWrapper: public MetricWrapper { - - public: - utils::SharedPtr message_metric; - virtual Json::Value GetJsonMetric(); -}; - -} -#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h new file mode 100644 index 0000000000..df568e7ebd --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h @@ -0,0 +1,54 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ + +#include + +#include "telemetry_monitor/metric_wrapper.h" +#include "telemetry_monitor/application_manager_observer.h" + + +namespace telemetry_monitor { + +class ApplicationManagerObserver; + +class ApplicationManagerMetricWrapper: public MetricWrapper { + + public: + utils::SharedPtr message_metric; + virtual Json::Value GetJsonMetric(); +}; + +} +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h index 995aad1085..4f509075b4 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h @@ -35,7 +35,7 @@ #include "utils/message_queue.h" #include "application_manager/telemetry_observer.h" -#include "telemetry_monitor/application_manager_metric.h" +#include "telemetry_monitor/application_manager_metric_wrapper.h" namespace telemetry_monitor { diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h index 66a0dc74f3..994065e0e3 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_H_ -#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_H_ +#ifndef SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_WRAPPER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_WRAPPER_H_ #include #include "utils/resource_usage.h" @@ -56,4 +56,4 @@ class MetricWrapper { } // namespace telemetry_monitor -#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_H_ +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.h b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.h deleted file mode 100644 index d3c27ba55b..0000000000 --- a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_H_ -#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_H_ - -#include -#include "utils/shared_ptr.h" -#include "telemetry_monitor/metric_wrapper.h" -#include "protocol_handler_observer.h" - -namespace telemetry_monitor { - -class ProtocolHandlerMecticWrapper: public MetricWrapper { - - public: - utils::SharedPtr message_metric; - virtual Json::Value GetJsonMetric(); -}; -} // namespace telemetry_monitor -#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.h new file mode 100644 index 0000000000..b3485e6942 --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_WRAPPER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_WRAPPER_H_ + +#include +#include "utils/shared_ptr.h" +#include "telemetry_monitor/metric_wrapper.h" +#include "protocol_handler_observer.h" + +namespace telemetry_monitor { + +class ProtocolHandlerMecticWrapper: public MetricWrapper { + + public: + utils::SharedPtr message_metric; + virtual Json::Value GetJsonMetric(); +}; +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h deleted file mode 100644 index 1e6cb501bc..0000000000 --- a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_H_ -#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_H_ - -#include -#include "telemetry_monitor/metric_wrapper.h" -#include "telemetry_monitor/transport_manager_observer.h" - -namespace telemetry_monitor { - -class TransportManagerMecticWrapper: public MetricWrapper { - public: - utils::SharedPtr message_metric; - virtual Json::Value GetJsonMetric(); -}; -} // namespace telemetry_monitor -#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h new file mode 100644 index 0000000000..8057402f11 --- /dev/null +++ b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h @@ -0,0 +1,48 @@ +/* + * 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_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_WRAPPER_H_ +#define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_H_ + +#include +#include "telemetry_monitor/metric_wrapper.h" +#include "telemetry_monitor/transport_manager_observer.h" + +namespace telemetry_monitor { + +class TransportManagerMecticWrapper: public MetricWrapper { + public: + utils::SharedPtr message_metric; + virtual Json::Value GetJsonMetric(); +}; +} // namespace telemetry_monitor +#endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_TRANSPORT_MANAGER_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/src/application_manager_metric.cc b/src/components/telemetry_monitor/src/application_manager_metric.cc deleted file mode 100644 index 0af9570c41..0000000000 --- a/src/components/telemetry_monitor/src/application_manager_metric.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 "telemetry_monitor/application_manager_metric.h" -#include "telemetry_monitor/json_keys.h" -#include "application_manager/smart_object_keys.h" -#include "utils/convert_utils.h" - -namespace telemetry_monitor { - -Json::Value ApplicationManagerMetricWrapper::GetJsonMetric() { - Json::Value result = MetricWrapper::GetJsonMetric(); - result[strings::logger] = "ApplicationManager"; - result[strings::begin] = - Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); - result[strings::end] = - Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); - const NsSmartDeviceLink::NsSmartObjects::SmartObject& params = - message_metric->message->getElement(application_manager::strings::params); - result[strings::correlation_id] = utils::ConvertInt64ToLongLongInt( - params[application_manager::strings::correlation_id].asInt()); - result[strings::connection_key] = utils::ConvertInt64ToLongLongInt( - params[application_manager::strings::connection_key].asInt()); - return result; -} -} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/application_manager_metric_wrapper.cc b/src/components/telemetry_monitor/src/application_manager_metric_wrapper.cc new file mode 100644 index 0000000000..b693d9df22 --- /dev/null +++ b/src/components/telemetry_monitor/src/application_manager_metric_wrapper.cc @@ -0,0 +1,55 @@ +/* + * 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 "telemetry_monitor/application_manager_metric_wrapper.h" +#include "telemetry_monitor/json_keys.h" +#include "application_manager/smart_object_keys.h" +#include "utils/convert_utils.h" + +namespace telemetry_monitor { + +Json::Value ApplicationManagerMetricWrapper::GetJsonMetric() { + Json::Value result = MetricWrapper::GetJsonMetric(); + result[strings::logger] = "ApplicationManager"; + result[strings::begin] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); + result[strings::end] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); + const NsSmartDeviceLink::NsSmartObjects::SmartObject& params = + message_metric->message->getElement(application_manager::strings::params); + result[strings::correlation_id] = utils::ConvertInt64ToLongLongInt( + params[application_manager::strings::correlation_id].asInt()); + result[strings::connection_key] = utils::ConvertInt64ToLongLongInt( + params[application_manager::strings::connection_key].asInt()); + return result; +} +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/application_manager_observer.cc b/src/components/telemetry_monitor/src/application_manager_observer.cc index 47570497cf..e3de439b96 100644 --- a/src/components/telemetry_monitor/src/application_manager_observer.cc +++ b/src/components/telemetry_monitor/src/application_manager_observer.cc @@ -32,7 +32,7 @@ #include "telemetry_monitor/application_manager_observer.h" #include "utils/shared_ptr.h" #include "telemetry_monitor/telemetry_monitor.h" -#include "telemetry_monitor/application_manager_metric.h" +#include "telemetry_monitor/application_manager_metric_wrapper.h" namespace telemetry_monitor { diff --git a/src/components/telemetry_monitor/src/protocol_handler_metric.cc b/src/components/telemetry_monitor/src/protocol_handler_metric.cc deleted file mode 100644 index 35beb3e1f7..0000000000 --- a/src/components/telemetry_monitor/src/protocol_handler_metric.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 "telemetry_monitor/protocol_handler_metric.h" -#include "json/json.h" -#include "telemetry_monitor/json_keys.h" - -namespace telemetry_monitor { - -Json::Value ProtocolHandlerMecticWrapper::GetJsonMetric() { - Json::Value result = MetricWrapper::GetJsonMetric(); - result[strings::logger] = "ProtocolHandler"; - result[strings::begin] = - Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); - result[strings::end] = - Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); - result[strings::message_id] = message_metric->message_id; - result[strings::connection_key] = message_metric->connection_key; - return result; -} - -} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/protocol_handler_metric_wrapper.cc b/src/components/telemetry_monitor/src/protocol_handler_metric_wrapper.cc new file mode 100644 index 0000000000..335f0dbb29 --- /dev/null +++ b/src/components/telemetry_monitor/src/protocol_handler_metric_wrapper.cc @@ -0,0 +1,51 @@ +/* + * 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 "telemetry_monitor/protocol_handler_metric_wrapper.h" +#include "json/json.h" +#include "telemetry_monitor/json_keys.h" + +namespace telemetry_monitor { + +Json::Value ProtocolHandlerMecticWrapper::GetJsonMetric() { + Json::Value result = MetricWrapper::GetJsonMetric(); + result[strings::logger] = "ProtocolHandler"; + result[strings::begin] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); + result[strings::end] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); + result[strings::message_id] = message_metric->message_id; + result[strings::connection_key] = message_metric->connection_key; + return result; +} + +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/protocol_handler_observer.cc b/src/components/telemetry_monitor/src/protocol_handler_observer.cc index c65e20121f..69f4564fc1 100644 --- a/src/components/telemetry_monitor/src/protocol_handler_observer.cc +++ b/src/components/telemetry_monitor/src/protocol_handler_observer.cc @@ -32,7 +32,7 @@ #include "utils/date_time.h" #include "telemetry_monitor/protocol_handler_observer.h" -#include "telemetry_monitor/protocol_handler_metric.h" +#include "telemetry_monitor/protocol_handler_metric_wrapper.h" #include "telemetry_monitor/telemetry_monitor.h" namespace telemetry_monitor { diff --git a/src/components/telemetry_monitor/src/transport_manager_metric.cc b/src/components/telemetry_monitor/src/transport_manager_metric.cc deleted file mode 100644 index 2e62a63797..0000000000 --- a/src/components/telemetry_monitor/src/transport_manager_metric.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 "telemetry_monitor/transport_manager_metric.h" -#include "json/json.h" -#include "telemetry_monitor/json_keys.h" -#include "application_manager/smart_object_keys.h" - -namespace telemetry_monitor { - -Json::Value TransportManagerMecticWrapper::GetJsonMetric() { - Json::Value result = MetricWrapper::GetJsonMetric(); - result[strings::logger] = "TransportManager"; - result[strings::begin] = - Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); - result[strings::end] = - Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); - result[strings::data_size] = static_cast(message_metric->data_size); - return result; -} - -} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/transport_manager_metric_wrapper.cc b/src/components/telemetry_monitor/src/transport_manager_metric_wrapper.cc new file mode 100644 index 0000000000..a891aa1118 --- /dev/null +++ b/src/components/telemetry_monitor/src/transport_manager_metric_wrapper.cc @@ -0,0 +1,51 @@ +/* + * 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 "telemetry_monitor/transport_manager_metric_wrapper.h" +#include "json/json.h" +#include "telemetry_monitor/json_keys.h" +#include "application_manager/smart_object_keys.h" + +namespace telemetry_monitor { + +Json::Value TransportManagerMecticWrapper::GetJsonMetric() { + Json::Value result = MetricWrapper::GetJsonMetric(); + result[strings::logger] = "TransportManager"; + result[strings::begin] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->begin)); + result[strings::end] = + Json::Int64(date_time::DateTime::getuSecs(message_metric->end)); + result[strings::data_size] = static_cast(message_metric->data_size); + return result; +} + +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/src/transport_manager_observer.cc b/src/components/telemetry_monitor/src/transport_manager_observer.cc index b74bc55b55..36f0e3c75a 100644 --- a/src/components/telemetry_monitor/src/transport_manager_observer.cc +++ b/src/components/telemetry_monitor/src/transport_manager_observer.cc @@ -33,7 +33,7 @@ #include -#include "telemetry_monitor/transport_manager_metric.h" +#include "telemetry_monitor/transport_manager_metric_wrapper.h" #include "telemetry_monitor/telemetry_monitor.h" namespace telemetry_monitor { diff --git a/src/components/telemetry_monitor/test/application_manager_metric_test.cc b/src/components/telemetry_monitor/test/application_manager_metric_test.cc index 0ec23ccda0..08cac32c65 100644 --- a/src/components/telemetry_monitor/test/application_manager_metric_test.cc +++ b/src/components/telemetry_monitor/test/application_manager_metric_test.cc @@ -34,7 +34,7 @@ #include "telemetry_monitor/json_keys.h" #include "utils/resource_usage.h" #include "application_manager/smart_object_keys.h" -#include "telemetry_monitor/application_manager_metric.h" +#include "telemetry_monitor/application_manager_metric_wrapper.h" namespace test { namespace components { diff --git a/src/components/telemetry_monitor/test/application_manager_observer_test.cc b/src/components/telemetry_monitor/test/application_manager_observer_test.cc index 9ca0850c15..4925544d09 100644 --- a/src/components/telemetry_monitor/test/application_manager_observer_test.cc +++ b/src/components/telemetry_monitor/test/application_manager_observer_test.cc @@ -33,7 +33,7 @@ #include "gtest/gtest.h" #include "telemetry_monitor/mock_telemetry_monitor.h" #include "application_manager/telemetry_observer.h" -#include "telemetry_monitor/application_manager_metric.h" +#include "telemetry_monitor/application_manager_metric_wrapper.h" #include "telemetry_monitor/application_manager_observer.h" #include "utils/shared_ptr.h" #include "telemetry_monitor/telemetry_monitor.h" diff --git a/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc b/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc index d74244a97f..b8114f5511 100644 --- a/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc +++ b/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc @@ -34,7 +34,7 @@ #include "telemetry_monitor/json_keys.h" #include "json/json.h" #include "utils/resource_usage.h" -#include "telemetry_monitor/protocol_handler_metric.h" +#include "telemetry_monitor/protocol_handler_metric_wrapper.h" #include "protocol_handler/telemetry_observer.h" namespace test { diff --git a/src/components/telemetry_monitor/test/transport_manager_metric_test.cc b/src/components/telemetry_monitor/test/transport_manager_metric_test.cc index 53d4ed1ba4..1219a9b1ab 100644 --- a/src/components/telemetry_monitor/test/transport_manager_metric_test.cc +++ b/src/components/telemetry_monitor/test/transport_manager_metric_test.cc @@ -34,7 +34,7 @@ #include "telemetry_monitor/json_keys.h" #include "json/json.h" #include "utils/resource_usage.h" -#include "telemetry_monitor/transport_manager_metric.h" +#include "telemetry_monitor/transport_manager_metric_wrapper.h" #include "protocol_handler/telemetry_observer.h" namespace test { diff --git a/src/components/telemetry_monitor/test/transport_manager_observer_test.cc b/src/components/telemetry_monitor/test/transport_manager_observer_test.cc index eba786ef70..71de55e47a 100644 --- a/src/components/telemetry_monitor/test/transport_manager_observer_test.cc +++ b/src/components/telemetry_monitor/test/transport_manager_observer_test.cc @@ -33,7 +33,7 @@ #include "gtest/gtest.h" #include "telemetry_monitor/mock_telemetry_monitor.h" #include "protocol_handler/telemetry_observer.h" -#include "telemetry_monitor/transport_manager_metric.h" +#include "telemetry_monitor/transport_manager_metric_wrapper.h" #include "telemetry_monitor/transport_manager_observer.h" namespace test { -- cgit v1.2.1 From 035d727bf11c3e6986a36843e11bd5b8919b3b30 Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Thu, 24 Mar 2016 08:44:23 +0200 Subject: TelemetryMonitor tests correctives --- src/components/telemetry_monitor/CMakeLists.txt | 1 + src/components/telemetry_monitor/test/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+) (limited to 'src/components/telemetry_monitor') diff --git a/src/components/telemetry_monitor/CMakeLists.txt b/src/components/telemetry_monitor/CMakeLists.txt index a70a6e18b7..815720e15c 100644 --- a/src/components/telemetry_monitor/CMakeLists.txt +++ b/src/components/telemetry_monitor/CMakeLists.txt @@ -39,6 +39,7 @@ include_directories ( ${COMPONENTS_DIR}/transport_manager/include/ ${COMPONENTS_DIR}/application_manager/include/ ${COMPONENTS_DIR}/policy/src/policy/include/ + ${COMPONENTS_DIR}/policy/src/policy/usage_statistics/include ${COMPONENTS_DIR}/hmi_message_handler/include/ ${COMPONENTS_DIR}/formatters/include/ ${COMPONENTS_DIR}/media_manager/include/ diff --git a/src/components/telemetry_monitor/test/CMakeLists.txt b/src/components/telemetry_monitor/test/CMakeLists.txt index f574621828..7d2de19854 100644 --- a/src/components/telemetry_monitor/test/CMakeLists.txt +++ b/src/components/telemetry_monitor/test/CMakeLists.txt @@ -37,6 +37,8 @@ include_directories( ${COMPONENTS_DIR}/utils/include ${COMPONENTS_DIR}/protocol_handler/include ${COMPONENTS_DIR}/application_manager/include + ${COMPONENTS_DIR}/resumption/include + ${JSONCPP_INCLUDE_DIRECTORY} ) -- cgit v1.2.1 From 5e4585b5353967f9c20d38387dfcb225821fc8ba Mon Sep 17 00:00:00 2001 From: iAndrew5 Date: Mon, 4 Apr 2016 17:21:43 +0300 Subject: Change other unit-tests according new code changes 1) Changed header files in tests 2) Renamed transport_manager_mock to mok=ck)transport_manager 3) Renamed other mock classes to match naming rules 4) Deleted redundant headers and namespaces. 5) Changed year in Ford headers 6) Changed raw "new" operator using to MakeShared for creating shared_ptr 7) Corrected header guards 8) Added new method CheckRegularMatches to control_message_matcher Relates: APPLINK-22767 --- src/components/telemetry_monitor/test/telemetry_monitor_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components/telemetry_monitor') diff --git a/src/components/telemetry_monitor/test/telemetry_monitor_test.cc b/src/components/telemetry_monitor/test/telemetry_monitor_test.cc index 14c7fe4cd5..8c95f75f0c 100644 --- a/src/components/telemetry_monitor/test/telemetry_monitor_test.cc +++ b/src/components/telemetry_monitor/test/telemetry_monitor_test.cc @@ -38,7 +38,7 @@ #include "protocol_handler/mock_session_observer.h" #include "protocol_handler/mock_protocol_handler_settings.h" #include "connection_handler/mock_connection_handler.h" -#include "transport_manager/transport_manager_mock.h" +#include "transport_manager/mock_transport_manager.h" #include "telemetry_monitor/mock_telemetry_observable.h" -- cgit v1.2.1 From 4ecdb2a83871784f34430ed09d5ef6a2c0855506 Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Tue, 26 Apr 2016 12:41:54 +0300 Subject: Format all code in project Formated all code in appMain, components, plugins to correct coding-style Used clang-format-3.6 Used 2 commands : find src/appMain/ -name "*.h" -o -name "*.cc" -o -name "*.hpp" -o -name "*.cpp" | xargs clang-format-3.6 -i -style=file find src/components/ -name "*.h" -o -name "*.cc" -o -name "*.hpp" -o -name "*.cpp" | xargs clang-format-3.6 -i -style=file find src/plugins/ -name "*.h" -o -name "*.cc" -o -name "*.hpp" -o -name "*.cpp" | xargs clang-format-3.6 -i -style=file --- .../application_manager_metric_wrapper.h | 12 ++-- .../application_manager_observer.h | 15 +++-- .../include/telemetry_monitor/json_keys.h | 26 ++++----- .../include/telemetry_monitor/metric_wrapper.h | 25 ++++---- .../protocol_handler_metric_wrapper.h | 10 ++-- .../telemetry_monitor/protocol_handler_observer.h | 5 +- .../include/telemetry_monitor/telemetry_monitor.h | 13 +++-- .../transport_manager_metric_wrapper.h | 5 +- .../telemetry_monitor/transport_manager_observer.h | 3 +- .../src/application_manager_observer.cc | 9 +-- .../telemetry_monitor/src/metric_wrapper.cc | 5 +- .../src/protocol_handler_observer.cc | 21 ++++--- .../telemetry_monitor/src/telemetry_monitor.cc | 61 ++++++++++---------- .../src/transport_manager_observer.cc | 38 +++++++------ .../test/application_manager_metric_test.cc | 66 ++++++++++++++-------- .../test/application_manager_observer_test.cc | 3 +- .../telemetry_monitor/mock_telemetry_monitor.h | 4 +- .../telemetry_monitor/test/metric_wrapper_test.cc | 4 +- .../test/protocol_handler_metric_test.cc | 22 +++++--- .../test/telemetry_monitor_test.cc | 30 +++++----- .../test/transport_manager_metric_test.cc | 22 +++++--- .../test/transport_manager_observer_test.cc | 3 +- 22 files changed, 222 insertions(+), 180 deletions(-) (limited to 'src/components/telemetry_monitor') diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h index df568e7ebd..d35de52e3b 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_metric_wrapper.h @@ -38,17 +38,15 @@ #include "telemetry_monitor/metric_wrapper.h" #include "telemetry_monitor/application_manager_observer.h" - namespace telemetry_monitor { class ApplicationManagerObserver; -class ApplicationManagerMetricWrapper: public MetricWrapper { - - public: - utils::SharedPtr message_metric; - virtual Json::Value GetJsonMetric(); +class ApplicationManagerMetricWrapper : public MetricWrapper { + public: + utils::SharedPtr + message_metric; + virtual Json::Value GetJsonMetric(); }; - } #endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h index 4f509075b4..ecb9c8002a 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/application_manager_observer.h @@ -37,19 +37,18 @@ #include "application_manager/telemetry_observer.h" #include "telemetry_monitor/application_manager_metric_wrapper.h" - namespace telemetry_monitor { class TelemetryMonitor; -class ApplicationManagerObserver: public application_manager::AMTelemetryObserver { - public: - explicit ApplicationManagerObserver(TelemetryMonitor* telemetry_monitor); - virtual void OnMessage(utils::SharedPtr metric); +class ApplicationManagerObserver + : public application_manager::AMTelemetryObserver { + public: + explicit ApplicationManagerObserver(TelemetryMonitor* telemetry_monitor); + virtual void OnMessage(utils::SharedPtr metric); - private: - TelemetryMonitor* telemetry_monitor_; + private: + TelemetryMonitor* telemetry_monitor_; }; - } #endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_APPLICATION_MANAGER_OBSERVER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/json_keys.h b/src/components/telemetry_monitor/include/telemetry_monitor/json_keys.h index f5aba07721..899c76b2e8 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/json_keys.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/json_keys.h @@ -35,18 +35,18 @@ #define SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_JSON_KEYS_H_ namespace telemetry_monitor { - namespace strings { - const char logger[] = "logger"; - const char begin[] = "begin"; - const char end[] = "end"; - const char data_size[] = "data_size"; - const char message_id[] = "message_id"; - const char session_id[] = "session_id"; - const char correlation_id[] = "correlation_id"; - const char connection_key[] = "connection_key"; - const char stime[] = "stime"; - const char utime[] = "utime"; - const char memory[] = "RAM"; - } +namespace strings { +const char logger[] = "logger"; +const char begin[] = "begin"; +const char end[] = "end"; +const char data_size[] = "data_size"; +const char message_id[] = "message_id"; +const char session_id[] = "session_id"; +const char correlation_id[] = "correlation_id"; +const char connection_key[] = "connection_key"; +const char stime[] = "stime"; +const char utime[] = "utime"; +const char memory[] = "RAM"; +} } #endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_JSON_KEYS_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h index 994065e0e3..b4d7ed12cb 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/metric_wrapper.h @@ -41,19 +41,20 @@ namespace telemetry_monitor { class MetricWrapper { utils::ResourseUsage* resources; - public: - MetricWrapper(); - /* - * @brief get current cpu and memory info and store it as member - */ - bool grabResources(); - virtual std::string GetStyledString(); - virtual Json::Value GetJsonMetric(); - virtual ~MetricWrapper(); - protected: - void Clear(); -}; + public: + MetricWrapper(); + /* + * @brief get current cpu and memory info and store it as member + */ + bool grabResources(); + virtual std::string GetStyledString(); + virtual Json::Value GetJsonMetric(); + virtual ~MetricWrapper(); + + protected: + void Clear(); +}; } // namespace telemetry_monitor #endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.h index b3485e6942..bc4e4c8e53 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_metric_wrapper.h @@ -40,11 +40,11 @@ namespace telemetry_monitor { -class ProtocolHandlerMecticWrapper: public MetricWrapper { - - public: - utils::SharedPtr message_metric; - virtual Json::Value GetJsonMetric(); +class ProtocolHandlerMecticWrapper : public MetricWrapper { + public: + utils::SharedPtr + message_metric; + virtual Json::Value GetJsonMetric(); }; } // namespace telemetry_monitor #endif // SRC_COMPONENTS_TELEMETRY_MONITOR_INCLUDE_TELEMETRY_MONITOR_PROTOCOL_HANDLER_MECTRIC_WRAPPER_H_ diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h index c9f6a7f07f..69e5658382 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/protocol_handler_observer.h @@ -40,11 +40,12 @@ namespace telemetry_monitor { class TelemetryMonitor; -class ProtocolHandlerObserver: public protocol_handler::PHTelemetryObserver { +class ProtocolHandlerObserver : public protocol_handler::PHTelemetryObserver { public: explicit ProtocolHandlerObserver(TelemetryMonitor* telemetry_monitor); - virtual void StartMessageProcess(uint32_t message_id, const TimevalStruct& start_time); + virtual void StartMessageProcess(uint32_t message_id, + const TimevalStruct& start_time); virtual void EndMessageProcess(utils::SharedPtr m); diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h b/src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h index 316f687b46..49895de8d3 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/telemetry_monitor.h @@ -60,11 +60,12 @@ class Streamer : public threads::ThreadDelegate { virtual void PushMessage(utils::SharedPtr metric); volatile bool is_client_connected_; + private: void Start(); void Stop(); bool IsReady() const; - bool Send(const std::string &msg); + bool Send(const std::string& msg); void ShutDownAndCloseSocket(int32_t socket_fd); TelemetryMonitor* const kserver_; int32_t server_socket_fd_; @@ -78,10 +79,12 @@ class TelemetryMonitor { public: TelemetryMonitor(const std::string& server_address, uint16_t port); virtual ~TelemetryMonitor(); - virtual void Init( - TelemetryObservable* protocol_handler, - TelemetryObservable* app_manager, - TelemetryObservable* transport_manager); + virtual void Init(TelemetryObservable* + protocol_handler, + TelemetryObservable< + application_manager::AMTelemetryObserver>* app_manager, + TelemetryObservable* + transport_manager); virtual void Stop(); virtual void Start(); virtual void SendMetric(utils::SharedPtr metric); diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h index 8057402f11..9cb158fa98 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_metric_wrapper.h @@ -39,9 +39,10 @@ namespace telemetry_monitor { -class TransportManagerMecticWrapper: public MetricWrapper { +class TransportManagerMecticWrapper : public MetricWrapper { public: - utils::SharedPtr message_metric; + utils::SharedPtr + message_metric; virtual Json::Value GetJsonMetric(); }; } // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h index 9390ecd209..bff5834586 100644 --- a/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h +++ b/src/components/telemetry_monitor/include/telemetry_monitor/transport_manager_observer.h @@ -41,11 +41,12 @@ namespace telemetry_monitor { class TelemetryMonitor; -class TransportManagerObserver: public transport_manager::TMTelemetryObserver { +class TransportManagerObserver : public transport_manager::TMTelemetryObserver { public: explicit TransportManagerObserver(TelemetryMonitor* telemetry_monitor); virtual void StartRawMsg(const protocol_handler::RawMessage* ptr); virtual void StopRawMsg(const protocol_handler::RawMessage* ptr); + private: TelemetryMonitor* telemetry_monitor_; std::map time_starts; diff --git a/src/components/telemetry_monitor/src/application_manager_observer.cc b/src/components/telemetry_monitor/src/application_manager_observer.cc index e3de439b96..cb390eddeb 100644 --- a/src/components/telemetry_monitor/src/application_manager_observer.cc +++ b/src/components/telemetry_monitor/src/application_manager_observer.cc @@ -36,11 +36,12 @@ namespace telemetry_monitor { -ApplicationManagerObserver::ApplicationManagerObserver(TelemetryMonitor* telemetry_monitor): - telemetry_monitor_(telemetry_monitor) { -} +ApplicationManagerObserver::ApplicationManagerObserver( + TelemetryMonitor* telemetry_monitor) + : telemetry_monitor_(telemetry_monitor) {} -void ApplicationManagerObserver::OnMessage(utils::SharedPtr metric) { +void ApplicationManagerObserver::OnMessage( + utils::SharedPtr metric) { ApplicationManagerMetricWrapper* m = new ApplicationManagerMetricWrapper(); m->message_metric = metric; m->grabResources(); diff --git a/src/components/telemetry_monitor/src/metric_wrapper.cc b/src/components/telemetry_monitor/src/metric_wrapper.cc index 2803921501..937a705ef7 100644 --- a/src/components/telemetry_monitor/src/metric_wrapper.cc +++ b/src/components/telemetry_monitor/src/metric_wrapper.cc @@ -35,9 +35,7 @@ namespace telemetry_monitor { - MetricWrapper::MetricWrapper(): - resources(NULL) { - } +MetricWrapper::MetricWrapper() : resources(NULL) {} bool MetricWrapper::grabResources() { Clear(); @@ -74,5 +72,4 @@ void MetricWrapper::Clear() { MetricWrapper::~MetricWrapper() { Clear(); } - } diff --git a/src/components/telemetry_monitor/src/protocol_handler_observer.cc b/src/components/telemetry_monitor/src/protocol_handler_observer.cc index 69f4564fc1..2244cb2259 100644 --- a/src/components/telemetry_monitor/src/protocol_handler_observer.cc +++ b/src/components/telemetry_monitor/src/protocol_handler_observer.cc @@ -39,26 +39,29 @@ namespace telemetry_monitor { CREATE_LOGGERPTR_GLOBAL(logger_, "TelemetryMonitor") -ProtocolHandlerObserver::ProtocolHandlerObserver(TelemetryMonitor *telemetry_monitor): - telemetry_monitor_(telemetry_monitor) { -} +ProtocolHandlerObserver::ProtocolHandlerObserver( + TelemetryMonitor* telemetry_monitor) + : telemetry_monitor_(telemetry_monitor) {} -void ProtocolHandlerObserver::StartMessageProcess(uint32_t message_id, - const TimevalStruct &start_time) { +void ProtocolHandlerObserver::StartMessageProcess( + uint32_t message_id, const TimevalStruct& start_time) { if (message_id == 0) { return; } if (time_starts.find(message_id) != time_starts.end()) { - LOG4CXX_DEBUG(logger_, "Already waiting for stop processing for Message ID: " - << message_id); + LOG4CXX_DEBUG( + logger_, + "Already waiting for stop processing for Message ID: " << message_id); return; } time_starts[message_id] = start_time; } -void ProtocolHandlerObserver::EndMessageProcess(utils::SharedPtr m) { +void ProtocolHandlerObserver::EndMessageProcess( + utils::SharedPtr m) { uint32_t message_id = m->message_id; - std::map::const_iterator it = time_starts.find(message_id); + std::map::const_iterator it = + time_starts.find(message_id); if (it == time_starts.end()) { LOG4CXX_WARN(logger_, "Cant find start time for message" << message_id); return; diff --git a/src/components/telemetry_monitor/src/telemetry_monitor.cc b/src/components/telemetry_monitor/src/telemetry_monitor.cc index 7a697cb309..759b843961 100644 --- a/src/components/telemetry_monitor/src/telemetry_monitor.cc +++ b/src/components/telemetry_monitor/src/telemetry_monitor.cc @@ -49,20 +49,18 @@ namespace telemetry_monitor { CREATE_LOGGERPTR_GLOBAL(logger_, "TelemetryMonitor") TelemetryMonitor::TelemetryMonitor(const std::string& server_address, - uint16_t port): - server_address_(server_address), - port_(port), - thread_(NULL), - streamer_(NULL), - app_observer(this), - tm_observer(this), - ph_observer(this) { - -} + uint16_t port) + : server_address_(server_address) + , port_(port) + , thread_(NULL) + , streamer_(NULL) + , app_observer(this) + , tm_observer(this) + , ph_observer(this) {} void TelemetryMonitor::Start() { streamer_ = new Streamer(this); - thread_ = threads::CreateThread("TelemetryMonitor", streamer_ ); + thread_ = threads::CreateThread("TelemetryMonitor", streamer_); } void TelemetryMonitor::set_streamer(Streamer* streamer) { @@ -78,7 +76,7 @@ void TelemetryMonitor::set_streamer(Streamer* streamer) { } } -const std::string& TelemetryMonitor::ip() const { +const std::string& TelemetryMonitor::ip() const { return server_address_; } @@ -93,8 +91,7 @@ TelemetryMonitor::~TelemetryMonitor() { void TelemetryMonitor::Init( TelemetryObservable* protocol_handler, - TelemetryObservable* - app_manager, + TelemetryObservable* app_manager, TelemetryObservable* transport_manager) { LOG4CXX_AUTO_TRACE(logger_); @@ -119,18 +116,17 @@ void TelemetryMonitor::Stop() { } void TelemetryMonitor::SendMetric(utils::SharedPtr metric) { - if ((NULL != streamer_ )&& streamer_->is_client_connected_) { + if ((NULL != streamer_) && streamer_->is_client_connected_) { streamer_->PushMessage(metric); } } Streamer::Streamer(TelemetryMonitor* const server) - : is_client_connected_(false), - kserver_(server), - server_socket_fd_(0), - client_socket_fd_(0), - stop_flag_(false) { -} + : is_client_connected_(false) + , kserver_(server) + , server_socket_fd_(0) + , client_socket_fd_(0) + , stop_flag_(false) {} Streamer::~Streamer() { Stop(); @@ -188,13 +184,16 @@ void Streamer::Start() { } int32_t optval = 1; - if (-1 == setsockopt(server_socket_fd_, SOL_SOCKET, SO_REUSEADDR, - &optval, sizeof optval)) { + if (-1 == setsockopt(server_socket_fd_, + SOL_SOCKET, + SO_REUSEADDR, + &optval, + sizeof optval)) { LOG4CXX_ERROR(logger_, "Unable to set sockopt"); return; } - sockaddr_in serv_addr_ = { 0 }; + sockaddr_in serv_addr_ = {0}; serv_addr_.sin_addr.s_addr = inet_addr(kserver_->ip().c_str()); serv_addr_.sin_family = AF_INET; serv_addr_.sin_port = htons(kserver_->port()); @@ -202,19 +201,20 @@ void Streamer::Start() { if (-1 == bind(server_socket_fd_, reinterpret_cast(&serv_addr_), sizeof(serv_addr_))) { - LOG4CXX_ERROR(logger_, "Unable to bind server " - << kserver_->ip().c_str() << ':' << kserver_->port()); + LOG4CXX_ERROR(logger_, + "Unable to bind server " << kserver_->ip().c_str() << ':' + << kserver_->port()); return; } if (-1 == listen(server_socket_fd_, 1)) { - LOG4CXX_ERROR(logger_, "Streamer listen error " << strerror(errno) ); + LOG4CXX_ERROR(logger_, "Streamer listen error " << strerror(errno)); return; } } void Streamer::ShutDownAndCloseSocket(int32_t socket_fd) { LOG4CXX_AUTO_TRACE(logger_); - if (0 < socket_fd){ + if (0 < socket_fd) { LOG4CXX_INFO(logger_, "Shutdown socket"); if (-1 == ::shutdown(socket_fd, SHUT_RDWR)) { LOG4CXX_ERROR(logger_, "Unable to shutdown socket"); @@ -251,7 +251,7 @@ bool Streamer::IsReady() const { FD_ZERO(&fds); FD_SET(client_socket_fd_, &fds); TimevalStruct tv = {0, 0}; - tv.tv_sec = 5; // set a 5 second timeout + tv.tv_sec = 5; // set a 5 second timeout tv.tv_usec = 0; const int retval = select(client_socket_fd_ + 1, 0, &fds, 0, &tv); @@ -274,8 +274,7 @@ bool Streamer::Send(const std::string& msg) { return false; } - if (-1 == ::send(client_socket_fd_, msg.c_str(), - msg.size(), MSG_NOSIGNAL)) { + if (-1 == ::send(client_socket_fd_, msg.c_str(), msg.size(), MSG_NOSIGNAL)) { LOG4CXX_ERROR(logger_, " Unable to send"); return false; } diff --git a/src/components/telemetry_monitor/src/transport_manager_observer.cc b/src/components/telemetry_monitor/src/transport_manager_observer.cc index 36f0e3c75a..b3e57ac22a 100644 --- a/src/components/telemetry_monitor/src/transport_manager_observer.cc +++ b/src/components/telemetry_monitor/src/transport_manager_observer.cc @@ -38,26 +38,30 @@ namespace telemetry_monitor { -TransportManagerObserver::TransportManagerObserver(TelemetryMonitor* telemetry_monitor): - telemetry_monitor_ (telemetry_monitor) { -} +TransportManagerObserver::TransportManagerObserver( + TelemetryMonitor* telemetry_monitor) + : telemetry_monitor_(telemetry_monitor) {} -void TransportManagerObserver::StartRawMsg(const protocol_handler::RawMessage* ptr) { +void TransportManagerObserver::StartRawMsg( + const protocol_handler::RawMessage* ptr) { time_starts[ptr] = date_time::DateTime::getCurrentTime(); } -void TransportManagerObserver::StopRawMsg(const protocol_handler::RawMessage* ptr) { - std::map::const_iterator it; - it = time_starts.find(ptr); - if (it != time_starts.end()) { - TransportManagerMecticWrapper* m = new TransportManagerMecticWrapper(); - m->message_metric = new transport_manager::TMTelemetryObserver::MessageMetric(); - m->message_metric->begin = it->second; - m->message_metric->end = date_time::DateTime::getCurrentTime(); - m->message_metric->data_size = ptr->data_size(); - m->grabResources(); - telemetry_monitor_->SendMetric(m); - } +void TransportManagerObserver::StopRawMsg( + const protocol_handler::RawMessage* ptr) { + std::map::const_iterator + it; + it = time_starts.find(ptr); + if (it != time_starts.end()) { + TransportManagerMecticWrapper* m = new TransportManagerMecticWrapper(); + m->message_metric = + new transport_manager::TMTelemetryObserver::MessageMetric(); + m->message_metric->begin = it->second; + m->message_metric->end = date_time::DateTime::getCurrentTime(); + m->message_metric->data_size = ptr->data_size(); + m->grabResources(); + telemetry_monitor_->SendMetric(m); + } } -} //namespace telemetry_monitor +} // namespace telemetry_monitor diff --git a/src/components/telemetry_monitor/test/application_manager_metric_test.cc b/src/components/telemetry_monitor/test/application_manager_metric_test.cc index 08cac32c65..5d97ac3528 100644 --- a/src/components/telemetry_monitor/test/application_manager_metric_test.cc +++ b/src/components/telemetry_monitor/test/application_manager_metric_test.cc @@ -57,23 +57,32 @@ TEST(ApplicationManagerMetricWrapper, GetJsonMetric) { TimevalStruct end_time; end_time.tv_sec = 10; end_time.tv_usec = 0; - metric_test.message_metric = new application_manager::AMTelemetryObserver::MessageMetric(); + metric_test.message_metric = + new application_manager::AMTelemetryObserver::MessageMetric(); metric_test.message_metric->begin = start_time; metric_test.message_metric->end = end_time; NsSmartDeviceLink::NsSmartObjects::SmartObject obj; obj["params"][application_manager::strings::correlation_id] = 11; obj["params"][application_manager::strings::connection_key] = 12; - metric_test.message_metric->message = new NsSmartDeviceLink::NsSmartObjects::SmartObject(obj); + metric_test.message_metric->message = + new NsSmartDeviceLink::NsSmartObjects::SmartObject(obj); Json::Value jvalue = metric_test.GetJsonMetric(); - EXPECT_EQ("null\n", jvalue[telemetry_monitor::strings::stime].toStyledString()); - EXPECT_EQ("null\n", jvalue[telemetry_monitor::strings::utime].toStyledString()); - EXPECT_EQ("null\n", jvalue[telemetry_monitor::strings::memory].toStyledString()); - - EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[telemetry_monitor::strings::begin].asInt64()); - EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[telemetry_monitor::strings::end].asInt64()); - EXPECT_EQ(obj["params"][application_manager::strings::correlation_id].asInt(), jvalue[telemetry_monitor::strings::correlation_id].asInt64()); - EXPECT_EQ(obj["params"][application_manager::strings::connection_key].asInt(), jvalue[telemetry_monitor::strings::connection_key].asInt()); + EXPECT_EQ("null\n", + jvalue[telemetry_monitor::strings::stime].toStyledString()); + EXPECT_EQ("null\n", + jvalue[telemetry_monitor::strings::utime].toStyledString()); + EXPECT_EQ("null\n", + jvalue[telemetry_monitor::strings::memory].toStyledString()); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), + jvalue[telemetry_monitor::strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), + jvalue[telemetry_monitor::strings::end].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::correlation_id].asInt(), + jvalue[telemetry_monitor::strings::correlation_id].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::connection_key].asInt(), + jvalue[telemetry_monitor::strings::connection_key].asInt()); } TEST(ApplicationManagerMetricWrapper, GetJsonMetricWithGrabResources) { @@ -89,26 +98,37 @@ TEST(ApplicationManagerMetricWrapper, GetJsonMetricWithGrabResources) { end_time.tv_sec = 10; end_time.tv_usec = 0; - metric_test.message_metric = new application_manager::AMTelemetryObserver::MessageMetric(); + metric_test.message_metric = + new application_manager::AMTelemetryObserver::MessageMetric(); metric_test.message_metric->begin = start_time; metric_test.message_metric->end = end_time; NsSmartDeviceLink::NsSmartObjects::SmartObject obj; obj["params"][application_manager::strings::correlation_id] = 11; obj["params"][application_manager::strings::connection_key] = 12; - metric_test.message_metric->message = new NsSmartDeviceLink::NsSmartObjects::SmartObject(obj); + metric_test.message_metric->message = + new NsSmartDeviceLink::NsSmartObjects::SmartObject(obj); Json::Value jvalue = metric_test.GetJsonMetric(); - EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[telemetry_monitor::strings::begin].asInt64()); - EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[telemetry_monitor::strings::end].asInt64()); - EXPECT_EQ(obj["params"][application_manager::strings::correlation_id].asInt(), jvalue[telemetry_monitor::strings::correlation_id].asInt64()); - EXPECT_EQ(obj["params"][application_manager::strings::connection_key].asInt(), jvalue[telemetry_monitor::strings::connection_key].asInt()); - - EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[telemetry_monitor::strings::begin].asInt64()); - EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[telemetry_monitor::strings::end].asInt64()); - - EXPECT_NEAR(resources->stime, jvalue[telemetry_monitor::strings::stime].asInt(),1); - EXPECT_NEAR(resources->utime, jvalue[telemetry_monitor::strings::utime].asInt(),1); - EXPECT_EQ(resources->memory, jvalue[telemetry_monitor::strings::memory].asInt()); + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), + jvalue[telemetry_monitor::strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), + jvalue[telemetry_monitor::strings::end].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::correlation_id].asInt(), + jvalue[telemetry_monitor::strings::correlation_id].asInt64()); + EXPECT_EQ(obj["params"][application_manager::strings::connection_key].asInt(), + jvalue[telemetry_monitor::strings::connection_key].asInt()); + + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), + jvalue[telemetry_monitor::strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), + jvalue[telemetry_monitor::strings::end].asInt64()); + + EXPECT_NEAR( + resources->stime, jvalue[telemetry_monitor::strings::stime].asInt(), 1); + EXPECT_NEAR( + resources->utime, jvalue[telemetry_monitor::strings::utime].asInt(), 1); + EXPECT_EQ(resources->memory, + jvalue[telemetry_monitor::strings::memory].asInt()); delete resources; } diff --git a/src/components/telemetry_monitor/test/application_manager_observer_test.cc b/src/components/telemetry_monitor/test/application_manager_observer_test.cc index 4925544d09..09ef04a2d8 100644 --- a/src/components/telemetry_monitor/test/application_manager_observer_test.cc +++ b/src/components/telemetry_monitor/test/application_manager_observer_test.cc @@ -49,7 +49,8 @@ TEST(ApplicationManagerObserver, CallOnMessage) { MockTelemetryMonitor mock_telemetry_monitor; ApplicationManagerObserver app_observer(&mock_telemetry_monitor); typedef application_manager::AMTelemetryObserver::MessageMetric AMMetric; - utils::SharedPtr ptr = application_manager::AMTelemetryObserver::MessageMetricSharedPtr(); + utils::SharedPtr ptr = + application_manager::AMTelemetryObserver::MessageMetricSharedPtr(); EXPECT_CALL(mock_telemetry_monitor, SendMetric(_)); app_observer.OnMessage(ptr); } diff --git a/src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h b/src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h index 2d849a634c..0ef5a530fd 100644 --- a/src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h +++ b/src/components/telemetry_monitor/test/include/telemetry_monitor/mock_telemetry_monitor.h @@ -43,9 +43,9 @@ namespace test { namespace components { namespace telemetry_monitor_test { -class MockTelemetryMonitor: public telemetry_monitor::TelemetryMonitor { +class MockTelemetryMonitor : public telemetry_monitor::TelemetryMonitor { public: - MockTelemetryMonitor():telemetry_monitor::TelemetryMonitor("",0u){} + MockTelemetryMonitor() : telemetry_monitor::TelemetryMonitor("", 0u) {} MOCK_METHOD1(Init, void(protocol_handler::ProtocolHandlerImpl* ph)); MOCK_METHOD0(Stop, void()); MOCK_METHOD0(Start, void()); diff --git a/src/components/telemetry_monitor/test/metric_wrapper_test.cc b/src/components/telemetry_monitor/test/metric_wrapper_test.cc index 08b9747742..91361f3df2 100644 --- a/src/components/telemetry_monitor/test/metric_wrapper_test.cc +++ b/src/components/telemetry_monitor/test/metric_wrapper_test.cc @@ -70,8 +70,8 @@ TEST(MetricWrapper, GetJsonMetricWithGrabResources) { EXPECT_NE("null/n", jvalue[strings::utime].toStyledString()); EXPECT_NE("null/n", jvalue[strings::memory].toStyledString()); - EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(),1); - EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(),1); + EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(), 1); + EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(), 1); EXPECT_EQ(resources->memory, jvalue[strings::memory].asInt()); delete resources; diff --git a/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc b/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc index b8114f5511..e41aeb6edd 100644 --- a/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc +++ b/src/components/telemetry_monitor/test/protocol_handler_metric_test.cc @@ -58,7 +58,8 @@ TEST(ProtocolHandlerMetricTest, GetJsonMetric) { TimevalStruct end_time; end_time.tv_sec = 10; end_time.tv_usec = 0; - metric_test.message_metric = new protocol_handler::PHTelemetryObserver::MessageMetric(); + metric_test.message_metric = + new protocol_handler::PHTelemetryObserver::MessageMetric(); metric_test.message_metric->begin = start_time; metric_test.message_metric->end = end_time; metric_test.message_metric->message_id = 5; @@ -70,8 +71,10 @@ TEST(ProtocolHandlerMetricTest, GetJsonMetric) { EXPECT_EQ("null\n", jvalue[strings::utime].toStyledString()); EXPECT_EQ("null\n", jvalue[strings::memory].toStyledString()); - EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); - EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), + jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), + jvalue[strings::end].asInt64()); EXPECT_EQ(5, jvalue[strings::message_id].asInt64()); EXPECT_EQ(2, jvalue[strings::connection_key].asInt()); } @@ -89,7 +92,8 @@ TEST(ProtocolHandlerMetricTest, GetJsonMetricWithGrabResources) { TimevalStruct end_time; end_time.tv_sec = 10; end_time.tv_usec = 0; - metric_test.message_metric = new protocol_handler::PHTelemetryObserver::MessageMetric(); + metric_test.message_metric = + new protocol_handler::PHTelemetryObserver::MessageMetric(); metric_test.message_metric->begin = start_time; metric_test.message_metric->end = end_time; metric_test.message_metric->message_id = 5; @@ -103,13 +107,15 @@ TEST(ProtocolHandlerMetricTest, GetJsonMetricWithGrabResources) { EXPECT_NE("null/n", jvalue[strings::utime].toStyledString()); EXPECT_NE("null/n", jvalue[strings::memory].toStyledString()); - EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); - EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), + jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), + jvalue[strings::end].asInt64()); EXPECT_EQ(5, jvalue[strings::message_id].asInt64()); EXPECT_EQ(2, jvalue[strings::connection_key].asInt()); - EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(),1); - EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(),1); + EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(), 1); + EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(), 1); EXPECT_EQ(resources->memory, jvalue[strings::memory].asInt()); delete resources; } diff --git a/src/components/telemetry_monitor/test/telemetry_monitor_test.cc b/src/components/telemetry_monitor/test/telemetry_monitor_test.cc index 8c95f75f0c..8c48a51304 100644 --- a/src/components/telemetry_monitor/test/telemetry_monitor_test.cc +++ b/src/components/telemetry_monitor/test/telemetry_monitor_test.cc @@ -41,7 +41,6 @@ #include "transport_manager/mock_transport_manager.h" #include "telemetry_monitor/mock_telemetry_observable.h" - using testing::Return; using testing::_; @@ -53,11 +52,10 @@ using namespace telemetry_monitor; class StreamerMock : public Streamer { public: - StreamerMock(TelemetryMonitor* const server) - : Streamer(server) { + StreamerMock(TelemetryMonitor* const server) : Streamer(server) { is_client_connected_ = true; } - MOCK_METHOD1(PushMessage,void(utils::SharedPtr metric)); + MOCK_METHOD1(PushMessage, void(utils::SharedPtr metric)); }; TEST(TelemetryMonitorTest, MessageProcess) { @@ -65,14 +63,14 @@ TEST(TelemetryMonitorTest, MessageProcess) { const uint16_t port = 12345; MockTelemetryObservable am_observeble; - transport_manager_test::MockTransportManager transport_manager_mock; - testing::NiceMock - connection_handler_mock; + transport_manager_test::MockTransportManager transport_manager_mock; + testing::NiceMock + connection_handler_mock; testing::NiceMock< ::test::components::protocol_handler_test::MockProtocolHandlerSettings> - protocol_handler_settings_mock; - ::test::components::protocol_handler_test::MockSessionObserver - session_observer_mock; + protocol_handler_settings_mock; + ::test::components::protocol_handler_test::MockSessionObserver + session_observer_mock; const size_t init_value = 1000u; ON_CALL(protocol_handler_settings_mock, maximum_payload_size()) @@ -83,9 +81,11 @@ TEST(TelemetryMonitorTest, MessageProcess) { .WillByDefault(Return(init_value)); ON_CALL(protocol_handler_settings_mock, multiframe_waiting_timeout()) .WillByDefault(Return(init_value)); - protocol_handler::ProtocolHandlerImpl protocol_handler_mock( - protocol_handler_settings_mock, session_observer_mock, - connection_handler_mock, transport_manager_mock); + protocol_handler::ProtocolHandlerImpl protocol_handler_mock( + protocol_handler_settings_mock, + session_observer_mock, + connection_handler_mock, + transport_manager_mock); EXPECT_CALL(am_observeble, SetTelemetryObserver(_)); EXPECT_CALL(transport_manager_mock, SetTelemetryObserver(_)); @@ -94,8 +94,8 @@ TEST(TelemetryMonitorTest, MessageProcess) { telemetry_monitor.Start(); telemetry_monitor.set_streamer(&streamer_mock); - telemetry_monitor.Init(&protocol_handler_mock, &am_observeble, - &transport_manager_mock); + telemetry_monitor.Init( + &protocol_handler_mock, &am_observeble, &transport_manager_mock); utils::SharedPtr test_metric; EXPECT_CALL(streamer_mock, PushMessage(test_metric)); telemetry_monitor.SendMetric(test_metric); diff --git a/src/components/telemetry_monitor/test/transport_manager_metric_test.cc b/src/components/telemetry_monitor/test/transport_manager_metric_test.cc index 1219a9b1ab..9e485ce4f1 100644 --- a/src/components/telemetry_monitor/test/transport_manager_metric_test.cc +++ b/src/components/telemetry_monitor/test/transport_manager_metric_test.cc @@ -58,7 +58,8 @@ TEST(TransportManagerMetricWrapper, GetJsonMetric) { TimevalStruct end_time; end_time.tv_sec = 10; end_time.tv_usec = 0; - metric_test.message_metric = new transport_manager::TMTelemetryObserver::MessageMetric(); + metric_test.message_metric = + new transport_manager::TMTelemetryObserver::MessageMetric(); metric_test.message_metric->begin = start_time; metric_test.message_metric->end = end_time; metric_test.message_metric->data_size = 1000; @@ -68,8 +69,10 @@ TEST(TransportManagerMetricWrapper, GetJsonMetric) { EXPECT_EQ("null\n", jvalue[strings::utime].toStyledString()); EXPECT_EQ("null\n", jvalue[strings::memory].toStyledString()); - EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); - EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), + jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), + jvalue[strings::end].asInt64()); EXPECT_EQ(1000, jvalue[strings::data_size].asInt()); } @@ -86,7 +89,8 @@ TEST(TransportManagerMetricWrapper, GetJsonMetricWithGrabResources) { TimevalStruct end_time; end_time.tv_sec = 10; end_time.tv_usec = 0; - metric_test.message_metric = new transport_manager::TMTelemetryObserver::MessageMetric(); + metric_test.message_metric = + new transport_manager::TMTelemetryObserver::MessageMetric(); metric_test.message_metric->begin = start_time; metric_test.message_metric->end = end_time; @@ -94,12 +98,14 @@ TEST(TransportManagerMetricWrapper, GetJsonMetricWithGrabResources) { Json::Value jvalue = metric_test.GetJsonMetric(); EXPECT_EQ("\"TransportManager\"\n", jvalue[strings::logger].toStyledString()); - EXPECT_EQ(date_time::DateTime::getuSecs(start_time), jvalue[strings::begin].asInt64()); - EXPECT_EQ(date_time::DateTime::getuSecs(end_time), jvalue[strings::end].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(start_time), + jvalue[strings::begin].asInt64()); + EXPECT_EQ(date_time::DateTime::getuSecs(end_time), + jvalue[strings::end].asInt64()); EXPECT_EQ(1000, jvalue[strings::data_size].asInt()); - EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(),1); - EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(),1); + EXPECT_NEAR(resources->stime, jvalue[strings::stime].asInt(), 1); + EXPECT_NEAR(resources->utime, jvalue[strings::utime].asInt(), 1); EXPECT_EQ(resources->memory, jvalue[strings::memory].asInt()); delete resources; diff --git a/src/components/telemetry_monitor/test/transport_manager_observer_test.cc b/src/components/telemetry_monitor/test/transport_manager_observer_test.cc index 71de55e47a..866ff25863 100644 --- a/src/components/telemetry_monitor/test/transport_manager_observer_test.cc +++ b/src/components/telemetry_monitor/test/transport_manager_observer_test.cc @@ -46,7 +46,8 @@ using ::testing::_; TEST(TransportManagerObserverTest, MessageProcess) { MockTelemetryMonitor mock_telemetry_monitor; TransportManagerObserver tr_observer(&mock_telemetry_monitor); - protocol_handler::RawMessage* ptr = new ::protocol_handler::RawMessage(0, 0, NULL, 0); + protocol_handler::RawMessage* ptr = + new ::protocol_handler::RawMessage(0, 0, NULL, 0); tr_observer.StartRawMsg(ptr); EXPECT_CALL(mock_telemetry_monitor, SendMetric(_)); tr_observer.StopRawMsg(ptr); -- cgit v1.2.1 From 9dba2aecd2a4c7b4054067deb413311c44c80cac Mon Sep 17 00:00:00 2001 From: Kozoriz Date: Wed, 11 May 2016 10:05:02 +0300 Subject: Correct project structure in Policy component FIles moved to correct directory CMakeLists files corrected Headers corrected --- src/components/telemetry_monitor/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/components/telemetry_monitor') diff --git a/src/components/telemetry_monitor/CMakeLists.txt b/src/components/telemetry_monitor/CMakeLists.txt index 815720e15c..f3004dc61e 100644 --- a/src/components/telemetry_monitor/CMakeLists.txt +++ b/src/components/telemetry_monitor/CMakeLists.txt @@ -38,8 +38,7 @@ include_directories ( ${COMPONENTS_DIR}/connection_handler/include/ ${COMPONENTS_DIR}/transport_manager/include/ ${COMPONENTS_DIR}/application_manager/include/ - ${COMPONENTS_DIR}/policy/src/policy/include/ - ${COMPONENTS_DIR}/policy/src/policy/usage_statistics/include + ${COMPONENTS_DIR}/policy/include/ ${COMPONENTS_DIR}/hmi_message_handler/include/ ${COMPONENTS_DIR}/formatters/include/ ${COMPONENTS_DIR}/media_manager/include/ -- cgit v1.2.1