OpenTransportKernel.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:55k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       OpenTransportKernel.h
  3.  
  4.      Contains:   Definitions for Open Transport kernel code, such as drivers and protocol modules.
  5.  
  6.      Version:    Technology: 2.5
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1993-2001 by Apple Computer, Inc. and Mentat Inc., all rights reserved.
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __OPENTRANSPORTKERNEL__
  18. #define __OPENTRANSPORTKERNEL__
  19. #ifdef OTKERNEL
  20. #if !OTKERNEL
  21. #error OpenTransportModule.h can only be used by kernel code.
  22. #endif  /* !OTKERNEL */
  23. #endif  /* defined(OTKERNEL) */
  24. #define OTKERNEL 1
  25. /*
  26.    We include "OpenTransportProtocol.h", which in turn includes
  27.    "OpenTransport.h", thereby picking up all the stuff which
  28.    is shared between client and kernel.
  29. */
  30. #ifndef __OPENTRANSPORTPROTOCOL__
  31. #include "OpenTransportProtocol.h"
  32. #endif
  33. #ifndef __NAMEREGISTRY__
  34. #include "NameRegistry.h"
  35. #endif
  36. #if PRAGMA_ONCE
  37. #pragma once
  38. #endif
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. #if PRAGMA_IMPORT
  43. #pragma import on
  44. #endif
  45. #if PRAGMA_STRUCT_ALIGN
  46.     #pragma options align=mac68k
  47. #elif PRAGMA_STRUCT_PACKPUSH
  48.     #pragma pack(push, 2)
  49. #elif PRAGMA_STRUCT_PACK
  50.     #pragma pack(2)
  51. #endif
  52. #if defined(__MWERKS__) && TARGET_CPU_68K
  53.  #pragma push
  54.    #pragma pointers_in_D0
  55. #endif
  56. /* ***** From the Mentat "mistream.h" ******/
  57. /*
  58.    Parts of "mistream.h" that are shared by the client
  59.    and the kernel are in "OpenTransportProtocol.h".
  60. */
  61. /** Re-allow a queue to be scheduled for service */
  62. #define enableok(q)    ((q)->q_flag &= ~QNOENB)
  63. /** Prevent a queue from being scheduled */
  64. #define noenable(q)   ((q)->q_flag |= QNOENB)
  65. /** Get pointer to the mate queue */
  66. #define OTHERQ(q)     (((q)->q_flag & QREADR) ? WR(q) : RD(q))
  67. /** Get pointer to the read queue, assumes 'q' is a write queue ptr */
  68. #define RD(q)  (&q[-1])
  69. /** Get pointer to the write queue, assumes 'q' is a read queue ptr */
  70. #define WR(q)  (&q[1])
  71. #if CALL_NOT_IN_CARBON
  72. EXTERN_API_C( mblk_t *)
  73. allocb                          (OTByteCount            size,
  74.                                  OTInt32                pri);
  75. #endif  /* CALL_NOT_IN_CARBON */
  76. typedef CALLBACK_API_C( void , allocbiProc )(char *arg);
  77. #if CALL_NOT_IN_CARBON
  78. EXTERN_API_C( mblk_t *)
  79. allocbi                         (OTByteCount            size,
  80.                                  OTInt32                pri,
  81.                                  allocbiProc            pfv,
  82.                                  char *                 arg,
  83.                                  unsigned char *        base);
  84. EXTERN_API_C( queue_t *)
  85. allocq                          (void);
  86. EXTERN_API_C( OTInt32 )
  87. adjmsg                          (mblk_t *               mp,
  88.                                  OTInt32                len_param);
  89. EXTERN_API_C( queue_t *)
  90. backq                           (queue_t *              q);
  91. EXTERN_API_C( OTInt32 )
  92. bcanput                         (queue_t *              q,
  93.                                  OTUInt8Param           pri);
  94. EXTERN_API_C( OTInt32 )
  95. bcanputnext                     (queue_t *              q,
  96.                                  OTUInt8Param           pri);
  97. EXTERN_API_C( OTInt32 )
  98. bufcall                         (OTByteCount            memNeeded,
  99.                                  OTInt32                pri,
  100.                                  bufcallp_t             proc,
  101.                                  long                   context);
  102. EXTERN_API_C( OTInt32 )
  103. canput                          (queue_t *              q);
  104. EXTERN_API_C( OTInt32 )
  105. canputnext                      (queue_t *              q);
  106. EXTERN_API_C( mblk_t *)
  107. copyb                           (mblk_t *               mp);
  108. EXTERN_API_C( mblk_t *)
  109. copymsg                         (mblk_t *               mp);
  110. EXTERN_API_C( mblk_t *)
  111. dupb                            (mblk_t *               mp);
  112. EXTERN_API_C( mblk_t *)
  113. dupmsg                          (mblk_t *               mp);
  114. EXTERN_API_C( mblk_t *)
  115. esballoc                        (unsigned char *        base,
  116.                                  OTByteCount            size,
  117.                                  OTInt32                pri,
  118.                                  frtn_t *               freeInfo);
  119. EXTERN_API_C( mblk_t *)
  120. esballoca                       (unsigned char *        base,
  121.                                  OTByteCount            size,
  122.                                  OTInt32                pri,
  123.                                  frtn_t *               freeInfo);
  124. #endif  /* CALL_NOT_IN_CARBON */
  125. typedef CALLBACK_API_C( void , esbbcallProc )(long arg);
  126. #if CALL_NOT_IN_CARBON
  127. EXTERN_API_C( OTInt32 )
  128. esbbcall                        (OTInt32                pri,
  129.                                  esbbcallProc           func,
  130.                                  long                   arg);
  131. EXTERN_API_C( void )
  132. flushband                       (queue_t *              q,
  133.                                  OTUInt8Param           pri,
  134.                                  OTInt32                flag);
  135. EXTERN_API_C( void )
  136. flushq                          (queue_t *              q,
  137.                                  OTInt32                flag);
  138. EXTERN_API_C( void )
  139. freeb                           (mblk_t *               mp);
  140. EXTERN_API_C( void )
  141. freemsg                         (mblk_t *               mp);
  142. EXTERN_API_C( OTInt32 )
  143. freeq                           (queue_t *              q);
  144. EXTERN_API_C( OTInt32 )
  145. freezestr                       (queue_t *              q);
  146. EXTERN_API_C( admin_t )
  147. getadmin                        (OTUInt16Param          mid);
  148. EXTERN_API_C( unsigned short )
  149. getmid                          (char *                 name);
  150. EXTERN_API_C( mblk_t *)
  151. getq                            (queue_t *              q);
  152. EXTERN_API_C( OTInt32 )
  153. insq                            (queue_t *              q,
  154.                                  mblk_t *               emp,
  155.                                  mblk_t *               nmp);
  156. EXTERN_API_C( void )
  157. linkb                           (mblk_t *               mp1,
  158.                                  mblk_t *               mp2);
  159. #endif  /* CALL_NOT_IN_CARBON */
  160. typedef CALLBACK_API_C( void , mpnotifyProc )(char *arg);
  161. #if CALL_NOT_IN_CARBON
  162. EXTERN_API_C( OTInt32 )
  163. mpnotify                        (mblk_t *               mp,
  164.                                  mpnotifyProc           pfv,
  165.                                  char *                 arg);
  166. EXTERN_API_C( OTInt32 )
  167. msgdsize                        (const mblk_t *         mp);
  168. EXTERN_API_C( mblk_t *)
  169. msgpullup                       (mblk_t *               mp,
  170.                                  OTInt32                len);
  171. EXTERN_API_C( OTInt32 )
  172. pullupmsg                       (mblk_t *               mp,
  173.                                  OTInt32                len);
  174. EXTERN_API_C( OTInt32 )
  175. put                             (queue_t *              q,
  176.                                  mblk_t *               mp);
  177. EXTERN_API_C( OTInt32 )
  178. putbq                           (queue_t *              q,
  179.                                  mblk_t *               mp);
  180. EXTERN_API_C( OTInt32 )
  181. putctl                          (queue_t *              q,
  182.                                  OTInt32                mType);
  183. EXTERN_API_C( OTInt32 )
  184. putnextctl                      (queue_t *              q,
  185.                                  OTInt32                mType);
  186. EXTERN_API_C( OTInt32 )
  187. putctl1                         (queue_t *              q,
  188.                                  OTInt32                mType,
  189.                                  OTInt32                c);
  190. EXTERN_API_C( OTInt32 )
  191. putnextctl1                     (queue_t *              q,
  192.                                  OTInt32                mType,
  193.                                  OTInt32                c);
  194. EXTERN_API_C( OTInt32 )
  195. putctl2                         (queue_t *              q,
  196.                                  OTInt32                mType,
  197.                                  OTInt32                c1,
  198.                                  OTInt32                c2);
  199. #endif  /* CALL_NOT_IN_CARBON */
  200. #ifndef puthere
  201. #if CALL_NOT_IN_CARBON
  202. EXTERN_API_C( OTInt32 )
  203. puthere                         (queue_t *              q,
  204.                                  mblk_t *               mp);
  205. #endif  /* CALL_NOT_IN_CARBON */
  206. #endif  /* !defined(puthere) */
  207. #if CALL_NOT_IN_CARBON
  208. EXTERN_API_C( OTInt32 )
  209. putnext                         (queue_t *              q,
  210.                                  mblk_t *               mp);
  211. EXTERN_API_C( OTInt32 )
  212. putq                            (queue_t *              q,
  213.                                  mblk_t *               mp);
  214. #endif  /* CALL_NOT_IN_CARBON */
  215. #if CALL_NOT_IN_CARBON
  216. EXTERN_API_C( void )
  217. qenable                         (queue_t *              q);
  218. EXTERN_API_C( void )
  219. qprocson                        (queue_t *              q);
  220. EXTERN_API_C( void )
  221. qprocsoff                       (queue_t *              q);
  222. EXTERN_API_C( OTInt32 )
  223. qreply                          (queue_t *              q,
  224.                                  mblk_t *               mp);
  225. EXTERN_API_C( OTInt32 )
  226. qsize                           (queue_t *              q);
  227. EXTERN_API_C( mblk_t *)
  228. rmvb                            (mblk_t *               mp,
  229.                                  mblk_t *               bp);
  230. EXTERN_API_C( void )
  231. rmvq                            (queue_t *              q,
  232.                                  mblk_t *               mp);
  233. /* prototype for strlog in "strlog.h" section, below */
  234. EXTERN_API_C( OTInt32 )
  235. strqget                         (queue_t *              q,
  236.                                  qfields_t              what,
  237.                                  OTUInt8Param           pri,
  238.                                  long *                 valp);
  239. EXTERN_API_C( OTInt32 )
  240. strqset                         (queue_t *              q,
  241.                                  qfields_t              what,
  242.                                  OTUInt8Param           pri,
  243.                                  long                   val);
  244. EXTERN_API_C( OTInt32 )
  245. testb                           (OTByteCount            size,
  246.                                  OTInt32                pri);
  247. EXTERN_API_C( void )
  248. unbufcall                       (OTInt32                id);
  249. EXTERN_API_C( void )
  250. unfreezestr                     (queue_t *              q,
  251.                                  OTInt32                oldpri);
  252. EXTERN_API_C( mblk_t *)
  253. unlinkb                         (mblk_t *               mp);
  254. /* ***** From the Mentat "strlog.h" ******/
  255. EXTERN_API_C( OTInt32 )
  256. strlog                          (OTInt32                mid,
  257.                                  OTInt32                sid,
  258.                                  OTInt32                level,
  259.                                  OTUInt32               flags,
  260.                                  char *                 fmt,
  261.                                  ...);
  262. /* ***** Printing Functions ******/
  263. #endif  /* CALL_NOT_IN_CARBON */
  264. enum {
  265.     kOTPrintOnly                = 0,
  266.     kOTPrintThenStop            = 1
  267. };
  268. #if CALL_NOT_IN_CARBON
  269. EXTERN_API_C( OTInt32 )
  270. OTKernelPrintf                  (OTInt32                toDo,
  271.                                  char *                 fmt,
  272.                                  ...);
  273. #endif  /* CALL_NOT_IN_CARBON */
  274. enum {
  275.     CE_CONT                     = 0,                            /* Does kOTPrintOnly   */
  276.     CE_NOTE                     = 0,                            /* Just print */
  277.     CE_WARN                     = 1,                            /* Does kOTPrintThenStop  */
  278.     CE_PANIC                    = 2                             /* Does System Error 107  */
  279. };
  280. #if CALL_NOT_IN_CARBON
  281. EXTERN_API_C( void )
  282. cmn_err                         (OTInt32                errType,
  283.                                  char *                 fmt,
  284.                                  ...);
  285. EXTERN_API_C( OTInt32 )
  286. mi_sprintf                      (char *                 buf,
  287.                                  char *                 fmt,
  288.                                  ...);
  289. /* Create sprintf and printf functions that will work in STREAM modules.*/
  290. #define sprintf                        mi_sprintf
  291. #define printf                       OTKernelPrintf
  292. /* ***** FIIK ******/
  293. /* ooo useful header comment please ooo*/
  294. /*
  295.    Function to convert the "long" value that comes back in some of the
  296.    netbufs as a result code to the equivalent OSStatus
  297. */
  298. #endif  /* CALL_NOT_IN_CARBON */
  299. typedef long                            OTError;
  300. #define GetEError(v)           ((OTUnixErr)(((v) >> 16) & 0xffff))
  301. #define GetXTIError(v)          ((OTXTIErr)((v) & 0xffff))
  302. #define MakeTPIEError(e)     ((OTError)(((((UInt16)(e)) << 16) | TSYSERR)))
  303. #define MakeDLPIEError(e)        ((OTError)(((((UInt16)(e)) << 16) | DL_SYSERR)))
  304. #define MakeXTIError(xti)      ((OTError)(xti))
  305. #define MakeOTError(xti, e)        ((OTError)((xti) | ((UInt16)(e)) << 16))
  306. #if CALL_NOT_IN_CARBON
  307. EXTERN_API_C( OSStatus )
  308. OTErrorToOSStatus               (OTError                err);
  309. /* ***** STREAMS Plug-in Interface *****/
  310. /*
  311.    Synchronization level codes.  These are supplied to modsw_install and
  312.    stored in the appropriate tables.  sth_osr_open and
  313.    sth_ipush use these to set up synch queue subordination for new devices
  314.    and modules.
  315. */
  316. #endif  /* CALL_NOT_IN_CARBON */
  317. enum {
  318.     SQLVL_QUEUE                 = 1,
  319.     SQLVL_QUEUEPAIR             = 2,
  320.     SQLVL_MODULE                = 3,
  321.     SQLVL_GLOBAL                = 4,
  322.     SQLVL_DEFAULT               = 3
  323. };
  324. /* The install_info structure.*/
  325. struct install_info {
  326.     streamtab *                     install_str;                /* Streamtab pointer.     */
  327.     UInt32                          install_flags;
  328.     UInt32                          install_sqlvl;              /* Synchronization level. */
  329.     char *                          install_buddy;              /* Shared writer list buddy */
  330.     long                            ref_load;                   /* Set to 0             */
  331.     UInt32                          ref_count;                  /* set to 0             */
  332. };
  333. typedef struct install_info             install_info;
  334. /*  Flags used in the install_flags field*/
  335. enum {
  336.     kOTModIsDriver              = 0x00000001,
  337.     kOTModIsModule              = 0x00000002,
  338.     kOTModNoWriter              = 0x00000010,
  339.     kOTModUpperIsTPI            = 0x00001000,
  340.     kOTModUpperIsDLPI           = 0x00002000,
  341.     kOTModLowerIsTPI            = 0x00004000,
  342.     kOTModLowerIsDLPI           = 0x00008000,
  343.     kOTModGlobalContext         = 0x00800000,                   /* This flag says you don't want per-context globals*/
  344.     kOTModUsesInterrupts        = 0x08000000,                   /* This flag is only valid if kOTModIsDriver is set and the driver is a PCI-card driver using the Name Registry*/
  345.     kOTModIsComplexDriver       = 0x20000000,                   /* This flag is only valid if kOTModIsDriver is set.*/
  346.     kOTModIsFilter              = 0x40000000                    /* This flag is only valid if kOTModIsModule is set.*/
  347. };
  348. /* Typedef for the GetOTInstallInfo function*/
  349. /*
  350.    Your module must export this function, and return a pointer to the
  351.    install_info structure for the module.
  352. */
  353. typedef CALLBACK_API_C( install_info *, GetOTInstallInfoProcPtr )(void );
  354. /* Typedef for the InitStreamModule function*/
  355. /*
  356.    Your module can optionally export this function.  It will be called 
  357.    whenever your module is about to be loaded into a stream for the
  358.    first time, or if it is about to be reloaded after having been 
  359.    unloaded. Return false if your module should NOT be loaded.
  360.    For STREAMS modules, the void* parameter will be NULL.  For drivers, it
  361.    will be the same cookie parameter that was used for registering the module.
  362.    For PCI card drivers, this will be a pointer to the OTPCIInfo structure,
  363.    which can also be interpreted as a RegEntryIDPtr.
  364. */
  365. typedef CALLBACK_API_C( Boolean , InitStreamModuleProcPtr )(void *portInfo);
  366. /* Typedef for the TerminateStreamModule function*/
  367. /*
  368.    Your module can optionally export this function.  It will be called 
  369.    whenever your module has been closed for the last time (i.e. no other 
  370.    outstanding instances of the module exist).
  371. */
  372. typedef CALLBACK_API_C( void , TerminateStreamModuleProcPtr )(void *portInfo);
  373. /* Equates for shared library prefixes*/
  374.     
  375.    /*
  376.   * Interface ID for STREAMS Modules for ASLM.
  377.   */
  378. #define kOTModuleInterfaceID     kOTModulePrefix "StrmMod"
  379. /* ***** Majors and Minors ******/
  380. /* Functions for dealing with major and minor device numbers*/
  381. typedef UInt16                          major_t;
  382. typedef UInt16                          minor_t;
  383. /* major part of a device */
  384. #define getmajor(x)       ((major_t)(((unsigned long)(x)>>16)&0xffff))
  385. /* minor part of a device */
  386. #define getminor(x)      ((minor_t)((x)&0xffff))
  387. /* make a device number */
  388. #define makedev(x,y)        ((dev_t)((((dev_t)(x))<<16) | ((y) & 0xffff)))
  389. #define getemajor           getmajor
  390. #define geteminor          getminor
  391. #define makedevice         makedev
  392. #define    etoimajor(majnum)   (majnum)
  393. #define    itoemajor(majnum,j) (majnum)
  394. /*
  395.    This is the first minor number that Apple OT drivers use for CLONEOPENs.
  396.    Minor numbers 0 through 9 are reserved for use by the modules
  397.    for various control streams.  Note that Mentat drivers, which
  398.    use mi_open_comm, start minor numbers from 5.
  399. */
  400. enum {
  401.     kFirstMinorNumber           = 10
  402. };
  403. /* ***** Logging Macros ******/
  404. #if CALL_NOT_IN_CARBON
  405. EXTERN_API_C( void )
  406. OTStrlog                        (queue_t *              q,
  407.                                  OTInt32                lvl,
  408.                                  OTInt32                flags,
  409.                                  const char *           str);
  410. /* These are enums for the level value*/
  411. #endif  /* CALL_NOT_IN_CARBON */
  412. enum {
  413.     kOTLvlFatal                 = 0,
  414.     kOTLvlNonfatal              = 1,
  415.     kOTLvlExtFatal              = 2,
  416.     kOTLvlExtNonfatal           = 3,
  417.     kOTLvlUserErr               = 4,
  418.     kOTLvlInfoErr               = 5,
  419.     kOTLvlInfoOnly              = 6
  420. };
  421. #define STRLOG(q, lvl, flags, str)     OTStrlog(q, lvl, flags, str)
  422. #if OTDEBUG
  423.   #define STRLOG1(q, lvl, flags, str) OTStrlog(q, lvl, flags, str)
  424. #else
  425.  #define STRLOG1(q, lvl, flags, str)
  426. #endif
  427. #if OTDEBUG > 1 || OTDEBUG > 1
  428.  #define STRLOG2(q, lvl, flags, str) OTStrlog(q, lvl, flags, str)
  429. #else
  430.  #define STRLOG2(q, lvl, flags, str)
  431. #endif
  432. /* ***** TPI Additions ******/
  433. /*
  434.    Extra OTCommand codes that may appear on your module queue.
  435.    These are extensions to the TPI specification for Open Transport.
  436.    T_PRIVATE_REQ is the first available TPI message number for private
  437.    use by modules (assuming you don't want to be confused by standard
  438.    TPI messages).
  439. */
  440. enum {
  441.     T_TIMER_REQ     = 80,   /* Timer event                          */
  442.  T_MIB_REQ       = 81,   /* Request module's MIB                 */
  443.  T_MIB_ACK       = 82,   /* The module's MIB is available        */
  444.  
  445.    T_PRIVATE_REQ   = 90    /* The first private request available  */
  446. };
  447. struct T_MIB_req {
  448.     long                            PRIM_type;                  /* Always T_MIB_REQ */
  449. };
  450. typedef struct T_MIB_req                T_MIB_req;
  451. struct T_MIB_ack {
  452.     long                            PRIM_type;                  /* Always T_MIB_ACK   */
  453.     long                            MIB_length;                 /* MIB length          */
  454.     long                            MIB_offset;                 /* MIB Offset         */
  455. };
  456. typedef struct T_MIB_ack                T_MIB_ack;
  457. struct T_stream_timer {
  458.     long                            PRIM_type;                  /* Always T_TIMER_REQ */
  459.     union {
  460.         long                            USER_long;
  461.         void *                          USER_ptr;
  462.     }                                 USER_data;
  463. };
  464. typedef struct T_stream_timer           T_stream_timer;
  465. /* ***** Kernel Port Stuff ******/
  466. /*
  467.    Kernel port record, which is a direct analogue of
  468.    the OTPortRecord in "OpenTransport.h".  Note that
  469.    when working with TPortRecord's, you're always
  470.    working with OT's one true copy of the record,
  471.    whereas when working with OTPortRecord's, you're
  472.    always working with a copy.
  473. */
  474. struct TPortRecord {
  475.     OTLink                          fLink;
  476.     char *                          fPortName;
  477.     char *                          fModuleName;
  478.     char *                          fResourceInfo;
  479.     char *                          fSlotID;
  480.     struct TPortRecord *            fAlias;
  481.     ItemCount                       fNumChildren;
  482.     OTPortRef *                     fChildPorts;
  483.     UInt32                          fPortFlags;
  484.     UInt32                          fInfoFlags;
  485.     UInt32                          fCapabilities;
  486.     OTPortRef                       fRef;
  487.     streamtab *                     fStreamtab;
  488.     void *                          fContext;
  489.     void *                          fExtra;
  490. };
  491. typedef struct TPortRecord              TPortRecord;
  492. /* Port utilities*/
  493. /*
  494.    These routines can be used by kernel code to register, find and iterate
  495.    through the various ports on the machine.  Do not confuse these with
  496.    the client-side routines, defined in "OpenTransport.h".
  497. */
  498. /*
  499.    Register a port. The name the port was registered under is returned in
  500.    the fPortName field.  This routine allocates a TPortRecord and
  501.    copies the supplied OTPortRecord into it.
  502. */
  503. #if CALL_NOT_IN_CARBON
  504. EXTERN_API_C( OSStatus )
  505. OTRegisterPort                  (OTPortRecord *         portInfo,
  506.                                  void *                 ref);
  507. /*
  508.    Unregister the port with the given name (If you re-register the
  509.    port, it may get a different name - use OTChangePortState if
  510.    that is not desireable).  Since a single OTPortRef can be registered
  511.    with several names, the API needs to use the portName rather than
  512.    the OTPortRef to disambiguate.
  513. */
  514. EXTERN_API_C( OSStatus )
  515. OTUnregisterPort                (const char *           portName,
  516.                                  void **                refPtr);
  517. /* Change the state of the port.*/
  518. EXTERN_API_C( OSStatus )
  519. OTChangePortState               (OTPortRef              portRef,
  520.                                  OTEventCode            theChange,
  521.                                  OTResult               why);
  522. /* Find the TPortRecord for a given Port Name*/
  523. EXTERN_API_C( TPortRecord *)
  524. OTFindPort                      (const char *           portName);
  525. /* Find the "nth" TPortRecord*/
  526. EXTERN_API_C( TPortRecord *)
  527. OTGetIndexedPort                (OTItemCount            index);
  528. /*
  529.    Find another port that is active and conflicts with
  530.    the port described by "ref"
  531. */
  532. EXTERN_API_C( TPortRecord *)
  533. OTFindPortConflict              (OTPortRef              ref);
  534. /* Other ways of finding the port*/
  535. EXTERN_API_C( TPortRecord *)
  536. OTFindPortByRef                 (OTPortRef              ref);
  537. EXTERN_API_C( TPortRecord *)
  538. OTFindPortByDev                 (dev_t                  dev);
  539. /* ***** Port Scanners ******/
  540. /* Shared library definitions*/
  541. /*
  542.    Prefix for Open Transport port scanners.
  543.    Your port-scanning ASLM function set must use the prefix kOTPortScannerPrefix.
  544. */
  545. #define kOTPortScannerPrefix        "ot:pScnr$"
  546. /*
  547.    The kOTPortScannerInterfaceID define is what you need to add to your
  548.    export file for the "interfaceID = " clause.  
  549. */
  550. #define kOTPortScannerInterfaceID          kOTKernelPrefix "pScnr"
  551. #define kOTPseudoPortScannerInterfaceID     kOTKernelPrefix "ppScnr"
  552. #define kOTCompatScannerInterfaceID            kOTKernelPrefix "cpScnr,1.0"
  553. #define kOTPortScannerCFMTag              kOTKernelPrefix "pScnr"
  554. #define kOTPseudoPortScannerCFMTag          kOTKernelPrefix "ppScnr"
  555. #define kOTCompatPortScannerCFMTag         kOTKernelPrefix "cpScnr"
  556. /* OTScanPorts entry point.*/
  557. /* Your port-scanning function must be exported by the name "OTScanPorts".*/
  558. #define kOTScanPortsID "OTScanPorts"
  559. /* Selectors for the scanType parameter to PortScanProcPtr.*/
  560. #endif  /* CALL_NOT_IN_CARBON */
  561. enum {
  562.     kOTInitialScan              = 0,
  563.     kOTScanAfterSleep           = 1
  564. };
  565. /* PortScanProcPtr is the typedef for the scanning function.*/
  566. typedef CALLBACK_API_C( void , PortScanProcPtr )(UInt32 scanType);
  567. /*
  568.    Memory allocation for port persistent data, such as the
  569.    memory referenced by the ref parameter you pass to
  570.    OTRegisterPort.
  571. */
  572. #if CALL_NOT_IN_CARBON
  573. EXTERN_API_C( void *)
  574. OTAllocPortMem                  (OTByteCount            size);
  575. EXTERN_API_C( void )
  576. OTFreePortMem                   (void *                 mem);
  577. /* ***** Interrupt Control Functions *****/
  578. #endif  /* CALL_NOT_IN_CARBON */
  579. #if TARGET_CPU_68K
  580. /*
  581.    MPS_INTR_STATE saves the current interrupt state
  582.    Its definition changes with the definition
  583.    of mps_intr_enable/disable, so this typedef is
  584.    also inside the TARGET_CPU_68K conditional.
  585. */
  586. typedef UInt8                           MPS_INTR_STATE;
  587. /* Disable interrupts and save the state*/
  588. #if CALL_NOT_IN_CARBON
  589.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  590.                                                                                             #pragma parameter mps_intr_disable(__A0)
  591.                                                                                             #endif
  592. EXTERN_API_C( void )
  593. mps_intr_disable                (MPS_INTR_STATE *       oldState)                           SEVENWORDINLINE(0x40C0, 0xE040, 0x007C, 0x0600, 0x027C, 0xFEFF, 0x1080);
  594. /*
  595.    move sr,d0
  596.    asr.w #8,d0
  597.    ori #$600,sr
  598.    andi #$FEFF,sr
  599.    move.b d0,(a0)
  600.    #if OTDEBUG
  601.        andi.b #$70,d0
  602.        cmpi.b #$70,d0
  603.        bne.s @3
  604.        DebugBreak
  605.    #endif
  606. */
  607. /* Enable interrupts from the saved state*/
  608.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  609.                                                                                             #pragma parameter mps_intr_enable(__A0)
  610.                                                                                             #endif
  611. EXTERN_API_C( void )
  612. mps_intr_enable                 (MPS_INTR_STATE *       oldState)                           THREEWORDINLINE(0x1010, 0xE140, 0x46C0);
  613. /*
  614.    #if OTDEBUG
  615.        move sr,d0
  616.        andi.w #$700,d0
  617.        cmpi.w #$600,d0
  618.        beq.s @2
  619.        DebugBreak
  620.    #endif
  621.    move.b (a0),d0
  622.    #if OTDEBUG
  623.        andi.b #$70,d0
  624.        cmpi.b #$70,d0
  625.        bne.s @3
  626.        DebugBreak
  627.        move.b (a0),d0
  628.    #endif
  629.    asl.w #8,d0
  630.    move d0,sr
  631. */
  632. #endif  /* CALL_NOT_IN_CARBON */
  633. #else
  634. typedef UInt8                           MPS_INTR_STATE;
  635. #if CALL_NOT_IN_CARBON
  636. EXTERN_API_C( void )
  637. mps_intr_disable                (MPS_INTR_STATE *       oldState);
  638. EXTERN_API_C( void )
  639. mps_intr_enable                 (MPS_INTR_STATE *       oldState);
  640. #endif  /* CALL_NOT_IN_CARBON */
  641. #endif  /* TARGET_CPU_68K */
  642. /* ***** Timer Functions ******/
  643. enum {
  644.     kOTMinimumTimerValue        = 8                             /* 8 milliseconds is the minimum timeout value*/
  645. };
  646. #if CALL_NOT_IN_CARBON
  647. EXTERN_API_C( mblk_t *)
  648. mi_timer_alloc                  (queue_t *              q,
  649.                                  OTByteCount            size);
  650. EXTERN_API_C( void )
  651. mi_timer_free                   (mblk_t *               mp);
  652. EXTERN_API_C( void )
  653. mi_timer                        (mblk_t *               mp,
  654.                                  unsigned long          milliSeconds);
  655. EXTERN_API_C( Boolean )
  656. mi_timer_cancel                 (mblk_t *               mp);
  657. EXTERN_API_C( Boolean )
  658. mi_timer_valid                  (mblk_t *               mp);
  659. EXTERN_API_C( mblk_t *)
  660. mi_timer_q_switch               (mblk_t *               mp,
  661.                                  queue_t *              q,
  662.                                  mblk_t *               new_mp);
  663. /* ***** Driver Deferred Task Extras ******/
  664. /*
  665.    This routine is used by a driver at interrupt time to schedule
  666.    a deferred task to run their interrupt processing code.
  667. */
  668. EXTERN_API_C( Boolean )
  669. OTScheduleDriverDeferredTask    (long                   dtCookie);
  670. /* ***** Driver Memory Routines ******/
  671. /*
  672.    These routines are different from the
  673.    similarly named routines in "OpenTransport.h" because they allocate
  674.    memory in the OT kernel pool.  See Technote oooo "Understanding
  675.    Open Transport Memory Management" for details.
  676. */
  677. /*
  678.    This is the typedef for a function that will be called when a message
  679.    created by OTAllocMsg is destroyed.
  680. */
  681. #endif  /* CALL_NOT_IN_CARBON */
  682. typedef CALLBACK_API_C( void , EsbFreeProcPtr )(char *arg);
  683. /*
  684.    This function creates a message which points to "size" bytes of data
  685.    at "buf".  When the message is freed, the EsbFreeProcPtr function "func"
  686.    will be called with the argument "arg".
  687.    NOTE: This function allows users of your buffer to modify the buffer.
  688. */
  689. #if CALL_NOT_IN_CARBON
  690. EXTERN_API_C( mblk_t *)
  691. OTAllocMsg                      (void *                 buf,
  692.                                  OTByteCount            size,
  693.                                  EsbFreeProcPtr         func,
  694.                                  void *                 arg);
  695. /*
  696.    Routines to allocate and free memory in your modules (these are
  697.    interrupt-time safe!).
  698. */
  699. EXTERN_API_C( void *)
  700. OTAllocMem                      (OTByteCount            size);
  701. EXTERN_API_C( void )
  702. OTFreeMem                       (void *                 mem);
  703. EXTERN_API_C( void *)
  704. OTReallocMem                    (void *                 ptr,
  705.                                  OTByteCount            newSize);
  706. /*
  707.    Also, make sure that calling traditional "C" allocation routines
  708.    will not compile.
  709. */
  710. #define calloc                     (DONT_CALL*THIS_FUNCTION)
  711. #define malloc                        (DONT_CALL*THIS_FUNCTION)
  712. #define realloc                       (DONT_CALL*THIS_FUNCTION)
  713. #define free                      (DONT_CALL*THIS_FUNCTION)
  714. /* ***** Kernel Memory Utilities ******/
  715. EXTERN_API_C( OTInt32 )
  716. mi_bcmp                         (const char *           first,
  717.                                  const char *           second,
  718.                                  OTByteCount            nBytes);
  719. /* Standard STREAMS memory utilities.*/
  720.     
  721. #define bcopy(s, d, l)         OTMemcpy(d, s, l)
  722. #define bzero(d, l)               OTMemzero(d, (OTByteCount)(l))
  723. #define bcmp(s, d, l)            mi_bcmp(s, d, l)
  724. /*
  725.    Standard STREAMS bcopy, bzero, & bcmp take char* parameters.
  726.    The BCOPY, BZERO, and BCMP routines take void* so that we do not have
  727.    to cast all the pointers.
  728. */
  729. #define BCOPY(s, d, l)         bcopy((const char*)(s), (char*)(d), l)
  730. #define BZERO(d, l)              bzero((char*)(d), l)
  731. #define BCMP(s, d, l)          mi_bcmp((const char*)(s), (const char*)(d), l)
  732. /*******************************************************************************
  733. ** Some helpful utilites from Mentat
  734. ********************************************************************************/
  735. /* Routines to calculate various sizes of STREAM messages*/
  736. #define HEAD_SIZE(mp)  ((mp)->b_rptr - (mp)->b_datap->db_base)
  737. #define TAIL_SIZE(mp)   ((mp)->b_datap->db_lim - (mp)->b_wptr)
  738. #define MBLK_SIZE(mp)    ((mp)->b_wptr - (mp)->b_rptr)
  739. #define DBLK_SIZE(mp) ((mp)->b_datap->db_lim - (mp)->b_datap->db_base)
  740. /* Useful macros for STREAMS copy in and out.*/
  741. #define    MI_COPY_IN      1
  742. #define   MI_COPY_OUT     2
  743. #define   MI_COPY_DIRECTION(mp)                            
  744.  (((UInt8*)&(mp)->b_cont->b_prev)[0])
  745. #define    MI_COPY_COUNT(mp)                    
  746.  (((UInt8*)&(mp)->b_cont->b_prev)[1])
  747. #define    MI_COPY_RVAL(mp)    (*(OTInt32 *)&(mp)->b_cont->b_next)
  748. #define MI_COPY_CASE(dir,cnt)   ((OTInt32)(((cnt)<<2)|dir))
  749. #define MI_COPY_STATE(mp)                            
  750.  ((OTInt32)MI_COPY_CASE(MI_COPY_DIRECTION(mp),MI_COPY_COUNT(mp)))
  751. #endif  /* CALL_NOT_IN_CARBON */
  752. typedef CALLBACK_API_C( void , OTWriterProcPtr )(queue_t *q, mblk_t *mp);
  753. #if CALL_NOT_IN_CARBON
  754. EXTERN_API_C( void )
  755. mps_become_writer               (queue_t *              q,
  756.                                  mblk_t *               mp,
  757.                                  OTWriterProcPtr        proc);
  758. EXTERN_API_C( OTInt32 )
  759. drv_priv                        (cred *                 credp);
  760. EXTERN_API_C( queue_t *)
  761. mi_allocq                       (streamtab *            st);
  762. EXTERN_API_C( mblk_t *)
  763. mi_tpi_ack_alloc                (mblk_t *               mp,
  764.                                  OTByteCount            size,
  765.                                  long                   primType);
  766. EXTERN_API_C( mblk_t *)
  767. mi_tpi_conn_con                 (mblk_t *               trailer_mp,
  768.                                  char *                 src,
  769.                                  OTByteCount            src_length,
  770.                                  char *                 opt,
  771.                                  OTByteCount            opt_length);
  772. EXTERN_API_C( mblk_t *)
  773. mi_tpi_conn_ind                 (mblk_t *               trailer_mp,
  774.                                  char *                 src,
  775.                                  OTByteCount            src_length,
  776.                                  char *                 opt,
  777.                                  OTByteCount            opt_length,
  778.                                  OTInt32                seqnum);
  779. EXTERN_API_C( mblk_t *)
  780. mi_tpi_conn_req                 (mblk_t *               trailer_mp,
  781.                                  char *                 dest,
  782.                                  OTByteCount            dest_length,
  783.                                  char *                 opt,
  784.                                  OTByteCount            opt_length);
  785. EXTERN_API_C( mblk_t *)
  786. mi_tpi_data_ind                 (mblk_t *               trailer_mp,
  787.                                  OTInt32                flags,
  788.                                  long                   ptype);
  789. EXTERN_API_C( mblk_t *)
  790. mi_tpi_data_req                 (mblk_t *               trailer_mp,
  791.                                  OTInt32                flags,
  792.                                  long                   pttype);
  793. EXTERN_API_C( mblk_t *)
  794. mi_tpi_discon_ind               (mblk_t *               trailer_mp,
  795.                                  OTInt32                reason,
  796.                                  OTInt32                seqnum);
  797. EXTERN_API_C( mblk_t *)
  798. mi_tpi_discon_req               (mblk_t *               trailer_mp,
  799.                                  OTInt32                seqnum);
  800. EXTERN_API_C( mblk_t *)
  801. mi_tpi_err_ack_alloc            (mblk_t *               mp,
  802.                                  OTInt32                tlierr,
  803.                                  OTInt32                unixerr);
  804. EXTERN_API_C( mblk_t *)
  805. mi_tpi_exdata_ind               (mblk_t *               trailer_mp,
  806.                                  OTInt32                flags,
  807.                                  long                   ptype);
  808. EXTERN_API_C( mblk_t *)
  809. mi_tpi_exdata_req               (mblk_t *               trailer_mp,
  810.                                  OTInt32                flags,
  811.                                  long                   ptype);
  812. EXTERN_API_C( mblk_t *)
  813. mi_tpi_info_req                 (void);
  814. EXTERN_API_C( mblk_t *)
  815. mi_tpi_ok_ack_alloc             (mblk_t *               mp);
  816. EXTERN_API_C( mblk_t *)
  817. mi_tpi_ordrel_ind               (void);
  818. EXTERN_API_C( mblk_t *)
  819. mi_tpi_ordrel_req               (void);
  820. EXTERN_API_C( mblk_t *)
  821. mi_tpi_uderror_ind              (char *                 dest,
  822.                                  OTByteCount            dest_length,
  823.                                  char *                 opt,
  824.                                  OTByteCount            opt_length,
  825.                                  OTInt32                error);
  826. EXTERN_API_C( mblk_t *)
  827. mi_tpi_unitdata_ind             (mblk_t *               trailer_mp,
  828.                                  char *                 src,
  829.                                  OTByteCount            src_length,
  830.                                  char *                 opt,
  831.                                  OTByteCount            opt_length);
  832. EXTERN_API_C( mblk_t *)
  833. mi_tpi_unitdata_req             (mblk_t *               trailer_mp,
  834.                                  char *                 dst,
  835.                                  OTByteCount            dst_length,
  836.                                  char *                 opt,
  837.                                  OTByteCount            opt_length);
  838. EXTERN_API_C( mblk_t *)
  839. mi_reuse_proto                  (mblk_t *               toReuse,
  840.                                  OTByteCount            sizeDesired,
  841.                                  OTBooleanParam         keepOnError);
  842. EXTERN_API_C( mblk_t *)
  843. mi_reallocb                     (mblk_t *               old_mp,
  844.                                  OTByteCount            new_size);
  845. EXTERN_API_C( Boolean )
  846. mi_set_sth_hiwat                (queue_t *              q,
  847.                                  OTByteCount            size);
  848. EXTERN_API_C( Boolean )
  849. mi_set_sth_lowat                (queue_t *              q,
  850.                                  OTByteCount            size);
  851. EXTERN_API_C( Boolean )
  852. mi_set_sth_maxblk               (queue_t *              q,
  853.                                  OTByteCount            size);
  854. EXTERN_API_C( Boolean )
  855. mi_set_sth_wroff                (queue_t *              q,
  856.                                  OTByteCount            size);
  857. EXTERN_API_C( UInt8 *)
  858. mi_offset_param                 (mblk_t *               mp,
  859.                                  long                   offset,
  860.                                  long                   len);
  861. EXTERN_API_C( UInt8 *)
  862. mi_offset_paramc                (mblk_t *               mp,
  863.                                  long                   offset,
  864.                                  long                   len);
  865. #endif  /* CALL_NOT_IN_CARBON */
  866. #if CALL_NOT_IN_CARBON
  867. EXTERN_API_C( char *)
  868. mi_open_detached                (char **                mi_opp_orig,
  869.                                  OTByteCount            size,
  870.                                  dev_t *                devp);
  871. EXTERN_API_C( OTInt32 )
  872. mi_open_comm                    (char **                mi_opp_orig,
  873.                                  OTByteCount            size,
  874.                                  queue_t *              q,
  875.                                  dev_t *                dev,
  876.                                  OTInt32                flag,
  877.                                  OTInt32                sflag,
  878.                                  cred_t *               credp);
  879. EXTERN_API_C( OTInt32 )
  880. mi_close_comm                   (char **                mi_opp_orig,
  881.                                  queue_t *              q);
  882. EXTERN_API_C( void )
  883. mi_bufcall                      (queue_t *              q,
  884.                                  OTByteCount            size,
  885.                                  OTInt32                pri);
  886. EXTERN_API_C( void )
  887. mi_detach                       (queue_t *              q,
  888.                                  char *                 ptr);
  889. EXTERN_API_C( void )
  890. mi_close_detached               (char **                mi_opp_orig,
  891.                                  char *                 ptr);
  892. EXTERN_API_C( char *)
  893. mi_next_ptr                     (char *                 ptr);
  894. EXTERN_API_C( void )
  895. mi_copyin                       (queue_t *              q,
  896.                                  mblk_t *               mp,
  897.                                  char *                 uaddr,
  898.                                  OTByteCount            len);
  899. EXTERN_API_C( void )
  900. mi_copyout                      (queue_t *              q,
  901.                                  mblk_t *               mp);
  902. EXTERN_API_C( mblk_t *)
  903. mi_copyout_alloc                (queue_t *              q,
  904.                                  mblk_t *               mp,
  905.                                  char *                 uaddr,
  906.                                  OTByteCount            len);
  907. EXTERN_API_C( void )
  908. mi_copy_done                    (queue_t *              q,
  909.                                  mblk_t *               mp,
  910.                                  OTInt32                err);
  911. EXTERN_API_C( void )
  912. mi_copy_set_rval                (mblk_t *               mp,
  913.                                  OTInt32                rval);
  914. EXTERN_API_C( OTInt32 )
  915. mi_copy_state                   (queue_t *              q,
  916.                                  mblk_t *               mp,
  917.                                  mblk_t **              mpp);
  918. /* ***** PCI-Specific Stuff*/
  919. /* This is the cookie that is passed to your STREAM Module.*/
  920. #endif  /* CALL_NOT_IN_CARBON */
  921. struct OTPCIInfo {
  922.     RegEntryID                      fTheID;
  923.     void *                          fConfigurationInfo;
  924.     ByteCount                       fConfigurationLength;
  925. };
  926. typedef struct OTPCIInfo                OTPCIInfo;
  927. /* Driver Description*/
  928. /*
  929.    All PCI card drivers should have the following bits set in their
  930.    install_info structure:
  931.    
  932.    o kOTModIsDriver.
  933.    
  934.    They should NEVER have the kOTModPushAlways or the kOTModIsModule
  935.    flags set.
  936.    The kOTModIsLowerMux bits should be set if the driver is a lower
  937.    multiplexor, although Open Transport does nothing with the information
  938.    today.
  939.    The kOTModUpperIsDLPI bit should be set if the driver uses the DLPI message
  940.    specification.  The kOTModUpperIsTPI bit should be set if the driver uses
  941.    the TPI message specification.
  942. */
  943. /*
  944.    Macro to put together the driverServices.service[x].serviceType field:
  945.    xxxxxddd dddddddd ffffffff xxxxxxTD
  946.    where "d" is the device type for Open Transport,
  947.    the lower two bits are whether the driver is TPI or DLPI,
  948.    and the "f" bits are the framing option flags.
  949.    and all other bits should be 0
  950. */
  951. #define OTPCIServiceType(devType, framingFlags, isTPI, isDLPI) 
  952.   ((devType << 16) | (((framingFlags) & 0xff) << 8) | (isTPI ? 2 : 0) | (isDLPI ? 1 : 0 ))
  953. /*
  954.    Typedef for the ValidateHardware function.  This function will be
  955.    called only once, at system boot time, before installing your driver
  956.    into the Open Transport module registry.
  957.    The param pointer will is a OTPCIInfo pointer - don't be changing the
  958.    values there!
  959. */
  960. typedef CALLBACK_API_C( OTResult , ValidateHardwareProcPtr )(OTPCIInfo *param);
  961. /*
  962.    Your driver can return this value if it loaded correctly
  963.    but wants to stay resident, presumably because it's hooked
  964.    itself irrevokably into some other system service.
  965. */
  966. enum {
  967.     kOTPCINoErrorStayLoaded     = 1
  968. };
  969. /*
  970.    Some descriptors we use - these should eventually show up
  971.    in system header files somewhere.
  972. */
  973. #define kDescriptorProperty        "driver-descriptor"
  974. #define kDriverProperty         "driver,AAPL,MacOS,PowerPC"
  975. #define kDriverPtrProperty      "driver-ptr"
  976. #define kSlotProperty          "AAPL,slot-name"
  977. /*
  978.    Maximum # of services support by Open Transport.  If your module
  979.    exports more than this # of services, Open Transport will not be
  980.    able to use the module.
  981. */
  982. enum {
  983.     kMaxServices                = 20
  984. };
  985. /*******************************************************************************
  986. ** Everything below here is C++ ONLY
  987. ********************************************************************************/
  988. #ifdef __cplusplus
  989. }                   // Terminate C definitions
  990. /*  -------------------------------------------------------------------------
  991.     TStreamQueue class
  992.     
  993.     This class is just a convenient interface to the queue structure
  994.     ------------------------------------------------------------------------- */
  995.     class TStreamQueue : public queue
  996.     {
  997.         public:
  998.             void        EnableQueue();
  999.     };
  1000.     
  1001.     /*  -------------------------------------------------------------------------
  1002.         Inline methods for TStreamQueue
  1003.         ------------------------------------------------------------------------- */
  1004.     
  1005.         inline void TStreamQueue::EnableQueue()
  1006.         {
  1007.             if ( q_flag & QNOENB )
  1008.             {
  1009.                 enableok(this);
  1010.                 if ( q_first )
  1011.                     qenable(this);
  1012.             }
  1013.         }
  1014. /*  -------------------------------------------------------------------------
  1015.     Class TStreamMessage
  1016.     
  1017.     This class is a C++ interface to the mblk_t structure defined in STREAMS
  1018.     ------------------------------------------------------------------------- */
  1019.     //
  1020.     // The maximum stream buffer size is the largest OTByteCount that
  1021.     // doesn't look negative if interpreted as a signed number
  1022.     //
  1023.     enum
  1024.     {
  1025.         kMaxStreamBufferSize    = (((OTByteCount)-1L) >> 1)
  1026.     };
  1027.     class TStreamMessage : public msgb
  1028.     {
  1029.         private:
  1030.                 void*       operator new (OTByteCount)  { return NULL; }
  1031.                 
  1032.         public:
  1033.                 void*       operator new(OTByteCount, OTByteCount size)
  1034.                     { return (TStreamMessage*)allocb(size, 0); }
  1035.                 void*       operator new(OTByteCount, void* buf, OTByteCount size,
  1036.                                          EsbFreeProcPtr func, void* arg)
  1037.                     { return OTAllocMsg(buf, size, func, arg); }
  1038.                 void        operator delete(void* ptr)
  1039.                     { if ( ptr != NULL ) freemsg((mblk_t*)ptr); }
  1040.     
  1041.                     void            Reset(OTByteCount = 0);
  1042.                     void            ResetWithLeader(OTByteCount);
  1043.             
  1044.                     void            FreeData();
  1045.                     TStreamMessage* RemoveData();
  1046.                     void            AppendData(TStreamMessage* data);
  1047.             
  1048.                     OTByteCount GetSize() const;
  1049.                     OTByteCount GetDataSize() const;
  1050.                     OTByteCount GetMessageDataSize() const;
  1051.                     void                SetDataSize(OTByteCount);
  1052.         
  1053.                     void            SetType(UInt8);
  1054.                     UInt8           GetType() const;
  1055.                     TStreamMessage* GetNextBlock() const;
  1056.                     TStreamMessage* ReuseMessage(OTByteCount newSize, OTBooleanParam keepOnFailure);
  1057.                     
  1058.                     void            SetNextBlock(TStreamMessage*);
  1059.                     char*           GetDataPointer() const;
  1060.                     Boolean         IsReuseable(OTByteCount size) const;
  1061.             
  1062.                     void            HideBytesAtFront(OTByteCount);
  1063.                     void            HideBytesAtEnd(OTByteCount);
  1064.             //
  1065.             // The following functions ignore non-M_DATA blocks.
  1066.             //
  1067.                     const TStreamMessage*
  1068.                                     _MDECL GetBlockAt(OTByteCount& offset) const;
  1069.                     const void*     _MDECL GetPointerTo(OTByteCount offset, OTByteCount* len) const;
  1070.                     const void*     _MDECL GetPointerTo(OTByteCount offset, OTByteCount* len, void* bfr) const;
  1071.             //
  1072.             // This function makes a non-shared copy of any initial non-M_DATA block, and
  1073.             // then makes shared copies of the requested data.  It only assumes 1 leading
  1074.             // non-M_DATA block, but will skip any other non-M_DATA blocks while 
  1075.             // searching for data to copy.
  1076.             //
  1077.                     TStreamMessage* _MDECL MakeSharedCopy(OTByteCount offset = 0, 
  1078.                                                           OTByteCount len = kMaxStreamBufferSize);
  1079.                     Boolean         _MDECL HasData() const;
  1080.                     Boolean         _MDECL WriteData(void* buf, OTByteCount len);
  1081.             //
  1082.             // These hide/remove the part of the data already read.  
  1083.             //
  1084.                     TStreamMessage* _MDECL ReadData(void* buf, OTByteCount* len);
  1085.                     OTByteCount     _MDECL ReadControl(void* buf, OTByteCount len);
  1086.     };
  1087.     
  1088.     /*  -------------------------------------------------------------------------
  1089.         Inline methods for TStreamMessage
  1090.         ------------------------------------------------------------------------- */
  1091.     
  1092.         inline void TStreamMessage::Reset(OTByteCount size)
  1093.         {
  1094.             b_rptr = b_datap->db_base;
  1095.             b_wptr = b_rptr + size;
  1096.         }
  1097.         
  1098.         inline OTByteCount OTLengthWithLeader(OTByteCount size)
  1099.         {
  1100.             return (size + 3) & ~3;
  1101.         }
  1102.         
  1103.         inline void TStreamMessage::ResetWithLeader(OTByteCount size)
  1104.         {
  1105.             b_rptr = b_datap->db_lim - OTLengthWithLeader(size);
  1106.             b_wptr = b_rptr + size;
  1107.         }
  1108.         
  1109.         inline void TStreamMessage::FreeData()
  1110.         {
  1111.             if ( b_cont )
  1112.             {
  1113.                 freemsg(b_cont);
  1114.                 b_cont = NULL;
  1115.             }
  1116.         }
  1117.         
  1118.         inline TStreamMessage* TStreamMessage::RemoveData()
  1119.         {
  1120.             TStreamMessage* temp = (TStreamMessage*)b_cont;
  1121.             b_cont = NULL;
  1122.             return temp;
  1123.         }
  1124.         
  1125.         inline void TStreamMessage::AppendData(TStreamMessage* mp)
  1126.         {
  1127.             linkb(this, mp);
  1128.         }
  1129.     
  1130.         inline OTByteCount TStreamMessage::GetSize() const
  1131.         {
  1132.             return b_datap->db_lim - b_datap->db_base;
  1133.         }
  1134.         
  1135.         inline OTByteCount TStreamMessage::GetDataSize() const
  1136.         {
  1137.             return b_wptr - b_rptr;
  1138.         }
  1139.         
  1140.         inline OTByteCount TStreamMessage::GetMessageDataSize() const
  1141.         {
  1142.             return (b_cont == NULL) ? 
  1143.                 (b_datap->db_type == M_DATA ? (b_wptr - b_rptr) : 0) : msgdsize(this);
  1144.         }
  1145.     
  1146.         inline void TStreamMessage::SetDataSize(OTByteCount size)
  1147.         {
  1148.             b_wptr = b_rptr + size;
  1149.         }
  1150.     
  1151.         inline void TStreamMessage::SetType(UInt8 type)
  1152.         {
  1153.             b_datap->db_type = type;
  1154.         }
  1155.     
  1156.         inline unsigned char TStreamMessage::GetType() const
  1157.         {
  1158.             return b_datap->db_type;
  1159.         }
  1160.         
  1161.         inline TStreamMessage* TStreamMessage::GetNextBlock() const
  1162.         {
  1163.             return (TStreamMessage*)b_cont;
  1164.         }
  1165.         
  1166.         inline void TStreamMessage::SetNextBlock(TStreamMessage* mp)
  1167.         {
  1168.             b_cont = (mblk_t*)mp;
  1169.         }
  1170.         
  1171.         inline char* TStreamMessage::GetDataPointer() const
  1172.         {
  1173.             return (char*)b_rptr;
  1174.         }
  1175.         
  1176.         inline Boolean TStreamMessage::IsReuseable(OTByteCount size) const
  1177.         {
  1178.             return (b_datap->db_ref == 1 && GetSize() >= size);
  1179.         }
  1180.         
  1181.         inline void TStreamMessage::HideBytesAtFront(OTByteCount len)
  1182.         {
  1183.             adjmsg(this, len);
  1184.         }
  1185.         
  1186.         inline void TStreamMessage::HideBytesAtEnd(OTByteCount len)
  1187.         {
  1188.             adjmsg(this, -len);
  1189.         }
  1190.         inline TStreamMessage* TStreamMessage::ReuseMessage(OTByteCount newSize, OTBooleanParam keepOnFailure)
  1191.         {
  1192.             return (TStreamMessage*)mi_reuse_proto(this, newSize, keepOnFailure);
  1193.         }
  1194.         
  1195. /*  -------------------------------------------------------------------------
  1196.     TTimerMessage class
  1197.     
  1198.     This class implements an interface to the STREAM environment timer
  1199.     facilities.  A TTimerMessage will be placed on the queue of your choice
  1200.     when it's timer expires.
  1201.     ------------------------------------------------------------------------- */
  1202. #if TARGET_CPU_PPC
  1203.     #define TIMER_BUG   1
  1204. #else
  1205.     #define TIMER_BUG   0
  1206. #endif
  1207.     class TTimerMessage : public TStreamMessage
  1208.     {
  1209.     #if TIMER_BUG
  1210.         private:
  1211.     #else
  1212.         public:
  1213.     #endif
  1214.             inline void* operator new(OTByteCount, queue_t* q)
  1215.                 {   return mi_timer_alloc(q, sizeof(T_stream_timer)); }
  1216.             inline void* operator new(OTByteCount, queue_t* q, OTByteCount extra)
  1217.                 {   return mi_timer_alloc(q, extra + sizeof(T_stream_timer)); }
  1218.     
  1219.             inline void operator delete(void* ptr)
  1220.                 {   if ( ptr != NULL ) mi_timer_free((mblk_t*)ptr); }
  1221.     
  1222.         public:     
  1223.                     Boolean         IsValid();
  1224.                     TTimerMessage*  ChangeQueue(TStreamQueue* newQ, TTimerMessage* newMP);
  1225.                     Boolean         Cancel();
  1226.                     void            Schedule(OTTimeout time);
  1227.     
  1228.         private:
  1229.             inline void* operator new(OTByteCount)
  1230.                 {   return 0; }
  1231.     };
  1232.     
  1233.     inline TTimerMessage* NewTimerMsg(queue_t* q, OTByteCount extra = 0)
  1234.     {
  1235.         return (TTimerMessage*)mi_timer_alloc(q, sizeof(T_stream_timer) + extra);
  1236.     }
  1237.     
  1238.     inline void FreeTimerMsg(TTimerMessage* msg)
  1239.     {
  1240.         mi_timer_free(msg);
  1241.     }
  1242.     
  1243.     /*  -------------------------------------------------------------------------
  1244.         Inline methods for TStreamTimer
  1245.         ------------------------------------------------------------------------- */
  1246.     
  1247.         inline Boolean TTimerMessage::IsValid()
  1248.         {
  1249.             return mi_timer_valid(this);
  1250.         }
  1251.         
  1252.         inline TTimerMessage* TTimerMessage::ChangeQueue(TStreamQueue* q, TTimerMessage* newMP)
  1253.         {
  1254.             return( (TTimerMessage*) mi_timer_q_switch(this, q, newMP));
  1255.         }
  1256.     
  1257.         inline Boolean TTimerMessage::Cancel()
  1258.         {
  1259.             return mi_timer_cancel(this);
  1260.         }
  1261.         
  1262.         inline void TTimerMessage::Schedule(OTTimeout time)
  1263.         {
  1264.             ((T_stream_timer*)b_rptr)->PRIM_type = T_TIMER_REQ;
  1265.             mi_timer(this, (unsigned long)time);
  1266.         }
  1267. extern "C" {        // resume C definitions
  1268. #endif  /* __cplusplus  */
  1269. #if defined(__MWERKS__) && TARGET_CPU_68K
  1270.  #pragma pop
  1271. #endif
  1272. #if PRAGMA_STRUCT_ALIGN
  1273.     #pragma options align=reset
  1274. #elif PRAGMA_STRUCT_PACKPUSH
  1275.     #pragma pack(pop)
  1276. #elif PRAGMA_STRUCT_PACK
  1277.     #pragma pack()
  1278. #endif
  1279. #ifdef PRAGMA_IMPORT_OFF
  1280. #pragma import off
  1281. #elif PRAGMA_IMPORT
  1282. #pragma import reset
  1283. #endif
  1284. #ifdef __cplusplus
  1285. }
  1286. #endif
  1287. #endif /* __OPENTRANSPORTKERNEL__ */