$darkmode
rdb_transceiver_shm.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
23 #pragma once
24 
25 #include <memory> // for unique_ptr<>
26 #include <vector> // for vector<>
27 
28 #include <boost/interprocess/mapped_region.hpp> // for mapped_region
29 
30 #include <cloe/core.hpp> // for Json
31 
32 #include "rdb_transceiver.hpp" // for RdbTransceiver
33 
34 namespace vtd {
35 
48  public:
57  RdbTransceiverShm(key_t key, uint32_t release_mask);
58 
59  virtual ~RdbTransceiverShm();
60 
61  bool has() const override {
62  throw std::runtime_error("RdbTransceiverShm: has not implemented yet");
63  }
64 
65  std::vector<std::shared_ptr<RDB_MSG_t>> receive() override;
66 
67  void send(const RDB_MSG_t*, size_t) override {
68  throw std::runtime_error("RdbTransceiverShm: send not implemented");
69  }
70 
71  void to_json(cloe::Json& j) const override {
72  j = cloe::Json{
73  {"connection_endpoint", "shm://unknown-key"},
74  {"num_errors", this->num_errors_},
75  {"num_messages", this->num_messages_},
76  };
77  }
78 
79  friend void to_json(cloe::Json& j, const RdbTransceiverShm& t) { t.to_json(j); }
80 
81  protected:
83  uint32_t release_mask_;
84 
86  boost::interprocess::mapped_region region_;
87 
89  RDB_SHM_HDR_t* rdb_shm_hdr_{nullptr};
90 
92  RDB_SHM_BUFFER_INFO_t** buffer_info_{nullptr};
93 
95  RDB_MSG_t** rdb_msg_{nullptr};
96 
97  // Hold on to some cheap statistics for the JSON representation.
98  uint64_t num_errors_{0};
99  uint64_t num_messages_{0};
100 };
101 
102 } // namespace vtd
Definition: rdb_transceiver_shm.hpp:47
void send(const RDB_MSG_t *, size_t) override
Definition: rdb_transceiver_shm.hpp:67
RDB_SHM_BUFFER_INFO_t ** buffer_info_
Array of pointers to buffer information.
Definition: rdb_transceiver_shm.hpp:92
RdbTransceiverShm(key_t key, uint32_t release_mask)
Definition: rdb_transceiver_shm.cpp:44
bool has() const override
Definition: rdb_transceiver_shm.hpp:61
std::vector< std::shared_ptr< RDB_MSG_t > > receive() override
Definition: rdb_transceiver_shm.cpp:90
RDB_MSG_t ** rdb_msg_
Array of pointers to rdb messages.
Definition: rdb_transceiver_shm.hpp:95
uint32_t release_mask_
VTD uses this mask to notify client when data in buffer is ready.
Definition: rdb_transceiver_shm.hpp:83
boost::interprocess::mapped_region region_
Shared memory region.
Definition: rdb_transceiver_shm.hpp:86
RDB_SHM_HDR_t * rdb_shm_hdr_
Pointer to the shared memory management header.
Definition: rdb_transceiver_shm.hpp:89
Definition: rdb_transceiver.hpp:59