summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2011-04-21 22:53:05 +0000
committerRichard Mudgett <rmudgett@digium.com>2011-04-21 22:53:05 +0000
commit0f1ff9141e22d0bfd46126cb4b22bc7de5cce3ae (patch)
tree30f81ccc30556c9db6a3f7e2e182b437744e6cae /channels
parent13e925b276887c6a5593f77541ceb9161c4b0281 (diff)
Implement AMI action PRIShowSpans.
PRIShowSpans works like the AMI action DAHDIShowChannels but for PRI spans. It is similar to the CLI command "pri show spans". (closes issue #15980) Reported by: dwery git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@314735 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_dahdi.c73
-rw-r--r--channels/sig_pri.c46
-rw-r--r--channels/sig_pri.h3
3 files changed, 122 insertions, 0 deletions
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index c8391c204..26a2d0100 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -252,6 +252,19 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<description>
</description>
</manager>
+ <manager name="PRIShowSpans" language="en_US">
+ <synopsis>
+ Show status of PRI spans.
+ </synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+ <parameter name="Span">
+ <para>Specify the specific span to show. Show all spans if zero or not present.</para>
+ </parameter>
+ </syntax>
+ <description>
+ </description>
+ </manager>
***/
#define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
@@ -15874,6 +15887,60 @@ static int action_dahdishowchannels(struct mansession *s, const struct message *
return 0;
}
+#if defined(HAVE_PRI)
+static int action_prishowspans(struct mansession *s, const struct message *m)
+{
+ int count;
+ int idx;
+ int span_query;
+ struct dahdi_pri *dspan;
+ const char *id = astman_get_header(m, "ActionID");
+ const char *span_str = astman_get_header(m, "Span");
+ char action_id[256];
+ const char *show_cmd = "PRIShowSpans";
+
+ /* NOTE: Asking for span 0 gets all spans. */
+ if (!ast_strlen_zero(span_str)) {
+ span_query = atoi(span_str);
+ } else {
+ span_query = 0;
+ }
+
+ if (!ast_strlen_zero(id)) {
+ snprintf(action_id, sizeof(action_id), "ActionID: %s\r\n", id);
+ } else {
+ action_id[0] = '\0';
+ }
+
+ astman_send_ack(s, m, "Span status will follow");
+
+ count = 0;
+ for (idx = 0; idx < ARRAY_LEN(pris); ++idx) {
+ dspan = &pris[idx];
+
+ /* If a specific span is asked for, only deliver status for that span. */
+ if (0 < span_query && dspan->pri.span != span_query) {
+ continue;
+ }
+
+ if (dspan->pri.pri) {
+ count += sig_pri_ami_show_spans(s, show_cmd, &dspan->pri, dspan->dchannels,
+ action_id);
+ }
+ }
+
+ astman_append(s,
+ "Event: %sComplete\r\n"
+ "Items: %d\r\n"
+ "%s"
+ "\r\n",
+ show_cmd,
+ count,
+ action_id);
+ return 0;
+}
+#endif /* defined(HAVE_PRI) */
+
#if defined(HAVE_SS7)
static int linkset_addsigchan(int sigchan)
{
@@ -16449,6 +16516,9 @@ static int __unload_module(void)
ast_manager_unregister("DAHDIDNDon");
ast_manager_unregister("DAHDIShowChannels");
ast_manager_unregister("DAHDIRestart");
+#if defined(HAVE_PRI)
+ ast_manager_unregister("PRIShowSpans");
+#endif /* defined(HAVE_PRI) */
ast_data_unregister(NULL);
ast_channel_unregister(&dahdi_tech);
@@ -18431,6 +18501,9 @@ static int load_module(void)
ast_manager_register_xml("DAHDIDNDoff", 0, action_dahdidndoff);
ast_manager_register_xml("DAHDIShowChannels", 0, action_dahdishowchannels);
ast_manager_register_xml("DAHDIRestart", 0, action_dahdirestart);
+#if defined(HAVE_PRI)
+ ast_manager_register_xml("PRIShowSpans", 0, action_prishowspans);
+#endif /* defined(HAVE_PRI) */
ast_cond_init(&ss_thread_complete, NULL);
diff --git a/channels/sig_pri.c b/channels/sig_pri.c
index 49fb246be..c032bf2de 100644
--- a/channels/sig_pri.c
+++ b/channels/sig_pri.c
@@ -7040,6 +7040,52 @@ static void *pri_dchannel(void *vpri)
return NULL;
}
+/*!
+ * \brief Output AMI show spans response events for the given PRI span.
+ * \since 1.10
+ *
+ * \param show_cmd AMI command name
+ * \param s AMI session to output span information.
+ * \param pri PRI span control structure.
+ * \param dchannels Array of D channel channel numbers.
+ * \param action_id Action ID line to use.
+ *
+ * \return Number of D channels on this span.
+ */
+int sig_pri_ami_show_spans(struct mansession *s, const char *show_cmd, struct sig_pri_span *pri, const int *dchannels, const char *action_id)
+{
+ int count;
+ int x;
+
+ count = 0;
+ for (x = 0; x < ARRAY_LEN(pri->dchans); ++x) {
+ if (pri->dchans[x]) {
+ ++count;
+
+ astman_append(s,
+ "Event: %s\r\n"
+ "Span: %d\r\n"
+ "DChannel: %d\r\n"
+ "Order: %s\r\n"
+ "Active: %s\r\n"
+ "Alarm: %s\r\n"
+ "Up: %s\r\n"
+ "%s"
+ "\r\n",
+ show_cmd,
+ pri->span,
+ dchannels[x],
+ pri_order(x),
+ (pri->dchans[x] == pri->pri) ? "Yes" : "No",
+ (pri->dchanavail[x] & DCHAN_NOTINALARM) ? "No" : "Yes",
+ (pri->dchanavail[x] & DCHAN_UP) ? "Yes" : "No",
+ action_id
+ );
+ }
+ }
+ return count;
+}
+
void sig_pri_init_pri(struct sig_pri_span *pri)
{
int i;
diff --git a/channels/sig_pri.h b/channels/sig_pri.h
index f2eef03d6..9b4f56e68 100644
--- a/channels/sig_pri.h
+++ b/channels/sig_pri.h
@@ -615,6 +615,9 @@ void sig_pri_chan_delete(struct sig_pri_chan *doomed);
int pri_is_up(struct sig_pri_span *pri);
+struct mansession;
+int sig_pri_ami_show_spans(struct mansession *s, const char *show_cmd, struct sig_pri_span *pri, const int *dchannels, const char *action_id);
+
void sig_pri_cli_show_channels_header(int fd);
void sig_pri_cli_show_channels(int fd, struct sig_pri_span *pri);
void sig_pri_cli_show_spans(int fd, int span, struct sig_pri_span *pri);