home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d166 / stevie.lha / Stevie / source / sendpacket.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  2KB  |  71 lines

  1. /*
  2.  * Sendpacket.c 
  3.  *
  4.  * An invaluable addition to your Amiga.lib file. This code sends a packet the
  5.  * given message port. This makes working around DOS lots easier. 
  6.  *
  7.  * Note, I didn't write this, those wonderful folks at CBM did. I do suggest
  8.  * however that you may wish to add it to Amiga.Lib, to do so, compile it and
  9.  * say 'oml lib:amiga.lib -r sendpacket.o' 
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/ports.h>
  14. #include <exec/memory.h>
  15. #include <libraries/dos.h>
  16. #include <libraries/dosextens.h>
  17.  
  18. /*
  19.  * Function - SendPacket written by Phil Lindsay, Carolyn Scheppner, and Andy
  20.  * Finkel. This function will send a packet of the given type to the Message
  21.  * Port supplied. 
  22.  */
  23.  
  24. long
  25. SendPacket(pid, action, args, nargs)
  26.     struct MsgPort *pid;    /* process indentifier ... (handlers message
  27.                  * port ) */
  28.     long            action,    /* packet type ... (what you want handler to
  29.                  * do )   */
  30.                     args[],    /* a pointer to a argument list */
  31.                     nargs;    /* number of arguments in list  */
  32. {
  33.     struct MsgPort *replyport;
  34.     struct StandardPacket *packet;
  35.  
  36.     long            count, *pargs, res1;
  37.  
  38.     replyport = (struct MsgPort *) CreatePort(NULL, 0);
  39.     if (!replyport)
  40.     return (0);
  41.  
  42.     /* Allocate space for a packet, make it public and clear it */
  43.     packet = (struct StandardPacket *)
  44.     AllocMem((long) sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR);
  45.     if (!packet) {
  46.     DeletePort(replyport);
  47.     return (0);
  48.     }
  49.     packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt);
  50.     packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
  51.     packet->sp_Pkt.dp_Port = replyport;
  52.     packet->sp_Pkt.dp_Type = action;
  53.  
  54.     /* copy the args into the packet */
  55.     pargs = &(packet->sp_Pkt.dp_Arg1);    /* address of first argument */
  56.     for (count = 0; count < nargs; count++)
  57.     pargs[count] = args[count];
  58.  
  59.     PutMsg(pid, packet);    /* send packet */
  60.  
  61.     WaitPort(replyport);
  62.     GetMsg(replyport);
  63.  
  64.     res1 = packet->sp_Pkt.dp_Res1;
  65.  
  66.     FreeMem(packet, (long) sizeof(struct StandardPacket));
  67.     DeletePort(replyport);
  68.  
  69.     return (res1);
  70. }
  71.