Logiciels divers autour du protocole « Open Sound Control » aka OSC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

burpmsg.c 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * BURPMSG.C
  3. */
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include <sys/select.h>
  7. #include <unistd.h>
  8. #include "laserblast.h"
  9. #include "burpmsg.h"
  10. /* ------------------------------------------------------------------- */
  11. int display_burp_msg(BurpMsg *header, void *data)
  12. {
  13. char *txt_type;
  14. if (BURP_MAGIC != header->magic) {
  15. fprintf(stderr, "burpmsg at %p : invalid magic %08X\n",
  16. header, header->magic);
  17. return -1;
  18. }
  19. txt_type = "wtf?"; /* nice default value */
  20. switch(header->msgtype) {
  21. case BURP_RESET:
  22. txt_type = "reset";
  23. break;
  24. case BURP_SETSIZE:
  25. txt_type = "setsize";
  26. break;
  27. case BURP_LASER:
  28. txt_type = "laser";
  29. break;
  30. case BURP_SCENE:
  31. txt_type = "scene";
  32. break;
  33. case BURP_TEXTE:
  34. txt_type = "texte";
  35. break;
  36. default:
  37. fprintf(stderr, "burpmsg at %p : invalid msgtype %d\n",
  38. header, header->msgtype);
  39. return -1;
  40. }
  41. fprintf(stderr, "type %4d/%-8s serial %9d szdata %3d\n",
  42. header->msgtype, txt_type, header->serial, header->szdata);
  43. return 0;
  44. }
  45. /* ------------------------------------------------------------------- */
  46. void la_grande_boucle( int fromfifo )
  47. {
  48. struct timeval tv;
  49. fd_set fds;
  50. int resval, foo;
  51. BurpMsg message;
  52. for(;;) { /* start of infinite loop */
  53. FD_ZERO(&fds);
  54. FD_SET(fromfifo, &fds);
  55. tv.tv_sec = 1;
  56. tv.tv_usec = 0;
  57. resval = select(1, &fds, NULL, NULL, &tv);
  58. if (-1 == resval) {
  59. perror("select()");
  60. /* ABORTING HERE ? */
  61. continue;
  62. }
  63. if (resval) {
  64. /* message available */
  65. foo = read(fromfifo, &message, sizeof(BurpMsg));
  66. if (sizeof(BurpMsg) != foo) {
  67. fprintf(stderr, "err: %d read, %lu expected\n",
  68. foo, sizeof(BurpMsg));
  69. }
  70. display_burp_msg(&message, NULL);
  71. /* read appended datas */
  72. }
  73. else {
  74. /* got a time out */
  75. fprintf(stderr, "TIMEOUT\n");
  76. }
  77. }
  78. /* NOT REACHED */
  79. }
  80. /* ------------------------------------------------------------------- */