summaryrefslogtreecommitdiff
path: root/cpp/src/Glacier/ClientBlobject.cpp
blob: 9cd92e4a459063a08ea221c219c5f6b14b69fb21 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#include <Ice/RoutingTable.h>
#include <Glacier/ClientBlobject.h>

using namespace std;
using namespace Ice;
using namespace Glacier;

Glacier::ClientBlobject::ClientBlobject(const CommunicatorPtr& communicator,
					const IceInternal::RoutingTablePtr& routingTable) :
    _communicator(communicator),
    _logger(_communicator->getLogger()),
    _routingTable(routingTable)
{
    PropertiesPtr properties = _communicator->getProperties();
    _traceLevel = atoi(properties->getProperty("Glacier.Trace.Client").c_str());
}

Glacier::ClientBlobject::~ClientBlobject()
{
    assert(!_communicator);
}

void
Glacier::ClientBlobject::destroy()
{
    // No mutex protection necessary, destroy is only called after all
    // object adapters have shut down.
    _communicator = 0;
    _logger = 0;
    _routingTable = 0;
}

void
Glacier::ClientBlobject::ice_invoke(const std::vector<Byte>& inParams, std::vector<Byte>& outParams,
				    const Current& current)
{
    assert(_communicator); // Destroyed?

    try
    {
	ObjectPrx proxy = _routingTable->get(current.identity);
	
	if (!proxy)
	{
	    throw ObjectNotExistException(__FILE__, __LINE__);
	}
	
	if (!current.facet.empty())
	{
	    proxy = proxy->ice_newFacet(current.facet);
	}

	Context::const_iterator p = current.context.find("_fwd");
	if (p != current.context.end())
	{
	    for (unsigned int i = 0; i < p->second.length(); ++i)
	    {
		char option = p->second[i];
		switch (option)
		{
		    case 't':
		    {
			proxy = proxy->ice_twoway();
			break;
		    }
		    
		    case 'o':
		    {
			proxy = proxy->ice_oneway();
			break;
		    }
		    
		    case 'd':
		    {
			proxy = proxy->ice_datagram();
			break;
		    }
		    
		    case 's':
		    {
			proxy = proxy->ice_secure(true);
			break;
		    }
		    
		    default:
		    {
			ostringstream s;
			s << "unknown forward option `" << option << "'";
			_logger->warning(s.str());
			break;
		    }
		}
	    }
	}
	
	if (_traceLevel >= 2)
	{
	    ostringstream s;
	    s << "routing to:\n"
	      << "proxy = " << _communicator->proxyToString(proxy) << '\n'
	      << "operation = " << current.operation << '\n'
	      << "nonmutating = " << (current.nonmutating ? "true" : "false");
	    _logger->trace("Glacier", s.str());
	}

	proxy->ice_invoke(current.operation, current.nonmutating, inParams, outParams, current.context);
    }
    catch (const Exception& ex)
    {
	if (_traceLevel)
	{
	    ostringstream s;
	    s << "routing exception:\n" << ex;
	    _logger->trace("Glacier", s.str());
	}

	ex.ice_throw();
    }
}