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 CFReleaseNull(queueName); 21 } 22 23 24 25 Source::~Source() 26 { 27 if (mLastValue != NULL) 28 { 29 CFReleaseNull(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 // is there an existing value? If so, release it 52 CFReleaseNull(mLastValue); 53 54 mLastValue = CFRetainSafe(value); 55 } 56 57 58 59 Boolean Source::Equal(const CoreFoundationObject* obj) 60 { 61 if (CoreFoundationObject::Equal(obj)) 62 { 63 const Source* objSource = (const Source*) obj; 64 if (objSource->mDestination == mDestination && 65 CFStringCompare(objSource->mDestinationName, mDestinationName, 0) == kCFCompareEqualTo) 66 { 67 return true; 68 } 69 } 70 71 return false; 72 } 73 74 75 76 std::string Source::DebugDescription() 77 { 78 string result = CoreFoundationObject::DebugDescription() + ": Source "; 79 80 char buffer[256]; 81 sprintf(buffer, "(Destination = %p, name = %s)", mDestination, StringFromCFString(mDestinationName).c_str()); 82 83 result += buffer; 84 85 return result; 86 } 87