PostgreSQL Source Code  git master
basebackup_target.h File Reference
Include dependency graph for basebackup_target.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct BaseBackupTargetHandle BaseBackupTargetHandle
 

Functions

void BaseBackupAddTarget (char *name, void *(*check_detail)(char *, char *), bbsink *(*get_sink)(bbsink *, void *))
 
BaseBackupTargetHandleBaseBackupGetTargetHandle (char *target, char *target_detail)
 
bbsinkBaseBackupGetSink (BaseBackupTargetHandle *handle, bbsink *next_sink)
 

Typedef Documentation

◆ BaseBackupTargetHandle

Definition at line 1 of file basebackup_target.h.

Function Documentation

◆ BaseBackupAddTarget()

void BaseBackupAddTarget ( char *  name,
void *(*)(char *, char *)  check_detail,
bbsink *(*)(bbsink *, void *)  get_sink 
)

Definition at line 61 of file basebackup_target.c.

64 {
65  BaseBackupTargetType *ttype;
66  MemoryContext oldcontext;
67  ListCell *lc;
68 
69  /* If the target list is not yet initialized, do that first. */
72 
73  /* Search the target type list for an existing entry with this name. */
74  foreach(lc, BaseBackupTargetTypeList)
75  {
76  BaseBackupTargetType *ttype = lfirst(lc);
77 
78  if (strcmp(ttype->name, name) == 0)
79  {
80  /*
81  * We found one, so update it.
82  *
83  * It is probably not a great idea to call BaseBackupAddTarget for
84  * the same name multiple times, but if it happens, this seems
85  * like the sanest behavior.
86  */
87  ttype->check_detail = check_detail;
88  ttype->get_sink = get_sink;
89  return;
90  }
91  }
92 
93  /*
94  * We use TopMemoryContext for allocations here to make sure that the data
95  * we need doesn't vanish under us; that's also why we copy the target
96  * name into a newly-allocated chunk of memory.
97  */
99  ttype = palloc(sizeof(BaseBackupTargetType));
100  ttype->name = pstrdup(name);
101  ttype->check_detail = check_detail;
102  ttype->get_sink = get_sink;
104  MemoryContextSwitchTo(oldcontext);
105 }
static List * BaseBackupTargetTypeList
static void initialize_target_list(void)
const char * name
Definition: encode.c:561
List * lappend(List *list, void *datum)
Definition: list.c:336
char * pstrdup(const char *in)
Definition: mcxt.c:1305
MemoryContext TopMemoryContext
Definition: mcxt.c:48
void * palloc(Size size)
Definition: mcxt.c:1068
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define lfirst(lc)
Definition: pg_list.h:169
#define NIL
Definition: pg_list.h:65
void *(* check_detail)(char *, char *)
bbsink *(* get_sink)(bbsink *, void *)

References BaseBackupTargetTypeList, BaseBackupTargetType::check_detail, BaseBackupTargetType::get_sink, initialize_target_list(), lappend(), lfirst, MemoryContextSwitchTo(), BaseBackupTargetType::name, name, NIL, palloc(), pstrdup(), and TopMemoryContext.

Referenced by _PG_init().

◆ BaseBackupGetSink()

bbsink* BaseBackupGetSink ( BaseBackupTargetHandle handle,
bbsink next_sink 
)

Definition at line 163 of file basebackup_target.c.

164 {
165  return handle->type->get_sink(next_sink, handle->detail_arg);
166 }
BaseBackupTargetType * type

References BaseBackupTargetHandle::detail_arg, BaseBackupTargetType::get_sink, and BaseBackupTargetHandle::type.

Referenced by SendBaseBackup().

◆ BaseBackupGetTargetHandle()

BaseBackupTargetHandle* BaseBackupGetTargetHandle ( char *  target,
char *  target_detail 
)

Definition at line 117 of file basebackup_target.c.

118 {
119  ListCell *lc;
120 
121  /* If the target list is not yet initialized, do that first. */
124 
125  /* Search the target type list for a match. */
126  foreach(lc, BaseBackupTargetTypeList)
127  {
128  BaseBackupTargetType *ttype = lfirst(lc);
129 
130  if (strcmp(ttype->name, target) == 0)
131  {
132  BaseBackupTargetHandle *handle;
133 
134  /* Found the target. */
135  handle = palloc(sizeof(BaseBackupTargetHandle));
136  handle->type = ttype;
137  handle->detail_arg = ttype->check_detail(target, target_detail);
138 
139  return handle;
140  }
141  }
142 
143  /* Did not find the target. */
144  ereport(ERROR,
145  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146  errmsg("unrecognized target: \"%s\"", target)));
147 
148  /* keep compiler quiet */
149  return NULL;
150 }
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143

References BaseBackupTargetTypeList, BaseBackupTargetType::check_detail, BaseBackupTargetHandle::detail_arg, ereport, errcode(), errmsg(), ERROR, initialize_target_list(), lfirst, BaseBackupTargetType::name, NIL, palloc(), and BaseBackupTargetHandle::type.

Referenced by parse_basebackup_options().