Annotation of driverkit/Examples/IOStub/main.m, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: /*     Copyright (c) 1992 NeXT Computer, Inc.  All rights reserved. 
                     25:  *
                     26:  * main.m - top-level module for IOStub example, Distributed Objects
                     27:  *         version.
                     28:  *
                     29:  * HISTORY
                     30:  * 09-Jun-92    Doug Mitchell at NeXT
                     31:  *      Created. 
                     32:  */
                     33: 
                     34: #import "IOStub.h"
                     35: #import <driverkit/generalFuncs.h>
                     36: #import <remote/NXConnection.h>
                     37: #import <objc/error.h>
                     38: #import <mach/cthreads.h>
                     39: #import <mach/mach.h>
                     40: #import <driverkit/debugging.h>
                     41: 
                     42: #define        NUM_STUB_DEVICES        2
                     43: #define        THREADS_PER_DEVICE      2
                     44: 
                     45: int main(int arcg, char **argv)
                     46: {
                     47:        id stub;
                     48:        id roserver;
                     49:        int stubNum;
                     50:        int threadNum;
                     51:        
                     52:        IOInitDDM(500, "IOStubXpr");
                     53:        IOInitGeneralFuncs();
                     54:        for(stubNum=0; stubNum<NUM_STUB_DEVICES; stubNum++) {
                     55:                stub = [[IOStub alloc] init];
                     56:                if(stub == nil) {
                     57:                        IOLog("IOSTub: can\'t init\n");
                     58:                        exit(1);
                     59:                }
                     60:                if([stub initStub:stubNum] == nil) {
                     61:                        IOLog("IOStub: initStub failed\n");
                     62:                        exit(1);
                     63:                }
                     64:                
                     65:                /*
                     66:                 * Set up an NXConnection, the means by which all clients
                     67:                 * communicate with us.
                     68:                 */
                     69:                NX_DURING {
                     70:                        roserver = [NXConnection registerRoot:stub
                     71:                                 withName:[stub name]];
                     72:                } NX_HANDLER {
                     73:                        IOLog("registerRoot raised %d\n", 
                     74:                                NXLocalHandler.code);
                     75:                        exit(1);
                     76:                } NX_ENDHANDLER
                     77:                
                     78:                if(roserver == nil) {
                     79:                        IOLog("registerRoot returned nil\n");
                     80:                        exit(1);
                     81:                }
                     82:                
                     83:                /*
                     84:                 * Start up "API threads".
                     85:                 */
                     86:                for(threadNum=0; threadNum<THREADS_PER_DEVICE; threadNum++) {
                     87:                        NX_DURING {
                     88:                                [roserver runInNewThread];
                     89:                        } NX_HANDLER {
                     90:                                IOLog("runInNewThread raised %d\n", 
                     91:                                        NXLocalHandler.code);
                     92:                                exit(1);
                     93:                        } NX_ENDHANDLER;
                     94:                }
                     95:        } 
                     96:        
                     97:        /*
                     98:         * Success. This thread is done; all subsequent work is done by 
                     99:         * the IOStub objects' I/O threads (started in initStub:) and
                    100:         * by the NXProxy threads.
                    101:         */
                    102:        cthread_exit(0);
                    103:        return 0;       
                    104: }
                    105: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.