Timer Tester Component Added
authorJustin Dickow <jjdickow@gmail.com>
Tue, 15 Jul 2014 15:47:42 +0000 (11:47 -0400)
committerJustin Dickow <jjdickow@gmail.com>
Tue, 15 Jul 2014 15:47:42 +0000 (11:47 -0400)
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
17 files changed:
src/components/time_tester/CMakeLists.txt [new file with mode: 0644]
src/components/time_tester/include/time_tester/application_manager_metric.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/application_manager_observer.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/json_keys.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/metric.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/protocol_handler_metric.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/protocol_handler_observer.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/time_manager.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/transport_manager_metric.h [new file with mode: 0644]
src/components/time_tester/include/time_tester/transport_manager_observer.h [new file with mode: 0644]
src/components/time_tester/src/application_manager_metric.cc [new file with mode: 0644]
src/components/time_tester/src/application_manager_observer.cc [new file with mode: 0644]
src/components/time_tester/src/protocol_handler_metric.cc [new file with mode: 0644]
src/components/time_tester/src/protocol_handler_observer.cc [new file with mode: 0644]
src/components/time_tester/src/time_manager.cc [new file with mode: 0644]
src/components/time_tester/src/transport_manager_metric.cc
src/components/time_tester/src/transport_manager_observer.cc [new file with mode: 0644]

