nds2-client - Developer 0.16.7
Loading...
Searching...
No Matches
nds_parameter_block.hh
Go to the documentation of this file.
1/* -*- mode: C++ ; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
3#ifndef SWIG__COMMON__NDS_PARAMS_HH
4#define SWIG__COMMON__NDS_PARAMS_HH
5
6#include <string>
7#include <vector>
8#include <unordered_map>
9#include <memory>
10
11#include "nds_gap_handler.hh"
12#include "nds_connection.hh"
13
14namespace NDS
15{
16 namespace detail
17 {
23 bool str_to_bool( const std::string& input, bool& dest );
24
26 {
27 std::string name;
28 std::unique_ptr< gap_handler > handler;
29
31 : name( "ABORT_HANDLER" ),
32 handler(
33 NDS::detail::make_unique< detail::abort_gap_handler >( ) )
34 {
35 }
36 param_gap_handler( std::string handler_name,
37 std::unique_ptr< gap_handler > handler_ptr )
38 : name( std::move( handler_name ) ),
39 handler( std::move( handler_ptr ) )
40 {
41 }
43 : name( other.name ), handler( other.handler->clone( ) )
44 {
45 }
49 {
50 if ( this != &other )
51 {
52 std::unique_ptr< gap_handler > tmp(
53 other.handler->clone( ) );
54 name = other.name;
55 handler = std::move( tmp );
56 }
57 return *this;
58 }
60 ~param_gap_handler( ) = default;
61 };
62
64 {
65 NDS::connection::host_type hostname;
66 NDS::connection::port_type port;
67 NDS::connection::protocol_type protocol;
68
70 : hostname( "localhost" ),
71 port( NDS::connection::DEFAULT_PORT ),
72 protocol( NDS::connection::PROTOCOL_TRY )
73 {
74 }
75 param_net_conn_info( NDS::connection::host_type Hostname,
76 NDS::connection::port_type Port,
77 NDS::connection::protocol_type Protocol )
78 : hostname( std::move( Hostname ) ), port( Port ),
79 protocol( Protocol )
80 {
81 }
82 param_net_conn_info( const param_net_conn_info& other ) = default;
84 default;
85
87 operator=( const param_net_conn_info& other ) = default;
89 operator=( param_net_conn_info&& other ) = delete;
90 };
91
92 //-----------------------------------------------------------------
95 //-----------------------------------------------------------------
96
98 {
99 public:
102
103 parameter_block( const parameter_block& other ) = default;
104 parameter_block( parameter_block&& other ) = default;
105
107 operator=( const parameter_block& other ) = default;
109 operator=( parameter_block&& other ) noexcept = delete;
110
111 // Get the string representation of the given parameter, or ""
112 // if the parameter does not exist
113 std::string get( const std::string& parameter ) const;
114
115 // Set the string representation of a parameter
116 // @param[in] parameter - The name of the parameter to set
117 // @param[in] value - The string representation of the value
118 // @returns - true if the value could be set, else false
119 bool set( const std::string& parameter, const std::string& value );
120
121 // Return a sequence of strings listing all the parameters
122 // that can be set
123 //
124 // @returns std::vector<std::string> contianing parameter names
125 std::vector< std::string > parameters( ) const;
126
127 // Return the standard prefix that should be applied to
128 // the parameter name when reading it from the environment
129 std::string env_prefix( ) const;
130
131 // After how many commands should we cycle an nds1 connection
132 int
134 {
136 }
137
138 // Are requests allowed to read data from tape?
139 bool
141 {
142 return _allow_data_on_tape;
143 };
144
145 // Retrieve gap handler
146 std::unique_ptr< NDS::detail::gap_handler >
147 gap_handler( ) const
148 {
149 return _gap_handler.handler->clone( );
150 }
151
152 // Should iterate use the gap handler
153 bool
155 {
157 }
158
160
161 const param_net_conn_info& conn_info( ) const;
162
163 private:
169
170 bool set_gap_handler( const std::string& handler_str );
171 };
172
178 {
179 public:
181 : params_( params )
182 {
183 }
184 parameter_accessor( const parameter_accessor& other ) = default;
186
188 operator( )( ) const
189 {
190 return *( params_.p_ );
191 }
192
193 private:
195 };
196 }
197}
198
199#endif // SWIG__COMMON__NDS_PARAMS_HH
A connection to the NDS/NDS2 server.
Definition nds_connection.hh:515
The parameters class holds the configuration for a connection. This includes gap handling strategy an...
Definition nds_connection.hh:930
std::unique_ptr< detail::parameter_block > p_
Definition nds_connection.hh:1101
Definition nds_gap_handler.hh:123
A parameter_accessor allows internal code to access the detail::parameter_block in a NDS::connection:...
Definition nds_parameter_block.hh:178
parameter_accessor(parameter_accessor &&other)=delete
parameter_accessor(const parameter_accessor &other)=default
NDS::parameters & params_
Definition nds_parameter_block.hh:194
parameter_accessor(NDS::parameters &params)
Definition nds_parameter_block.hh:180
A parameter block describes parameters affecting the behavior of the NDS::connection.
Definition nds_parameter_block.hh:98
parameter_block(parameter_block &&other)=default
param_net_conn_info _net_conn_info
Definition nds_parameter_block.hh:168
bool set(const std::string &parameter, const std::string &value)
Definition nds_parameter_block.cc:358
std::string get(const std::string &parameter) const
Definition nds_parameter_block.cc:305
bool set_gap_handler(const std::string &handler_str)
Definition nds_parameter_block.cc:287
bool allow_data_on_tape() const
Definition nds_parameter_block.hh:140
parameter_block & operator=(parameter_block &&other) noexcept=delete
int _max_nds1_command_count
Definition nds_parameter_block.hh:164
bool _allow_data_on_tape
Definition nds_parameter_block.hh:165
bool iterate_uses_gap_handler() const
Definition nds_parameter_block.hh:154
bool _iterate_uses_gap_handler
Definition nds_parameter_block.hh:166
std::unique_ptr< NDS::detail::gap_handler > gap_handler() const
Definition nds_parameter_block.hh:147
parameter_block & operator=(const parameter_block &other)=default
parameter_block(const parameter_block &other)=default
int max_nds1_command_count() const
Definition nds_parameter_block.hh:133
param_gap_handler _gap_handler
Definition nds_parameter_block.hh:167
parameter_block()
Definition nds_parameter_block.cc:259
std::vector< std::string > parameters() const
Definition nds_parameter_block.cc:425
std::string env_prefix() const
Definition nds_parameter_block.cc:437
param_net_conn_info & conn_info()
Definition nds_parameter_block.cc:293
std::unique_ptr< T > make_unique(Ts &&... params)
Definition nds_memory.hh:24
bool str_to_bool(const std::string &input, bool &dest)
Given a std::string extract a boolean value.
Definition nds_parameter_block.cc:242
The NDS client namespace.
Definition debug_stream.cc:18
Definition nds_parameter_block.hh:26
param_gap_handler(std::string handler_name, std::unique_ptr< gap_handler > handler_ptr)
Definition nds_parameter_block.hh:36
param_gap_handler(param_gap_handler &&other)=default
param_gap_handler & operator=(const param_gap_handler &other)
Definition nds_parameter_block.hh:48
param_gap_handler()
Definition nds_parameter_block.hh:30
std::string name
Definition nds_parameter_block.hh:27
std::unique_ptr< gap_handler > handler
Definition nds_parameter_block.hh:28
param_gap_handler & operator=(param_gap_handler &&other)=default
param_gap_handler(const param_gap_handler &other)
Definition nds_parameter_block.hh:42
Definition nds_parameter_block.hh:64
param_net_conn_info & operator=(const param_net_conn_info &other)=default
param_net_conn_info(const param_net_conn_info &other)=default
NDS::connection::protocol_type protocol
Definition nds_parameter_block.hh:67
NDS::connection::host_type hostname
Definition nds_parameter_block.hh:65
NDS::connection::port_type port
Definition nds_parameter_block.hh:66
param_net_conn_info(param_net_conn_info &&other) noexcept=default
param_net_conn_info & operator=(param_net_conn_info &&other)=delete
param_net_conn_info()
Definition nds_parameter_block.hh:69
param_net_conn_info(NDS::connection::host_type Hostname, NDS::connection::port_type Port, NDS::connection::protocol_type Protocol)
Definition nds_parameter_block.hh:75