own.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_OWN_HPP_INCLUDED__
4 #define __ZMQ_OWN_HPP_INCLUDED__
5 
6 #include <set>
7 
8 #include "object.hpp"
9 #include "options.hpp"
10 #include "atomic_counter.hpp"
11 #include "stdint.hpp"
12 
13 namespace zmq
14 {
15 class ctx_t;
16 class io_thread_t;
17 
18 // Base class for objects forming a part of ownership hierarchy.
19 // It handles initialisation and destruction of such objects.
20 
21 class own_t : public object_t
22 {
23  public:
24  // Note that the owner is unspecified in the constructor.
25  // It'll be supplied later on when the object is plugged in.
26 
27  // The object is not living within an I/O thread. It has it's own
28  // thread outside of 0MQ infrastructure.
29  own_t (zmq::ctx_t *parent_, uint32_t tid_);
30 
31  // The object is living within I/O thread.
32  own_t (zmq::io_thread_t *io_thread_, const options_t &options_);
33 
34  // When another owned object wants to send command to this object
35  // it calls this function to let it know it should not shut down
36  // before the command is delivered.
37  void inc_seqnum ();
38 
39  // Use following two functions to wait for arbitrary events before
40  // terminating. Just add number of events to wait for using
41  // register_tem_acks functions. When event occurs, call
42  // remove_term_ack. When number of pending acks reaches zero
43  // object will be deallocated.
44  void register_term_acks (int count_);
45  void unregister_term_ack ();
46 
47  protected:
48  // Launch the supplied object and become its owner.
49  void launch_child (own_t *object_);
50 
51  // Terminate owned object
52  void term_child (own_t *object_);
53 
54  // Ask owner object to terminate this object. It may take a while
55  // while actual termination is started. This function should not be
56  // called more than once.
57  void terminate ();
58 
59  // Returns true if the object is in process of termination.
60  bool is_terminating () const;
61 
62  // Derived object destroys own_t. There's no point in allowing
63  // others to invoke the destructor. At the same time, it has to be
64  // virtual so that generic own_t deallocation mechanism destroys
65  // specific type of the owned object correctly.
67 
68  // Term handler is protected rather than private so that it can
69  // be intercepted by the derived class. This is useful to add custom
70  // steps to the beginning of the termination process.
71  void process_term (int linger_) ZMQ_OVERRIDE;
72 
73  // A place to hook in when physical destruction of the object
74  // is to be delayed.
75  virtual void process_destroy ();
76 
77  // Socket options associated with this object.
79 
80  private:
81  // Set owner of the object
82  void set_owner (own_t *owner_);
83 
84  // Handlers for incoming commands.
85  void process_own (own_t *object_) ZMQ_OVERRIDE;
86  void process_term_req (own_t *object_) ZMQ_OVERRIDE;
89 
90  // Check whether all the pending term acks were delivered.
91  // If so, deallocate this object.
92  void check_term_acks ();
93 
94  // True if termination was already initiated. If so, we can destroy
95  // the object if there are no more child objects or pending term acks.
97 
98  // Sequence number of the last command sent to this object.
100 
101  // Sequence number of the last command processed by this object.
103 
104  // Socket owning this object. It's responsible for shutting down
105  // this object.
107 
108  // List of all objects owned by this socket. We are responsible
109  // for deallocating them before we quit.
110  typedef std::set<own_t *> owned_t;
112 
113  // Number of events we have to get before we can destroy the object.
115 
117 };
118 }
119 
120 #endif
zmq::own_t::term_child
void term_child(own_t *object_)
Definition: own.cpp:66
zmq::own_t::launch_child
void launch_child(own_t *object_)
Definition: own.cpp:54
zmq::own_t::process_seqnum
void process_seqnum() ZMQ_OVERRIDE
Definition: own.cpp:45
atomic_counter.hpp
zmq::own_t::_sent_seqnum
atomic_counter_t _sent_seqnum
Definition: own.hpp:99
zmq::options_t
Definition: options.hpp:34
zmq::own_t::owned_t
std::set< own_t * > owned_t
Definition: own.hpp:110
zmq::own_t::process_term_req
void process_term_req(own_t *object_) ZMQ_OVERRIDE
Definition: own.cpp:71
zmq::own_t::process_term
void process_term(int linger_) ZMQ_OVERRIDE
Definition: own.cpp:128
zmq::own_t::_owner
own_t * _owner
Definition: own.hpp:106
zmq::own_t::check_term_acks
void check_term_acks()
Definition: own.cpp:165
zmq::own_t::is_terminating
bool is_terminating() const
Definition: own.cpp:123
zmq::own_t::~own_t
~own_t() ZMQ_OVERRIDE
Definition: own.cpp:29
zmq
Definition: zmq.hpp:229
ZMQ_OVERRIDE
#define ZMQ_OVERRIDE
Definition: zmq.hpp:91
zmq::own_t::_owned
owned_t _owned
Definition: own.hpp:111
stdint.hpp
zmq::own_t::unregister_term_ack
void unregister_term_ack()
Definition: own.cpp:151
zmq::atomic_counter_t
Definition: atomic_counter.hpp:61
zmq::own_t::options
options_t options
Definition: own.hpp:78
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
zmq::own_t::process_term_ack
void process_term_ack() ZMQ_OVERRIDE
Definition: own.cpp:160
zmq::own_t::own_t
own_t(zmq::ctx_t *parent_, uint32_t tid_)
zmq::own_t::register_term_acks
void register_term_acks(int count_)
Definition: own.cpp:146
zmq::own_t::terminate
void terminate()
Definition: own.cpp:105
zmq::object_t
Definition: object.hpp:28
zmq::own_t::inc_seqnum
void inc_seqnum()
Definition: own.cpp:39
zmq::own_t::set_owner
void set_owner(own_t *owner_)
Definition: own.cpp:33
options.hpp
zmq::own_t::process_own
void process_own(own_t *object_) ZMQ_OVERRIDE
Definition: own.cpp:91
std
zmq::own_t
Definition: own.hpp:21
zmq::own_t::_processed_seqnum
uint64_t _processed_seqnum
Definition: own.hpp:102
cpp.gmock_class.set
set
Definition: gmock_class.py:44
zmq::own_t::_terminating
bool _terminating
Definition: own.hpp:96
zmq::own_t::_term_acks
int _term_acks
Definition: own.hpp:114
zmq::own_t::process_destroy
virtual void process_destroy()
Definition: own.cpp:182
object.hpp
options_
DebugStringOptions options_
Definition: src/google/protobuf/descriptor.cc:2410


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:57