} results;
};
+static int td_source_change_state(td_source* self, enum td_source_state state) {
+ // If the state has not changed, we are doing nothing
+ if (self->state == state)
+ return 0;
+
+ // Store the new state
+ self->state = state;
+
+ // Log the state change
+ switch (state) {
+ case STATE_HEALTHY:
+ DEBUG(self->ctx, "%s is now healthy\n", td_source_name(self));
+ break;
+
+ case STATE_FLAPPING:
+ ERROR(self->ctx, "%s is now flapping\n", td_source_name(self));
+ break;
+
+ case STATE_ERROR:
+ ERROR(self->ctx, "%s is now in error state\n", td_source_name(self));
+ break;
+
+ case STATE_DISABLED:
+ DEBUG(self->ctx, "%s has been disabled\n", td_source_name(self));
+ break;
+ }
+
+ return 0;
+}
+
// Return the number of recent bad results
static int td_source_count_bad_results(td_source* self) {
int counter = 0;
td_source_name(self), td_source_count_bad_results(self));
}
+ // If the source has disabled itself, we don't need to change the state again
+ if (self->state == STATE_DISABLED)
+ return 0;
+
// Count all bad results
int bad_results = td_source_count_bad_results(self);
else
state = STATE_HEALTHY;
- // If the state has not changed, we are don
- if (self->state == state)
- return 0;
-
- // Store the new state
- self->state = state;
-
- // Log the state change
- switch (state) {
- case STATE_HEALTHY:
- DEBUG(self->ctx, "%s is now healthy\n", td_source_name(self));
- break;
-
- case STATE_FLAPPING:
- ERROR(self->ctx, "%s is now flapping\n", td_source_name(self));
- break;
-
- case STATE_ERROR:
- ERROR(self->ctx, "%s is now in error state\n", td_source_name(self));
- break;
-
- case STATE_DISABLED:
- ERROR(self->ctx, "%s has been disabled\n", td_source_name(self));
- break;
- }
-
- return 0;
+ // Change state
+ return td_source_change_state(self, state);
}
static uint64_t td_source_elapsed_time(void) {
return self->impl->name;
}
+// Called to disable the source (e.g. if there is no support for it)
+int td_source_disable(td_source* self) {
+ return td_source_change_state(self, STATE_DISABLED);
+}
+
struct udev* td_source_get_udev(td_source* self) {
return td_daemon_get_udev(self->daemon);
}