Kinetic C/C++ Client
 All Classes Functions Variables Pages
nonblocking_packet_service.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_SERVICE_H_
22 #define KINETIC_CPP_CLIENT_NONBLOCKING_PACKET_SERVICE_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 #include "nonblocking_packet_sender.h"
41 
42 namespace kinetic {
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  NonblockingPacketService(shared_ptr<SocketWrapperInterface> socket_wrapper,
56  unique_ptr<NonblockingSenderInterface> sender,
57  shared_ptr<NonblockingReceiverInterface> receiver);
59  // handler instances cannot be reused
60  HandlerKey Submit(unique_ptr<Message> message, unique_ptr<Command> command, const shared_ptr<const string> value,
61  unique_ptr<HandlerInterface> handler);
62  bool Run(fd_set *read_fds, fd_set *write_fds, int *nfds);
63  bool Remove(HandlerKey handler_key);
64 
65  private:
66  shared_ptr<SocketWrapperInterface> socket_wrapper_;
67  unique_ptr<NonblockingSenderInterface> sender_;
68  shared_ptr<NonblockingReceiverInterface> receiver_;
69  bool failed_;
70  HandlerKey next_key_;
71  void CleanUp();
72  DISALLOW_COPY_AND_ASSIGN(NonblockingPacketService);
73 };
74 
75 } // namespace kinetic
76 
77 #endif // KINETIC_CPP_CLIENT_NONBLOCKING_PACKET_SERVICE_H_