home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / devs / netinfo / base.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-19  |  5.9 KB  |  217 lines

  1. #ifndef _BASE_H_
  2. #define _BASE_H_
  3. /*
  4.  * $Id: base.h,v 3.3 1994/05/19 04:29:29 ppessi Exp $
  5.  *
  6.  * Netinfo device base. Define the device structure 
  7.  *
  8.  * Copyright (c) 1993 Pekka Pessi
  9.  *
  10.  * Created      : Sun Nov 28 17:45:55 1993 ppessi
  11.  * Last modified: Thu May 19 04:09:29 1994 ppessi
  12.  *
  13.  * $Log: base.h,v $
  14.  * Revision 3.3  1994/05/19  04:29:29  ppessi
  15.  * Added support for DOS notifications
  16.  *
  17.  * Revision 3.2  1994/02/27  00:07:45  ppessi
  18.  * Removed from DeviceCmd_t typedef a "const" keyword.
  19.  * It resulted in bad optimization with SAS C 6.51.
  20.  *
  21.  * Revision 3.1  1994/01/23  02:46:18  ppessi
  22.  * New command semantics, new version.
  23.  *
  24.  * Revision 1.3  1994/01/23  02:34:32  ppessi
  25.  * Created new unit hieararchy, dropped the magic cookie passing
  26.  * system for setnet/getent/endent -style access.
  27.  *
  28.  * Revision 1.2  1994/01/20  16:16:17  ppessi
  29.  * Added CMD_WRITE and CMD_UPDATE
  30.  *
  31.  * Revision 1.1  1994/01/18  09:12:48  ppessi
  32.  * Initial revision
  33.  *
  34.  * Revision 1.1  93/11/30  03:18:50  ppessi
  35.  * Initial revision
  36.  * 
  37.  */
  38.  
  39. #include "config.h"
  40.  
  41. #ifndef EXEC_LIBRARIES_H
  42. #include <exec/libraries.h>
  43. #endif
  44.  
  45. #ifndef DEVICES_NETINFO_H
  46. #include <devices/netinfo.h>
  47. #endif
  48.  
  49. #ifndef EXEC_TASKS_H
  50. #include <exec/tasks.h>
  51. #endif
  52.  
  53. #ifndef UTILITY_TAGITEM_H
  54. #include <utility/tagitem.h>
  55. #endif
  56.  
  57. #ifndef EXEC_IO_H
  58. #include <exec/io.h>
  59. #endif
  60.  
  61. #ifndef EXEC_DEVICES_H
  62. #include <exec/devices.h>
  63. #endif
  64.  
  65. #ifndef EXEC_ERRORS_H
  66. #include <exec/errors.h>
  67. #endif
  68.  
  69. #ifndef EXEC_MEMORY_H
  70. #include <exec/memory.h>
  71. #endif
  72.  
  73. #ifndef EXEC_SEMAPHORES_H
  74. #include <exec/semaphores.h>
  75. #endif
  76.  
  77. #ifdef USE_PRAGMAS
  78. #include <clib/exec_protos.h>
  79. #include <pragmas/exec_sysbase_pragmas.h>
  80.  
  81. #include <clib/dos_protos.h>
  82. #include <pragmas/dos_pragmas.h>
  83.  
  84. #define SysBase (nid->nid_ExecBase)
  85. #define DOSBase (nid->nid_DOSBase)
  86. #endif
  87.  
  88. extern const UBYTE _DevName[]; 
  89.  
  90. /*
  91.  * Device base 
  92.  */
  93. struct NetInfoDevice {
  94.   struct Library         nid_Lib;
  95.   APTR                 nid_SegList;
  96.   /* like there were no reference operator in C... */
  97.   struct SignalSemaphore nid_Lock[1];
  98.   APTR                   nid_ExecBase;
  99.   APTR                   nid_DOSBase;
  100.   struct MsgPort         nid_Port[1];    /* Port to send requests */
  101.   struct Message        *nid_Death;    /* Kill task by this message */
  102.   struct MsgPort         nid_NotifyPort[1]; /* Port for notify messages */
  103.   struct List            nid_Instances[1];
  104.   struct NetInfoMap     *nid_Maps[NETINFO_UNITS];
  105. };
  106.  
  107. #define nid_Task nid_Port->mp_SigTask
  108. #define nid_SigBit nid_Port->mp_SigBit
  109.  
  110. /* Internal constants */
  111. #define NETINFOSIZE ((sizeof(struct NetInfoDevice) +3) & ~3)
  112. #define NID_PRIORITY 1
  113.  
  114. typedef void (* DeviceCmd_t)(BASE, struct NetInfoReq *, struct NetInfoMap *);
  115.  
  116. /*
  117.  * Structure for each netinfo map
  118.  */
  119. struct NetInfoMap {
  120.   struct Node            nim_Node[1];
  121.   struct MsgPort        *nim_Port;
  122.   const struct MapMethods *nim_Methods;
  123.   const DeviceCmd_t     *nim_Commands;
  124.   struct SignalSemaphore nim_PointerLock[1];
  125.   struct List            nim_Pointer[1];     /* under nid_Lock */
  126.   struct SignalSemaphore nim_ReqLock[1];
  127.   struct List            nim_Rx[1];
  128.   struct List            nim_Wx[1];
  129.   WORD                   nim_OpenCnt;
  130.   WORD                   nim_Flags;         
  131.   const UBYTE           *nim_Filename;
  132.   struct SignalSemaphore nim_EntLock[1];
  133.   struct List            nim_Ent[1];
  134.   struct NotifyRequest   nim_Notify[1];
  135. };
  136.  
  137. #define NIMF_PARSED   0x0001
  138. #define NIMF_CHANGED  0x0002
  139.  
  140. #define nim_Name nim_Node->ln_Name
  141.  
  142. /*
  143.  * Define map methods
  144.  */
  145. struct MapMethods {
  146.   struct Ent *        (*parse_ent)(BASE, register UBYTE *p);
  147.   int                 (*print_out)(BASE, BPTR, struct Ent *); 
  148.   void *              (*copy_out)(struct NetInfoReq *req, struct Ent *e);
  149.   struct Ent *        (*copy_in)(BASE, struct NetInfoReq *req);
  150.   void                (*cleanup)(BASE, struct NetInfoMap *);
  151.   void                (*membercmd)(BASE, struct NetInfoReq *, 
  152.                    struct NetInfoMap *);
  153.   void                (*notify)(BASE, struct NetInfoMap *);
  154. };
  155.  
  156. #define DoMethod(cmd, req, unit)\
  157.   ((unit)->nim_Commands[cmd])(nid, (req), (unit))
  158. #define Method(method, unit)\
  159.   (*((unit)->nim_Methods->method))
  160.  
  161. /*
  162.  * Instance allocated for each opener (stored to io_Unit)
  163.  */
  164. struct NetInfoPointer {
  165.   struct Node        nip_Node[1];
  166.   UBYTE              nip_Flags;
  167.   UBYTE              nip_UnitNumber;
  168.   struct NetInfoMap *nip_Map;             /* backpointer */
  169.   struct Ent        *nip_Ent;             /* latest entry read */
  170. };
  171.  
  172. #define nip_Name nip_Node->ln_Name
  173.  
  174. /* Device initialization functions */
  175. ASM ULONG _LibInit(REG(a0) APTR seglist, REG(d0) struct Library *devbase);
  176. ASM ULONG _DevInit(BASEREG, REG(a0) APTR seglist);
  177.  
  178. /* Library entry points */
  179. ASM LONG _DevOpen(BASEREG, REG(a1) struct IORequest *req, REG(d0) ULONG unit,
  180.           REG(d1) ULONG flags);
  181. ASM ULONG _DevClose(BASEREG, REG(a1) struct IORequest *req);
  182. ASM ULONG _DevExpunge(BASEREG);
  183. ASM ULONG _DevRes(void);
  184. ASM VOID _NetInfoBeginIO(BASEREG, REG(a1) struct NetInfoReq *req);
  185. ASM ULONG _NetInfoAbortIO(BASEREG, REG(a1) struct NetInfoReq *req);
  186.  
  187. /* in server.c */
  188. ASM LONG NetInfoStartup(void);
  189. void NetInfoTask(BASE, struct Message *msg);
  190. struct NetInfoMap *InitNetInfoMap(BASE, struct MsgPort *, ULONG);
  191. void DeInitNetInfoMap(BASE, struct NetInfoMap *);
  192. struct Unit *CreateNewUnit(BASE, short unit);
  193. void ExpungeUnit(BASE, struct Unit *);
  194. void PerformIO(BASE, struct NetInfoReq *req);
  195. void TermIO(struct NetInfoReq *req);
  196. ULONG AbortReq(BASE, struct List *, struct NetInfoReq *);
  197.  
  198. /* Common method */
  199. void UnknownCommand(BASE, struct NetInfoReq *, struct NetInfoMap *);   
  200.  
  201. /* support functions */
  202. struct NetInfoMap *CheckUnit(BASE, struct Unit *u);
  203. void FreeListVec(BASE, struct List *list);
  204. struct Node *FindNode(struct List *list, struct Node *node);
  205. char *strsep(register char **stringp, register const char *delim);
  206.  
  207. static __inline void InitList(struct List *list)
  208. {
  209.   list->lh_Head = (struct Node*)&list->lh_Tail;
  210.   list->lh_Tail = NULL;
  211.   list->lh_TailPred = (struct Node*)&list->lh_Head;
  212. }
  213.  
  214. void InMsg(const char *fmt, ...);
  215.  
  216. #endif /* _BASE_H_ */
  217.