1 /* Copyright (c) 2012-2013 Apple Inc. All Rights Reserved. */
3 #include "connection.h"
10 struct _connection_s
{
11 __AUTH_BASE_STRUCT_HEADER__
;
15 dispatch_queue_t dispatch_queue
;
16 dispatch_queue_t dispatch_queue_internal
;
17 bool sent_syslog_warn
;
21 _connection_finalize(CFTypeRef value
)
23 connection_t conn
= (connection_t
)value
;
25 process_remove_connection(conn
->proc
, conn
);
27 dispatch_barrier_sync(conn
->dispatch_queue
, ^{});
28 dispatch_barrier_sync(conn
->dispatch_queue_internal
, ^{});
30 CFReleaseNull(conn
->proc
);
31 CFReleaseNull(conn
->engine
);
32 dispatch_release(conn
->dispatch_queue
);
33 dispatch_release(conn
->dispatch_queue_internal
);
36 AUTH_TYPE_INSTANCE(connection
,
39 .finalize
= _connection_finalize
,
42 .copyFormattingDesc
= NULL
,
46 static CFTypeID
connection_get_type_id() {
47 static CFTypeID type_id
= _kCFRuntimeNotATypeID
;
48 static dispatch_once_t onceToken
;
50 dispatch_once(&onceToken
, ^{
51 type_id
= _CFRuntimeRegisterClass(&_auth_type_connection
);
58 connection_create(process_t proc
)
60 connection_t conn
= NULL
;
62 conn
= (connection_t
)_CFRuntimeCreateInstance(kCFAllocatorDefault
, connection_get_type_id(), AUTH_CLASS_SIZE(connection
), NULL
);
63 require(conn
!= NULL
, done
);
65 conn
->proc
= (process_t
)CFRetain(proc
);
66 conn
->dispatch_queue
= dispatch_queue_create(NULL
, DISPATCH_QUEUE_SERIAL
);
67 conn
->dispatch_queue_internal
= dispatch_queue_create(NULL
, DISPATCH_QUEUE_SERIAL
);
73 pid_t
connection_get_pid(connection_t conn
)
75 return process_get_pid(conn
->proc
);
78 process_t
connection_get_process(connection_t conn
)
83 dispatch_queue_t
connection_get_dispatch_queue(connection_t conn
)
85 return conn
->dispatch_queue
;
88 void connection_set_engine(connection_t conn
, engine_t engine
)
90 dispatch_sync(conn
->dispatch_queue_internal
, ^{
92 CFReleaseNull(conn
->engine
);
93 conn
->engine
= (engine_t
)CFRetain(engine
);
95 CFReleaseNull(conn
->engine
);
100 void connection_destroy_agents(connection_t conn
)
102 dispatch_sync(conn
->dispatch_queue_internal
, ^{
104 engine_destroy_agents(conn
->engine
);
109 bool connection_get_syslog_warn(connection_t conn
)
111 return conn
->sent_syslog_warn
;
114 void connection_set_syslog_warn(connection_t conn
)
116 conn
->sent_syslog_warn
= true;