summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/dispatcher/Dispatcher.h
blob: c65736a65ef7d092b93fd0c12777042cb9ede952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// **********************************************************************
//
// Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef DISPATCHER_I_H
#define DISPATCHER_I_H

#include <IceUtil/Thread.h>
#include <IceUtil/Monitor.h>
#include <IceUtil/Mutex.h>
#include <Ice/Dispatcher.h>
#include <Ice/Connection.h>

#include <deque>

#ifdef ICE_CPP11_MAPPING
class DispatcherCall
{
public:

    DispatcherCall(std::function<void()> call) :
        _call(std::move(call))
    {
    }

    void run()
    {
        _call();
    }

private:

    std::function<void()> _call;
};
#endif

class Dispatcher :
#ifndef ICE_CPP11_MAPPING
    public Ice::Dispatcher,
#endif
public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
{
public:

    Dispatcher();

#ifdef ICE_CPP11_MAPPING
    void dispatch(const std::shared_ptr<DispatcherCall>&, const std::shared_ptr<Ice::Connection>&);
#else
    virtual void dispatch(const Ice::DispatcherCallPtr&, const Ice::ConnectionPtr&);
#endif

    void run();

    static void terminate();
    static bool isDispatcherThread();

private:

    static IceUtil::Handle<Dispatcher> _instance;
#ifdef ICE_CPP11_MAPPING
    std::deque<std::shared_ptr<DispatcherCall>> _calls;
#else
    std::deque<Ice::DispatcherCallPtr> _calls;
#endif
    bool _terminated;
};

#endif