APPLINK-6379 Style fix, remove useless connections
authorAlex Kutsan <AKutsan@luxoft.com>
Fri, 18 Apr 2014 06:40:22 +0000 (09:40 +0300)
committerJustin Dickow <jjdickow@gmail.com>
Tue, 15 Jul 2014 15:16:19 +0000 (11:16 -0400)
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Conflicts:
src/components/connection_handler/CMakeLists.txt
src/components/protocol_handler/include/protocol_handler/time_metric_observer.h
src/components/time_tester/src/transport_manager_metric.cc
src/components/transport_manager/include/transport_manager/time_metric_observer.h
src/components/transport_manager/include/transport_manager/transport_manager_impl.h
src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc
src/components/transport_manager/src/transport_manager_impl.cc

src/components/connection_handler/CMakeLists.txt
src/components/protocol_handler/include/protocol_handler/time_metric_observer.h [new file with mode: 0644]
src/components/time_tester/src/transport_manager_metric.cc [new file with mode: 0644]
src/components/transport_manager/include/transport_manager/time_metric_observer.h [new file with mode: 0644]
src/components/transport_manager/include/transport_manager/transport_manager_impl.h
src/components/transport_manager/src/transport_adapter/transport_adapter_impl.cc
src/components/transport_manager/src/transport_manager_impl.cc

index 5689604..941aa6a 100644 (file)
@@ -4,6 +4,7 @@ include_directories (
   ../protocol_handler/include/
   ../config_profile/include/
   ../utils/include/
+  ../../thirdPartyLibs/encryption/include
 )
 
 set (SOURCES
diff --git a/src/components/protocol_handler/include/protocol_handler/time_metric_observer.h b/src/components/protocol_handler/include/protocol_handler/time_metric_observer.h
new file mode 100644 (file)
index 0000000..c003d89
--- /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_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_TIME_METRIC_OBSERVER_H_
+#define SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_TIME_METRIC_OBSERVER_H_
+
+namespace protocol_handler {
+
+class PHMetricObserver {
+  struct MessageMetric {
+      time_t begin;
+      time_t end;
+      std::string GetStylesString() {
+        return "PHMetricObserver";
+      }
+  };
+  virtual void OnMessage(MessageMetric& metric) = 0;
+};
+
+}
+#endif  // SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_TIME_METRIC_OBSERVER_H_
diff --git a/src/components/time_tester/src/transport_manager_metric.cc b/src/components/time_tester/src/transport_manager_metric.cc
new file mode 100644 (file)
index 0000000..e277469
--- /dev/null
@@ -0,0 +1,19 @@
+
+#include "application_manager/smart_object_keys.h"
+#include "transport_manager_metric.h"
+
+#include "json/json.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();
+}
+
+}
diff --git a/src/components/transport_manager/include/transport_manager/time_metric_observer.h b/src/components/transport_manager/include/transport_manager/time_metric_observer.h
new file mode 100644 (file)
index 0000000..64c4067
--- /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_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TIME_METRIC_OBSERVER_H_
+#define SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TIME_METRIC_OBSERVER_H_
+
+#include "transport_manager/common.h"
+
+namespace transport_manager {
+
+class TMMetricObserver {
+  public:
+    struct MessageMetric {
+        time_t begin;
+        time_t end;
+        size_t data_size;
+    };
+    virtual void StartRawMsg(const protocol_handler::RawMessage* ptr) = 0;
+    virtual void StopRawMsg(const protocol_handler::RawMessage* ptr) = 0;
+
+    //virtual void StopRawMsg(RawMessageSptr ptr) = 0;
+
+};
+
+}
+#endif  // SRC_COMPONENTS_TRANSPORT_MANAGER_INCLUDE_TRANSPORT_MANAGER_TIME_METRIC_OBSERVER_H_
index 409e227..53e62f2 100755 (executable)
@@ -55,6 +55,7 @@
 #include "transport_manager/transport_manager.h"
 #include "transport_manager/transport_manager_listener.h"
 #include "transport_manager/transport_adapter/transport_adapter_listener_impl.h"
+#include "transport_manager/time_metric_observer.h"
 
 using ::transport_manager::transport_adapter::TransportAdapterListener;
 
