command.hpp 4.26 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
2
    Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
3 4 5 6

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
7
    the terms of the GNU Lesser General Public License as published by
Martin Sustrik's avatar
Martin Sustrik committed
8 9 10 11 12 13
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU Lesser General Public License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
15

16
    You should have received a copy of the GNU Lesser General Public License
Martin Sustrik's avatar
Martin Sustrik committed
17 18 19
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Martin Sustrik's avatar
Martin Sustrik committed
20 21
#ifndef __ZMQ_COMMAND_HPP_INCLUDED__
#define __ZMQ_COMMAND_HPP_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
22 23 24

#include "stdint.hpp"

Martin Sustrik's avatar
Martin Sustrik committed
25
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
26 27
{

28 29 30 31 32 33
    class object_t;
    class own_t;
    struct i_engine;
    class pipe_t;
    class socket_base_t;

Martin Sustrik's avatar
Martin Sustrik committed
34 35 36 37 38
    //  This structure defines the commands that can be sent between threads.

    struct command_t
    {
        //  Object to process the command.
39
        zmq::object_t *destination;
Martin Sustrik's avatar
Martin Sustrik committed
40 41 42 43

        enum type_t
        {
            stop,
44 45
            plug,
            own,
46
            attach,
Martin Sustrik's avatar
Martin Sustrik committed
47
            bind,
48 49
            activate_read,
            activate_write,
50
            hiccup,
Martin Sustrik's avatar
Martin Sustrik committed
51 52
            pipe_term,
            pipe_term_ack,
53 54
            term_req,
            term,
55 56
            term_ack,
            reap,
57
            reaped,
58
            done
Martin Sustrik's avatar
Martin Sustrik committed
59 60 61 62
        } type;

        union {

63 64
            //  Sent to I/O thread to let it know that it should
            //  terminate itself.
Martin Sustrik's avatar
Martin Sustrik committed
65 66 67
            struct {
            } stop;

68
            //  Sent to I/O object to make it register with its I/O thread.
Martin Sustrik's avatar
Martin Sustrik committed
69
            struct {
70
            } plug;
Martin Sustrik's avatar
Martin Sustrik committed
71

72
            //  Sent to socket to let it know about the newly created object.
Martin Sustrik's avatar
Martin Sustrik committed
73
            struct {
74
                zmq::own_t *object;
75
            } own;
Martin Sustrik's avatar
Martin Sustrik committed
76

77 78
            //  Attach the engine to the session. If engine is NULL, it informs
            //  session that the connection have failed.
79
            struct {
80
                struct i_engine *engine;
81 82
            } attach;

Martin Sustrik's avatar
Martin Sustrik committed
83
            //  Sent from session to socket to establish pipe(s) between them.
84
            //  Caller have used inc_seqnum beforehand sending the command.
Martin Sustrik's avatar
Martin Sustrik committed
85
            struct {
86
                zmq::pipe_t *pipe;
87
            } bind;
Martin Sustrik's avatar
Martin Sustrik committed
88

Martin Sustrik's avatar
Martin Sustrik committed
89 90 91
            //  Sent by pipe writer to inform dormant pipe reader that there
            //  are messages in the pipe.
            struct {
92
            } activate_read;
Martin Sustrik's avatar
Martin Sustrik committed
93

94 95
            //  Sent by pipe reader to inform pipe writer about how many
            //  messages it has read so far.
Martin Hurton's avatar
Martin Hurton committed
96 97
            struct {
                uint64_t msgs_read;
98
            } activate_write;
Martin Hurton's avatar
Martin Hurton committed
99

100 101 102 103 104 105 106
            //  Sent by pipe reader to writer after creating a new inpipe.
            //  The parameter is actually of type pipe_t::upipe_t, however,
            //  its definition is private so we'll have to do with void*.
            struct {
                void *pipe;
            } hiccup;

Martin Sustrik's avatar
Martin Sustrik committed
107 108 109 110 111 112 113 114 115
            //  Sent by pipe reader to pipe writer to ask it to terminate
            //  its end of the pipe.
            struct {
            } pipe_term;

            //  Pipe writer acknowledges pipe_term command.
            struct {
            } pipe_term_ack;

116 117
            //  Sent by I/O object ot the socket to request the shutdown of
            //  the I/O object.
Martin Sustrik's avatar
Martin Sustrik committed
118
            struct {
119
                zmq::own_t *object;
120
            } term_req;
Martin Sustrik's avatar
Martin Sustrik committed
121

122
            //  Sent by socket to I/O object to start its shutdown.
Martin Sustrik's avatar
Martin Sustrik committed
123
            struct {
124
                int linger;
125
            } term;
Martin Sustrik's avatar
Martin Sustrik committed
126

127 128
            //  Sent by I/O object to the socket to acknowledge it has
            //  shut down.
Martin Sustrik's avatar
Martin Sustrik committed
129
            struct {
130
            } term_ack;
Martin Sustrik's avatar
Martin Sustrik committed
131

132 133 134
            //  Transfers the ownership of the closed socket
            //  to the reaper thread.
            struct {
135
                zmq::socket_base_t *socket;
136 137
            } reap;

138 139 140 141
            //  Closed socket notifies the reaper that it's already deallocated.
            struct {
            } reaped;

142 143 144 145 146
            //  Sent by reaper thread to the term thread when all the sockets
            //  are successfully deallocated.
            struct {
            } done;

Martin Sustrik's avatar
Martin Sustrik committed
147 148 149 150 151 152
        } args;
    };

}    

#endif