25 #ifndef SWIG__COMMON__NDS_CONNECTION_HH
26 #define SWIG__COMMON__NDS_CONNECTION_HH
116 #include "nds_export.hh"
117 #include "nds_buffer.hh"
118 #include "nds_channel.hh"
119 #include "nds_data_iterator.hh"
120 #include "nds_availability.hh"
121 #include "nds_epoch.hh"
128 class parameter_block;
129 class parameter_accessor;
131 inline namespace abi_0
136 struct frequency_range
138 NDS::channel::sample_rate_type
140 NDS::channel::sample_rate_type
144 : minimum( NDS::channel::MIN_SAMPLE_RATE ),
145 maximum( NDS::channel::MAX_SAMPLE_RATE )
148 frequency_range( NDS::channel::sample_rate_type Min,
149 NDS::channel::sample_rate_type Max )
150 : minimum( Min ), maximum( Max )
153 frequency_range(
const frequency_range& other ) =
default;
155 operator=(
const frequency_range& other ) =
default;
168 class channel_predicate_object
171 typedef std::vector< NDS::channel::channel_type > channel_type_list;
172 typedef std::vector< NDS::channel::data_type > data_type_list;
174 channel_predicate_object( )
175 : epoch_(
"", 0, NDS::buffer::GPS_INF ), glob_( ),
176 channel_types_( ), data_types_( ), sample_rates_( )
180 channel_predicate_object(
const channel_predicate_object& other ) =
183 channel_predicate_object( channel_predicate_object&& other ) =
186 channel_predicate_object&
187 operator=(
const channel_predicate_object& other ) =
default;
189 channel_predicate_object&
190 operator=( channel_predicate_object&& other ) =
default;
196 return ( glob_.empty( ) ?
"*" : glob_ );
202 const channel_type_list
203 channel_types( )
const
206 if ( channel_types_.empty( ) )
208 channel_type_list result{ all_channel_types };
211 return channel_types_;
216 NDS::channel::channel_type
217 channel_type_mask( )
const
219 if ( channel_types_.empty( ) )
221 return NDS::channel::DEFAULT_CHANNEL_MASK;
223 NDS::channel::channel_type result;
224 for (
const NDS::channel::channel_type val : channel_types_ )
226 result = ( NDS::channel::channel_type )( result | val );
237 if ( data_types_.empty( ) )
239 data_type_list result{ all_data_types };
247 NDS::channel::data_type
248 data_type_mask( )
const
250 if ( data_types_.empty( ) )
252 return NDS::channel::DEFAULT_DATA_MASK;
254 NDS::channel::data_type result;
255 for (
const NDS::channel::data_type val : data_types_ )
257 result = ( NDS::channel::data_type )( result | val );
266 const frequency_range&
267 sample_rates( )
const
269 return sample_rates_;
274 NDS::channel::sample_rate_type
275 min_sample_rate( )
const
277 return sample_rates_.minimum;
282 NDS::channel::sample_rate_type
283 max_sample_rate( )
const
285 return sample_rates_.maximum;
298 NDS::buffer::gps_second_type
301 return epoch_.gps_start;
306 NDS::buffer::gps_second_type
309 return epoch_.gps_stop;
317 channel_predicate_object&
318 set( std::string val )
320 glob_ = std::move( val );
330 set_glob( std::string val )
342 channel_predicate_object&
343 set( NDS::channel::channel_type val )
346 for (
auto entry : all_channel_types )
347 if ( (
int)entry | (
int)val )
349 channel_types_.push_back( val );
361 set_channel_type_mask( NDS::channel::channel_type val )
373 channel_predicate_object&
374 set( NDS::channel::data_type val )
376 for (
auto entry : all_data_types )
378 if ( (
int)entry | (
int)val )
380 data_types_.push_back( val );
392 set_data_type_mask( NDS::channel::data_type val )
402 channel_predicate_object&
403 set( frequency_range val )
416 NDS::channel::sample_rate_type min_sample_rate,
417 NDS::channel::sample_rate_type max_sample_rate )
419 frequency_range range( min_sample_rate, max_sample_rate );
427 channel_predicate_object&
441 set_timespan( NDS::buffer::gps_second_type gps_start,
442 NDS::buffer::gps_second_type gps_stop )
444 NDS::epoch e(
"", gps_start, gps_stop );
449 DLL_EXPORT
const static data_type_list all_data_types;
450 DLL_EXPORT
const static channel_type_list all_channel_types;
454 channel_type_list channel_types_;
455 data_type_list data_types_;
456 frequency_range sample_rates_;
460 build_channel_predicate( channel_predicate_object& pred )
464 template <
typename T >
466 build_channel_predicate( channel_predicate_object& pred, T val )
471 template <
typename T,
typename... Args >
473 build_channel_predicate( channel_predicate_object& pred,
478 build_channel_predicate( pred, args... );
491 template <
typename... Args >
492 channel_predicate_object
493 channel_predicate( Args... args )
495 channel_predicate_object pred;
496 build_channel_predicate( pred, args... );
520 class error :
public std::runtime_error
524 error(
const std::string& What,
int ErrNo = 0 );
530 class already_closed_error :
public error
534 already_closed_error( );
541 class minute_trend_error :
public error
545 minute_trend_error( );
551 class transfer_busy_error :
public error
555 transfer_busy_error( );
561 class unexpected_channels_received_error :
public error
565 unexpected_channels_received_error( );
571 class daq_error :
public error
575 explicit daq_error(
int daq_code );
578 daq_error(
int daq_code,
579 const std::string& additional_information );
582 daq_error(
int daq_code,
const char* additional_information );
597 static std::string format(
int DAQCode,
598 const char* extra =
nullptr );
606 PROTOCOL_INVALID = -1,
612 typedef std::string host_type;
613 typedef int port_type;
614 typedef size_t count_type;
619 typedef channel::channel_names_type channel_names_type;
620 typedef std::vector< std::string > parameters_type;
622 static const port_type DEFAULT_PORT =
629 connection( ) =
delete;
640 explicit connection(
const host_type& host,
641 port_type port = DEFAULT_PORT,
642 protocol_type protocol = PROTOCOL_TRY );
653 explicit connection(
const NDS::parameters& params );
658 connection(
const NDS::connection& other ) =
delete;
663 connection& operator=(
const NDS::connection& other ) =
delete;
719 count_type count_channels(
const channel_predicate_object& pred );
759 DLL_EXPORT channels_type
760 find_channels(
const channel_predicate_object& pred );
773 DLL_EXPORT epochs_type get_epochs( );
789 DLL_EXPORT availability_list_type
790 get_availability(
const epoch& time_span,
791 const channel_names_type& channel_names );
808 DLL_EXPORT
bool check( buffer::gps_second_type gps_start,
809 buffer::gps_second_type gps_stop,
810 const channel_names_type& channel_names );
830 DLL_EXPORT buffers_type
831 fetch( buffer::gps_second_type gps_start,
832 buffer::gps_second_type gps_stop,
833 const channel_names_type& channel_names );
840 DLL_EXPORT NDS::parameters& parameters( )
const;
853 DLL_EXPORT
const channel::hash_type& hash( )
const;
904 DLL_EXPORT NDS::data_iterable
905 iterate( NDS::request_period period,
906 const channel_names_type& channel_names );
915 DLL_EXPORT
bool request_in_progress( )
const;
918 std::shared_ptr< detail::conn_p_type > p_;
921 DLL_EXPORT
extern std::ostream& operator<<( std::ostream& os,
922 const connection& conn );
932 DLL_EXPORT parameters( );
933 DLL_EXPORT
explicit parameters(
934 const connection::host_type& host,
935 connection::port_type port = connection::DEFAULT_PORT,
936 connection::protocol_type protocol = connection::PROTOCOL_TRY );
938 DLL_EXPORT parameters(
const parameters& other );
939 DLL_EXPORT parameters( parameters&& other ) noexcept;
941 DLL_EXPORT parameters& operator=( const parameters& other );
942 DLL_EXPORT parameters& operator=( parameters&& other ) noexcept;
944 DLL_EXPORT ~parameters( );
950 DLL_EXPORT connection::host_type host( ) const;
956 DLL_EXPORT connection::port_type port( ) const;
961 DLL_EXPORT connection::protocol_type protocol( ) const;
974 DLL_EXPORT std::
string get( const std::
string& key ) const;
1089 DLL_EXPORT
bool set( const std::
string& key,
1090 const std::
string& value );
1097 DLL_EXPORT connection::parameters_type parameter_list( ) const;
1100 friend class NDS::detail::parameter_accessor;
1101 std::unique_ptr< detail::parameter_block > p_;