Qpid Proton C++  0.13.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
event_loop.hpp
1 #ifndef PROTON_EVENT_LOOP_HPP
2 #define PROTON_EVENT_LOOP_HPP
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include "./internal/config.hpp"
26 
27 #include <functional>
28 
29 #if PN_CPP_HAS_CPP11
30 #include <future>
31 #include <type_traits>
32 #endif
33 
34 struct pn_connection_t;
35 struct pn_session_t;
36 struct pn_link_t;
37 
38 namespace proton {
39 
42  public:
43  virtual ~inject_handler() {}
44 
45  // XXX bad name, should be operator()() to be idiomatic and consistent with C++11.
47  virtual void on_inject() = 0;
48 };
49 
56 class PN_CPP_CLASS_EXTERN event_loop {
57  public:
58  virtual ~event_loop() {}
59 
65  virtual bool inject(inject_handler& f) = 0;
66 
67 #if PN_CPP_HAS_CPP11
68  virtual bool inject(std::function<void()> f) = 0;
70 #endif
71 
72  protected:
73  event_loop() {}
74 
75  private:
76  PN_CPP_EXTERN static event_loop* get(pn_connection_t*);
77  PN_CPP_EXTERN static event_loop* get(pn_session_t*);
78  PN_CPP_EXTERN static event_loop* get(pn_link_t*);
79 
81  friend class connection;
82  template <class T> friend class thread_safe;
84 };
85 
86 } // proton
87 
88 #endif // PROTON_EVENT_LOOP_HPP
A connection to a remote AMQP peer.
Definition: connection.hpp:48
virtual void on_inject()=0
Called when the injected code is executed.
Experimental - A serial execution context.
Definition: event_loop.hpp:56
Experimental - A handler for injected code.
Definition: event_loop.hpp:41
Experimental - A thread-safe object wrapper.
Definition: connection.hpp:45