libpq-events.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*-------------------------------------------------------------------------
  2. *
  3. * libpq-events.h
  4. * This file contains definitions that are useful to applications
  5. * that invoke the libpq "events" API, but are not interesting to
  6. * ordinary users of libpq.
  7. *
  8. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  9. * Portions Copyright (c) 1994, Regents of the University of California
  10. *
  11. * src/interfaces/libpq/libpq-events.h
  12. *
  13. *-------------------------------------------------------------------------
  14. */
  15. #ifndef LIBPQ_EVENTS_H
  16. #define LIBPQ_EVENTS_H
  17. #include "libpq-fe.h"
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. /* Callback Event Ids */
  23. typedef enum
  24. {
  25. PGEVT_REGISTER,
  26. PGEVT_CONNRESET,
  27. PGEVT_CONNDESTROY,
  28. PGEVT_RESULTCREATE,
  29. PGEVT_RESULTCOPY,
  30. PGEVT_RESULTDESTROY
  31. } PGEventId;
  32. typedef struct
  33. {
  34. PGconn *conn;
  35. } PGEventRegister;
  36. typedef struct
  37. {
  38. PGconn *conn;
  39. } PGEventConnReset;
  40. typedef struct
  41. {
  42. PGconn *conn;
  43. } PGEventConnDestroy;
  44. typedef struct
  45. {
  46. PGconn *conn;
  47. PGresult *result;
  48. } PGEventResultCreate;
  49. typedef struct
  50. {
  51. const PGresult *src;
  52. PGresult *dest;
  53. } PGEventResultCopy;
  54. typedef struct
  55. {
  56. PGresult *result;
  57. } PGEventResultDestroy;
  58. typedef int (*PGEventProc) (PGEventId evtId, void *evtInfo, void *passThrough);
  59. /* Registers an event proc with the given PGconn. */
  60. extern int PQregisterEventProc(PGconn *conn, PGEventProc proc,
  61. const char *name, void *passThrough);
  62. /* Sets the PGconn instance data for the provided proc to data. */
  63. extern int PQsetInstanceData(PGconn *conn, PGEventProc proc, void *data);
  64. /* Gets the PGconn instance data for the provided proc. */
  65. extern void *PQinstanceData(const PGconn *conn, PGEventProc proc);
  66. /* Sets the PGresult instance data for the provided proc to data. */
  67. extern int PQresultSetInstanceData(PGresult *result, PGEventProc proc, void *data);
  68. /* Gets the PGresult instance data for the provided proc. */
  69. extern void *PQresultInstanceData(const PGresult *result, PGEventProc proc);
  70. /* Fires RESULTCREATE events for an application-created PGresult. */
  71. extern int PQfireResultCreateEvents(PGconn *conn, PGresult *res);
  72. #ifdef __cplusplus
  73. }
  74. #endif
  75. #endif /* LIBPQ_EVENTS_H */