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

    This file is part of 0MQ.

    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
Martin Sustrik's avatar
Martin Sustrik committed
9 10 11 12 13 14
    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
15
    GNU Lesser General Public License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
16

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

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

#include "stdint.hpp"

Martin Sustrik's avatar
Martin Sustrik committed
26
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
27 28 29 30 31 32 33 34 35 36 37 38
{

    //  This structure defines the commands that can be sent between threads.

    struct command_t
    {
        //  Object to process the command.
        class object_t *destination;

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

        union {

58 59
            //  Sent to I/O thread to let it know that it should
            //  terminate itself.
Martin Sustrik's avatar
Martin Sustrik committed
60 61 62
            struct {
            } stop;

63
            //  Sent to I/O object to make it register with its I/O thread.
Martin Sustrik's avatar
Martin Sustrik committed
64
            struct {
65
            } plug;
Martin Sustrik's avatar
Martin Sustrik committed
66

67
            //  Sent to socket to let it know about the newly created object.
Martin Sustrik's avatar
Martin Sustrik committed
68
            struct {
69
                class own_t *object;
70
            } own;
Martin Sustrik's avatar
Martin Sustrik committed
71

72 73
            //  Attach the engine to the session. If engine is NULL, it informs
            //  session that the connection have failed.
74
            struct {
75
                struct i_engine *engine;
76 77
            } attach;

Martin Sustrik's avatar
Martin Sustrik committed
78
            //  Sent from session to socket to establish pipe(s) between them.
79
            //  Caller have used inc_seqnum beforehand sending the command.
Martin Sustrik's avatar
Martin Sustrik committed
80
            struct {
81
                class pipe_t *pipe;
82
            } bind;
Martin Sustrik's avatar
Martin Sustrik committed
83

Martin Sustrik's avatar
Martin Sustrik committed
84 85 86
            //  Sent by pipe writer to inform dormant pipe reader that there
            //  are messages in the pipe.
            struct {
87
            } activate_read;
Martin Sustrik's avatar
Martin Sustrik committed
88

89 90
            //  Sent by pipe reader to inform pipe writer about how many
            //  messages it has read so far.
Martin Hurton's avatar
Martin Hurton committed
91 92
            struct {
                uint64_t msgs_read;
93
            } activate_write;
Martin Hurton's avatar
Martin Hurton committed
94

95 96 97 98 99 100 101
            //  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
102 103 104 105 106 107 108 109 110
            //  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;

111 112
            //  Sent by I/O object ot the socket to request the shutdown of
            //  the I/O object.
Martin Sustrik's avatar
Martin Sustrik committed
113
            struct {
114
                class own_t *object;
115
            } term_req;
Martin Sustrik's avatar
Martin Sustrik committed
116

117
            //  Sent by socket to I/O object to start its shutdown.
Martin Sustrik's avatar
Martin Sustrik committed
118
            struct {
119
                int linger;
120
            } term;
Martin Sustrik's avatar
Martin Sustrik committed
121

122 123
            //  Sent by I/O object to the socket to acknowledge it has
            //  shut down.
Martin Sustrik's avatar
Martin Sustrik committed
124
            struct {
125
            } term_ack;
Martin Sustrik's avatar
Martin Sustrik committed
126

127 128 129 130 131 132
            //  Transfers the ownership of the closed socket
            //  to the reaper thread.
            struct {
                class socket_base_t *socket;
            } reap;

133 134 135 136
            //  Closed socket notifies the reaper that it's already deallocated.
            struct {
            } reaped;

137 138 139 140 141
            //  Sent by reaper thread to the term thread when all the sockets
            //  are successfully deallocated.
            struct {
            } done;

Martin Sustrik's avatar
Martin Sustrik committed
142 143 144 145 146 147
        } args;
    };

}    

#endif