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