1 // Copyright (C) 2020 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 #ifndef VSOMEIP_V3_E2E_PROFILE04_PROTECTOR_HPP
7 #define VSOMEIP_V3_E2E_PROFILE04_PROTECTOR_HPP
8 
9 #include <mutex>
10 #include "../profile04/profile_04.hpp"
11 #include "../profile_interface/protector.hpp"
12 
13 namespace vsomeip_v3 {
14 namespace e2e {
15 namespace profile04 {
16 
17 class protector final : public e2e::profile_interface::protector {
18 public:
19     protector(void) = delete;
20 
protector(const profile_config & _config)21     explicit protector(const profile_config &_config)
22         : config_(_config), counter_(0) {};
23 
24     void protect(e2e_buffer &_buffer, instance_t _instance) override final;
25 
26 private:
27     bool verify_inputs(e2e_buffer &_buffer);
28     void increment_counter();
29 
30     void write_16(e2e_buffer &_buffer, uint16_t _data, size_t _index);
31     void write_32(e2e_buffer &_buffer, uint32_t _data, size_t _index);
32 
33 private:
34     profile_config config_;
35     uint16_t counter_;
36     std::mutex protect_mutex_;
37 };
38 
39 } // namespace profile_04
40 } // namespace e2e
41 } // namespace vsomeip_v3
42 
43 #endif // VSOMEIP_V3_E2E_PROFILE04_PROTECTOR_HPP
44