24
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Sony Ericsson Mobile Communications AB
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Sony Ericsson Mobile Communications AB - initial contribution.
|
|
11 |
* Nokia Corporation - additional changes.
|
|
12 |
*
|
|
13 |
* Contributors:
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
* Implements the Enhanced SMS Predefined and User Defined sound IE.
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
|
|
21 |
/**
|
|
22 |
* @file
|
|
23 |
*
|
|
24 |
* Implements CEMSPreDefSoundIE and CEmsSoundIE classes
|
|
25 |
*/
|
|
26 |
|
|
27 |
#include <emssoundie.h>
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
EXPORT_C CEmsPreDefSoundIE* CEmsPreDefSoundIE::NewL(TPredefinedSound aSound)
|
|
32 |
/**
|
|
33 |
* @capability None
|
|
34 |
*/
|
|
35 |
{
|
|
36 |
if(aSound > EChordLow)User::Leave(KErrArgument);
|
|
37 |
CEmsPreDefSoundIE* self = new (ELeave) CEmsPreDefSoundIE();
|
|
38 |
CleanupStack::PushL(self);
|
|
39 |
self->ConstructL(aSound);
|
|
40 |
CleanupStack::Pop(self);
|
|
41 |
return self;
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
EXPORT_C CEmsInformationElement* CEmsPreDefSoundIE::DuplicateL() const
|
|
46 |
/**
|
|
47 |
* @capability None
|
|
48 |
*/
|
|
49 |
{
|
|
50 |
CEmsPreDefSoundIE* copy = new (ELeave) CEmsPreDefSoundIE();
|
|
51 |
CleanupStack::PushL(copy);
|
|
52 |
copy->CopyL(*this);
|
|
53 |
CleanupStack::Pop(copy);
|
|
54 |
return copy;
|
|
55 |
}
|
|
56 |
|
|
57 |
EXPORT_C CEmsPreDefSoundIE::TPredefinedSound CEmsPreDefSoundIE::PredefinedSound() const
|
|
58 |
/**
|
|
59 |
* @capability None
|
|
60 |
*/
|
|
61 |
{
|
|
62 |
return iSound;
|
|
63 |
}
|
|
64 |
|
|
65 |
|
|
66 |
CEmsPreDefSoundIE::CEmsPreDefSoundIE(): CEmsInformationElement(CSmsInformationElement::ESmsEnhancedPredefinedSound){iEncodedBodyLength=1;}
|
|
67 |
|
|
68 |
void CEmsPreDefSoundIE::ConstructL(TPredefinedSound aSound)
|
|
69 |
{
|
|
70 |
iSound = aSound;
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
EXPORT_C void CEmsPreDefSoundIE::CopyL(const CEmsPreDefSoundIE& aSrc)
|
|
75 |
/**
|
|
76 |
* @capability None
|
|
77 |
*/
|
|
78 |
{
|
|
79 |
CEmsInformationElement::CopyL(aSrc);
|
|
80 |
iSound = aSrc.iSound;
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Encodes the information element into its raw format. (no IE id)
|
|
85 |
*
|
|
86 |
* @param aPtr the buffer to be used which is to contain the data
|
|
87 |
* @param TBool boolean to indicate if it is for serialisation or encoding
|
|
88 |
*/
|
|
89 |
void CEmsPreDefSoundIE::EncodeBodyL(TPtr8 aPtr, TBool) const
|
|
90 |
{
|
|
91 |
aPtr.Append(static_cast<TUint8>(iSound));
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Decodes the raw data out of an information element into this class.
|
|
97 |
*
|
|
98 |
* @param aPtr The raw predefined animation data
|
|
99 |
* @param TBool boolean to indicate if it is from serialisation
|
|
100 |
* @leave KErrCorrupt If the size of the data does not match what is expected.
|
|
101 |
*/
|
|
102 |
void CEmsPreDefSoundIE::DecodeBodyL(const TPtrC8 aPtr, TBool)
|
|
103 |
{
|
|
104 |
__ASSERT_ALWAYS( aPtr.Length()==1, User::Leave(KErrCorrupt));
|
|
105 |
iSound = static_cast<TPredefinedSound>(aPtr[0]);
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
CEmsSoundIE* CEmsSoundIE::NewL()
|
|
110 |
{
|
|
111 |
CEmsSoundIE* self = new (ELeave) CEmsSoundIE();
|
|
112 |
return self;
|
|
113 |
}
|
|
114 |
|
|
115 |
EXPORT_C CEmsSoundIE* CEmsSoundIE::NewL(const TDesC8& aMelody)
|
|
116 |
/**
|
|
117 |
* @capability None
|
|
118 |
*/
|
|
119 |
{
|
|
120 |
CEmsSoundIE* self = new (ELeave) CEmsSoundIE();
|
|
121 |
CleanupStack::PushL(self);
|
|
122 |
self->ConstructL(aMelody);
|
|
123 |
CleanupStack::Pop(self);
|
|
124 |
return self;
|
|
125 |
}
|
|
126 |
|
|
127 |
EXPORT_C CEmsInformationElement* CEmsSoundIE::DuplicateL() const
|
|
128 |
/**
|
|
129 |
* @capability None
|
|
130 |
*/
|
|
131 |
{
|
|
132 |
CEmsSoundIE* copy = new (ELeave) CEmsSoundIE();
|
|
133 |
CleanupStack::PushL(copy);
|
|
134 |
copy->CopyL(*this);
|
|
135 |
CleanupStack::Pop(copy);
|
|
136 |
return copy;
|
|
137 |
}
|
|
138 |
|
|
139 |
CEmsSoundIE::CEmsSoundIE() : CEmsInformationElement(CSmsInformationElement::ESmsEnhancedUserDefinedSound){}
|
|
140 |
|
|
141 |
|
|
142 |
void CEmsSoundIE::ConstructL(const TDesC8& aMelody)
|
|
143 |
{
|
|
144 |
__ASSERT_ALWAYS(aMelody.Length()<=EMaxSoundLength, User::Leave(KErrCorrupt));
|
|
145 |
iMelody = aMelody.AllocL();
|
|
146 |
iEncodedBodyLength=iMelody->Length();
|
|
147 |
}
|
|
148 |
|
|
149 |
EXPORT_C void CEmsSoundIE::CopyL(const CEmsSoundIE& aSrc)
|
|
150 |
/**
|
|
151 |
* @capability None
|
|
152 |
*/
|
|
153 |
{
|
|
154 |
Reset();
|
|
155 |
CEmsInformationElement::CopyL(aSrc);
|
|
156 |
__ASSERT_ALWAYS(aSrc.iMelody, User::Leave(KErrCorrupt));
|
|
157 |
iMelody = aSrc.iMelody->AllocL();
|
|
158 |
}
|
|
159 |
|
|
160 |
EXPORT_C const HBufC8* CEmsSoundIE::Melody() const
|
|
161 |
/**
|
|
162 |
* @capability None
|
|
163 |
*/
|
|
164 |
{
|
|
165 |
return iMelody;
|
|
166 |
}
|
|
167 |
|
|
168 |
/**
|
|
169 |
* Encodes the information element into its raw format. (no IE id)
|
|
170 |
*
|
|
171 |
* @param aPtr the buffer to be used which is to contain the data
|
|
172 |
* @param TBool boolean to indicate if it is for serialisation or encoding
|
|
173 |
* @leave KErrCorrupt If the melody has not been defined.
|
|
174 |
*/
|
|
175 |
void CEmsSoundIE::EncodeBodyL(TPtr8 aPtr, TBool) const
|
|
176 |
{
|
|
177 |
__ASSERT_ALWAYS(iMelody!=NULL, User::Leave(KErrCorrupt));
|
|
178 |
aPtr.Append(*iMelody);
|
|
179 |
}
|
|
180 |
|
|
181 |
/**
|
|
182 |
* Decodes the raw data out of an information element into this class.
|
|
183 |
*
|
|
184 |
* @param aPtr The raw predefined animation data
|
|
185 |
* @param TBool boolean to indicate if it is from serialisation
|
|
186 |
* @leave KErrCorrupt If the size of the data does not match what is expected.
|
|
187 |
*/
|
|
188 |
void CEmsSoundIE::DecodeBodyL(const TPtrC8 aPtr, TBool)
|
|
189 |
{
|
|
190 |
__ASSERT_ALWAYS(aPtr.Length()<=EMaxSoundLength, User::Leave(KErrCorrupt));
|
|
191 |
|
|
192 |
Reset();
|
|
193 |
iMelody = aPtr.AllocL();
|
|
194 |
}
|
|
195 |
|
|
196 |
EXPORT_C CEmsSoundIE::~CEmsSoundIE()
|
|
197 |
/**
|
|
198 |
* @capability None
|
|
199 |
*/
|
|
200 |
{
|
|
201 |
Reset();
|
|
202 |
}
|
|
203 |
|
|
204 |
void CEmsSoundIE::Reset()
|
|
205 |
{
|
|
206 |
delete iMelody;
|
|
207 |
iMelody = NULL;
|
|
208 |
}
|