node.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef _NODE_H
  2. #define _NODE_H 1
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "hash.h"
  7. #include "pdu.h"
  8. struct coap_queue_t;
  9. typedef uint32_t coap_tick_t;
  10. /*
  11. 1. queue(first)->t store when to send PDU for the next time, it's a base(absolute) time
  12. 2. queue->next->t store the delta between time and base-time. queue->next->t = timeout + now - basetime
  13. 3. node->next->t store the delta between time and previous->t. node->next->t = timeout + now - node->t - basetime
  14. 4. time to fire: 10, 15, 18, 25
  15. node->t: 10, 5, 3, 7
  16. */
  17. typedef struct coap_queue_t {
  18. struct coap_queue_t *next;
  19. coap_tick_t t; /**< when to send PDU for the next time */
  20. unsigned char retransmit_cnt; /**< retransmission counter, will be removed when zero */
  21. unsigned int timeout; /**< the randomized timeout value */
  22. coap_tid_t id; /**< unique transaction id */
  23. // coap_packet_t *pkt;
  24. coap_pdu_t *pdu; /**< the CoAP PDU to send */
  25. struct espconn *pconn;
  26. } coap_queue_t;
  27. void coap_free_node(coap_queue_t *node);
  28. /** Adds node to given queue, ordered by node->t. */
  29. int coap_insert_node(coap_queue_t **queue, coap_queue_t *node);
  30. /** Destroys specified node. */
  31. int coap_delete_node(coap_queue_t *node);
  32. /** Removes all items from given queue and frees the allocated storage. */
  33. void coap_delete_all(coap_queue_t *queue);
  34. /** Creates a new node suitable for adding to the CoAP sendqueue. */
  35. coap_queue_t *coap_new_node(void);
  36. coap_queue_t *coap_pop_next( coap_queue_t **queue );
  37. int coap_remove_node( coap_queue_t **queue, const coap_tid_t id);
  38. #ifdef __cplusplus
  39. }
  40. #endif
  41. #endif