realtimenetprots/sipfw/ProfileAgent/Client/Src/SIPProfileITCReceiver.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2007-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        : sipprofileitcreceiver
       
    15 // Part of     : SIP Profile Client
       
    16 // implementation
       
    17 // Version     : 1.0
       
    18 // INCLUDE FILES
       
    19 //
       
    20 
       
    21 
       
    22 
       
    23 #include <s32mem.h>
       
    24 #include <eikenv.h>
       
    25 
       
    26 #include "SIPProfileITCReceiver.h"
       
    27 #include "SIPRemoteProfile.h"
       
    28 #include "sipconcreteprofile.h"
       
    29 #include "sipconcreteprofileobserver.h"
       
    30 #include "sipprofileslots.h"
       
    31 #include "sipprofilealrobserver.h"
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CSIPProfileITCReceiver::NewL
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CSIPProfileITCReceiver* CSIPProfileITCReceiver::NewL(
       
    41 	RSIPProfile& aSipProfile, MSIPConcreteProfileObserver& aObserver)
       
    42 	{
       
    43     CSIPProfileITCReceiver* self = 
       
    44 		CSIPProfileITCReceiver::NewLC(aSipProfile, aObserver);
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47 	}
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSIPProfileITCReceiver::NewLC
       
    51 // Two-phased constructor.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CSIPProfileITCReceiver* CSIPProfileITCReceiver::NewLC(
       
    55 	RSIPProfile& aSipProfile, MSIPConcreteProfileObserver& aObserver)
       
    56 	{
       
    57 	CSIPProfileITCReceiver* self = new (ELeave)
       
    58 		CSIPProfileITCReceiver(aSipProfile, aObserver);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61     return self;
       
    62 	}
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CSIPProfileITCReceiver::CSIPProfileITCReceiver
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CSIPProfileITCReceiver::CSIPProfileITCReceiver(
       
    69 	RSIPProfile& aSipProfile, MSIPConcreteProfileObserver& aObserver) 
       
    70 	: CActive(EPriorityStandard),
       
    71 	iSip(aSipProfile),
       
    72 	iObserver(aObserver)
       
    73 	{
       
    74     CActiveScheduler::Add(this);
       
    75 	}
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSIPProfileITCReceiver::ConstructL
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CSIPProfileITCReceiver::ConstructL()
       
    82 	{
       
    83     iITCMsgArgs.Set(ESipProfileItcArgSlots, &iIdsPckg);
       
    84 	Receive();
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSIPProfileITCReceiver::~CSIPProfileITCReceiver
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CSIPProfileITCReceiver::~CSIPProfileITCReceiver() 
       
    92 	{
       
    93 	CActive::Cancel();
       
    94 	}
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CSIPProfileITCReceiver::Receive
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CSIPProfileITCReceiver::Receive()
       
   101 	{
       
   102 	if (!IsActive())
       
   103 		{
       
   104     	iSip.Receive(iITCMsgArgs, iStatus);
       
   105 		SetActive();
       
   106 		}
       
   107 	}
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CSIPProfileITCReceiver::RunL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CSIPProfileITCReceiver::RunL()
       
   114 	{
       
   115 	TInt err = iStatus.Int();
       
   116 	TSIPProfileSlots ids = iIdsPckg();
       
   117 	
       
   118 	if (err == KErrServerTerminated)
       
   119 		{
       
   120 		User::LeaveIfError(iSip.Connect());
       
   121 		}
       
   122 
       
   123 	Receive();
       
   124 
       
   125 	if (err == KErrNone)
       
   126 		{
       
   127 		IncomingEventL(ids);
       
   128 		}
       
   129 	else
       
   130 		{
       
   131 		ErrorOccuredL(err,ids);
       
   132 		}
       
   133 	}
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CSIPProfileITCReceiver::RunError
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 TInt CSIPProfileITCReceiver::RunError(TInt aError)
       
   140 	{
       
   141 	if (aError == KErrServerTerminated)
       
   142 		{
       
   143 		// to avoid infinite loop
       
   144 		return aError;
       
   145 		}
       
   146 	Receive();
       
   147 	return KErrNone;
       
   148 	}
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CSIPProfileITCReceiver::DoCancel
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CSIPProfileITCReceiver::DoCancel()
       
   155 	{
       
   156     iSip.CancelReceive();
       
   157 	}
       
   158 	
       
   159 // -----------------------------------------------------------------------------
       
   160 // CSIPProfileITCReceiver::IncomingEventL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CSIPProfileITCReceiver::IncomingEventL(TSIPProfileSlots& aIds)
       
   164     {
       
   165 	switch (aIds.iEventId)
       
   166 		{
       
   167 		case ESipProfileItcOpRegistered:
       
   168 			iObserver.RegistrationStatusChangedL(
       
   169 				aIds.iProfileId, 
       
   170 				CSIPConcreteProfile::ERegistered, 
       
   171 				aIds.iSlot1);
       
   172 			break;
       
   173 		case ESipProfileItcOpRegistrationError:
       
   174 			iObserver.ErrorOccurredL(
       
   175 				aIds.iProfileId,
       
   176 				CSIPConcreteProfile::ERegistrationInProgress, 
       
   177 				aIds.iSlot1);
       
   178 			break;
       
   179 		case ESipProfileItcOpUnregistrationError:
       
   180 			iObserver.ErrorOccurredL(
       
   181 				aIds.iProfileId, 
       
   182 				CSIPConcreteProfile::EUnregistrationInProgress, 
       
   183 				aIds.iSlot1);
       
   184 			break;
       
   185 		case ESipProfileItcOpDeregistered:
       
   186 			iObserver.RegistrationStatusChangedL(
       
   187 				aIds.iProfileId, 
       
   188 				CSIPConcreteProfile::EUnregistered, 
       
   189 				0);
       
   190 			break;
       
   191 		case ESipProfileItcOpProfileAdded:
       
   192 		case ESipProfileItcOpProfileAddedDefault:
       
   193 			iObserver.AddedL(aIds.iProfileId);
       
   194 			break;
       
   195 		case ESipProfileItcOpProfileUpdated:
       
   196 			iObserver.UpdatedL(aIds.iProfileId, aIds.iSlot1);
       
   197 			break;
       
   198 		case ESipProfileItcOpProfileRemoved:
       
   199 			iObserver.RemovedL(aIds.iProfileId);
       
   200 			break;
       
   201 		case ESipProfileItcOpIapAvailable:
       
   202 			if (iALRObserver)
       
   203 				{
       
   204 				iALRObserver->AlrEvent(
       
   205 					MSipProfileAlrObserver::EIapAvailable, 
       
   206 					aIds.iProfileId,
       
   207 					aIds.iSlot1, 
       
   208 					aIds.iSlot2);
       
   209 				}
       
   210 			break;
       
   211 		case ESipProfileItcOpMigrationStarted:
       
   212 			if (iALRObserver)
       
   213 				{
       
   214 				iALRObserver->AlrEvent(
       
   215 					MSipProfileAlrObserver::EMigrationStarted, 
       
   216 					aIds.iProfileId,
       
   217 					aIds.iSlot1, 
       
   218 					aIds.iSlot2);
       
   219 				}
       
   220 			break; 
       
   221 		case ESipProfileItcOpMigrationCompleted:
       
   222 			if (iALRObserver)
       
   223 				{
       
   224 				iALRObserver->AlrEvent(
       
   225 					MSipProfileAlrObserver::EMigrationCompleted, 
       
   226 					aIds.iProfileId,
       
   227 					aIds.iSlot1, 
       
   228 					aIds.iSlot2);
       
   229 				}
       
   230 			break;
       
   231 		case ESipProfileItcOpALRError:
       
   232 			if (iALRObserver)
       
   233 				{
       
   234 				iALRObserver->AlrError(
       
   235 					aIds.iError, 
       
   236 					aIds.iProfileId,
       
   237 					aIds.iSlot1,
       
   238 					aIds.iSlot2);
       
   239 				}
       
   240 			break;
       
   241 		case ESipProfileItcOpProfileForciblyDisabled:
       
   242 			{
       
   243 			iObserver.RegistrationStatusChangedL(
       
   244 				aIds.iProfileId, 
       
   245 				CSIPConcreteProfile::EUnregistered, 
       
   246 				aIds.iEventId);
       
   247 			break;
       
   248 			}
       
   249 		default:
       
   250 			User::Leave(KErrNotSupported);
       
   251 		}
       
   252 	}
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CSIPProfileITCReceiver::ErrorOccuredL
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CSIPProfileITCReceiver::ErrorOccuredL(TInt aError, TSIPProfileSlots& aIds)
       
   259 	{
       
   260 	iObserver.ErrorOccurredL(aIds.iProfileId, 
       
   261 							 CSIPConcreteProfile::ERegistrationInProgress, 
       
   262 							 aError);
       
   263 	}
       
   264 	
       
   265 // -----------------------------------------------------------------------------
       
   266 // CSIPProfileITCReceiver::SetALRObserver
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 TInt
       
   270 CSIPProfileITCReceiver::SetALRObserver(MSipProfileAlrObserver* aALRObserver)
       
   271 	{
       
   272 	if (aALRObserver && iALRObserver)
       
   273 		{
       
   274 		return KErrAlreadyExists;
       
   275 		}
       
   276 	iALRObserver = aALRObserver;
       
   277 	return KErrNone;
       
   278 	}