summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/threads/TestI.h
blob: db1e96836f455afde0541b777175ddd3fcbf67b6 (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
75
76
// **********************************************************************
//
// Copyright (c) 2003-2007 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 TEST_I_H
#define TEST_I_H

#include <Test.h>
#include <IceUtil/Thread.h>
#include <Ice/Ice.h>

class ThreadHookI : public Ice::ThreadNotification, public IceUtil::Mutex
{
public:

    ThreadHookI();

    virtual void start();
    virtual void stop();

    Ice::Int getThreadNum() const;
    int activeThreads() const;

private:

    Ice::Int getThreadNumInternal() const;

    typedef std::vector<std::pair<IceUtil::ThreadControl::ID, Ice::Int> > ThreadList;
    ThreadList _threads;
    Ice::Int _nextThreadId;
};
typedef IceUtil::Handle<ThreadHookI> ThreadHookIPtr;

class AdapterI : virtual public Test::Adapter, public IceUtil::Monitor<IceUtil::Mutex>
{
public:

    AdapterI(const ThreadHookIPtr&, bool);

    virtual bool isThreadPerConnection(const Ice::Current&);
    virtual Ice::Int getThreadId(const Ice::Current&);
    virtual void reset(const Ice::Current&);
    virtual Ice::Int waitForWakeup(Ice::Int, bool&, const Ice::Current&);
    virtual Ice::Int wakeup(const Ice::Current&);
    virtual void callSelf(const Test::AdapterPrx&, const Ice::Current&);

private:

    ThreadHookIPtr _threadHook;
    bool _threadPerConnection;
    bool _waiting;
    bool _notified;
};

class ServerI : virtual public Test::Server
{
public:

    ServerI(const Ice::CommunicatorPtr&);

    virtual Test::AdapterSeq getAdapters(const Ice::Current&);
    virtual void ping(const Ice::Current&);
    virtual void shutdown(const Ice::Current&);

private:

    ThreadHookIPtr _hook;
    Test::AdapterSeq _adapters;
};

#endif