diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-05-02 15:37:34 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-05-02 15:37:34 +0000 |
commit | 69841867537dfa3d428ff5006c5f4a76a4a781ab (patch) | |
tree | 3b65f539dfb3e4461436cdc4d8a48891221a677c | |
parent | f90d5056f66da9d01d4223b369c4bcba0bf83681 (diff) |
Show uptime
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@951 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-x | asterisk.c | 4 | ||||
-rwxr-xr-x | cli.c | 87 | ||||
-rwxr-xr-x | include/asterisk/options.h | 2 | ||||
-rwxr-xr-x | include/asterisk/rtp.h | 4 | ||||
-rwxr-xr-x | loader.c | 1 | ||||
-rwxr-xr-x | rtp.c | 33 |
6 files changed, 130 insertions, 1 deletions
diff --git a/asterisk.c b/asterisk.c index 551c72e32..70cd1a88d 100755 --- a/asterisk.c +++ b/asterisk.c @@ -70,6 +70,9 @@ struct console { pthread_t t; /* Thread of handler */ }; +time_t ast_startuptime; +time_t ast_lastreloadtime; + static History *el_hist = NULL; static EditLine *el = NULL; static char *remotehostname; @@ -1349,6 +1352,7 @@ int main(int argc, char *argv[]) #ifdef __AST_DEBUG_MALLOC __ast_mm_init(); #endif + time(&ast_startuptime); ast_cli_register(&astshutdownnow); ast_cli_register(&astshutdowngracefully); ast_cli_register(&astrestartnow); @@ -173,6 +173,92 @@ static char version_help[] = "Usage: show version\n" " Shows Asterisk version information.\n "; +static char *format_uptimestr(time_t timeval) +{ + int years = 0, weeks = 0, days = 0, hours = 0, mins = 0, secs = 0; + char timestr[256]; + int pos = 0; +#define SECOND (1) +#define MIN (SECOND*60) +#define HOUR (MIN*60) +#define DAY (HOUR*24) +#define WEEK (DAY*7) +#define YEAR (DAY*365) + + if (timeval > YEAR) { + years = (timeval / YEAR); + timeval -= (years * YEAR); + if (years > 1) + pos += sprintf(timestr + pos, "%d years, ", years); + else + pos += sprintf(timestr + pos, "1 year, "); + } + if (timeval > WEEK) { + weeks = (timeval / WEEK); + timeval -= (weeks * WEEK); + if (weeks > 1) + pos += sprintf(timestr + pos, "%d weeks, ", weeks); + else + pos += sprintf(timestr + pos, "1 week, "); + } + if (timeval > DAY) { + days = (timeval / DAY); + timeval -= (days * DAY); + if (days > 1) + pos += sprintf(timestr + pos, "%d days, ", days); + else + pos += sprintf(timestr + pos, "1 day, "); + + } + if (timeval > HOUR) { + hours = (timeval / HOUR); + timeval -= (hours * HOUR); + if (hours > 1) + pos += sprintf(timestr + pos, "%d hours, ", hours); + else + pos += sprintf(timestr + pos, "1 hour, "); + } + if (timeval > MIN) { + mins = (timeval / MIN); + timeval -= (mins * MIN); + if (mins > 1) + pos += sprintf(timestr + pos, "%d minutes, ", mins); + else if (mins > 0) + pos += sprintf(timestr + pos, "1 minute, "); + } + secs = timeval; + + if (secs > 0) + pos += sprintf(timestr + pos, "%d seconds", secs); + + return timestr ? strdup(timestr) : NULL; +} + +static int handle_showuptime(int fd, int argc, char *argv[]) +{ + time_t curtime, tmptime; + char *timestr; + + time(&curtime); + if (ast_startuptime) { + tmptime = curtime - ast_startuptime; + timestr = format_uptimestr(tmptime); + if (timestr) { + ast_cli(fd, "System uptime: %s\n", timestr); + free(timestr); + } + } + if (ast_lastreloadtime) { + tmptime = curtime - ast_lastreloadtime; + timestr = format_uptimestr(tmptime); + if (timestr) { + ast_cli(fd, "Last reload: %s\n", timestr); + free(timestr); + } + } + return RESULT_SUCCESS; +} + static int handle_modlist(int fd, int argc, char *argv[]) { if (argc != 2) @@ -476,6 +562,7 @@ static struct ast_cli_entry builtins[] = { { { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch }, { { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help }, { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help }, + { { "show", "uptime", NULL }, handle_showuptime, "Show uptime information", modlist_help }, { { "show", "version", NULL }, handle_version, "Display version info", version_help }, { { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch }, { { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn }, diff --git a/include/asterisk/options.h b/include/asterisk/options.h index 56b23908c..f9314bb1f 100755 --- a/include/asterisk/options.h +++ b/include/asterisk/options.h @@ -27,6 +27,8 @@ extern int option_initcrypto; extern int option_nocolor; extern int fully_booted; extern char defaultlanguage[]; +extern time_t ast_startuptime; +extern time_t ast_lastreloadtime; #define VERBOSE_PREFIX_1 " " #define VERBOSE_PREFIX_2 " == " diff --git a/include/asterisk/rtp.h b/include/asterisk/rtp.h index 6ae6b0a2c..e0b83bb0f 100755 --- a/include/asterisk/rtp.h +++ b/include/asterisk/rtp.h @@ -30,8 +30,10 @@ extern "C" { #define AST_RTP_DTMF (1 << 0) /*! 'Comfort Noise' (RFC3389) */ #define AST_RTP_CN (1 << 1) +/*! DTMF (Cisco Proprietary) */ +#define AST_RTP_CISCO_DTMF (1 << 2) /*! Maximum RTP-specific code */ -#define AST_RTP_MAX AST_RTP_CN +#define AST_RTP_MAX AST_RTP_CISCO_DTMF struct ast_rtp_protocol { struct ast_rtp *(*get_rtp_info)(struct ast_channel *chan); /* Get RTP struct, or NULL if unwilling to transfer */ @@ -146,6 +146,7 @@ void ast_module_reload(void) /* We'll do the logger and manager the favor of calling its reload here first */ reload_manager(); ast_enum_reload(); + time(&ast_lastreloadtime); ast_pthread_mutex_lock(&modlock); m = module_list; @@ -151,6 +151,33 @@ static struct ast_frame *send_dtmf(struct ast_rtp *rtp) } +static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *data, int len) +{ + unsigned int event; + char resp = 0; + struct ast_frame *f = NULL; + event = ntohl(*((unsigned int *)(data))); + event &= 0x001F; +#if 0 + printf("Cisco Digit: %08x (len = %d)\n", event, len); +#endif + if (event < 10) { + resp = '0' + event; + } else if (event < 11) { + resp = '*'; + } else if (event < 12) { + resp = '#'; + } else if (event < 16) { + resp = 'A' + (event - 12); + } + if (rtp->resp && (rtp->resp != resp)) { + f = send_dtmf(rtp); + } + rtp->resp = resp; + rtp->dtmfcount = dtmftimeout; + return f; +} + static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *data, int len) { unsigned int event; @@ -287,6 +314,10 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp) /* It's special -- rfc2833 process it */ f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); if (f) return f; else return &null_frame; + } else if (rtpPT.code == AST_RTP_CISCO_DTMF) { + /* It's really special -- process it the Cisco way */ + f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); + if (f) return f; else return &null_frame; } else if (rtpPT.code == AST_RTP_CN) { /* Comfort Noise */ f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); @@ -379,6 +410,7 @@ static struct { {{1, AST_FORMAT_SPEEX}, "audio", "SPEEX"}, {{1, AST_FORMAT_ILBC}, "audio", "iLBC"}, {{0, AST_RTP_DTMF}, "audio", "telephone-event"}, + {{0, AST_RTP_CISCO_DTMF}, "audio", "bastard-telephone-event"}, {{0, AST_RTP_CN}, "audio", "CN"}, {{1, AST_FORMAT_JPEG}, "video", "JPEG"}, {{1, AST_FORMAT_PNG}, "video", "PNG"}, @@ -410,6 +442,7 @@ static struct rtpPayloadType static_RTP_PT[MAX_RTP_PT] = { [97] = {1, AST_FORMAT_ILBC}, [101] = {0, AST_RTP_DTMF}, [110] = {1, AST_FORMAT_SPEEX}, + [121] = {0, AST_RTP_CISCO_DTMF}, // Must be type 121 }; void ast_rtp_pt_clear(struct ast_rtp* rtp) |