Kinetic C/C++ Client
 All Classes Functions Variables Pages
nonblocking_packet_sender.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 KINETIC_CPP_CLIENT_NONBLOCKING_PACKET_SENDER_H_
22 #define KINETIC_CPP_CLIENT_NONBLOCKING_PACKET_SENDER_H_
23 
24 #include <sys/select.h>
25 #include <cstdint>
26 
27 #include <queue>
28 #include <unordered_map>
29 #include <glog/logging.h>
30 
31 #include "gmock/gmock.h"
32 
33 #include "kinetic/nonblocking_packet_service_interface.h"
34 #include "kinetic/connection_options.h"
35 #include "kinetic/hmac_provider.h"
36 #include "kinetic_client.pb.h"
37 #include "nonblocking_packet.h"
38 #include "socket_wrapper_interface.h"
39 #include "nonblocking_packet_receiver.h"
40 
41 namespace kinetic {
42 
43 using com::seagate::kinetic::client::proto::Message;
44 using com::seagate::kinetic::client::proto::Command;
45 using com::seagate::kinetic::client::proto::Command_Status_StatusCode;
46 
47 using std::string;
48 using std::unique_ptr;
49 using std::deque;
50 using std::pair;
51 using std::unordered_map;
52 
54  public:
55  virtual ~NonblockingSenderInterface() {}
56  // The HandlerKey returned will be unique for the lifespan of the Sender instance.
57  virtual void Enqueue(unique_ptr<Message> message, unique_ptr<Command> command, const shared_ptr<const string> value,
58  unique_ptr<HandlerInterface> handler, HandlerKey handler_key) = 0;
59  virtual NonblockingPacketServiceStatus Send() = 0;
60  // remove the handler if it hasn't already started being processed. Returns true if a handler
61  // actually was removed.
62  virtual bool Remove(HandlerKey key) = 0;
63 };
64 
66  public:
67  NonblockingSender(shared_ptr<SocketWrapperInterface> socket_wrapper,
68  shared_ptr<NonblockingReceiverInterface> receiver,
69  shared_ptr<NonblockingPacketWriterFactoryInterface> packet_writer_factory,
70  HmacProvider hmac_provider, const ConnectionOptions &connection_options);
72  void Enqueue(unique_ptr<Message> message, unique_ptr<Command> command, const shared_ptr<const string> value,
73  unique_ptr<HandlerInterface> handler, HandlerKey handler_key);
74  NonblockingPacketServiceStatus Send();
75  bool Remove(HandlerKey key);
76 
77  private:
78  struct Request {
79  unique_ptr<const Message> message;
80  unique_ptr<const Command> command;
81  shared_ptr<const string> value;
82  unique_ptr<HandlerInterface> handler;
83  HandlerKey handler_key;
84  };
85 
86  shared_ptr<SocketWrapperInterface> socket_wrapper_;
87  shared_ptr<NonblockingReceiverInterface> receiver_;
88  shared_ptr<NonblockingPacketWriterFactoryInterface> packet_writer_factory_;
89  HmacProvider hmac_provider_;
90  ConnectionOptions connection_options_;
91  int64_t sequence_number_;
92  HandlerKey handler_key_;
93  unique_ptr<NonblockingPacketWriterInterface> current_writer_;
94  shared_ptr<HandlerInterface> handler_;
95  deque<unique_ptr<Request>> request_queue_;
96  google::int64 message_sequence_;
97  DISALLOW_COPY_AND_ASSIGN(NonblockingSender);
98 };
99 
100 
101 } // namespace kinetic
102 
103 #endif // KINETIC_CPP_CLIENT_NONBLOCKING_PACKET_SENDER_H_
Wrapper class that handles computing HMACs. The supplied implementation uses openssl, but users can supply an alternate implementation that uses a different library (e. g. one providing specialized HW accelaration)
Definition: hmac_provider.h:33
Use this struct to pass all connection options to the KineticConnectionFactory.