appfw/viewserver/server/VWSSESSN.CPP
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-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 //
       
    15 
       
    16 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    17 #include "vwsinternal.h"
       
    18 #include "vwsdefpartner.h"
       
    19 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    20 
       
    21 #include "VWSSESSN.H"
       
    22 #include "VWSERVER.H"
       
    23 #include "VWSQUEUE.H"
       
    24 #include "VWSSEVNT.H"
       
    25 #include "VWSPRIV.H"
       
    26 #include "VWSDEBUG.H"
       
    27 
       
    28 
       
    29 
       
    30 //
       
    31 // TVwsViewSwitchNotification
       
    32 //
       
    33 
       
    34 TVwsViewSwitchNotification::TVwsViewSwitchNotification()
       
    35 	: iViewId(KNullViewId), iIsOutstanding(EFalse)
       
    36 	{}
       
    37 
       
    38 void TVwsViewSwitchNotification::SetRequest(const TVwsViewId& aViewId)
       
    39 	{
       
    40 	iViewId=aViewId;
       
    41 	iIsOutstanding=ETrue;
       
    42 	}
       
    43 
       
    44 void TVwsViewSwitchNotification::ClearRequest()
       
    45 	{
       
    46 	iViewId=KNullViewId;
       
    47 	iIsOutstanding=EFalse;
       
    48 	}
       
    49 
       
    50 TBool TVwsViewSwitchNotification::IsViewToNotify(const TVwsViewId& aViewId) const
       
    51 	{
       
    52 	return (iIsOutstanding && (aViewId==iViewId || iViewId==KNullViewId));
       
    53 	}
       
    54 
       
    55 
       
    56 //
       
    57 // CVwsSession.
       
    58 //
       
    59 
       
    60 const TInt KVwsViewArrayGranularity=4;
       
    61 
       
    62 
       
    63 CVwsSession::~CVwsSession()
       
    64 	{
       
    65 	iIsExiting=ETrue;
       
    66 	iServer.HandleSessionRemoval(iClientThreadId);
       
    67 	delete iEventQueue;
       
    68 	delete iClientMessage;
       
    69 	}
       
    70 
       
    71 CVwsSession* CVwsSession::NewL(const TThreadId& aThreadId,CVwsServer& aServer)
       
    72 	{
       
    73 	CVwsSession* self=new(ELeave) CVwsSession(aThreadId,aServer);
       
    74 	CleanupStack::PushL(self);
       
    75 	self->ConstructL();
       
    76 	CleanupStack::Pop();
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 CVwsSession::CVwsSession(const TThreadId& aThreadId,CVwsServer& aServer)
       
    81 	:iServer(aServer),
       
    82 	iViewIdArray(KVwsViewArrayGranularity),
       
    83 	iActiveViewIndex(-1),
       
    84 	iLastActiveViewIndex(-1),
       
    85 	iClientThreadId(aThreadId),
       
    86 	iIsExiting(EFalse)
       
    87 	{
       
    88 	}
       
    89 
       
    90 void CVwsSession::ConstructL()
       
    91 	{
       
    92 #ifdef __DO_LOGGING__
       
    93 	iEventQueue=new(ELeave) CVwsEventQueue(_L("Session Queue (client unknown)"));
       
    94 #else
       
    95 	iEventQueue=new(ELeave) CVwsEventQueue;
       
    96 #endif
       
    97 	}
       
    98 
       
    99 void CVwsSession::ServiceL(const RMessage2& aMessage)
       
   100 	{
       
   101 	TBool completeMessage=ETrue;
       
   102 	switch (aMessage.Function())
       
   103 		{
       
   104 		case EVwsAsynchronousMessageForServerToPanicClientWith:
       
   105 			iPanicMessage=aMessage;
       
   106 			completeMessage=EFalse;
       
   107 			break;
       
   108 		case EVwsClose:
       
   109 			CActiveScheduler::Stop();
       
   110 			break;
       
   111 		case EVwsAddView:
       
   112 			AddViewL(aMessage);
       
   113 			break;
       
   114 		case EVwsSetSystemDefaultView:
       
   115 			SetSystemDefaultViewL(aMessage);
       
   116 			break;
       
   117 		case EVwsGetSystemDefaultView:
       
   118 			GetSystemDefaultViewL(aMessage);
       
   119 			break;
       
   120 		case EVwsRemoveView:
       
   121 			RemoveViewL(aMessage);
       
   122 			break;
       
   123 		case EVwsRequestViewEvent:
       
   124 			RequestViewEventL(aMessage);
       
   125 			completeMessage=EFalse;
       
   126 			break;
       
   127 		case EVwsRequestViewEventCancel:
       
   128 			CancelRequestViewEvent();
       
   129 			break;
       
   130 		case EVwsActivateView:
       
   131 			ActivateViewL(aMessage,ECompleteRequest);
       
   132 			completeMessage=EFalse;
       
   133 			break;
       
   134 		case EVwsCreateActivateViewEvent:
       
   135 			ActivateViewL(aMessage,EDoNotCompleteRequest);
       
   136 			break;
       
   137 		case EVwsRequestCustomMessage:
       
   138 			RequestCustomMessageL(aMessage);
       
   139 			break;
       
   140 		case EVwsStartApp:
       
   141 			StartAppL(aMessage);
       
   142 			completeMessage=EFalse;
       
   143 			break;
       
   144 		case EVwsDeactivateActiveView:
       
   145 			DeactivateActiveViewL(aMessage,ECompleteRequest);
       
   146 			completeMessage=EFalse;
       
   147 			break;
       
   148 		case EVwsDeactivateActiveViewIfOwnerMatch:
       
   149  			DeactivateActiveViewIfOwnerMatchL(aMessage,ECompleteRequest);
       
   150  			completeMessage=EFalse;
       
   151  			break;
       
   152 		case EVwsCreateDeactivateViewEvent:
       
   153 			DeactivateActiveViewL(aMessage,EDoNotCompleteRequest);
       
   154 			break;
       
   155 		case EVwsNotifyNextDeactivation:
       
   156 			NotifyNextDeactivationL(aMessage);
       
   157 			break;
       
   158 		case EVwsNotifyNextActivation:
       
   159 			NotifyNextActivationL(aMessage);
       
   160 			break;
       
   161 		case EVwsSetClientRequestTimeOut:
       
   162 			SetClientRequestTimeOut(aMessage);
       
   163 			break;
       
   164 		case EVwsSetServerEventTimeOut:
       
   165 			SetServerEventTimeOut(aMessage);
       
   166 			break;
       
   167 		case EVwsEnableServerEventTimeOut:
       
   168 			EnableServerEventTimeOut(aMessage);
       
   169 			break;
       
   170 		case EVwsCheckSourceOfViewSwitch:
       
   171 			CheckSourceOfViewSwitchL(aMessage);
       
   172 			break;
       
   173 		case EVwsPriority:
       
   174 			GetPriorityForActiveObjectL(aMessage);
       
   175 			break; 
       
   176 		case EVwsEnableServerBlankScreen:
       
   177 			EnableServerBlankScreen(aMessage);
       
   178 			break;
       
   179 		case EVwsSetProtected:
       
   180 			SetProtectedL(aMessage);
       
   181 			break;
       
   182 		case EVwsSetCrossCheckUid:
       
   183 			iServer.SetCrossCheckUid(aMessage);
       
   184 			break;
       
   185 		case EVwsSetWindowBackgroundColor:
       
   186 			iServer.SetWindowBackgroundColor(aMessage);
       
   187 			break;
       
   188 		case EVwsCurrentActiveViewId:
       
   189 			GetCurrentActiveViewIdL(aMessage);
       
   190 			break;
       
   191 		default:
       
   192 			PanicClient(aMessage,EVwsBadRequest);
       
   193 		}
       
   194 	if (completeMessage && !aMessage.IsNull())
       
   195 		{
       
   196 		LOG3(CVwsLog::ENormal,_L("Auto completing with %d"),KErrNone);
       
   197 		aMessage.Complete(KErrNone);
       
   198 		}
       
   199 	}
       
   200 
       
   201 void CVwsSession::ServiceError(const RMessage2& aMessage,TInt aError)
       
   202 	{
       
   203 	LOG3(CVwsLog::ENormal,_L("Auto completing with %d"),aError);
       
   204 	CSession2::ServiceError(aMessage,aError);
       
   205 	}
       
   206 
       
   207 
       
   208 void CVwsSession::PanicClient(const RMessage2& aMessage,TInt aPanic)
       
   209 	{
       
   210 	if (!aMessage.IsNull())
       
   211 		{
       
   212 		aMessage.Panic(_L("ViewSrv"),aPanic);
       
   213 		}
       
   214 	}
       
   215 
       
   216 void CVwsSession::PanicClient(TInt aPanic)
       
   217 	{
       
   218 	__ASSERT_DEBUG(aPanic!=0,User::Invariant());
       
   219 	PanicClient(iPanicMessage,aPanic);
       
   220 	}
       
   221 
       
   222 
       
   223 TUid CVwsSession::AppUid() const
       
   224 	{
       
   225 	return iAppUid;
       
   226 	}
       
   227 
       
   228 CVwsSession::TState CVwsSession::State() const
       
   229 	{
       
   230 	return iState;
       
   231 	}
       
   232 
       
   233 void CVwsSession::RequestClientActivationL(MVwsSessionObserver& aObserver,const TVwsViewId& aViewId,
       
   234 										   const TVwsViewId& aPreviousViewId,CVwsClientMessage* aClientMessage,RThread aThreadOfClientInitiatingViewSwitch)
       
   235 	{
       
   236 	User::LeaveIfError(aThreadOfClientInitiatingViewSwitch.Duplicate(RThread()));
       
   237 	CleanupClosePushL(aThreadOfClientInitiatingViewSwitch);
       
   238 	CVwsSessionEvent* activationEvent=new(ELeave) CVwsSessionEvent_Activation(*this,*iEventQueue,aObserver,aViewId,aPreviousViewId,aClientMessage,aThreadOfClientInitiatingViewSwitch);
       
   239 	aObserver.NowObserving(activationEvent);
       
   240 	CleanupStack::Pop(&aThreadOfClientInitiatingViewSwitch);
       
   241 	TRAPD(err, iEventQueue->ProcessEventL(activationEvent))
       
   242 	if(err!=KErrNone)
       
   243 		{
       
   244 		iLeaveAfterOwnershipTaken=ETrue;
       
   245 		User::Leave(err);
       
   246 		};
       
   247 	}
       
   248 
       
   249 void CVwsSession::RequestClientDeactivationL(MVwsSessionObserver& aObserver,const TVwsViewId& aViewId,const TVwsViewId& aActiveViewId, TBool aDifferentInstanceOfSameApp)
       
   250 	{
       
   251 	CVwsSessionEvent* deactivationEvent=new(ELeave) CVwsSessionEvent_Deactivation(*this,*iEventQueue,aObserver,aViewId,aActiveViewId, aDifferentInstanceOfSameApp);
       
   252 	aObserver.NowObserving(deactivationEvent);
       
   253 	iEventQueue->ProcessEventL(deactivationEvent);
       
   254 	}
       
   255 
       
   256 void CVwsSession::RequestScreenDeviceChangeNotificationL(MVwsSessionObserver& aObserver,const TVwsViewId& aViewId)
       
   257 	{
       
   258 	CVwsSessionEvent* screenDeviceChangeEvent=new(ELeave) CVwsSessionEvent_ScreenDeviceChangeNotification(*this,*iEventQueue,aObserver,aViewId);
       
   259 	aObserver.NowObserving(screenDeviceChangeEvent);
       
   260 	iEventQueue->ProcessEventL(screenDeviceChangeEvent);
       
   261 	}
       
   262 
       
   263 void CVwsSession::SetMessageHandler(MVwsMessageHandler& aMessageHandler)
       
   264 	{
       
   265 	ASSERT(iMessageHandler==NULL);
       
   266 	iMessageHandler=&aMessageHandler;
       
   267 	}
       
   268 
       
   269 void CVwsSession::ClearMessageHandler()
       
   270 	{
       
   271 	ASSERT(iMessageHandler);
       
   272 	iMessageHandler=NULL;
       
   273 	}
       
   274 
       
   275 void CVwsSession::AddViewL(const RMessage2& aMessage)
       
   276 	{
       
   277 	TVwsViewId viewId(ViewIdFromMessageL(aMessage));
       
   278 
       
   279 	if (iAppUid.iUid==0)
       
   280 		{
       
   281 		iAppUid.iUid=viewId.iAppUid.iUid;
       
   282 #ifdef __DO_LOGGING__
       
   283 		TBuf<64> queueName;
       
   284 		queueName.Format(_L("Session Queue for \"%x\""),iAppUid.iUid);
       
   285 		iEventQueue->SetName(queueName);
       
   286 #endif
       
   287 		}
       
   288 	else if (iAppUid!=viewId.iAppUid)
       
   289 		{
       
   290 		// All views added by the same client should have the same app uid.
       
   291 		PanicClient(aMessage,EVwsInvalidViewUid);
       
   292 		}
       
   293 
       
   294 	LOG4(CVwsLog::ENormal,_L("Adding view \"%x,%x\""),viewId.iAppUid.iUid,viewId.iViewUid.iUid);
       
   295 	AddViewL(viewId);
       
   296 	}
       
   297 
       
   298 void CVwsSession::RemoveViewL(const RMessage2& aMessage)
       
   299 	{
       
   300 	TVwsViewId viewId(ViewIdFromMessageL(aMessage));
       
   301 	LOG4(CVwsLog::ENormal,_L("Removing view \"%x,%x\""),viewId.iAppUid.iUid,viewId.iViewUid.iUid);
       
   302 	if (RemoveView(aMessage,viewId)==KErrNotFound)
       
   303 		{
       
   304 		PanicClient(aMessage,EVwsViewNotFound);
       
   305 		}
       
   306 	}
       
   307 
       
   308 void CVwsSession::SetSystemDefaultViewL(const RMessage2& aMessage)
       
   309 	{
       
   310 	TPckgBuf<TVwsViewId> viewId;
       
   311 	aMessage.ReadL(0,viewId);
       
   312 	iServer.SetSystemDefaultViewL(aMessage.Int1(),viewId());
       
   313 	}
       
   314 
       
   315 void CVwsSession::GetSystemDefaultViewL(const RMessage2& aMessage)
       
   316 	{
       
   317 	TVwsViewId viewId;
       
   318 	iServer.GetSystemDefaultView(viewId);
       
   319 	TRAP_IGNORE(aMessage.WriteL(0,TPckgC<TVwsViewId>(viewId)));
       
   320 	}
       
   321 
       
   322 void CVwsSession::RequestViewEventL(const RMessage2& aMessage)
       
   323 	{
       
   324 	iViewEventMessage=aMessage;
       
   325 	const TInt error=aMessage.Int1();
       
   326 	switch (iState)
       
   327 		{
       
   328 		case EWaitingForClientRequest:
       
   329 			{
       
   330 			LOG4(CVwsLog::ENormal,_L("Client \"%x\" requested view event [session state: EWaitingClientRequest, last error: %d]"),iAppUid.iUid,error);
       
   331 			iState=EClientRequestPending;
       
   332 			CVwsEvent* headEvent=iEventQueue->Head();
       
   333 			if (headEvent)
       
   334 				{
       
   335 				STATIC_CAST(CVwsSessionEvent*,headEvent)->HandleViewEventRequestL(error,iViewEventMessage);
       
   336 				}
       
   337 			}
       
   338 			break;
       
   339 		case EClientRequestPending:
       
   340 			LOG3(CVwsLog::ENormal,_L("PANIC Client \"%x\" for requesting view event when one is already pending"),iAppUid.iUid);
       
   341 			PanicClient(aMessage,EVwsViewEventRequestAlreadyPending);
       
   342 			break;
       
   343 		default:
       
   344 			ASSERT(EFalse);
       
   345 		}
       
   346 	}
       
   347 
       
   348 void CVwsSession::CancelRequestViewEvent()
       
   349 	{
       
   350 	LOG3(CVwsLog::ENormal,_L("Client \"%x\" requested cancelation of view event request"),iAppUid.iUid);
       
   351 	if (iState==EClientRequestPending)
       
   352 		{
       
   353 		CompleteViewEvent(KErrCancel);
       
   354 		}
       
   355 	}
       
   356 
       
   357 void CVwsSession::CompleteViewEvent(TInt aNotification)
       
   358 	{
       
   359 	ASSERT(iState==EClientRequestPending);
       
   360 
       
   361 	if (iState==EClientRequestPending)
       
   362 		{
       
   363 		LOG4(CVwsLog::ENormal,_L("Completing view event in client \"%x\" with \"%d\""),iAppUid.iUid,aNotification);
       
   364 		iViewEventMessage.Complete(aNotification);
       
   365 		iState=EWaitingForClientRequest;
       
   366 		}
       
   367 	else
       
   368 		{
       
   369 		LOG3(CVwsLog::ELoud,_L("Completing view event in client \"%x\" - ERROR: No pending client request!"),iAppUid.iUid);
       
   370 		}
       
   371 	}
       
   372 
       
   373 void CVwsSession::CompleteViewEventL(TInt aNotification,const TVwsViewEvent& aEvent)
       
   374 	{
       
   375 	ASSERT(iState==EClientRequestPending);
       
   376 
       
   377 	if (aNotification==KErrNone && iState==EClientRequestPending)
       
   378 		{
       
   379 		LOG3(CVwsLog::ENormal,_L("Writing view event buffer to client \"%x\""),iAppUid.iUid);
       
   380 		iViewEventMessage.WriteL(0,TPckgC<TVwsViewEvent>(aEvent));
       
   381 		}
       
   382 	CompleteViewEvent(aNotification);
       
   383 	}
       
   384 
       
   385 void CVwsSession::ActivateViewL(const RMessage2& aMessage,TVwsCompleteRequest aCompleteRequest)
       
   386 	{
       
   387 	TPckgBuf<TVwsViewId> viewId;
       
   388 	aMessage.ReadL(0,viewId);
       
   389 	LOG5(CVwsLog::ENormal,_L("Client \"%x\" requested activation of \"%x,%x\""),iAppUid.iUid,viewId().iAppUid.iUid,viewId().iViewUid.iUid);
       
   390 	CVwsClientMessage* clientMessage=CVwsClientMessage::NewL(TUid::Uid(aMessage.Int1()),User::LeaveIfError(aMessage.GetDesLength(2)),aMessage,2);
       
   391 	LOG2(CVwsLog::ENormal,_L("Allocated custom message"));
       
   392 	iServer.ActivateViewL(viewId(),clientMessage,aMessage,*this,aCompleteRequest);
       
   393 	}
       
   394 
       
   395 void CVwsSession::RequestCustomMessageL(const RMessage2& aMessage)
       
   396 	{
       
   397 	if (iMessageHandler==NULL)
       
   398 		{
       
   399 		User::Leave(KErrUnknown);
       
   400 		}
       
   401 	iMessageHandler->WriteClientMessageL(aMessage);
       
   402 	}
       
   403 
       
   404 TVwsViewId CVwsSession::ViewIdFromMessageL(const RMessage2& aMessage)
       
   405 	{
       
   406 	TPckgBuf<TVwsViewId> viewIdBuf;
       
   407 	aMessage.ReadL(0,viewIdBuf);
       
   408 	return viewIdBuf();
       
   409 	}
       
   410 
       
   411 void CVwsSession::StartAppL(const RMessage2& aMessage)
       
   412 	{
       
   413 	TUid appToStart={aMessage.Int0()};
       
   414 	iServer.RequestAppStartL(aMessage,appToStart);
       
   415 	}
       
   416 
       
   417 void CVwsSession::DeactivateActiveViewL(const RMessage2& aMessage,TVwsCompleteRequest aCompleteRequest)
       
   418 	{
       
   419 	iServer.RequestDeactivateActiveViewL(aMessage,*this,aCompleteRequest);
       
   420 	}
       
   421 void CVwsSession::DeactivateActiveViewIfOwnerMatchL(const RMessage2& aMessage,TVwsCompleteRequest aCompleteRequest)
       
   422  	{
       
   423  	if(iServer.ActiveViewSession() == this)
       
   424  		{
       
   425  		return DeactivateActiveViewL(aMessage, aCompleteRequest);
       
   426  		}
       
   427  	else if(aCompleteRequest==ECompleteRequest)
       
   428  		{
       
   429  		aMessage.Complete(KErrNone);
       
   430  		}
       
   431  	}
       
   432 
       
   433 void CVwsSession::NotifyNextDeactivationL(const RMessage2& aMessage)
       
   434 	{
       
   435 	iDeactivationNotification.SetRequest(ViewIdFromMessageL(aMessage));
       
   436 	}
       
   437 
       
   438 void CVwsSession::HandleDeactivationL(const TVwsViewId& aDeactivatedViewId, const TVwsViewId& aActivatedViewId)
       
   439 	{
       
   440 	if (iDeactivationNotification.IsViewToNotify(aDeactivatedViewId))
       
   441 		{
       
   442 		LOG3(CVwsLog::ENormal,_L("Requesting deactivation notification in \"%x\""),iAppUid);
       
   443 		iDeactivationNotification.ClearRequest();
       
   444 		CVwsSessionEvent* deactivationNotificationEvent=new(ELeave) CVwsSessionEvent_DeactivationNotification(*this,*iEventQueue,aDeactivatedViewId,aActivatedViewId);
       
   445 		iEventQueue->ProcessEventL(deactivationNotificationEvent);
       
   446 		}
       
   447 	}
       
   448 
       
   449 void CVwsSession::NotifyNextActivationL(const RMessage2& aMessage)
       
   450 	{
       
   451 	iActivationNotification.SetRequest(ViewIdFromMessageL(aMessage));
       
   452 	}
       
   453 
       
   454 void CVwsSession::HandleActivationL(const TVwsViewId& aActivatedViewId, const TVwsViewId& aViewToBeDeactivatedId)
       
   455 	{
       
   456 	if (iActivationNotification.IsViewToNotify(aActivatedViewId))
       
   457 		{
       
   458 		LOG3(CVwsLog::ENormal,_L("Requesting activation notification in \"%x\""),iAppUid);
       
   459 		iActivationNotification.ClearRequest();
       
   460 		CVwsSessionEvent* activationNotificationEvent=new(ELeave) CVwsSessionEvent_ActivationNotification(*this,*iEventQueue,aActivatedViewId,aViewToBeDeactivatedId);
       
   461 		iEventQueue->ProcessEventL(activationNotificationEvent);
       
   462 		}
       
   463 	}
       
   464 
       
   465 void CVwsSession::SetClientRequestTimeOut(const RMessage2& aMessage)
       
   466 	{
       
   467 	iServer.SetClientRequestTimeOut(TTimeIntervalMicroSeconds32(REINTERPRET_CAST(TInt32,aMessage.Ptr0())));
       
   468 	}
       
   469 
       
   470 void CVwsSession::SetServerEventTimeOut(const RMessage2& aMessage)
       
   471 	{
       
   472 	iServer.SetServerEventTimeOut(TTimeIntervalMicroSeconds32(REINTERPRET_CAST(TInt32,aMessage.Ptr0())));
       
   473 	}
       
   474 
       
   475 void CVwsSession::EnableServerEventTimeOut(const RMessage2& aMessage)
       
   476 	{
       
   477 	iServer.EnableServerEventTimeOut(TBool(REINTERPRET_CAST(TInt32,aMessage.Ptr0())));
       
   478 	}
       
   479 
       
   480 void CVwsSession::EnableServerBlankScreen(const RMessage2& aMessage)
       
   481 	{
       
   482 	iServer.EnableServerBlankScreen(aMessage.Int0());
       
   483 	}
       
   484 
       
   485 void CVwsSession::CheckSourceOfViewSwitchL(const RMessage2& aMessage)
       
   486 	{
       
   487 	if (iMessageHandler==NULL)
       
   488 		{
       
   489 		User::Leave(KErrUnknown);
       
   490 		}
       
   491 	iMessageHandler->CheckSourceOfViewSwitchL(aMessage);
       
   492 	}
       
   493 
       
   494 void CVwsSession::SetProtectedL(const RMessage2& aMessage)
       
   495 	{
       
   496 	iProtected = (aMessage.Int0() != 0);
       
   497 	}
       
   498 
       
   499 
       
   500 TInt CVwsSession::IndexById(const TVwsViewId& aViewId) const
       
   501 	{
       
   502 	const TInt numViews=iViewIdArray.Count();
       
   503 	for (TInt ii=0;ii<numViews;ii++)
       
   504 		{
       
   505 		if (iViewIdArray[ii] == aViewId)
       
   506 			{
       
   507 			return ii;
       
   508 			}
       
   509 		}
       
   510 
       
   511 	return KErrNotFound;
       
   512 	}
       
   513 
       
   514 TInt CVwsSession::GetTopView(TVwsViewId& aViewId)
       
   515 	{
       
   516 	TInt ret=KErrNone;
       
   517 	const TInt numViews=iViewIdArray.Count();
       
   518 	if (numViews && iLastActiveViewIndex!=-1 && iLastActiveViewIndex<numViews)
       
   519 		{
       
   520 		aViewId=iViewIdArray[(iLastActiveViewIndex) ? iLastActiveViewIndex : 0];
       
   521 		}
       
   522 	else
       
   523 		{
       
   524 		ret=KErrNotFound;
       
   525 		}
       
   526 	return ret;
       
   527 	}
       
   528 
       
   529 void CVwsSession::AddViewL(const TVwsViewId& aViewId)
       
   530 	{
       
   531 	iViewIdArray.AppendL(aViewId);
       
   532 	iServer.HandleSessionViewAddition(aViewId, iClientThreadId);
       
   533 	}
       
   534 
       
   535 TInt CVwsSession::RemoveView(const RMessage2& /*aMessage*/,const TVwsViewId& aViewId)
       
   536 	{
       
   537 	TBool systemView=iServer.IsSystemDefaultView(aViewId);
       
   538 	TInt index=IndexById(aViewId);
       
   539 	if (index==iActiveViewIndex && !systemView)
       
   540 		{
       
   541 		LOG4(CVwsLog::ENormal,_L("Not removing the currently active view [\"%x,%x\"]"),aViewId.iAppUid.iUid,aViewId.iViewUid.iUid);
       
   542 		return KErrInUse;
       
   543 		}
       
   544 	else if (index>=0)
       
   545 		{
       
   546 		iViewIdArray.Delete(index);
       
   547 		if (iActiveViewIndex>index)
       
   548 			{
       
   549 			iActiveViewIndex--;
       
   550 			iLastActiveViewIndex--;
       
   551 			}
       
   552 #ifdef _DEBUG
       
   553 		if (systemView)
       
   554 			{
       
   555 			LOG4(CVwsLog::ENormal,_L("Removed system default view [\"%x,%x\"]"),aViewId.iAppUid.iUid,aViewId.iViewUid.iUid);
       
   556 			}
       
   557 #endif
       
   558 		return KErrNone;
       
   559 		}
       
   560 
       
   561 	return KErrNotFound;
       
   562 	}
       
   563 
       
   564 void CVwsSession::SetActiveView(const TVwsViewId& aViewId)
       
   565 	{
       
   566 	iActiveViewIndex=IndexById(aViewId);
       
   567 	iLastActiveViewIndex=iActiveViewIndex;
       
   568 	}
       
   569 
       
   570 TVwsViewId CVwsSession::ActiveView() const
       
   571 	{
       
   572 	if (iViewIdArray.Count()>0 && iActiveViewIndex>=0)
       
   573 		{
       
   574 		return iViewIdArray[iActiveViewIndex];
       
   575 		}
       
   576 
       
   577 	return KNullViewId;
       
   578 	}
       
   579 
       
   580 void CVwsSession::ClearActiveView()
       
   581 	{
       
   582 	iActiveViewIndex=-1;
       
   583 	}
       
   584 
       
   585 TBool CVwsSession::HasActiveView() const
       
   586 	{
       
   587 	return (iActiveViewIndex==-1) ? EFalse : ETrue;
       
   588 	}
       
   589 
       
   590 TInt CVwsSession::CheckViewExists(const TVwsViewId& aViewId) const
       
   591 	{
       
   592 	return IndexById(aViewId);
       
   593 	}
       
   594 
       
   595 TBool CVwsSession::IsViewActive(const TVwsViewId& aViewId) const
       
   596 	{
       
   597 	if (iViewIdArray.Count()>0 && iActiveViewIndex>=0)
       
   598 		{
       
   599 		if (iViewIdArray[iActiveViewIndex]==aViewId)
       
   600 			{
       
   601 			return ETrue;
       
   602 			}
       
   603 		}
       
   604 
       
   605 	return EFalse;
       
   606 	}
       
   607 
       
   608 TBool CVwsSession::Protected() const
       
   609 	{
       
   610 	return iProtected;
       
   611 	}
       
   612 
       
   613 
       
   614 //
       
   615 // CVwsClientMessage.
       
   616 //
       
   617 
       
   618 CVwsClientMessage* CVwsClientMessage::New()
       
   619 	{
       
   620 	CVwsClientMessage* self=new CVwsClientMessage();
       
   621 	return self;
       
   622 	}
       
   623 
       
   624 CVwsClientMessage* CVwsClientMessage::NewL()
       
   625 	{
       
   626 	CVwsClientMessage* self=new(ELeave) CVwsClientMessage();
       
   627 	return self;
       
   628 	}
       
   629 
       
   630 CVwsClientMessage* CVwsClientMessage::NewL(const TUid& aMessageId)
       
   631 	{
       
   632 	CVwsClientMessage* self=new(ELeave) CVwsClientMessage(aMessageId);
       
   633 	return self;
       
   634 	}
       
   635 
       
   636 CVwsClientMessage* CVwsClientMessage::NewL(const TUid& aMessageId,TInt aMessageLength,const RMessage2& aMessage,TInt aParameter)
       
   637 	{
       
   638 	CVwsClientMessage* self=new(ELeave) CVwsClientMessage(aMessageId);
       
   639 	CleanupStack::PushL(self);
       
   640 	self->ConstructL(aMessageLength,aMessage,aParameter);
       
   641 	CleanupStack::Pop();
       
   642 	return self;
       
   643 	}
       
   644 
       
   645 
       
   646 CVwsClientMessage::~CVwsClientMessage()
       
   647 	{
       
   648 	delete iMessage;
       
   649 	}
       
   650 
       
   651 CVwsClientMessage::CVwsClientMessage()	
       
   652 	{
       
   653 	}
       
   654 
       
   655 CVwsClientMessage::CVwsClientMessage(const TUid& aMessageId)
       
   656 	: iMessageId(aMessageId)
       
   657 	{
       
   658 	}
       
   659 
       
   660 void CVwsClientMessage::ConstructL(TInt aMessageLength,const RMessage2& aMessage,TInt aParameter)
       
   661 	{
       
   662 	if (aMessageLength)
       
   663 		{
       
   664 		iMessage=HBufC8::NewL(aMessageLength);
       
   665 		TPtr8 ptr(iMessage->Des());
       
   666 		aMessage.ReadL(aParameter,ptr);
       
   667 		}
       
   668 	}
       
   669 
       
   670 void CVwsSession::GetPriorityForActiveObjectL(const RMessage2& aMessage)
       
   671 	{
       
   672 	TInt priority;
       
   673 	iServer.GetPriorityForActiveObjectL(priority);
       
   674 	aMessage.WriteL(0,TPckgBuf<TInt>(priority));
       
   675 	}
       
   676 
       
   677 void CVwsSession::GetCurrentActiveViewIdL(const RMessage2& aMessage)
       
   678 	{
       
   679 	TVwsViewId activeViewId;
       
   680 	iServer.GetCurrentActiveViewId(activeViewId);
       
   681 	aMessage.WriteL(0,TPckgBuf<TVwsViewId>(activeViewId));
       
   682 	}