languageinterworkingfw/servicehandler/src/liwcommon.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2003-2005 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 the License "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 for common LIW classes to be used both
       
    15 *                consumer and provider side.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #include "liwcommon.h"
       
    25 #include <eikenv.h>
       
    26 const TInt KInitialMaxProviders = 0xff;
       
    27 
       
    28 CLiwCriteriaItem::CLiwCriteriaItem()
       
    29     {
       
    30     }
       
    31 
       
    32 
       
    33 
       
    34 EXPORT_C CLiwCriteriaItem* CLiwCriteriaItem::NewL()
       
    35     {
       
    36     CLiwCriteriaItem* item = new (ELeave) CLiwCriteriaItem();
       
    37     CleanupStack::PushL( item );
       
    38     item->ConstructL();
       
    39     CleanupStack::Pop(item); // item
       
    40     return item;
       
    41     }
       
    42 
       
    43 
       
    44 
       
    45 EXPORT_C CLiwCriteriaItem* CLiwCriteriaItem::NewLC()
       
    46     {
       
    47     CLiwCriteriaItem* item = new (ELeave) CLiwCriteriaItem();
       
    48     CleanupStack::PushL( item );
       
    49     item->ConstructL();
       
    50     return item;
       
    51     }
       
    52 
       
    53 
       
    54 
       
    55 EXPORT_C CLiwCriteriaItem* CLiwCriteriaItem::NewL(
       
    56     TInt aCriteriaId,
       
    57     TInt aServiceCmd,
       
    58     const TDesC8& aContentType)
       
    59     {
       
    60     CLiwCriteriaItem* item = new (ELeave) CLiwCriteriaItem();
       
    61     CleanupStack::PushL( item );
       
    62     item->ConstructL(aCriteriaId, aServiceCmd, aContentType);
       
    63     CleanupStack::Pop(item); // item
       
    64     return item;
       
    65     }
       
    66 
       
    67 
       
    68 
       
    69 EXPORT_C CLiwCriteriaItem* CLiwCriteriaItem::NewLC(
       
    70     TInt aCriteriaId,
       
    71     TInt aServiceCmd,
       
    72     const TDesC8& aContentType)
       
    73     {
       
    74     CLiwCriteriaItem* item = new (ELeave) CLiwCriteriaItem();
       
    75     CleanupStack::PushL( item );
       
    76     item->ConstructL(aCriteriaId, aServiceCmd, aContentType);
       
    77     return item;    
       
    78     }
       
    79 
       
    80 EXPORT_C CLiwCriteriaItem* CLiwCriteriaItem::NewL(       
       
    81                                     TInt aCriteriaId,
       
    82                                     const TDesC8& aServiceCmd,
       
    83                                     const TDesC8& aContentType)
       
    84     {
       
    85     CLiwCriteriaItem* item = new (ELeave) CLiwCriteriaItem();
       
    86     CleanupStack::PushL( item );
       
    87     item->ConstructL(aCriteriaId, aServiceCmd, aContentType);
       
    88     CleanupStack::Pop(item); // item
       
    89     return item;
       
    90     }
       
    91 
       
    92 EXPORT_C CLiwCriteriaItem* CLiwCriteriaItem::NewLC(
       
    93                                 TInt aCriteriaId,
       
    94                                 const TDesC8& aServiceCmd,
       
    95                                 const TDesC8& aContentType)
       
    96     {
       
    97     CLiwCriteriaItem* item = new (ELeave) CLiwCriteriaItem();
       
    98     CleanupStack::PushL( item );
       
    99     item->ConstructL(aCriteriaId, aServiceCmd, aContentType);
       
   100     return item;    
       
   101     }
       
   102 
       
   103 
       
   104 EXPORT_C CLiwCriteriaItem::~CLiwCriteriaItem()
       
   105     {
       
   106     delete iReserved.iData.iBufC8; 
       
   107     delete iContentType;
       
   108     iOptions.Reset();
       
   109     
       
   110     iMetadataOptions.Reset();
       
   111     }
       
   112 
       
   113 
       
   114 void CLiwCriteriaItem::ConstructL()
       
   115     {
       
   116     iMaxProviders = KInitialMaxProviders;
       
   117     }
       
   118 
       
   119 
       
   120 
       
   121 void CLiwCriteriaItem::ConstructL(TInt aCriteriaId, TInt aServiceCmd,
       
   122     const TDesC8& aContentType)
       
   123     {
       
   124     iMaxProviders = KInitialMaxProviders;
       
   125 	iCriteriaId = aCriteriaId;
       
   126     iServiceCmd = aServiceCmd;
       
   127     SetContentTypeL( aContentType );
       
   128     }
       
   129 
       
   130 void CLiwCriteriaItem::ConstructL(TInt aCriteriaId, const TDesC8& aServiceCmd,
       
   131                                   const TDesC8& aContentType)
       
   132     {
       
   133     iMaxProviders = KInitialMaxProviders;
       
   134     iCriteriaId = aCriteriaId;
       
   135     SetServiceCmdL( aServiceCmd );
       
   136     SetContentTypeL( aContentType );
       
   137     }
       
   138 
       
   139 EXPORT_C void CLiwCriteriaItem::SetId(TInt aId)
       
   140     {
       
   141     iCriteriaId = aId;      
       
   142     }
       
   143 
       
   144 
       
   145 
       
   146 EXPORT_C void CLiwCriteriaItem::SetServiceClass(const TUid& aServiceUid)
       
   147     {
       
   148     iServiceClass = aServiceUid;
       
   149     }
       
   150     
       
   151 
       
   152 
       
   153 EXPORT_C void CLiwCriteriaItem::SetServiceCmd(TInt aServiceCmd)
       
   154     {
       
   155     iServiceCmd = aServiceCmd;
       
   156     }
       
   157 
       
   158 EXPORT_C void CLiwCriteriaItem::SetServiceCmdL(const TDesC8& aServiceCmd)
       
   159     {
       
   160     iServiceCmd = KLiwCmdAsStr;
       
   161     delete iReserved.iData.iBufC8;
       
   162     iReserved.iData.iBufC8 = NULL;
       
   163     iReserved.iData.iBufC8 = HBufC8::NewL(aServiceCmd.Length());
       
   164     TPtr8 content(iReserved.iData.iBufC8->Des());
       
   165     content.SetLength(aServiceCmd.Length());
       
   166     content.Copy(aServiceCmd);
       
   167     }
       
   168 
       
   169 EXPORT_C void CLiwCriteriaItem::SetContentTypeL(const TDesC8& aContentType)
       
   170     {
       
   171     delete iContentType;
       
   172     iContentType = NULL;
       
   173     iContentType = HBufC8::NewL(aContentType.Length());
       
   174     TPtr8 content(iContentType->Des());
       
   175     content.SetLength(aContentType.Length());
       
   176     content.Copy(aContentType);
       
   177     }
       
   178 
       
   179 
       
   180 
       
   181 EXPORT_C TInt CLiwCriteriaItem::Id() const
       
   182     {
       
   183     return iCriteriaId;
       
   184     }
       
   185 
       
   186 
       
   187 
       
   188 EXPORT_C const TUid& CLiwCriteriaItem::ServiceClass() const
       
   189     {
       
   190     return iServiceClass;
       
   191     }
       
   192     
       
   193 
       
   194 
       
   195 EXPORT_C TInt CLiwCriteriaItem::ServiceCmd() const
       
   196     {   
       
   197     return iServiceCmd;
       
   198     }
       
   199 
       
   200 EXPORT_C const TDesC8& CLiwCriteriaItem::ServiceCmdStr() const
       
   201     {   
       
   202     return ((iReserved.iData.iBufC8) ? *iReserved.iData.iBufC8 : KNullDesC8());
       
   203     }
       
   204 
       
   205 EXPORT_C const TDesC8& CLiwCriteriaItem::ContentType() const
       
   206     {
       
   207     if (iContentType)
       
   208         {
       
   209         return *iContentType;
       
   210         }
       
   211 
       
   212     return KNullDesC8();
       
   213     }
       
   214 
       
   215 
       
   216 
       
   217 EXPORT_C void CLiwCriteriaItem::SetOptions(TUint aOptions)
       
   218     {
       
   219     if(aOptions == 0)
       
   220     	return;
       
   221     
       
   222     iOptions.Set(aOptions);
       
   223     }
       
   224 
       
   225 
       
   226 EXPORT_C void CLiwCriteriaItem::SetMetaDataOptions(const TLiwVariant& aMetaDataOptions)
       
   227     {
       
   228     iMetadataOptions.SetL(aMetaDataOptions);
       
   229     }
       
   230 
       
   231 EXPORT_C void CLiwCriteriaItem::GetMetaDataOptions(TLiwVariant& aMetaDataOptions) const
       
   232     {
       
   233     aMetaDataOptions.SetL(iMetadataOptions);
       
   234     }
       
   235 
       
   236 EXPORT_C TUint CLiwCriteriaItem::Options() const
       
   237     {
       
   238     return iOptions.AsTUint();
       
   239     }
       
   240 
       
   241 
       
   242 
       
   243 EXPORT_C void CLiwCriteriaItem::ReadFromResoureL(TResourceReader& aReader)
       
   244     {
       
   245     delete iContentType;
       
   246     iContentType = NULL;
       
   247 
       
   248     delete iReserved.iData.iBufC8;   
       
   249     iReserved.iData.iBufC8 = NULL;   
       
   250     
       
   251     iCriteriaId = aReader.ReadInt32();
       
   252     iServiceCmd = aReader.ReadInt32();
       
   253 
       
   254     if (iServiceCmd == KLiwCmdAsStr)   
       
   255       {
       
   256         TPtrC8 txtptr = aReader.ReadTPtrC8();
       
   257         iReserved.iData.iBufC8 = HBufC8::NewL(txtptr.Length());
       
   258         TPtr8 content(iReserved.iData.iBufC8->Des());
       
   259         content.Copy( txtptr );
       
   260       }
       
   261 
       
   262     {
       
   263       TPtrC8 txtptr = aReader.ReadTPtrC8();
       
   264       iContentType = HBufC8::NewL(txtptr.Length());
       
   265       TPtr8 content(iContentType->Des());
       
   266       content.Copy( txtptr );
       
   267     }
       
   268 
       
   269     iServiceClass = TUid::Uid(aReader.ReadInt32());
       
   270 
       
   271     iDefaultProvider = TUid::Uid(aReader.ReadInt32());
       
   272 
       
   273     iMaxProviders = aReader.ReadUint8();
       
   274     
       
   275     SetOptions((TUint)aReader.ReadUint8());
       
   276     
       
   277     TInt capResID = aReader.ReadInt32(); // Skip over reserved field.
       
   278     
       
   279     
       
   280     }
       
   281 
       
   282 
       
   283 
       
   284 EXPORT_C TUid CLiwCriteriaItem::DefaultProvider() const
       
   285     {
       
   286     return iDefaultProvider;
       
   287     }
       
   288 
       
   289 
       
   290 
       
   291 EXPORT_C void CLiwCriteriaItem::SetDefaultProvider(TInt aDefault)
       
   292     {
       
   293     iDefaultProvider = TUid::Uid(aDefault);
       
   294     }   
       
   295 
       
   296 
       
   297 EXPORT_C TInt CLiwCriteriaItem::MaxProviders() const
       
   298     {
       
   299     return iMaxProviders;
       
   300     }
       
   301 
       
   302 
       
   303 EXPORT_C void CLiwCriteriaItem::SetMaxProviders(TInt aMaxProviders)
       
   304     {
       
   305     iMaxProviders = aMaxProviders;
       
   306     }
       
   307 
       
   308 
       
   309 EXPORT_C TBool CLiwCriteriaItem::operator==(const CLiwCriteriaItem& aItem)
       
   310     {
       
   311       if (iServiceCmd != KLiwCmdAsStr) 
       
   312         {
       
   313           return ((iCriteriaId                                  == aItem.iCriteriaId)           &&
       
   314                   (iServiceCmd                                  == aItem.iServiceCmd)           &&
       
   315                   (iContentType->Compare(*(aItem.iContentType)) == KErrNone)                    &&
       
   316                   (iServiceClass.iUid                           == aItem.iServiceClass.iUid)    &&
       
   317                   (iDefaultProvider.iUid                        == aItem.iDefaultProvider.iUid) &&
       
   318                   (iMaxProviders                                == aItem.iMaxProviders)         &&
       
   319                   (iOptions                                     == aItem.iOptions)				&&       
       
   320                   (iMetadataOptions                             == aItem.iMetadataOptions));       
       
   321         }
       
   322       else
       
   323         {
       
   324         	if(iCriteriaId== aItem.iCriteriaId)
       
   325         	{
       
   326         		if(0 == iReserved.iData.iBufC8->Des().Compare(aItem.iReserved.iData.iBufC8->Des()))
       
   327         		{
       
   328         			if(iContentType->Compare(*(aItem.iContentType)) == KErrNone)
       
   329         			{
       
   330         				if(iServiceClass.iUid == aItem.iServiceClass.iUid)
       
   331         				{
       
   332         					if(iDefaultProvider.iUid == aItem.iDefaultProvider.iUid)
       
   333         					{
       
   334         						if(iMaxProviders == aItem.iMaxProviders)
       
   335         						{
       
   336         							if((iOptions == aItem.iOptions))
       
   337         							{
       
   338         								if((iMetadataOptions == aItem.iMetadataOptions))
       
   339         								{
       
   340         									return ETrue;
       
   341         								}
       
   342         							}
       
   343         						}
       
   344         					}
       
   345         				}
       
   346         			}
       
   347         		}
       
   348         	}
       
   349            	return EFalse;
       
   350         }
       
   351     }
       
   352 
       
   353 EXPORT_C TInt32 MLiwNotifyCallback::GetTransactionID()
       
   354 {
       
   355 	TTime currentTime;
       
   356 	const TInt KMin = 60;
       
   357 	const TInt KSec = 60;
       
   358 	const TInt KMcSec = 1000;
       
   359 	currentTime.HomeTime();
       
   360 	return	 (KMin * KSec * currentTime.DateTime().Hour())+ 
       
   361 			 (KMin * currentTime.DateTime().Minute())+
       
   362 			 (KMcSec * currentTime.DateTime().Second()) + 
       
   363 			 (currentTime.DateTime().MicroSecond());
       
   364 }
       
   365 // End of file