1999-11-12 06:29:40 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
1999-11-12 06:29:40 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-11-12 06:29:40 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
1999-11-12 06:29:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief GTK Console monitor -- very kludgy right now
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
1999-11-12 06:29:40 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<depend>gtk</depend>
|
|
|
|
<defaultenabled>no</defaultenabled>
|
|
|
|
***/
|
1999-11-12 06:29:40 +00:00
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2003-04-23 19:09:13 +00:00
|
|
|
#include <sys/types.h>
|
1999-11-12 06:29:40 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
2003-09-08 16:48:07 +00:00
|
|
|
#include <signal.h>
|
2000-01-02 20:59:00 +00:00
|
|
|
#include <sys/time.h>
|
1999-11-12 06:29:40 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib.h>
|
2005-06-06 22:12:19 +00:00
|
|
|
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/config.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/options.h"
|
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/utils.h"
|
1999-11-12 06:29:40 +00:00
|
|
|
|
2004-06-09 01:45:08 +00:00
|
|
|
AST_MUTEX_DEFINE_STATIC(verb_lock);
|
1999-11-12 06:29:40 +00:00
|
|
|
|
|
|
|
static pthread_t console_thread;
|
|
|
|
|
|
|
|
static int inuse=0;
|
2000-01-02 20:59:00 +00:00
|
|
|
static int clipipe[2];
|
|
|
|
static int cleanupid = -1;
|
|
|
|
|
1999-11-12 06:29:40 +00:00
|
|
|
static char *dtext = "Asterisk PBX Console (GTK Version)";
|
|
|
|
|
|
|
|
static GtkWidget *window;
|
|
|
|
static GtkWidget *quit;
|
|
|
|
static GtkWidget *closew;
|
|
|
|
static GtkWidget *verb;
|
|
|
|
static GtkWidget *modules;
|
|
|
|
static GtkWidget *statusbar;
|
2000-01-02 20:59:00 +00:00
|
|
|
static GtkWidget *cli;
|
|
|
|
|
|
|
|
static struct timeval last;
|
1999-11-12 06:29:40 +00:00
|
|
|
|
|
|
|
static void update_statusbar(char *msg)
|
|
|
|
{
|
|
|
|
gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 1);
|
|
|
|
gtk_statusbar_push(GTK_STATUSBAR(statusbar), 1, msg);
|
|
|
|
}
|
|
|
|
|
2006-07-30 23:11:07 +00:00
|
|
|
static int unload_module(void *mod)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
|
|
|
if (inuse) {
|
|
|
|
/* Kill off the main thread */
|
|
|
|
pthread_cancel(console_thread);
|
|
|
|
gdk_threads_enter();
|
|
|
|
gtk_widget_destroy(window);
|
|
|
|
gdk_threads_leave();
|
2000-01-02 20:59:00 +00:00
|
|
|
close(clipipe[0]);
|
|
|
|
close(clipipe[1]);
|
1999-11-12 06:29:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-02 20:59:00 +00:00
|
|
|
static int cleanup(void *useless)
|
|
|
|
{
|
|
|
|
gdk_threads_enter();
|
|
|
|
gtk_clist_thaw(GTK_CLIST(verb));
|
|
|
|
gtk_widget_queue_resize(verb->parent);
|
|
|
|
gtk_clist_moveto(GTK_CLIST(verb), GTK_CLIST(verb)->rows - 1, 0, 0, 0);
|
|
|
|
cleanupid = -1;
|
|
|
|
gdk_threads_leave();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-12 06:29:40 +00:00
|
|
|
|
2003-08-15 04:38:39 +00:00
|
|
|
static void __verboser(const char *stuff, int opos, int replacelast, int complete)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
|
|
|
char *s2[2];
|
2000-01-02 20:59:00 +00:00
|
|
|
struct timeval tv;
|
|
|
|
int ms;
|
2004-07-14 13:57:15 +00:00
|
|
|
s2[0] = (char *)stuff;
|
1999-11-12 06:29:40 +00:00
|
|
|
s2[1] = NULL;
|
2000-01-02 20:59:00 +00:00
|
|
|
gtk_clist_freeze(GTK_CLIST(verb));
|
1999-11-12 06:29:40 +00:00
|
|
|
if (replacelast)
|
|
|
|
gtk_clist_remove(GTK_CLIST(verb), GTK_CLIST(verb)->rows - 1);
|
|
|
|
gtk_clist_append(GTK_CLIST(verb), s2);
|
2005-07-15 23:00:47 +00:00
|
|
|
if (!ast_tvzero(last)) {
|
2000-01-02 20:59:00 +00:00
|
|
|
gdk_threads_leave();
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
if (cleanupid > -1)
|
|
|
|
gtk_timeout_remove(cleanupid);
|
2005-07-15 23:00:47 +00:00
|
|
|
ms = ast_tvdiff_ms(tv, last);
|
2000-01-02 20:59:00 +00:00
|
|
|
if (ms < 100) {
|
|
|
|
/* We just got a message within 100ms, so just schedule an update
|
|
|
|
in the near future */
|
|
|
|
cleanupid = gtk_timeout_add(200, cleanup, NULL);
|
|
|
|
} else {
|
|
|
|
cleanup(&cleanupid);
|
|
|
|
}
|
|
|
|
last = tv;
|
|
|
|
} else {
|
|
|
|
gettimeofday(&last, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-15 04:38:39 +00:00
|
|
|
static void verboser(const char *stuff, int opos, int replacelast, int complete)
|
2000-01-02 20:59:00 +00:00
|
|
|
{
|
2003-08-13 15:25:16 +00:00
|
|
|
ast_mutex_lock(&verb_lock);
|
2000-01-02 20:59:00 +00:00
|
|
|
/* Lock appropriately if we're really being called in verbose mode */
|
|
|
|
__verboser(stuff, opos, replacelast, complete);
|
2003-08-13 15:25:16 +00:00
|
|
|
ast_mutex_unlock(&verb_lock);
|
1999-11-12 06:29:40 +00:00
|
|
|
}
|
|
|
|
|
2000-01-02 20:59:00 +00:00
|
|
|
static void cliinput(void *data, int source, GdkInputCondition ic)
|
|
|
|
{
|
|
|
|
static char buf[256];
|
|
|
|
static int offset = 0;
|
|
|
|
int res;
|
|
|
|
char *c;
|
|
|
|
char *l;
|
|
|
|
char n;
|
|
|
|
/* Read as much stuff is there */
|
|
|
|
res = read(source, buf + offset, sizeof(buf) - 1 - offset);
|
|
|
|
if (res > -1)
|
|
|
|
buf[res + offset] = '\0';
|
|
|
|
/* make sure we've null terminated whatever we have so far */
|
|
|
|
c = buf;
|
|
|
|
l = buf;
|
|
|
|
while(*c) {
|
|
|
|
if (*c == '\n') {
|
|
|
|
/* Keep the trailing \n */
|
|
|
|
c++;
|
|
|
|
n = *c;
|
|
|
|
*c = '\0';
|
|
|
|
__verboser(l, 0, 0, 1);
|
|
|
|
*(c - 1) = '\0';
|
|
|
|
*c = n;
|
|
|
|
l = c;
|
|
|
|
} else
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
if (strlen(l)) {
|
|
|
|
/* We have some left over */
|
|
|
|
memmove(buf, l, strlen(l) + 1);
|
|
|
|
offset = strlen(buf);
|
|
|
|
} else {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-16 22:37:31 +00:00
|
|
|
static void remove_module(void)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
char *module;
|
|
|
|
char buf[256];
|
|
|
|
if (GTK_CLIST(modules)->selection) {
|
|
|
|
module= (char *)gtk_clist_get_row_data(GTK_CLIST(modules), (int) GTK_CLIST(modules)->selection->data);
|
|
|
|
gdk_threads_leave();
|
|
|
|
res = ast_unload_resource(module, 0);
|
|
|
|
gdk_threads_enter();
|
|
|
|
if (res) {
|
|
|
|
snprintf(buf, sizeof(buf), "Module '%s' is in use", module);
|
|
|
|
update_statusbar(buf);
|
|
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "Module '%s' removed", module);
|
|
|
|
update_statusbar(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-30 23:11:07 +00:00
|
|
|
static int reload_module(void *mod)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
|
|
|
int res, x;
|
|
|
|
char *module;
|
|
|
|
char buf[256];
|
|
|
|
if (GTK_CLIST(modules)->selection) {
|
|
|
|
module= (char *)gtk_clist_get_row_data(GTK_CLIST(modules), (int) GTK_CLIST(modules)->selection->data);
|
|
|
|
module = strdup(module);
|
|
|
|
if (module) {
|
|
|
|
gdk_threads_leave();
|
|
|
|
res = ast_unload_resource(module, 0);
|
|
|
|
gdk_threads_enter();
|
|
|
|
if (res) {
|
|
|
|
snprintf(buf, sizeof(buf), "Module '%s' is in use", module);
|
|
|
|
update_statusbar(buf);
|
|
|
|
} else {
|
|
|
|
gdk_threads_leave();
|
|
|
|
res = ast_load_resource(module);
|
|
|
|
gdk_threads_enter();
|
|
|
|
if (res) {
|
|
|
|
snprintf(buf, sizeof(buf), "Error reloading module '%s'", module);
|
|
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "Module '%s' reloaded", module);
|
|
|
|
}
|
|
|
|
for (x=0; x < GTK_CLIST(modules)->rows; x++) {
|
|
|
|
if (!strcmp((char *)gtk_clist_get_row_data(GTK_CLIST(modules), x), module)) {
|
|
|
|
gtk_clist_select_row(GTK_CLIST(modules), x, -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update_statusbar(buf);
|
|
|
|
|
|
|
|
}
|
|
|
|
free(module);
|
|
|
|
}
|
|
|
|
}
|
2006-07-30 23:16:23 +00:00
|
|
|
|
|
|
|
return 0;
|
1999-11-12 06:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void file_ok_sel(GtkWidget *w, GtkFileSelection *fs)
|
|
|
|
{
|
2006-06-10 04:34:48 +00:00
|
|
|
char tmp[PATH_MAX];
|
1999-11-12 06:29:40 +00:00
|
|
|
char *module = gtk_file_selection_get_filename(fs);
|
|
|
|
char buf[256];
|
2004-07-14 13:57:15 +00:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/", ast_config_AST_MODULE_DIR);
|
2003-01-30 15:03:20 +00:00
|
|
|
if (!strncmp(module, (char *)tmp, strlen(tmp)))
|
|
|
|
module += strlen(tmp);
|
1999-11-12 06:29:40 +00:00
|
|
|
gdk_threads_leave();
|
|
|
|
if (ast_load_resource(module)) {
|
|
|
|
snprintf(buf, sizeof(buf), "Error loading module '%s'.", module);
|
|
|
|
update_statusbar(buf);
|
|
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "Module '%s' loaded", module);
|
|
|
|
update_statusbar(buf);
|
|
|
|
}
|
|
|
|
gdk_threads_enter();
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(fs));
|
|
|
|
}
|
|
|
|
|
2003-03-16 22:37:31 +00:00
|
|
|
static void add_module(void)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
2006-06-10 04:34:48 +00:00
|
|
|
char tmp[PATH_MAX];
|
1999-11-12 06:29:40 +00:00
|
|
|
GtkWidget *filew;
|
2004-07-14 13:57:15 +00:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/*.so", ast_config_AST_MODULE_DIR);
|
1999-11-12 06:29:40 +00:00
|
|
|
filew = gtk_file_selection_new("Load Module");
|
|
|
|
gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION(filew)->ok_button),
|
|
|
|
"clicked", GTK_SIGNAL_FUNC(file_ok_sel), filew);
|
|
|
|
gtk_signal_connect_object(GTK_OBJECT (GTK_FILE_SELECTION(filew)->cancel_button),
|
|
|
|
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(filew));
|
2003-01-30 15:03:20 +00:00
|
|
|
gtk_file_selection_set_filename(GTK_FILE_SELECTION(filew), (char *)tmp);
|
1999-11-12 06:29:40 +00:00
|
|
|
gtk_widget_show(filew);
|
|
|
|
}
|
|
|
|
|
2005-06-24 02:33:14 +00:00
|
|
|
static int add_mod(const char *module, const char *description, int usecount, const char *like)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
|
|
|
char use[10];
|
2006-07-30 23:16:23 +00:00
|
|
|
const char *pass[4];
|
1999-11-12 06:29:40 +00:00
|
|
|
int row;
|
|
|
|
snprintf(use, sizeof(use), "%d", usecount);
|
|
|
|
pass[0] = module;
|
|
|
|
pass[1] = description;
|
|
|
|
pass[2] = use;
|
|
|
|
pass[3] = NULL;
|
2006-07-30 23:16:23 +00:00
|
|
|
row = gtk_clist_append(GTK_CLIST(modules), (char **) pass);
|
|
|
|
gtk_clist_set_row_data(GTK_CLIST(modules), row, (char *) module);
|
1999-11-12 06:29:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mod_update(void)
|
|
|
|
{
|
|
|
|
char *module= NULL;
|
|
|
|
/* Update the mod stuff */
|
|
|
|
if (GTK_CLIST(modules)->selection) {
|
|
|
|
module= (char *)gtk_clist_get_row_data(GTK_CLIST(modules), (int) GTK_CLIST(modules)->selection->data);
|
|
|
|
}
|
|
|
|
gtk_clist_freeze(GTK_CLIST(modules));
|
|
|
|
gtk_clist_clear(GTK_CLIST(modules));
|
2005-06-24 02:33:14 +00:00
|
|
|
ast_update_module_list(add_mod, NULL);
|
1999-11-12 06:29:40 +00:00
|
|
|
if (module)
|
|
|
|
gtk_clist_select_row(GTK_CLIST(modules), gtk_clist_find_row_from_data(GTK_CLIST(modules), module), -1);
|
|
|
|
gtk_clist_thaw(GTK_CLIST(modules));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void exit_now(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
ast_loader_unregister(mod_update);
|
|
|
|
gtk_main_quit();
|
|
|
|
inuse--;
|
|
|
|
ast_update_use_count();
|
|
|
|
ast_unregister_verbose(verboser);
|
|
|
|
ast_unload_resource("pbx_gtkconsole", 0);
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(2, "GTK Console Monitor Exiting\n");
|
2001-04-23 16:50:12 +00:00
|
|
|
/* XXX Trying to quit after calling this makes asterisk segfault XXX */
|
1999-11-12 06:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void exit_completely(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2000-01-02 20:59:00 +00:00
|
|
|
#if 0
|
|
|
|
/* Clever... */
|
|
|
|
ast_cli_command(clipipe[1], "quit");
|
|
|
|
#else
|
|
|
|
kill(getpid(), SIGTERM);
|
|
|
|
#endif
|
1999-11-12 06:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void exit_nicely(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
fflush(stdout);
|
|
|
|
gtk_widget_destroy(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *consolethread(void *data)
|
|
|
|
{
|
|
|
|
gtk_widget_show(window);
|
|
|
|
gdk_threads_enter();
|
|
|
|
gtk_main();
|
|
|
|
gdk_threads_leave();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-16 22:37:31 +00:00
|
|
|
static int cli_activate(void)
|
2000-01-02 20:59:00 +00:00
|
|
|
{
|
2004-07-14 13:57:15 +00:00
|
|
|
char buf[256] = "";
|
|
|
|
strncpy(buf, gtk_entry_get_text(GTK_ENTRY(cli)), sizeof(buf) - 1);
|
2000-01-02 20:59:00 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(cli), "");
|
|
|
|
if (strlen(buf)) {
|
|
|
|
ast_cli_command(clipipe[1], buf);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-03-16 22:37:31 +00:00
|
|
|
static int show_console(void)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *wbox;
|
|
|
|
GtkWidget *notebook;
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *bbox, *hbbox, *add, *removew, *reloadw;
|
|
|
|
char *modtitles[3] = { "Module", "Description", "Use Count" };
|
|
|
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
|
|
|
statusbar = gtk_statusbar_new();
|
|
|
|
gtk_widget_show(statusbar);
|
|
|
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
|
|
|
|
GTK_SIGNAL_FUNC (exit_nicely), window);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(window), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (exit_now), window);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
|
|
|
|
|
|
|
|
quit = gtk_button_new_with_label("Quit Asterisk");
|
|
|
|
gtk_signal_connect(GTK_OBJECT(quit), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC (exit_completely), window);
|
|
|
|
gtk_widget_show(quit);
|
|
|
|
|
|
|
|
closew = gtk_button_new_with_label("Close Window");
|
|
|
|
gtk_signal_connect(GTK_OBJECT(closew), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC (exit_nicely), window);
|
|
|
|
gtk_widget_show(closew);
|
|
|
|
|
|
|
|
notebook = gtk_notebook_new();
|
|
|
|
verb = gtk_clist_new(1);
|
|
|
|
gtk_clist_columns_autosize(GTK_CLIST(verb));
|
|
|
|
sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
|
|
|
|
gtk_container_add(GTK_CONTAINER(sw), verb);
|
|
|
|
gtk_widget_show(verb);
|
|
|
|
gtk_widget_show(sw);
|
2000-01-02 20:59:00 +00:00
|
|
|
gtk_widget_set_usize(verb, 640, 400);
|
1999-11-12 06:29:40 +00:00
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, gtk_label_new("Verbose Status"));
|
|
|
|
|
|
|
|
|
|
|
|
modules = gtk_clist_new_with_titles(3, modtitles);
|
|
|
|
gtk_clist_columns_autosize(GTK_CLIST(modules));
|
|
|
|
gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 0, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 1, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(GTK_CLIST(modules), 2, TRUE);
|
|
|
|
gtk_clist_set_sort_column(GTK_CLIST(modules), 0);
|
|
|
|
gtk_clist_set_auto_sort(GTK_CLIST(modules), TRUE);
|
|
|
|
gtk_clist_column_titles_passive(GTK_CLIST(modules));
|
|
|
|
sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
|
|
|
|
gtk_container_add(GTK_CONTAINER(sw), modules);
|
|
|
|
gtk_clist_set_selection_mode(GTK_CLIST(modules), GTK_SELECTION_BROWSE);
|
|
|
|
gtk_widget_show(modules);
|
|
|
|
gtk_widget_show(sw);
|
|
|
|
|
|
|
|
add = gtk_button_new_with_label("Load...");
|
|
|
|
gtk_widget_show(add);
|
|
|
|
removew = gtk_button_new_with_label("Unload");
|
|
|
|
gtk_widget_show(removew);
|
|
|
|
reloadw = gtk_button_new_with_label("Reload");
|
|
|
|
gtk_widget_show(reloadw);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(removew), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC (remove_module), window);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(add), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC (add_module), window);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(reloadw), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC (reload_module), window);
|
|
|
|
|
|
|
|
bbox = gtk_vbox_new(FALSE, 5);
|
|
|
|
gtk_widget_show(bbox);
|
|
|
|
|
|
|
|
gtk_widget_set_usize(bbox, 100, -1);
|
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), add, FALSE, FALSE, 5);
|
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), removew, FALSE, FALSE, 5);
|
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), reloadw, FALSE, FALSE, 5);
|
|
|
|
|
|
|
|
hbbox = gtk_hbox_new(FALSE, 5);
|
|
|
|
gtk_widget_show(hbbox);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbbox), sw, TRUE, TRUE, 5);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbbox), bbox, FALSE, FALSE, 5);
|
|
|
|
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), hbbox, gtk_label_new("Module Information"));
|
|
|
|
|
|
|
|
gtk_widget_show(notebook);
|
|
|
|
|
|
|
|
wbox = gtk_hbox_new(FALSE, 5);
|
|
|
|
gtk_widget_show(wbox);
|
|
|
|
gtk_box_pack_end(GTK_BOX(wbox), quit, FALSE, FALSE, 5);
|
|
|
|
gtk_box_pack_end(GTK_BOX(wbox), closew, FALSE, FALSE, 5);
|
|
|
|
|
|
|
|
hbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
gtk_widget_show(hbox);
|
2000-01-02 20:59:00 +00:00
|
|
|
|
|
|
|
/* Command line */
|
|
|
|
cli = gtk_entry_new();
|
|
|
|
gtk_widget_show(cli);
|
|
|
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(cli), "activate",
|
|
|
|
GTK_SIGNAL_FUNC (cli_activate), NULL);
|
1999-11-12 06:29:40 +00:00
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 5);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), wbox, FALSE, FALSE, 5);
|
2000-01-02 20:59:00 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), cli, FALSE, FALSE, 0);
|
1999-11-12 06:29:40 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), statusbar, FALSE, FALSE, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), hbox);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(window), "Asterisk Console");
|
2000-01-02 20:59:00 +00:00
|
|
|
gtk_widget_grab_focus(cli);
|
2004-08-08 17:15:02 +00:00
|
|
|
ast_pthread_create(&console_thread, NULL, consolethread, NULL);
|
1999-11-12 06:29:40 +00:00
|
|
|
/* XXX Okay, seriously fix me! XXX */
|
|
|
|
usleep(100000);
|
|
|
|
ast_register_verbose(verboser);
|
|
|
|
gtk_clist_freeze(GTK_CLIST(verb));
|
|
|
|
ast_loader_register(mod_update);
|
|
|
|
gtk_clist_thaw(GTK_CLIST(verb));
|
2000-01-02 20:59:00 +00:00
|
|
|
gdk_input_add(clipipe[0], GDK_INPUT_READ, cliinput, NULL);
|
1999-11-12 06:29:40 +00:00
|
|
|
mod_update();
|
|
|
|
update_statusbar("Asterisk Console Ready");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-30 23:11:07 +00:00
|
|
|
static int load_module(void *mod)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
2000-01-02 20:59:00 +00:00
|
|
|
if (pipe(clipipe)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create CLI pipe\n");
|
|
|
|
return -1;
|
|
|
|
}
|
1999-11-12 06:29:40 +00:00
|
|
|
g_thread_init(NULL);
|
|
|
|
if (gtk_init_check(NULL, NULL)) {
|
|
|
|
if (!show_console()) {
|
|
|
|
inuse++;
|
|
|
|
ast_update_use_count();
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(2, "Launched GTK Console monitor\n");
|
1999-11-12 06:29:40 +00:00
|
|
|
} else
|
|
|
|
ast_log(LOG_WARNING, "Unable to start GTK console\n");
|
|
|
|
} else {
|
|
|
|
if (option_debug)
|
|
|
|
ast_log(LOG_DEBUG, "Unable to start GTK console monitor -- ignoring\n");
|
2007-07-26 15:49:18 +00:00
|
|
|
else
|
|
|
|
ast_verb(2, "GTK is not available -- skipping monitor\n");
|
1999-11-12 06:29:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-30 23:11:07 +00:00
|
|
|
static const char *description(void)
|
1999-11-12 06:29:40 +00:00
|
|
|
{
|
|
|
|
return dtext;
|
|
|
|
}
|
2001-03-07 00:52:22 +00:00
|
|
|
|
2006-07-30 23:11:07 +00:00
|
|
|
static const char *key(void)
|
2001-03-07 00:52:22 +00:00
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|
2006-04-24 17:11:45 +00:00
|
|
|
|
2006-07-30 23:11:07 +00:00
|
|
|
STD_MOD(MOD_0, reload_module, NULL, NULL);
|