dect
/
asterisk
Archived
13
0
Fork 0

Version 0.1.0 from FTP

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@16 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
markster 1999-11-12 06:29:40 +00:00
parent 57f2b9b65e
commit c807c3d28c
2 changed files with 539 additions and 0 deletions

152
include/asterisk/channel.h Executable file
View File

@ -0,0 +1,152 @@
/*
* Asterisk -- A telephony toolkit for Linux.
*
* General Asterisk channel definitions.
*
* Copyright (C) 1999, Adtran Inc. and Linux Support Services, LLC
*
* Mark Spencer <markster@linux-support.net>
*
* This program is free software, distributed under the terms of
* the GNU General Public License
*/
#ifndef _ASTERISK_CHANNEL_H
#define _ASTERISK_CHANNEL_H
#include <asterisk/frame.h>
#include <asterisk/sched.h>
#include <setjmp.h>
#include <pthread.h>
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#define AST_CHANNEL_NAME 80
#define AST_CHANNEL_MAX_STACK 32
/* Max length an extension can be (unique) is this number */
#define AST_MAX_EXTENSION 80
struct ast_channel {
char name[AST_CHANNEL_NAME]; /* ASCII Description of channel name */
pthread_t blocker; /* If anyone is blocking, this is them */
char *blockproc; /* Procedure causing blocking */
int blocking; /* Whether or not we're blocking */
struct sched_context *sched; /* Schedule context */
int streamid; /* For streaming playback, the schedule ID */
struct ast_filestream *stream; /* Stream itself. */
struct ast_channel *trans; /* Translator if present */
struct ast_channel *master; /* Master channel, if this is a translator */
int fd; /* File descriptor for channel -- all must have
a file descriptor! */
char *type; /* Type of channel */
int state; /* State of line */
int rings; /* Number of rings so far */
int stack; /* Current level of application */
int format; /* Kinds of data this channel can
natively handle */
char *dnid; /* Malloc'd Dialed Number Identifier */
char *callerid; /* Malloc'd Caller ID */
char context[AST_MAX_EXTENSION]; /* Current extension context */
char exten[AST_MAX_EXTENSION]; /* Current extension number */
int priority; /* Current extension priority */
void *app[AST_CHANNEL_MAX_STACK]; /* Application information -- see assigned numbers */
struct ast_channel_pvt *pvt;
/* Private channel implementation details */
jmp_buf jmp[AST_CHANNEL_MAX_STACK]; /* Jump buffer used for returning from applications */
struct ast_pbx *pbx;
struct ast_channel *next; /* For easy linking */
};
/* Bits 0-15 of state are reserved for the state (up/down) of the line */
#define AST_STATE_DOWN 0 /* Channel is down and available */
#define AST_STATE_RESERVED 1 /* Channel is down, but reserved */
#define AST_STATE_OFFHOOK 2 /* Channel is off hook */
#define AST_STATE_DIALING 3 /* Digits (or equivalent) have been dialed */
#define AST_STATE_RING 4 /* Line is ringing */
#define AST_STATE_RINGING 5 /* Remote end is ringing */
#define AST_STATE_UP 6 /* Line is up */
#define AST_STATE_BUSY 7 /* Line is busy */
/* Bits 16-32 of state are reserved for flags */
#define AST_STATE_MUTE (1 << 16) /* Do not transmit voice data */
/* Request a channel of a given type, with data as optional information used
by the low level module */
struct ast_channel *ast_request(char *type, int format, void *data);
/* Called by a channel module to register the kind of channels it supports.
It supplies a brief type, a longer, but still short description, and a
routine that creates a channel */
int ast_channel_register(char *type, char *description, int capabilities,
struct ast_channel* (*requester)(char *type, int format, void *data));
/* Unregister a channel class */
void ast_channel_unregister(char *type);
/* Hang up a channel -- chan is no longer valid after this call! */
int ast_hangup(struct ast_channel *chan);
/* Softly hangup up a channel -- call the protocol layer, but don't
destroy the channel structure (use this if you are trying to
safely hangup a channel managed by another thread. */
int ast_softhangup(struct ast_channel *chan);
/* Answer a ringing call */
int ast_answer(struct ast_channel *chan);
/* Place a call, take no longer than timeout ms. Returns -1 on failure,
0 on not enough time (does not auto matically stop ringing), and
the number of seconds the connect took otherwise. */
int ast_call(struct ast_channel *chan, char *addr, int timeout);
/* Misc stuff */
/* Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
int ast_waitfor(struct ast_channel *chan, int ms);
/* Wait for input on an array of channels for a given # of milliseconds. Return channel
with activity, or NULL if none has activity. time "ms" is modified in-place, if applicable */
struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
/* This version works on fd's only. Be careful with it. */
int ast_waitfor_n_fd(int *fds, int n, int *ms);
/* Read a frame. Returns a frame, or NULL on error. If it returns NULL, you
best just stop reading frames and assume the channel has been
disconnected. */
struct ast_frame *ast_read(struct ast_channel *chan);
/* Write a frame to a channel */
int ast_write(struct ast_channel *chan, struct ast_frame *frame);
/* Wait for a digit. Returns <0 on error, 0 on no entry, and the digit on success. */
char ast_waitfordigit(struct ast_channel *c, int ms);
/* Read in a digit string "s", max length "len", maximum timeout between
digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
for the first digit */
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
#define CHECK_BLOCKING(c) { \
if ((c)->blocking) \
ast_log(LOG_WARNING, "Blocking '%s', already blocked by thread %ld in procedure %s\n", (c)->name, (c)->blocker, (c)->blockproc); \
else { \
(c)->blocker = pthread_self(); \
(c)->blockproc = __PRETTY_FUNCTION__; \
c->blocking = -1; } }
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif

