Not a subject for review
authorVladislav Smenyuk <VSmenyuk@luxoft.com>
Tue, 8 Apr 2014 10:54:48 +0000 (03:54 -0700)
committerJustin Dickow <jjdickow@gmail.com>
Wed, 9 Jul 2014 18:10:24 +0000 (14:10 -0400)
Reason: Local changes

Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Conflicts:
src/appMain/log4cxx.properties

src/appMain/log4cxx.properties
src/components/application_manager/src/application_manager_impl.cc
src/components/protocol_handler/include/protocol_handler/protocol_packet.h
src/components/protocol_handler/src/protocol_handler_impl.cc
src/components/protocol_handler/src/protocol_packet.cc
src/components/protocol_handler/src/protocol_payload.cc
src/components/protocol_handler/src/rpc_type.cc
src/components/protocol_handler/src/service_type.cc

index 5a3c37c..8198832 100644 (file)
@@ -47,7 +47,7 @@ log4j.appender.HmiFrameworkPluginLogFile.layout=org.apache.log4j.PatternLayout
 log4j.appender.HmiFrameworkPluginLogFile.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, SmartDeviceLinkCoreSocketHub
+log4j.rootLogger=ALL, Console, SmartDeviceLinkCoreSocketHub
 
 # TransportManager logs
 log4j.logger.TransportManager=ALL, TransportManagerLogFile
