smsprotocols/smsstack/gsmu/src/gsmusar.cpp
branchRCL_3
changeset 65 630d2f34d719
parent 0 3553901f7fa8
child 66 07a122eea281
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    17 
    17 
    18 /**
    18 /**
    19  @file
    19  @file
    20 */
    20 */
    21 
    21 
       
    22 
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "gsmusarTraces.h"
       
    26 #endif
       
    27 
    22 #include "gsmusar.h"
    28 #include "gsmusar.h"
    23 #include "Gsmumain.h"
    29 #include "Gsmumain.h"
    24 
    30 
    25 //
    31 //
    26 // CSmsBufferSegmenter - segments and reassembles (unpacked) data to and from CSmsBufferBase
    32 // CSmsBufferSegmenter - segments and reassembles (unpacked) data to and from CSmsBufferBase
    36  *  
    42  *  
    37  *  @capability None
    43  *  @capability None
    38  */
    44  */
    39 EXPORT_C CSmsBufferSegmenter* CSmsBufferSegmenter::NewLC(CSmsAlphabetConverter& aAlphabetConverter,const CSmsBufferBase& aBuffer,TInt aSegmentSize)
    45 EXPORT_C CSmsBufferSegmenter* CSmsBufferSegmenter::NewLC(CSmsAlphabetConverter& aAlphabetConverter,const CSmsBufferBase& aBuffer,TInt aSegmentSize)
    40 	{
    46 	{
    41 	LOGGSMU1("CSmsBufferSegmenter::NewLC()");
    47 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CSMSBUFFERSEGMENTER_NEWLC_1, "CSmsBufferSegmenter::NewLC()");
    42 	
    48 	
    43 	CSmsBufferSegmenter* segmenter=new(ELeave) CSmsBufferSegmenter(aAlphabetConverter,aBuffer,aSegmentSize);
    49 	CSmsBufferSegmenter* segmenter=new(ELeave) CSmsBufferSegmenter(aAlphabetConverter,aBuffer,aSegmentSize);
    44 	CleanupStack::PushL(segmenter);
    50 	CleanupStack::PushL(segmenter);
    45 	segmenter->ConstructL();
    51 	segmenter->ConstructL();
    46 	return segmenter;
    52 	return segmenter;
    57 /**
    63 /**
    58  *  2nd phase of constructor. Esures we have an initial buffer.
    64  *  2nd phase of constructor. Esures we have an initial buffer.
    59  */
    65  */
    60 void CSmsBufferSegmenter::ConstructL()
    66 void CSmsBufferSegmenter::ConstructL()
    61 	{
    67 	{
    62 	LOGGSMU1("CSmsBufferSegmenter::ConstructL()");
    68 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSBUFFERSEGMENTER_CONSTRUCTL_1, "CSmsBufferSegmenter::ConstructL()");
    63 
    69 
    64 	iConvertedBuffer=HBufC8::NewMaxL(iSegmentSize);
    70 	iConvertedBuffer=HBufC8::NewMaxL(iSegmentSize);
    65 	iConvertedBufferPtr.Set((TUint8*)iConvertedBuffer->Des().Ptr(),0,iConvertedBuffer->Length());
    71 	iConvertedBufferPtr.Set((TUint8*)iConvertedBuffer->Des().Ptr(),0,iConvertedBuffer->Length());
    66 	} // CSmsBufferSegmenter::ConstructL
    72 	} // CSmsBufferSegmenter::ConstructL
    67 
    73 
    80 /**
    86 /**
    81  *  Resets the converted buffer
    87  *  Resets the converted buffer
    82  */
    88  */
    83 void CSmsBufferSegmenter::Reset()
    89 void CSmsBufferSegmenter::Reset()
    84 	{
    90 	{
    85 	LOGGSMU1("CSmsBufferSegmenter::Reset()");
    91 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSBUFFERSEGMENTER_RESET_1, "CSmsBufferSegmenter::Reset()");
    86 
    92 
    87 	iConvertedBufferPtr.Zero();
    93 	iConvertedBufferPtr.Zero();
    88 	iElementsExtracted=0;
    94 	iElementsExtracted=0;
    89 	} // CSmsBufferSegmenter::Reset
    95 	} // CSmsBufferSegmenter::Reset
    90 
    96 
   102  */
   108  */
   103 EXPORT_C TBool CSmsBufferSegmenter::SegmentNextL(TDes8& aSegmentBuffer,
   109 EXPORT_C TBool CSmsBufferSegmenter::SegmentNextL(TDes8& aSegmentBuffer,
   104 		                                         TInt& aUnconvertedChars, TInt& aDowngradedChars,
   110 		                                         TInt& aUnconvertedChars, TInt& aDowngradedChars,
   105 		                                         TSmsEncoding aEncoding)
   111 		                                         TSmsEncoding aEncoding)
   106 	{
   112 	{
   107 	LOGGSMU2("CSmsBufferSegmenter::SegmentNextL(): iSegmentSize=%d", iSegmentSize);
   113 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CSMSBUFFERSEGMENTER_SEGMENTNEXTL_1, "CSmsBufferSegmenter::SegmentNextL(): iSegmentSize=%d", iSegmentSize);
   108 
   114 
   109 	TBool  ret = DoSegmentNextL(aSegmentBuffer, iSegmentSize,
   115 	TBool  ret = DoSegmentNextL(aSegmentBuffer, iSegmentSize,
   110 			                    aUnconvertedChars, aDowngradedChars,
   116 			                    aUnconvertedChars, aDowngradedChars,
   111 			                    aEncoding);
   117 			                    aEncoding);
   112 	LOGGSMU2("CSmsBufferSegmenter::SegmentNextL() returns %d ", ret);
   118 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CSMSBUFFERSEGMENTER_SEGMENTNEXTL_2, "CSmsBufferSegmenter::SegmentNextL() returns %d ", ret);
   113 
   119 
   114 	return ret;
   120 	return ret;
   115 	} // CSmsBufferSegmenter::SegmentNextL
   121 	} // CSmsBufferSegmenter::SegmentNextL
   116 
   122 
   117 
   123 
   122 // Extracts a "native" segment from the SMS buffer, converts to the required
   128 // Extracts a "native" segment from the SMS buffer, converts to the required
   123 // character set and breaks off the next segment of required size.
   129 // character set and breaks off the next segment of required size.
   124 // Returns true if this was the last segment
   130 // Returns true if this was the last segment
   125 //
   131 //
   126 	{
   132 	{
   127 	LOGGSMU2("CSmsBufferSegmenter::DoSegmentNextL(): aSegmentSize=%d", aSegmentSize);
   133 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSBUFFERSEGMENTER_DOSEGMENTNEXTL_1, "CSmsBufferSegmenter::DoSegmentNextL(): aSegmentSize=%d", aSegmentSize);
   128 
   134 
   129 	__ASSERT_ALWAYS(aSegmentSize>0,Panic(KGsmuPanicIllegalSegmentSize));
   135 	__ASSERT_ALWAYS(aSegmentSize>0,Panic(KGsmuPanicIllegalSegmentSize));
   130 	__ASSERT_ALWAYS(aSegmentBuffer.MaxLength()>=aSegmentSize,Panic(KGsmuPanicSegmentBufferTooSmall));
   136 	__ASSERT_ALWAYS(aSegmentBuffer.MaxLength()>=aSegmentSize,Panic(KGsmuPanicSegmentBufferTooSmall));
   131 
   137 
   132 	// Extract from buffer until we have enough chars for a segment or we're at the end
   138 	// Extract from buffer until we have enough chars for a segment or we're at the end
   161 	} // CSmsBufferSegmenter::DoSegmentNextL
   167 	} // CSmsBufferSegmenter::DoSegmentNextL
   162 
   168 
   163 
   169 
   164 TBool CSmsBufferSegmenter::MoreL()
   170 TBool CSmsBufferSegmenter::MoreL()
   165 	{
   171 	{
   166 	LOGGSMU1("CSmsBufferSegmenter::MoreL()");
   172 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSBUFFERSEGMENTER_MOREL_1, "CSmsBufferSegmenter::MoreL()");
   167 
   173 
   168 	if ((iElementsExtracted>=iSmsBuffer.Length())&&(iConvertedBufferPtr.Length()==0))
   174 	if ((iElementsExtracted>=iSmsBuffer.Length())&&(iConvertedBufferPtr.Length()==0))
   169 		{
   175 		{
   170 		if (iAlphabetConverter.UnconvertedNativeCharacters().Length()>0)
   176 		if (iAlphabetConverter.UnconvertedNativeCharacters().Length()>0)
   171 			{
   177 			{
   188  *  
   194  *  
   189  *  @capability None
   195  *  @capability None
   190  */
   196  */
   191 EXPORT_C TInt CSmsBufferSegmenter::TotalConvertedLengthL(TSmsEncoding aEncoding)
   197 EXPORT_C TInt CSmsBufferSegmenter::TotalConvertedLengthL(TSmsEncoding aEncoding)
   192 	{
   198 	{
   193 	LOGGSMU2("CSmsBufferSegmenter::TotalConvertedLengthL(): aEncoding=%d", aEncoding);
   199 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CSMSBUFFERSEGMENTER_TOTALCONVERTEDLENGTHL_1, "CSmsBufferSegmenter::TotalConvertedLengthL(): aEncoding=%d", aEncoding);
   194 	
   200 	
   195 	// Check for shortcut
   201 	// Check for shortcut
   196 	CSmsAlphabetConverter::TSmsAlphabetConversionProperties conversionProperties;
   202 	CSmsAlphabetConverter::TSmsAlphabetConversionProperties conversionProperties;
   197 	iAlphabetConverter.ConversionPropertiesL(conversionProperties);
   203 	iAlphabetConverter.ConversionPropertiesL(conversionProperties);
   198 	if (conversionProperties.iWidthConversion==CSmsAlphabetConverter::ESmsAlphabetWidthConversionFixed)
   204 	if (conversionProperties.iWidthConversion==CSmsAlphabetConverter::ESmsAlphabetWidthConversionFixed)
   227 
   233 
   228 
   234 
   229 TSmsEncoding CSmsBufferSegmenter::FindBestAlternativeEncodingL(TSmsEncoding aSuggestedEncoding,
   235 TSmsEncoding CSmsBufferSegmenter::FindBestAlternativeEncodingL(TSmsEncoding aSuggestedEncoding,
   230 									  			       		   TInt aMaxBodyLength) const
   236 									  			       		   TInt aMaxBodyLength) const
   231 	{
   237 	{
   232 	LOGGSMU3("CSmsBufferSegmenter::FindBestAlternativeEncodingL(): aSuggestedEncoding=%d, aMaxBodyLength=%d",
   238 	OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSBUFFERSEGMENTER_FINDBESTALTERNATIVEENCODINGL_1, "CSmsBufferSegmenter::FindBestAlternativeEncodingL(): aSuggestedEncoding=%d, aMaxBodyLength=%d",aSuggestedEncoding, aMaxBodyLength);
   233 			 aSuggestedEncoding, aMaxBodyLength);
       
   234 
   239 
   235 	TSmsEncoding  encodingToUse = ESmsEncodingNone;
   240 	TSmsEncoding  encodingToUse = ESmsEncodingNone;
   236 	
   241 	
   237 	//
   242 	//
   238 	// If this is not 7bit or the alternative encoding is not set then do
   243 	// If this is not 7bit or the alternative encoding is not set then do
   264 /**
   269 /**
   265  *  Ensures the segmentation buffer is of the specified length
   270  *  Ensures the segmentation buffer is of the specified length
   266  */
   271  */
   267 void CSmsBufferSegmenter::CheckConvertedBufferAllocL(TInt aMaxLength)
   272 void CSmsBufferSegmenter::CheckConvertedBufferAllocL(TInt aMaxLength)
   268 	{
   273 	{
   269 	LOGGSMU2("CSmsBufferSegmenter::CheckConvertedBufferAllocL(): aMaxLength=%d",
   274 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSBUFFERSEGMENTER_CHECKCONVERTEDBUFFERALLOCL_1, "CSmsBufferSegmenter::CheckConvertedBufferAllocL(): aMaxLength=%d",aMaxLength);
   270 			 aMaxLength);
       
   271 
   275 
   272 	if (iConvertedBuffer->Length()<aMaxLength)
   276 	if (iConvertedBuffer->Length()<aMaxLength)
   273 		{
   277 		{
   274 		iConvertedBuffer=iConvertedBuffer->ReAllocL(aMaxLength);
   278 		iConvertedBuffer=iConvertedBuffer->ReAllocL(aMaxLength);
   275 		iConvertedBuffer->Des().SetLength(aMaxLength);
   279 		iConvertedBuffer->Des().SetLength(aMaxLength);
   282  *  Determines the number of converted elements that should be returned in the
   286  *  Determines the number of converted elements that should be returned in the
   283  *  segment - called from DoSegmentNextL
   287  *  segment - called from DoSegmentNextL
   284  */
   288  */
   285 TInt CSmsBufferSegmenter::ElementsToReturnFromConvertedBufferL(TInt aSegmentSize)
   289 TInt CSmsBufferSegmenter::ElementsToReturnFromConvertedBufferL(TInt aSegmentSize)
   286 	{
   290 	{
   287 	LOGGSMU2("CSmsBufferSegmenter::CheckConvertedBufferAllocL(): aSegmentSize=%d",
   291 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSBUFFERSEGMENTER_ELEMENTSTORETURNFROMCONVERTEDBUFFERL_1, "CSmsBufferSegmenter::CheckConvertedBufferAllocL(): aSegmentSize=%d",aSegmentSize);
   288 			 aSegmentSize);
       
   289 
   292 
   290 	TInt elementCount=Min(aSegmentSize,iConvertedBufferPtr.Length());
   293 	TInt elementCount=Min(aSegmentSize,iConvertedBufferPtr.Length());
   291 	if (iAlphabetConverter.Alphabet()==TSmsDataCodingScheme::ESmsAlphabet7Bit)
   294 	if (iAlphabetConverter.Alphabet()==TSmsDataCodingScheme::ESmsAlphabet7Bit)
   292 		{
   295 		{
   293 		// For 7-bit, don't break an extended character across a segment
   296 		// For 7-bit, don't break an extended character across a segment
   306 /**
   309 /**
   307  *  @capability None
   310  *  @capability None
   308  */
   311  */
   309 EXPORT_C CSmsEMSBufferSegmenter* CSmsEMSBufferSegmenter::NewLC(CSmsAlphabetConverter& aAlphabetConverter,const CSmsBufferBase& aBuffer, TInt aSegmentSize)
   312 EXPORT_C CSmsEMSBufferSegmenter* CSmsEMSBufferSegmenter::NewLC(CSmsAlphabetConverter& aAlphabetConverter,const CSmsBufferBase& aBuffer, TInt aSegmentSize)
   310 	{
   313 	{
   311 	LOGGSMU2("CSmsBufferSegmenter::NewLC(): aSegmentSize=%d", aSegmentSize);
   314 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CSMSEMSBUFFERSEGMENTER_NEWLC_1, "CSmsBufferSegmenter::NewLC(): aSegmentSize=%d", aSegmentSize);
   312 
   315 
   313 	CSmsEMSBufferSegmenter* self = new (ELeave) CSmsEMSBufferSegmenter(aAlphabetConverter, aBuffer,  aSegmentSize);
   316 	CSmsEMSBufferSegmenter* self = new (ELeave) CSmsEMSBufferSegmenter(aAlphabetConverter, aBuffer,  aSegmentSize);
   314 	CleanupStack::PushL(self);
   317 	CleanupStack::PushL(self);
   315 	self->ConstructL();
   318 	self->ConstructL();
   316 	return self;
   319 	return self;
   335  */
   338  */
   336 EXPORT_C TBool CSmsEMSBufferSegmenter::SegmentNextL(TDes8& aSegmentBuffer, TInt aSegmentSize,
   339 EXPORT_C TBool CSmsEMSBufferSegmenter::SegmentNextL(TDes8& aSegmentBuffer, TInt aSegmentSize,
   337 		                                            TInt& aUnconvertedChars, TInt& aDowngradedChars,
   340 		                                            TInt& aUnconvertedChars, TInt& aDowngradedChars,
   338 		                                            TSmsEncoding aEncoding)
   341 		                                            TSmsEncoding aEncoding)
   339 	{
   342 	{
   340 	LOGGSMU2("CSmsEMSBufferSegmenter::SegmentNext(): aSegmentSize=%d", aSegmentSize);
   343 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CSMSEMSBUFFERSEGMENTER_SEGMENTNEXTL_1, "CSmsEMSBufferSegmenter::SegmentNext(): aSegmentSize=%d", aSegmentSize);
   341 
   344 
   342 	TBool ret=DoSegmentNextL(aSegmentBuffer, aSegmentSize, aUnconvertedChars, aDowngradedChars,
   345 	TBool ret=DoSegmentNextL(aSegmentBuffer, aSegmentSize, aUnconvertedChars, aDowngradedChars,
   343 							 aEncoding);
   346 							 aEncoding);
   344 
   347 
   345 	LOGGSMU2("CSmsEMSBufferSegmenter::SegmentNext() returns %d ", ret);
   348 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, CSMSEMSBUFFERSEGMENTER_SEGMENTNEXTL_2, "CSmsEMSBufferSegmenter::SegmentNext() returns %d ", ret);
   346 
   349 
   347 	return ret;
   350 	return ret;
   348 	} // CSmsEMSBufferSegmenter::SegmentNextL
   351 	} // CSmsEMSBufferSegmenter::SegmentNextL
   349 
   352 
   350 
   353 
   359  */
   362  */
   360 TInt CSmsEMSBufferSegmenter::SegmentL(TDes8& aSegmentBuffer, TInt aNativeChars, TInt aSegmentMax,
   363 TInt CSmsEMSBufferSegmenter::SegmentL(TDes8& aSegmentBuffer, TInt aNativeChars, TInt aSegmentMax,
   361 		                              TInt& aUnconvertedChars, TInt& aDowngradedChars,
   364 		                              TInt& aUnconvertedChars, TInt& aDowngradedChars,
   362 		                              TSmsEncoding aEncoding)
   365 		                              TSmsEncoding aEncoding)
   363 	{
   366 	{
   364 	LOGGSMU3("CSmsEMSBufferSegmenter::SegmentL(): aNativeChars=%d, aSegmentMax=%d",
   367 	OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSMSEMSBUFFERSEGMENTER_SEGMENTL_1, "CSmsEMSBufferSegmenter::SegmentL(): aNativeChars=%d, aSegmentMax=%d",aNativeChars, aSegmentMax);
   365 			 aNativeChars, aSegmentMax);
       
   366 
   368 
   367 	__ASSERT_ALWAYS(iConvertedBufferPtr.Length()==0, User::Leave(KGsmuPanicBufferNotReset));
   369 	__ASSERT_ALWAYS(iConvertedBufferPtr.Length()==0, User::Leave(KGsmuPanicBufferNotReset));
   368 	__ASSERT_ALWAYS(aNativeChars>0,User::Leave(KGsmuPanicIllegalSegmentSize));
   370 	__ASSERT_ALWAYS(aNativeChars>0,User::Leave(KGsmuPanicIllegalSegmentSize));
   369 	__ASSERT_ALWAYS(aSegmentMax>0,User::Leave(KGsmuPanicIllegalSegmentSize));
   371 	__ASSERT_ALWAYS(aSegmentMax>0,User::Leave(KGsmuPanicIllegalSegmentSize));
   370 	__ASSERT_ALWAYS(aSegmentBuffer.MaxLength()>=aNativeChars,User::Leave(KGsmuPanicSegmentBufferTooSmall));
   372 	__ASSERT_ALWAYS(aSegmentBuffer.MaxLength()>=aNativeChars,User::Leave(KGsmuPanicSegmentBufferTooSmall));
   428  *  @capability None
   430  *  @capability None
   429  */
   431  */
   430 EXPORT_C void TSmsBufferReassembler::ReassembleNextL(const TDesC8& aSegmentBuffer,
   432 EXPORT_C void TSmsBufferReassembler::ReassembleNextL(const TDesC8& aSegmentBuffer,
   431 													 TSmsEncoding aEncoding,TBool aIsLast)
   433 													 TSmsEncoding aEncoding,TBool aIsLast)
   432 	{
   434 	{
   433 	LOGGSMU3("TSmsBufferReassembler::ReassembleNextL(): aEncoding=%d aIsLast=%d",
   435 	OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_BORDER, TSMSBUFFERREASSEMBLER_REASSEMBLENEXTL_1, "TSmsBufferReassembler::ReassembleNextL(): aEncoding=%d aIsLast=%d",aEncoding, aIsLast);
   434 			 aEncoding, aIsLast);
       
   435 
   436 
   436 	TPtrC nativeChars=iAlphabetConverter.ConvertToNativeL(aSegmentBuffer, aEncoding);
   437 	TPtrC nativeChars=iAlphabetConverter.ConvertToNativeL(aSegmentBuffer, aEncoding);
   437 	iSmsBuffer.InsertL(iSmsBuffer.Length(),nativeChars);
   438 	iSmsBuffer.InsertL(iSmsBuffer.Length(),nativeChars);
   438 	if ((aIsLast)&&(iAlphabetConverter.UnconvertedUDElements().Length()>0))
   439 	if ((aIsLast)&&(iAlphabetConverter.UnconvertedUDElements().Length()>0))
   439 		{
   440 		{