This fits in with the GoF's subject/observer pattern.
*(char *) var = !value;
- cs_notify_listeners(cs, he, he->key.strkey, CE_SET);
+ cs_notify_observers(cs, he, he->key.strkey, CE_SET);
return CSR_SUCCESS;
}
*(char *) var = quad_toggle(value);
- cs_notify_listeners(cs, he, he->key.strkey, CE_SET);
+ cs_notify_observers(cs, he, he->key.strkey, CE_SET);
return CSR_SUCCESS;
}
}
/**
- * cs_add_listener - Add a listener (callback function)
+ * cs_add_observer - Add a observer (callback function)
* @param cs Config items
- * @param fn Listener callback function
+ * @param fn Observer callback function
*/
-void cs_add_listener(struct ConfigSet *cs, cs_listener fn)
+void cs_add_observer(struct ConfigSet *cs, cs_observer fn)
{
if (!cs || !fn)
return;
- for (size_t i = 0; i < mutt_array_size(cs->listeners); i++)
+ for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
{
- if (cs->listeners[i] == fn)
+ if (cs->observers[i] == fn)
{
- mutt_debug(LL_DEBUG1, "Listener was already registered\n");
+ mutt_debug(LL_DEBUG1, "Observer was already registered\n");
return;
}
}
- for (size_t i = 0; i < mutt_array_size(cs->listeners); i++)
+ for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
{
- if (!cs->listeners[i])
+ if (!cs->observers[i])
{
- cs->listeners[i] = fn;
+ cs->observers[i] = fn;
return;
}
}
}
/**
- * cs_remove_listener - Remove a listener (callback function)
+ * cs_remove_observer - Remove a observer (callback function)
* @param cs Config items
- * @param fn Listener callback function
+ * @param fn Observer callback function
*/
-void cs_remove_listener(struct ConfigSet *cs, cs_listener fn)
+void cs_remove_observer(struct ConfigSet *cs, cs_observer fn)
{
if (!cs || !fn)
return;
- for (size_t i = 0; i < mutt_array_size(cs->listeners); i++)
+ for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
{
- if (cs->listeners[i] == fn)
+ if (cs->observers[i] == fn)
{
- cs->listeners[i] = NULL;
+ cs->observers[i] = NULL;
return;
}
}
- mutt_debug(LL_DEBUG1, "Listener wasn't registered\n");
+ mutt_debug(LL_DEBUG1, "Observer wasn't registered\n");
}
/**
- * cs_notify_listeners - Notify all listeners of an event
+ * cs_notify_observers - Notify all observers of an event
* @param cs Config items
* @param he HashElem representing config item
* @param name Name of config item
* @param ev Type of event
*/
-void cs_notify_listeners(const struct ConfigSet *cs, struct HashElem *he,
+void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he,
const char *name, enum ConfigEvent ev)
{
if (!cs || !he || !name)
return;
- for (size_t i = 0; i < mutt_array_size(cs->listeners); i++)
+ for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
{
- if (!cs->listeners[i])
+ if (!cs->observers[i])
return;
- cs->listeners[i](cs, he, name, ev);
+ cs->observers[i](cs, he, name, ev);
}
}
}
if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
- cs_notify_listeners(cs, he, he->key.strkey, CE_RESET);
+ cs_notify_observers(cs, he, he->key.strkey, CE_RESET);
return rc;
}
if (CSR_RESULT(rc) != CSR_SUCCESS)
return rc;
- cs_notify_listeners(cs, he, he->key.strkey, CE_INITIAL_SET);
+ cs_notify_observers(cs, he, he->key.strkey, CE_INITIAL_SET);
return CSR_SUCCESS;
}
he->type = i->parent->type | DT_INHERITED;
}
if (!(rc & CSR_SUC_NO_CHANGE))
- cs_notify_listeners(cs, he, he->key.strkey, CE_SET);
+ cs_notify_observers(cs, he, he->key.strkey, CE_SET);
return rc;
}
if (he->type & DT_INHERITED)
he->type = cdef->type | DT_INHERITED;
if (!(rc & CSR_SUC_NO_CHANGE))
- cs_notify_listeners(cs, he, cdef->name, CE_SET);
+ cs_notify_observers(cs, he, cdef->name, CE_SET);
}
return rc;
if (he->type & DT_INHERITED)
he->type = cdef->type | DT_INHERITED;
if (!(rc & CSR_SUC_NO_CHANGE))
- cs_notify_listeners(cs, he, cdef->name, CE_SET);
+ cs_notify_observers(cs, he, cdef->name, CE_SET);
}
return rc;
#define CSR_RESULT(x) ((x) & CSR_RESULT_MASK)
/**
- * enum CsListenerAction - Config Listener responses
+ * enum CsObserverAction - Config Observer responses
*/
-enum CsListenerAction
+enum CsObserverAction
{
- CSLA_CONTINUE = 1, ///< Continue notifying listeners
- CSLA_STOP, ///< Stop notifying listeners
+ CSOA_CONTINUE = 1, ///< Continue notifying observers
+ CSOA_STOP, ///< Stop notifying observers
};
/**
- * typedef cs_listener - Listen for config changes
+ * typedef cs_observer - Listen for config changes
* @param cs Config items
* @param he HashElem representing config item
* @param name Name of the config item
* @param ev Event type, e.g. #CE_SET
* @retval true Continue notifying
*/
-typedef bool (*cs_listener) (const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+typedef bool (*cs_observer) (const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
/**
* typedef cs_validator - Validate the "charset" config variable
* @param cs Config items
{
struct Hash *hash; /**< HashTable storing the config itesm */
struct ConfigSetType types[18]; /**< All the defined config types */
- cs_listener listeners[8]; /**< Listeners for notifications of changes to config items */
+ cs_observer observers[8]; /**< Observers for notifications of changes to config items */
};
struct ConfigSet *cs_new(size_t size);
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags);
struct HashElem *cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name);
-void cs_add_listener(struct ConfigSet *cs, cs_listener fn);
-void cs_remove_listener(struct ConfigSet *cs, cs_listener fn);
-void cs_notify_listeners(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+void cs_add_observer(struct ConfigSet *cs, cs_observer fn);
+void cs_remove_observer(struct ConfigSet *cs, cs_observer fn);
+void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
}
/**
- * mutt_reply_listener - Listen for config changes to "reply_regex" - Implements ::cs_listener()
+ * mutt_reply_observer - Listen for config changes to "reply_regex" - Implements ::cs_observer()
*/
-bool mutt_reply_listener(const struct ConfigSet *cs, struct HashElem *he,
+bool mutt_reply_observer(const struct ConfigSet *cs, struct HashElem *he,
const char *name, enum ConfigEvent ev)
{
if (mutt_str_strcmp(name, "reply_regex") != 0)
}
/**
- * mutt_mailbox_changed - Notify listeners of a change to a Mailbox
+ * mutt_mailbox_changed - Notify observers of a change to a Mailbox
* @param m Mailbox
* @param action Change to Mailbox
*/
goto main_ok; // TEST22: neomutt -B
}
- cs_add_listener(Config, mutt_hist_listener);
- cs_add_listener(Config, mutt_log_listener);
- cs_add_listener(Config, mutt_menu_listener);
- cs_add_listener(Config, mutt_reply_listener);
+ cs_add_observer(Config, mutt_hist_observer);
+ cs_add_observer(Config, mutt_log_observer);
+ cs_add_observer(Config, mutt_menu_observer);
+ cs_add_observer(Config, mutt_reply_observer);
if (sendflags & SEND_POSTPONED)
{
}
/**
- * mutt_menu_listener - Listen for config changes affecting the menu - Implements ::cs_listener()
+ * mutt_menu_observer - Listen for config changes affecting the menu - Implements ::cs_observer()
*/
-bool mutt_menu_listener(const struct ConfigSet *cs, struct HashElem *he,
+bool mutt_menu_observer(const struct ConfigSet *cs, struct HashElem *he,
const char *name, enum ConfigEvent ev)
{
const struct ConfigDef *cdef = he->data;
}
/**
- * mutt_hist_listener - Listen for config changes affecting the history - Implements ::cs_listener()
+ * mutt_hist_observer - Listen for config changes affecting the history - Implements ::cs_observer()
*/
-bool mutt_hist_listener(const struct ConfigSet *cs, struct HashElem *he,
+bool mutt_hist_observer(const struct ConfigSet *cs, struct HashElem *he,
const char *name, enum ConfigEvent ev)
{
if (mutt_str_strcmp(name, "history") != 0)
#include "mutt/mutt.h"
void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass);
-bool mutt_hist_listener(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+bool mutt_hist_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
#endif /* MUTT_MUTT_HISTORY_H */
}
/**
- * mutt_log_listener - Listen for config changes affecting the log file - Implements ::cs_listener()
+ * mutt_log_observer - Listen for config changes affecting the log file - Implements ::cs_observer()
*/
-bool mutt_log_listener(const struct ConfigSet *cs, struct HashElem *he,
+bool mutt_log_observer(const struct ConfigSet *cs, struct HashElem *he,
const char *name, enum ConfigEvent ev)
{
if (mutt_str_strcmp(name, "debug_file") == 0)
void mutt_log_stop(void);
int mutt_log_set_level(int level, bool verbose);
int mutt_log_set_file(const char *file, bool verbose);
-bool mutt_log_listener(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+bool mutt_log_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
int level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
void mutt_clear_error(void);
void mutt_menu_set_redraw_full(int menu_type);
void mutt_menu_set_redraw(int menu_type, MuttRedrawFlags redraw);
-bool mutt_menu_listener(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+bool mutt_menu_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
#endif /* MUTT_MENU_H */
int wcscasecmp(const wchar_t *a, const wchar_t *b);
#endif
-bool mutt_reply_listener(const struct ConfigSet *cs, struct HashElem *he,
+bool mutt_reply_observer(const struct ConfigSet *cs, struct HashElem *he,
const char *name, enum ConfigEvent ev);
#endif /* MUTT_PROTOS_H */
set_list(cs);
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
const char *account = "damaged";
const char *BrokenVarStr[] = {
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
TEST_MSG("%s\n", line + 40);
}
-bool log_listener(const struct ConfigSet *cs, struct HashElem *he,
+bool log_observer(const struct ConfigSet *cs, struct HashElem *he,
const char *name, enum ConfigEvent ev)
{
struct Buffer result;
void log_line(const char *fn);
void short_line(void);
-bool log_listener(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+bool log_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
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_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
TEST_CHECK_(1, "cs_init(NULL, 100)");
cs_free(NULL);
TEST_CHECK_(1, "cs_free(NULL)");
- cs_add_listener(cs, NULL);
- TEST_CHECK_(1, "cs_add_listener(cs, NULL)");
- cs_add_listener(NULL, log_listener);
- TEST_CHECK_(1, "cs_add_listener(NULL, log_listener)");
- cs_remove_listener(cs, NULL);
- TEST_CHECK_(1, "cs_remove_listener(cs, NULL)");
- cs_remove_listener(NULL, log_listener);
- TEST_CHECK_(1, "cs_remove_listener(NULL, log_listener)");
- cs_notify_listeners(NULL, he, "apple", CE_SET);
- TEST_CHECK_(1, "cs_notify_listeners(NULL, he, \"apple\", CE_SET)");
- cs_notify_listeners(cs, NULL, "apple", CE_SET);
- TEST_CHECK_(1, "cs_notify_listeners(cs, NULL, \"apple\", CE_SET)");
- cs_notify_listeners(cs, he, NULL, CE_SET);
- TEST_CHECK_(1, "cs_notify_listeners(cs, he, NULL, CE_SET)");
+ 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)");
if (!TEST_CHECK(cs_register_type(NULL, DT_NUMBER, &cst_dummy) == false))
return false;
if (!TEST_CHECK(cs != NULL))
return;
- cs_add_listener(cs, log_listener);
- cs_add_listener(cs, log_listener); /* dupe */
- cs_remove_listener(cs, log_listener);
- cs_remove_listener(cs, log_listener); /* non-existant */
+ 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_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
dont_fail = false;
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);
return;
}
- cs_add_listener(cs, log_listener);
+ cs_add_observer(cs, log_observer);
set_list(cs);