app_thread.hpp 2.21 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
2
    Copyright (c) 2007-2010 iMatix Corporation
Martin Sustrik's avatar
Martin Sustrik committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
    the terms of the Lesser GNU General Public License as published by
    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
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Martin Sustrik's avatar
Martin Sustrik committed
20 21
#ifndef __ZMQ_APP_THREAD_HPP_INCLUDED__
#define __ZMQ_APP_THREAD_HPP_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
22 23 24 25 26

#include <vector>

#include "stdint.hpp"
#include "object.hpp"
27
#include "yarray.hpp"
Martin Sustrik's avatar
Martin Sustrik committed
28

Martin Sustrik's avatar
Martin Sustrik committed
29
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
30 31
{

32
    class app_thread_t : public object_t
Martin Sustrik's avatar
Martin Sustrik committed
33 34 35
    {
    public:

36 37
        app_thread_t (class dispatcher_t *dispatcher_, int thread_slot_,
            int flags_);
Martin Sustrik's avatar
Martin Sustrik committed
38

39
        ~app_thread_t ();
Martin Sustrik's avatar
Martin Sustrik committed
40 41

        //  Returns signaler associated with this application thread.
42
        struct i_signaler *get_signaler ();
Martin Sustrik's avatar
Martin Sustrik committed
43 44 45

        //  Processes commands sent to this thread (if any). If 'block' is
        //  set to true, returns only after at least one command was processed.
Martin Sustrik's avatar
Martin Sustrik committed
46 47 48
        //  If throttle argument is true, commands are processed at most once
        //  in a predefined time period.
        void process_commands (bool block_, bool throttle_);
Martin Sustrik's avatar
Martin Sustrik committed
49

50
        //  Create a socket of a specified type.
51
        class socket_base_t *create_socket (int type_);
52 53

        //  Unregister the socket from the app_thread (called by socket itself).
54
        void remove_socket (class socket_base_t *socket_);
55

Martin Sustrik's avatar
Martin Sustrik committed
56 57
    private:

58
        //  All the sockets created from this application thread.
59
        typedef yarray_t <socket_base_t> sockets_t;
60
        sockets_t sockets;
Martin Sustrik's avatar
Martin Sustrik committed
61 62

        //  App thread's signaler object.
63
        struct i_signaler *signaler;
Martin Sustrik's avatar
Martin Sustrik committed
64 65 66 67 68 69 70 71 72 73 74

        //  Timestamp of when commands were processed the last time.
        uint64_t last_processing_time;

        app_thread_t (const app_thread_t&);
        void operator = (const app_thread_t&);
    };

}

#endif