• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 
6 #include "../include/load_balancing_option_impl.hpp"
7 #include "../../message/include/deserializer.hpp"
8 #include "../../message/include/serializer.hpp"
9 
10 namespace vsomeip_v3 {
11 namespace sd {
12 
load_balancing_option_impl()13 load_balancing_option_impl::load_balancing_option_impl() {
14     length_ = 1 + 2 + 2;
15     type_ = option_type_e::LOAD_BALANCING;
16     priority_ = 0;
17     weight_ = 0;
18 }
19 
~load_balancing_option_impl()20 load_balancing_option_impl::~load_balancing_option_impl() {
21 }
22 
23 bool
operator ==(const option_impl & _other) const24 load_balancing_option_impl::operator ==(const option_impl &_other) const {
25     bool is_equal(option_impl::operator ==(_other));
26 
27     if (is_equal) {
28         const load_balancing_option_impl &its_other
29             = dynamic_cast<const load_balancing_option_impl &>(_other);
30         is_equal = (priority_ == its_other.priority_
31             && priority_ == its_other.weight_);
32     }
33 
34     return is_equal;
35 }
36 
get_priority() const37 priority_t load_balancing_option_impl::get_priority() const {
38     return priority_;
39 }
40 
set_priority(priority_t _priority)41 void load_balancing_option_impl::set_priority(priority_t _priority) {
42     priority_ = _priority;
43 }
44 
get_weight() const45 weight_t load_balancing_option_impl::get_weight() const {
46     return weight_;
47 }
48 
set_weight(weight_t _weight)49 void load_balancing_option_impl::set_weight(weight_t _weight) {
50     weight_ = _weight;
51 }
52 
serialize(vsomeip_v3::serializer * _to) const53 bool load_balancing_option_impl::serialize(vsomeip_v3::serializer *_to) const {
54     bool is_successful = option_impl::serialize(_to);
55     is_successful = is_successful
56             && _to->serialize(static_cast<uint16_t>(priority_));
57     is_successful = is_successful
58             && _to->serialize(static_cast<uint16_t>(weight_));
59     return is_successful;
60 }
61 
deserialize(vsomeip_v3::deserializer * _from)62 bool load_balancing_option_impl::deserialize(vsomeip_v3::deserializer *_from) {
63     bool is_successful = option_impl::deserialize(_from);
64 
65     uint16_t tmp_priority = 0;
66     is_successful = is_successful && _from->deserialize(tmp_priority);
67     priority_ = static_cast<priority_t>(tmp_priority);
68 
69     uint16_t tmp_weight = 0;
70     is_successful = is_successful && _from->deserialize(tmp_weight);
71     weight_ = static_cast<weight_t>(tmp_weight);
72 
73     return is_successful;
74 }
75 
76 } // namespace sd
77 } // namespace vsomeip_v3
78