]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDHandle.c
configd-24.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDHandle.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <SystemConfiguration/SCD.h>
24 #include "SCDPrivate.h"
25
26
27 SCDHandleRef
28 SCDHandleInit()
29 {
30 SCDHandlePrivateRef privateHandle = CFAllocatorAllocate(NULL, sizeof(SCDHandlePrivate), 0);
31
32 /* set data */
33 privateHandle->data = NULL;
34
35 /* set instance */
36 privateHandle->instance = 0;
37
38 return (SCDHandleRef)privateHandle;
39 }
40
41
42 void
43 SCDHandleRelease(SCDHandleRef handle)
44 {
45 SCDHandlePrivateRef privateHandle = (SCDHandlePrivateRef)handle;
46
47 if (privateHandle->data)
48 CFRelease(privateHandle->data);
49
50 CFAllocatorDeallocate(NULL, privateHandle);
51 return;
52 }
53
54
55 int
56 SCDHandleGetInstance(SCDHandleRef handle)
57 {
58 SCDHandlePrivateRef privateHandle = (SCDHandlePrivateRef)handle;
59
60 return privateHandle->instance;
61 }
62
63
64 void
65 _SCDHandleSetInstance(SCDHandleRef handle, int instance)
66 {
67 SCDHandlePrivateRef privateHandle = (SCDHandlePrivateRef)handle;
68
69 privateHandle->instance = instance;
70 return;
71 }
72
73
74 CFPropertyListRef
75 SCDHandleGetData(SCDHandleRef handle)
76 {
77 SCDHandlePrivateRef privateHandle = (SCDHandlePrivateRef)handle;
78
79 if (privateHandle->data == NULL) {
80 return CFSTR("SCDHandleRef not initialized.");
81 }
82
83 return privateHandle->data;
84 }
85
86
87 void
88 SCDHandleSetData(SCDHandleRef handle, CFPropertyListRef data)
89 {
90 SCDHandlePrivateRef privateHandle = (SCDHandlePrivateRef)handle;
91
92 /* remove reference to data previously associated with handle */
93 if (privateHandle->data)
94 CFRelease(privateHandle->data);
95
96 /* associate new data with handle, keep a reference as needed */
97 privateHandle->data = data;
98 if (privateHandle->data)
99 CFRetain(privateHandle->data);
100
101 return;
102 }