cbs/CbsServer/ServerSrc/CCbsMessage.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of CCbsMessage class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CbsServerPanic.h"
       
    21 #include "CCbsMessage.h"
       
    22 #include "CbsLogger.h"
       
    23 
       
    24 
       
    25 // ================= MEMBER FUNCTIONS =======================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CCbsMessage::CCbsMessage
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CCbsMessage::CCbsMessage()
       
    34     {
       
    35     }
       
    36 
       
    37 // Destructor    
       
    38 CCbsMessage::~CCbsMessage()
       
    39     {
       
    40     CBSLOGSTRING("CBSSERVER: >>> CCbsMessage::~CCbsMessage()");
       
    41     CBSLOGSTRING("CBSSERVER: <<< CCbsMessage::~CCbsMessage()");
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CCbsMessage::Alphabet
       
    46 // Returns the alphabet set of this message.
       
    47 // Decides the alphabet set of this message by examining DCS field. 
       
    48 // Note that DCS value "unspecified" isn't used anymore.
       
    49 // All messages are considered to have "default" representation.
       
    50 // (other items were commented in a header).
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 TCbsRecAlphabet CCbsMessage::Alphabet() const
       
    54     {
       
    55     CBSLOGSTRING("CBSSERVER: >>> CCbsMessage::Alphabet()");
       
    56     CBSLOGSTRING2("CBSSERVER: CCbsMessage::Alphabet(): iDCS: %d", iDCS );
       
    57     
       
    58     TCbsRecAlphabet alphabet( ECbsRecAlphabetUnspecified );   
       
    59 
       
    60     // Check for Message preceded by language indication/UCS2 and
       
    61     // General Data Coding Indication/UCS2
       
    62     if ( 
       
    63         ( iDCS & DCS_MASK_LANGUAGE_INDICATION_PRECEDES ) == DCS_MPLI_UCS2 || 
       
    64         ( iDCS & DCS_MASK_GENERAL_DATA_CODING_INDICATION ) == DCS_GDCI_UCS2 )
       
    65         {
       
    66         alphabet = ECbsRecAlphabetUCS2;
       
    67         }
       
    68     // Check for 8-bit DCSs
       
    69     else if ( 
       
    70         ( iDCS & DCS_MASK_GENERAL_DATA_CODING_INDICATION ) == DCS_GDCI_8BIT ||
       
    71         ( iDCS & DCS_MASK_MESSAGE_HANDLING )== DCS_DCMH_8BIT ||
       
    72         ( iDCS & DCS_MASK_UDH ) == DCS_UDH_8BIT )
       
    73         {
       
    74         alphabet = ECbsRecAlphabet8bit;
       
    75         }
       
    76      // Else assume that alphabet is default
       
    77     else
       
    78         {
       
    79         alphabet = ECbsRecAlphabetDefault;
       
    80         }
       
    81 
       
    82     CBSLOGSTRING("CBSSERVER: <<< CCbsMessage::Alphabet(), returning alphabet.");
       
    83     return alphabet;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CCbsMessage::AppendContent
       
    88 // Appends another message's content to this message's content.
       
    89 // (other items were commented in a header).
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CCbsMessage::AppendContent( 
       
    93     const TDesC& aMsg )
       
    94     {
       
    95     iMessage->Des().Append( aMsg );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CCbsMessage::AppendContent8
       
   100 // Appends another message's content to this message's content.
       
   101 // (other items were commented in a header).
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CCbsMessage::AppendContent8( 
       
   105     const TDesC8& aMsg )
       
   106     {
       
   107     iMessage8->Des().Append( aMsg );
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CCbsMessage::CellId
       
   112 // Returns identifier of the cell in which the phone was when this  message was received.
       
   113 // (other items were commented in a header).
       
   114 // -----------------------------------------------------------------------------
       
   115 //  
       
   116 TUint CCbsMessage::CellId() const
       
   117     {
       
   118     return iLocationArea.iCellId;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CCbsMessage::Contents
       
   123 // Returns a pointer descriptor to the Unicode contents of the message.
       
   124 // (other items were commented in a header).
       
   125 // -----------------------------------------------------------------------------
       
   126 // 
       
   127 const TDesC& CCbsMessage::Contents() const
       
   128     {
       
   129     __ASSERT_DEBUG( iMessage != 0, CbsServerPanic( ECbsMsgRepUnprepared ) );
       
   130     return *iMessage;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CCbsMessage::Contents8
       
   135 // Returns a pointer descriptor to 8-bit descriptor representation
       
   136 // of the message body. 
       
   137 // (other items were commented in a header).
       
   138 // -----------------------------------------------------------------------------
       
   139 // 
       
   140 const TDesC8& CCbsMessage::Contents8() const
       
   141     {
       
   142     __ASSERT_DEBUG( iMessage8 != 0, CbsServerPanic( ECbsMsgRepUnprepared ) );
       
   143     return *iMessage8;
       
   144     }
       
   145 
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CCbsMessage::DCS
       
   149 // Returns the Data Coding Scheme of this message page.
       
   150 // Refer to GSM specification 03.38 for details on DCS.
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 // 
       
   154 TCbsRecDCS CCbsMessage::DCS() const
       
   155     {
       
   156     return iDCS;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CCbsMessage::GeographicalScope
       
   161 // Returns the geographical scope of the message.
       
   162 // This is a 16-bit value containing Geographical 
       
   163 // Scope (2 bits), Message Code (10 bits) and Update Number (4 bits).
       
   164 // (other items were commented in a header).
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TCbsRecGeographicalScope CCbsMessage::GeographicalScope() const
       
   168     {
       
   169     TInt gs( Key() >> 14 );
       
   170     if ( gs == KGeographicalScopeCellImmediate || 
       
   171          gs == KGeographicalScopeCellNormal )
       
   172         {
       
   173         return ECbsRecGeographicalScopeCell;
       
   174         }
       
   175     else if ( gs == KGeographicalScopePLMNNormal ) 
       
   176         {
       
   177         return ECbsRecGeographicalScopePLMN;
       
   178         }
       
   179     else
       
   180         {
       
   181         return ECbsRecGeographicalScopeLAC;
       
   182         }
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CCbsMessage::GetPLMN
       
   187 // Returns operator information.
       
   188 // On return, aNetworkInfo contains identity of the network
       
   189 // in which the phone was when this message was received.
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 // 
       
   193 void CCbsMessage::GetPLMN( 
       
   194     RMobilePhone::TMobilePhoneNetworkInfoV1& aNetworkInfo ) const
       
   195     {
       
   196     aNetworkInfo.iCountryCode = iNetworkInfo.iCountryCode;
       
   197     aNetworkInfo.iNetworkId = iNetworkInfo.iNetworkId;
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CCbsMessage::IsChildSubindex
       
   202 // Returns boolean value indicating if this message is a child subindex message.
       
   203 // Child subindex messages have message code 1010101010b and
       
   204 // (other items were commented in a header).
       
   205 // -----------------------------------------------------------------------------
       
   206 // 
       
   207 TBool CCbsMessage::IsChildSubindex() const
       
   208     {
       
   209     return IsIndexMessage() && ( TopicNumber() != 0 );
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CCbsMessage::IsClass0
       
   214 // Returns ETrue, if this message is a Class 0 message according to 
       
   215 // ETSI GSM specification 03.38.
       
   216 // Message is of class 0 if the 6th and 7th bit of Geographical Scope
       
   217 // are both zero.
       
   218 // (other items were commented in a header).
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 TBool CCbsMessage::IsClass0() const
       
   222     {
       
   223     // Examine bits 0, 1, 4, 6 and 7 of DCS.
       
   224     TUint8 class0( DCS() );
       
   225     class0 &= DCS_MASK_CLASS0;
       
   226     // Check Class 0 indication.
       
   227     return class0 == DCS_CLASS0; 
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CCbsMessage::IsCompressed
       
   232 // Returns ETrue, if the message is compressed.
       
   233 // (other items were commented in a header).
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 TBool CCbsMessage::IsCompressed() const
       
   237     {
       
   238     // The CB message is compressed only if the value of DCS is 011xxxxx.
       
   239     return ( TUint8( iDCS >> 5 ) == 3 );
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CCbsMessage::IsIndexMessage
       
   244 // Returns boolean value indicating if this is the index message.  
       
   245 // Index messages have message code 1010101010b.
       
   246 // Refer to GSM specifications to for details.
       
   247 // (other items were commented in a header).
       
   248 // -----------------------------------------------------------------------------
       
   249 // 
       
   250 TBool CCbsMessage::IsIndexMessage() const
       
   251     {
       
   252     return MessageCode() == KIndexMessageCode;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CCbsMessage::Key
       
   257 // Returns the key of the message (serial number).
       
   258 // (other items were commented in a header).
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 TCbsDbMessageKey CCbsMessage::Key() const
       
   262     {
       
   263     return TCbsDbMessageKey( iSerialNumber );
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CCbsMessage::LAC
       
   268 // Returns location area information.
       
   269 // (other items were commented in a header).
       
   270 // -----------------------------------------------------------------------------
       
   271 //  
       
   272 TUint CCbsMessage::LAC() const
       
   273     {
       
   274     return iLocationArea.iLocationAreaCode;
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CCbsMessage::Language
       
   279 // Returns the language specified in this message.
       
   280 // (other items were commented in a header).
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TCbsDbLanguage CCbsMessage::Language() const
       
   284     {
       
   285     __ASSERT_DEBUG( iLanguage != -1, 
       
   286         CbsServerPanic( ECbsLanguageNotResolved ) );
       
   287 
       
   288     return iLanguage;
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CCbsMessage::LanguagePrecedingMessage
       
   293 // Determines and returns the language of this message
       
   294 // based on first two characters of message content.
       
   295 // Assumes that the message content contains language
       
   296 // indication and that the content has been decoded
       
   297 // into UCS-2 representation.
       
   298 // (other items were commented in a header).
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 TCbsDbLanguage CCbsMessage::LanguagePrecedingMessage() const
       
   302     {
       
   303     /// Mapping of ISO639 codes to server internal language representation
       
   304     const TCbsIso639ToLangMapElement KLanguageMap[ KNumberOfLanguageMappings ] = 
       
   305         {
       
   306         TCbsIso639ToLangMapElement( KIso639Danish, ECbsDanish ),
       
   307         TCbsIso639ToLangMapElement( KIso639German, ECbsGerman ),
       
   308         TCbsIso639ToLangMapElement( KIso639Greek, ECbsGreek ),
       
   309         TCbsIso639ToLangMapElement( KIso639English, ECbsEnglish ),
       
   310         TCbsIso639ToLangMapElement( KIso639Spanish, ECbsSpanish ),
       
   311         TCbsIso639ToLangMapElement( KIso639Finnish, ECbsFinnish ),
       
   312         TCbsIso639ToLangMapElement( KIso639French, ECbsFrench ),
       
   313         TCbsIso639ToLangMapElement( KIso639Italian, ECbsItalian ),
       
   314         TCbsIso639ToLangMapElement( KIso639Dutch, ECbsDutch ),
       
   315         TCbsIso639ToLangMapElement( KIso639Norwegian, ECbsNorwegian ),
       
   316         TCbsIso639ToLangMapElement( KIso639Portuguese, ECbsPortuguese ),
       
   317         TCbsIso639ToLangMapElement( KIso639Swedish, ECbsSwedish ),
       
   318         TCbsIso639ToLangMapElement( KIso639Turkish, ECbsTurkish ),
       
   319         TCbsIso639ToLangMapElement( KIso639Hungarian, ECbsHungarian ),
       
   320         TCbsIso639ToLangMapElement( KIso639Polish, ECbsPolish ),
       
   321         TCbsIso639ToLangMapElement( KIso639Czech, ECbsCzech ),
       
   322         TCbsIso639ToLangMapElement( KIso639Hebrew, ECbsHebrew ),
       
   323         TCbsIso639ToLangMapElement( KIso639Arabic, ECbsArabic ),
       
   324         TCbsIso639ToLangMapElement( KIso639Russian, ECbsRussian ),
       
   325         TCbsIso639ToLangMapElement( KIso639Icelandic, ECbsIcelandic )
       
   326         };
       
   327 
       
   328     __ASSERT_DEBUG( iMessage != NULL , CbsServerPanic( ECbsMsgRepUnprepared ) );
       
   329 
       
   330     TPtrC isoCode( 
       
   331         Contents().Left( KLanguageIndicationLengthWithoutCR ) );
       
   332 
       
   333     for ( TInt i( 0 ); i<KNumberOfLanguageMappings; i++ )
       
   334         {
       
   335         TCbsIso639ToLangMapElement element( KLanguageMap[i] );
       
   336         TPtrC code( element.iCode );
       
   337         if ( code == isoCode )
       
   338             {
       
   339             TCbsDbLanguage language( element.iLang );
       
   340             return language;
       
   341             }
       
   342         }
       
   343     return ECbsOther;
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CCbsMessage::LanguageWithDefaultAlphabet
       
   348 // Determines and returns the language of this message
       
   349 // based on DCS value. Assumes that the same DCS value
       
   350 // indicates, that the language can be determined in this
       
   351 // way (and not from message content).
       
   352 // (other items were commented in a header).
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 TCbsDbLanguage CCbsMessage::LanguageWithDefaultAlphabet() const
       
   356     {
       
   357     TCbsDbLanguage language;
       
   358     switch ( iDCS )
       
   359         {
       
   360         // These cases handle DCS values with bits 0000xxxx.
       
   361         // All languages use the default alphabet.
       
   362         case ECbsRecLanguageGerman: 
       
   363             language = ECbsGerman; 
       
   364             break;
       
   365         case ECbsRecLanguageEnglish: 
       
   366             language = ECbsEnglish; 
       
   367             break;
       
   368         case ECbsRecLanguageItalian: 
       
   369             language = ECbsItalian; 
       
   370             break;
       
   371         case ECbsRecLanguageFrench: 
       
   372             language = ECbsFrench; 
       
   373             break;
       
   374         case ECbsRecLanguageSpanish: 
       
   375             language = ECbsSpanish; 
       
   376             break;
       
   377         case ECbsRecLanguageDutch: 
       
   378             language = ECbsDutch; 
       
   379             break;
       
   380         case ECbsRecLanguageSwedish: 
       
   381             language = ECbsSwedish; 
       
   382             break;
       
   383         case ECbsRecLanguageDanish: 
       
   384             language = ECbsDanish; 
       
   385             break;
       
   386         case ECbsRecLanguagePortuguese: 
       
   387             language = ECbsPortuguese; 
       
   388             break;
       
   389         case ECbsRecLanguageFinnish: 
       
   390             language = ECbsFinnish; 
       
   391             break;
       
   392         case ECbsRecLanguageNorwegian: 
       
   393             language = ECbsNorwegian; 
       
   394             break;
       
   395         case ECbsRecLanguageGreek: 
       
   396             language = ECbsGreek; 
       
   397             break;
       
   398         case ECbsRecLanguageTurkish: 
       
   399             language = ECbsTurkish; 
       
   400             break;
       
   401         case ECbsRecLanguageHungarian: 
       
   402             language = ECbsHungarian; 
       
   403             break;
       
   404         case ECbsRecLanguagePolish: 
       
   405             language = ECbsPolish; 
       
   406             break;
       
   407         case ECbsRecLanguageUnspecified: 
       
   408             language = ECbsOther; 
       
   409             break;
       
   410         case ECbsRecLanguageCzech:
       
   411             language = ECbsCzech;
       
   412             break;
       
   413         case ECbsRecLanguageHebrew:
       
   414             language = ECbsHebrew;
       
   415             break;
       
   416         case ECbsRecLanguageArabic:
       
   417             language = ECbsArabic;
       
   418             break;
       
   419         case ECbsRecLanguageRussian:
       
   420             language = ECbsRussian;
       
   421             break;
       
   422         case ECbsRecLanguageIcelandic:
       
   423             language = ECbsIcelandic;
       
   424             break;
       
   425         default:
       
   426             language = ECbsOther;
       
   427             break;
       
   428         }
       
   429     return language;
       
   430     }
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // CCbsMessage::Message
       
   434 // Returns the 16-bit message content
       
   435 // (other items were commented in a header).
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 HBufC* CCbsMessage::Message() const
       
   439     {
       
   440     return iMessage;
       
   441     }
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 // CCbsMessage::Message8
       
   445 // Returns the 8-bit representation of the message
       
   446 // (other items were commented in a header).
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 HBufC8* CCbsMessage::Message8() const
       
   450     {
       
   451     return iMessage8;
       
   452     }
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 // CCbsMessage::MessageCode
       
   456 // Returns the message code of the message.
       
   457 // (other items were commented in a header).
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 TCbsRecMessageCode CCbsMessage::MessageCode() const
       
   461     {
       
   462     return TCbsRecMessageCode( ( TUint16( Key() & KMessageCodeMask ) ) >> 4 );
       
   463     }
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CCbsMessage::MessageClass
       
   467 // Returns the class of the message.
       
   468 // (other items were commented in a header).
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 TInt CCbsMessage::MessageClass() const
       
   472     {
       
   473 	TUint8 msgclass;
       
   474 	msgclass = TUint8( iDCS >> 4 );
       
   475 	TInt messageClass( 0 );
       
   476 
       
   477     if ( msgclass == 0x05 || msgclass == 0x07 || msgclass == 0x0f ) // 0000 0101 or 0000 0111 or 0000 1111
       
   478 		{
       
   479 			msgclass = 0x03; // 0000 0011
       
   480 
       
   481 			// Lets find out last two bits
       
   482 			msgclass = TUint8( msgclass & iDCS );
       
   483 			switch ( msgclass )
       
   484 			{
       
   485 				case 1:
       
   486 					messageClass = 1;
       
   487 					break;
       
   488 				case 2:
       
   489 					messageClass = 2;
       
   490 					break;
       
   491 				case 3:
       
   492 					messageClass = 3;
       
   493 					break;
       
   494 				case 0:
       
   495 				default:
       
   496 					messageClass = 0;
       
   497 					break;
       
   498 			}
       
   499 		}
       
   500 	return messageClass;
       
   501     }
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CCbsMessage::MessagePrecededByLanguageIndication
       
   505 // Returns ECbsRecLanguageIndicationBody if message's content is preceded 
       
   506 // by language indication (see GSM 03.38).
       
   507 // (other items were commented in a header).
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 TCbsRecLanguageIndication CCbsMessage::MessagePrecededByLanguageIndication() const
       
   511     {
       
   512     TCbsRecLanguageIndication indication( ECbsRecLanguageIndicationHeader );
       
   513     if ( iDCS == 0x10 || iDCS == 0x11 )
       
   514         {
       
   515         indication = ECbsRecLanguageIndicationBody;
       
   516         }
       
   517     return indication;
       
   518     }
       
   519 
       
   520 // -----------------------------------------------------------------------------
       
   521 // CCbsMessage::NetworkMode
       
   522 // Returns current network mode (GSM/WCDMA)
       
   523 // 
       
   524 // (other items were commented in a header).
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 TCbsNetworkMode CCbsMessage::NetworkMode() const
       
   528     {
       
   529     return iNetworkMode;
       
   530     }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CCbsMessage::PageParameter
       
   534 // Returns the Page Parameter of the message page
       
   535 //
       
   536 // Page Parameter is a 8-bit field describing the number
       
   537 // of pages in a message and the index of this page in a
       
   538 // sequence of pages comprising a message.
       
   539 // For single-page messages this value is 00010001b. 
       
   540 // Value 0 (zero) is reserved with coding beginning at 0001b.
       
   541 // Thus there can be 1..15 pages in one message.
       
   542 // Total and this page -fields can be accessed with 
       
   543 // methods TotalPages() and ThisPage().
       
   544 // (other items were commented in a header).
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 TCbsRecPageParameter CCbsMessage::PageParameter() const
       
   548     {
       
   549     return iPageParameter;
       
   550     }
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // CCbsMessage::ReleaseEightBitRepresentation
       
   554 // Frees the memory allocated for 8-bit representation of message content.
       
   555 // (other items were commented in a header).
       
   556 // -----------------------------------------------------------------------------
       
   557 //  
       
   558 void CCbsMessage::ReleaseEightBitRepresentation()
       
   559     {
       
   560     delete iMessage8;
       
   561     iMessage8 = NULL;
       
   562     }
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // CCbsMessage::RemoveIndexHeaderL
       
   566 // Removes any index header prefix from the message body.
       
   567 //    
       
   568 // This method assumes that the index header is contained in the
       
   569 // first line of message body. This line, including trailing <cr><lf>
       
   570 // is removed.
       
   571 //
       
   572 // Index header prefix is assumed to contain "EIn<cr><lf>", where n
       
   573 // specifies the version number this index message claims to 
       
   574 // follow and <cr><lf> is a carriage return + line feed.
       
   575 //  
       
   576 // It is also assumed that any language indication prefix has
       
   577 // already been removed prior to this operation.
       
   578 //
       
   579 // Message must be in UCS-2 representation.
       
   580 // (other items were commented in a header).
       
   581 // -----------------------------------------------------------------------------
       
   582 //
       
   583 void CCbsMessage::RemoveIndexHeaderL() 
       
   584     {
       
   585     __ASSERT_DEBUG( IsIndexMessage(), CbsServerPanic( ECbsNotIndexMessage ) );
       
   586 
       
   587     if ( iMessage->Length() < KIndexHeaderLength )
       
   588         {
       
   589         User::Leave( KErrUnderflow );   // Msg too short to contain ix header.
       
   590         }
       
   591 
       
   592     iMessage->Des().Delete( KIndexHeaderPosition, KIndexHeaderLength );
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CCbsMessage::RemoveLanguageIndicationFromBodyL
       
   597 // Removes language indication field from the message body.
       
   598 //   
       
   599 // Presence of an indication is verified with the DCS value 
       
   600 // according to ETSI specifications. Message is assumed to
       
   601 // contain valid indication, i.e., three bytes preceding the message
       
   602 // body specifying the language code. 
       
   603 //  
       
   604 // The correctness of this operation is not checked. If the
       
   605 // indication is invalid, the message body is likely to either have
       
   606 // a couple of characters too many or few.
       
   607 // 
       
   608 // Message is assumed to be decoded into UCS-2.
       
   609 // (other items were commented in a header).
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 void CCbsMessage::RemoveLanguageIndicationFromBodyL()
       
   613     {
       
   614     if ( MessagePrecededByLanguageIndication() == 
       
   615         ECbsRecLanguageIndicationBody )
       
   616         {
       
   617         if ( iMessage->Length() < KLanguageIndicationPosition + 
       
   618             KLanguageIndicationLength )
       
   619             {
       
   620             User::Leave( KErrUnderflow );
       
   621             }
       
   622 
       
   623         iMessage->Des().Delete( KLanguageIndicationPosition, 
       
   624             KLanguageIndicationLength );
       
   625         }
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CCbsMessage::RequiresImmediateDisplay
       
   630 // Returns ETrue, if this message requires to be displayed immediately.
       
   631 //       	   
       
   632 // The CB message has to be displayed immediately
       
   633 // if either it is flagged as a Class 0 message (see GSM 03.38)
       
   634 // or has a geographical scope of the type "Immediate" 
       
   635 // (see GSM 03.41).
       
   636 //  
       
   637 // This function always returns EFalse for Base station ID messages 
       
   638 // (message identifier = 50).
       
   639 // (other items were commented in a header).
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 TBool CCbsMessage::RequiresImmediateDisplay() const
       
   643     {
       
   644     return IsClass0();
       
   645     }
       
   646 
       
   647 // -----------------------------------------------------------------------------
       
   648 // CCbsMessage::ReserveContentSizeL
       
   649 // Increases the space allocated for message content.
       
   650 // Reallocates message content to match parameter aLength.
       
   651 // Should be used before AppendContent()-call.
       
   652 // (other items were commented in a header).
       
   653 // -----------------------------------------------------------------------------
       
   654 //
       
   655 void CCbsMessage::ReserveContentSizeL( 
       
   656     TInt aLength )
       
   657     {
       
   658     if ( iMessage == NULL )
       
   659         {
       
   660         iMessage = HBufC::NewL( aLength );
       
   661         }
       
   662     else if ( ( iMessage ) && ( aLength < iMessage->Length() ) )                
       
   663         {
       
   664         User::Leave( KErrArgument );
       
   665         }
       
   666     else
       
   667         {
       
   668         iMessage = iMessage->ReAllocL( aLength );
       
   669         }    
       
   670     }
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 // CCbsMessage::ReserveContentSize8L
       
   674 // Increases the space allocated for message content.
       
   675 // Reallocates message content to match parameter aLength.
       
   676 // Should be used before AppendContent()-call.
       
   677 // (other items were commented in a header).
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 void CCbsMessage::ReserveContentSize8L( 
       
   681     TInt aLength )
       
   682     {
       
   683     if ( iMessage8 == NULL )
       
   684         {
       
   685         iMessage8 = HBufC8::NewL( aLength );
       
   686         }
       
   687     else if ( ( iMessage8 ) && ( aLength < iMessage8->Length() ) )                
       
   688         {
       
   689         User::Leave( KErrArgument );
       
   690         }
       
   691     else
       
   692         {
       
   693         iMessage8 = iMessage8->ReAllocL( aLength );
       
   694         }    
       
   695     }
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CCbsMessage::ResolveLanguage
       
   699 // Determines language of this message so that calls to Language() 
       
   700 // will return the correct value.
       
   701 //
       
   702 // Language information may be determined from Data Coding Scheme
       
   703 // of message header or from the first characters in message body.
       
   704 // For the latter to succeed, the message has to be decoded into UCS-2.
       
   705 // (other items were commented in a header).
       
   706 // -----------------------------------------------------------------------------
       
   707 //
       
   708 void CCbsMessage::ResolveLanguage()
       
   709     {
       
   710     if ( iDCS <= ECbsRecLanguageUnspecified ||      // 0000xxxx
       
   711         ( iDCS >= ECbsRecLanguageCzech && iDCS < ECbsRecLanguageMax ) )
       
   712         {
       
   713         // Default alphabet, bits 0-3 specify language.
       
   714         iLanguage = LanguageWithDefaultAlphabet();
       
   715         }
       
   716     else if ( MessagePrecededByLanguageIndication() == 
       
   717         ECbsRecLanguageIndicationBody )
       
   718         {
       
   719         iLanguage = LanguagePrecedingMessage();
       
   720         }
       
   721     else
       
   722         {
       
   723         iLanguage = ECbsOther;
       
   724         }
       
   725     }
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // CCbsMessage::SetNetworkInfo
       
   729 // Sets the network information of this message.
       
   730 // (other items were commented in a header).
       
   731 // -----------------------------------------------------------------------------
       
   732 // 
       
   733 void CCbsMessage::SetNetworkInfo(
       
   734     const RMobilePhone::TMobilePhoneNetworkInfoV1& aNetworkInfo,
       
   735     const RMobilePhone::TMobilePhoneLocationAreaV1& aArea )
       
   736     {
       
   737     iNetworkInfo = aNetworkInfo;
       
   738     iLocationArea = aArea;
       
   739     }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // CCbsMessage::TopicNumber
       
   743 // Returns the 16-bit Message Identifier containing the topic number.	
       
   744 // (other items were commented in a header).
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 TCbsDbTopicNumber CCbsMessage::TopicNumber() const
       
   748     {
       
   749     return TCbsDbTopicNumber( iMessageIdentifier );
       
   750     }
       
   751 
       
   752 // -----------------------------------------------------------------------------
       
   753 // CCbsMessage::UpdateNumber
       
   754 // Returns the update number of the message
       
   755 // (other items were commented in a header).
       
   756 // -----------------------------------------------------------------------------
       
   757 //
       
   758 TCbsRecUpdateNumber CCbsMessage::UpdateNumber() const
       
   759     {
       
   760     return TCbsRecUpdateNumber( Key() & 0xF );            // 00001111b
       
   761     }
       
   762 
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CCbsMessage::IsLivecastMessage
       
   766 // Checks if this message is a Livecast message.
       
   767 // (other items were commented in a header).
       
   768 // -----------------------------------------------------------------------------
       
   769 // 
       
   770 TBool CCbsMessage::IsLivecastMessage() const
       
   771     {
       
   772     TBool isLivecastMsg( EFalse );
       
   773 
       
   774     // Check if this message is a Livecast message (just check the topic number)
       
   775     if ( TopicNumber() >= KCbsLivecastTopicMin && 
       
   776         TopicNumber() <= KCbsLivecastTopicMax )
       
   777         {
       
   778         // This is a Livecast msg
       
   779         isLivecastMsg = ETrue;
       
   780         }
       
   781 
       
   782     return isLivecastMsg;
       
   783     }
       
   784 
       
   785 
       
   786 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   787 
       
   788 //  End of File