PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
libpq-events.h File Reference
#include "libpq-fe.h"
Include dependency graph for libpq-events.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PGEventRegister
 
struct  PGEventConnReset
 
struct  PGEventConnDestroy
 
struct  PGEventResultCreate
 
struct  PGEventResultCopy
 
struct  PGEventResultDestroy
 

Typedefs

typedef int(* PGEventProc )(PGEventId evtId, void *evtInfo, void *passThrough)
 

Enumerations

enum  PGEventId {
  PGEVT_REGISTER, PGEVT_CONNRESET, PGEVT_CONNDESTROY, PGEVT_RESULTCREATE,
  PGEVT_RESULTCOPY, PGEVT_RESULTDESTROY
}
 

Functions

int PQregisterEventProc (PGconn *conn, PGEventProc proc, const char *name, void *passThrough)
 
int PQsetInstanceData (PGconn *conn, PGEventProc proc, void *data)
 
void * PQinstanceData (const PGconn *conn, PGEventProc proc)
 
int PQresultSetInstanceData (PGresult *result, PGEventProc proc, void *data)
 
void * PQresultInstanceData (const PGresult *result, PGEventProc proc)
 
int PQfireResultCreateEvents (PGconn *conn, PGresult *res)
 

Typedef Documentation

typedef int(* PGEventProc)(PGEventId evtId, void *evtInfo, void *passThrough)

Definition at line 69 of file libpq-events.h.

Enumeration Type Documentation

enum PGEventId
Enumerator
PGEVT_REGISTER 
PGEVT_CONNRESET 
PGEVT_CONNDESTROY 
PGEVT_RESULTCREATE 
PGEVT_RESULTCOPY 
PGEVT_RESULTDESTROY 

Definition at line 27 of file libpq-events.h.

Function Documentation

int PQfireResultCreateEvents ( PGconn conn,
PGresult res 
)

Definition at line 185 of file libpq-events.c.

References conn, PGEventResultCreate::conn, pg_result::events, FALSE, i, pg_result::nEvents, PGEvent::passThrough, PGEVT_RESULTCREATE, PGEvent::proc, PGEventResultCreate::result, PGEvent::resultInitialized, and TRUE.

186 {
187  int i;
188 
189  if (!res)
190  return FALSE;
191 
192  for (i = 0; i < res->nEvents; i++)
193  {
194  if (!res->events[i].resultInitialized)
195  {
197 
198  evt.conn = conn;
199  evt.result = res;
200  if (!res->events[i].proc(PGEVT_RESULTCREATE, &evt,
201  res->events[i].passThrough))
202  return FALSE;
203 
204  res->events[i].resultInitialized = TRUE;
205  }
206  }
207 
208  return TRUE;
209 }
bool resultInitialized
Definition: libpq-int.h:164
int nEvents
Definition: libpq-int.h:188
#define FALSE
Definition: c.h:221
PGconn * conn
Definition: streamutil.c:42
PGEventProc proc
Definition: libpq-int.h:160
int i
void * passThrough
Definition: libpq-int.h:162
#define TRUE
Definition: c.h:217
PGEvent * events
Definition: libpq-int.h:187
void* PQinstanceData ( const PGconn conn,
PGEventProc  proc 
)

Definition at line 121 of file libpq-events.c.

References PGEvent::data, pg_conn::events, i, pg_conn::nEvents, NULL, and PGEvent::proc.

122 {
123  int i;
124 
125  if (!conn || !proc)
126  return NULL;
127 
128  for (i = 0; i < conn->nEvents; i++)
129  {
130  if (conn->events[i].proc == proc)
131  return conn->events[i].data;
132  }
133 
134  return NULL;
135 }
PGEvent * events
Definition: libpq-int.h:373
void * data
Definition: libpq-int.h:163
#define NULL
Definition: c.h:229
PGEventProc proc
Definition: libpq-int.h:160
int nEvents
Definition: libpq-int.h:374
int i
int PQregisterEventProc ( PGconn conn,
PGEventProc  proc,
const char *  name,
void *  passThrough 
)

Definition at line 40 of file libpq-events.c.

References PGEventRegister::conn, conn, PGEvent::data, pg_conn::eventArraySize, pg_conn::events, FALSE, free, i, malloc, PGEvent::name, pg_conn::nEvents, NULL, PGEvent::passThrough, PGEVT_REGISTER, PGEvent::proc, realloc, PGEvent::resultInitialized, and TRUE.