387
pbx/pbx_gtkconsole.c Executable file
View File

@ -0,0 +1,387 @@
/*
* Asterisk -- A telephony toolkit for Linux.
*
* GTK Console monitor -- very kludgy right now
*
* Copyright (C) 1999, Adtran Inc. and Linux Support Services, LLC
*
* Mark Spencer <markster@linux-support.net>
*
* This program is free software, distributed under the terms of
* the GNU General Public License
*/
/*
* I know this might seem somewhat pointless in its current phase, but one
* of the most important parts of this module is demonstrate that modules
* can require other external libraries and still be loaded (in this
* case, a host of libraries involving gtk), so long as they are properly
* linked (see the Makefile)
*/
#include <asterisk/pbx.h>
#include <asterisk/config.h>
#include <asterisk/module.h>
#include <asterisk/logger.h>
#include <asterisk/options.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <gtk/gtk.h>
#include <glib.h>
/* For where to put dynamic tables */
#include "../asterisk.h"
static pthread_mutex_t verb_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_t console_thread;
static int inuse=0;
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;
static void update_statusbar(char *msg)
{
gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 1);
gtk_statusbar_push(GTK_STATUSBAR(statusbar), 1, msg);
}
int unload_module(void)
{
if (inuse) {
/* Kill off the main thread */
pthread_cancel(console_thread);
gdk_threads_enter();
gtk_widget_destroy(window);
gdk_threads_leave();
}
return 0;
}
static void verboser(char *stuff, int opos, int replacelast, int complete)
{
char *s2[2];
pthread_mutex_lock(&verb_lock);
s2[0] = stuff;
s2[1] = NULL;
gdk_threads_enter();
if (replacelast)
gtk_clist_remove(GTK_CLIST(verb), GTK_CLIST(verb)->rows - 1);
gtk_clist_append(GTK_CLIST(verb), s2);
gtk_clist_moveto(GTK_CLIST(verb), GTK_CLIST(verb)->rows - 1, 0, 0, 0);
gdk_threads_leave();
pthread_mutex_unlock(&verb_lock);
}
static void remove_module()
{
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);
}
}
}
static void reload_module()
{
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);
}
}
}
static void file_ok_sel(GtkWidget *w, GtkFileSelection *fs)
{
char *module = gtk_file_selection_get_filename(fs);
char buf[256];
if (!strncmp(module, AST_MODULE_DIR "/", strlen(AST_MODULE_DIR "/")))
module += strlen(AST_MODULE_DIR "/");
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));
}
static void add_module()
{
GtkWidget *filew;
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));
gtk_file_selection_set_filename(GTK_FILE_SELECTION(filew), AST_MODULE_DIR "/*.so");
gtk_widget_show(filew);
}
static int add_mod(char *module, char *description, int usecount)
{
char use[10];
char *pass[4];
int row;
snprintf(use, sizeof(use), "%d", usecount);
pass[0] = module;
pass[1] = description;
pass[2] = use;
pass[3] = NULL;
row = gtk_clist_append(GTK_CLIST(modules), pass);
gtk_clist_set_row_data(GTK_CLIST(modules), row, module);
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);
}
gdk_threads_enter();
gtk_clist_freeze(GTK_CLIST(modules));
gtk_clist_clear(GTK_CLIST(modules));
ast_update_module_list(add_mod);
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));
gdk_threads_leave();
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);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "GTK Console Monitor Exiting\n");
}
static void exit_completely(GtkWidget *widget, gpointer data)
{
/* This is the wrong way to do this. We need an ast_clean_exit() routine */
exit(0);
}
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;
}
static int show_console()
{
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);
gtk_widget_set_usize(verb, 600, 400);
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);
gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 5);
gtk_box_pack_start(GTK_BOX(hbox), wbox, FALSE, FALSE, 5);
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");
pthread_create(&console_thread, NULL, consolethread, NULL);
/* 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));
mod_update();
update_statusbar("Asterisk Console Ready");
return 0;
}
int load_module(void)
{
g_thread_init(NULL);
if (gtk_init_check(NULL, NULL)) {
/* XXX Do we need to call this twice? XXX */
gtk_init(NULL, NULL);
if (!show_console()) {
inuse++;
ast_update_use_count();
if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Launched GTK Console monitor\n");
} 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");
else if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "GTK is not available -- skipping monitor\n");
}
return 0;
}
int usecount(void)
{
return inuse;
}
char *description(void)
{
return dtext;
}