blob: b19380284b8591fea7c6410ae37b9e19f4c22c2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2006, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
#include <cstdlib>
#include <cstring>
#include <db_cxx.h>
// Chainable struct used to store host information.
typedef struct RepHostInfoObj{
char* host;
u_int16_t port;
RepHostInfoObj* next; // used for chaining multiple "other" hosts.
bool creator;
} REP_HOST_INFO;
class RepConfigInfo {
public:
RepConfigInfo();
virtual ~RepConfigInfo();
void addOtherHost(char* host, int port);
public:
u_int32_t start_policy;
char* home;
bool got_listen_address;
REP_HOST_INFO this_host;
int nrsites;
int priority;
// used to store a set of optional other hosts.
REP_HOST_INFO *other_hosts;
};
RepConfigInfo::RepConfigInfo()
{
start_policy = DB_REP_ELECTION;
home = NULL;
got_listen_address = false;
nrsites = 0;
priority = 100;
other_hosts = NULL;
}
RepConfigInfo::~RepConfigInfo()
{
// release any other_hosts structs.
if (other_hosts != NULL) {
REP_HOST_INFO *CurItem = other_hosts;
while (CurItem->next != NULL) {
REP_HOST_INFO *TmpItem = CurItem->next;
free(CurItem);
CurItem = TmpItem;
}
free(CurItem);
}
other_hosts = NULL;
}
void RepConfigInfo::addOtherHost(char* host, int port)
{
REP_HOST_INFO *newinfo;
newinfo = (REP_HOST_INFO*)malloc(sizeof(REP_HOST_INFO));
newinfo->host = host;
newinfo->port = port;
if (other_hosts == NULL) {
other_hosts = newinfo;
newinfo->next = NULL;
} else {
newinfo->next = other_hosts;
other_hosts = newinfo;
}
nrsites++;
}
|