nds2-client - User 0.16.7
Loading...
Searching...
No Matches
nds_parameter_block.hh
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
25 struct param_gap_handler
26 {
27 std::string name;
28 std::unique_ptr< gap_handler > handler;
29
30 param_gap_handler( )
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 }
42 param_gap_handler( const param_gap_handler& other )
43 : name( other.name ), handler( other.handler->clone( ) )
44 {
45 }
46 param_gap_handler( param_gap_handler&& other ) = default;
47 param_gap_handler&
48 operator=( const param_gap_handler& other )
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 }
59 param_gap_handler& operator=( param_gap_handler&& other ) = default;
60 ~param_gap_handler( ) = default;
61 };
62
63 struct param_net_conn_info
64 {
68
69 param_net_conn_info( )
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;
83 param_net_conn_info( param_net_conn_info&& other ) noexcept =
84 default;
85
86 param_net_conn_info&
87 operator=( const param_net_conn_info& other ) = default;
88 param_net_conn_info&
89 operator=( param_net_conn_info&& other ) = delete;
90 };
91
92 //-----------------------------------------------------------------
95 //-----------------------------------------------------------------
96
97 class parameter_block
98 {
99 public:
100 parameter_block( );
101 explicit parameter_block( const param_net_conn_info& conn_info );
102
103 parameter_block( const parameter_block& other ) = default;
104 parameter_block( parameter_block&& other ) = default;
105
106 parameter_block&
107 operator=( const parameter_block& other ) = default;
108 parameter_block&
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
133 max_nds1_command_count( ) const
134 {
135 return _max_nds1_command_count;
136 }
137
138 // Are requests allowed to read data from tape?
139 bool
140 allow_data_on_tape( ) const
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
154 iterate_uses_gap_handler( ) const
155 {
156 return _iterate_uses_gap_handler;
157 }
158
159 param_net_conn_info& conn_info( );
160
161 const param_net_conn_info& conn_info( ) const;
162
163 private:
164 int _max_nds1_command_count;
165 bool _allow_data_on_tape;
166 bool _iterate_uses_gap_handler;
167 param_gap_handler _gap_handler;
168 param_net_conn_info _net_conn_info;
169
170 bool set_gap_handler( const std::string& handler_str );
171 };
172
177 class parameter_accessor
178 {
179 public:
180 explicit parameter_accessor( NDS::parameters& params )
181 : params_( params )
182 {
183 }
184 parameter_accessor( const parameter_accessor& other ) = default;
185 parameter_accessor( parameter_accessor&& other ) = delete;
186
187 parameter_block&
188 operator( )( ) const
189 {
190 return *( params_.p_ );
191 }
192
193 private:
194 NDS::parameters& params_;
195 };
196 }
197}
198
199#endif // SWIG__COMMON__NDS_PARAMS_HH
protocol_type
Connection constants.
Definition nds_connection.hh:605
int port_type
Host port number type.
Definition nds_connection.hh:613
std::string host_type
Host name type.
Definition nds_connection.hh:612
The parameters class holds the configuration for a connection. This includes gap handling strategy an...
Definition nds_connection.hh:930
The NDS client namespace.
Definition debug_stream.cc:18