[asterisk-commits] mmichelson: branch group/CCSS r247034 - in /team/group/CCSS: channels/ includ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Feb 16 16:47:46 CST 2010
Author: mmichelson
Date: Tue Feb 16 16:47:42 2010
New Revision: 247034
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247034
Log:
All functions that previously took a debug string now take a printf-formatted string.
This will allow for easier, more accurate debugging to be done with CC-related
functions.
Note that this commit mostly is just changing the functions to be able to take
printf-formatted strings. Actually changing current uses to take advantage of this
will be done in later commits.
Modified:
team/group/CCSS/channels/chan_sip.c
team/group/CCSS/include/asterisk/ccss.h
team/group/CCSS/main/ccss.c
Modified: team/group/CCSS/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_sip.c?view=diff&rev=247034&r1=247033&r2=247034
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Tue Feb 16 16:47:42 2010
@@ -19641,10 +19641,10 @@
construct_pidf_body(CC_CLOSED, monitor_instance->suspension_entry->body, sizeof(monitor_instance->suspension_entry->body));
transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_INITIAL, monitor_instance->notify_uri);
} else {
- ast_cc_monitor_callee_available(monitor_instance->core_id);
+ ast_cc_monitor_callee_available(monitor_instance->core_id, "SIP monitored callee has become available");
}
} else {
- ast_cc_monitor_callee_available(monitor_instance->core_id);
+ ast_cc_monitor_callee_available(monitor_instance->core_id, "SIP monitored callee has become available");
}
ao2_ref(monitor_instance, -1);
transmit_response(pvt, "200 OK", req);
Modified: team/group/CCSS/include/asterisk/ccss.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/include/asterisk/ccss.h?view=diff&rev=247034&r1=247033&r2=247034
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Tue Feb 16 16:47:42 2010
@@ -1066,7 +1066,7 @@
* \retval 0 Success
* \retval -1 Failure
*/
-int ast_cc_agent_accept_request(int core_id, const char * const debug);
+int __attribute__((format(printf, 2, 3))) ast_cc_agent_accept_request(int core_id, const char * const debug, ...);
/*!
* \since 1.8
@@ -1081,7 +1081,7 @@
* \retval 0 Success
* \retval -1 Failure
*/
-int ast_cc_monitor_request_acked(int core_id, const char * const debug);
+int __attribute__((format(printf, 2, 3))) ast_cc_monitor_request_acked(int core_id, const char * const debug, ...);
/*!
* \since 1.8
@@ -1100,7 +1100,7 @@
* \retval 0 Success
* \retval -1 Failure
*/
-int ast_cc_agent_caller_busy(int core_id, const char * const debug);
+int __attribute__((format(printf, 2, 3))) ast_cc_agent_caller_busy(int core_id, const char * const debug, ...);
/*!
* \since 1.8
@@ -1115,7 +1115,7 @@
* \retval 0 Success
* \retval -1 Failure
*/
-int ast_cc_agent_caller_available(int core_id, const char * const debug);
+int __attribute__((format(printf, 2, 3))) ast_cc_agent_caller_available(int core_id, const char * const debug, ...);
/*!
* \since 1.8
@@ -1131,7 +1131,7 @@
* \retval 0 Success
* \retval -1 Failure
*/
-int ast_cc_agent_recalling(int core_id, const char * const debug);
+int __attribute__((format(printf, 2, 3))) ast_cc_agent_recalling(int core_id, const char * const debug, ...);
/*!
* \since 1.8
@@ -1146,7 +1146,7 @@
* \retval 0 Success
* \retval -1 Failure
*/
-int ast_cc_completed(struct ast_channel *chan, const char * const debug);
+int __attribute__((format(printf, 2, 3))) ast_cc_completed(struct ast_channel *chan, const char * const debug, ...);
/*!
* \since 1.8
@@ -1161,7 +1161,7 @@
* \retval 0 Success
* \retval -1 Failure
*/
-int ast_cc_failed(int core_id, const char * const debug);
+int __attribute__((format(printf, 2, 3))) ast_cc_failed(int core_id, const char * const debug, ...);
/*!
* \since 1.8
@@ -1303,7 +1303,7 @@
* \retval 0 Request successfully queued
* \retval -1 Request could not be queued
*/
-int ast_cc_monitor_callee_available(const int core_id);
+int __attribute__((format(printf, 2, 3))) ast_cc_monitor_callee_available(const int core_id, const char * const debug, ...);
/* END API FOR USE WITH/BY MONITORS */
Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=247034&r1=247033&r2=247034
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Tue Feb 16 16:47:42 2010
@@ -171,10 +171,11 @@
* \param state The state to which we wish to change
* \param core_id The unique identifier for this instance of the CCSS core state machine
* \param debug Optional message explaining the reason for the state change
+ * \param ap varargs list
* \retval 0 State change successfully queued
* \retval -1 Unable to queue state change request
*/
-static int cc_request_state_change(enum cc_state state, const int core_id, const char *debug);
+static int __attribute__((format(printf, 3, 0))) cc_request_state_change(enum cc_state state, const int core_id, const char *debug, va_list ap);
/*!
* \internal
@@ -1006,7 +1007,7 @@
if (new_state == AST_DEVICE_NOT_INUSE || new_state == AST_DEVICE_UNKNOWN) {
AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
if (!generic_instance->is_suspended) {
- ast_cc_monitor_callee_available(generic_instance->core_id);
+ ast_cc_monitor_callee_available(generic_instance->core_id, "Generic monitored party has become available");
break;
}
}
@@ -1140,7 +1141,7 @@
AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
if (!generic_instance->is_suspended) {
- ast_cc_monitor_callee_available(generic_instance->core_id);
+ ast_cc_monitor_callee_available(generic_instance->core_id, "Generic monitored party has become available");
break;
}
}
@@ -1170,7 +1171,7 @@
* its availability
*/
if (state == AST_DEVICE_NOT_INUSE || state == AST_DEVICE_UNKNOWN) {
- ast_cc_monitor_callee_available(monitor->core_id);
+ ast_cc_monitor_callee_available(monitor->core_id, "Generic monitored party has become available");
}
/* In addition, we need to mark this generic_monitor_instance as not being suspended anymore */
@@ -2117,15 +2118,13 @@
static void generic_agent_devstate_cb(const struct ast_event *event, void *userdata)
{
struct ast_cc_agent *agent = userdata;
- struct ast_str *str = ast_str_alloca(128);
/* We can't unsubscribe from device state events here because it causes a deadlock */
if (ast_taskprocessor_push(cc_core_taskprocessor, generic_agent_devstate_unsubscribe,
cc_ref(agent, "ref agent for device state unsubscription"))) {
cc_unref(agent, "Unref agent unsubscribing from devstate failed");
}
- ast_str_set(&str, 0, "%s is no longer busy\n", agent->device_name);
- ast_cc_agent_caller_available(agent->core_id, ast_str_buffer(str));
+ ast_cc_agent_caller_available(agent->core_id, "%s is no longer busy", agent->device_name);
}
static int cc_generic_agent_start_monitoring(struct ast_cc_agent *agent)
@@ -2629,19 +2628,32 @@
return res;
}
-static int cc_request_state_change(enum cc_state state, const int core_id, const char *debug)
+static int cc_request_state_change(enum cc_state state, const int core_id, const char *debug, va_list ap)
{
int res;
+ int debuglen;
+ char dummy[1];
+ va_list aq;
struct cc_state_change_args *args = ast_calloc(1, sizeof(*args) +
(ast_strlen_zero(debug) ? 0 : strlen(debug)));
- if (!args) {
+ /* This initial call to vsnprintf is simply to find what the
+ * size of the string needs to be
+ */
+ va_copy(aq, ap);
+ /* We add 1 to the result since vsnprintf's return does not
+ * include the terminating null byte
+ */
+ debuglen = vsnprintf(dummy, sizeof(dummy), debug, aq) + 1;
+ va_end(aq);
+
+ if (!(args = ast_calloc(1, sizeof(*args) + debuglen))) {
return -1;
}
args->state = state;
args->core_id = core_id;
- strcpy(args->debug, debug);
+ vsnprintf(args->debug, debuglen, debug, ap);
res = ast_taskprocessor_push(cc_core_taskprocessor, cc_do_state_change, args);
if (res) {
@@ -2943,6 +2955,17 @@
ast_channel_unlock(chan);
}
+static __attribute__((format(printf, 2, 3))) int cc_offer(const int core_id, const char * const debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_CALLER_OFFERED, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
int ast_cc_offer(struct ast_channel *caller_chan)
{
int core_id;
@@ -2963,46 +2986,84 @@
ast_channel_unlock(caller_chan);
if (cc_is_offerable) {
- res = cc_request_state_change(CC_CALLER_OFFERED, core_id, "Offer CC to caller");
+ res = cc_offer(core_id, "CC offered to caller %s", caller_chan->name);
}
return res;
}
-int ast_cc_agent_accept_request(int core_id, const char * const debug)
-{
- return cc_request_state_change(CC_CALLER_REQUESTED, core_id, debug);
-}
-
-int ast_cc_monitor_request_acked(int core_id, const char * const debug)
-{
- return cc_request_state_change(CC_ACTIVE, core_id, debug);
-}
-
-int ast_cc_monitor_callee_available(const int core_id)
-{
- return cc_request_state_change(CC_CALLEE_READY, core_id, "Device being monitored has become available");
-}
-
-int ast_cc_agent_caller_busy(int core_id, const char * debug)
-{
- return cc_request_state_change(CC_CALLER_BUSY, core_id, debug);
-}
-
-int ast_cc_agent_caller_available(int core_id, const char * const debug)
-{
- return cc_request_state_change(CC_ACTIVE, core_id, debug);
-}
-
-int ast_cc_agent_recalling(int core_id, const char * const debug)
-{
- return cc_request_state_change(CC_RECALLING, core_id, debug);
-}
-
-int ast_cc_completed(struct ast_channel *chan, const char * const debug)
+int ast_cc_agent_accept_request(int core_id, const char * const debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_CALLER_REQUESTED, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
+int ast_cc_monitor_request_acked(int core_id, const char * const debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_ACTIVE, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
+int ast_cc_monitor_callee_available(const int core_id, const char * const debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_CALLEE_READY, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
+int ast_cc_agent_caller_busy(int core_id, const char * debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_CALLER_BUSY, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
+int ast_cc_agent_caller_available(int core_id, const char * const debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_ACTIVE, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
+int ast_cc_agent_recalling(int core_id, const char * const debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_RECALLING, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
+int ast_cc_completed(struct ast_channel *chan, const char * const debug, ...)
{
struct ast_datastore *recall_datastore;
struct cc_recall_ds_data *recall_data;
int core_id;
+ va_list ap;
+ int res;
ast_channel_lock(chan);
if (!(recall_datastore = ast_channel_datastore_find(chan, &recall_ds_info, NULL))) {
@@ -3027,12 +3088,21 @@
}
core_id = recall_data->core_id;
ast_channel_unlock(chan);
- return cc_request_state_change(CC_COMPLETE, core_id, debug);
-}
-
-int ast_cc_failed(int core_id, const char * const debug)
-{
- return cc_request_state_change(CC_FAILED, core_id, debug);
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_COMPLETE, core_id, debug, ap);
+ va_end(ap);
+ return res;
+}
+
+int ast_cc_failed(int core_id, const char * const debug, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, debug);
+ res = cc_request_state_change(CC_FAILED, core_id, debug, ap);
+ va_end(ap);
+ return res;
}
struct ast_cc_monitor_failure_data {
@@ -3154,8 +3224,11 @@
/* If an agent is being asked to stop ringing, then he needs to be prepared if for
* whatever reason he needs to be called back again. The proper state to be in to
* detect such a circumstance is the CC_ACTIVE state.
- */
- cc_request_state_change(CC_ACTIVE, core_instance->core_id, "Agent asked to stop ringing. Be prepared to be recalled again.");
+ *
+ * We get to this state using the slightly unintuitive method of calling
+ * ast_cc_monitor_request_acked because it gets us to the proper state.
+ */
+ ast_cc_monitor_request_acked(core_instance->core_id, "Agent asked to stop ringing. Be prepared to be recalled again.");
cc_unref(core_instance, "Stop ringing finished. Unref core_instance");
return res;
}
More information about the asterisk-commits
mailing list