home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 240.lha / PickPacket_v1.0 / Sources / sendpkt.c < prev    next >
C/C++ Source or Header  |  1989-05-04  |  2KB  |  69 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989 The Software Distillery.                    *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by John Toebes and Doug Walker               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           235 Trillingham Lane                                 *
  7. * ======             Cary, NC 27513                                       *
  8. *                    BBS:(919)-471-6436                                   *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/ports.h>
  13. #include <libraries/dosextens.h>
  14. #include <proto/exec.h>
  15. #include <proto/dos.h>
  16.  
  17. LONG sendpkt(struct MsgPort *, long, long*, long, long*);
  18.  
  19. LONG sendpkt(pid,action,args,nargs,res)
  20. struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
  21. LONG action,          /* packet type ... (what you want handler to do )   */
  22.      args[],          /* a pointer to a argument list           */
  23.      nargs,           /* number of arguments in list            */
  24.      res[];           /* pointer to 2 longs for result, or NULL */
  25.    {
  26.    struct MsgPort        *replyport;
  27.    struct StandardPacket *packet;
  28.  
  29.    LONG  count, lres, *pargs;
  30.  
  31.    replyport = (struct MsgPort *) CreatePort(NULL,0);
  32.    if(!replyport) return(0L);
  33.  
  34.    packet = (struct StandardPacket *) 
  35.       AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  36.    if(!packet) 
  37.       {
  38.       DeletePort(replyport);
  39.       return(0L);
  40.       }
  41.  
  42.    packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  43.    packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
  44.    packet->sp_Pkt.dp_Port         = replyport;
  45.    packet->sp_Pkt.dp_Type         = action;
  46.  
  47.    /* copy the args into the packet */
  48.    pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
  49.    for(count=0;count < nargs;count++) 
  50.       pargs[count]=args[count];
  51.  
  52.    PutMsg(pid,(struct Message *)packet); /* send packet */
  53.  
  54.    WaitPort(replyport);
  55.    GetMsg(replyport); 
  56.  
  57.    if(res)
  58.    {
  59.       lres = res[0] = packet->sp_Pkt.dp_Res1;
  60.       res[1] = packet->sp_Pkt.dp_Res2;
  61.    }
  62.  
  63.    FreeMem((char *)packet,(long)sizeof(struct StandardPacket));
  64.    DeletePort(replyport); 
  65.  
  66.    return(lres);
  67. }
  68.  
  69.