summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/adapterDeactivation/ServantLocatorI.cpp
blob: 16d54bb5adf0b37110f816dfa83387f822b68433 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// **********************************************************************

#include <ServantLocatorI.h>
#include <TestHelper.h>
#include <TestI.h>

using namespace std;
using namespace Ice;
using namespace Test;

namespace
{

class RouterI : public Ice::Router
{
public:

    RouterI() : _nextPort(23456)
    {
    }

    virtual Ice::ObjectPrxPtr
    getClientProxy(IceUtil::Optional<bool>&, const Ice::Current&) const
    {
        return ICE_NULLPTR;
    }

    virtual Ice::ObjectPrxPtr
    getServerProxy(const Ice::Current& c) const
    {
        ostringstream os;
        os << "dummy:tcp -h localhost -p " << _nextPort++ << " -t 30000";
        return c.adapter->getCommunicator()->stringToProxy(os.str());
    }

    virtual Ice::ObjectProxySeq
#ifdef ICE_CPP11_MAPPING
    addProxies(Ice::ObjectProxySeq, const Ice::Current&)
#else
    addProxies(const Ice::ObjectProxySeq&, const Ice::Current&)
#endif
    {
        return Ice::ObjectProxySeq();
    }

private:

    mutable int _nextPort;
};

}

ServantLocatorI::ServantLocatorI() : _deactivated(false), _router(ICE_MAKE_SHARED(RouterI))
{
}

ServantLocatorI::~ServantLocatorI()
{
    test(_deactivated);
}

Ice::ObjectPtr
#ifdef ICE_CPP11_MAPPING
ServantLocatorI::locate(const Ice::Current& current, std::shared_ptr<void>& cookie)
#else
ServantLocatorI::locate(const Ice::Current& current, Ice::LocalObjectPtr& cookie)
#endif
{
    test(!_deactivated);

    if(current.id.name == "router")
    {
        return _router;
    }

    test(current.id.category == "");
    test(current.id.name == "test");

    cookie = ICE_MAKE_SHARED(CookieI);

    return ICE_MAKE_SHARED(TestI);
}

void
#ifdef ICE_CPP11_MAPPING
ServantLocatorI::finished(const Ice::Current& current, const Ice::ObjectPtr&, const std::shared_ptr<void>& cookie)
#else
ServantLocatorI::finished(const Ice::Current& current, const Ice::ObjectPtr&, const Ice::LocalObjectPtr& cookie)
#endif
{
    test(!_deactivated);
    if(current.id.name == "router")
    {
        return;
    }

#ifdef ICE_CPP11_MAPPING
    shared_ptr<CookieI> co = static_pointer_cast<CookieI>(cookie);
#else
    CookiePtr co = CookiePtr::dynamicCast(cookie);
#endif
    test(co);
    test(co->message() == "blahblah");
}

void
ServantLocatorI::deactivate(const string&)
{
    test(!_deactivated);

    _deactivated = true;
}