@@ -243,6 +244,14 @@ class TransportManagerImpl : public TransportManager {
    */
   void UpdateDeviceList(TransportAdapter* ta);
 
+
+  /**
+   * @brief Setup observer for time metric.
+   *
+   * @param observer - pointer to observer
+   */
+  virtual void SetTimeMetricObserver(TMMetricObserver* observer);
+
   /**
    * @brief Constructor.
    **/
@@ -443,6 +452,7 @@ class TransportManagerImpl : public TransportManager {
    * Device ID)
    */
   Handle2GUIDConverter converter_;
+  TMMetricObserver* metric_observer_;
 
   explicit TransportManagerImpl(const TransportManagerImpl&);
   int connection_id_counter_;
@@ -456,7 +466,6 @@ class TransportManagerImpl : public TransportManager {
   typedef std::vector<std::pair<const TransportAdapter*, DeviceInfo> >
       DeviceList;
   DeviceList device_list_;
-
   void AddConnection(const ConnectionInternal& c);
   void RemoveConnection(int id);
   ConnectionInternal* GetConnection(const ConnectionUID& id);
index ff7dae1..fd69bdc 100644 (file)
@@ -59,7 +59,8 @@ TransportAdapterImpl::TransportAdapterImpl(
       connections_mutex_(),
       device_scanner_(device_scanner),
       server_connection_factory_(server_connection_factory),
-      client_connection_listener_(client_connection_listener) {
+      client_connection_listener_(client_connection_listener),
+      metric_observer_(NULL) {
   pthread_mutex_init(&devices_mutex_, 0);
   pthread_mutex_init(&connections_mutex_, 0);
 }
@@ -425,6 +426,9 @@ void TransportAdapterImpl::DisconnectDone(const DeviceUID& device_id,
 void TransportAdapterImpl::DataReceiveDone(const DeviceUID& device_id,
                                            const ApplicationHandle& app_handle,
                                            RawMessageSptr message) {
+  if (metric_observer_) {
+    metric_observer_->StartRawMsg(message.get());
+  }
   for (TransportAdapterListenerList::iterator it = listeners_.begin();
        it != listeners_.end(); ++it)
     (*it)->OnDataReceiveDone(this, device_id, app_handle, message);
@@ -561,6 +565,14 @@ std::string TransportAdapterImpl::DeviceName(const DeviceUID& device_id) const {
   }
 }
 
+void TransportAdapterImpl::SetTimeMetricObserver(TMMetricObserver* observer) {
+  metric_observer_ = observer;
+}
+
+TMMetricObserver* TransportAdapterImpl::GetTimeMetricObserver() {
+  return metric_observer_;
+}
+
 void TransportAdapterImpl::Store() const {
 }
 
index 3d9ecd5..8a83752 100644 (file)
@@ -78,7 +78,8 @@ TransportManagerImpl::TransportManagerImpl()
       event_queue_thread_(),
       device_listener_thread_wakeup_(),
       is_initialized_(false),
-      connection_id_counter_(0) {
+      connection_id_counter_(0),
+      metric_observer_(NULL) {
   LOG4CXX_INFO(logger_, "==============================================");
 #ifdef USE_RWLOCK
   pthread_rwlock_init(&message_queue_rwlock_, NULL);
@@ -316,7 +317,9 @@ int TransportManagerImpl::AddTransportAdapter(
       transport_adapter->Init() == TransportAdapter::OK) {
     transport_adapters_.push_back(transport_adapter);
   }
-
+  if (metric_observer_) {
+    transport_adapter->SetTimeMetricObserver(metric_observer_);
+  }
   return E_SUCCESS;
 }
 
@@ -509,6 +512,7 @@ void TransportManagerImpl::PostEvent(const TransportAdapterEvent& event) {
 #else
   pthread_mutex_lock(&event_queue_mutex_);
 #endif
+  RawMessageSptr data = event.data();
   event_queue_.push_back(event);
   pthread_cond_signal(&device_listener_thread_wakeup_);
 #ifdef USE_RWLOCK
@@ -596,7 +600,6 @@ void TransportManagerImpl::EventListenerThread(void) {
       DeviceHandle device_handle;
       BaseError* error = current->event_error();
       RawMessageSptr data = current->data();
-
       int event_type = current->event_type();
       event_queue_.erase(current);
 #ifdef USE_RWLOCK
@@ -713,6 +716,9 @@ void TransportManagerImpl::EventListenerThread(void) {
             break;
           }
           data->set_connection_key(connection->id);
+          if (metric_observer_) {
+            metric_observer_->StopRawMsg(data.get());
+          }
           RaiseEvent(&TransportManagerListener::OnTMMessageReceived, data);
           break;
         }
@@ -765,6 +771,10 @@ void TransportManagerImpl::EventListenerThread(void) {
 
   LOG4CXX_INFO(logger_, "Event listener thread finished");
 }
+
+void TransportManagerImpl::SetTimeMetricObserver(TMMetricObserver* observer) {
+  metric_observer_ = observer;
+}
 void* TransportManagerImpl::MessageQueueStartThread(void* data) {
   if (NULL != data) {
     static_cast<TransportManagerImpl*>(data)->MessageQueueThread();