#include <CoreFoundation/CFBridgingPriv.h>
#include <uuid/uuid.h>
#include "CFODContext.h"
#include "internal.h"
#include "transaction.h"
#include "context_internal.h"
struct __ODContext {
CFRuntimeBase _base;
ODNodeRef _node;
CFDataRef _uuid;
};
static CFTypeID __kODContextTypeID = _kCFRuntimeNotATypeID;
static void
__ODContextFinalize(CFTypeRef cf)
{
ODContextRef context = (ODContextRef)cf;
CFArrayRef response;
uint32_t code;
response = transaction_simple(&code, _NodeGetSession(context->_node), context->_node, CFSTR("ODContextRelease"), 1, context->_uuid);
if (response != NULL) {
CFRelease(response);
}
CFRelease(context->_node);
CFRelease(context->_uuid);
}
static CFStringRef
__ODContextCopyDebugDesc(CFTypeRef cf)
{
ODContextRef context = (ODContextRef)cf;
uuid_string_t uuidstr;
uuid_unparse_upper(CFDataGetBytePtr(context->_uuid), uuidstr);
return CFStringCreateWithFormat(NULL, NULL, CFSTR("<ODContext %p [node: %@] [uuid: %s]>"), context, ODNodeGetName(context->_node), uuidstr);
}
static const CFRuntimeClass __ODContextClass = {
0, "ODContext", NULL, NULL, __ODContextFinalize, NULL, NULL, NULL, __ODContextCopyDebugDesc, NULL, #if CF_REFCOUNT_AVAILABLE
NULL, #endif
};
CFTypeID
ODContextGetTypeID(void)
{
static dispatch_once_t once;
dispatch_once(&once, ^ {
__kODContextTypeID = _CFRuntimeRegisterClass(&__ODContextClass);
if (__kODContextTypeID != _kCFRuntimeNotATypeID) {
_CFRuntimeBridgeClasses(__kODContextTypeID, "NSODContext");
}
});
return __kODContextTypeID;
}
ODContextRef
_ODContextCreateWithNodeAndUUID(CFAllocatorRef allocator, ODNodeRef node, CFDataRef uuid)
{
struct __ODContext *context = NULL;
if (uuid != NULL) {
context = (struct __ODContext *)_CFRuntimeCreateInstance(allocator, ODContextGetTypeID(), sizeof(struct __ODContext) - sizeof(CFRuntimeBase), NULL);
context->_node = (ODNodeRef)CFRetain(node);
context->_uuid = CFRetain(uuid);
}
return context;
}
CFDataRef
_ODContextGetUUID(ODContextRef context)
{
if (context != NULL) {
return context->_uuid;
}
return NULL;
}