1 /*
2     Copyright (c) 2007-2011 iMatix Corporation
3     Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
4 
5     This file is part of 0MQ.
6 
7     0MQ is free software; you can redistribute it and/or modify it under
8     the terms of the GNU Lesser General Public License as published by
9     the Free Software Foundation; either version 3 of the License, or
10     (at your option) any later version.
11 
12     0MQ is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef __ZMQ_COMMAND_HPP_INCLUDED__
22 #define __ZMQ_COMMAND_HPP_INCLUDED__
23 
24 #include "stdint.hpp"
25 
26 namespace zmq
27 {
28 
29     //  This structure defines the commands that can be sent between threads.
30 
31     struct command_t
32     {
33         //  Object to process the command.
34         class object_t *destination;
35 
36         enum type_t
37         {
38             stop,
39             plug,
40             own,
41             attach,
42             bind,
43             activate_reader,
44             activate_writer,
45             pipe_term,
46             pipe_term_ack,
47             term_req,
48             term,
49             term_ack,
50             reap,
51             reaped,
52             done
53         } type;
54 
55         union {
56 
57             //  Sent to I/O thread to let it know that it should
58             //  terminate itself.
59             struct {
60             } stop;
61 
62             //  Sent to I/O object to make it register with its I/O thread.
63             struct {
64             } plug;
65 
66             //  Sent to socket to let it know about the newly created object.
67             struct {
68                 class own_t *object;
69             } own;
70 
71             //  Attach the engine to the session. If engine is NULL, it informs
72             //  session that the connection have failed.
73             struct {
74                 struct i_engine *engine;
75                 size_t peer_identity_size;
76                 unsigned char *peer_identity;
77             } attach;
78 
79             //  Sent from session to socket to establish pipe(s) between them.
80             //  Caller have used inc_seqnum beforehand sending the command.
81             struct {
82                 class reader_t *in_pipe;
83                 class writer_t *out_pipe;
84                 size_t peer_identity_size;
85                 unsigned char *peer_identity;
86             } bind;
87 
88             //  Sent by pipe writer to inform dormant pipe reader that there
89             //  are messages in the pipe.
90             struct {
91             } activate_reader;
92 
93             //  Sent by pipe reader to inform pipe writer about how many
94             //  messages it has read so far.
95             struct {
96                 uint64_t msgs_read;
97             } activate_writer;
98 
99             //  Sent by pipe reader to pipe writer to ask it to terminate
100             //  its end of the pipe.
101             struct {
102             } pipe_term;
103 
104             //  Pipe writer acknowledges pipe_term command.
105             struct {
106             } pipe_term_ack;
107 
108             //  Sent by I/O object ot the socket to request the shutdown of
109             //  the I/O object.
110             struct {
111                 class own_t *object;
112             } term_req;
113 
114             //  Sent by socket to I/O object to start its shutdown.
115             struct {
116                 int linger;
117             } term;
118 
119             //  Sent by I/O object to the socket to acknowledge it has
120             //  shut down.
121             struct {
122             } term_ack;
123 
124             //  Transfers the ownership of the closed socket
125             //  to the reaper thread.
126             struct {
127                 class socket_base_t *socket;
128             } reap;
129 
130             //  Closed socket notifies the reaper that it's already deallocated.
131             struct {
132             } reaped;
133 
134             //  Sent by reaper thread to the term thread when all the sockets
135             //  are successfully deallocated.
136             struct {
137             } done;
138 
139         } args;
140     };
141 
142     //  Function to deallocate dynamically allocated components of the command.
143     void deallocate_command (command_t *cmd_);
144 
145 }
146 
147 #endif
148