applicationinterworkingfw/ServiceHandler/src/AiwCommon.cpp
changeset 0 2f259fa3e83a
child 9 0aa5fbdfbc30
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 "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 AIW classes to be used both
       
    15 *                consumer and provider side.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "AiwCommon.h"
       
    23 
       
    24 const TInt KInitialMaxProviders = 0xff;
       
    25 
       
    26 
       
    27 CAiwCriteriaItem::CAiwCriteriaItem()
       
    28     {
       
    29     }
       
    30 
       
    31 
       
    32 
       
    33 EXPORT_C CAiwCriteriaItem* CAiwCriteriaItem::NewL()
       
    34     {
       
    35     CAiwCriteriaItem* item = new (ELeave) CAiwCriteriaItem();
       
    36     CleanupStack::PushL( item );
       
    37     item->ConstructL();
       
    38     CleanupStack::Pop(); // item
       
    39     return item;
       
    40     }
       
    41 
       
    42 
       
    43 
       
    44 EXPORT_C CAiwCriteriaItem* CAiwCriteriaItem::NewLC()
       
    45     {
       
    46     CAiwCriteriaItem* item = new (ELeave) CAiwCriteriaItem();
       
    47     CleanupStack::PushL( item );
       
    48     item->ConstructL();
       
    49     return item;
       
    50     }
       
    51 
       
    52 
       
    53 
       
    54 EXPORT_C CAiwCriteriaItem* CAiwCriteriaItem::NewL(
       
    55     TInt aCriteriaId,
       
    56     TInt aServiceCmd,
       
    57     const TDesC8& aContentType)
       
    58     {
       
    59     CAiwCriteriaItem* item = new (ELeave) CAiwCriteriaItem();
       
    60     CleanupStack::PushL( item );
       
    61     item->ConstructL(aCriteriaId, aServiceCmd, aContentType);
       
    62     CleanupStack::Pop(); // item
       
    63     return item;
       
    64     }
       
    65 
       
    66 
       
    67 
       
    68 EXPORT_C CAiwCriteriaItem* CAiwCriteriaItem::NewLC(
       
    69     TInt aCriteriaId,
       
    70     TInt aServiceCmd,
       
    71     const TDesC8& aContentType)
       
    72     {
       
    73     CAiwCriteriaItem* item = new (ELeave) CAiwCriteriaItem();
       
    74     CleanupStack::PushL( item );
       
    75     item->ConstructL(aCriteriaId, aServiceCmd, aContentType);
       
    76     return item;    
       
    77     }
       
    78 
       
    79 
       
    80 
       
    81 EXPORT_C CAiwCriteriaItem::~CAiwCriteriaItem()
       
    82     {
       
    83     delete iContentType;
       
    84     }
       
    85 
       
    86 
       
    87 
       
    88 void CAiwCriteriaItem::ConstructL()
       
    89     {
       
    90     iMaxProviders = KInitialMaxProviders;
       
    91     iOptions.Set(TInt32(0));
       
    92     }
       
    93 
       
    94 
       
    95 
       
    96 void CAiwCriteriaItem::ConstructL(TInt aCriteriaId, TInt aServiceCmd,
       
    97     const TDesC8& aContentType)
       
    98     {
       
    99     iMaxProviders = KInitialMaxProviders;
       
   100     iOptions.Set(TInt32(0));
       
   101     iCriteriaId = aCriteriaId;
       
   102     iServiceCmd = aServiceCmd;
       
   103     SetContentTypeL( aContentType );
       
   104     }
       
   105 
       
   106 
       
   107 
       
   108 EXPORT_C void CAiwCriteriaItem::SetId(TInt aId)
       
   109     {
       
   110     iCriteriaId = aId;      
       
   111     }
       
   112 
       
   113 
       
   114 
       
   115 EXPORT_C void CAiwCriteriaItem::SetServiceClass(const TUid& aServiceUid)
       
   116     {
       
   117     iServiceClass = aServiceUid;
       
   118     }
       
   119     
       
   120 
       
   121 
       
   122 EXPORT_C void CAiwCriteriaItem::SetServiceCmd(TInt aServiceCmd)
       
   123     {
       
   124     iServiceCmd = aServiceCmd;
       
   125     }
       
   126 
       
   127 
       
   128 
       
   129 EXPORT_C void CAiwCriteriaItem::SetContentTypeL(const TDesC8& aContentType)
       
   130     {
       
   131     delete iContentType;
       
   132     iContentType = NULL;
       
   133     iContentType = HBufC8::NewL(aContentType.Length());
       
   134     TPtr8 content(iContentType->Des());
       
   135     content.SetLength(aContentType.Length());
       
   136     content.Copy(aContentType);
       
   137     }
       
   138 
       
   139 
       
   140 
       
   141 EXPORT_C TInt CAiwCriteriaItem::Id() const
       
   142     {
       
   143     return iCriteriaId;
       
   144     }
       
   145 
       
   146 
       
   147 
       
   148 EXPORT_C const TUid& CAiwCriteriaItem::ServiceClass() const
       
   149     {
       
   150     return iServiceClass;
       
   151     }
       
   152     
       
   153 
       
   154 
       
   155 EXPORT_C TInt CAiwCriteriaItem::ServiceCmd() const
       
   156     {   
       
   157     return iServiceCmd;
       
   158     }
       
   159 
       
   160 
       
   161 
       
   162 EXPORT_C const TDesC8& CAiwCriteriaItem::ContentType() const
       
   163     {
       
   164     if (iContentType)
       
   165         {
       
   166         return *iContentType;
       
   167         }
       
   168 
       
   169     return KNullDesC8();
       
   170     }
       
   171 
       
   172 
       
   173 
       
   174 EXPORT_C void CAiwCriteriaItem::SetOptions(TUint aOptions)
       
   175     {
       
   176     iOptions.Set(aOptions);
       
   177     }
       
   178 
       
   179 
       
   180 
       
   181 EXPORT_C TUint CAiwCriteriaItem::Options() const
       
   182     {
       
   183     TInt32 ret = 0;
       
   184     iOptions.Get( ret );
       
   185     return ret; 
       
   186     }
       
   187 
       
   188 
       
   189 
       
   190 EXPORT_C void CAiwCriteriaItem::ReadFromResoureL(TResourceReader& aReader)
       
   191     {
       
   192     delete iContentType;
       
   193     iContentType = NULL;
       
   194     
       
   195     iCriteriaId = aReader.ReadInt32();
       
   196     iServiceCmd = aReader.ReadInt32();
       
   197 
       
   198     TPtrC8 txtptr = aReader.ReadTPtrC8();
       
   199     iContentType = HBufC8::NewL(txtptr.Length());
       
   200     TPtr8 content(iContentType->Des());
       
   201     content.Copy( txtptr );
       
   202 
       
   203     iServiceClass = TUid::Uid(aReader.ReadInt32());
       
   204 
       
   205     iDefaultProvider = TUid::Uid(aReader.ReadInt32());
       
   206 
       
   207     iMaxProviders = aReader.ReadUint8();
       
   208     
       
   209     iOptions = aReader.ReadUint8();
       
   210     aReader.ReadInt32(); // Skip over reserved field.
       
   211     }
       
   212 
       
   213 
       
   214 
       
   215 EXPORT_C TUid CAiwCriteriaItem::DefaultProvider() const
       
   216     {
       
   217     return iDefaultProvider;
       
   218     }
       
   219 
       
   220 
       
   221 
       
   222 EXPORT_C void CAiwCriteriaItem::SetDefaultProvider(TInt aDefault)
       
   223     {
       
   224     iDefaultProvider = TUid::Uid(aDefault);
       
   225     }   
       
   226 
       
   227 
       
   228 EXPORT_C TInt CAiwCriteriaItem::MaxProviders() const
       
   229     {
       
   230     return iMaxProviders;
       
   231     }
       
   232 
       
   233 
       
   234 EXPORT_C void CAiwCriteriaItem::SetMaxProviders(TInt aMaxProviders)
       
   235     {
       
   236     iMaxProviders = aMaxProviders;
       
   237     }
       
   238 
       
   239 
       
   240 EXPORT_C TBool CAiwCriteriaItem::operator==(const CAiwCriteriaItem& aItem)
       
   241     {
       
   242     return ((iCriteriaId                                  == aItem.iCriteriaId)           &&
       
   243             (iServiceCmd                                  == aItem.iServiceCmd)           &&
       
   244             (iContentType->Compare(*(aItem.iContentType)) == KErrNone)                    &&
       
   245             (iServiceClass.iUid                           == aItem.iServiceClass.iUid)    &&
       
   246             (iDefaultProvider.iUid                        == aItem.iDefaultProvider.iUid) &&
       
   247             (iMaxProviders                                == aItem.iMaxProviders)         &&
       
   248             (iOptions                                     == aItem.iOptions));       
       
   249     }
       
   250 
       
   251 // End of file