libcouchbase 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/ext/libcouchbase/CMakeLists.txt +8 -6
  5. data/ext/libcouchbase/README.markdown +2 -2
  6. data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
  7. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
  8. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
  9. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
  10. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  11. data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
  12. data/ext/libcouchbase/cmake/defs.mk.in +2 -0
  13. data/ext/libcouchbase/cmake/source_files.cmake +5 -21
  14. data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
  15. data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
  16. data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
  17. data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
  18. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  19. data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
  20. data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
  21. data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
  22. data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
  23. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
  26. data/ext/libcouchbase/src/README.md +2 -0
  27. data/ext/libcouchbase/src/auth-priv.h +0 -1
  28. data/ext/libcouchbase/src/auth.cc +4 -10
  29. data/ext/libcouchbase/src/bootstrap.c +269 -0
  30. data/ext/libcouchbase/src/bootstrap.h +39 -50
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
  37. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  38. data/ext/libcouchbase/src/cbft.cc +27 -22
  39. data/ext/libcouchbase/src/cntl.cc +19 -30
  40. data/ext/libcouchbase/src/connspec.cc +1 -48
  41. data/ext/libcouchbase/src/connspec.h +0 -27
  42. data/ext/libcouchbase/src/dump.cc +2 -2
  43. data/ext/libcouchbase/src/getconfig.cc +33 -7
  44. data/ext/libcouchbase/src/handler.cc +2 -0
  45. data/ext/libcouchbase/src/hostlist.cc +36 -0
  46. data/ext/libcouchbase/src/hostlist.h +62 -41
  47. data/ext/libcouchbase/src/http/http-priv.h +112 -125
  48. data/ext/libcouchbase/src/http/http.cc +30 -15
  49. data/ext/libcouchbase/src/http/http.h +34 -1
  50. data/ext/libcouchbase/src/http/http_io.cc +26 -22
  51. data/ext/libcouchbase/src/instance.cc +23 -94
  52. data/ext/libcouchbase/src/internal.h +26 -52
  53. data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
  54. data/ext/libcouchbase/src/jsparse/parser.h +98 -91
  55. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  56. data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
  57. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  58. data/ext/libcouchbase/src/lcbio/connect.h +2 -9
  59. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  60. data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
  61. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  62. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  63. data/ext/libcouchbase/src/mc/mcreq.h +2 -9
  64. data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
  65. data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
  66. data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
  67. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  68. data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
  69. data/ext/libcouchbase/src/newconfig.cc +6 -6
  70. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  71. data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
  72. data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
  73. data/ext/libcouchbase/src/operations/durability.cc +26 -6
  74. data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
  75. data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
  76. data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
  77. data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
  78. data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
  79. data/ext/libcouchbase/src/operations/stats.cc +8 -3
  80. data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
  81. data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
  82. data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
  83. data/ext/libcouchbase/src/packetutils.c +37 -0
  84. data/ext/libcouchbase/src/packetutils.h +2 -2
  85. data/ext/libcouchbase/src/probes.d +1 -1
  86. data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
  87. data/ext/libcouchbase/src/retryq.cc +4 -4
  88. data/ext/libcouchbase/src/settings.c +0 -3
  89. data/ext/libcouchbase/src/settings.h +0 -5
  90. data/ext/libcouchbase/src/simplestring.c +211 -0
  91. data/ext/libcouchbase/src/simplestring.h +228 -0
  92. data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
  93. data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
  94. data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
  95. data/ext/libcouchbase/src/ssobuf.h +82 -0
  96. data/ext/libcouchbase/src/trace.h +4 -4
  97. data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
  98. data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
  99. data/ext/libcouchbase/src/views/docreq.h +30 -24
  100. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  101. data/ext/libcouchbase/src/views/viewreq.h +13 -43
  102. data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
  103. data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
  104. data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
  105. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  106. data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
  107. data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
  108. data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
  109. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  110. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  111. data/lib/libcouchbase/ext/tasks.rb +6 -2
  112. data/lib/libcouchbase/query_view.rb +1 -1
  113. data/lib/libcouchbase/results_fiber.rb +6 -6
  114. data/lib/libcouchbase/version.rb +1 -1
  115. metadata +26 -26
  116. data/ext/libcouchbase/src/bootstrap.cc +0 -216
  117. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
  118. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
  119. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
  120. data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
  121. data/ext/libcouchbase/src/dns-srv.cc +0 -142
  122. data/ext/libcouchbase/src/errmap.cc +0 -107
  123. data/ext/libcouchbase/src/errmap.h +0 -113
  124. data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
  125. data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
  126. data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
  127. data/ext/libcouchbase/src/mctx-helper.h +0 -51
  128. data/ext/libcouchbase/src/views/viewreq.cc +0 -318
  129. data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -1,115 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2014 Couchbase, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- #include <lcbio/lcbio.h>
