File: mapdev.cpp

package info (click to toggle)
vpb-driver 4.2.55-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,528 kB
  • sloc: cpp: 26,247; ansic: 19,041; sh: 3,210; perl: 1,132; makefile: 752; asm: 182
file content (132 lines) | stat: -rw-r--r-- 3,782 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*---------------------------------------------------------------------------*\

    FILE....: MAPDEV.CPP
    TYPE....: WIN32 C++ Function
    AUTHOR..: John Kostogiannis
    DATE....: 6/11/97
    AUTHOR..: Ron Lee
    DATE....: 11/11/06

    Functions used to map the board and channel number to a handle and 
	vice versa.


         Voicetronix Voice Processing Board (VPB) Software
         Copyright (C) 1999-2006 Voicetronix www.voicetronix.com.au

         This library is free software; you can redistribute it and/or
         modify it under the terms of the GNU Lesser General Public
         License as published by the Free Software Foundation; either
         version 2.1 of the License, or (at your option) any later version.

         This library is distributed in the hope that it will be useful,
         but WITHOUT ANY WARRANTY; without even the implied warranty of
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
         Lesser General Public License for more details.

         You should have received a copy of the GNU Lesser General Public
         License along with this library; if not, write to the Free Software
         Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
         MA  02110-1301  USA

\*---------------------------------------------------------------------------*/

#include <assert.h>

#include "mapdev.h"
#include "apifunc.h"
#include "wobbly.h"

#ifdef _OPENPRI
 #include "openpri.h"
#endif

/*--------------------------------------------------------------------------*\

	FUNCTION.: mapdevtohndle
	AUTHOR...: John Kostogiannis
	DATE.....: 25/11/97

	Maps the board number and channel number to a handle, this function
	assumes four channels per board.

\*--------------------------------------------------------------------------*/
int mapdevtohndle(unsigned int board, unsigned int port)
{ //{{{
	VPBREG    *v = vpb_c->vpbreg(board);

	if( port >= v->handles.size() )
		v->handles.resize( port + 1, -1 );

	int handle = v->handles[port];

	if( handle == -1 )
		return v->handles[port] = vpb_c->NewHandle( board, port );

	return handle;
} //}}}

/*--------------------------------------------------------------------------*\

	FUNCTION.: maphndletodev
	AUTHOR...: John Kostogiannis
	DATE.....: 25/11/97

	Maps the handle to board number and channel number.  This function
	assumes four channels per board.

\*--------------------------------------------------------------------------*/
void maphndletodev(int handle, unsigned short *board, unsigned short *port)
{ //{{{
        const VPBHANDLE   &lookup = vpb_c->LookupHandle( handle );

        *board = lookup.board;
        *port  = lookup.channel;
} //}}}


#ifdef _OPENPRI
/*--------------------------------------------------------------------------*\

	FUNCTION.: get_idx_from_ch()
	AUTHOR...: Ben Kramer
	DATE.....: xx/12/04
	
	Finds out the index to chans given a vpb channel

\*--------------------------------------------------------------------------*/
int get_idx_from_ch(VPBREG *v, int ch)
{
	pri_chan *chans = (pri_chan*)v->chans;
	int i = 0;

	for(; i < v->numch; ++i){
		if(ch == chans[i].chan_num)
			return i;
	}
	throw Wobbly(MAPDEV_INVALID_CHANNEL);
}

/*--------------------------------------------------------------------------*\

	FUNCTION.: get_idx_from_ich()
	AUTHOR...: Ben Kramer
	DATE.....: xx/01/05
	
	Finds out the index to chans given an ISDN channel

\*--------------------------------------------------------------------------*/
int get_idx_from_ich(VPBREG *v, int ch)
{
	pri_chan *chans = (pri_chan *)v->chans;
	int i = 0;

	ch &= 0xff;     // strip off any extra flags added by libpri.
	for(; i < v->numch; ++i){
		if(ch == chans[i].iface->channel)
			return i;
	}
	throw Wobbly(MAPDEV_INVALID_CHANNEL);
}
#endif