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

  1. /*
  2.  
  3. these functions are used by the user to read and process information from
  4. incoming slots 
  5.  
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <sys/time.h>
  10. #include "cm_constants.h"
  11. #include "cm_sd.h"
  12. #include "cm_interface.h"
  13. #include "cm_slot.h"
  14.  
  15. cm_variable *get_variable();
  16.  
  17. user_decode_slot(s)
  18. struct slot *s;
  19. {
  20.     int rc = 0;
  21.  
  22.     switch (s->s_type) {
  23.     case CM_SLOT_READ_RESPONSE:
  24.         rc = get_slot_read_response(s->s_name,
  25.                 &s->subslot.read_response);
  26.         break;
  27.     case CM_SLOT_ERROR:
  28.         rc = get_slot_error(s->s_name,&s->subslot.error);
  29.         break;
  30.     default:
  31.         fprintf(stderr,"user_decode_slot: unknown slot type (%d)...msg aborted\n",s->s_type);
  32.         rc = E_CM_GET_SLOT_UNKNOWN_SLOT_TYPE;
  33.         break;
  34.     }
  35.     return(rc);
  36. }
  37.  
  38. /* returns 0 if ok, negative if problem decoding slot */
  39. int
  40. get_slot_error(name,s)
  41. char *name;
  42. struct slot_error *s;
  43. {
  44.     fprintf(stderr,"CMM: error processing variable <%s> - %s\n",name,
  45.         s->msg);
  46.     /* isn't there a "type" field in the error subslot, too? */
  47.     return(0);
  48. }
  49.  
  50. /* 0 if ok, negative if problem decoding slot */
  51. int
  52. get_slot_read_response(name,s)
  53. char *name;
  54. struct slot_read_response *s;
  55. {
  56.     int rc;
  57.     cm_variable *v;
  58.  
  59.     if (!(v = get_variable(name))) {
  60.         fprintf(stderr,"get_slot_read_response: <%s> unknown (sent from cm)\n",v->name);
  61.         return(E_CM_GET_SLOT_GET_VARIABLE);
  62.     }
  63.  
  64.     if (0 > cm_flat_to_sd(&s->fdata,&v->data))
  65.         return(E_CM_GET_SLOT_FLAT_TO_SD);
  66.     v->count = s->srr_count;
  67.     v->command_association = s->srr_command_association;
  68.     cm_time_copy(&s->srr_timestamp,&v->timestamp);
  69.     return(0);
  70. }
  71.     
  72.