home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / sharedmem / part01 / src / put_slot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  2.0 KB  |  84 lines

  1. /*
  2.  
  3. These are some utility routines for building slots.  These slots
  4. are placed in a msg structure and sent from the user to the cmm or vice-versa.
  5.  
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <sys/time.h>
  10. #include <strings.h>
  11. #include "cm_constants.h"
  12. #include "cm_sd.h"
  13. #include "cm_slot.h"    /* definitions of slot structures */
  14. #include "cm_msg.h"    /* definitions of msg structures */
  15. #include "cm_bytestuff.h"
  16.  
  17. #define TRUE 1
  18. #define FALSE 0
  19.  
  20. extern char cm_process_name[];
  21.  
  22. int    /* returns # of bytes written into msg structure */
  23. finish_slot(m,slot,slotsize)
  24. struct msg *m;
  25. struct slot *slot;
  26. unsigned int slotsize;
  27. {
  28.     if (m->size + slotsize > CM_MSGSIZE) {
  29.         fprintf(stderr,"too much data for msg!!\n");
  30.         fprintf(stderr,"output msg size = %d  slotsize = %d  CM_MSGSIZE = %d\n",
  31.             m->size,slotsize,CM_MSGSIZE);
  32.         return(0);
  33.     }
  34.     /* copy slot into msg after previous slot */
  35.     slot->s_size = slotsize; /* this is not aligned, right? */
  36.     eprintf(10,"finish_slot: bcopying slot (size = %d) into msg\n",
  37.                         slot->s_size);
  38.     safebcopy((char *)slot,(char *)byteadd(m,m->size),slotsize);
  39.     eprintf(10,"finish_slot: after bcopy, message slot size = %d\n",
  40.                 ((struct slot *)byteadd(m,m->size))->s_size);
  41.     m->slots++;
  42.     m->size += align(slotsize);
  43.     return(align(slotsize));
  44. }
  45.  
  46. init_msg(m)
  47. struct msg *m;
  48. {
  49.     m->version = CMM_VERSION;
  50.     m->slots = 0;
  51.     m->read_wait = FALSE;
  52.     strcpy(m->name,cm_process_name);
  53.     m->size = sizeof(struct msg) - sizeof(struct slot);
  54. }
  55.  
  56. /*
  57. init_slot does the following:
  58.     sets the slot name and type
  59. */
  60. init_slot(s,name,type)
  61. struct slot *s;
  62. char *name;
  63. int type;
  64. {
  65.     s->s_type = type;
  66.     strcpy(s->s_name,name);
  67. }
  68.  
  69. char *
  70. cm_slot_type(t)
  71. int t;
  72. {
  73.     switch (t) {
  74.     case CM_SLOT_NULL: return("null slot type");
  75.     case CM_SLOT_DECLARE: return("declare");
  76.     case CM_SLOT_WRITE: return("write");
  77.     case CM_SLOT_READ: return("read");
  78.     case CM_SLOT_READ_RESPONSE: return("read response");
  79.     case CM_SLOT_ERROR: return("error");
  80.     case CM_SLOT_UNDECLARE: return("undeclare");
  81.     default: return("unknown slot type");
  82.     }
  83. }
  84.