Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
TestDadaDB.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef SKA_CHEETAH_PSRDADA_TEST_UTILS_TESTDADADB_H
25 #define SKA_CHEETAH_PSRDADA_TEST_UTILS_TESTDADADB_H
26 
27 #include "dada_def.h"
28 #include "ipcbuf.h"
29 #include <mutex>
30 
31 namespace ska {
32 namespace cheetah {
33 namespace psrdada {
34 namespace test_utils {
35 
47 {
48  public:
58  TestDadaDB(uint64_t nbufs = DADA_DEFAULT_BLOCK_NUM,
59  uint64_t bufsz = DADA_DEFAULT_BLOCK_SIZE,
60  uint64_t nhdrs = IPCBUF_XFERS,
61  uint64_t hdrsz = DADA_DEFAULT_HEADER_SIZE);
62  TestDadaDB(TestDadaDB const&) = delete;
63  ~TestDadaDB();
64 
68  void create();
69 
73  void destroy();
74 
78  uint64_t num_data_buffers() const;
79 
83  uint64_t data_buffer_size() const;
84 
88  uint64_t num_header_buffers() const;
89 
93  uint64_t header_buffer_size() const;
94 
106  key_t key() const;
107 
108  protected:
109  void do_destroy();
110 
111  private:
112  uint64_t _nbufs;
113  uint64_t _bufsz;
114  uint64_t _nhdrs;
115  uint64_t _hdrsz;
116  key_t _dada_key;
117  ipcbuf_t _data_block;
118  ipcbuf_t _header;
119  bool _data_blocks_created;
120  bool _header_blocks_created;
121  std::mutex _lock;
122 };
123 
124 
125 } // namespace test_utils
126 } // namespace psrdada
127 } // namespace cheetah
128 } // namespace ska
129 
130 #endif // SKA_CHEETAH_PSRDADA_TEST_UTILS_TESTDADADB_H
uint64_t num_data_buffers() const
Return the number of data buffers.
Definition: TestDadaDB.cpp:138
void destroy()
Destroy the allocated shared memory blocks.
Definition: TestDadaDB.cpp:115
A mock class for implementing the interface of a DADA DB (Header/Data Unit)
Definition: TestDadaDB.h:46
uint64_t num_header_buffers() const
Return the number of header buffers.
Definition: TestDadaDB.cpp:148
uint64_t header_buffer_size() const
Return the size of each header buffer.
Definition: TestDadaDB.cpp:153
Some limits and constants for FLDO.
Definition: Brdz.h:35
TestDadaDB(uint64_t nbufs=DADA_DEFAULT_BLOCK_NUM, uint64_t bufsz=DADA_DEFAULT_BLOCK_SIZE, uint64_t nhdrs=IPCBUF_XFERS, uint64_t hdrsz=DADA_DEFAULT_HEADER_SIZE)
Constructa new TestDadaDB instance.
Definition: TestDadaDB.cpp:70
void create()
Create the data and header blocks in shared memory.
Definition: TestDadaDB.cpp:88
uint64_t data_buffer_size() const
Return the size of each data buffer.
Definition: TestDadaDB.cpp:143
key_t key() const
Return the hexidecimal shared memory key.
Definition: TestDadaDB.cpp:158