myco-ipc.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 2016 Max Riechelmann <max.riechelmann@student.kit.edu>
  2. (Karlsruhe Institute of Technology)
  3. This library is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Lesser General Public License as published by the
  5. Free Software Foundation; either version 2.1 of the License, or (at your
  6. option) any later version.
  7. This library is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  10. details.
  11. You should have received a copy of the GNU Lesser General Public License along
  12. with this library; if not, write to the Free Software Foundation, Inc., 51
  13. Franklin St, Fifth Floor, Boston, MA 02110, USA
  14. */
  15. /**
  16. * SECTION: myco-ipc
  17. * @Short_description: common header for ipc between agents, workers and daemon
  18. * @Title: MycoIpc
  19. *
  20. * MycoIpc organizes the message queues that are used between agents, workers
  21. * and daemons.
  22. */
  23. #ifndef __MYCO_IPC_H
  24. #define __MYCO_IPC_H
  25. #include <stdlib.h>
  26. #include <signal.h>
  27. #define _GNU_SOURCE
  28. #include <sys/uio.h>
  29. #include <sys/types.h>
  30. #include <sys/ipc.h>
  31. #include <sys/msg.h>
  32. #include <sys/stat.h>
  33. #include <stdio.h>
  34. #include <unistd.h>
  35. #include <errno.h>
  36. #include <string.h>
  37. #define KEY 5234L
  38. #define MESSAGE_LENGTH 256
  39. #define RESOURCE_NAME_LENGTH 256
  40. #define AGENT_NAME_LENGTH 256
  41. #define PERM 0666
  42. #define RESOURCE_TRANSACTIONAL 1
  43. #define RESOURCE_NOT_TRANSACTIONAL 2
  44. struct resource {
  45. void *pointer;
  46. int size;
  47. };
  48. typedef struct {
  49. char message[MESSAGE_LENGTH];
  50. char resource_name[RESOURCE_NAME_LENGTH];
  51. char agent_name[AGENT_NAME_LENGTH];
  52. int agent_message_queue_id;
  53. void *resource_pointer;
  54. int resource_size;
  55. int resource_transactional;
  56. pid_t sender_pid;
  57. int version;
  58. } message;
  59. typedef struct {
  60. long int mtype;
  61. char mtext[sizeof(message)];
  62. } message_item;
  63. int myco_send(int message_queue_id, message msg);
  64. message myco_receive(int message_queue_id);
  65. message myco_send_and_receive(message msg, int send_message_queue_id, int receive_message_queue_id);
  66. int myco_read_transactional(pid_t source_pid, void *source_pointer, int source_length, void *target_pointer, int target_length);
  67. #endif //__MYCO_IPC_H