19
- #include <lcbio/timer-ng.h>
20
- #include <lcbio/timer-cxx.h>
21
- #include <libcouchbase/vbucket.h>
22
- #include "clconfig.h"
23
-
24
- #define LOGARGS(mcr, lvlbase) mcr->parent->settings, "mcraw", LCB_LOG_##lvlbase, __FILE__, __LINE__
25
- #define LOGFMT "(MCRAW=%p)> "
26
- #define LOGID(mcr) (void *)mcr
27
-
28
- using namespace lcb::clconfig;
29
-
30
- /* Raw memcached provider */
31
-
32
- struct McRawProvider : Provider {
33
- McRawProvider(Confmon*);
34
- ~McRawProvider();
35
-
36
- /* Overrides */
37
- ConfigInfo* get_cached();
38
- lcb_error_t refresh();
39
- void configure_nodes(const lcb::Hostlist& l);
40
- void async_update();
41
-
42
- /* Current (user defined) configuration */
43
- ConfigInfo *config;
44
- lcb::io::Timer<McRawProvider, &McRawProvider::async_update> async;
45
- };
46
-
47
-
48
- void McRawProvider::async_update() {
49
- if (!config) {
50
- lcb_log(LOGARGS(this, WARN), "No current config set. Not setting configuration");
51
- return;
52
- }
53
- parent->provider_got_config(this, config);
54
- }
55
-
56
- ConfigInfo* McRawProvider::get_cached() {
57
- return config;
58
- }
59
-
60
- lcb_error_t McRawProvider::refresh() {
61
- async.signal();
62
- return LCB_SUCCESS;
63
- }
64
-
65
- void McRawProvider::configure_nodes(const lcb::Hostlist& hl)
66
- {
67
- lcbvb_SERVER *servers;
68
- lcbvb_CONFIG *newconfig;
69
- unsigned nsrv = hl.size();
70
-
71
- if (!nsrv) {
72
- lcb_log(LOGARGS(this, FATAL), "No nodes provided");
73
- return;
74
- }
75
-
76
- servers = reinterpret_cast<lcbvb_SERVER*>(calloc(nsrv, sizeof(*servers)));
77
- for (size_t ii = 0; ii < nsrv; ii++) {
78
- const lcb_host_t& curhost = hl[ii];
79
- lcbvb_SERVER *srv = servers + ii;
80
-
81
- /* just set the memcached port and hostname */
82
- srv->hostname = (char *)curhost.host;
83
- srv->svc.data = std::atoi(curhost.port);
84
- if (parent->settings->sslopts) {
85
- srv->svc_ssl.data = srv->svc.data;
86
- }
87
- }
88
-
89
- newconfig = lcbvb_create();
90
- lcbvb_genconfig_ex(newconfig, "NOBUCKET", "deadbeef", servers, nsrv, 0, 2);
91
- lcbvb_make_ketama(newconfig);
92
- newconfig->revid = -1;
93
-
94
- if (config) {
95
- config->decref();
96
- config = NULL;
97
- }
98
- config = ConfigInfo::create(newconfig, CLCONFIG_MCRAW);
99
- }
100
-
101
- McRawProvider::~McRawProvider() {
102
- if (config) {
103
- config->decref();
104
- }
105
- async.release();
106
- }
107
-
108
- Provider* lcb::clconfig::new_mcraw_provider(Confmon* parent) {
109
- return new McRawProvider(parent);
110
- }
111
-
112
- McRawProvider::McRawProvider(Confmon *parent_)
113
- : Provider(parent_, CLCONFIG_MCRAW),
114
- config(NULL), async(parent->iot, this) {
115
- }
@@ -1,378 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2013 Couchbase, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- #include "internal.h"
19
- #include "clconfig.h"
20
- #include <list>
21
- #include <algorithm>
22
-
23
- #define LOGARGS(mon, lvlbase) mon->settings, "confmon", LCB_LOG_##lvlbase, __FILE__, __LINE__
24
- #define LOG(mon, lvlbase, msg) lcb_log(mon->settings, "confmon", LCB_LOG_##lvlbase, __FILE__, __LINE__, msg)
25
-
26
- using namespace lcb::clconfig;
27
-
28
- Provider* Confmon::next_active(Provider *cur) {
29
- ProviderList::iterator ii = std::find(
30
- active_providers.begin(), active_providers.end(), cur);
31
-
32
- if (ii == active_providers.end() || (++ii) == active_providers.end()) {
33
- return NULL;
34
- } else {
35
- return *ii;
36
- }
37
- }
38
-
39
- Provider* Confmon::first_active()
40
- {
41
- if (active_providers.empty()) {
42
- return NULL;
43
- } else {
44
- return active_providers.front();
45
- }
46
- }
47
-
48
- static const char *
49
- provider_string(Method type) {
50
- if (type == CLCONFIG_HTTP) { return "HTTP"; }
51
- if (type == CLCONFIG_CCCP) { return "CCCP"; }
52
- if (type == CLCONFIG_FILE) { return "FILE"; }
53
- if (type == CLCONFIG_MCRAW) { return "MCRAW"; }
54
- return "";
55
- }
56
-
57
- Confmon::Confmon(lcb_settings *settings_, lcbio_pTABLE iot_)
58
- : cur_provider(NULL),
59
- config(NULL),
60
- settings(settings_),
61
- last_error(LCB_SUCCESS),
62
- iot(iot_),
63
- as_start(iot_, this),
64
- as_stop(iot_, this),
65
- state(0),
66
- last_stop_us(0) {
67
-
68
- lcbio_table_ref(iot);
69
- lcb_settings_ref(settings);
70
-
71
- all_providers[CLCONFIG_FILE] = new_file_provider(this);
72
- all_providers[CLCONFIG_CCCP] = new_cccp_provider(this);
73
- all_providers[CLCONFIG_HTTP] = new_http_provider(this);
74
- all_providers[CLCONFIG_MCRAW] = new_mcraw_provider(this);
75
-
76
- for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
77
- all_providers[ii]->parent = this;
78
- }
79
- }
80
-
81
- void Confmon::prepare() {
82
- active_providers.clear();
83
- lcb_log(LOGARGS(this, DEBUG), "Preparing providers (this may be called multiple times)");
84
-
85
- for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
86
- Provider *cur = all_providers[ii];
87
- if (cur) {
88
- if (cur->enabled) {
89
- active_providers.push_back(cur);
90
- lcb_log(LOGARGS(this, DEBUG), "Provider %s is ENABLED", provider_string(cur->type));
91
- } else if (cur->pause()) {
92
- lcb_log(LOGARGS(this, DEBUG), "Provider %s is DISABLED", provider_string(cur->type));
93
- }
94
- }
95
- }
96
-
97
- lcb_assert(!active_providers.empty());
98
- cur_provider = first_active();
99
- }
100
-
101
- Confmon::~Confmon() {
102
- as_start.release();
103
- as_stop.release();
104
-
105
- if (config) {
106
- config->decref();
107
- config = NULL;
108
- }
109
-
110
- for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
111
- Provider *provider = all_providers[ii];
112
- if (provider == NULL) {
113
- continue;
114
- }
115
- delete provider;
116
- all_providers[ii] = NULL;
117
- }
118
-
119
- lcbio_table_unref(iot);
120
- lcb_settings_unref(settings);
121
- }
122
-
123
- int Confmon::do_set_next(ConfigInfo *new_config, bool notify_miss)
124
- {
125
- unsigned ii;
126
-
127
- if (config) {
128
- lcbvb_CHANGETYPE chstatus = LCBVB_NO_CHANGES;
129
- lcbvb_CONFIGDIFF *diff = lcbvb_compare(config->vbc, new_config->vbc);
130
-
131
- if (!diff) {
132
- lcb_log(LOGARGS(this, DEBUG), "Couldn't create vbucket diff");
133
- return 0;
134
- }
135
-
136
- chstatus = lcbvb_get_changetype(diff);
137
- lcbvb_free_diff(diff);
138
-
139
- if (chstatus == 0 || config->compare(*new_config) >= 0) {
140
- const lcbvb_CONFIG *ca, *cb;
141
-
142
- ca = config->vbc;
143
- cb = new_config->vbc;
144
-
145
- lcb_log(LOGARGS(this, INFO), "Not applying configuration received via %s. No changes detected. A.rev=%d, B.rev=%d", provider_string(new_config->get_origin()), ca->revid, cb->revid);
146
- if (notify_miss) {
147
- invoke_listeners(CLCONFIG_EVENT_GOT_ANY_CONFIG, new_config);
148
- }
149
- return 0;
150
- }
151
- }
152
-
153
- lcb_log(LOGARGS(this, INFO), "Setting new configuration. Received via %s", provider_string(new_config->get_origin()));
154
-
155
- if (config) {
156
- /** DECREF the old one */
157
- config->decref();
158
- }
159
-
160
- for (ii = 0; ii < CLCONFIG_MAX; ii++) {
161
- Provider *cur = all_providers[ii];
162
- if (cur && cur->enabled) {
163
- cur->config_updated(new_config->vbc);
164
- }
165
- }
166
-
167
- new_config->incref();
168
- config = new_config;
169
- stop();
170
-
171
- invoke_listeners(CLCONFIG_EVENT_GOT_NEW_CONFIG, new_config);
172
-
173
- return 1;
174
- }
175
-
176
- void Confmon::provider_failed(Provider *provider, lcb_error_t reason) {
177
- lcb_log(LOGARGS(this, INFO), "Provider '%s' failed", provider_string(provider->type));
178
-
179
- if (provider != cur_provider) {
180
- lcb_log(LOGARGS(this, TRACE), "Ignoring failure. Current=%p (%s)", (void*)cur_provider, provider_string(cur_provider->type));
181
- return;
182
- }
183
- if (!is_refreshing()) {
184
- lcb_log(LOGARGS(this, DEBUG), "Ignoring failure. Refresh not active");
185
- }
186
-
187
- if (reason != LCB_SUCCESS) {
188
- if (settings->detailed_neterr && last_error != LCB_SUCCESS) {
189
- /* Filter out any artificial 'connect error' or 'network error' codes */
190
- if (reason != LCB_CONNECT_ERROR && reason != LCB_NETWORK_ERROR) {
191
- last_error = reason;
192
- }
193
- } else {
194
- last_error = reason;
195
- }
196
- }
197
-
198
- cur_provider = next_active(cur_provider);
199
-
200
- if (!cur_provider) {
201
- LOG(this, TRACE, "Maximum provider reached. Resetting index");
202
- invoke_listeners(CLCONFIG_EVENT_PROVIDERS_CYCLED, NULL);
203
- cur_provider = first_active();
204
- stop();
205
- } else {
206
- uint32_t interval = 0;
207
- if (config) {
208
- /* Not first */
209
- interval = settings->grace_next_provider;
210
- }
211
- lcb_log(LOGARGS(this, DEBUG), "Will try next provider in %uus", interval);
212
- state |= CONFMON_S_ITERGRACE;
213
- as_start.rearm(interval);
214
- }
215
- }
216
-
217
- void Confmon::provider_got_config(Provider *, ConfigInfo *config_) {
218
- do_set_next(config_, true);
219
- stop();
220
- }
221
-
222
- void Confmon::do_next_provider()
223
- {
224
- state &= ~CONFMON_S_ITERGRACE;
225
- for (ProviderList::const_iterator ii = active_providers.begin();
226
- ii != active_providers.end(); ++ii) {
227
- ConfigInfo *info;
228
- Provider* cached_provider = *ii;
229
- info = cached_provider->get_cached();
230
- if (!info) {
231
- continue;
232
- }
233
-
234
- if (do_set_next(info, false)) {
235
- LOG(this, DEBUG, "Using cached configuration");
236
- }
237
- }
238
-
239
- lcb_log(LOGARGS(this, TRACE), "Attempting to retrieve cluster map via %s", provider_string(cur_provider->type));
240
-
241
- cur_provider->refresh();
242
- }
243
-
244
- void Confmon::start() {
245
- lcb_U32 tmonext = 0;
246
- as_stop.cancel();
247
- if (is_refreshing()) {
248
- LOG(this, DEBUG, "Cluster map refresh already in progress");
249
- return;
250
- }
251
-
252
- LOG(this, TRACE, "Refreshing current cluster map");
253
- lcb_assert(cur_provider);
254
- state = CONFMON_S_ACTIVE|CONFMON_S_ITERGRACE;
255
-
256
- if (last_stop_us > 0) {
257
- lcb_U32 diff = LCB_NS2US(gethrtime()) - last_stop_us;
258
- if (diff <= settings->grace_next_cycle) {
259
- tmonext = settings->grace_next_cycle - diff;
260
- }
261
- }
262
-
263
- as_start.rearm(tmonext);
264
- }
265
-
266
- void Confmon::stop_real() {
267
- ProviderList::const_iterator ii;
268
- for (ii = active_providers.begin(); ii != active_providers.end(); ++ii) {
269
- (*ii)->pause();
270
- }
271
-
272
- last_stop_us = LCB_NS2US(gethrtime());
273
- invoke_listeners(CLCONFIG_EVENT_MONITOR_STOPPED, NULL);
274
- }
275
-
276
- void Confmon::stop() {
277
- if (!is_refreshing()) {
278
- return;
279
- }
280
- as_start.cancel();
281
- as_stop.cancel();
282
- state = CONFMON_S_INACTIVE;
283
- }
284
-
285
- Provider::Provider(Confmon *parent_, Method type_)
286
- : type(type_), enabled(false), parent(parent_) {
287
- }
288
-
289
- Provider::~Provider() {
290
- parent = NULL;
291
- }
292
-
293
- ConfigInfo::~ConfigInfo() {
294
- if (vbc) {
295
- lcbvb_destroy(vbc);
296
- }
297
- }
298
-
299
- int ConfigInfo::compare(const ConfigInfo& other) {
300
- /** First check if both have revisions */
301
- int rev_a, rev_b;
302
- rev_a = lcbvb_get_revision(this->vbc);
303
- rev_b = lcbvb_get_revision(other.vbc);
304
- if (rev_a >= 0 && rev_b >= 0) {
305
- return rev_a - rev_b;
306
- }
307
-
308
- if (this->cmpclock == other.cmpclock) {
309
- return 0;
310
-
311
- } else if (this->cmpclock < other.cmpclock) {
312
- return -1;
313
- }
314
-
315
- return 1;
316
- }
317
-
318
- ConfigInfo::ConfigInfo(lcbvb_CONFIG *config_, Method origin_)
319
- : vbc(config_), cmpclock(gethrtime()), refcount(1), origin(origin_) {
320
- }
321
-
322
- void Confmon::add_listener(Listener *lsn) {
323
- listeners.push_back(lsn);
324
- }
325
-
326
- void Confmon::remove_listener(Listener *lsn) {
327
- listeners.remove(lsn);
328
- }
329
-
330
- void Confmon::invoke_listeners(EventType event, ConfigInfo *info) {
331
- ListenerList::iterator ii = listeners.begin();
332
- while (ii != listeners.end()) {
333
- ListenerList::iterator cur = ii++;
334
- (*cur)->clconfig_lsn(event, info);
335
- }
336
- }
337
-
338
-
339
- void Confmon::set_active(Method type, bool enabled)
340
- {
341
- Provider *provider = all_providers[type];
342
- if (provider->enabled == enabled) {
343
- return;
344
- } else {
345
- provider->enabled = enabled;
346
- }
347
- prepare();
348
- }
349
-
350
- void Confmon::dump(FILE *fp) {
351
- fprintf(fp, "CONFMON=%p\n", (void*)this);
352
- fprintf(fp, "STATE= (0x%x)", state);
353
- if (state & CONFMON_S_ACTIVE) {
354
- fprintf(fp, "ACTIVE|");
355
- }
356
- if (state == CONFMON_S_INACTIVE) {
357
- fprintf(fp, "INACTIVE/IDLE");
358
- }
359
- if (state & CONFMON_S_ITERGRACE) {
360
- fprintf(fp, "ITERGRACE");
361
- }
362
- fprintf(fp, "\n");
363
- fprintf(fp, "LAST ERROR: 0x%x\n", last_error);
364
-
365
-
366
- for (size_t ii = 0; ii < CLCONFIG_MAX; ii++) {
367
- Provider *cur = all_providers[ii];
368
- if (!cur) {
369
- continue;
370
- }
371
-
372
- fprintf(fp, "** PROVIDER: 0x%x (%s) %p\n", cur->type, provider_string(cur->type), (void*)cur);
373
- fprintf(fp, "** ENABLED: %s\n", cur->enabled ? "YES" : "NO");
374
- fprintf(fp, "** CURRENT: %s\n", cur == cur_provider ? "YES" : "NO");
375
- cur->dump(fp);
376
- fprintf(fp, "\n");
377
- }
378
- }