Qpid Proton C++  0.12.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
connection_engine.hpp
1 #ifndef CONNECTION_ENGINE_HPP
2 #define CONNECTION_ENGINE_HPP
3 
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License. You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied. See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22 
23 #include "proton/connection.hpp"
24 #include "proton/connection_options.hpp"
25 #include "proton/export.hpp"
26 #include "proton/id_generator.hpp"
27 #include "proton/pn_unique_ptr.hpp"
28 #include "proton/types.hpp"
29 
30 #include <cstddef>
31 #include <utility>
32 #include <string>
33 
34 namespace proton {
35 
36 class connection_engine_context;
37 class handler;
38 class connection;
39 
40 // TODO aconway 2016-01-23: doc contrast with container.
41 
65  public:
66  // FIXME aconway 2016-01-23: DOC
67  class container {
68  public:
71  PN_CPP_EXTERN container(const std::string &id = "");
72 
74  PN_CPP_EXTERN std::string id() const;
75 
81  PN_CPP_EXTERN connection_options make_options();
82 
85  PN_CPP_EXTERN void options(const connection_options&);
86 
87  private:
88  const std::string id_;
89  id_generator id_gen_;
90  connection_options options_;
91  };
92 
94  PN_CPP_EXTERN connection_engine(handler&, const connection_options& = no_opts);
95 
96  PN_CPP_EXTERN virtual ~connection_engine();
97 
99  PN_CPP_EXTERN size_t can_read() const;
100 
102  PN_CPP_EXTERN size_t can_write() const;
103 
105  enum io_flag {
106  READ = 1,
107  WRITE = 2
108  };
109 
118  PN_CPP_EXTERN bool process(int io_flags=READ|WRITE);
119 
122  PN_CPP_EXTERN bool process_nothrow(int io_flags=READ|WRITE);
123 
127  PN_CPP_EXTERN bool closed() const;
128 
130  PN_CPP_EXTERN std::string error_str() const;
131 
133  PN_CPP_EXTERN class connection connection() const;
134 
136  PN_CPP_EXTERN class transport transport() const;
137 
147  PN_CPP_EXTERN void disconnect();
148 
149  protected:
156  virtual size_t io_read(char* buf, size_t max) = 0;
157 
163  virtual size_t io_write(const char*, size_t) = 0;
164 
168  virtual void io_close() = 0;
169 
170  PN_CPP_EXTERN static const connection_options no_opts;
171 
172  private:
173  connection_engine(const connection_engine&);
174  connection_engine& operator=(const connection_engine&);
175 
176  void dispatch();
177  void try_read();
178  void try_write();
179 
180  class connection connection_;
181  connection_engine_context* ctx_;
182 };
183 
184 }
185 
186 #endif // CONNECTION_ENGINE_HPP
io_flag
Combine these flags with | to indicate read, write, both or neither.
Definition: connection_engine.hpp:105
An interface for connection-oriented IO integration.
Definition: connection_engine.hpp:64
bool process(int io_flags=READ|WRITE)
Read, write and dispatch events.
void disconnect()
Disconnect the engine.
Defines C++ types representing AMQP types.
A connection to a remote AMQP peer.
Definition: connection.hpp:42
Options for creating a connection.
Definition: connection_options.hpp:60
std::string error_str() const
If the engine was closed by an error, return a pointer.
bool closed() const
True if the engine is closed, meaning there are no further events to process and close_io has been ca...
connection_engine(handler &, const connection_options &=no_opts)
Create a connection engine that dispatches to handler.
size_t can_read() const
Return the number of bytes that the engine is currently ready to read.
Callback functions for handling proton events.
Definition: handler.hpp:40
bool process_nothrow(int io_flags=READ|WRITE)
Non-throwing version of process.
size_t can_write() const
Return the number of bytes that the engine is currently ready to write.
A network layer supporting an AMQP connection.
Definition: transport.hpp:38