24
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// For manipulting of received data
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file schat.cpp
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "SCHAT.H"
|
|
23 |
#include "ND_STD.H"
|
|
24 |
|
|
25 |
//
|
|
26 |
// CCommChatter definitions
|
|
27 |
//
|
|
28 |
|
|
29 |
CCommChatter* CCommChatter::NewL(MCommChatNotify* aNotify,TInt aPriority,TInt aBufferSize)
|
|
30 |
/**
|
|
31 |
2 phased constructor for CCommChatter, first phase.
|
|
32 |
|
|
33 |
@param aNotify a pointer to chat notifier.
|
|
34 |
@param aPriority is priority for this timer.
|
|
35 |
@param aBufferSize is buffer size for this object.
|
|
36 |
@exception Leaves if ConstructL() leaves, or not enough memory is available.
|
|
37 |
@return a new CCommChatter object.
|
|
38 |
*/
|
|
39 |
{
|
|
40 |
CCommChatter* cc=new(ELeave) CCommChatter(aNotify,aPriority);
|
|
41 |
CleanupStack::PushL(cc);
|
|
42 |
cc->ConstructL(aBufferSize);
|
|
43 |
CleanupStack::Pop();
|
|
44 |
return cc;
|
|
45 |
}
|
|
46 |
|
|
47 |
CCommChatter::CCommChatter(MCommChatNotify* aNotify, TInt aPriority)
|
|
48 |
: CTimer(aPriority), iNotify(aNotify)
|
|
49 |
/**
|
|
50 |
Private constructor for CCommChatter, used in the first phase of construction.
|
|
51 |
|
|
52 |
@param aNotify a pointer to chat notifier.
|
|
53 |
@param aPriority is priority for this timer.
|
|
54 |
*/
|
|
55 |
{
|
|
56 |
CActiveScheduler::Add(this);
|
|
57 |
iList.SetOffset(_FOFF(CCommChatString,iLink));
|
|
58 |
}
|
|
59 |
|
|
60 |
void CCommChatter::ConstructL(TInt aBufSize)
|
|
61 |
/**
|
|
62 |
Instantiates member variables.
|
|
63 |
|
|
64 |
@param aBufSize is buffer size for this object.
|
|
65 |
@exception Leaves if CTimer::ConstructL() or User::AllocL() leaves.
|
|
66 |
*/
|
|
67 |
{
|
|
68 |
CTimer::ConstructL();
|
|
69 |
iBuffer=(TText8*)User::AllocL(aBufSize);
|
|
70 |
iBufferEnd=(iBuffer+aBufSize)-1;
|
|
71 |
ClearHistory();
|
|
72 |
}
|
|
73 |
|
|
74 |
CCommChatter::~CCommChatter()
|
|
75 |
/**
|
|
76 |
Destructor.
|
|
77 |
Frees iBuffer's allocated memory.
|
|
78 |
*/
|
|
79 |
{
|
|
80 |
User::Free(iBuffer);
|
|
81 |
}
|
|
82 |
|
|
83 |
void CCommChatter::ClearHistory()
|
|
84 |
/**
|
|
85 |
Empties history.
|
|
86 |
*/
|
|
87 |
{
|
|
88 |
iLastChar=iBuffer;
|
|
89 |
iCount=0;
|
|
90 |
}
|
|
91 |
|
|
92 |
void CCommChatter::AddChar(TText8 aChar)
|
|
93 |
/**
|
|
94 |
Adds a character to the history buffer.
|
|
95 |
Scan all strings to find any matches that may be completed.
|
|
96 |
*/
|
|
97 |
{
|
|
98 |
if (++iLastChar>iBufferEnd)
|
|
99 |
iLastChar=iBuffer;
|
|
100 |
*iLastChar=aChar;
|
|
101 |
++iCount;
|
|
102 |
|
|
103 |
TText8 fchar=(TText8)User::Fold(aChar);
|
|
104 |
|
|
105 |
// Scan for matching last character
|
|
106 |
CCommChatString* cs;
|
|
107 |
TDblQueIter<CCommChatString> iter(iList);
|
|
108 |
TInt index=0;
|
|
109 |
|
|
110 |
while (cs=iter++, cs!=NULL)
|
|
111 |
{
|
|
112 |
if (cs->IsFolded()
|
|
113 |
? (cs->LastChar()==fchar && MatchF(cs))
|
|
114 |
: (cs->LastChar()==aChar && Match(cs)) )
|
|
115 |
{
|
|
116 |
iNotify->ChatStringMatch(index);
|
|
117 |
cs=iter; // In case user removed cs;
|
|
118 |
}
|
|
119 |
index++;
|
|
120 |
}
|
|
121 |
}
|
|
122 |
|
|
123 |
TBool CCommChatter::Match(const CCommChatString* aString) const
|
|
124 |
/**
|
|
125 |
Matches a chat string against the history buffer (Case sensitive).
|
|
126 |
*/
|
|
127 |
{
|
|
128 |
__ASSERT_ALWAYS(aString!=NULL, NetDialPanic(ENullCommChatString));
|
|
129 |
|
|
130 |
const TText8* s=aString->Ptr();
|
|
131 |
const TText8* sp=aString->EndPtr();
|
|
132 |
const TText8* bp=iLastChar;
|
|
133 |
|
|
134 |
if (iCount<aString->Length())
|
|
135 |
return EFalse;
|
|
136 |
|
|
137 |
while (*bp==*sp && sp>=s)
|
|
138 |
{
|
|
139 |
--sp;
|
|
140 |
if (--bp<iBuffer)
|
|
141 |
bp=iBufferEnd;
|
|
142 |
}
|
|
143 |
|
|
144 |
return sp<s;
|
|
145 |
}
|
|
146 |
|
|
147 |
TBool CCommChatter::MatchF(const CCommChatString* aString) const
|
|
148 |
/**
|
|
149 |
Matches a folded chat string against the history buffer (Case insensitive).
|
|
150 |
*/
|
|
151 |
{
|
|
152 |
__ASSERT_ALWAYS(aString!=NULL, NetDialPanic(ENullCommChatString));
|
|
153 |
|
|
154 |
const TText8* s=aString->Ptr();
|
|
155 |
const TText8* sp=aString->EndPtr();
|
|
156 |
const TText8* bp=iLastChar;
|
|
157 |
|
|
158 |
if (iCount<aString->Length())
|
|
159 |
return EFalse;
|
|
160 |
|
|
161 |
while (User::Fold(*bp)==*sp && sp>=s)
|
|
162 |
{
|
|
163 |
--sp;
|
|
164 |
if (--bp<iBuffer)
|
|
165 |
bp=iBufferEnd;
|
|
166 |
}
|
|
167 |
|
|
168 |
return sp<s;
|
|
169 |
}
|
|
170 |
|
|
171 |
void CCommChatter::RunL()
|
|
172 |
/**
|
|
173 |
Timer completed.
|
|
174 |
*/
|
|
175 |
{
|
|
176 |
iNotify->ChatTimeout();
|
|
177 |
}
|
|
178 |
|
|
179 |
void CCommChatter::AddString(CCommChatString* aString)
|
|
180 |
/**
|
|
181 |
Adds a string to the list.
|
|
182 |
*/
|
|
183 |
{
|
|
184 |
__ASSERT_ALWAYS(aString!=NULL, NetDialPanic(ENullCommChatString));
|
|
185 |
iList.AddLast(*aString);
|
|
186 |
}
|
|
187 |
|
|
188 |
void CCommChatter::RemoveString(CCommChatString* aString)
|
|
189 |
/**
|
|
190 |
Removes a string from the list.
|
|
191 |
*/
|
|
192 |
{
|
|
193 |
__ASSERT_ALWAYS(aString!=NULL, NetDialPanic(ENullCommChatString));
|
|
194 |
aString->iLink.Deque();
|
|
195 |
}
|
|
196 |
|
|
197 |
void CCommChatter::DeleteAllAndStop()
|
|
198 |
/**
|
|
199 |
Removes all strings from the list.
|
|
200 |
*/
|
|
201 |
{
|
|
202 |
StopTimer();
|
|
203 |
CCommChatString* cs;
|
|
204 |
while (!iList.IsEmpty())
|
|
205 |
{
|
|
206 |
cs=iList.First();
|
|
207 |
RemoveString(cs);
|
|
208 |
delete cs;
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
void CCommChatter::StartTimer(const TTimeIntervalMicroSeconds32& aTimeout)
|
|
213 |
/**
|
|
214 |
Starts timer.
|
|
215 |
*/
|
|
216 |
{
|
|
217 |
|
|
218 |
if (IsActive())
|
|
219 |
Cancel();
|
|
220 |
After(aTimeout);
|
|
221 |
}
|
|
222 |
|
|
223 |
void CCommChatter::StopTimer()
|
|
224 |
/**
|
|
225 |
Stops timer.
|
|
226 |
*/
|
|
227 |
{
|
|
228 |
Cancel();
|
|
229 |
}
|
|
230 |
|
|
231 |
//
|
|
232 |
// CCommChatString definitions
|
|
233 |
//
|
|
234 |
|
|
235 |
CCommChatString* CCommChatString::NewL(const TDesC8& aDes,TBool aIsFolded)
|
|
236 |
/**
|
|
237 |
2 phased constructor for CCommChatString, first phase.
|
|
238 |
|
|
239 |
@param aDes a pointer to chat notifier.
|
|
240 |
@param aIsFolded is buffer size for this object.
|
|
241 |
@exception Leaves if ConstructL() leaves, or not enough memory is available.
|
|
242 |
@return a new CCommChatString object.
|
|
243 |
*/
|
|
244 |
{
|
|
245 |
CCommChatString* cs=new (ELeave) CCommChatString;
|
|
246 |
CleanupStack::PushL(cs);
|
|
247 |
cs->ConstructL(aDes,aIsFolded);
|
|
248 |
CleanupStack::Pop();
|
|
249 |
return cs;
|
|
250 |
}
|
|
251 |
|
|
252 |
CCommChatString::CCommChatString()
|
|
253 |
/**
|
|
254 |
Private constructor for CCommChatString, used in the first phase of construction.
|
|
255 |
*/
|
|
256 |
{}
|
|
257 |
|
|
258 |
void CCommChatString::ConstructL(const TDesC8& aDes,TBool aIsFolded)
|
|
259 |
/**
|
|
260 |
Instantiates member variables.
|
|
261 |
*/
|
|
262 |
{
|
|
263 |
__ASSERT_ALWAYS(aDes.Length()>0, NetDialPanic(ENullCommChatString));
|
|
264 |
iIsFolded=aIsFolded;
|
|
265 |
iString=(TText8*)User::AllocL(aDes.Length());
|
|
266 |
iLastChar=(iString+aDes.Length())-1;
|
|
267 |
Mem::Copy(iString, (TText8*)aDes.Ptr(), aDes.Length());
|
|
268 |
}
|
|
269 |
|
|
270 |
CCommChatString::~CCommChatString()
|
|
271 |
/**
|
|
272 |
Destructor.
|
|
273 |
Deletes allocations/objects.
|
|
274 |
*/
|
|
275 |
{
|
|
276 |
User::Free(iString);
|
|
277 |
}
|