0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

Apple CF wrapper: renamed OWN/BORROW.

In keeping with Apple terminology, do the following renames:

  CF::BORROW -> CF::GET
  CF::OWN -> CF::CREATE

This more clearly ties into Apple's "Get" and "Create" rules
for object allocation and wrapping.

Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
James Yonan 2017-04-12 12:20:02 -06:00
parent 962fe87103
commit 10eb7233f2
3 changed files with 23 additions and 19 deletions

View File

@ -126,7 +126,7 @@ namespace openvpn {
void thread_func()
{
runloop.reset(CFRunLoopGetCurrent(), CF::BORROW);
runloop.reset(CFRunLoopGetCurrent(), CF::GET);
Log::Context logctx(logwrap);
try {
// set up dynamic store query object

View File

@ -50,7 +50,7 @@
{ \
CFTypeRef o = Type<cftype>::cast(obj); \
if (o) \
return cls(cftype(o), BORROW); \
return cls(cftype(o), GET); \
else \
return cls(); \
}
@ -58,9 +58,9 @@
namespace openvpn {
namespace CF
{
enum Own {
OWN,
BORROW
enum Rule {
CREATE, // create rule
GET // get rule
};
template <typename T> struct Type {};
@ -71,10 +71,9 @@ namespace openvpn {
public:
Wrap() : obj_(nullptr) {}
// Set own=BORROW if we don't currently own the object
explicit Wrap(T obj, const Own own=OWN)
explicit Wrap(T obj, const Rule rule=CREATE)
{
if (own == BORROW && obj)
if (rule == GET && obj)
CFRetain(obj);
obj_ = obj;
}
@ -116,9 +115,9 @@ namespace openvpn {
std::swap(obj_, other.obj_);
}
void reset(T obj=nullptr, const Own own=OWN)
void reset(T obj=nullptr, const Rule rule=CREATE)
{
if (own == BORROW && obj)
if (rule == GET && obj)
CFRetain(obj);
if (obj_)
CFRelease(obj_);
@ -127,15 +126,20 @@ namespace openvpn {
bool defined() const { return obj_ != nullptr; }
explicit operator bool() const noexcept
{
return defined();
}
T operator()() const { return obj_; }
CFTypeRef generic() const { return (CFTypeRef)obj_; }
static T cast(CFTypeRef obj) { return T(Type<T>::cast(obj)); }
static Wrap from_generic(CFTypeRef obj, const Own own=OWN)
static Wrap from_generic(CFTypeRef obj, const Rule rule=CREATE)
{
return Wrap(cast(obj), own);
return Wrap(cast(obj), rule);
}
T release()
@ -153,7 +157,7 @@ namespace openvpn {
}
// Intended for use with Core Foundation methods that require
// a T* for saving a (non-borrowed) return value
// a T* for saving a create-rule return value
T* mod_ref()
{
if (obj_)
@ -179,7 +183,7 @@ namespace openvpn {
}
private:
Wrap& operator=(T obj); // prevent use because no way to pass ownership parameter
Wrap& operator=(T obj) = delete; // prevent use because no way to pass rule parameter
T obj_;
};
@ -202,7 +206,7 @@ namespace openvpn {
inline Generic generic_cast(CFTypeRef obj)
{
return Generic(obj, BORROW);
return Generic(obj, GET);
}
// constructors
@ -214,7 +218,7 @@ namespace openvpn {
inline String string(CFStringRef str)
{
return String(str, BORROW);
return String(str, GET);
}
inline String string(const String& str)
@ -274,12 +278,12 @@ namespace openvpn {
inline Dict const_dict(MutableDict& mdict)
{
return Dict(mdict(), CF::BORROW);
return Dict(mdict(), CF::GET);
}
inline Array const_array(MutableArray& marray)
{
return Array(marray(), CF::BORROW);
return Array(marray(), CF::GET);
}
inline Dict empty_dict()

View File

@ -183,7 +183,7 @@ namespace openvpn {
// as well.
void thread_func()
{
runloop.reset(CFRunLoopGetCurrent(), CF::BORROW);
runloop.reset(CFRunLoopGetCurrent(), CF::GET);
Log::Context logctx(logwrap);
try {