2010-07-28 17:17:30 -05:00
|
|
|
#ifndef RUST_PROXY_H
|
|
|
|
#define RUST_PROXY_H
|
|
|
|
|
2010-07-19 16:05:18 -05:00
|
|
|
/**
|
|
|
|
* A proxy object is a wrapper around other Rust objects. One use of the proxy
|
|
|
|
* object is to mitigate access between tasks in different thread domains.
|
|
|
|
*/
|
|
|
|
|
2010-07-28 17:17:30 -05:00
|
|
|
template <typename T> struct rust_proxy;
|
|
|
|
/**
|
|
|
|
* The base class of all objects that may delegate.
|
|
|
|
*/
|
2010-07-19 16:05:18 -05:00
|
|
|
template <typename T> struct
|
2010-07-28 17:17:30 -05:00
|
|
|
maybe_proxy : public rc_base<T>, public rust_cond {
|
2010-07-19 16:05:18 -05:00
|
|
|
protected:
|
|
|
|
T *_delegate;
|
|
|
|
public:
|
2010-07-28 17:17:30 -05:00
|
|
|
maybe_proxy(T * delegate) : _delegate(delegate) {
|
|
|
|
|
|
|
|
}
|
|
|
|
T *delegate() {
|
|
|
|
return _delegate;
|
|
|
|
}
|
|
|
|
bool is_proxy() {
|
|
|
|
return _delegate != this;
|
|
|
|
}
|
|
|
|
rust_proxy<T> *as_proxy() {
|
|
|
|
return (rust_proxy<T> *) this;
|
|
|
|
}
|
|
|
|
T *as_delegate() {
|
|
|
|
I(_delegate->get_dom(), !is_proxy());
|
|
|
|
return (T *) this;
|
2010-07-19 16:05:18 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-28 17:17:30 -05:00
|
|
|
/**
|
|
|
|
* A proxy object that delegates to another.
|
|
|
|
*/
|
2010-07-19 16:05:18 -05:00
|
|
|
template <typename T> struct
|
2010-07-28 17:17:30 -05:00
|
|
|
rust_proxy : public maybe_proxy<T>,
|
2010-07-19 16:05:18 -05:00
|
|
|
public dom_owned<rust_proxy<T> > {
|
2010-07-28 17:17:30 -05:00
|
|
|
private:
|
|
|
|
bool _strong;
|
2010-07-19 16:05:18 -05:00
|
|
|
public:
|
|
|
|
rust_dom *dom;
|
2010-07-28 17:17:30 -05:00
|
|
|
rust_proxy(rust_dom *dom, T *delegate, bool strong) :
|
|
|
|
maybe_proxy<T> (delegate), _strong(strong), dom(dom) {
|
|
|
|
this->dom->log(rust_log::COMM,
|
|
|
|
"new proxy: 0x%" PRIxPTR " => 0x%" PRIxPTR, this, delegate);
|
|
|
|
if (strong) {
|
|
|
|
delegate->ref();
|
|
|
|
}
|
2010-07-19 16:05:18 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-28 02:36:35 -05:00
|
|
|
//
|
|
|
|
// 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:
|
|
|
|
//
|
|
|
|
|
2010-07-19 16:05:18 -05:00
|
|
|
#endif /* RUST_PROXY_H */
|