MQTTPersistence.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*******************************************************************************
  2. * Copyright (c) 2009, 2013 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Ian Craggs - initial API and implementation and/or initial documentation
  15. * Ian Craggs - async client updates
  16. * Ian Craggs - fix for bug 432903 - queue persistence
  17. *******************************************************************************/
  18. #if defined(__cplusplus)
  19. extern "C" {
  20. #endif
  21. #include "Clients.h"
  22. /** Stem of the key for a sent PUBLISH QoS1 or QoS2 */
  23. #define PERSISTENCE_PUBLISH_SENT "s-"
  24. /** Stem of the key for a sent PUBREL */
  25. #define PERSISTENCE_PUBREL "sc-"
  26. /** Stem of the key for a received PUBLISH QoS2 */
  27. #define PERSISTENCE_PUBLISH_RECEIVED "r-"
  28. /** Stem of the key for an async client command */
  29. #define PERSISTENCE_COMMAND_KEY "c-"
  30. /** Stem of the key for an async client message queue */
  31. #define PERSISTENCE_QUEUE_KEY "q-"
  32. #define PERSISTENCE_MAX_KEY_LENGTH 8
  33. int MQTTPersistence_create(MQTTClient_persistence** per, int type, void* pcontext);
  34. int MQTTPersistence_initialize(Clients* c, const char* serverURI);
  35. int MQTTPersistence_close(Clients* c);
  36. int MQTTPersistence_clear(Clients* c);
  37. int MQTTPersistence_restore(Clients* c);
  38. void* MQTTPersistence_restorePacket(char* buffer, size_t buflen);
  39. void MQTTPersistence_insertInOrder(List* list, void* content, size_t size);
  40. int MQTTPersistence_put(int socket, char* buf0, size_t buf0len, int count,
  41. char** buffers, size_t* buflens, int htype, int msgId, int scr);
  42. int MQTTPersistence_remove(Clients* c, char* type, int qos, int msgId);
  43. void MQTTPersistence_wrapMsgID(Clients *c);
  44. typedef struct
  45. {
  46. char struct_id[4];
  47. int struct_version;
  48. int payloadlen;
  49. void* payload;
  50. int qos;
  51. int retained;
  52. int dup;
  53. int msgid;
  54. } MQTTPersistence_message;
  55. typedef struct
  56. {
  57. MQTTPersistence_message* msg;
  58. char* topicName;
  59. int topicLen;
  60. unsigned int seqno; /* only used on restore */
  61. } MQTTPersistence_qEntry;
  62. int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry* qe);
  63. int MQTTPersistence_persistQueueEntry(Clients* aclient, MQTTPersistence_qEntry* qe);
  64. int MQTTPersistence_restoreMessageQueue(Clients* c);
  65. #ifdef __cplusplus
  66. }
  67. #endif