[Asterisk-code-review] func presencestate: Add ability to clear states with TEST FR... (asterisk[master])

Jonathan Rose asteriskteam at digium.com
Fri Jul 31 17:59:30 CDT 2015


Jonathan Rose has uploaded a new change for review.

  https://gerrit.asterisk.org/1027

Change subject: func_presencestate: Add ability to clear states with TEST_FRAMEWORK
......................................................................

func_presencestate: Add ability to clear states with TEST_FRAMEWORK

Adds the ability to specify 'invalid' as a state to set a custom
presence state to when using the CLI command or the Dialplan functions
for setting presence state, but only when TEST_FRAMEWORK is enabled.
Doing so will clear the presence state from the database and set the
cached stasis value to invalid (forcing it to go outside the cache when
something attempts to retrieve the value from the cache).

Change-Id: Ie5f850911bc7cf473c458d2e14cee3857c4a8274
---
M funcs/func_presencestate.c
M main/presencestate.c
2 files changed, 16 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/27/1027/1

diff --git a/funcs/func_presencestate.c b/funcs/func_presencestate.c
index 775c7dc..c356d7c 100644
--- a/funcs/func_presencestate.c
+++ b/funcs/func_presencestate.c
@@ -177,8 +177,13 @@
 
 	*state = ast_presence_state_val(state_str);
 
+#ifdef TEST_FRAMEWORK
+	/* Allow setting invalid state when in test mode, but only if the state_str is explicitly 'invalid' */
+	if (strcasecmp(state_str, "invalid") && (*state == AST_PRESENCE_INVALID)) {
+#else
 	/* not a valid state */
 	if (*state == AST_PRESENCE_INVALID) {
+#endif
 		ast_log(LOG_WARNING, "Unknown presence state value %s\n", state_str);
 		return -1;
 	}
@@ -242,6 +247,10 @@
 		ast_presence_state_changed_literal(state, decoded_subtype, decoded_message, tmp);
 	} else {
 		ast_presence_state_changed_literal(state, subtype, message, tmp);
+	}
+
+	if (state == AST_PRESENCE_INVALID) {
+		ast_db_del(astdb_family, data);
 	}
 
 	return 0;
@@ -437,6 +446,10 @@
 
 	ast_presence_state_changed_literal(state_val, subtype, message, full_dev);
 
+	if (state_val == AST_PRESENCE_INVALID) {
+		ast_db_del(astdb_family, dev);
+	}
+
 	return CLI_SUCCESS;
 }
 
diff --git a/main/presencestate.c b/main/presencestate.c
index 3be2ebe..fc425a4 100644
--- a/main/presencestate.c
+++ b/main/presencestate.c
@@ -81,6 +81,9 @@
 	{ "xa", AST_PRESENCE_XA},
 	{ "chat", AST_PRESENCE_CHAT},
 	{ "dnd", AST_PRESENCE_DND},
+#ifdef TEST_FRAMEWORK
+	{ "invalid", AST_PRESENCE_INVALID},
+#endif
 };
 
 static struct ast_manager_event_blob *presence_state_to_ami(struct stasis_message *msg);

-- 
To view, visit https://gerrit.asterisk.org/1027
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie5f850911bc7cf473c458d2e14cee3857c4a8274
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Jonathan Rose <jrose at digium.com>



More information about the asterisk-code-review mailing list