Kinetic C/C++ Client
 All Classes Functions Variables Pages
nonblocking_kinetic_connection_interface.h
1 /*
2  * kinetic-cpp-client
3  * Copyright (C) 2014 Seagate Technology.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #ifndef NONBLOCKING_KINETIC_CONNECTION_INTERFACE_H_
22 #define NONBLOCKING_KINETIC_CONNECTION_INTERFACE_H_
23 
24 #include "kinetic/common.h"
25 #include "kinetic_client.pb.h"
26 #include "kinetic/kinetic_record.h"
27 #include "kinetic/drive_log.h"
28 #include "kinetic/acls.h"
29 #include "kinetic/kinetic_connection.h"
30 #include "kinetic/kinetic_status.h"
31 #include "kinetic/nonblocking_packet_service_interface.h"
32 #include <memory>
33 #include <string>
34 #include <vector>
35 #include <list>
36 
37 namespace kinetic {
38 
39 using com::seagate::kinetic::client::proto::Command;
40 using com::seagate::kinetic::client::proto::Command_MessageType;
41 using com::seagate::kinetic::client::proto::Command_P2POperation;
42 using com::seagate::kinetic::client::proto::Command_Synchronization;
43 using com::seagate::kinetic::client::proto::Command_GetLog_Type;
44 
45 using std::shared_ptr;
46 using std::unique_ptr;
47 using std::string;
48 using std::make_shared;
49 using std::list;
50 using std::vector;
51 
52 // SimpleCallbackInterface is used for operations that return success or an
53 // error but do not otherwise return a result.
55  public:
56  virtual ~SimpleCallbackInterface() {}
57  virtual void Success() = 0;
58  virtual void Failure(KineticStatus error) = 0;
59 };
60 
62  public:
63  explicit SimpleHandler(const shared_ptr<SimpleCallbackInterface> callback);
64  void Handle(const Command &response, unique_ptr<const string> value);
65  void Error(KineticStatus error, Command const * const response);
66 
67  private:
68  const shared_ptr<SimpleCallbackInterface> callback_;
69  DISALLOW_COPY_AND_ASSIGN(SimpleHandler);
70 };
71 
73  public:
74  virtual ~GetCallbackInterface() {}
75  virtual void Success(const std::string &key, std::unique_ptr<KineticRecord> record) = 0;
76  virtual void Failure(KineticStatus error) = 0;
77 };
78 
79 class GetHandler : public HandlerInterface {
80  public:
81  explicit GetHandler(const shared_ptr<GetCallbackInterface> callback);
82  void Handle(const Command &response, unique_ptr<const string> value);
83  void Error(KineticStatus error, Command const * const response);
84 
85  private:
86  const shared_ptr<GetCallbackInterface> callback_;
87  DISALLOW_COPY_AND_ASSIGN(GetHandler);
88 };
89 
91  public:
92  virtual ~GetVersionCallbackInterface() {}
93  virtual void Success(const std::string &version) = 0;
94  virtual void Failure(KineticStatus error) = 0;
95 };
96 
98  public:
99  explicit GetVersionHandler(const shared_ptr<GetVersionCallbackInterface> callback);
100  void Handle(const Command &response, unique_ptr<const string> value);
101  void Error(KineticStatus error, Command const * const response);
102 
103  private:
104  const shared_ptr<GetVersionCallbackInterface> callback_;
105  DISALLOW_COPY_AND_ASSIGN(GetVersionHandler);
106 };
107 
109  public:
110  virtual ~GetKeyRangeCallbackInterface() {}
111  virtual void Success(unique_ptr<vector<string>> keys) = 0;
112  virtual void Failure(KineticStatus error) = 0;
113 };
114 
116  public:
117  explicit GetKeyRangeHandler(const shared_ptr<GetKeyRangeCallbackInterface> callback);
118  void Handle(const Command &response, unique_ptr<const string> value);
119  void Error(KineticStatus error, Command const * const response);
120 
121  private:
122  const shared_ptr<GetKeyRangeCallbackInterface> callback_;
123  DISALLOW_COPY_AND_ASSIGN(GetKeyRangeHandler);
124 };
125 
127  public:
128  virtual ~PutCallbackInterface() {}
129  virtual void Success() = 0;
130  virtual void Failure(KineticStatus error) = 0;
131 };
132 
133 
134 class PutHandler : public HandlerInterface {
135  public:
136  explicit PutHandler(const shared_ptr<PutCallbackInterface> callback);
137  void Handle(const Command &response, unique_ptr<const string> value);
138  void Error(KineticStatus error, Command const * const response);
139 
140  private:
141  const shared_ptr<PutCallbackInterface> callback_;
142  DISALLOW_COPY_AND_ASSIGN(PutHandler);
143 };
144 
146  public:
147  virtual ~GetLogCallbackInterface() {}
148  virtual void Success(unique_ptr<DriveLog> drive_log) = 0;
149  virtual void Failure(KineticStatus error) = 0;
150 };
151 
153  public:
154  explicit GetLogHandler(const shared_ptr<GetLogCallbackInterface> callback);
155  void Handle(const Command& response, unique_ptr<const string> value);
156  void Error(KineticStatus error, Command const * const response);
157 
158  private:
159  const shared_ptr<GetLogCallbackInterface> callback_;
160  DISALLOW_COPY_AND_ASSIGN(GetLogHandler);
161 };
162 
164  public:
165  virtual ~P2PPushCallbackInterface() {}
166  virtual void Success(unique_ptr<vector<KineticStatus>> operation_statuses, const Command& response) = 0;
167  virtual void Failure(KineticStatus error, Command const * const response) = 0;
168 };
169 
171  public:
172  explicit P2PPushHandler(const shared_ptr<P2PPushCallbackInterface> callback);
173  void Handle(const Command& response, unique_ptr<const string> value);
174  void Error(KineticStatus error, Command const * const response);
175 
176  private:
177  const shared_ptr<P2PPushCallbackInterface> callback_;
178  DISALLOW_COPY_AND_ASSIGN(P2PPushHandler);
179 };
180 
181 struct P2PPushRequest;
182 
186  string key;
187 
190  string version;
191 
194  string newKey;
195 
197  bool force;
198 
203  shared_ptr<P2PPushRequest> request;
204 };
205 
209  string host;
210 
212  int port;
213 
215  vector<P2PPushOperation> operations;
216 };
217 
219 
220 public:
222  virtual void SetClientClusterVersion(int64_t cluster_version) = 0;
223  virtual bool Run(fd_set *read_fds, fd_set *write_fds, int *nfds) = 0;
224  virtual bool RemoveHandler(HandlerKey handler_key) = 0;
225 
226  virtual HandlerKey NoOp(const shared_ptr<SimpleCallbackInterface> callback) = 0;
227  virtual HandlerKey Get(const string key, const shared_ptr<GetCallbackInterface> callback) = 0;
228  virtual HandlerKey Get(const shared_ptr<const string> key,
229  const shared_ptr<GetCallbackInterface> callback) = 0;
230  virtual HandlerKey GetNext(const shared_ptr<const string> key,
231  const shared_ptr<GetCallbackInterface> callback) = 0;
232  virtual HandlerKey GetNext(const string key,
233  const shared_ptr<GetCallbackInterface> callback) = 0;
234  virtual HandlerKey GetPrevious(const shared_ptr<const string> key,
235  const shared_ptr<GetCallbackInterface> callback) = 0;
236  virtual HandlerKey GetPrevious(const string key,
237  const shared_ptr<GetCallbackInterface> callback) = 0;
238  virtual HandlerKey GetVersion(const shared_ptr<const string> key,
239  const shared_ptr<GetVersionCallbackInterface> callback) = 0;
240  virtual HandlerKey GetVersion(const string key,
241  const shared_ptr<GetVersionCallbackInterface> callback) = 0;
242  virtual HandlerKey GetKeyRange(const shared_ptr<const string> start_key,
243  bool start_key_inclusive,
244  const shared_ptr<const string> end_key,
245  bool end_key_inclusive,
246  bool reverse_results,
247  int32_t max_results,
248  const shared_ptr<GetKeyRangeCallbackInterface> callback) = 0;
249  virtual HandlerKey GetKeyRange(const string start_key,
250  bool start_key_inclusive,
251  const string end_key,
252  bool end_key_inclusive,
253  bool reverse_results,
254  int32_t max_results,
255  const shared_ptr<GetKeyRangeCallbackInterface> callback) = 0;
256  virtual HandlerKey Put(const shared_ptr<const string> key,
257  const shared_ptr<const string> current_version, WriteMode mode,
258  const shared_ptr<const KineticRecord> record,
259  const shared_ptr<PutCallbackInterface> callback) = 0;
260  virtual HandlerKey Put(const string key,
261  const string current_version, WriteMode mode,
262  const shared_ptr<const KineticRecord> record,
263  const shared_ptr<PutCallbackInterface> callback) = 0;
264  virtual HandlerKey Put(const shared_ptr<const string> key,
265  const shared_ptr<const string> current_version, WriteMode mode,
266  const shared_ptr<const KineticRecord> record,
267  const shared_ptr<PutCallbackInterface> callback,
268  PersistMode persistMode) = 0;
269  virtual HandlerKey Put(const string key,
270  const string current_version, WriteMode mode,
271  const shared_ptr<const KineticRecord> record,
272  const shared_ptr<PutCallbackInterface> callback,
273  PersistMode persistMode) = 0;
274  virtual HandlerKey Delete(const shared_ptr<const string> key,
275  const shared_ptr<const string> version, WriteMode mode,
276  const shared_ptr<SimpleCallbackInterface> callback, PersistMode persistMode) = 0;
277  virtual HandlerKey Delete(const string key, const string version, WriteMode mode,
278  const shared_ptr<SimpleCallbackInterface> callback, PersistMode persistMode) = 0;
279  virtual HandlerKey Delete(const shared_ptr<const string> key,
280  const shared_ptr<const string> version, WriteMode mode,
281  const shared_ptr<SimpleCallbackInterface> callback) = 0;
282  virtual HandlerKey Delete(const string key, const string version, WriteMode mode,
283  const shared_ptr<SimpleCallbackInterface> callback) = 0;
284  virtual HandlerKey P2PPush(const P2PPushRequest& push_request,
285  const shared_ptr<P2PPushCallbackInterface> callback) = 0;
286  virtual HandlerKey P2PPush(const shared_ptr<const P2PPushRequest> push_request,
287  const shared_ptr<P2PPushCallbackInterface> callback) = 0;
288  virtual HandlerKey GetLog(const shared_ptr<GetLogCallbackInterface> callback) = 0;
289  virtual HandlerKey GetLog(const vector<Command_GetLog_Type>& types,
290  const shared_ptr<GetLogCallbackInterface> callback) = 0;
291 
292  virtual HandlerKey UpdateFirmware(const shared_ptr<const string> new_firmware,
293  const shared_ptr<SimpleCallbackInterface> callback) = 0;
294  virtual HandlerKey SetClusterVersion(int64_t new_cluster_version,
295  const shared_ptr<SimpleCallbackInterface> callback) = 0;
296 
297  virtual HandlerKey SetACLs(const shared_ptr<const list<ACL>> acls,
298  const shared_ptr<SimpleCallbackInterface> callback) = 0;
299  virtual HandlerKey SetErasePIN(const shared_ptr<const string> new_pin,
300  const shared_ptr<const string> current_pin,
301  const shared_ptr<SimpleCallbackInterface> callback) = 0;
302  virtual HandlerKey SetErasePIN(const string new_pin,
303  const string current_pin,
304  const shared_ptr<SimpleCallbackInterface> callback) = 0;
305  virtual HandlerKey SetLockPIN(const shared_ptr<const string> new_pin,
306  const shared_ptr<const string> current_pin,
307  const shared_ptr<SimpleCallbackInterface> callback) = 0;
308  virtual HandlerKey SetLockPIN(const string new_pin,
309  const string current_pin,
310  const shared_ptr<SimpleCallbackInterface> callback) = 0;
311 
312  virtual HandlerKey InstantErase(const shared_ptr<string> pin,
313  const shared_ptr<SimpleCallbackInterface> callback) = 0;
314  virtual HandlerKey InstantErase(const string pin,
315  const shared_ptr<SimpleCallbackInterface> callback) = 0;
316  virtual HandlerKey SecureErase(const shared_ptr<string> pin,
317  const shared_ptr<SimpleCallbackInterface> callback) = 0;
318  virtual HandlerKey SecureErase(const string pin,
319  const shared_ptr<SimpleCallbackInterface> callback) = 0;
320  virtual HandlerKey LockDevice(const shared_ptr<string> pin,
321  const shared_ptr<SimpleCallbackInterface> callback) = 0;
322  virtual HandlerKey LockDevice(const string pin,
323  const shared_ptr<SimpleCallbackInterface> callback) = 0;
324  virtual HandlerKey UnlockDevice(const shared_ptr<string> pin,
325  const shared_ptr<SimpleCallbackInterface> callback) = 0;
326  virtual HandlerKey UnlockDevice(const string pin,
327  const shared_ptr<SimpleCallbackInterface> callback) = 0;
328 
329 };
330 
331 } // namespace kinetic
332 
333 
334 
335 #endif
Represents a collection of P2P operations.
vector< P2PPushOperation > operations
Operations to perform against the drive specified above.
Represents a single P2P copy operation.
string newKey
Optionally specify that the key should be copied to a different key on the remote drive...
shared_ptr< P2PPushRequest > request
P2P operations to execute on the drive specified in the request. This lets you set up a pipeline of P...
bool force
Ignore version on the remote drive. The same as specifying force with a regular put.
Indicates whether a Kinetic operation (get, put, security, etc) put succeeded or failed. Unlike Status it provides details like whether the failure resulted from a version or an HMAC error.
string host
Host/IP address of the target drive.
string version
The expected version on the remote peer. The same as specifying a version with a regular put...