diff --git a/src/components/time_tester/CMakeLists.txt b/src/components/time_tester/CMakeLists.txt
new file mode 100644 (file)
index 0000000..fea8743
--- /dev/null
@@ -0,0 +1,30 @@
+include_directories (
+  ./include/time_tester
+  ../utils/include/
+  ../protocol_handler/include/
+  ../connection_handler/include/
+  ../transport_manager/include/
+  ../application_manager/include/
+  ../hmi_message_handler/include/
+  ../request_watchdog/include/
+  ../formatters/include/
+  ../media_manager/include/
+  ../smart_objects/include/
+  ../config_profile/include/
+  ../../thirdPartyLibs/jsoncpp/include/
+  ${CMAKE_BINARY_DIR}/src/components/
+)
+
+set (SOURCES
+    ./src/time_manager.cc
+    ./src/application_manager_observer.cc
+    ./src/transport_manager_observer.cc
+    ./src/protocol_handler_observer.cc
+    ./src/application_manager_metric.cc
+    ./src/transport_manager_metric.cc
+    ./src/protocol_handler_metric.cc
+
+)
+
+add_library("TimeTester" ${SOURCES})
+target_link_libraries("TimeTester" ${LIBRARIES})
diff --git a/src/components/time_tester/include/time_tester/application_manager_metric.h b/src/components/time_tester/include/time_tester/application_manager_metric.h
new file mode 100644 (file)
index 0000000..a0c8bf6
--- /dev/null
@@ -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_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_H_
+
+#include <string>
+
+#include "metric.h"
+#include "application_manager_observer.h"
+
+
+namespace time_tester {
+
+class ApplicationManagerObserver;
+
+class ApplicationManagerMetric: public Metric {
+
+  public:
+    utils::SharedPtr<application_manager::AMMetricObserver::MessageMetric> message_metric;
+    std::string GetStyledString();
+};
+
+}
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_H_
diff --git a/src/components/time_tester/include/time_tester/application_manager_observer.h b/src/components/time_tester/include/time_tester/application_manager_observer.h
new file mode 100644 (file)
index 0000000..8331682
--- /dev/null
@@ -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_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_OBSERVER_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_OBSERVER_H_
+
+#include "utils/message_queue.h"
+#include "application_manager/time_metric_observer.h"
+#include "application_manager_metric.h"
+
+
+namespace time_tester {
+
+class TimeManager;
+
+class ApplicationManagerObserver: public application_manager::AMMetricObserver {
+   public:
+    explicit ApplicationManagerObserver(TimeManager* time_manager);
+   virtual void OnMessage(utils::SharedPtr<MessageMetric> metric);
+
+  private:
+    TimeManager* time_manager_;
+};
+
+}
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_OBSERVER_H_
diff --git a/src/components/time_tester/include/time_tester/json_keys.h b/src/components/time_tester/include/time_tester/json_keys.h
new file mode 100644 (file)
index 0000000..7540991
--- /dev/null
@@ -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.
+ */
+
+#ifndef SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_JSON_KEYS_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_JSON_KEYS_H_
+
+namespace time_tester {
+  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";
+
+
+  }
+}
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_JSON_KEYS_H_
diff --git a/src/components/time_tester/include/time_tester/metric.h b/src/components/time_tester/include/time_tester/metric.h
new file mode 100644 (file)
index 0000000..93193b4
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_MECTRIC_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_MECTRIC_H_
+
+#include <string>
+
+namespace time_tester {
+
+class Metric {
+  public:
+    virtual std::string GetStyledString() = 0;
+    virtual ~Metric(){}
+};
+}  // namespace time_tester
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_MECTRIC_H_
diff --git a/src/components/time_tester/include/time_tester/protocol_handler_metric.h b/src/components/time_tester/include/time_tester/protocol_handler_metric.h
new file mode 100644 (file)
index 0000000..507f054
--- /dev/null
@@ -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_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_MECTRIC_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_MECTRIC_H_
+
+#include <string>
+#include "utils/shared_ptr.h"
+#include "metric.h"
+#include "protocol_handler_observer.h"
+
+namespace time_tester {
+
+class ProtocolHandlerMectic: public Metric {
+
+  public:
+    utils::SharedPtr<protocol_handler::PHMetricObserver::MessageMetric> message_metric;
+    std::string GetStyledString();
+};
+}  // namespace time_tester
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_MECTRIC_H_
diff --git a/src/components/time_tester/include/time_tester/protocol_handler_observer.h b/src/components/time_tester/include/time_tester/protocol_handler_observer.h
new file mode 100644 (file)
index 0000000..03339c0
--- /dev/null
@@ -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_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_OBSERVER_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_OBSERVER_H_
+
+#include "protocol_handler/time_metric_observer.h"
+#include "utils/message_queue.h"
+
+namespace time_tester {
+
+class TimeManager;
+
+class ProtocolHandlerObserver: public protocol_handler::PHMetricObserver {
+ public:
+  explicit ProtocolHandlerObserver(TimeManager* time_manager);
+
+  virtual void StartMessageProcess(uint32_t message_id);
+
+  virtual void EndMessageProcess(utils::SharedPtr<MessageMetric> m);
+
+ private:
+  TimeManager* time_manager_;
+  std::map<uint32_t, TimevalStruct> time_starts;
+};
+}  // namespace time_tester
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_OBSERVER_H_
diff --git a/src/components/time_tester/include/time_tester/time_manager.h b/src/components/time_tester/include/time_tester/time_manager.h
new file mode 100644 (file)
index 0000000..a4f26dc
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef SRC_COMPONENTS_TIME_MANAGER_INCLUDE_TIME_MANAGER_MEDIA_MANAGER_H_
+#define SRC_COMPONENTS_TIME_MANAGER_INCLUDE_TIME_MANAGER_MEDIA_MANAGER_H_
+
+#include <string>
+
+#include "utils/shared_ptr.h"
+#include "utils/message_queue.h"
+#include "utils/threads/thread.h"
+#include "utils/singleton.h"
+#include "utils/threads/thread_delegate.h"
+#include "metric.h"
+#include "application_manager_observer.h"
+#include "application_manager/application_manager_impl.h"
+#include "transport_manager_observer.h"
+#include "transport_manager/transport_manager_impl.h"
+#include "protocol_handler_observer.h"
+#include "protocol_handler/protocol_handler_impl.h"
+
+namespace time_tester {
+
+class TimeManager {
+ public:
+  TimeManager();
+  ~TimeManager();
+  void Init(protocol_handler::ProtocolHandlerImpl* ph);
+  void Stop();
+  void SendMetric(utils::SharedPtr<Metric> metric);
+ private:
+  ApplicationManagerObserver app_observer;
+  TransportManagerObserver tm_observer;
+  ProtocolHandlerObserver ph_observer;
+
+  int16_t port_;
+  std::string ip_;
+  int32_t socket_fd_;
+  bool is_ready_;
+  threads::Thread* thread_;
+  MessageQueue<utils::SharedPtr<Metric> > messages_;
+
+  class Streamer : public threads::ThreadDelegate {
+   public:
+    explicit Streamer(TimeManager* const server);
+    ~Streamer();
+    void threadMain() OVERRIDE;
+    bool exitThreadMain() OVERRIDE;
+    bool IsReady() const;
+    void Start();
+    void Stop();
+    bool Send(const std::string &msg);
+  private:
+    TimeManager* const server_;
+    int32_t new_socket_fd_;
+    volatile bool is_client_connected_;
+    volatile bool stop_flag_;
+    DISALLOW_COPY_AND_ASSIGN(Streamer);
+  };
+  DISALLOW_COPY_AND_ASSIGN(TimeManager);
+};
+}  // namespace time_manager
+#endif  // SRC_COMPONENTS_TIME_MANAGER_INCLUDE_TIME_MANAGER_MEDIA_MANAGER_H_
diff --git a/src/components/time_tester/include/time_tester/transport_manager_metric.h b/src/components/time_tester/include/time_tester/transport_manager_metric.h
new file mode 100644 (file)
index 0000000..c2c9c4a
--- /dev/null
@@ -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_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_MECTRIC_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_MECTRIC_H_
+
+#include <string>
+#include "metric.h"
+#include "transport_manager_observer.h"
+
+namespace time_tester {
+
+class TransportManagerMectic: public Metric {
+ public:
+  utils::SharedPtr<transport_manager::TMMetricObserver::MessageMetric> message_metric;
+  std::string GetStyledString();
+};
+}  // namespace time_tester
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_MECTRIC_H_
diff --git a/src/components/time_tester/include/time_tester/transport_manager_observer.h b/src/components/time_tester/include/time_tester/transport_manager_observer.h
new file mode 100644 (file)
index 0000000..ee83888
--- /dev/null
@@ -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_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_OBSERVER_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_OBSERVER_H_
+
+#include "transport_manager/time_metric_observer.h"
+#include "utils/message_queue.h"
+#include "utils/date_time.h"
+
+namespace time_tester {
+
+class TimeManager;
+
+class TransportManagerObserver: public transport_manager::TMMetricObserver {
+ public:
+  explicit TransportManagerObserver(TimeManager* time_manager);
+  virtual void StartRawMsg(const protocol_handler::RawMessage* ptr);
+  virtual void StopRawMsg(const protocol_handler::RawMessage* ptr);
+ private:
+  TimeManager* time_manager_;
+  std::map<const protocol_handler::RawMessage*, TimevalStruct> time_starts;
+};
+}  // namespace time_tester
+#endif  // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_OBSERVER_H_
diff --git a/src/components/time_tester/src/application_manager_metric.cc b/src/components/time_tester/src/application_manager_metric.cc
new file mode 100644 (file)
index 0000000..6978e72
--- /dev/null
@@ -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.
+ */
+
+#include "application_manager_metric.h"
+#include "json_keys.h"
+#include "application_manager/smart_object_keys.h"
+
+namespace time_tester {
+
+std::string ApplicationManagerMetric::GetStyledString() {
+  Json::Value result;
+  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] =
+      params[application_manager::strings::correlation_id].asInt();
+  result[strings::connection_key] =
+      params[application_manager::strings::connection_key].asInt();
+  return result.toStyledString();
+}
+}  // namespace time_tester
diff --git a/src/components/time_tester/src/application_manager_observer.cc b/src/components/time_tester/src/application_manager_observer.cc
new file mode 100644 (file)
index 0000000..fa768e2
--- /dev/null
@@ -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.
+*/
+#include "application_manager_observer.h"
+#include "utils/shared_ptr.h"
+#include "time_manager.h"
+#include "application_manager_metric.h"
+
+namespace time_tester {
+
+ApplicationManagerObserver::ApplicationManagerObserver(TimeManager* time_manager):
+  time_manager_(time_manager) {
+}
+
+void ApplicationManagerObserver::OnMessage(utils::SharedPtr<MessageMetric> metric) {
+  ApplicationManagerMetric* m = new ApplicationManagerMetric();
+  m->message_metric = metric;
+  time_manager_->SendMetric(m);
+}
+}  // namespace time_tester
diff --git a/src/components/time_tester/src/protocol_handler_metric.cc b/src/components/time_tester/src/protocol_handler_metric.cc
new file mode 100644 (file)
index 0000000..278cab2
--- /dev/null
@@ -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.
+ */
+
+#include "protocol_handler_metric.h"
+#include "json/json.h"
+#include "json_keys.h"
+
+namespace time_tester {
+
+std::string ProtocolHandlerMectic::GetStyledString() {
+  Json::Value result;
+  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.toStyledString();
+}
+}  // namespace time_tester
diff --git a/src/components/time_tester/src/protocol_handler_observer.cc b/src/components/time_tester/src/protocol_handler_observer.cc
new file mode 100644 (file)
index 0000000..1ddf084
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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 "protocol_handler_observer.h"
+#include "utils/date_time.h"
+#include "protocol_handler_metric.h"
+#include "time_manager.h"
+
+namespace time_tester {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "Utils")
+
+ProtocolHandlerObserver::ProtocolHandlerObserver(TimeManager *time_manager):
+  time_manager_(time_manager) {
+}
+
+void ProtocolHandlerObserver::StartMessageProcess(uint32_t message_id) {
+  if (message_id == 0) {
+    return;
+  }
+  if (time_starts.find(message_id) != time_starts.end()) {
+    LOG4CXX_INFO(logger_, "Message ID already wait for stop processing" << message_id);
+    return;
+  }
+  time_starts[message_id] = date_time::DateTime::getCurrentTime();
+}
+
+void ProtocolHandlerObserver::EndMessageProcess(utils::SharedPtr<MessageMetric> m) {
+  uint32_t message_id = m->message_id;
+  std::map<uint32_t, TimevalStruct>::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();
+  ProtocolHandlerMectic* metric = new ProtocolHandlerMectic();
+  metric->message_metric = m;
+  time_manager_->SendMetric(metric);
+}
+}  //namespace time_tester
diff --git a/src/components/time_tester/src/time_manager.cc b/src/components/time_tester/src/time_manager.cc
new file mode 100644 (file)
index 0000000..d7c4589
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "time_manager.h"
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "transport_manager/transport_manager_default.h"
+#include "config_profile/profile.h"
+
+namespace time_tester {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "TimeManager")
+
+TimeManager::TimeManager():
+  socket_fd_(0),
+  messages_(),
+  thread_(NULL),
+  app_observer(this),
+  tm_observer(this),
+  ph_observer(this) {
+    ip_ = profile::Profile::instance()->server_address();
+    port_ = profile::Profile::instance()->time_testing_port();
+}
+
+TimeManager::~TimeManager() {
+  LOG4CXX_INFO(logger_, "Destroing TimeManager");
+  Stop();
+}
+
+void TimeManager::Init(protocol_handler::ProtocolHandlerImpl* ph) {
+  DCHECK(ph);
+  if (!thread_) {
+    thread_ = new threads::Thread("SocketAdapter", new Streamer(this));
+    application_manager::ApplicationManagerImpl::instance()->SetTimeMetricObserver(&app_observer);
+    transport_manager::TransportManagerDefault::instance()->SetTimeMetricObserver(&tm_observer);
+    ph->SetTimeMetricObserver(&ph_observer);
+    thread_->startWithOptions(threads::ThreadOptions());
+    LOG4CXX_INFO(logger_, "Create and start sending thread");
+    }
+}
+
+void TimeManager::Stop() {
+  if (thread_) {
+    thread_->stop();
+    delete thread_;
+    thread_ = NULL;
+    if (socket_fd_ != -1) {
+      ::close(socket_fd_);
+    }
+  }
+  LOG4CXX_INFO(logger_, "TimeManager stopped");
+}
+
+void TimeManager::SendMetric(utils::SharedPtr<Metric> metric) {
+  messages_.push(metric);
+}
+
+TimeManager::Streamer::Streamer(
+  TimeManager* const server)
+  : server_(server),
+    new_socket_fd_(0),
+    is_client_connected_(false),
+    stop_flag_(false) {
+}
+
+TimeManager::Streamer::~Streamer() {
+  Stop();
+}
+
+void TimeManager::Streamer::threadMain() {
+  LOG4CXX_INFO(logger_, "Streamer::threadMain");
+
+  Start();
+
+  while (!stop_flag_) {
+    new_socket_fd_ = accept(server_->socket_fd_, NULL, NULL);
+    if (0 > new_socket_fd_) {
+      LOG4CXX_ERROR(logger_, "Socket is closed");
+      sleep(1);
+      continue;
+    }
+
+    is_client_connected_ = true;
+    while (is_client_connected_) {
+      while (!server_->messages_.empty()) {
+        utils::SharedPtr<Metric> metric = server_->messages_.pop();
+        is_client_connected_ = Send(metric->GetStyledString());
+      }
+
+      if (!IsReady()) {
+        LOG4CXX_INFO(logger_, "Client disconnected.");
+        Stop();
+        break;
+      }
+
+      server_->messages_.wait();
+    }
+  }
+}
+
+bool TimeManager::Streamer::exitThreadMain() {
+  LOG4CXX_INFO(logger_, "Streamer::exitThreadMain");
+  stop_flag_ = true;
+  Stop();
+  server_->messages_.Shutdown();
+  return false;
+}
+
+void TimeManager::Streamer::Start() {
+  server_->socket_fd_ = socket(AF_INET, SOCK_STREAM, 0);
+
+  if (0 >= server_->socket_fd_) {
+    LOG4CXX_ERROR_EXT(logger_, "Server open error");
+    return;
+  }
+
+  int32_t optval = 1;
+  if (-1 == setsockopt(server_->socket_fd_, SOL_SOCKET, SO_REUSEADDR,
+                       &optval, sizeof optval)) {
+    LOG4CXX_ERROR_EXT(logger_, "Unable to set sockopt");
+    return;
+  }
+
+  sockaddr_in serv_addr_;
+  memset(&serv_addr_, 0, sizeof(serv_addr_));
+  serv_addr_.sin_addr.s_addr = inet_addr(server_->ip_.c_str());
+  serv_addr_.sin_family = AF_INET;
+  serv_addr_.sin_port = htons(server_->port_);
+
+  if (-1 == bind(server_->socket_fd_,
+                 reinterpret_cast<struct sockaddr*>(&serv_addr_),
+                 sizeof(serv_addr_))) {
+    LOG4CXX_ERROR(logger_, "Unable to bind server "
+                  << server_->ip_.c_str() << ':' << server_->port_);
+    return;
+  }
+  if (-1 == listen(server_->socket_fd_, 1)) {
+    LOG4CXX_ERROR(logger_, "Streamer listen error " << strerror(errno) );
+    return;
+  }
+  LOG4CXX_INFO(logger_, "Streamer is listetning for connections");
+}
+
+void TimeManager::Streamer::Stop() {
+  LOG4CXX_INFO(logger_, "SocketStreamerAdapter::Streamer::stop");
+  if (!new_socket_fd_) {
+    return;
+  }
+
+  if (-1 == shutdown(new_socket_fd_, SHUT_RDWR)) {
+    LOG4CXX_ERROR(logger_, "Unable to shutdown socket");
+    return;
+  }
+
+  if (-1 == close(new_socket_fd_)) {
+    LOG4CXX_ERROR(logger_, "Unable to close socket");
+    return;
+  }
+
+  new_socket_fd_ = -1;
+  is_client_connected_ = false;
+}
+
+bool TimeManager::Streamer::IsReady() const {
+  bool result = true;
+  fd_set fds;
+  FD_ZERO(&fds);
+  FD_SET(new_socket_fd_, &fds);
+  TimevalStruct tv;
+  tv.tv_sec = 5;                       // set a 5 second timeout
+  tv.tv_usec = 0;
+
+  const int retval = select(new_socket_fd_ + 1, 0, &fds, 0, &tv);
+
+  if (-1 == retval) {
+    LOG4CXX_ERROR_EXT(logger_, "An error occurred");
+    result = false;
+  } else if (0 == retval) {
+    LOG4CXX_ERROR_EXT(logger_, "The timeout expired");
+    result = false;
+  }
+
+  return result;
+}
+
+bool TimeManager::Streamer::Send(const std::string& msg) {
+  if (!IsReady()) {
+    LOG4CXX_ERROR_EXT(logger_, " Socket is not ready");
+    return false;
+  }
+
+  if (-1 == ::send(new_socket_fd_, msg.c_str(),
+                   msg.size(), MSG_NOSIGNAL)) {
+    LOG4CXX_ERROR_EXT(logger_, " Unable to send");
+    return false;
+  }
+  return true;
+}
+}  // namespace time_tester
index e277469..cb2567f 100644 (file)
@@ -1,19 +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.
+ */
 
