command.hpp 4.35 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
Martin Sustrik's avatar
Martin Sustrik committed
2
    Copyright (c) 2009-2011 250bpm s.r.o.
3
    Copyright (c) 2007-2009 iMatix Corporation
4
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
5 6 7 8

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
9
    the terms of the GNU Lesser General Public License as published by
Martin Sustrik's avatar
Martin Sustrik committed
10 11 12 13 14 15
    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
16
    GNU Lesser General Public License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
17

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

Martin Sustrik's avatar
Martin Sustrik committed
22 23
#ifndef __ZMQ_COMMAND_HPP_INCLUDED__
#define __ZMQ_COMMAND_HPP_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
24 25 26

#include "stdint.hpp"

Martin Sustrik's avatar
Martin Sustrik committed
27
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
28 29
{

30 31 32 33 34 35
    class object_t;
    class own_t;
    struct i_engine;
    class pipe_t;
    class socket_base_t;

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

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

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

        union {

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

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

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

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

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

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

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

102 103 104 105 106 107 108
            //  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
109 110 111 112 113 114 115 116 117
            //  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;

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

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

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

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

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

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

Martin Sustrik's avatar
Martin Sustrik committed
149 150 151 152 153 154
        } args;
    };

}    

#endif