Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DadaWriteClient.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_DADAWRITECLIENT_H
25 #define SKA_CHEETAH_PSRDADA_DADAWRITECLIENT_H
26 
27 #include "cheetah/psrdada/DadaClientBase.h"
28 #include "cheetah/psrdada/detail/RawBytes.h"
29 #include "cheetah/psrdada/detail/RawBytesWriter.h"
30 #include <memory>
31 #include <cstddef>
32 
33 namespace ska {
34 namespace cheetah {
35 namespace psrdada {
36 
60 {
61  typedef std::function<void(std::ostream&)> NewSequenceCallback;
62 
63  public:
79  DadaWriteClient(key_t key, NewSequenceCallback const& new_sequence_callback);
80  DadaWriteClient(DadaWriteClient const&) = delete;
81  ~DadaWriteClient();
82 
96  template <typename Iterator, typename DataType=typename std::iterator_traits<Iterator>::value_type>
97  void write(Iterator& begin, Iterator const& end);
98 
106  void new_sequence();
107 
111  void write_eod();
112 
113  private:
114  void new_sequence_impl();
115  std::unique_ptr<detail::RawBytesWriter>& acquire_data_block();
116  void release_data_block();
117  void lock();
118  void unlock();
119  void reset();
120 
121  private:
122  NewSequenceCallback _new_sequence_callback;
123  std::unique_ptr<detail::RawBytes> _current_block;
124  std::unique_ptr<detail::RawBytesWriter> _current_writer;
125  bool _locked;
126 };
127 
128 } // namespace psrdada
129 } // namespace cheetah
130 } // namespace ska
131 
132 #include "cheetah/psrdada/detail/DadaWriteClient.cpp"
133 
134 #endif // SKA_CHEETAH_PSRDADA_DADAWRITECLIENT_H
Class that provides means for writing to a DADA ring buffer.
void new_sequence()
Start a new writing sequence in the buffer.
A general base class for DADA readers and writers.
Some limits and constants for FLDO.
Definition: Brdz.h:35
void write(Iterator &begin, Iterator const &end)
Write to the data ring buffer.
DadaWriteClient(key_t key, NewSequenceCallback const &new_sequence_callback)
Instatiate new DadaWriteClient.
void write_eod()
: Write an EOD marker without writing a next header