return;
mutt_hash_free(&(*cs)->hash);
+ notify_free(&(*cs)->notify);
FREE(cs);
}
if (!ptr || !*ptr)
return;
- // struct Notify *notify = *ptr;
+ struct Notify *notify = *ptr;
// NOTIFY observers
- // FREE observers
+
+ notify_observer_remove(notify, NULL);
FREE(ptr);
}
* @param notify Notification handler
* @param callback Function to call on a matching event, see ::observer_t
* @retval true If successful
+ *
+ * If callback is NULL, all the observers will be removed.
*/
bool notify_observer_remove(struct Notify *notify, observer_t callback)
{
- if (!notify || !callback)
+ if (!notify)
return false;
struct ObserverNode *np = NULL;
STAILQ_FOREACH(np, ¬ify->observers, entries)
{
- if (np->observer->callback == callback)
+ if (!callback || (np->observer->callback == callback))
{
STAILQ_REMOVE(¬ify->observers, np, ObserverNode, entries);
FREE(&np->observer);
set_list(cs);
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
const char *account = "damaged";
const char *BrokenVarStr[] = {
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
TEST_MSG("%s\n", line + 40);
}
-bool log_observer(const struct ConfigSet *cs, struct HashElem *he,
- const char *name, enum ConfigEvent ev)
+int log_observer(struct NotifyCallback *nc)
{
+ if (!nc)
+ return -1;
+
+ struct EventConfig *ec = (struct EventConfig *) nc->event;
+
struct Buffer result;
mutt_buffer_init(&result);
result.dsize = 256;
mutt_buffer_reset(&result);
- if (ev != CE_INITIAL_SET)
- cs_he_string_get(cs, he, &result);
+ if (nc->event_type != NT_CONFIG_INITIAL_SET)
+ cs_he_string_get(ec->cs, ec->he, &result);
else
- cs_he_initial_get(cs, he, &result);
+ cs_he_initial_get(ec->cs, ec->he, &result);
- TEST_MSG("Event: %s has been %s to '%s'\n", name, events[ev - 1], result.data);
+ TEST_MSG("Event: %s has been %s to '%s'\n", ec->name, events[nc->event_type - 1], result.data);
FREE(&result.data);
return true;
struct Buffer;
struct Hash;
struct HashElem;
+struct NotifyCallback;
extern const char *line;
extern bool dont_fail;
void log_line(const char *fn);
void short_line(void);
-bool log_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+int log_observer(struct NotifyCallback *nc);
void set_list(const struct ConfigSet *cs);
void cs_dump_set(const struct ConfigSet *cs);
if (!cs_register_variables(cs, Vars, 0))
return;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
TEST_CHECK_(1, "cs_init(NULL, 100)");
cs_free(NULL);
TEST_CHECK_(1, "cs_free(NULL)");
- cs_add_observer(cs, NULL);
- TEST_CHECK_(1, "cs_add_observer(cs, NULL)");
- cs_add_observer(NULL, log_observer);
- TEST_CHECK_(1, "cs_add_observer(NULL, log_observer)");
- cs_remove_observer(cs, NULL);
- TEST_CHECK_(1, "cs_remove_observer(cs, NULL)");
- cs_remove_observer(NULL, log_observer);
- TEST_CHECK_(1, "cs_remove_observer(NULL, log_observer)");
- cs_notify_observers(NULL, he, "apple", CE_SET);
- TEST_CHECK_(1, "cs_notify_observers(NULL, he, \"apple\", CE_SET)");
- cs_notify_observers(cs, NULL, "apple", CE_SET);
- TEST_CHECK_(1, "cs_notify_observers(cs, NULL, \"apple\", CE_SET)");
- cs_notify_observers(cs, he, NULL, CE_SET);
- TEST_CHECK_(1, "cs_notify_observers(cs, he, NULL, CE_SET)");
+ cs_notify_observers(NULL, he, "apple", NT_CONFIG_SET);
+ TEST_CHECK_(1, "cs_notify_observers(NULL, he, \"apple\", NT_CONFIG_SET)");
+ cs_notify_observers(cs, NULL, "apple", NT_CONFIG_SET);
+ TEST_CHECK_(1, "cs_notify_observers(cs, NULL, \"apple\", NT_CONFIG_SET)");
+ cs_notify_observers(cs, he, NULL, NT_CONFIG_SET);
+ TEST_CHECK_(1, "cs_notify_observers(cs, he, NULL, NT_CONFIG_SET)");
if (!TEST_CHECK(cs_register_type(NULL, DT_NUMBER, &cst_dummy) == false))
return false;
if (!TEST_CHECK(cs != NULL))
return;
- cs_add_observer(cs, log_observer);
- cs_add_observer(cs, log_observer); /* dupe */
- cs_remove_observer(cs, log_observer);
- cs_remove_observer(cs, log_observer); /* non-existant */
-
const struct ConfigSetType cst_dummy = {
"dummy", NULL, NULL, NULL, NULL, NULL, NULL,
};
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
dont_fail = false;
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);
return;
}
- cs_add_observer(cs, log_observer);
+ notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
set_list(cs);