-#include "application_manager/smart_object_keys.h"
 #include "transport_manager_metric.h"
-
 #include "json/json.h"
-
+#include "json_keys.h"
+#include "application_manager/smart_object_keys.h"
 
 namespace time_tester {
 
 std::string TransportManagerMectic::GetStyledString() {
-    Json::Value result;
-    result["logger"] = "TransportManager";
-    result["begin"] = static_cast<uint32_t>(message_metric->begin);
-    result["end"] = static_cast<uint32_t>(message_metric->end);
-    result["data_size"] = message_metric->data_size;
-    return result.toStyledString();
-}
-
+  Json::Value result;
+  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<uint32_t>(message_metric->data_size);
+  return result.toStyledString();
 }
+}  // namespace time_tester
diff --git a/src/components/time_tester/src/transport_manager_observer.cc b/src/components/time_tester/src/transport_manager_observer.cc
new file mode 100644 (file)
index 0000000..ad86281
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2014, Ford Motor Company
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the Ford Motor Company nor the names of its contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+#include "transport_manager_observer.h"
+
+#include <time.h>
+
+#include "transport_manager_metric.h"
+#include "time_manager.h"
+
+namespace time_tester {
+
+TransportManagerObserver::TransportManagerObserver(TimeManager* time_manager):
+  time_manager_ (time_manager) {
+}
+
+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 protocol_handler::RawMessage*, TimevalStruct>::const_iterator it;
+    it = time_starts.find(ptr);
+    if (it != time_starts.end()) {
+      TransportManagerMectic* m = new TransportManagerMectic();
+      m->message_metric = new transport_manager::TMMetricObserver::MessageMetric();
+      m->message_metric->begin = it->second;
+      m->message_metric->end = date_time::DateTime::getCurrentTime();
+      m->message_metric->data_size = ptr->data_size();
+      time_manager_->SendMetric(m);
+    }
+}
+
+} //namespace time_tester