42 {
43  int i;
44  PGEventRegister regevt;
45 
46  if (!proc || !conn || !name || !*name)
47  return FALSE; /* bad arguments */
48 
49  for (i = 0; i < conn->nEvents; i++)
50  {
51  if (conn->events[i].proc == proc)
52  return FALSE; /* already registered */
53  }
54 
55  if (conn->nEvents >= conn->eventArraySize)
56  {
57  PGEvent *e;
58  int newSize;
59 
60  newSize = conn->eventArraySize ? conn->eventArraySize * 2 : 8;
61  if (conn->events)
62  e = (PGEvent *) realloc(conn->events, newSize * sizeof(PGEvent));
63  else
64  e = (PGEvent *) malloc(newSize * sizeof(PGEvent));
65 
66  if (!e)
67  return FALSE;
68 
69  conn->eventArraySize = newSize;
70  conn->events = e;
71  }
72 
73  conn->events[conn->nEvents].proc = proc;
74  conn->events[conn->nEvents].name = strdup(name);
75  if (!conn->events[conn->nEvents].name)
76  return FALSE;
77  conn->events[conn->nEvents].passThrough = passThrough;
78  conn->events[conn->nEvents].data = NULL;
79  conn->events[conn->nEvents].resultInitialized = FALSE;
80  conn->nEvents++;
81 
82  regevt.conn = conn;
83  if (!proc(PGEVT_REGISTER, &regevt, passThrough))
84  {
85  conn->nEvents--;
86  free(conn->events[conn->nEvents].name);
87  return FALSE;
88  }
89 
90  return TRUE;
91 }
PGEvent * events
Definition: libpq-int.h:373
bool resultInitialized
Definition: libpq-int.h:164
int eventArraySize
Definition: libpq-int.h:375
#define malloc(a)
Definition: header.h:50
#define FALSE
Definition: c.h:221
void * data
Definition: libpq-int.h:163
PGconn * conn
Definition: streamutil.c:42
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
PGEventProc proc
Definition: libpq-int.h:160
#define realloc(a, b)
Definition: header.h:60
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
int nEvents
Definition: libpq-int.h:374
int i
void * passThrough
Definition: libpq-int.h:162
#define TRUE
Definition: c.h:217
char * name
Definition: libpq-int.h:161
void* PQresultInstanceData ( const PGresult result,
PGEventProc  proc 
)

Definition at line 165 of file libpq-events.c.

References PGEvent::data, pg_result::events, i, pg_result::nEvents, NULL, and PGEvent::proc.

166 {
167  int i;
168 
169  if (!result || !proc)
170  return NULL;
171 
172  for (i = 0; i < result->nEvents; i++)
173  if (result->events[i].proc == proc)
174  return result->events[i].data;
175 
176  return NULL;
177 }
int nEvents
Definition: libpq-int.h:188
void * data
Definition: libpq-int.h:163
#define NULL
Definition: c.h:229
PGEventProc proc
Definition: libpq-int.h:160
int i
PGEvent * events
Definition: libpq-int.h:187
int PQresultSetInstanceData ( PGresult result,
PGEventProc  proc,
void *  data 
)

Definition at line 142 of file libpq-events.c.

References PGEvent::data, pg_result::events, FALSE, i, pg_result::nEvents, PGEvent::proc, and TRUE.

143 {
144  int i;
145 
146  if (!result || !proc)
147  return FALSE;
148 
149  for (i = 0; i < result->nEvents; i++)
150  {
151  if (result->events[i].proc == proc)
152  {
153  result->events[i].data = data;
154  return TRUE;
155  }
156  }
157 
158  return FALSE;
159 }
int nEvents
Definition: libpq-int.h:188
#define FALSE
Definition: c.h:221
void * data
Definition: libpq-int.h:163
PGEventProc proc
Definition: libpq-int.h:160
int i
#define TRUE
Definition: c.h:217
PGEvent * events
Definition: libpq-int.h:187
int PQsetInstanceData ( PGconn conn,
PGEventProc  proc,
void *  data 
)

Definition at line 98 of file libpq-events.c.

References PGEvent::data, pg_conn::events, FALSE, i, pg_conn::nEvents, PGEvent::proc, and TRUE.

99 {
100  int i;
101 
102  if (!conn || !proc)
103  return FALSE;
104 
105  for (i = 0; i < conn->nEvents; i++)
106  {
107  if (conn->events[i].proc == proc)
108  {
109  conn->events[i].data = data;
110  return TRUE;
111  }
112  }
113 
114  return FALSE;
115 }
PGEvent * events
Definition: libpq-int.h:373
#define FALSE
Definition: c.h:221
void * data
Definition: libpq-int.h:163
PGEventProc proc
Definition: libpq-int.h:160
int nEvents
Definition: libpq-int.h:374
int i
#define TRUE
Definition: c.h:217