File: span.cpp

package info (click to toggle)
bayonne 2.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 11,180 kB
  • ctags: 3,662
  • sloc: cpp: 38,791; sh: 9,323; ansic: 1,391; makefile: 485; perl: 471; java: 405; cs: 402; php: 354; python: 293
file content (100 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download
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
// Copyright (C) 2005 Open Source Telecom Corp.
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "engine.h"

using namespace ost;
using namespace std;

BayonneSpan *BayonneSpan::first = NULL;
BayonneSpan *BayonneSpan::last = NULL;
BayonneSpan **BayonneSpan::index = NULL;
unsigned BayonneSpan::spans = 0;

BayonneSpan::BayonneSpan(BayonneDriver *d, timeslot_t ports) :
Keydata()
{
	char name[128];

	snprintf(name, sizeof(name), "/bayonne/spans/%d", spans);
	load(name);

	id = spans++;
	if(first)
		last->next = this;
	else
		first = last = this;

	driver = d;
	next = NULL;
	timeslot = ts_used;
	count = ports;
	used = 0;
	active_calls = 0;
}

bool BayonneSpan::suspend(void)
{
	return false;
}

bool BayonneSpan::resume(void)
{
	return false;
}

bool BayonneSpan::reset(void)
{
	return false;
}

BayonneSession *BayonneSpan::getTimeslot(timeslot_t ts)
{
	if(ts >= count)
		return NULL;

	return getSession(timeslot + ts);
}

void BayonneSpan::allocate(unsigned count)
{
	BayonneSpan *span = first;

	if(!count)
		count = spans;

	if(index)
		return;

	index = new BayonneSpan*[spans];
	while(span)
	{
		index[span->id] = span;
		span = span->next;
	}
}

BayonneSpan *BayonneSpan::get(unsigned id)
{
        if(!index && spans)
                allocate();

        if(id >= spans)
                return NULL;

        return index[id];
}