-rw-r--r-- | T42Secretary.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/T42Secretary.cpp b/T42Secretary.cpp new file mode 100644 index 0000000..62cef87 --- a/dev/null +++ b/T42Secretary.cpp | |||
@@ -0,0 +1,121 @@ | |||
1 | // T42Secretary.cpp : implementation file | ||
2 | // | ||
3 | |||
4 | #include "stdafx.h" | ||
5 | #include "T42.h" | ||
6 | #include "T42Document.h" | ||
7 | #include "T42Secretary.h" | ||
8 | |||
9 | #include "T42View.h" | ||
10 | #include "T42Frame.h" | ||
11 | |||
12 | CT42Secretary::CT42Secretary() | ||
13 | { | ||
14 | m_logEntry.m_Time = CTime::GetCurrentTime(); | ||
15 | CT42App* app = (CT42App*)AfxGetApp(); | ||
16 | app->m_T42LinesBusy++; | ||
17 | m_limitTime = app->m_T42STimeLimit; | ||
18 | m_limitBytes = app->m_T42SBytesLimit; | ||
19 | TRACE0("Secretary++\n"); | ||
20 | } | ||
21 | |||
22 | CT42Secretary::~CT42Secretary() | ||
23 | { | ||
24 | CT42App* app = (CT42App*)AfxGetApp(); | ||
25 | app->m_T42LinesBusy--; | ||
26 | TRACE0("Secretary--\n"); | ||
27 | } | ||
28 | |||
29 | |||
30 | BOOL CT42Secretary::OnAttach(T42Document* pDocument) | ||
31 | { | ||
32 | TRACE0("T42S - OnAttach\n"); | ||
33 | return CT42Robot::OnAttach(pDocument); | ||
34 | } | ||
35 | |||
36 | BOOL CT42Secretary::OnConnect() | ||
37 | { | ||
38 | m_logEntry.m_Caller = m_pDocument->m_pView->m_pFrame->m_Target; | ||
39 | m_logEntry.m_Callee = m_pDocument->m_pView->m_pFrame->m_LocalUser; | ||
40 | m_logEntry.m_Message.Empty(); | ||
41 | m_logEntry.m_Time = CTime::GetCurrentTime(); | ||
42 | |||
43 | CT42App* app = (CT42App*)AfxGetApp(); | ||
44 | CString greet = app->m_T42SGreeting; | ||
45 | int ix; | ||
46 | while((ix=greet.Find("%t"))>=0){ | ||
47 | CString tmp; | ||
48 | tmp.Format("%lu",app->m_T42STimeLimit.GetTotalSeconds()/60); | ||
49 | greet = greet.Left(ix)+tmp+greet.Mid(ix+2); | ||
50 | } | ||
51 | while((ix=greet.Find("%c"))>=0){ | ||
52 | CString tmp; | ||
53 | tmp.Format("%u",app->m_T42SBytesLimit); | ||
54 | greet = greet.Left(ix)+tmp+greet.Mid(ix+2); | ||
55 | } | ||
56 | m_pDocument->SendOver(greet); | ||
57 | return TRUE; | ||
58 | } | ||
59 | |||
60 | BOOL CT42Secretary::OnReceive(char* pData,int nBytes) | ||
61 | { | ||
62 | if(m_limitBytes && m_pDocument->m_pView->m_remoteCtl.GetTextLength()>=m_limitBytes) | ||
63 | OnDisconnect(); | ||
64 | return TRUE; | ||
65 | } | ||
66 | |||
67 | BOOL CT42Secretary::OnDisconnect() | ||
68 | { | ||
69 | m_logEntry.m_Duration = CTime::GetCurrentTime()-m_logEntry.m_Time; | ||
70 | EDITSTREAM es; | ||
71 | memset(&es,0,sizeof(es)); | ||
72 | es.dwCookie = (DWORD)&m_logEntry.m_Message; | ||
73 | es.pfnCallback = ESINProc; | ||
74 | m_pDocument->m_pView->m_remoteCtl.StreamOut(SF_RTF,es); | ||
75 | m_logEntry.m_Status = CT42CallLogEntry::statusOk; | ||
76 | CT42App* app = (CT42App*)AfxGetApp(); | ||
77 | VERIFY(app->AddT42Call(m_logEntry)); | ||
78 | m_pDocument->m_pView->m_pFrame->OnTalkClose(); | ||
79 | return TRUE; | ||
80 | } | ||
81 | |||
82 | BOOL CT42Secretary::OnDetach() | ||
83 | { | ||
84 | TRACE0("T42S - OnDetach\n"); | ||
85 | delete this; | ||
86 | return TRUE; | ||
87 | } | ||
88 | |||
89 | |||
90 | BOOL CT42Secretary::OnIPResolved() | ||
91 | { | ||
92 | m_logEntry.m_Caller = m_pDocument->m_pView->m_pFrame->m_Target; | ||
93 | return TRUE; | ||
94 | } | ||
95 | |||
96 | DWORD CALLBACK CT42Secretary::ESINProc(DWORD dwCookie,LPBYTE pbBuff,LONG cb,LONG FAR *pcb) | ||
97 | { | ||
98 | CString* str = (CString*)dwCookie; | ||
99 | if(memchr(pbBuff,0,cb-1)){ | ||
100 | (*pcb) = 0; | ||
101 | return 1; | ||
102 | } | ||
103 | UINT p = str->GetLength(); | ||
104 | CHAR* s = str->GetBuffer(p+cb+1); | ||
105 | memmove(&s[p],pbBuff,cb); | ||
106 | s[p+cb]=0; | ||
107 | str->ReleaseBuffer(); | ||
108 | (*pcb)=cb; | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | BOOL CT42Secretary::OnMinute() | ||
113 | { | ||
114 | if( | ||
115 | m_limitTime.GetTotalSeconds() && | ||
116 | (CTime::GetCurrentTime()-m_logEntry.m_Time)>=m_limitTime | ||
117 | ) | ||
118 | OnDisconnect(); | ||
119 | return TRUE; | ||
120 | } | ||
121 | |||