]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_transform/lib/Source.cpp
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / libsecurity_transform / lib / Source.cpp
1 #include "Source.h"
2 #include "Utilities.h"
3 #include "c++utils.h"
4
5 #include <string>
6
7 using namespace std;
8
9 Source::Source(CFStringRef sourceObjectName, Transform* destination, CFStringRef destinationName) :
10 CoreFoundationObject(sourceObjectName),
11 mDestination(destination),
12 mDestinationName(destinationName)
13 {
14 CFStringRef queueName = CFStringCreateWithFormat(NULL, NULL, CFSTR("source:%@"), sourceObjectName);
15 char *queueName_cstr = utf8(queueName);
16
17 mLastValue = NULL;
18 mDispatchQueue = MyDispatchQueueCreate(queueName_cstr, NULL);
19 free((void*)queueName_cstr);
20 CFRelease(queueName);
21 }
22
23
24
25 Source::~Source()
26 {
27 if (mLastValue != NULL)
28 {
29 CFRelease(mLastValue);
30 }
31
32 dispatch_release(mDispatchQueue);
33 }
34
35
36
37 void Source::Activate()
38 {
39 dispatch_async(mDispatchQueue, ^{DoActivate();});
40 }
41
42
43
44 void Source::SetValue(CFTypeRef value)
45 {
46 if (value == mLastValue)
47 {
48 return;
49 }
50
51 if (mLastValue != NULL) // is there an existing value? If so, release it
52 {
53 CFRelease(mLastValue);
54 }
55
56 if (value != NULL)
57 {
58 mLastValue = CFRetain(value);
59 }
60 else
61 {
62 mLastValue = NULL;
63 }
64 }
65
66
67
68 Boolean Source::Equal(const CoreFoundationObject* obj)
69 {
70 if (CoreFoundationObject::Equal(obj))
71 {
72 const Source* objSource = (const Source*) obj;
73 if (objSource->mDestination == mDestination &&
74 CFStringCompare(objSource->mDestinationName, mDestinationName, 0) == kCFCompareEqualTo)
75 {
76 return true;
77 }
78 }
79
80 return false;
81 }
82
83
84
85 std::string Source::DebugDescription()
86 {
87 string result = CoreFoundationObject::DebugDescription() + ": Source ";
88
89 char buffer[256];
90 sprintf(buffer, "(Destination = %p, name = %s)", mDestination, StringFromCFString(mDestinationName).c_str());
91
92 result += buffer;
93
94 return result;
95 }
96