realtimenetprots/sipfw/ProfileAgent/Client/Src/SipProfileItem.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : sipprofileitem
       
    15 // Part of     : SIP Profile Client
       
    16 // implementation
       
    17 // Version     : 1.0
       
    18 // INCLUDE FILES
       
    19 //
       
    20 
       
    21 
       
    22 
       
    23 #include "SipProfileItem.h"
       
    24 #include "sipmanagedprofile.h"
       
    25 #include "sipconcreteprofile.h"
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CSIPProfileItem::NewL
       
    31 // Two-phased constructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CSIPProfileItem* CSIPProfileItem::NewL()
       
    35 	{
       
    36     CSIPProfileItem* self = CSIPProfileItem::NewLC();
       
    37     CleanupStack::Pop(self);
       
    38     return self;
       
    39 	}
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CSIPProfileItem::NewLC
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CSIPProfileItem* CSIPProfileItem::NewLC()
       
    47 	{
       
    48 	CSIPProfileItem* self = new (ELeave) CSIPProfileItem();
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     return self;
       
    52 	}
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CSIPProfileItem::CSIPProfileItem
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CSIPProfileItem::CSIPProfileItem()
       
    59 :iProfileId(0), iEnabled(EFalse)
       
    60 	{
       
    61 	}
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CSIPProfileItem::ConstructL
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CSIPProfileItem::ConstructL()
       
    68 	{
       
    69 	}
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CSIPProfileItem::~CSIPProfileItem
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CSIPProfileItem::~CSIPProfileItem()
       
    76 	{
       
    77 	iProfiles.Reset();
       
    78 	iProfiles.Close();
       
    79 	}
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CSIPProfileItem::SetProfileId
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CSIPProfileItem::SetProfileId(TUint aProfileId)
       
    86 	{
       
    87 	iProfileId = aProfileId;
       
    88 	}
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CSIPProfileItem::SetProfile
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CSIPProfileItem::SetProfile(CSIPProfile& aProfile)
       
    95 	{
       
    96 	iConcreteProfile = &(aProfile.ConcreteProfile());
       
    97 	iProfileId = iConcreteProfile->Id();
       
    98 	}
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CSIPProfileItem::Profile
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CSIPProfile* CSIPProfileItem::Profile() const
       
   105 	{
       
   106 	ASSERT(iProfiles.Count() > 0);
       
   107 	return static_cast<CSIPProfile*>(iProfiles[0]);
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CSIPProfileItem::SetConcreteProfile
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CSIPProfileItem::SetConcreteProfile(CSIPConcreteProfile* aProfile)
       
   115 	{
       
   116 
       
   117 	for (int i = 0; i < iProfiles.Count(); i++)
       
   118 		{
       
   119 		iProfiles[i]->ClearConcreteProfile();
       
   120 		iProfiles[i]->SetConcreteProfile(aProfile);
       
   121 		}
       
   122 	delete iConcreteProfile;
       
   123 	iConcreteProfile = aProfile;
       
   124 	}
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CSIPProfileItem::ConcreteProfile
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 const CSIPConcreteProfile& CSIPProfileItem::ConcreteProfile() const
       
   131 	{
       
   132 	return *iConcreteProfile;
       
   133 	}
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CSIPProfileItem::ConcreteProfile
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 CSIPConcreteProfile& CSIPProfileItem::ConcreteProfile()
       
   140 	{
       
   141 	return *iConcreteProfile;
       
   142 	}
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CSIPProfileItem::IncrementReferenceCountL
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CSIPProfileItem::IncrementReferenceCountL(CSIPProfile& aProfile)
       
   149 	{
       
   150 	User::LeaveIfError(iProfiles.Append(&aProfile));
       
   151 	}
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CSIPProfileItem::DecrementReferenceCount
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CSIPProfileItem::DecrementReferenceCount(CSIPProfile& aProfile)
       
   158 	{
       
   159 	TBool found = EFalse;
       
   160 	for (int i = 0; i < iProfiles.Count() && !found; i++)
       
   161 		{
       
   162 		if(iProfiles[i] == &aProfile)
       
   163 			{
       
   164 			iProfiles.Remove(i);
       
   165 			found = ETrue;
       
   166 			}
       
   167 		}
       
   168 	}
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CSIPProfileItem::ReferenceCount
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TUint CSIPProfileItem::ReferenceCount() const
       
   175 	{
       
   176 	return iProfiles.Count();
       
   177 	}
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CSIPProfileItem::SetEnabled
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CSIPProfileItem::SetEnabled(TBool aEnabled)
       
   184 	{
       
   185 	for (int i = 0; i < iProfiles.Count(); i++)
       
   186 		{
       
   187 		(iProfiles[i])->SetEnabled(aEnabled);
       
   188 		}
       
   189 	iEnabled = aEnabled;
       
   190 	}
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CSIPProfileItem::IsEnabled
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 TBool CSIPProfileItem::IsEnabled() const
       
   197 	{
       
   198 	return iEnabled;
       
   199 	}
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CSIPProfileItem::ErrorOccurred
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CSIPProfileItem::ErrorOccurred(CSIPConcreteProfile::TStatus aStatus, 
       
   206 									TInt aError)
       
   207 	{
       
   208 	iConcreteProfile->SetStatus(CSIPConcreteProfile::EUnregistered);
       
   209 	if (aStatus == CSIPConcreteProfile::ERegistrationInProgress)
       
   210 		{
       
   211 		iConcreteProfile->SetLastRegistrationError(aError);
       
   212 		}
       
   213 	SetEnabled(EFalse);
       
   214 	}
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CSIPProfileItem::Compare
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 TBool CSIPProfileItem::Compare(const CSIPProfileItem& aItem,
       
   221 				const CSIPProfileItem& aItem2) 
       
   222 	{
       
   223 	return (aItem.iProfileId == aItem2.iProfileId);
       
   224 	}
       
   225