-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCTIServer.cpp
144 lines (120 loc) · 3.06 KB
/
CTIServer.cpp
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
133
134
135
136
137
138
139
140
141
142
143
144
#include "StdAfx.h"
#include "CTIServer.h"
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
CTIServer::CTIServer(void)
{
}
CTIServer::~CTIServer(void)
{
}
BOOL CTIServer::InitSystem()
{
DriverOpenFlag = LoadDRV ( );
if( DriverOpenFlag )
{
AfxMessageBox("Load Driver FAIL");
return FALSE;
}
TotalLine = CheckValidCh();
if ( EnableCard(TotalLine,1024*8) != (long)0)
{
FreeDRV();
AfxMessageBox ("Enable Board FAIL");
return FALSE;
}
Sig_Init(0);
Lines = new Channel[TotalLine];
for(int i=0;i<TotalLine;i++)
{
InitDtmfBuf(i);
Lines[i].UsableFlag=TRUE;
Lines[i].ConnectToLine=-1;
Lines[i].nType=CheckChTypeNew(i);
Lines[i].State = CH_FREE;
Lines[i].TelLength=0;
Lines[i].CallerID[0]=NULL;
Lines[i].DTMFCode[0] =NULL;
Lines[i].nTimeElapse=0;
Lines[i].IsLogin = FALSE;
Lines[i].TotalLine = TotalLine;
Lines[i].No = i;
Lines[i].Connected = FALSE;
Lines[i].UserId[0] = NULL;
Lines[i].PhoneNum[0] = NULL;
Lines[i].strItemId = _T("");
Lines[i].flag1 = FALSE;
Lines[i].ctStartTime = CTime::GetCurrentTime();
Lines[i].setCTIServer(this);
}
return TRUE;
}
void CTIServer::ExitSystem()
{
for( int LineNo=0; LineNo<TotalLine; LineNo++ )
{
if( Lines[LineNo].nType==CHTYPE_TRUNK )
{
FeedPower(Lines[LineNo].ConnectToLine);
HangUp(LineNo);
Sig_ResetCheck(LineNo); //清空忙音检测的缓冲区以及内部计数。当检测对方挂机的忙音后,必须调用本函数
StartSigCheck(LineNo); //某路开始新的信号音检测。一般在摘机或者挂机后,调用本函数来开始新的信号音检测。
}
if( Lines[LineNo].nType == CHTYPE_USER )
{
FeedPower( Lines[LineNo].ConnectToLine);
StartPlaySignal( LineNo,SIG_STOP );
if( Lines[Lines[LineNo].ConnectToLine].nType == CHTYPE_TRUNK )
HangUp( Lines[LineNo].ConnectToLine );
}
if(Lines[LineNo].ConnectToLine!=-1)
{
ClearLink(LineNo,Lines[LineNo].ConnectToLine);
Lines[LineNo].ConnectToLine = -1;
Lines[Lines[LineNo].ConnectToLine].ConnectToLine = -1;
}
}
DisableCard();
FreeDRV();
delete []Lines;
_CrtDumpMemoryLeaks(); /////////////////////////////////////////
}
Channel* CTIServer::getChannel(int LineNo)
{
// memset(Lines[LineNo].DTMFCode,0,100);
// Lines[LineNo].DTMFCode[0] = NULL;
return &Lines[LineNo];
}
void CTIServer::Run()
{
PUSH_PLAY();
FeedSigFunc();
for(int LineNo=0;LineNo<TotalLine;LineNo++)
{
Lines[LineNo].Run(LineNo);
}
}
void CTIServer::SetListCtrls(CListCtrl *plist1, CListCtrl *plist2, CListCtrl *plist3, CListCtrl *plist4)
{
for(int LineNo=0;LineNo<TotalLine;LineNo++)
{
Lines[LineNo].SetListCtrls(plist1,plist2,plist3,plist4);
}
}
BOOL CTIServer::checkLoginByUserId(CString UserId,CString &strPhone,int &lineNo)
{
for(int LineNo=0;LineNo<TotalLine;LineNo++)
{
if( Lines[LineNo].IsLogin )
{
if( strcmp( Lines[LineNo].UserId,(LPTSTR)(LPCTSTR)UserId ) == 0 )
{
strPhone = (LPCTSTR)(LPTSTR)Lines[LineNo].PhoneNum;
lineNo = Lines[LineNo].No;
return TRUE;
}
}
}
return FALSE;
}