aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_modem.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-03-04 06:47:24 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-03-04 06:47:24 +0000
commit8ba4898a1eece83e44568bf8a4373a3de341a40c (patch)
treed4f64d65fd10bb76d2839b641fa20091909210c5 /channels/chan_modem.c
parentb0180cc4f641d4097a85f52b887ac0bef130604b (diff)
Rework channel structure to eliminate "pvt" portion of channel (bug #3573)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5137 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_modem.c')
-rwxr-xr-xchannels/chan_modem.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/channels/chan_modem.c b/channels/chan_modem.c
index 74f9ec7fc..64c73aa38 100755
--- a/channels/chan_modem.c
+++ b/channels/chan_modem.c
@@ -15,7 +15,6 @@
#include <string.h>
#include <asterisk/lock.h>
#include <asterisk/channel.h>
-#include <asterisk/channel_pvt.h>
#include <asterisk/config.h>
#include <asterisk/logger.h>
#include <asterisk/module.h>
@@ -39,10 +38,10 @@
/* Up to 10 seconds for an echo to arrive */
#define ECHO_TIMEOUT 10
-static char *desc = "Generic Voice Modem Driver";
-static char *tdesc = "Generic Voice Modem Channel Driver";
-static char *type = "Modem";
-static char *config = "modem.conf";
+static const char desc[] = "Generic Voice Modem Driver";
+static const char tdesc[] = "Generic Voice Modem Channel Driver";
+static const char type[] = "Modem";
+static const char config[] = "modem.conf";
static char dialtype = 'T';
static int gmode = MODEM_MODE_IMMEDIATE;
@@ -97,6 +96,29 @@ static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
+static struct ast_channel *modem_request(const char *type, int format, void *data, int *cause);
+static int modem_digit(struct ast_channel *ast, char digit);
+static int modem_call(struct ast_channel *ast, char *idest, int timeout);
+static int modem_hangup(struct ast_channel *ast);
+static int modem_answer(struct ast_channel *ast);
+static struct ast_frame *modem_read(struct ast_channel *);
+static int modem_write(struct ast_channel *ast, struct ast_frame *frame);
+static int modem_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
+
+static const struct ast_channel_tech modem_tech = {
+ .type = type,
+ .description = tdesc,
+ .capabilities = AST_FORMAT_SLINEAR,
+ .requester = modem_request,
+ .send_digit = modem_digit,
+ .call = modem_call,
+ .hangup = modem_hangup,
+ .answer = modem_answer,
+ .read = modem_read,
+ .write = modem_write,
+ .fixup = modem_fixup,
+};
+
/* The private structures of the Phone Jack channels are linked for
selecting outgoing channels */
@@ -105,7 +127,7 @@ static struct ast_modem_pvt *iflist = NULL;
static int modem_digit(struct ast_channel *ast, char digit)
{
struct ast_modem_pvt *p;
- p = ast->pvt->pvt;
+ p = ast->tech_pvt;
if (p->mc->dialdigit)
return p->mc->dialdigit(p, digit);
ast_log(LOG_DEBUG, "Channel %s lacks digit dialing\n", ast->name);
@@ -114,8 +136,6 @@ static int modem_digit(struct ast_channel *ast, char digit)
static struct ast_modem_driver *drivers = NULL;
-static struct ast_frame *modem_read(struct ast_channel *);
-
static struct ast_modem_driver *find_capability(char *ident)
{
struct ast_modem_driver *mc;
@@ -191,7 +211,7 @@ static int modem_call(struct ast_channel *ast, char *idest, int timeout)
ast_log(LOG_WARNING, "Destination %s requres a real destination (device:destination)\n", idest);
return -1;
}
- p = ast->pvt->pvt;
+ p = ast->tech_pvt;
strncpy(dstr, where + p->stripmsd, sizeof(dstr) - 1);
/* if not a transfer or just sending tones, must be in correct state */
if (strcasecmp(rdest, "transfer") && strcasecmp(rdest,"sendtones")) {
@@ -421,7 +441,7 @@ static int modem_hangup(struct ast_channel *ast)
struct ast_modem_pvt *p;
if (option_debug)
ast_log(LOG_DEBUG, "modem_hangup(%s)\n", ast->name);
- p = ast->pvt->pvt;
+ p = ast->tech_pvt;
/* Hang up */
if (p->mc->hangup)
p->mc->hangup(p);
@@ -432,7 +452,7 @@ static int modem_hangup(struct ast_channel *ast)
memset(p->cid_num, 0, sizeof(p->cid_num));
memset(p->cid_name, 0, sizeof(p->cid_name));
memset(p->dnid, 0, sizeof(p->dnid));
- ((struct ast_modem_pvt *)(ast->pvt->pvt))->owner = NULL;
+ ((struct ast_modem_pvt *)(ast->tech_pvt))->owner = NULL;
ast_mutex_lock(&usecnt_lock);
usecnt--;
if (usecnt < 0)
@@ -441,7 +461,7 @@ static int modem_hangup(struct ast_channel *ast)
ast_update_use_count();
if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
- ast->pvt->pvt = NULL;
+ ast->tech_pvt = NULL;
ast_setstate(ast, AST_STATE_DOWN);
restart_monitor();
return 0;
@@ -453,7 +473,7 @@ static int modem_answer(struct ast_channel *ast)
int res=0;
if (option_debug)
ast_log(LOG_DEBUG, "modem_answer(%s)\n", ast->name);
- p = ast->pvt->pvt;
+ p = ast->tech_pvt;
if (p->mc->answer) {
res = p->mc->answer(p);
}
@@ -479,7 +499,7 @@ static char modem_2digit(char c)
#endif
static struct ast_frame *modem_read(struct ast_channel *ast)
{
- struct ast_modem_pvt *p = ast->pvt->pvt;
+ struct ast_modem_pvt *p = ast->tech_pvt;
struct ast_frame *fr=NULL;
if (p->mc->read)
fr = p->mc->read(p);
@@ -490,7 +510,7 @@ static int modem_write(struct ast_channel *ast, struct ast_frame *frame)
{
int res=0;
long flags;
- struct ast_modem_pvt *p = ast->pvt->pvt;
+ struct ast_modem_pvt *p = ast->tech_pvt;
/* Modems tend to get upset when they receive data whilst in
* command mode. This makes esp. dial commands short lived.
@@ -512,7 +532,7 @@ static int modem_write(struct ast_channel *ast, struct ast_frame *frame)
static int modem_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
{
- struct ast_modem_pvt *p = newchan->pvt->pvt;
+ struct ast_modem_pvt *p = newchan->tech_pvt;
ast_log(LOG_WARNING, "fixup called\n");
if (p->owner!=oldchan) {
ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n",oldchan,p->owner);
@@ -527,6 +547,7 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
struct ast_channel *tmp;
tmp = ast_channel_alloc(1);
if (tmp) {
+ tmp->tech = &modem_tech;
snprintf(tmp->name, sizeof(tmp->name), "Modem[%s]/%s", i->mc->name, i->dev + 5);
tmp->type = type;
tmp->fds[0] = i->fd;
@@ -534,14 +555,7 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
ast_setstate(tmp, state);
if (state == AST_STATE_RING)
tmp->rings = 1;
- tmp->pvt->pvt = i;
- tmp->pvt->send_digit = modem_digit;
- tmp->pvt->call = modem_call;
- tmp->pvt->hangup = modem_hangup;
- tmp->pvt->answer = modem_answer;
- tmp->pvt->read = modem_read;
- tmp->pvt->write = modem_write;
- tmp->pvt->fixup = modem_fixup;
+ tmp->tech_pvt = i;
strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
if (!ast_strlen_zero(i->cid_num))
@@ -889,7 +903,7 @@ static int __unload_module(void)
{
struct ast_modem_pvt *p, *pl;
/* First, take us out of the channel loop */
- ast_channel_unregister(type);
+ ast_channel_unregister(&modem_tech);
if (!ast_mutex_lock(&iflock)) {
/* Hangup all interfaces if they have an owner */
p = iflist;
@@ -1052,8 +1066,7 @@ int load_module()
v = v->next;
}
ast_mutex_unlock(&iflock);
- if (ast_channel_register(type, tdesc, /* XXX Don't know our types -- maybe we should register more than one XXX */
- AST_FORMAT_SLINEAR, modem_request)) {
+ if (ast_channel_register(&modem_tech)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
ast_config_destroy(cfg);
__unload_module();
@@ -1076,7 +1089,7 @@ int usecount(void)
char *description()
{
- return desc;
+ return (char *) desc;
}
char *key()