PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/etc/ctalks/linux/common-libs/src/lib/ipc_protocol2.h

http://y-la-morocha-tambien.googlecode.com/
C Header | 120 lines | 75 code | 17 blank | 28 comment | 0 complexity | 91ddc756f3b9111a5eaaf217a2c75db4 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. /*
  2. * Copyright (c) 2011, C-Talks and/or its owners. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This code is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * version 2 for more details (a copy is included in the LICENSE file that
  13. * accompanied this code).
  14. *
  15. * You should have received a copy of the GNU General Public License version
  16. * 2 along with this work; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Please contact C-Talks owners, Matias Dumrauf or Facundo Viale
  20. * or visit https://sites.google.com/site/utnfrbactalks/ if you need additional
  21. * information or have any questions.
  22. */
  23. /*
  24. * @FILE: ipc_protocol2.h
  25. * @AUTOR: Facundo Viale
  26. * @VERSION: 1.0 (29/08/2009)
  27. * - Full Revision
  28. */
  29. #ifndef OLD_IPC_PROTOCOL2_H_
  30. #define OLD_IPC_PROTOCOL2_H_
  31. #define _XOPEN_SOURCE 500
  32. #include "sockets.h"
  33. #define IPC_PKG_DEFAULT_DESCID_SIZE 15
  34. typedef enum {
  35. IPC_NONE = 0x0,
  36. IPC_REQUEST = 0x21,
  37. IPC_RESPONSE = 0x22,
  38. IPC_OK = 0x23,
  39. IPC_FAIL = 0x24
  40. }e_ipc_pkg_type;
  41. typedef enum {
  42. IPC_PKG_AUTODESTROY_TRUE = 0x1,
  43. IPC_PKG_AUTODESTROY_FALSE = 0x0
  44. }e_ipc_pkg_autodestroy;
  45. typedef enum {
  46. IPC_HANDSHAKE_OK = 200,
  47. IPC_HANDSHAKE_UNABLE = 201
  48. }e_ipc_handshake_state;
  49. typedef struct {
  50. char descId[IPC_PKG_DEFAULT_DESCID_SIZE];
  51. unsigned char payload_desc;
  52. unsigned int payload_length;
  53. void *payload;
  54. } __attribute__((__packed__)) t_ipc_pkg;
  55. t_ipc_pkg *ipcpkg2_create1(char descId[], e_ipc_pkg_type type, void* payload, int lenght);
  56. t_ipc_pkg *ipcpkg2_create2(e_ipc_pkg_type type, void* payload, int lenght);
  57. t_ipc_pkg *ipcpkg2_createFromBuffer1(char descId[], e_ipc_pkg_type type, t_socket_sbuffer* buffer);
  58. t_ipc_pkg *ipcpkg2_createFromBuffer2(e_ipc_pkg_type type, t_socket_sbuffer* buffer);
  59. t_ipc_pkg *ipcpkg2_createFromString1(char descId[], e_ipc_pkg_type type, char *str);
  60. t_ipc_pkg *ipcpkg2_createFromString2(e_ipc_pkg_type type, char *str);
  61. t_ipc_pkg *ipcpkg2_createFromSerializer1(char descId[], e_ipc_pkg_type type, void *data, t_socket_sbuffer *(*serializer)(void*));
  62. t_ipc_pkg *ipcpkg2_createFromSerializer2(e_ipc_pkg_type type, void *data, t_socket_sbuffer *(*serializer)(void*));
  63. int ipcpkg2_isRequest(t_ipc_pkg *pkg);
  64. int ipcpkg2_isResponse(t_ipc_pkg *pkg);
  65. char *ipcpkg2_getDescriptorID(t_ipc_pkg *pkg);
  66. e_ipc_pkg_type ipcpkg2_getPayloadDescriptor1(t_ipc_pkg *pkg);
  67. int ipcpkg2_getPayloadLength(t_ipc_pkg *pkg);
  68. void *ipcpkg2_getPayload(t_ipc_pkg *pkg);
  69. void ipcpkg2_getPayloadInBuffer1(t_ipc_pkg *pkg, t_socket_sbuffer *buffer);
  70. t_socket_sbuffer *ipcpkg2_getPayloadInBuffer2(t_ipc_pkg *pkg);
  71. char *ipcpkg2_getPayloadAsString(t_ipc_pkg *pkg);
  72. char *ipcpkg2_getPayloadAsStringBuffer(t_ipc_pkg *pkg, char buffer[]);
  73. #define ipcpkg2_getPayloadAs(pkg, type) ((type *)(pkg->payload))
  74. void ipcpkg2_destroy(t_ipc_pkg *pkg);
  75. t_socket_sbuffer *ipcpkg2_serializer(t_ipc_pkg *pkg);
  76. t_ipc_pkg *ipcpkg2_deserializer(t_socket_sbuffer *buffer);
  77. e_ipc_handshake_state ipcprotocol2_handshake(t_socket_client *client, int process_id, char *server_ip, int server_port);
  78. int ipcprotocol2_accepthandshake1(t_socket_client *client);
  79. int ipcprotocol2_accepthandshake2(t_socket_client *client,
  80. void *context,
  81. e_ipc_handshake_state (*onAccept)(void *context, int process_id, t_socket_client*));
  82. t_socket_client *ipcprotocol2_accepthandshake3(t_socket_server *server);
  83. t_socket_client *ipcprotocol2_accepthandshake4(t_socket_server *server,
  84. void *context,
  85. e_ipc_handshake_state (*onAccept)(void *context, int process_id, t_socket_client*));
  86. int ipcprotocol2_send1(t_socket_client *client, t_ipc_pkg *pkg, e_ipc_pkg_autodestroy destroy);
  87. int ipcprotocol2_send2(t_socket_client *client, t_ipc_pkg *pkg);
  88. t_ipc_pkg *ipcprotocol2_syncSend1(t_socket_client *client, t_ipc_pkg *pkg, e_ipc_pkg_autodestroy destroy);
  89. t_ipc_pkg *ipcprotocol2_syncSend2(t_socket_client *client, t_ipc_pkg *pkg);
  90. int ipcprotocol2_sendFromReq(t_socket_client *client, t_ipc_pkg *pkg, void* payload, int lenght );
  91. int ipcprotocol2_sendWithoutPkg(t_socket_client *client, char descId[], e_ipc_pkg_type type, void* payload, int lenght);
  92. t_ipc_pkg *ipcprotocol2_recv(t_socket_client *client);
  93. int ipcprotocol2_recvWithClosures(t_socket_client *client, void *context, void (*onRequest)(void *context, t_ipc_pkg*), void (*onResponse)(void *context, t_ipc_pkg*));
  94. void ipcprotocol2_select(t_list* servers,
  95. t_list* clients,
  96. int usec_timeout,
  97. void *context,
  98. e_ipc_handshake_state (*onHandshake)(void *context, int process_id, t_socket_client*),
  99. int (*onAccept)(void *context, t_socket_client*),
  100. void (*onRequest)(void *context, t_socket_client*, t_ipc_pkg*),
  101. void (*onResponse)(void *context, t_socket_client*, t_ipc_pkg*),
  102. int (*onClose)(void *context, t_socket_client*));
  103. #endif /* OLD_IPC_PROTOCOL2_H_ */