Kinetic C/C++ Client
 All Classes Functions Variables Pages
threadsafe_nonblocking_kinetic_connection.cc
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 #include "kinetic/threadsafe_nonblocking_connection.h"
22 #include <mutex>
23 
24 namespace kinetic {
25 
26 using std::shared_ptr;
27 using std::string;
28 
29 ThreadsafeNonblockingKineticConnection::ThreadsafeNonblockingKineticConnection(
30  unique_ptr<NonblockingKineticConnection> connection) {
31  connection_ = std::move(connection);
32 }
33 
34 ThreadsafeNonblockingKineticConnection::~ThreadsafeNonblockingKineticConnection() {
35 }
36 
37 bool ThreadsafeNonblockingKineticConnection::Run(fd_set *read_fds, fd_set *write_fds, int *nfds) {
38  std::lock_guard<std::recursive_mutex> guard(mutex_);
39  return connection_->Run(read_fds, write_fds, nfds);
40 }
41 
42 bool ThreadsafeNonblockingKineticConnection::RemoveHandler(HandlerKey handler_key) {
43  std::lock_guard<std::recursive_mutex> guard(mutex_);
44  return connection_->RemoveHandler(handler_key);
45 }
46 
47 void ThreadsafeNonblockingKineticConnection::SetClientClusterVersion(int64_t cluster_version) {
48  std::lock_guard<std::recursive_mutex> guard(mutex_);
49  return connection_->SetClientClusterVersion(cluster_version);
50 }
51 
52 HandlerKey ThreadsafeNonblockingKineticConnection::NoOp(const shared_ptr<SimpleCallbackInterface> callback) {
53  std::lock_guard<std::recursive_mutex> guard(mutex_);
54  return connection_->NoOp(callback);
55 }
56 
57 HandlerKey ThreadsafeNonblockingKineticConnection::Get(const shared_ptr<const string> key, const shared_ptr<GetCallbackInterface> callback) {
58  std::lock_guard<std::recursive_mutex> guard(mutex_);
59  return connection_->Get(key, callback);
60 }
61 
62 HandlerKey ThreadsafeNonblockingKineticConnection::Get(const string key, const shared_ptr<GetCallbackInterface> callback) {
63  std::lock_guard<std::recursive_mutex> guard(mutex_);
64  return connection_->Get(key, callback);
65 }
66 
67 
68 HandlerKey ThreadsafeNonblockingKineticConnection::GetNext(const string key, const shared_ptr<GetCallbackInterface> callback){
69  std::lock_guard<std::recursive_mutex> guard(mutex_);
70  return connection_->GetNext(key, callback);
71 }
72 
73 HandlerKey ThreadsafeNonblockingKineticConnection::GetNext(const shared_ptr<const string> key,
74  const shared_ptr<GetCallbackInterface> callback) {
75  std::lock_guard<std::recursive_mutex> guard(mutex_);
76  return connection_->GetNext(key, callback);
77 }
78 
79 HandlerKey ThreadsafeNonblockingKineticConnection::GetPrevious(const shared_ptr<const string> key,
80  const shared_ptr<GetCallbackInterface> callback) {
81  std::lock_guard<std::recursive_mutex> guard(mutex_);
82  return connection_->GetPrevious(key, callback);
83 }
84 
85 HandlerKey ThreadsafeNonblockingKineticConnection::GetPrevious(const string key, const shared_ptr<GetCallbackInterface> callback){
86  std::lock_guard<std::recursive_mutex> guard(mutex_);
87  return connection_->GetPrevious(key, callback);
88 }
89 
90 HandlerKey ThreadsafeNonblockingKineticConnection::GetVersion(const string key, const shared_ptr<GetVersionCallbackInterface> callback){
91  std::lock_guard<std::recursive_mutex> guard(mutex_);
92  return connection_->GetVersion(key, callback);
93 }
94 
95 HandlerKey ThreadsafeNonblockingKineticConnection::GetVersion(const shared_ptr<const string> key,
96  const shared_ptr<GetVersionCallbackInterface> callback) {
97  std::lock_guard<std::recursive_mutex> guard(mutex_);
98  return connection_->GetVersion(key, callback);
99 }
100 
101 HandlerKey ThreadsafeNonblockingKineticConnection::GetKeyRange(
102  const shared_ptr<const string> start_key,
103  bool start_key_inclusive,
104  const shared_ptr<const string> end_key,
105  bool end_key_inclusive,
106  bool reverse_results,
107  int32_t max_results,
108  const shared_ptr<GetKeyRangeCallbackInterface> callback) {
109  std::lock_guard<std::recursive_mutex> guard(mutex_);
110  return connection_->GetKeyRange(start_key, start_key_inclusive, end_key,
111  end_key_inclusive, reverse_results, max_results, callback);
112 }
113 
114 HandlerKey ThreadsafeNonblockingKineticConnection::GetKeyRange(const string start_key, bool start_key_inclusive,
115  const string end_key, bool end_key_inclusive,
116  bool reverse_results, int32_t max_results, const shared_ptr<GetKeyRangeCallbackInterface> callback){
117  std::lock_guard<std::recursive_mutex> guard(mutex_);
118  return connection_->GetKeyRange(start_key, start_key_inclusive, end_key,
119  end_key_inclusive, reverse_results, max_results, callback);
120 }
121 
122 HandlerKey ThreadsafeNonblockingKineticConnection::Put(const shared_ptr<const string> key, const shared_ptr<const string> current_version, WriteMode mode,
123  const shared_ptr<const KineticRecord> record, const shared_ptr<PutCallbackInterface> callback){
124  std::lock_guard<std::recursive_mutex> guard(mutex_);
125  return connection_->Put(key, current_version, mode, record, callback);
126 }
127 HandlerKey ThreadsafeNonblockingKineticConnection::Put(const string key, const string current_version, WriteMode mode,
128  const shared_ptr<const KineticRecord> record, const shared_ptr<PutCallbackInterface> callback){
129  std::lock_guard<std::recursive_mutex> guard(mutex_);
130  return connection_->Put(key, current_version, mode, record, callback);
131 }
132 HandlerKey ThreadsafeNonblockingKineticConnection::Put(const shared_ptr<const string> key, const shared_ptr<const string> current_version, WriteMode mode,
133  const shared_ptr<const KineticRecord> record, const shared_ptr<PutCallbackInterface> callback,
134  PersistMode persistMode){
135  std::lock_guard<std::recursive_mutex> guard(mutex_);
136  return connection_->Put(key, current_version, mode, record, callback, persistMode);
137 }
138 HandlerKey ThreadsafeNonblockingKineticConnection::Put(const string key, const string current_version, WriteMode mode,
139  const shared_ptr<const KineticRecord> record, const shared_ptr<PutCallbackInterface> callback,
140  PersistMode persistMode){
141  std::lock_guard<std::recursive_mutex> guard(mutex_);
142  return connection_->Put(key, current_version, mode, record, callback, persistMode);
143 }
144 
145 HandlerKey ThreadsafeNonblockingKineticConnection::Delete(const shared_ptr<const string> key, const shared_ptr<const string> version, WriteMode mode,
146  const shared_ptr<SimpleCallbackInterface> callback, PersistMode persistMode){
147  std::lock_guard<std::recursive_mutex> guard(mutex_);
148  return connection_->Delete(key, version, mode, callback, persistMode);
149 }
150 HandlerKey ThreadsafeNonblockingKineticConnection::Delete(const string key, const string version, WriteMode mode,
151  const shared_ptr<SimpleCallbackInterface> callback, PersistMode persistMode){
152  std::lock_guard<std::recursive_mutex> guard(mutex_);
153  return connection_->Delete(key, version, mode, callback, persistMode);
154 }
155 HandlerKey ThreadsafeNonblockingKineticConnection::Delete(const shared_ptr<const string> key, const shared_ptr<const string> version, WriteMode mode,
156  const shared_ptr<SimpleCallbackInterface> callback){
157  std::lock_guard<std::recursive_mutex> guard(mutex_);
158  return connection_->Delete(key, version, mode, callback);
159 }
160 HandlerKey ThreadsafeNonblockingKineticConnection::Delete(const string key, const string version, WriteMode mode,
161  const shared_ptr<SimpleCallbackInterface> callback){
162  std::lock_guard<std::recursive_mutex> guard(mutex_);
163  return connection_->Delete(key, version, mode, callback);
164 }
165 
166 HandlerKey ThreadsafeNonblockingKineticConnection::InstantErase(const string pin, const shared_ptr<SimpleCallbackInterface> callback){
167  std::lock_guard<std::recursive_mutex> guard(mutex_);
168  return connection_->InstantErase(pin, callback);
169 }
170 HandlerKey ThreadsafeNonblockingKineticConnection::InstantErase(const shared_ptr<string> pin,
171  const shared_ptr<SimpleCallbackInterface> callback) {
172  std::lock_guard<std::recursive_mutex> guard(mutex_);
173  return connection_->InstantErase(pin, callback);
174 }
175 
176 HandlerKey ThreadsafeNonblockingKineticConnection::SecureErase(const string pin, const shared_ptr<SimpleCallbackInterface> callback){
177  std::lock_guard<std::recursive_mutex> guard(mutex_);
178  return connection_->SecureErase(pin, callback);
179 }
180 HandlerKey ThreadsafeNonblockingKineticConnection::SecureErase(const shared_ptr<string> pin,
181  const shared_ptr<SimpleCallbackInterface> callback) {
182  std::lock_guard<std::recursive_mutex> guard(mutex_);
183  return connection_->SecureErase(pin, callback);
184 }
185 
186 HandlerKey ThreadsafeNonblockingKineticConnection::SetClusterVersion(int64_t new_cluster_version,
187  const shared_ptr<SimpleCallbackInterface> callback) {
188  std::lock_guard<std::recursive_mutex> guard(mutex_);
189  return connection_->SetClusterVersion(new_cluster_version, callback);
190 }
191 
192 HandlerKey ThreadsafeNonblockingKineticConnection::GetLog(
193  const shared_ptr<GetLogCallbackInterface> callback) {
194  std::lock_guard<std::recursive_mutex> guard(mutex_);
195  return connection_->GetLog(callback);
196 }
197 HandlerKey ThreadsafeNonblockingKineticConnection::GetLog(const vector<Command_GetLog_Type>& types,
198  const shared_ptr<GetLogCallbackInterface> callback) {
199  std::lock_guard<std::recursive_mutex> guard(mutex_);
200  return connection_->GetLog(types, callback);
201 }
202 
203 HandlerKey ThreadsafeNonblockingKineticConnection::UpdateFirmware(
204  const shared_ptr<const string> new_firmware,
205  const shared_ptr<SimpleCallbackInterface> callback) {
206  std::lock_guard<std::recursive_mutex> guard(mutex_);
207  return connection_->UpdateFirmware(new_firmware, callback);
208 }
209 
210 HandlerKey ThreadsafeNonblockingKineticConnection::SetACLs(const shared_ptr<const list<ACL>> acls,
211  const shared_ptr<SimpleCallbackInterface> callback) {
212  std::lock_guard<std::recursive_mutex> guard(mutex_);
213  return connection_->SetACLs(acls, callback);
214 }
215 
216 HandlerKey ThreadsafeNonblockingKineticConnection::SetErasePIN(const shared_ptr<const string> new_pin,
217  const shared_ptr<const string> current_pin,
218  const shared_ptr<SimpleCallbackInterface> callback) {
219  std::lock_guard<std::recursive_mutex> guard(mutex_);
220  return connection_->SetErasePIN(new_pin, current_pin, callback);
221 }
222 
223 HandlerKey ThreadsafeNonblockingKineticConnection::SetErasePIN(const string new_pin, const string current_pin, const shared_ptr<SimpleCallbackInterface> callback) {
224  std::lock_guard<std::recursive_mutex> guard(mutex_);
225  return connection_->SetErasePIN(new_pin, current_pin, callback);
226 }
227 
228 HandlerKey ThreadsafeNonblockingKineticConnection::LockDevice(const string pin, const shared_ptr<SimpleCallbackInterface> callback){
229  std::lock_guard<std::recursive_mutex> guard(mutex_);
230  return connection_->LockDevice(pin, callback);
231 }
232 HandlerKey ThreadsafeNonblockingKineticConnection::LockDevice(const shared_ptr<string> pin,
233  const shared_ptr<SimpleCallbackInterface> callback) {
234  std::lock_guard<std::recursive_mutex> guard(mutex_);
235  return connection_->LockDevice(pin, callback);
236 }
237 
238 HandlerKey ThreadsafeNonblockingKineticConnection::UnlockDevice(const string pin, const shared_ptr<SimpleCallbackInterface> callback){
239  std::lock_guard<std::recursive_mutex> guard(mutex_);
240  return connection_->UnlockDevice(pin, callback);
241 }
242 HandlerKey ThreadsafeNonblockingKineticConnection::UnlockDevice(const shared_ptr<string> pin,
243  const shared_ptr<SimpleCallbackInterface> callback) {
244  std::lock_guard<std::recursive_mutex> guard(mutex_);
245  return connection_->UnlockDevice(pin, callback);
246 }
247 
248 HandlerKey ThreadsafeNonblockingKineticConnection::SetLockPIN(const shared_ptr<const string> new_pin,
249  const shared_ptr<const string> current_pin,
250  const shared_ptr<SimpleCallbackInterface> callback) {
251  std::lock_guard<std::recursive_mutex> guard(mutex_);
252  return connection_->SetLockPIN(new_pin, current_pin, callback);
253 }
254 
255 HandlerKey ThreadsafeNonblockingKineticConnection::SetLockPIN(const string new_pin, const string current_pin, const shared_ptr<SimpleCallbackInterface> callback) {
256  std::lock_guard<std::recursive_mutex> guard(mutex_);
257  return connection_->SetLockPIN(new_pin, current_pin, callback);
258 }
259 
260 HandlerKey ThreadsafeNonblockingKineticConnection::P2PPush(
261  const shared_ptr<const P2PPushRequest> push_request,
262  const shared_ptr<P2PPushCallbackInterface> callback) {
263  std::lock_guard<std::recursive_mutex> guard(mutex_);
264  return connection_->P2PPush(push_request, callback);
265 }
266 
267 HandlerKey ThreadsafeNonblockingKineticConnection::P2PPush(const P2PPushRequest& push_request,
268  const shared_ptr<P2PPushCallbackInterface> callback) {
269  std::lock_guard<std::recursive_mutex> guard(mutex_);
270  return connection_->P2PPush(push_request, callback);
271 }
272 
273 
274 
275 } // namespace kinetic