| 185 | | } |
|---|
| 186 | | |
|---|
| 187 | | int ExecuteOnMainThread( id target, SEL sel, void * p_arg ) |
|---|
| 188 | | { |
|---|
| 189 | | int i_ret = 0; |
|---|
| 190 | | |
|---|
| 191 | | //NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 192 | | |
|---|
| 193 | | if( [target respondsToSelector: @selector(performSelectorOnMainThread: |
|---|
| 194 | | withObject:waitUntilDone:)] ) |
|---|
| 195 | | { |
|---|
| 196 | | [target performSelectorOnMainThread: sel |
|---|
| 197 | | withObject: [NSValue valueWithPointer: p_arg] |
|---|
| 198 | | waitUntilDone: NO]; |
|---|
| 199 | | } |
|---|
| 200 | | else if( NSApp != nil && [[VLCMain sharedInstance] respondsToSelector: @selector(getIntf)] ) |
|---|
| 201 | | { |
|---|
| 202 | | NSValue * o_v1; |
|---|
| 203 | | NSValue * o_v2; |
|---|
| 204 | | NSArray * o_array; |
|---|
| 205 | | NSPort * o_recv_port; |
|---|
| 206 | | NSInvocation * o_inv; |
|---|
| 207 | | NSPortMessage * o_msg; |
|---|
| 208 | | intf_thread_t * p_intf; |
|---|
| 209 | | NSConditionLock * o_lock; |
|---|
| 210 | | NSMethodSignature * o_sig; |
|---|
| 211 | | |
|---|
| 212 | | id * val[] = { &o_lock, &o_v2 }; |
|---|
| 213 | | |
|---|
| 214 | | p_intf = (intf_thread_t *)VLCIntf; |
|---|
| 215 | | |
|---|
| 216 | | o_recv_port = [[NSPort port] retain]; |
|---|
| 217 | | o_v1 = [NSValue valueWithPointer: val]; |
|---|
| 218 | | o_v2 = [NSValue valueWithPointer: p_arg]; |
|---|
| 219 | | |
|---|
| 220 | | o_sig = [target methodSignatureForSelector: sel]; |
|---|
| 221 | | o_inv = [NSInvocation invocationWithMethodSignature: o_sig]; |
|---|
| 222 | | [o_inv setArgument: &o_v1 atIndex: 2]; |
|---|
| 223 | | [o_inv setTarget: target]; |
|---|
| 224 | | [o_inv setSelector: sel]; |
|---|
| 225 | | |
|---|
| 226 | | o_array = [NSArray arrayWithObject: |
|---|
| 227 | | [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]]; |
|---|
| 228 | | o_msg = [[NSPortMessage alloc] |
|---|
| 229 | | initWithSendPort: p_intf->p_sys->o_sendport |
|---|
| 230 | | receivePort: o_recv_port components: o_array]; |
|---|
| 231 | | |
|---|
| 232 | | o_lock = [[NSConditionLock alloc] initWithCondition: 0]; |
|---|
| 233 | | [o_msg sendBeforeDate: [NSDate distantPast]]; |
|---|
| 234 | | [o_lock lockWhenCondition: 1]; |
|---|
| 235 | | [o_lock unlock]; |
|---|
| 236 | | [o_lock release]; |
|---|
| 237 | | |
|---|
| 238 | | [o_msg release]; |
|---|
| 239 | | [o_recv_port release]; |
|---|
| 240 | | } |
|---|
| 241 | | else |
|---|
| 242 | | { |
|---|
| 243 | | i_ret = 1; |
|---|
| 244 | | } |
|---|
| 245 | | |
|---|
| 246 | | //[o_pool release]; |
|---|
| 247 | | |
|---|
| 248 | | return( i_ret ); |
|---|