about summary refs log tree commit diff
path: root/src/rt/rust_proxy.h
blob: 2b5e820da100a1cdc2847b96299e447e97c0ad11 (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
#ifndef RUST_PROXY_H
#define RUST_PROXY_H

/**
 * A proxy object is a wrapper for remote objects. Proxy objects are domain
 * owned and provide a way distinguish between local and remote objects.
 */

template <typename T> struct rust_proxy;

/**
 * The base class of all objects that may delegate.
 */
template <typename T> struct
maybe_proxy : public rc_base<T>, public rust_cond {
protected:
    T *_referent;
public:
    maybe_proxy(T *referent) : _referent(referent) {
        // Nop.
    }

    T *referent() {
        return (T *)_referent;
    }

    bool is_proxy() {
        return _referent != this;
    }

    rust_proxy<T> *as_proxy() {
        return (rust_proxy<T> *) this;
    }

    T *as_referent() {
        return (T *) this;
    }
};

template <typename T> class rust_handle;

/**
 * A proxy object that delegates to another.
 */
template <typename T> struct
rust_proxy : public maybe_proxy<T> {
private:
    bool _strong;
    rust_handle<T> *_handle;
public:
    rust_proxy(rust_handle<T> *handle) :
        maybe_proxy<T> (NULL), _strong(FALSE), _handle(handle) {
        // Nop.
    }

    rust_proxy(T *referent) :
        maybe_proxy<T> (referent), _strong(FALSE), _handle(NULL) {
        // Nop.
    }

    rust_handle<T> *handle() {
        return _handle;
    }
};

class rust_message_queue;
class rust_task;

//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//

#endif /* RUST_PROXY_H */