blob: 1672a3945964aa269b919a18721e4a6f189d81e5 (
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
|
#ifndef TEMPORARYICEADAPTER_H
#define TEMPORARYICEADAPTER_H
#include <Ice/ObjectAdapter.h>
#include <visibility.h>
namespace P2PVR {
template <typename Object>
class DLL_PUBLIC TemporaryIceAdapterObject {
public:
TemporaryIceAdapterObject(Ice::ObjectAdapterPtr a, std::shared_ptr<Object> o) :
adapter(a),
object(o),
proxy(Ice::checkedCast<typename Object::ProxyType>(adapter->addWithUUID(object)))
{
if (!proxy) {
throw std::runtime_error("Failed to set up new object proxy");
}
}
~TemporaryIceAdapterObject()
{
remove();
}
TemporaryIceAdapterObject(const TemporaryIceAdapterObject &) = delete;
void operator=(const TemporaryIceAdapterObject &) = delete;
operator std::shared_ptr<typename Object::ProxyType>() const
{
return proxy;
}
Object * Get() const
{
return object.get();
}
typename Object::ProxyType operator->() const
{
return proxy;
}
bool operator==(const std::shared_ptr<typename Object::ProxyType> & pr) const
{
return pr == proxy;
}
void remove()
{
if (proxy) {
adapter->remove(proxy->ice_getIdentity());
proxy.reset();
}
}
private:
Ice::ObjectAdapterPtr adapter;
std::shared_ptr<Object> object;
std::shared_ptr<typename Object::ProxyType> proxy;
};
}
#endif
|