index 2bd7133..98c356d 100644 (file)
@@ -346,6 +346,9 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication(
   application->set_version(version);
 
   application->set_mobile_app_id(message[strings::msg_params][strings::app_id]);
+  application->set_protocol_version(
+      static_cast<ProtocolVersion>(
+          message[strings::params][strings::protocol_version].asInt()));
 
   sync_primitives::AutoLock lock(applications_list_lock_);
 
@@ -682,7 +685,10 @@ void ApplicationManagerImpl::OnMessageReceived(
     return;
   }
 
+  LOG4CXX_INFO(logger_, "RawMessagePtr service type" << message->service_type());
+
   utils::SharedPtr<Message> outgoing_message = ConvertRawMsgToMessage(message);
+
   if (outgoing_message) {
     messages_from_mobile_.PostMessage(
       impl::MessageFromMobile(outgoing_message));
@@ -724,7 +730,7 @@ void ApplicationManagerImpl::OnDeviceListUpdated(
     hmi_apis::FunctionID::BasicCommunication_UpdateDeviceList;
   so_to_send[jhs::S_PARAMS][jhs::S_MESSAGE_TYPE] =
     hmi_apis::messageType::request;
-  so_to_send[jhs::S_PARAMS][jhs::S_PROTOCOL_VERSION] = 2;
+  so_to_send[jhs::S_PARAMS][jhs::S_PROTOCOL_VERSION] = 3;
   so_to_send[jhs::S_PARAMS][jhs::S_PROTOCOL_TYPE] = 1;
   so_to_send[jhs::S_PARAMS][jhs::S_CORRELATION_ID] = GetNextHMICorrelationID();
   smart_objects::SmartObject* msg_params = MessageHelper::CreateDeviceListSO(
@@ -904,6 +910,30 @@ void ApplicationManagerImpl::SendMessageToMobile(
     return;
   }
 
+  LOG4CXX_INFO(
+      logger_,
+      "Connection key: " <<  (*message)[strings::params][strings::connection_key].asUInt());
+
+  ApplicationSharedPtr app = application(
+                 (*message)[strings::params][strings::connection_key].asUInt());
+
+  if (!app) {
+     LOG4CXX_ERROR_EXT(logger_,
+                       "No application associated with connection key");
+     (*message)[strings::params][strings::protocol_version] =
+         ProtocolVersion::kV3;
+     return;
+   } else {
+     LOG4CXX_INFO(logger_,
+           "Protocol version: " <<  app->protocol_version());
+
+     (*message)[strings::params][strings::protocol_version] =
+           app->protocol_version();
+   }
+
+  (*message)[strings::params][strings::protocol_version] =
+      app->protocol_version();
+
   mobile_so_factory().attachSchema(*message);
   LOG4CXX_INFO(
     logger_,
@@ -980,7 +1010,7 @@ bool ApplicationManagerImpl::ManageMobileCommand(
           correlation_id,
           static_cast<int32_t>(mobile_apis::Result::APPLICATION_NOT_REGISTERED));
 
-      ApplicationManagerImpl::instance()->SendMessageToMobile(response);
+      SendMessageToMobile(response);
       return false;
     }
 
@@ -1046,7 +1076,7 @@ bool ApplicationManagerImpl::ManageMobileCommand(
             correlation_id,
             static_cast<int32_t>(mobile_apis::Result::TOO_MANY_PENDING_REQUESTS));
 
-        ApplicationManagerImpl::instance()->SendMessageToMobile(response);
+        SendMessageToMobile(response);
         return false;
       } else if (result ==
                  request_controller::RequestController::TOO_MANY_REQUESTS) {
@@ -1189,8 +1219,8 @@ bool ApplicationManagerImpl::ConvertMessageToSO(
     << "; json " << message.json_message());
 
   switch (message.protocol_version()) {
+    case ProtocolVersion::kV3:
     case ProtocolVersion::kV2: {
-
       if (!formatters::CFormatterJsonSDLRPCv2::fromString(
             message.json_message(),
             output,
@@ -1330,7 +1360,10 @@ bool ApplicationManagerImpl::ConvertSOtoMessage(
             LOG4CXX_WARN(logger_, "Failed to serialize smart object");
             return false;
           }
-          output.set_protocol_version(application_manager::kV2);
+          output.set_protocol_version(
+              static_cast<ProtocolVersion>(
+                  message.getElement(jhs::S_PARAMS).getElement(
+                                            jhs::S_PROTOCOL_VERSION).asUInt()));
         }
 
       break;
@@ -1406,7 +1439,8 @@ utils::SharedPtr<Message> ApplicationManagerImpl::ConvertRawMsgToMessage(
   if (message->protocol_version() == 1) {
     convertion_result =
       MobileMessageHandler::HandleIncomingMessageProtocolV1(message);
-  } else if (message->protocol_version() == 2) {
+  } else if ((message->protocol_version() == 2) ||
+             (message->protocol_version() == 3)) {
     convertion_result =
       MobileMessageHandler::HandleIncomingMessageProtocolV2(message);
   } else {
@@ -1631,7 +1665,8 @@ void ApplicationManagerImpl::Handle(const impl::MessageToMobile& message) {
   protocol_handler::RawMessage* rawMessage = 0;
   if (message->protocol_version() == application_manager::kV1) {
     rawMessage = MobileMessageHandler::HandleOutgoingMessageProtocolV1(message);
-  } else if (message->protocol_version() == application_manager::kV2) {
+  } else if ((message->protocol_version() == application_manager::kV2) ||
+             (message->protocol_version() == application_manager::kV3)) {
     rawMessage = MobileMessageHandler::HandleOutgoingMessageProtocolV2(message);
   } else {
     return;
index 3775439..41ddb89 100644 (file)
@@ -64,6 +64,11 @@ const uint8_t PROTOCOL_VERSION_1 = 0x01;
 const uint8_t PROTOCOL_VERSION_2 = 0x02;
 
 /**
+ *\brief Constant: number of protocol version (3).
+ */
+const uint8_t PROTOCOL_VERSION_3 = 0x03;
+
+/**
  *\brief Constant: flag of no compression
  */
 const bool COMPRESS_OFF = false;
index 1cbd721..fcd47ac 100644 (file)
@@ -131,6 +131,7 @@ class ProtocolHandlerImpl::IncomingDataHandler {
       case PROTOCOL_VERSION_1:
         required_size += PROTOCOL_HEADER_V1_SIZE;
         break;
+      case PROTOCOL_VERSION_3:
       case PROTOCOL_VERSION_2:
         required_size += PROTOCOL_HEADER_V2_SIZE;
         break;
@@ -203,7 +204,7 @@ void ProtocolHandlerImpl::SendStartSessionAck(ConnectionID connection_id,
   LOG4CXX_TRACE_ENTER(logger_);
 
   ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id,
-      PROTOCOL_VERSION_2, COMPRESS_OFF, FRAME_TYPE_CONTROL,
+      PROTOCOL_VERSION_3, COMPRESS_OFF, FRAME_TYPE_CONTROL,
       service_type, FRAME_DATA_START_SERVICE_ACK, session_id,
       0, hash_code));
 
@@ -290,7 +291,7 @@ RESULT_CODE ProtocolHandlerImpl::SendHeartBeatAck(ConnectionID connection_id,
   LOG4CXX_TRACE_ENTER(logger_);
 
   ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id,
-      PROTOCOL_VERSION_2, COMPRESS_OFF, FRAME_TYPE_CONTROL,
+      PROTOCOL_VERSION_3, COMPRESS_OFF, FRAME_TYPE_CONTROL,
       SERVICE_TYPE_ZERO, FRAME_DATA_HEART_BEAT_ACK, session_id,
       0, message_id));
 
@@ -314,7 +315,7 @@ void ProtocolHandlerImpl::SendMessageToMobileApp(const RawMessagePtr& message,
   uint32_t maxDataSize = 0;
   if (PROTOCOL_VERSION_1 == message->protocol_version()) {
     maxDataSize = MAXIMUM_FRAME_DATA_SIZE - PROTOCOL_HEADER_V1_SIZE;
-  } else if (PROTOCOL_VERSION_2 == message->protocol_version()) {
+  } else {
     maxDataSize = MAXIMUM_FRAME_DATA_SIZE - PROTOCOL_HEADER_V2_SIZE;
   }
 
@@ -515,12 +516,8 @@ RESULT_CODE ProtocolHandlerImpl::SendSingleFrameMessage(
     const bool is_final_message) {
   LOG4CXX_TRACE_ENTER(logger_);
 
-  uint8_t versionF = PROTOCOL_VERSION_1;
-  if (2 == protocol_version) {
-    versionF = PROTOCOL_VERSION_2;
-  }
   ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id,
-      versionF, compress, FRAME_TYPE_SINGLE, service_type, 0,
+      protocol_version, compress, FRAME_TYPE_SINGLE, service_type, 0,
       session_id, data_size, message_counters_[session_id]++, data));
 
   raw_ford_messages_to_mobile_.PostMessage(
@@ -541,11 +538,6 @@ RESULT_CODE ProtocolHandlerImpl::SendMultiFrameMessage(
   LOG4CXX_INFO_EXT(
       logger_, " data size " << data_size << " maxdata_size " << maxdata_size);
 
-  uint8_t versionF = PROTOCOL_VERSION_1;
-  if (2 == protocol_version) {
-    versionF = PROTOCOL_VERSION_2;
-  }
-
   int32_t numOfFrames = 0;
   int32_t lastdata_size = 0;
 
@@ -574,7 +566,7 @@ RESULT_CODE ProtocolHandlerImpl::SendMultiFrameMessage(
   outDataFirstFrame[7] = numOfFrames;
 
   ProtocolFramePtr firstPacket(new protocol_handler::ProtocolPacket(connection_id,
-      versionF, compress, FRAME_TYPE_FIRST, service_type, 0,
+      protocol_version, compress, FRAME_TYPE_FIRST, service_type, 0,
       session_id, FIRST_FRAME_DATA_SIZE, ++message_counters_[session_id],
       outDataFirstFrame));
 
@@ -588,7 +580,7 @@ RESULT_CODE ProtocolHandlerImpl::SendMultiFrameMessage(
       memcpy(outDataFrame, data + (maxdata_size * i), maxdata_size);
 
       ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id,
-          versionF, compress, FRAME_TYPE_CONSECUTIVE,
+          protocol_version, compress, FRAME_TYPE_CONSECUTIVE,
           service_type, ((i % FRAME_DATA_MAX_VALUE) + 1), session_id,
           maxdata_size, message_counters_[session_id], outDataFrame));
 
@@ -599,7 +591,7 @@ RESULT_CODE ProtocolHandlerImpl::SendMultiFrameMessage(
       memcpy(outDataFrame, data + (maxdata_size * i), lastdata_size);
 
       ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id,
-          versionF, compress, FRAME_TYPE_CONSECUTIVE,
+          protocol_version, compress, FRAME_TYPE_CONSECUTIVE,
           service_type, 0x0, session_id, lastdata_size,
           message_counters_[session_id], outDataFrame));
 
@@ -776,7 +768,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndSession(
   uint8_t current_session_id = packet.session_id();
 
   uint32_t hash_code = 0;
-  if (packet.protocol_version() == 2) {
+  if (1 != packet.protocol_version()) {
     hash_code = packet.message_id();
   }
 
@@ -786,7 +778,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndSession(
       ServiceTypeFromByte(packet.service_type()));
 
   if (-1 != session_hash_code) {
-    if (2 == packet.protocol_version()) {
+    if (1 != packet.protocol_version()) {
       if (packet.message_id() != session_hash_code) {
         success = false;
       }
@@ -813,11 +805,9 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndSession(
 
 RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
     ConnectionID connection_id, const ProtocolPacket& packet) {
-  LOG4CXX_INFO(logger_,
-               "ProtocolHandlerImpl::HandleControlMessageStartSession" 
-                               << (int) packet.protocol_version() );
   LOG4CXX_INFO_EXT(logger_,
-                   "Version 2 " << (packet.protocol_version() == PROTOCOL_VERSION_2));
+                   "Protocol version: " <<
+                   static_cast<int>(packet.protocol_version()));
 
   int32_t session_id = session_observer_->OnSessionStartedCallback(
       connection_id, packet.session_id(),
@@ -891,7 +881,7 @@ void ProtocolHandlerImpl::SendFramesNumber(int32_t connection_key,
   uint8_t session_id = 0;
   session_observer_->PairFromKey(connection_key, &connection_id, &session_id);
   ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id,
-      PROTOCOL_VERSION_2, COMPRESS_OFF, FRAME_TYPE_CONTROL,
+      PROTOCOL_VERSION_3, COMPRESS_OFF, FRAME_TYPE_CONTROL,
       SERVICE_TYPE_NAVI, FRAME_DATA_SERVICE_DATA_ACK,
       session_id, 0, number_of_frames));
 
index 4917bec..c65a918 100644 (file)
@@ -128,7 +128,7 @@ RESULT_CODE ProtocolPacket::serializePacket(uint8_t version,
   packet_[offset++] = dataSize >> 8;
   packet_[offset++] = dataSize;
 
-  if (version == PROTOCOL_VERSION_2) {
+  if (version != PROTOCOL_VERSION_1) {
     packet_[offset++] = messageID >> 24;
     packet_[offset++] = messageID >> 16;
     packet_[offset++] = messageID >> 8;
@@ -204,7 +204,7 @@ RESULT_CODE ProtocolPacket::deserializePacket(const uint8_t* message,
   packet_header_.dataSize |= message[offset++] << 8u;
   packet_header_.dataSize |= message[offset++];
 
-  if (packet_header_.version == PROTOCOL_VERSION_2) {
+  if (packet_header_.version != PROTOCOL_VERSION_1) {
     packet_header_.messageId = message[offset++] << 24u;
     packet_header_.messageId |= message[offset++] << 16u;
     packet_header_.messageId |= message[offset++] << 8u;
index eefd428..c83ed14 100644 (file)
@@ -55,6 +55,7 @@ void Extract(utils::BitStream* bs, ProtocolPayloadHeaderV2* headerv2) {
     utils::Extract(bs, &rpc_type, kRpcTypeBits);
     headerv2->rpc_type = RpcTypeFromByte(rpc_type);
     if (headerv2->rpc_type == kRpcTypeReserved) {
+      printf("&&&&&&&");
       bs->MarkBad();
       return;
     }
index 10aab37..fc7f631 100644 (file)
@@ -56,8 +56,10 @@ RpcType RpcTypeFromByte(uint8_t byte) {
   RpcType type = RpcType(byte);
   bool supported_type = IsSupported(type);
   if (!supported_type) {
-    LOG4CXX_INFO(g_logger, "Invalid service type: "<<int32_t(byte))
+    LOG4CXX_INFO(g_logger, "Invalid service type RPCfromByte: "<<int32_t(byte));
   }
+
+  LOG4CXX_INFO(g_logger, "Service type RPCfromByte: "<<int32_t(byte));
   return supported_type ? type : kRpcTypeReserved;
 }
 
index 6bc4896..b7de276 100644 (file)
@@ -30,7 +30,7 @@ ServiceType ServiceTypeFromByte(uint8_t byte) {
   ServiceType type = ServiceType(byte);
   bool valid_type = IsValid(type);
   if (!valid_type) {
-    LOG4CXX_INFO(g_logger, "Invalid service type: "<<int32_t(byte))
+    LOG4CXX_INFO(g_logger, "Invalid service type RPCfromByte: "<<int32_t(byte))
   }
   return valid_type ? type : kInvalidServiceType;
 }