45 #include "CACFMachPort.h"
46 #include "CAException.h"
47 #include "CADebugMacros.h"
54 CACFMachPort::CACFMachPort(CFMachPortCallBack inCallBack,
void* inUserData)
60 CFMachPortContext theContext = { 1, inUserData, NULL, NULL, NULL };
61 mMachPort = CFMachPortCreate(NULL, inCallBack, &theContext, NULL);
62 ThrowIfNULL(mMachPort, CAException(
'what'),
"CACFMachPort::CACFMachPort(s): couldn't create the CFMachPort");
64 mRunLoopSource = CFMachPortCreateRunLoopSource(NULL, mMachPort, 0);
65 if(mRunLoopSource == NULL)
67 CFMachPortInvalidate(mMachPort);
70 DebugMessage(
"CACFMachPort::CACFMachPort(s): couldn't create the CFRunLoopSource");
71 throw CAException(
'what');
83 CACFMachPort::CACFMachPort(mach_port_t inMachPort, CFMachPortCallBack inCallBack, CFMachPortInvalidationCallBack inInvalidationCallBack,
void* inUserData)
89 CFMachPortContext theContext = { 1, inUserData, NULL, NULL, NULL };
91 if(inMachPort == MACH_PORT_NULL)
93 mMachPort = CFMachPortCreate(NULL, inCallBack, &theContext, NULL);
94 ThrowIfNULL(mMachPort, CAException(
'what'),
"CACFMachPort::CACFMachPort: couldn't create the CFMachPort");
99 mMachPort = CFMachPortCreateWithPort(NULL, inMachPort, inCallBack, &theContext, NULL);
100 ThrowIfNULL(mMachPort, CAException(
'what'),
"CACFMachPort::CACFMachPort: couldn't create the CFMachPort with a port");
104 mRunLoopSource = CFMachPortCreateRunLoopSource(NULL, mMachPort, 0);
105 if(mRunLoopSource == NULL)
109 CFMachPortInvalidate(mMachPort);
111 CFRelease(mMachPort);
113 DebugMessage(
"CACFMachPort::CACFMachPort: couldn't create the CFRunLoopSource");
114 throw CAException(
'what');
117 if(inInvalidationCallBack != NULL)
119 CFMachPortSetInvalidationCallBack(mMachPort, inInvalidationCallBack);
123 CACFMachPort::~CACFMachPort()
125 if(mRunLoopSource != NULL)
127 CFRelease(mRunLoopSource);
130 if(mMachPort != NULL)
134 CFMachPortInvalidate(mMachPort);
136 CFRelease(mMachPort);