summaryrefslogtreecommitdiff
path: root/src/components/protocol
diff options
context:
space:
mode:
authorJustin Dickow <jjdickow@gmail.com>2014-10-20 17:44:41 -0400
committerJustin Dickow <jjdickow@gmail.com>2014-10-20 17:44:41 -0400
commit34e7256493ff0e6594029b9857d7e2aa31f5dbeb (patch)
tree367306b507c52d3af211533810adbc22004e0192 /src/components/protocol
parent2eef966e9b5fd4d94dd98820095eb765e200c64b (diff)
downloadsdl_core-34e7256493ff0e6594029b9857d7e2aa31f5dbeb.tar.gz
SDL 3.8!
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Diffstat (limited to 'src/components/protocol')
-rw-r--r--src/components/protocol/CMakeLists.txt14
-rw-r--r--src/components/protocol/src/message_priority.cc59
-rw-r--r--src/components/protocol/src/raw_message.cc91
-rw-r--r--src/components/protocol/src/rpc_type.cc86
-rw-r--r--src/components/protocol/src/service_type.cc71
5 files changed, 321 insertions, 0 deletions
diff --git a/src/components/protocol/CMakeLists.txt b/src/components/protocol/CMakeLists.txt
new file mode 100644
index 0000000000..2459bbc493
--- /dev/null
+++ b/src/components/protocol/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories(
+ ./include
+ ${APR_INCLUDE_DIRECTORY}
+)
+
+set(SOURCES
+ ./src/raw_message.cc
+ ./src/service_type.cc
+ ./src/message_priority.cc
+ ./src/rpc_type.cc
+)
+
+add_library(ProtocolLibrary ${SOURCES})
+target_link_libraries(ProtocolLibrary Utils)
diff --git a/src/components/protocol/src/message_priority.cc b/src/components/protocol/src/message_priority.cc
new file mode 100644
index 0000000000..d76cde038c
--- /dev/null
+++ b/src/components/protocol/src/message_priority.cc
@@ -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.
+ */
+
+#include "protocol/message_priority.h"
+
+#include "protocol/service_type.h"
+#include "utils/macro.h"
+
+namespace protocol_handler {
+
+// static
+const MessagePriority MessagePriority::kDefault = MessagePriority(0);
+
+// static
+MessagePriority MessagePriority::FromServiceType(ServiceType service_type) {
+ size_t message_priority_value = size_t(service_type);
+ DCHECK(message_priority_value <= 0xFF);
+ // According to Applink Protocol Specification v5 service with numerically
+ // lower service type identifiers have higher priority
+ return MessagePriority(0xFF - service_type);
+}
+
+MessagePriority::MessagePriority(const MessagePriority& that)
+ : value_(that.value_) {
+}
+
+size_t MessagePriority::OrderingValue() const {
+ return value_;
+}
+} // namespace protocol_handler
diff --git a/src/components/protocol/src/raw_message.cc b/src/components/protocol/src/raw_message.cc
new file mode 100644
index 0000000000..348eb16199
--- /dev/null
+++ b/src/components/protocol/src/raw_message.cc
@@ -0,0 +1,91 @@
+/*
+ * 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/raw_message.h"
+
+#include <memory.h>
+
+namespace protocol_handler {
+
+RawMessage::RawMessage(uint32_t connection_key, uint32_t protocol_version,
+ const uint8_t *const data_param, uint32_t data_sz,
+ uint8_t type, uint32_t payload_size)
+ : connection_key_(connection_key),
+ data_(NULL),
+ data_size_(data_sz),
+ protocol_version_(protocol_version),
+ service_type_(ServiceTypeFromByte(type)),
+ payload_size_(payload_size),
+ waiting_(false) {
+ if (data_sz > 0) {
+ data_ = new uint8_t[data_sz];
+ memcpy(data_, data_param, sizeof(*data_) * data_sz);
+ }
+}
+
+RawMessage::~RawMessage() {
+ delete[] data_;
+}
+
+uint32_t RawMessage::connection_key() const {
+ return connection_key_;
+}
+
+void RawMessage::set_connection_key(uint32_t key) {
+ connection_key_ = key;
+}
+
+uint8_t *RawMessage::data() const {
+ return data_;
+}
+
+size_t RawMessage::payload_size() const {
+ return payload_size_;
+}
+
+size_t RawMessage::data_size() const {
+ return data_size_;
+}
+
+uint32_t RawMessage::protocol_version() const {
+ return protocol_version_;
+}
+
+bool RawMessage::IsWaiting() const {
+ return waiting_;
+}
+
+void RawMessage::set_waiting(bool v) {
+ waiting_ = v;
+}
+
+} // namespace protocol_handler
diff --git a/src/components/protocol/src/rpc_type.cc b/src/components/protocol/src/rpc_type.cc
new file mode 100644
index 0000000000..ce8ab898f5
--- /dev/null
+++ b/src/components/protocol/src/rpc_type.cc
@@ -0,0 +1,86 @@
+/*
+ * 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/rpc_type.h"
+
+#include "utils/logger.h"
+#include "utils/macro.h"
+
+namespace protocol_handler {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "ProtocolHandler")
+
+namespace {
+bool IsSupported(RpcType rpc_type) {
+ switch (rpc_type) {
+ case kRpcTypeRequest:
+ case kRpcTypeResponse:
+ case kRpcTypeNotification:
+ return true;
+ default:
+ return false;
+ }
+}
+} // namespace
+
+RpcType RpcTypeFromByte(uint8_t byte) {
+ RpcType type = RpcType(byte);
+ bool supported_type = IsSupported(type);
+ if (!supported_type) {
+ LOG4CXX_INFO(logger_, "Invalid service type: " << int32_t(byte));
+ }
+
+ return supported_type ? type : kRpcTypeReserved;
+}
+
+uint8_t RpcTypeToByte(RpcType type) {
+ DCHECK(IsSupported(type));
+ return uint8_t(type);
+}
+
+const char *RpcTypeToString(RpcType type) {
+ switch (type) {
+ case kRpcTypeRequest:
+ return "kRpcTypeRequest";
+ case kRpcTypeResponse:
+ return "kRpcTypeResponse";
+ case kRpcTypeNotification:
+ return "kRpcTypeNotification";
+ default:
+ return "kRpcTypeReserved";
+ }
+}
+
+std::ostream &operator<<(std::ostream &os, RpcType rpc_type) {
+ return os << RpcTypeToString(rpc_type);
+}
+} // namespace protocol_handler
diff --git a/src/components/protocol/src/service_type.cc b/src/components/protocol/src/service_type.cc
new file mode 100644
index 0000000000..09adae23be
--- /dev/null
+++ b/src/components/protocol/src/service_type.cc
@@ -0,0 +1,71 @@
+/*
+ * 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/service_type.h"
+
+#include "utils/logger.h"
+#include "utils/macro.h"
+
+namespace protocol_handler {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "ConnectionHandler")
+
+namespace {
+// Check if provided service value is one of the specified
+bool IsValid(ServiceType service_type) {
+ switch (service_type) {
+ case kControl:
+ case kRpc:
+ case kAudio:
+ case kMobileNav:
+ case kBulk:
+ return true;
+ default:
+ return false;
+ }
+}
+} // namespace
+
+ServiceType ServiceTypeFromByte(uint8_t byte) {
+ ServiceType type = ServiceType(byte);
+ const bool valid_type = IsValid(type);
+ if (!valid_type) {
+ LOG4CXX_INFO(logger_, "Invalid service type: "<< int32_t(byte));
+ }
+ return valid_type ? type : kInvalidServiceType;
+}
+
+uint8_t ServiceTypeToByte(ServiceType type) {
+ DCHECK(IsValid(type));
+ return uint8_t(type);
+}
+
+} // namespace protocol_handler