Annotation of driverkit/libDriver/User/ddmServer.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) 1991 NeXT Computer, Inc.  All rights reserved. 
                     25:  *
                     26:  * ddmServer.m - user-level ddm server module.
                     27:  *
                     28:  * HISTORY
                     29:  * 22-Feb-91    Doug Mitchell at NeXT
                     30:  *      Created. 
                     31:  */
                     32: 
                     33: #import <bsd/sys/types.h>
                     34: #import <driverkit/debugging.h>
                     35: #import <driverkit/ddmPrivate.h>
                     36: #import <driverkit/debuggingMsg.h>
                     37: #import <driverkit/generalFuncs.h>
                     38: #ifdef KERNEL
                     39: #import <m68k/dev/ldd.h>
                     40: #import <mach/mach_interface.h>
                     41: #else  KERNEL
                     42: #import <mach/mach.h>
                     43: #import <bsd/libc.h>
                     44: #endif KERNEL
                     45: #import <servers/netname.h>
                     46: #import <machkit/NXLock.h>
                     47: 
                     48: static void ddmGetString(IODDMMsg *msgp);
                     49: 
                     50: /*
                     51:  * xpr server thread. This advertises specified port name with the nmserver,
                     52:  * the looops waiting for incoming requests from an XPR Viewer app. These
                     53:  * requests are generally either IODDMMasks set operations or requests for
                     54:  * strings cooked up from xprArray. 
                     55:  */
                     56: volatile void xprServerThread(char *portName)
                     57: {
                     58:        port_name_t xprServerPort, sigPort;
                     59:        kern_return_t krtn;
                     60:        netname_name_t regname;
                     61:        IODDMMsg *msgp;
                     62:        
                     63: 
                     64:        /*
                     65:         * Set up port which external utility uses to communicate with us.
                     66:         */
                     67:        krtn = port_allocate(task_self(), &xprServerPort);
                     68:        if(krtn) {
                     69:                IOLog("xprServerThread: port_allocate returned %d\n", krtn);
                     70:                IOExitThread();
                     71:        }
                     72:        krtn = port_allocate(task_self(), &sigPort);
                     73:        if(krtn) {
                     74:                IOLog("xprServerThread: port_allocate returned %d\n", krtn);
                     75:                IOExitThread();
                     76:        }
                     77:        strcpy(regname, portName);
                     78:        krtn = netname_check_in(name_server_port,
                     79:                regname,
                     80:                sigPort,
                     81:                xprServerPort);
                     82:        if(krtn) {
                     83:                IOLog("xprServerThread: netname_check_in returned %d\n", krtn);
                     84:                IOExitThread();
                     85:        }
                     86: 
                     87:        msgp = IOMalloc(sizeof(*msgp));
                     88:        
                     89:        /*
                     90:         * Main loop. 
                     91:         */
                     92:        while(1) {
                     93:                msgp->header.msg_local_port = xprServerPort;
                     94:                msgp->header.msg_size = sizeof(*msgp);
                     95:                krtn = msg_receive(&msgp->header, MSG_OPTION_NONE, 0);
                     96:                if(krtn) {
                     97:                        IOLog("xprServerThread: msg_receive returned %d\n",
                     98:                                krtn);
                     99:                        continue;
                    100:                }
                    101:                msgp->status = IO_DDM_SUCCESS;
                    102:                switch(msgp->header.msg_id) {
                    103:                    case IO_LOCK_DDM_MSG:
                    104:                        [xprLock lock];
                    105:                        xprLocked = 1;
                    106:                        [xprLock unlock];
                    107:                        break;
                    108:                    case IO_UNLOCK_DDM_MSG:
                    109:                        [xprLock lock];
                    110:                        xprLocked = 0;
                    111:                        [xprLock unlock];
                    112:                        break;
                    113:                    case IO_GET_DDM_ENTRY_MSG:
                    114:                        ddmGetString(msgp);
                    115:                        break;
                    116:                    case IO_SET_DDM_MASK_MSG:
                    117:                        IOSetDDMMask(msgp->index, msgp->maskValue);
                    118:                        break;
                    119:                    case IO_CLEAR_DDM_MSG:
                    120:                        IOClearDDM();
                    121:                        break;
                    122:                    default:
                    123:                        IOLog("xprServerThread: bogus msg_id (0x%x)\n",
                    124:                                (u_int)msgp->header.msg_id);
                    125:                        break;
                    126:                }
                    127:                
                    128:                /*
                    129:                 * Return message.
                    130:                 */
                    131:                krtn = msg_send(&msgp->header, MSG_OPTION_NONE, 0);
                    132:                if(krtn) {
                    133:                        IOLog("xprServerThread: msg_send returned %d\n", krtn);
                    134:                        continue;
                    135:                }
                    136:                
                    137:        }
                    138:        /* NOT REACHED */       
                    139: }
                    140: 
                    141: /*
                    142:  * Cook up one xpr string from the entry in xprArray[msgp->index] prior to 
                    143:  * xprLast, stash it in msgp->string. xprLocked really should be true here, but
                    144:  * if it isn't, that's the XPRViewer utility's problem.
                    145:  */
                    146: static void ddmGetString(IODDMMsg *msgp)
                    147: {
                    148:        unsigned long long timestamp;
                    149:        
                    150:        if(IOGetDDMEntry(msgp->index,
                    151:                IO_DDM_STRING_LENGTH,
                    152:                msgp->string,
                    153:                &timestamp,
                    154:                &msgp->cpuNumber)) {
                    155:                
                    156:                msgp->status = IO_NO_DDM_BUFFER;
                    157:        }
                    158:        else {
                    159:                msgp->timestampLowInt = (unsigned)timestamp; 
                    160:                msgp->timestampHighInt  = (unsigned)(timestamp >> 32);
                    161:        }
                    162:        return;
                    163: }

unix.superglobalmegacorp.com

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