Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Typedefs | Enumerations | Functions

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.

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


Function Documentation

int PQfireResultCreateEvents ( PGconn conn,
PGresult res 
)

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

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

{
    int         i;

    if (!res)
        return FALSE;

    for (i = 0; i < res->nEvents; i++)
    {
        if (!res->events[i].resultInitialized)
        {
            PGEventResultCreate evt;

            evt.conn = conn;
            evt.result = res;
            if (!res->events[i].proc(PGEVT_RESULTCREATE, &evt,
                                     res->events[i].passThrough))
                return FALSE;

            res->events[i].resultInitialized = TRUE;
        }
    }

    return TRUE;
}

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, and PGEvent::proc.

{
    int         i;

    if (!conn || !proc)
        return NULL;

    for (i = 0; i < conn->nEvents; i++)
    {
        if (conn->events[i].proc == proc)
            return conn->events[i].data;
    }

    return NULL;
}

int PQregisterEventProc ( PGconn conn,
PGEventProc  proc,
const char *  name,
void *  passThrough 
)

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

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

{
    int         i;
    PGEventRegister regevt;

    if (!proc || !conn || !name || !*name)
        return FALSE;           /* bad arguments */

    for (i = 0; i < conn->nEvents; i++)
    {
        if (conn->events[i].proc == proc)
            return FALSE;       /* already registered */
    }

    if (conn->nEvents >= conn->eventArraySize)
    {
        PGEvent    *e;
        int         newSize;

        newSize = conn->eventArraySize ? conn->eventArraySize * 2 : 8;
        if (conn->events)
            e = (PGEvent *) realloc(conn->events, newSize * sizeof(PGEvent));
        else
            e = (PGEvent *) malloc(newSize * sizeof(PGEvent));

        if (!e)
            return FALSE;

        conn->eventArraySize = newSize;
        conn->events = e;
    }

    conn->events[conn->nEvents].proc = proc;
    conn->events[conn->nEvents].name = strdup(name);
    if (!conn->events[conn->nEvents].name)
        return FALSE;
    conn->events[conn->nEvents].passThrough = passThrough;
    conn->events[conn->nEvents].data = NULL;
    conn->events[conn->nEvents].resultInitialized = FALSE;
    conn->nEvents++;

    regevt.conn = conn;
    if (!proc(PGEVT_REGISTER, &regevt, passThrough))
    {
        conn->nEvents--;
        free(conn->events[conn->nEvents].name);
        return FALSE;
    }

    return TRUE;
}

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, and PGEvent::proc.

{
    int         i;

    if (!result || !proc)
        return NULL;

    for (i = 0; i < result->nEvents; i++)
        if (result->events[i].proc == proc)
            return result->events[i].data;

    return NULL;
}

int PQresultSetInstanceData ( PGresult result,
PGEventProc  proc,
void *  data 
)

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

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

{
    int         i;

    if (!result || !proc)
        return FALSE;

    for (i = 0; i < result->nEvents; i++)
    {
        if (result->events[i].proc == proc)
        {
            result->events[i].data = data;
            return TRUE;
        }
    }

    return FALSE;
}

int PQsetInstanceData ( PGconn conn,
PGEventProc  proc,
void *  data 
)

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

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

{
    int         i;

    if (!conn || !proc)
        return FALSE;

    for (i = 0; i < conn->nEvents; i++)
    {
        if (conn->events[i].proc == proc)
        {
            conn->events[i].data = data;
            return TRUE;
        }
    }

    return FALSE;
}