Wired Networking  2.0
Objective-C implementation of the Wired 2.0 protocol
WIThread.m
00001 /* $Id$ */
00002 
00003 /*
00004  *  Copyright (c) 2006-2009 Axel Andersson
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *  1. Redistributions of source code must retain the above copyright
00011  *     notice, this list of conditions and the following disclaimer.
00012  *  2. Redistributions in binary form must reproduce the above copyright
00013  *     notice, this list of conditions and the following disclaimer in the
00014  *     documentation and/or other materials provided with the distribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
00020  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00023  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00024  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00025  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #import <WiredNetworking/WIThread.h>
00030 
00031 @interface WIThread(Private)
00032 
00033 + (void)_threadTrampoline:(id)arg;
00034 
00035 @end
00036 
00037 
00038 @implementation WIThread(Private)
00039 
00040 + (void)_threadTrampoline:(id)arg {
00041                 NSInvocation    *invocation = arg;
00042 
00043                 wi_thread_enter_thread();
00044                 
00045                 [invocation invoke];
00046 
00047                 wi_thread_exit_thread();
00048 }
00049 
00050 @end
00051 
00052 
00053 
00054 @implementation WIThread
00055 
00056 + (void)load {
00057                 NSAutoreleasePool               *pool;
00058                 NSArray                                                         *arguments;
00059                 const char                                      **argv;
00060                 int                                                                             i, argc;
00061                 
00062                 wi_initialize();
00063 
00064                 pool                            = [[NSAutoreleasePool alloc] init];
00065                 arguments       = [[NSProcessInfo processInfo] arguments];
00066                 argc                            = (int) [arguments count];
00067                 argv                            = malloc(argc);
00068 
00069                 for(i = 0; i < argc; i++)
00070                                 argv[i] = [[arguments objectAtIndex:i] UTF8String];
00071 
00072                 wi_load(argc, argv);
00073                 free(argv);
00074                 
00075                 [pool release];
00076 
00077                 wi_log_stderr = true;
00078                 wi_log_level = WI_LOG_DEBUG;
00079 }
00080 
00081 
00082 
00083 #pragma mark -
00084 
00085 + (void)detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)argument {
00086                 NSInvocation    *invocation;
00087                 
00088                 invocation = [NSInvocation invocationWithTarget:target action:selector];
00089                 [invocation setArgument:&argument atIndex:2];
00090                 [invocation retainArguments];
00091                 
00092                 [super detachNewThreadSelector:@selector(_threadTrampoline:) toTarget:self withObject:invocation];
00093 }
00094 
00095 @end
 All Classes