Common.h

/*------------------------------------------------------------------------------
#
#   Macintosh Developer Technical Support
#
#   Sample Control Panel Device and INIT Combination
#
#   Program:    INIT - CDEV
#   File:       Common.h    -   C Header for CDEV.c and INIT.c
#
#   Copyright © 1990 Apple Computer, Inc.
#   All rights reserved.
#
------------------------------------------------------------------------------*/
 
#include <Types.h>
#include <Errors.h>
#include <Events.h>
#include <Folders.h>
#include <Gestalt.h>
#include <PLStringFuncs.h>
#include <PPCToolBox.h>
#include <Script.h>
 
 
/*  Information about our preferences file. We keep the name, file type, and
    creator type stored here. If we ever change the creator type, we'd have
    to modify kCreator. */
 
#define kPrefsFileName "\pBackground Beeper Prefs"
#define kCreator 'INCD'
#define kDocKind 'PREF'
 
 
/*  Common constants. kGetCommonGlobalsPtr is the message number we send to the
    INIT when we want it to return a pointer to its globals. If we wanted to ask
    it other things, we could define more message numbers. kBufferSize is the
    size of the buffer we use for messaging. Currently, we only return a pointer
    as data, so 256 is way overkill. However, if we define other messages that
    could result in the transfer of more data, 256 bytes could some in handy. */
    
enum {kGetCommonGlobalsPtr = 1000};
enum {kBufferSize = 256};
 
 
/*  Format of the public globals. The INIT uses these two fields when
    determining when to beep. When the user closes the CDEV, the two values
    are updated in memory, and are written out to the preferences file. */
 
typedef struct {
    short           timesToBeep;
    long            beepInterval;
} CommonGlobalsRec, *CommonGlobalsPtr;
 
 
/*  This struct is used for our PPC communications. It consists of five parts.
    The first field is a parameter block large enough for any PPC call. We
    use that parameter block for all of our calls. We only make one call at 
    a time, so this is OK. The next three fields are used as extended
    information for the PPC parameter block. The parameter block needs to 
    have some pointers to additional information stored in it. To keep
    everything together, we keep that extra information along with the
    parameter block. Finally, we have the buffer that's used for transferring
    information in PPCRead and PPCWrite calls. This is also kept with the
    parameter block so that when we get to the Read/Write portion of our
    show, we have a handy buffer at a known offset from the parameter block. */
    
typedef struct {
    PPCParamBlockRec    pb;
    PPCPortRec          portName;
    LocationNameRec     locationName;
    Str255              userName;
    char                buffer[kBufferSize];
} SessionRecord, *SessionPtr;
 
 
/*  When the INIT receives a message number, it has to decide what information
    to return. This information is stored in the buffer in the SessionRecord
    and then we make a PPCWrite call. Depending on the message number, we
    might have to return different kinds of information. To make this
    easier, we define different structs to overlay on top of the buffer.
    Since we only have one message number (get the pointer to the global
    variables), we have only one struct overlay, which is below. However,
    we could easily add more. We could even merge them all together into a
    union, and define our buffer to be the size of the union. */
 
typedef struct {
    CommonGlobalsPtr    commonGlobalsAddress;       // <- return the address of our globals here
} GetCommonGlobalsRecord, *GetCommonGlobalsPtr;