summaryrefslogtreecommitdiff
path: root/implementation/message
diff options
context:
space:
mode:
authorLutz Bichler <Lutz.Bichler@bmw.de>2014-07-01 09:08:45 +0200
committerLutz Bichler <Lutz.Bichler@bmw.de>2014-07-01 09:08:45 +0200
commita111a08e42a227fb61426b210e69c6369eb96fff (patch)
treed922faa3443c166c83bf8f173cc19804eeec46ea /implementation/message
parent7dba9c645ee7a310ddb2bbd0d722a892f3ae6e34 (diff)
downloadvSomeIP-a111a08e42a227fb61426b210e69c6369eb96fff.tar.gz
Initial commit of redesigned vsomeip libraries.
Diffstat (limited to 'implementation/message')
-rw-r--r--implementation/message/include/byteorder.hpp59
-rw-r--r--implementation/message/include/deserializer.hpp60
-rw-r--r--implementation/message/include/message_base_impl.hpp65
-rw-r--r--implementation/message/include/message_header_impl.hpp48
-rw-r--r--implementation/message/include/message_impl.hpp36
-rw-r--r--implementation/message/include/payload_impl.hpp44
-rw-r--r--implementation/message/include/payload_owner.hpp26
-rw-r--r--implementation/message/include/serializer.hpp49
-rw-r--r--implementation/message/src/deserializer.cpp197
-rw-r--r--implementation/message/src/message_base_impl.cpp105
-rw-r--r--implementation/message/src/message_header_impl.cpp81
-rw-r--r--implementation/message/src/message_impl.cpp42
-rw-r--r--implementation/message/src/payload_impl.cpp89
-rw-r--r--implementation/message/src/serializer.cpp118
14 files changed, 1019 insertions, 0 deletions
diff --git a/implementation/message/include/byteorder.hpp b/implementation/message/include/byteorder.hpp
new file mode 100644
index 0000000..ba04b61
--- /dev/null
+++ b/implementation/message/include/byteorder.hpp
@@ -0,0 +1,59 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_BYTEORDER_HPP
+#define VSOMEIP_BYTEORDER_HPP
+
+#if defined(LINUX)
+#include <endian.h>
+#elif defined(FREEBSD)
+#include <sys/endian.h>
+#else
+#error "Undefined OS (only Linux/FreeBSD are currently supported)"
+#endif
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+#define VSOMEIP_BYTES_TO_WORD(x0, x1) ((x0) << 8 | (x1))
+#define VSOMEIP_BYTES_TO_LONG(x0, x1, x2, x3) ((x0) << 24 | (x1) << 16 | (x2) << 8 | (x3))
+
+#define VSOMEIP_WORDS_TO_LONG(x0, x1) ((x0) << 16 | (x1))
+
+#define VSOMEIP_WORD_BYTE0(x) ((x) & 0xFF)
+#define VSOMEIP_WORD_BYTE1(x) ((x) >> 8)
+
+#define VSOMEIP_LONG_BYTE0(x) ((x) & 0xFF)
+#define VSOMEIP_LONG_BYTE1(x) (((x) >> 8) & 0xFF)
+#define VSOMEIP_LONG_BYTE2(x) (((x) >> 16) & 0xFF)
+#define VSOMEIP_LONG_BYTE3(x) (((x) >> 24) & 0xFF)
+
+#define VSOMEIP_LONG_WORD0(x) ((x) & 0xFFFF)
+#define VSOMEIP_LONG_WORD1(x) (((x) >> 16) & 0xFFFF)
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+#define VSOMEIP_BYTES_TO_WORD(x0, x1) ((x1) << 8 | (x0))
+#define VSOMEIP_BYTES_TO_LONG(x0, x1, x2, x3) ((x3) << 24 | (x2) << 16 | (x1) << 8 | (x0))
+
+#define VSOMEIP_WORD_BYTE0(x) ((x) >> 8)
+#define VSOMEIP_WORD_BYTE1(x) ((x) & 0xFF)
+
+#define VSOMEIP_LONG_BYTE0(x) (((x) >> 24) & 0xFF)
+#define VSOMEIP_LONG_BYTE1(x) (((x) >> 16) & 0xFF)
+#define VSOMEIP_LONG_BYTE2(x) (((x) >> 8) & 0xFF)
+#define VSOMEIP_LONG_BYTE3(x) ((x) & 0xFF)
+
+#define VSOMEIP_LONG_WORD0(x) ((((x) >> 16) & 0xFFFF)
+#define VSOMEIP_LONG_WORD1(x) (((x) & 0xFFFF)
+
+#else
+
+#error "__BYTE_ORDER is not defined!"
+
+#endif
+
+
+#endif // VSOMEIP_BYTEORDER_HPP
diff --git a/implementation/message/include/deserializer.hpp b/implementation/message/include/deserializer.hpp
new file mode 100644
index 0000000..871cbf4
--- /dev/null
+++ b/implementation/message/include/deserializer.hpp
@@ -0,0 +1,60 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_DESERIALIZER_HPP
+#define VSOMEIP_DESERIALIZER_HPP
+
+#include <vector>
+
+#include <vsomeip/primitive_types.hpp>
+
+namespace vsomeip {
+
+class message;
+
+class deserializer {
+public:
+ deserializer();
+ deserializer(uint8_t *_data, std::size_t _length);
+ deserializer(const deserializer& _other);
+ virtual ~deserializer();
+
+ void set_data(const uint8_t *_data, std::size_t _length);
+ void append_data(const uint8_t *_data, std::size_t _length);
+ void drop_data(std::size_t _length);
+
+ std::size_t get_available() const;
+ std::size_t get_remaining() const;
+ void set_remaining(std::size_t _length);
+
+ // to be used by applications to deserialize a message
+ message * deserialize_message();
+
+ // to be used (internally) by objects to deserialize their members
+ // Note: this needs to be encapsulated!
+ bool deserialize(uint8_t& _value);
+ bool deserialize(uint16_t& _value);
+ bool deserialize(uint32_t& _value, bool _omit_last_byte = false);
+ bool deserialize(uint8_t *_data, std::size_t _length);
+ bool deserialize(std::vector< uint8_t >& _value);
+
+ bool look_ahead(std::size_t _index, uint8_t &_value) const;
+ bool look_ahead(std::size_t _index, uint16_t &_value) const;
+ bool look_ahead(std::size_t _index, uint32_t &_value) const;
+
+ void reset();
+#ifdef VSOMEIP_DEBUG
+ void show_data() const;
+#endif
+protected:
+ std::vector< uint8_t > data_;
+ std::vector< uint8_t >::iterator position_;
+ std::size_t remaining_;
+};
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_DESERIALIZER_HPP
diff --git a/implementation/message/include/message_base_impl.hpp b/implementation/message/include/message_base_impl.hpp
new file mode 100644
index 0000000..4238168
--- /dev/null
+++ b/implementation/message/include/message_base_impl.hpp
@@ -0,0 +1,65 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_MESSAGE_BASE_IMPL_HPP
+#define VSOMEIP_MESSAGE_BASE_IMPL_HPP
+
+#include <boost/thread.hpp>
+
+#include <vsomeip/message.hpp>
+
+#include "message_header_impl.hpp"
+
+namespace vsomeip {
+
+class message_base_impl
+ : virtual public message_base {
+public:
+ message_base_impl();
+ virtual ~message_base_impl();
+
+ message_t get_message() const;
+ void set_message(message_t _message);
+
+ service_t get_service() const;
+ void set_service(service_t _service);
+
+ instance_t get_instance() const;
+ void set_instance(instance_t _instance);
+
+ method_t get_method() const;
+ void set_method(method_t _method);
+
+ request_t get_request() const;
+
+ client_t get_client() const;
+ void set_client(client_t _client);
+
+ session_t get_session() const;
+ void set_session(session_t _session);
+
+ protocol_version_t get_protocol_version() const;
+ void set_protocol_version(protocol_version_t _version);
+
+ interface_version_t get_interface_version() const;
+ void set_interface_version(interface_version_t _version);
+
+ message_type_e get_message_type() const;
+ void set_message_type(message_type_e _type);
+
+ return_code_e get_return_code() const;
+ void set_return_code(return_code_e _code);
+
+ message * get_owner() const;
+ void set_owner(message *_owner);
+
+protected: // members
+ message_header_impl header_;
+};
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_INTERNAL_MESSAGE_BASE_IMPL_HPP
diff --git a/implementation/message/include/message_header_impl.hpp b/implementation/message/include/message_header_impl.hpp
new file mode 100644
index 0000000..8d0507a
--- /dev/null
+++ b/implementation/message/include/message_header_impl.hpp
@@ -0,0 +1,48 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_MESSAGE_HEADER_IMPL_HPP
+#define VSOMEIP_MESSAGE_HEADER_IMPL_HPP
+
+#include <vsomeip/primitive_types.hpp>
+#include <vsomeip/enumeration_types.hpp>
+#include <vsomeip/serializable.hpp>
+
+namespace vsomeip {
+
+class message_base;
+
+class message_header_impl : virtual public serializable {
+
+public:
+ message_header_impl();
+ message_header_impl(const message_header_impl& header);
+
+ virtual bool serialize(serializer *_to) const;
+ virtual bool deserialize(deserializer *_from);
+
+ // internal
+ message_base * get_owner() const;
+ void set_owner(message_base *_owner);
+
+public:
+ service_t service_;
+ method_t method_;
+ length_t length_;
+ client_t client_;
+ session_t session_;
+ protocol_version_t protocol_version_;
+ interface_version_t interface_version_;
+ message_type_e type_;
+ return_code_e code_;
+
+ instance_t instance_;
+ message_base *owner_;
+};
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_MESSAGE_HEADER_IMPL_HPP
diff --git a/implementation/message/include/message_impl.hpp b/implementation/message/include/message_impl.hpp
new file mode 100644
index 0000000..0c1c636
--- /dev/null
+++ b/implementation/message/include/message_impl.hpp
@@ -0,0 +1,36 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_MESSAGE_IMPL_HPP
+#define VSOMEIP_MESSAGE_IMPL_HPP
+
+#include "message_base_impl.hpp"
+#include "payload_impl.hpp"
+
+namespace vsomeip {
+
+class message_impl
+ : virtual public message,
+ virtual public message_base_impl {
+public:
+ virtual ~message_impl();
+
+ length_t get_length() const;
+ void set_length(length_t _length);
+
+ payload & get_payload();
+ const payload & get_payload() const;
+
+ bool serialize(serializer *_to) const;
+ bool deserialize(deserializer *_from);
+
+protected: // members
+ payload_impl payload_;
+};
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_MESSAGE_IMPL_HPP
diff --git a/implementation/message/include/payload_impl.hpp b/implementation/message/include/payload_impl.hpp
new file mode 100644
index 0000000..79523bb
--- /dev/null
+++ b/implementation/message/include/payload_impl.hpp
@@ -0,0 +1,44 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_PAYLOAD_IMPL_HPP
+#define VSOMEIP_PAYLOAD_IMPL_HPP
+
+#include <vsomeip/payload.hpp>
+
+namespace vsomeip {
+
+class payload_owner;
+class serializer;
+class deserializer;
+
+class payload_impl : public payload {
+public:
+ payload_impl();
+ payload_impl(const payload_owner *_owner);
+ payload_impl(const payload_impl& _payload);
+ virtual ~payload_impl();
+
+ byte_t * get_data();
+ const byte_t * get_data() const;
+ length_t get_length() const;
+
+ void set_capacity(length_t _capacity);
+
+ void set_data(const byte_t *_data, length_t _length);
+ void set_data(const std::vector< byte_t > &_data);
+
+ bool serialize(serializer *_to) const;
+ bool deserialize(deserializer *_from);
+
+private:
+ std::vector< byte_t > data_;
+ const payload_owner *owner_;
+};
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_PAYLOAD_IMPL_HPP
diff --git a/implementation/message/include/payload_owner.hpp b/implementation/message/include/payload_owner.hpp
new file mode 100644
index 0000000..696bf64
--- /dev/null
+++ b/implementation/message/include/payload_owner.hpp
@@ -0,0 +1,26 @@
+//
+// payload_impl.hpp
+//
+// Author: Lutz Bichler
+//
+// This file is part of the BMW Some/IP implementation.
+//
+// Copyright © 2013, 2014 Bayerische Motoren Werke AG (BMW).
+// All rights reserved.
+//
+
+#ifndef VSOMEIP_INTERNAL_PAYLOAD_OWNER_HPP
+#define VSOMEIP_INTERNAL_PAYLOAD_OWNER_HPP
+
+namespace vsomeip {
+
+class payload_owner {
+public:
+ virtual ~payload_owner() {};
+
+ virtual void notify() const = 0;
+};
+
+}
+
+#endif // VSOMEIP_INTERNAL_PAYLOAD_OWNER_HPP
diff --git a/implementation/message/include/serializer.hpp b/implementation/message/include/serializer.hpp
new file mode 100644
index 0000000..96b2c97
--- /dev/null
+++ b/implementation/message/include/serializer.hpp
@@ -0,0 +1,49 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_SERIALIZER_HPP
+#define VSOMEIP_SERIALIZER_HPP
+
+#include <cstdint>
+#include <vector>
+
+namespace vsomeip {
+
+class serializable;
+
+class serializer
+{
+public:
+ serializer();
+ virtual ~serializer();
+
+ bool serialize(const serializable *_from);
+
+ bool serialize(const uint8_t _value);
+ bool serialize(const uint16_t _value);
+ bool serialize(const uint32_t _value, bool _omit_last_byte = false);
+ bool serialize(const uint8_t *_data, uint32_t _length);
+
+ virtual uint8_t * get_data() const;
+ virtual uint32_t get_capacity() const;
+ virtual uint32_t get_size() const;
+
+ virtual void create_data(uint32_t _capacity);
+ virtual void set_data(uint8_t *_data, uint32_t _capacity);
+
+ virtual void reset();
+
+private:
+ uint8_t *data_;
+ uint32_t capacity_;
+
+ uint8_t *position_;
+ uint32_t remaining_;
+};
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_SERIALIZER_IMPL_HPP
diff --git a/implementation/message/src/deserializer.cpp b/implementation/message/src/deserializer.cpp
new file mode 100644
index 0000000..ebd2793
--- /dev/null
+++ b/implementation/message/src/deserializer.cpp
@@ -0,0 +1,197 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <cstring>
+#include <iostream>
+
+#include "../include/byteorder.hpp"
+#include "../include/message_impl.hpp"
+#include "../include/deserializer.hpp"
+
+namespace vsomeip {
+
+deserializer::deserializer()
+ : position_(data_.begin()),
+ remaining_(0) {
+}
+
+deserializer::deserializer(uint8_t *_data, std::size_t _length)
+ : data_(_data, _data + _length),
+ position_(data_.begin()),
+ remaining_(_length) {
+}
+
+deserializer::deserializer(const deserializer &_other)
+ : data_(_other.data_),
+ position_(_other.position_){
+}
+
+deserializer::~deserializer() {
+}
+
+std::size_t deserializer::get_available() const {
+ return data_.size();
+}
+
+std::size_t deserializer::get_remaining() const {
+ return remaining_;
+}
+
+void deserializer::set_remaining(std::size_t _remaining) {
+ remaining_ = _remaining;
+}
+
+bool deserializer::deserialize(uint8_t& _value) {
+ if (0 == remaining_)
+ return false;
+
+ _value = *position_++;
+
+ remaining_--;
+ return true;
+}
+
+bool deserializer::deserialize(uint16_t& _value) {
+ if (2 > remaining_)
+ return false;
+
+ uint8_t byte0, byte1;
+ byte0 = *position_++;
+ byte1 = *position_++;
+ remaining_ -= 2;
+
+ _value = VSOMEIP_BYTES_TO_WORD(byte0, byte1);
+
+ return true;
+}
+
+bool deserializer::deserialize(uint32_t &_value, bool _omit_last_byte) {
+ if (3 > remaining_ || (!_omit_last_byte && 4 > remaining_))
+ return false;
+
+ uint8_t byte0 = 0, byte1, byte2, byte3;
+ if (!_omit_last_byte) {
+ byte0 = *position_++;
+ remaining_--;
+ }
+ byte1 = *position_++;
+ byte2 = *position_++;
+ byte3 = *position_++;
+ remaining_ -= 3;
+
+ _value = VSOMEIP_BYTES_TO_LONG(
+ byte0, byte1, byte2, byte3);
+
+ return true;
+}
+
+bool deserializer::deserialize(uint8_t *_data, std::size_t _length) {
+ if (_length > remaining_)
+ return false;
+
+ ::memcpy(_data, &_data[position_ - data_.begin()], _length);
+ position_ += _length;
+ remaining_ -= _length;
+
+ return true;
+}
+
+bool deserializer::deserialize(std::vector<uint8_t>& _value) {
+ if (_value.capacity() > remaining_)
+ return false;
+
+ _value.assign(position_, position_ + _value.capacity());
+ remaining_ -= _value.capacity();
+ position_ += _value.capacity();
+
+ return true;
+}
+
+bool deserializer::look_ahead(std::size_t _index, uint8_t &_value) const {
+ if (_index >= data_.size())
+ return false;
+
+ _value = *(position_ + _index);
+
+ return true;
+}
+
+bool deserializer::look_ahead(std::size_t _index, uint16_t &_value) const {
+ if (_index+1 >= data_.size())
+ return false;
+
+ std::vector< uint8_t >::iterator i = position_ + _index;
+ _value = VSOMEIP_BYTES_TO_WORD(*i, *(i+1));
+
+ return true;
+}
+
+bool deserializer::look_ahead(std::size_t _index, uint32_t &_value) const {
+ if (_index+3 >= data_.size())
+ return false;
+
+ std::vector< uint8_t >::const_iterator i = position_ + _index;
+ _value = VSOMEIP_BYTES_TO_LONG(*i, *(i+1), *(i+2), *(i+3));
+
+ return true;
+}
+
+message * deserializer::deserialize_message() {
+ message_impl* deserialized_message = new message_impl;
+ if (0 != deserialized_message) {
+ if (false == deserialized_message->deserialize(this)) {
+ delete deserialized_message;
+ deserialized_message = 0;
+ }
+ }
+
+ return deserialized_message;
+}
+
+void deserializer::set_data(const uint8_t *_data, std::size_t _length) {
+ if (0 != _data) {
+ data_.assign(_data, _data + _length);
+ position_ = data_.begin();
+ remaining_ = data_.end() - position_;
+ } else {
+ data_.clear();
+ position_ = data_.end();
+ remaining_ = 0;
+ }
+}
+
+void deserializer::append_data(const uint8_t *_data, std::size_t _length) {
+ std::size_t offset = (position_ - data_.begin());
+ data_.insert(data_.end(), _data, _data + _length);
+ position_ = data_.begin() + offset;
+ remaining_ += _length;
+}
+
+void deserializer::drop_data(std::size_t _length) {
+ if (position_ + _length < data_.end())
+ position_ += _length;
+ else
+ position_ = data_.end();
+}
+
+void deserializer::reset() {
+ data_.erase(data_.begin(), position_);
+ position_ = data_.begin();
+ remaining_ = data_.size();
+}
+
+#ifdef VSOMEIP_DEBUG
+void deserializer::show_data() const {
+ std::cout << "("
+ << std::hex << std::setw(2) << std::setfill('0') << (int)*position_ << ", "
+ << std:: dec << remaining_ << ") ";
+ for (int i = 0; i < data_.size(); ++i)
+ std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)data_[i] << " ";
+ std::cout << std::dec << std::endl;
+}
+#endif
+
+} // namespace vsomeip
diff --git a/implementation/message/src/message_base_impl.cpp b/implementation/message/src/message_base_impl.cpp
new file mode 100644
index 0000000..5bef55f
--- /dev/null
+++ b/implementation/message/src/message_base_impl.cpp
@@ -0,0 +1,105 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include "../include/byteorder.hpp"
+#include "../include/message_impl.hpp"
+
+namespace vsomeip {
+
+message_base_impl::message_base_impl() {
+ header_.set_owner(this);
+}
+
+message_base_impl::~message_base_impl() {
+};
+
+// header interface
+message_t message_base_impl::get_message() const {
+ return VSOMEIP_WORDS_TO_LONG(header_.service_, header_.method_);
+}
+
+void message_base_impl::set_message(message_t _message) {
+ header_.service_ = VSOMEIP_LONG_WORD0(_message);
+ header_.method_ = VSOMEIP_LONG_WORD1(_message);
+}
+
+service_t message_base_impl::get_service() const {
+ return header_.service_;
+}
+
+void message_base_impl::set_service(service_t _service) {
+ header_.service_ = _service;
+}
+
+instance_t message_base_impl::get_instance() const {
+ return header_.instance_;
+}
+
+void message_base_impl::set_instance(instance_t _instance) {
+ header_.instance_ = _instance;
+}
+
+method_t message_base_impl::get_method() const {
+ return header_.method_;
+}
+
+void message_base_impl::set_method(method_t _method) {
+ header_.method_ = _method;
+}
+
+request_t message_base_impl::get_request() const {
+ return VSOMEIP_WORDS_TO_LONG(header_.client_, header_.session_);
+}
+
+client_t message_base_impl::get_client() const {
+ return header_.client_;
+}
+
+void message_base_impl::set_client(client_t _client) {
+ header_.client_ = _client;
+}
+
+session_t message_base_impl::get_session() const {
+ return header_.session_;
+}
+
+void message_base_impl::set_session(session_t _session) {
+ header_.session_ = _session;
+}
+
+protocol_version_t message_base_impl::get_protocol_version() const {
+ return header_.protocol_version_;
+}
+
+void message_base_impl::set_protocol_version(protocol_version_t _protocol_version) {
+ header_.protocol_version_ = _protocol_version;
+}
+
+interface_version_t message_base_impl::get_interface_version() const {
+ return header_.interface_version_;
+}
+
+void message_base_impl::set_interface_version(interface_version_t _interface_version) {
+ header_.interface_version_ = _interface_version;
+}
+
+message_type_e message_base_impl::get_message_type() const {
+ return header_.type_;
+}
+
+void message_base_impl::set_message_type(message_type_e _type) {
+ header_.type_ = _type;
+}
+
+return_code_e message_base_impl::get_return_code() const {
+ return header_.code_;
+}
+
+void message_base_impl::set_return_code(return_code_e _code) {
+ header_.code_ = _code;
+}
+
+} // namespace vsomeip
diff --git a/implementation/message/src/message_header_impl.cpp b/implementation/message/src/message_header_impl.cpp
new file mode 100644
index 0000000..ce22920
--- /dev/null
+++ b/implementation/message/src/message_header_impl.cpp
@@ -0,0 +1,81 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <vsomeip/defines.hpp>
+
+#include "../include/message_base_impl.hpp"
+#include "../include/message_header_impl.hpp"
+#include "../include/serializer.hpp"
+#include "../include/deserializer.hpp"
+
+namespace vsomeip {
+
+message_header_impl::message_header_impl()
+ : service_(0x0), instance_(0x0), method_(0x0),
+ client_(0x0), session_(0x0),
+ protocol_version_(0x1), interface_version_(0x0),
+ type_(message_type_e::UNKNOWN),
+ code_(return_code_e::E_UNKNOWN) {
+};
+
+message_header_impl::message_header_impl(const message_header_impl& _header)
+ : service_(_header.service_), instance_(_header.instance_), method_(_header.method_),
+ client_(_header.client_), session_(_header.session_),
+ protocol_version_(_header.protocol_version_), interface_version_(_header.interface_version_),
+ type_(_header.type_),
+ code_(_header.code_) {
+};
+
+bool message_header_impl::serialize(serializer *_to) const {
+ return (0 != _to
+ && _to->serialize(service_)
+ && _to->serialize(method_)
+ && _to->serialize(owner_->get_length())
+ && _to->serialize(client_)
+ && _to->serialize(session_)
+ && _to->serialize(protocol_version_)
+ && _to->serialize(interface_version_)
+ && _to->serialize(static_cast<uint8_t>(type_))
+ && _to->serialize(static_cast<uint8_t>(code_)));
+};
+
+bool message_header_impl::deserialize(deserializer *_from) {
+ bool is_successful;
+
+ uint8_t tmp_message_type, tmp_return_code;
+ uint32_t tmp_length;
+
+ is_successful = (0 != _from
+ && _from->deserialize(service_)
+ && _from->deserialize(method_)
+ && _from->deserialize(tmp_length)
+ && _from->deserialize(client_)
+ && _from->deserialize(session_)
+ && _from->deserialize(protocol_version_)
+ && _from->deserialize(interface_version_)
+ && _from->deserialize(tmp_message_type)
+ && _from->deserialize(tmp_return_code));
+
+ if (is_successful) {
+ type_ = static_cast< message_type_e >(tmp_message_type);
+ code_ = static_cast< return_code_e >(tmp_return_code);
+ length_ = static_cast< length_t >(tmp_length - VSOMEIP_SOMEIP_HEADER_SIZE);
+ }
+
+ return is_successful;
+};
+
+message_base * message_header_impl::get_owner() const {
+ return owner_;
+}
+
+void message_header_impl::set_owner(message_base *_owner) {
+ owner_ = _owner;
+}
+
+} // namespace vsomeip
+
+
diff --git a/implementation/message/src/message_impl.cpp b/implementation/message/src/message_impl.cpp
new file mode 100644
index 0000000..8088192
--- /dev/null
+++ b/implementation/message/src/message_impl.cpp
@@ -0,0 +1,42 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <vsomeip/defines.hpp>
+
+#include "../include/byteorder.hpp"
+#include "../include/message_impl.hpp"
+
+namespace vsomeip {
+
+message_impl::~message_impl() {
+};
+
+length_t message_impl::get_length() const {
+ return VSOMEIP_SOMEIP_HEADER_SIZE + payload_.get_length();
+}
+
+payload & message_impl::get_payload() {
+ return payload_;
+}
+
+const payload & message_impl::get_payload() const {
+ return payload_;
+}
+
+bool message_impl::serialize(serializer *_to) const {
+ return (header_.serialize(_to) && payload_.serialize(_to));
+}
+
+bool message_impl::deserialize(deserializer *_from) {
+ bool is_successful = header_.deserialize(_from);
+ if (is_successful) {
+ payload_.set_capacity(header_.length_);
+ is_successful = payload_.deserialize(_from);
+ }
+ return is_successful;
+}
+
+} // namespace vsomeip
diff --git a/implementation/message/src/payload_impl.cpp b/implementation/message/src/payload_impl.cpp
new file mode 100644
index 0000000..ebcd692
--- /dev/null
+++ b/implementation/message/src/payload_impl.cpp
@@ -0,0 +1,89 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include "../include/deserializer.hpp"
+#include "../include/payload_impl.hpp"
+#include "../include/payload_owner.hpp"
+#include "../include/serializer.hpp"
+
+namespace vsomeip {
+
+payload_impl::payload_impl()
+ : data_(), owner_(0) {
+}
+
+payload_impl::payload_impl(const payload_owner *_owner)
+ : data_(), owner_(_owner) {
+}
+
+payload_impl::payload_impl(const payload_impl& _payload)
+ : data_(_payload.data_) {
+}
+
+payload_impl::~payload_impl() {
+}
+
+byte_t * payload_impl::get_data() {
+ return data_.data();
+}
+
+const byte_t * payload_impl::get_data() const {
+ return data_.data();
+}
+
+length_t payload_impl::get_length() const {
+ return data_.size();
+}
+
+void payload_impl::set_capacity(length_t _capacity) {
+ data_.reserve(_capacity);
+}
+
+void payload_impl::set_data(const byte_t *_data, const length_t _length) {
+ bool is_changed = false;
+ if (data_.size() != _length) {
+ is_changed = true;
+ } else {
+ for (std::size_t i = 0; i < _length; ++i) {
+ if (data_[i] != _data[i]) {
+ is_changed = true;
+ break;
+ }
+ }
+ }
+ data_.assign(_data, _data + _length);
+
+ if (is_changed && owner_)
+ owner_->notify();
+}
+
+void payload_impl::set_data(const std::vector< byte_t > &_data) {
+ bool is_changed = false;
+ if (data_.size() != _data.size()) {
+ is_changed = true;
+ } else {
+ for (std::size_t i = 0; i < _data.size(); ++i) {
+ if (data_[i] != _data[i]) {
+ is_changed = true;
+ break;
+ }
+ }
+ }
+ data_ = _data;
+
+ if (is_changed && owner_)
+ owner_->notify();
+}
+
+bool payload_impl::serialize(serializer *_to) const {
+ return (0 != _to && _to->serialize(data_.data(), data_.size()));
+}
+
+bool payload_impl::deserialize(deserializer *_from) {
+ return (0 != _from && _from->deserialize(data_));
+}
+
+} // namespace vsomeip
diff --git a/implementation/message/src/serializer.cpp b/implementation/message/src/serializer.cpp
new file mode 100644
index 0000000..d4784c0
--- /dev/null
+++ b/implementation/message/src/serializer.cpp
@@ -0,0 +1,118 @@
+// Copyright (C) 2014 BMW Group
+// Author: Lutz Bichler (lutz.bichler@bmw.de)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <cstring>
+
+#include <vsomeip/serializable.hpp>
+
+#include "../include/byteorder.hpp"
+#include "../include/serializer.hpp"
+
+namespace vsomeip {
+
+serializer::serializer()
+ : data_(0), capacity_(0), position_(0), remaining_(0) {
+}
+
+serializer::~serializer() {
+};
+
+bool serializer::serialize(const serializable *_from) {
+ return (_from && _from->serialize(this));
+}
+
+bool serializer::serialize(const uint8_t _value) {
+ if (1 > remaining_)
+ return false;
+
+ *position_++ = _value;
+ remaining_--;
+
+ return true;
+}
+
+bool serializer::serialize(const uint16_t _value) {
+ if (2 > remaining_)
+ return false;
+
+ *position_++ = VSOMEIP_WORD_BYTE1(_value);
+ *position_++ = VSOMEIP_WORD_BYTE0(_value);
+ remaining_ -= 2;
+
+ return true;
+}
+
+bool serializer::serialize(const uint32_t _value, bool _omit_last_byte) {
+ if (3 > remaining_ || (!_omit_last_byte && 4 > remaining_))
+ return false;
+
+ if (!_omit_last_byte) {
+ *position_++ = VSOMEIP_LONG_BYTE3(_value);
+ remaining_--;
+ }
+ *position_++ = VSOMEIP_LONG_BYTE2(_value);
+ *position_++ = VSOMEIP_LONG_BYTE1(_value);
+ *position_++ = VSOMEIP_LONG_BYTE0(_value);
+ remaining_ -= 3;
+
+ return true;
+}
+
+bool serializer::serialize(const uint8_t *_data, uint32_t _length) {
+ if (_length > remaining_)
+ return false;
+
+ ::memcpy(position_, _data, _length);
+ position_ += _length;
+ remaining_ -= _length;
+
+ return true;
+}
+
+uint8_t * serializer::get_data() const {
+ return data_;
+}
+
+uint32_t serializer::get_capacity() const {
+ return capacity_;
+}
+
+uint32_t serializer::get_size() const {
+ return capacity_ - remaining_;
+}
+
+void serializer::create_data(uint32_t _capacity) {
+ if (0 != data_)
+ delete [] data_;
+
+ data_ = new uint8_t[_capacity];
+ position_ = data_;
+ if (0 != data_) {
+ capacity_ = remaining_ = _capacity;
+ } else {
+ capacity_ = remaining_ = 0;
+ }
+}
+
+void serializer::set_data(uint8_t *_data, uint32_t _capacity) {
+ delete [] data_;
+
+ data_ = _data;
+ position_ = _data;
+
+ if (0 != data_) {
+ capacity_ = remaining_ = _capacity;
+ } else {
+ capacity_ = remaining_ = 0;
+ }
+}
+
+void serializer::reset() {
+ position_ = data_;
+ remaining_ = capacity_;
+}
+
+} // namespace vsomeip