appfw/viewserver/client/VIEWCLI.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 #include <e32svr.h>
       
    17 
       
    18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include "vwsinternal.h"
       
    20 #include "viewclipartner.h"
       
    21 #include "vwsdefpartner.h"
       
    22 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    23 
       
    24 #include "VIEWCLI.H"
       
    25 #include "VWSPRIV.H"
       
    26 #include "VWSAPPST.H"
       
    27 #include "VWSERVER.H"
       
    28 
       
    29 
       
    30 //
       
    31 // Constants.
       
    32 //
       
    33 
       
    34 const TUint KDefaultMessageSlots=5;
       
    35 const TInt KVwsDefaultScreenDeviceMode=0;
       
    36 const TInt KVwsServerStackSize=KDefaultStackSize;
       
    37 const TInt KVwsMinHeapSize=0x2000; 
       
    38 const TInt KVwsMaxHeapSize=0x1000000; 
       
    39 
       
    40 _LIT(KVwsViewServerThreadName,"ViewServerThread");
       
    41 _LIT(KVwsViewServerName,"!ViewServer");
       
    42 
       
    43 
       
    44 //
       
    45 // Macros.
       
    46 //
       
    47 
       
    48 #define CONNECT_AS_REQUIRED	TInt err=CheckCreateViewServerSession();	if (err) {return err;}
       
    49 
       
    50 
       
    51 //
       
    52 // Global functions.
       
    53 //
       
    54 
       
    55 
       
    56 
       
    57 //
       
    58 // RVwsSession.
       
    59 //
       
    60 
       
    61 RVwsSession::RVwsSession()
       
    62 	{
       
    63 	}
       
    64 
       
    65 TInt RVwsSession::Connect()
       
    66 	{
       
    67 	TInt ret=CreateSession(KVwsViewServerName,Version(),KDefaultMessageSlots);
       
    68 	if (ret == KErrNone)
       
    69 		SendReceive(EVwsAsynchronousMessageForServerToPanicClientWith,TIpcArgs(), iPanicStatus);
       
    70 	return ret;
       
    71 	}
       
    72 
       
    73 TVersion RVwsSession::Version() const
       
    74 	{
       
    75 	return(TVersion(KVwsMajorVersionNumber,KVwsMinorVersionNumber,KVwsBuildVersionNumber));
       
    76 	}
       
    77 
       
    78 TInt RVwsSession::Shutdown() const
       
    79 	{
       
    80 	return SendReceive(EVwsClose,TIpcArgs());
       
    81 	}
       
    82 
       
    83 TInt RVwsSession::AddView(const TVwsViewId& aViewId) const
       
    84 	{
       
    85 	const TPckgC<TVwsViewId> viewId(aViewId);
       
    86 	return SendReceive(EVwsAddView,TIpcArgs(&viewId));
       
    87 	}
       
    88 
       
    89 TInt RVwsSession::SetClientRequestTimeOut(TTimeIntervalMicroSeconds32 aDuration) const
       
    90 	{
       
    91 	return SendReceive(EVwsSetClientRequestTimeOut,TIpcArgs(aDuration.Int()));
       
    92 	}
       
    93 
       
    94 TInt RVwsSession::SetServerEventTimeOut(TTimeIntervalMicroSeconds32 aDuration) const
       
    95 	{
       
    96 	return SendReceive(EVwsSetServerEventTimeOut,TIpcArgs(aDuration.Int()));
       
    97 	}
       
    98 
       
    99 TInt RVwsSession::EnableServerEventTimeOut(TBool aEnable) const
       
   100 	{
       
   101 	return SendReceive(EVwsEnableServerEventTimeOut,TIpcArgs(aEnable));
       
   102 	}
       
   103 
       
   104 TInt RVwsSession::SetSystemDefaultView(const TVwsViewId& aViewId,TInt aMode) const
       
   105 	{
       
   106 	const TPckgC<TVwsViewId> viewId(aViewId);
       
   107 	return SendReceive(EVwsSetSystemDefaultView,TIpcArgs(&viewId,aMode));
       
   108 	}
       
   109 
       
   110 TInt RVwsSession::GetSystemDefaultView(TVwsViewId& aViewId)
       
   111 	{
       
   112 	TPckg<TVwsViewId> viewId(aViewId);
       
   113 	return SendReceive(EVwsGetSystemDefaultView,TIpcArgs(&viewId));
       
   114 	}
       
   115 
       
   116 TInt RVwsSession::RemoveView(const TVwsViewId& aViewId) const
       
   117 	{
       
   118 	const TPckgC<TVwsViewId> viewId(aViewId);
       
   119 	return SendReceive(EVwsRemoveView,TIpcArgs(&viewId));
       
   120 	}
       
   121 
       
   122 void RVwsSession::RequestViewEvent(TVwsViewEventBuf& aViewEventBuf,TInt aLastError,TRequestStatus& aStatus) const
       
   123 	{
       
   124 	SendReceive(EVwsRequestViewEvent,TIpcArgs(&aViewEventBuf,aLastError,0,0),aStatus);
       
   125 	}
       
   126 	
       
   127 	void RVwsSession::RequestViewEvent(TVwsViewEventBuf& aViewEventBuf,TInt aLastError,const TVwsViewIdAndMessageBuf& aViewActivationBuf,const TDesC8& aMessage,TRequestStatus& aStatus) const
       
   128 	{
       
   129 	SendReceive(EVwsRequestViewEvent,TIpcArgs(&aViewEventBuf,aLastError,&aViewActivationBuf,&aMessage),aStatus);
       
   130 	}
       
   131 
       
   132 TInt RVwsSession::RequestViewEventCancel() const
       
   133 	{
       
   134 	return SendReceive(EVwsRequestViewEventCancel,TIpcArgs());
       
   135 	}
       
   136 
       
   137 void RVwsSession::ActivateView(const TVwsViewId& aViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage,TRequestStatus& aStatus, TInt aCustomControl)
       
   138 	{
       
   139 	iActivateViewId=aViewId;
       
   140 	iCustomMessage.Set(aCustomMessage);
       
   141 	SendReceive(EVwsActivateView,TIpcArgs(&iActivateViewId,aCustomMessageId.iUid,&iCustomMessage,aCustomControl),aStatus);
       
   142 	}
       
   143 
       
   144 TInt RVwsSession::ActivateView(const TVwsViewId& aViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage, TInt aCustomControl)
       
   145 	{
       
   146 	const TPckgC<TVwsViewId> viewId(aViewId);
       
   147 	return SendReceive(EVwsCreateActivateViewEvent,TIpcArgs(&viewId,aCustomMessageId.iUid,&aCustomMessage,aCustomControl));
       
   148 	}
       
   149 
       
   150 TInt RVwsSession::RequestCustomMessage(TDes8& aMessageBuf) const
       
   151 	{
       
   152 	return SendReceive(EVwsRequestCustomMessage,TIpcArgs(&aMessageBuf));
       
   153 	}
       
   154 
       
   155 TInt RVwsSession::StartApp(TUid aAppToStart) const
       
   156 	{
       
   157 	return SendReceive(EVwsStartApp,TIpcArgs(aAppToStart.iUid));
       
   158 	}
       
   159 
       
   160 void RVwsSession::DeactivateActiveView(TRequestStatus& aStatus) const
       
   161 	{
       
   162 	SendReceive(EVwsDeactivateActiveView,TIpcArgs(),aStatus);
       
   163 	}
       
   164 
       
   165 TInt RVwsSession::DeactivateActiveView() const
       
   166 	{
       
   167 	return SendReceive(EVwsCreateDeactivateViewEvent,TIpcArgs());
       
   168 	}
       
   169 void RVwsSession::DeactivateActiveViewIfOwnerMatch(TRequestStatus& aStatus) const
       
   170  	{
       
   171  	SendReceive(EVwsDeactivateActiveViewIfOwnerMatch,TIpcArgs(), aStatus);
       
   172  	}
       
   173  
       
   174 TInt RVwsSession::DeactivateActiveViewIfOwnerMatch() const
       
   175  	{
       
   176  	return SendReceive(EVwsDeactivateActiveViewIfOwnerMatch,TIpcArgs());
       
   177  	}
       
   178  
       
   179 
       
   180 
       
   181 TInt RVwsSession::NotifyNextDeactivation(const TVwsViewId& aViewId) const
       
   182 	{
       
   183 	const TPckgC<TVwsViewId> viewId(aViewId);
       
   184 	return SendReceive(EVwsNotifyNextDeactivation,TIpcArgs(&viewId));
       
   185 	}
       
   186 
       
   187 TInt RVwsSession::NotifyNextActivation(const TVwsViewId& aViewId) const
       
   188 	{
       
   189 	const TPckgC<TVwsViewId> viewId(aViewId);
       
   190 	return SendReceive(EVwsNotifyNextActivation,TIpcArgs(&viewId));
       
   191 	}
       
   192 
       
   193 TInt RVwsSession::GetPriority()	
       
   194 	{
       
   195 	TInt eventHandlerPriority = CActive::EPriorityStandard;
       
   196 	TPckg<TInt> package(eventHandlerPriority);
       
   197 	TInt err = SendReceive(EVwsPriority,TIpcArgs(&package));
       
   198 	if (err != KErrNone)
       
   199 		{
       
   200 		return CActive::EPriorityStandard;
       
   201 		}
       
   202 	return eventHandlerPriority;
       
   203 	}
       
   204  
       
   205 TInt RVwsSession::CheckSourceOfViewSwitch(TBool& aResult,const TSecurityPolicy& aSecurityPolicy,const char* aDiagnostic) const
       
   206 	{
       
   207 	const TPckgC<TSecurityPolicy> securityPolicy(aSecurityPolicy);
       
   208 	TBool result;
       
   209 	TPckg<TBool> resultPckg(result);
       
   210 	TIpcArgs ipcArgs(&securityPolicy,NULL,&resultPckg);
       
   211 	if (aDiagnostic == KSuppressPlatSecDiagnosticMagicValue)
       
   212     	{
       
   213     	ipcArgs.Set(1, reinterpret_cast<TInt>(KSuppressPlatSecDiagnosticMagicValue));
       
   214     	}
       
   215   	else if (aDiagnostic!=NULL)
       
   216 	    	{
       
   217 	    	TPtrC8 diagnostic(TPtrC8(REINTERPRET_CAST(const TUint8*,aDiagnostic)));
       
   218 	    	ipcArgs.Set(1,&diagnostic);
       
   219 	    	}
       
   220 
       
   221 	const TInt ret=SendReceive(EVwsCheckSourceOfViewSwitch,ipcArgs);
       
   222 	if (ret==KErrNone)
       
   223 		{
       
   224 		aResult=result;
       
   225 		}
       
   226 	return ret;
       
   227 	}
       
   228 
       
   229 TInt RVwsSession::EnableServerBlankScreen(TBool aEnable) const
       
   230 	{
       
   231 	return SendReceive(EVwsEnableServerBlankScreen,TIpcArgs(aEnable));
       
   232 	}
       
   233 
       
   234 TInt RVwsSession::SetProtected(TBool aEnable) const
       
   235 	{
       
   236 	return SendReceive(EVwsSetProtected,TIpcArgs(aEnable));
       
   237 	}
       
   238 
       
   239 TInt RVwsSession::SetCrossCheckUid(const TUid& aCrossCheckUid)
       
   240 	{
       
   241 	return SendReceive(EVwsSetCrossCheckUid,TIpcArgs(aCrossCheckUid.iUid));
       
   242 	}
       
   243 	
       
   244 TInt RVwsSession::SetWindowBackgroundColor(const TRgb& aBgColor)
       
   245 	{
       
   246 	return SendReceive(EVwsSetWindowBackgroundColor, TIpcArgs(aBgColor.Internal()));
       
   247 	}
       
   248 
       
   249 TInt RVwsSession::GetCurrentActiveViewInSystem(TVwsViewId& aActiveViewId)
       
   250 	{
       
   251 	TPckg<TVwsViewId> pckgViewId(aActiveViewId);
       
   252 	return SendReceive(EVwsCurrentActiveViewId, TIpcArgs(&pckgViewId));
       
   253 	}
       
   254 
       
   255 //
       
   256 // CVwsSessionEventHandler.
       
   257 //
       
   258 //The priority is read from the resource file
       
   259 
       
   260 CVwsSessionEventHandler::CVwsSessionEventHandler(MVwsSessionWrapperObserver& aObserver,RVwsSession& aViewServer,TInt aPriority)
       
   261 	: CActive(aPriority),iObserver(aObserver),iVwsSession(aViewServer)
       
   262  	{
       
   263 	CActiveScheduler::Add(this);
       
   264 	Queue();
       
   265 	}
       
   266 
       
   267 CVwsSessionEventHandler::~CVwsSessionEventHandler()
       
   268 	{
       
   269 	Cancel();
       
   270 	}
       
   271 
       
   272 void CVwsSessionEventHandler::Queue()
       
   273 	{
       
   274 	ASSERT(!IsActive());
       
   275 
       
   276 	if (iDoActivationNextQueue)
       
   277 		{
       
   278 		iDoActivationNextQueue=EFalse;
       
   279 		iVwsSession.RequestViewEvent(iViewEventBuf,iLastError,iViewActivationBuf,iCustomMessage,iStatus);
       
   280 		}
       
   281 	else
       
   282 		{
       
   283 		iVwsSession.RequestViewEvent(iViewEventBuf,iLastError,iStatus);
       
   284 		}
       
   285 	SetActive();
       
   286 	}
       
   287 
       
   288 void CVwsSessionEventHandler::OnNextQueueActivateView(const TVwsViewIdAndMessage& aViewIdAndMessage)
       
   289 	{
       
   290 	iViewActivationBuf=aViewIdAndMessage;
       
   291 	iCustomMessage.Set(aViewIdAndMessage.iCustomMessage);
       
   292 	iDoActivationNextQueue=ETrue;
       
   293 	}
       
   294 
       
   295 void CVwsSessionEventHandler::RunL()
       
   296 	{
       
   297 	TRAP(iLastError,iObserver.HandleViewEventL(iViewEventBuf()));
       
   298 	Queue();
       
   299 	}
       
   300 
       
   301 void CVwsSessionEventHandler::DoRunL()
       
   302 	{
       
   303 	RunL();
       
   304 	}
       
   305 
       
   306 void CVwsSessionEventHandler::DoCancel()
       
   307 	{
       
   308 	iVwsSession.RequestViewEventCancel();
       
   309 	}
       
   310 
       
   311 
       
   312 //
       
   313 // CVwsSessionWrapper.
       
   314 //
       
   315 
       
   316 
       
   317 EXPORT_C CVwsSessionWrapper* CVwsSessionWrapper::NewL()
       
   318 /**
       
   319 Creates a new CVwsSessionWrapper object.
       
   320 
       
   321 The object returned by this function cannot be used to add new views or request 
       
   322 notification of view activations or deactivations. To create an instance without these
       
   323 limitations, an MVwsSessionWrapperObserver must be specified.
       
   324 
       
   325 @return A pointer to the new CVwsSessionWrapper object.
       
   326  */
       
   327 	{
       
   328 	CVwsSessionWrapper* self=NewLC();
       
   329 	CleanupStack::Pop();
       
   330 	return self;
       
   331 	}
       
   332 
       
   333 EXPORT_C CVwsSessionWrapper* CVwsSessionWrapper::NewLC()
       
   334 /**
       
   335 Creates a new CVwsSessionWrapper object, leaving it on the cleanup stack
       
   336 
       
   337 The object returned by this function cannot be used to add new views or request 
       
   338 notification of view activations or deactivations. To create an instance without these
       
   339 limitations, an MVwsSessionWrapperObserver must be specified.
       
   340 
       
   341 @return A pointer to the new CVwsSessionWrapper object.
       
   342  */
       
   343 	{
       
   344 	CVwsSessionWrapper* self=new(ELeave) CVwsSessionWrapper();
       
   345 	CleanupStack::PushL(self);
       
   346 	self->ConstructL();
       
   347 	return self;
       
   348 	}
       
   349 
       
   350 EXPORT_C CVwsSessionWrapper* CVwsSessionWrapper::NewL(MVwsSessionWrapperObserver& aObserver)
       
   351 /**
       
   352 Creates a new CVwsSessionWrapper object.
       
   353 
       
   354 @param aObserver An implementation of MVwsSessionWrapperObserver.
       
   355                  The session observer should handle server events such as view
       
   356                  activation/deactivation requests for views owned by this session
       
   357                  and notifications of view activations/deactivations that have been
       
   358                  requested.
       
   359 
       
   360 @return A pointer to the new CVwsSessionWrapper object.
       
   361  */
       
   362 	{
       
   363 	CVwsSessionWrapper* self=NewLC(aObserver);
       
   364 	CleanupStack::Pop();
       
   365 	return self;
       
   366 	}
       
   367 
       
   368 EXPORT_C CVwsSessionWrapper* CVwsSessionWrapper::NewLC(MVwsSessionWrapperObserver& aObserver)
       
   369 /**
       
   370 Creates a new CVwsSessionWrapper object, leaving it on the cleanup stack.
       
   371 
       
   372 @param aObserver An implementation of MVwsSessionWrapperObserver.
       
   373                  The session observer should handle server events such as view
       
   374                  activation/deactivation requests for views owned by this session
       
   375                  and notifications of view activations/deactivations that have been
       
   376                  requested.
       
   377 
       
   378 @return A pointer to the new CVwsSessionWrapper object.
       
   379  */
       
   380 	{
       
   381 	CVwsSessionWrapper* self=new(ELeave) CVwsSessionWrapper(aObserver);
       
   382 	CleanupStack::PushL(self);
       
   383 	self->ConstructL();
       
   384 	return self;
       
   385 	}
       
   386 
       
   387 EXPORT_C CVwsSessionWrapper::~CVwsSessionWrapper()
       
   388 	{
       
   389 	delete iViewEventHandler;
       
   390 	if (iVwsSession)
       
   391 		{
       
   392 		iVwsSession->Close();
       
   393 		delete iVwsSession;
       
   394 		}
       
   395 	}
       
   396 
       
   397 // static
       
   398 EXPORT_C TInt CVwsSessionWrapper::StartViewServer(MVwsAppStarter& aAppStarter)
       
   399 /**
       
   400 Starts the view server, spawning a new thread in which the server will run.
       
   401  
       
   402 Takes a reference to the implementation of the MVwsAppStarter interface aAppStarter
       
   403 which it will share from the heap and which should be for the exclusive use of the view
       
   404 server only.
       
   405 
       
   406 @param aAppStarer An implementation of MVwsAppStarter that the server can use for
       
   407                   starting applications.
       
   408 
       
   409 @return A system-wide error code if the server cannot be started or is already running.
       
   410  */
       
   411 	{
       
   412 	TFindServer findServer(KVwsViewServerName);
       
   413 	TFullName name;
       
   414 	if (findServer.Next(name)==KErrNone)
       
   415 	    {
       
   416 	    return KErrAlreadyExists;
       
   417 	    }
       
   418 
       
   419 	RThread viewServerThread;
       
   420 	SVwsCommandLine comLine;
       
   421 	comLine.iAppStarter=&aAppStarter;
       
   422     TInt err = viewServerThread.Create(KVwsViewServerThreadName,ViewServerThreadStart,KVwsServerStackSize,KVwsMinHeapSize,KVwsMaxHeapSize,&comLine,EOwnerThread);
       
   423 	if (err==KErrNone)
       
   424         {
       
   425 		TRequestStatus requestStatus;
       
   426 		viewServerThread.Rendezvous(requestStatus);
       
   427 
       
   428 		viewServerThread.Resume();
       
   429 		
       
   430 		User::WaitForRequest(requestStatus);
       
   431 		err=requestStatus.Int();
       
   432 		viewServerThread.Close();
       
   433 		}
       
   434 
       
   435 	return err;
       
   436 	}
       
   437 
       
   438 EXPORT_C TInt CVwsSessionWrapper::ShutdownViewServer()
       
   439 /**
       
   440 Shut down the view server. 
       
   441 
       
   442 Establishes a connection to the view server if necessary.
       
   443 
       
   444 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   445  */
       
   446 	{
       
   447 	CONNECT_AS_REQUIRED
       
   448 	return iVwsSession->Shutdown();
       
   449 	}
       
   450 
       
   451 EXPORT_C TInt CVwsSessionWrapper::AddView(const TVwsViewId& aViewId)
       
   452 /**
       
   453 Adds the view to the list maintained by the view server.
       
   454 
       
   455 Establishes a connection to the view server if necessary.
       
   456 
       
   457 @param aViewId The view to be added to the view server's list.
       
   458 
       
   459 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   460  */	
       
   461 	{
       
   462 	CONNECT_AS_REQUIRED
       
   463 	return iVwsSession->AddView(aViewId);
       
   464 	}
       
   465 
       
   466 EXPORT_C TInt CVwsSessionWrapper::RemoveView(const TVwsViewId& aViewId) const
       
   467 /**
       
   468 Removes a view from the list maintained by the view server.
       
   469 
       
   470 @param aViewId The view to be removed from the view server's list.
       
   471 
       
   472 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   473 
       
   474 @panic USER 0 if a connection to the view server has not previously been established.
       
   475  */		
       
   476 	{
       
   477 	ASSERT(iVwsSession);
       
   478 	return iVwsSession->RemoveView(aViewId);
       
   479 	}
       
   480 
       
   481 EXPORT_C TInt CVwsSessionWrapper::SetSystemDefaultView(const TVwsViewId& aViewId,TInt aMode)
       
   482 /**
       
   483 Sets the system default view for a specific screen device mode.
       
   484 
       
   485 The system default view is the view used when an unrecoverable error in view activation occurs
       
   486 or when an application exits.
       
   487 
       
   488 Establishes a connection to the view server if necessary.
       
   489 
       
   490 @param aViewId The view to use as the system default view in the specified
       
   491                screen device mode
       
   492 @param aMode The screen device mode that should use aViewId as the system
       
   493              default view. Valid values for aMode are those listed in the Wserv
       
   494              initialization file.
       
   495              
       
   496 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   497  */
       
   498 	{
       
   499 	CONNECT_AS_REQUIRED
       
   500 	return iVwsSession->SetSystemDefaultView(aViewId,aMode);
       
   501 	}
       
   502 
       
   503 EXPORT_C TInt CVwsSessionWrapper::SetSystemDefaultView(const TVwsViewId& aViewId)
       
   504 /**
       
   505 Sets the system default view for the default screen device mode.
       
   506 
       
   507 Establishes a connection to the view server if necessary.
       
   508 
       
   509 @param aViewId The view to use as the system default view in the default screen
       
   510                device mode
       
   511              
       
   512 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   513  */
       
   514 	{
       
   515 	return SetSystemDefaultView(aViewId,KVwsDefaultScreenDeviceMode);
       
   516 	}
       
   517 
       
   518 EXPORT_C TInt CVwsSessionWrapper::GetSystemDefaultView(TVwsViewId& aViewId)
       
   519 /**
       
   520 Gets the system default view for the current screen device mode
       
   521 
       
   522 @param aViewId The ViewId of the system default view will be returned in this
       
   523                paramater.
       
   524 
       
   525 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   526  */
       
   527 	{
       
   528 	return iVwsSession->GetSystemDefaultView(aViewId);
       
   529 	}
       
   530 
       
   531 EXPORT_C TInt CVwsSessionWrapper::SetClientRequestTimeOut(TTimeIntervalMicroSeconds32 aDuration)
       
   532 /**
       
   533 Sets the time out duration for client requests.
       
   534 
       
   535 If the time taken to process a view event exceeds this limit any outstanding
       
   536 client request will silently be completed.
       
   537 
       
   538 Establishes a connection to the view server if necessary.
       
   539 
       
   540 @param aDuration The duration of the timeout, in microseconds.
       
   541 
       
   542 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   543 
       
   544 @since App-Framework_6.1
       
   545  */
       
   546 	{
       
   547 	CONNECT_AS_REQUIRED
       
   548 	return iVwsSession->SetClientRequestTimeOut(aDuration);
       
   549 	}
       
   550 
       
   551 EXPORT_C TInt CVwsSessionWrapper::SetServerEventTimeOut(TTimeIntervalMicroSeconds32 aDuration)
       
   552 /**
       
   553 Sets the time out duration for server events.
       
   554 
       
   555 If the time taken to process a view event exceeds this limit the server event
       
   556 will be completed. If a client is preventing the view event from completing
       
   557 the server will panic that client.
       
   558 
       
   559 Establishes a connection to the view server if necessary.
       
   560 
       
   561 @param aDuration The duration of the timeout, in microseconds.
       
   562 
       
   563 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   564 
       
   565 @since App-Framework_6.1
       
   566  */
       
   567 	{
       
   568 	CONNECT_AS_REQUIRED
       
   569 	return iVwsSession->SetServerEventTimeOut(aDuration);
       
   570 	}
       
   571 
       
   572 EXPORT_C TInt CVwsSessionWrapper::EnableServerEventTimeOut(TBool aEnable)
       
   573 /**
       
   574 Enables or disables the server event time out.
       
   575 
       
   576 This may be called, for example, when debugging on target hardware since server
       
   577 event processing can be interrupted indefinitely by the debugger.
       
   578 
       
   579 Establishes a connection to the view server if necessary.
       
   580 
       
   581 @param aEnable The timeout is enabled if aEnable is set to ETrue, and disabled
       
   582                if aEnable is set to EFalse
       
   583 
       
   584 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   585 
       
   586 @since App-Framework_6.1
       
   587  */
       
   588 	{
       
   589 	CONNECT_AS_REQUIRED
       
   590 	return iVwsSession->EnableServerEventTimeOut(aEnable);
       
   591 	}
       
   592 
       
   593 /**
       
   594 Sets the session default view for the screen device mode aMode to aViewId.
       
   595 Valid values for aMode are those listed in the Wserv initialisation file.
       
   596 
       
   597 As of R6 this function has no effect.
       
   598 
       
   599 @deprecated
       
   600 
       
   601 @return KErrNone.
       
   602  */
       
   603 EXPORT_C TInt CVwsSessionWrapper::SetDefaultView(const TVwsViewId& /*aViewId*/,TInt /*aMode*/) const
       
   604 	{
       
   605 	return KErrNone;
       
   606 	}
       
   607 
       
   608 EXPORT_C TInt CVwsSessionWrapper::SetDefaultView(const TVwsViewId& aViewId) const
       
   609 /**
       
   610 Overloaded member funtion that sets the session default view for the
       
   611 default screen device mode to aViewId.
       
   612 
       
   613 As of R6 this funtion has no effect.
       
   614 
       
   615 @deprecated
       
   616 
       
   617 @return KErrNone.
       
   618  */
       
   619 	{
       
   620 	return SetDefaultView(aViewId,KVwsDefaultScreenDeviceMode);
       
   621 	}
       
   622 
       
   623 EXPORT_C TInt CVwsSessionWrapper::ActivateView(const TVwsViewId& aViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage)
       
   624 /**
       
   625 Activates a view.
       
   626 
       
   627 Supplies the narrow message text descriptor aCustomMessage for the message type
       
   628 identified by aCustomMessageId to the server.
       
   629 
       
   630 Establishes a connection to the view server if necessary.
       
   631 Starts the application which owns the view if necessary.
       
   632 
       
   633 Once a new view is activated the current view is deactivated and the new view
       
   634 is marked as current.
       
   635 
       
   636 If this thread has an active environment the method returns when view
       
   637 activation completes. Otherwise the method returns
       
   638 immediately after creating an activation event in the view server.
       
   639 
       
   640 @param aViewId The view to activate
       
   641 @param aCustomMessageId The message type being passed in aCustomMessage.
       
   642 @param aCustomMessage  A custom message for the view being activated.
       
   643 
       
   644 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   645  */			
       
   646 	{
       
   647 	return ActivateView(aViewId, aCustomMessageId, aCustomMessage, 0);
       
   648 	}
       
   649 
       
   650 EXPORT_C TInt CVwsSessionWrapper::ActivateView(const TVwsViewId& aViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage, TInt aCustomControl)
       
   651 	{
       
   652 	CONNECT_AS_REQUIRED
       
   653 
       
   654 	if (!IsSchedulerRunning())
       
   655 		{
       
   656 		return iVwsSession->ActivateView(aViewId,aCustomMessageId,aCustomMessage, aCustomControl);
       
   657 		}
       
   658 	else
       
   659 		{
       
   660 		TRequestStatus status;
       
   661 		iVwsSession->ActivateView(aViewId,aCustomMessageId,aCustomMessage,status, aCustomControl);
       
   662 		TInt error=KErrNone;
       
   663 		for (;;)
       
   664 			{
       
   665 			if (iViewEventHandler)
       
   666 				{
       
   667 				User::WaitForRequest(status, iViewEventHandler->iStatus);
       
   668 				}
       
   669 			else
       
   670 				{
       
   671 				User::WaitForRequest(status);
       
   672 				}
       
   673 			if (status!=KRequestPending)
       
   674 				break;
       
   675 			if (iViewEventHandler && iViewEventHandler->iStatus!=KRequestPending)
       
   676 				{
       
   677 				// Set the event handler active object to inactive to avoid it running
       
   678 				// a second time if the DoRunL call results in a new active scheduler
       
   679 				// loop being started.
       
   680 				TRequestStatus* eventHandlerStatus = &iViewEventHandler->iStatus;
       
   681 				User::RequestComplete(eventHandlerStatus, iViewEventHandler->iStatus.Int());
       
   682 				iViewEventHandler->Cancel();
       
   683 				TRAP(error,iViewEventHandler->DoRunL(););	// Run event handler directly and request new view event.
       
   684 				if (error != KErrNone)
       
   685 					{
       
   686 					break;
       
   687 					}
       
   688 				}
       
   689 			}
       
   690 
       
   691 		return (error != KErrNone) ? error : status.Int();
       
   692 		}
       
   693 	}
       
   694 
       
   695 EXPORT_C void CVwsSessionWrapper::ActivateView(
       
   696 									const TVwsViewId& aViewId,
       
   697 									TUid aCustomMessageId,
       
   698 									const TDesC8& aCustomMessage,
       
   699 									TRequestStatus& aStatus)
       
   700 /**
       
   701 Activates a view asynchronously.
       
   702 
       
   703 Supplies the narrow message text descriptor aCustomMessage for the message type
       
   704 identified by aCustomMessageId to the server.
       
   705 
       
   706 Establishes a connection to the view server if necessary.
       
   707 Starts the application which owns the view if necessary.
       
   708 
       
   709 Once a new view is activated the current view is deactivated and the new view
       
   710 is marked as current.
       
   711 
       
   712 This function will return immediately
       
   713 
       
   714 @param aViewId The view to activate
       
   715 @param aCustomMessageId The message type being passed in aCustomMessage.
       
   716 @param aCustomMessage  A custom message for the view being activated.
       
   717 @param aStatus A TRequestStatus for the view activation. The request will be
       
   718                completed when the the view has been activated or when the
       
   719                view activation has failed.
       
   720 
       
   721 @return KErrNone if the request was dispatched successfully, otherwise one of
       
   722         the system-wide error codes.
       
   723  */
       
   724 	{
       
   725 	ActivateView(aViewId, aCustomMessageId, aCustomMessage, aStatus, 0);
       
   726 	}
       
   727 	
       
   728 EXPORT_C void CVwsSessionWrapper::ActivateView(
       
   729 									const TVwsViewId& aViewId,
       
   730 									TUid aCustomMessageId,
       
   731 									const TDesC8& aCustomMessage,
       
   732 									TRequestStatus& aStatus, TInt aCustomControl)
       
   733 	{
       
   734 	TInt res = CheckCreateViewServerSession();
       
   735 	if (res != KErrNone)
       
   736 		{
       
   737 		TRequestStatus* status = &aStatus;
       
   738 		User::RequestComplete(status, res);
       
   739 		return;
       
   740 		}
       
   741 	iVwsSession->ActivateView(aViewId, aCustomMessageId, aCustomMessage, aStatus, aCustomControl);
       
   742 	}
       
   743 
       
   744 EXPORT_C TInt CVwsSessionWrapper::CreateActivateViewEvent(const TVwsViewId& aViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage)
       
   745 /**
       
   746 Creates an event to be processed to activate the view identified by aViewId and
       
   747 returns without waiting for the activation to complete. Passes the view the
       
   748 message text descriptor aCustomMessage for a message of type aCustomMessageId.
       
   749 
       
   750 Note that this method may return without error but the activation may subsequently fail.
       
   751 
       
   752 Establishes a connection to the view server if necessary.
       
   753 
       
   754 @param aViewId The view to activate
       
   755 @param aCustomMessageId The message type being passed in aCustomMessage.
       
   756 @param aCustomMessage  A custom message for the view being activated.
       
   757 
       
   758 @return KErrNone if the request was dispatched successfully, otherwise one of
       
   759         the system-wide error codes.
       
   760  */
       
   761 	{
       
   762 	return CreateActivateViewEvent(aViewId, aCustomMessageId, aCustomMessage, 0);
       
   763 	}
       
   764 
       
   765 EXPORT_C TInt CVwsSessionWrapper::CreateActivateViewEvent(const TVwsViewId& aViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage, TInt aCustomControl)
       
   766 	{
       
   767 	CONNECT_AS_REQUIRED
       
   768 
       
   769 	return iVwsSession->ActivateView(aViewId, aCustomMessageId, aCustomMessage, aCustomControl);
       
   770 	}
       
   771 
       
   772 EXPORT_C TInt CVwsSessionWrapper::ActivateViewViaViewEvent(const TVwsViewIdAndMessage& aViewIdAndMessage)
       
   773 /**
       
   774 Activates the view identified in aViewIdAndMessage on the next queue of the
       
   775 session's view event handler. This activation path should be used for
       
   776 activation requests that come via view events.
       
   777 
       
   778 For example, a screen device change will generate a view event in the active
       
   779 view. The active view is then responsible for choosing the next view to
       
   780 activate. Using this activation path ensures that the view activation is
       
   781 processed immediately by the server.
       
   782 
       
   783 Establishes a connection to the view server if necessary.
       
   784 
       
   785 @param aViewIdAndMessage An object encapsulating the view to activate and
       
   786                          the message to be passed to it with the activation
       
   787                          event
       
   788 
       
   789 @return KErrNone
       
   790 */
       
   791 	{
       
   792 	CONNECT_AS_REQUIRED
       
   793 
       
   794 	if (iViewEventHandler)
       
   795 		{
       
   796 		iViewEventHandler->OnNextQueueActivateView(aViewIdAndMessage);
       
   797 		}
       
   798 	return KErrNone;
       
   799 	}
       
   800 
       
   801 /**
       
   802 Retrives the custom message contents for the event currently being processsed
       
   803 from the server.
       
   804 
       
   805 This method is typically called when the MVwsSessionObserver is notified that
       
   806 it should activate a new view.
       
   807 
       
   808 @param aMessageBufPtr The narrow descriptor for the custom message contents to
       
   809                       be written to.
       
   810  
       
   811 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   812 
       
   813 @panic USER 0 If a connection to the view server has not previously been established
       
   814  */
       
   815 EXPORT_C TInt CVwsSessionWrapper::RequestCustomMessage(TDes8& aMessageBufPtr) const
       
   816 	{
       
   817 	ASSERT(iVwsSession);
       
   818 	return iVwsSession->RequestCustomMessage(aMessageBufPtr);
       
   819 	}
       
   820 
       
   821 /**
       
   822 Queues an asynchronous view server event request. This method should be called
       
   823 by the active scheduler so that an outstanding request for view server event
       
   824 notification is maintained. The view server interprets the first queue made by
       
   825 a session as the sign that the session application is up and runnning.
       
   826 
       
   827 This method is now deprecated becasue the requests are now automatically queued
       
   828 by CVwsSessionWrapper.
       
   829 
       
   830 @deprecated
       
   831  */
       
   832 EXPORT_C void CVwsSessionWrapper::QueueAsyncRequest()
       
   833 	{
       
   834 	if (iViewEventHandler)
       
   835 		{
       
   836 		iViewEventHandler->Queue();
       
   837 		}
       
   838 	}
       
   839 
       
   840 /**
       
   841 Starts the application with Uid aAppToStart.
       
   842 
       
   843 Establishes a connection to the view server if necessary.
       
   844 
       
   845 The request is queued in the server and processed in turn. The application will
       
   846 be started by a call to the implementation of the MVwsAppStarter interface that
       
   847 is provided at server start up. 
       
   848 
       
   849 This method provides an alternative to apparc for starting apps on systems
       
   850 where use of the view server is preferred to use of the apparc server.
       
   851  
       
   852 
       
   853 @param aAppToStart The Uid of the app that should be started.
       
   854 
       
   855 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   856  */
       
   857 EXPORT_C TInt CVwsSessionWrapper::StartApp(TUid aAppToStart)
       
   858 	{
       
   859 	CONNECT_AS_REQUIRED
       
   860 	return iVwsSession->StartApp(aAppToStart);
       
   861 	}
       
   862 
       
   863 /**
       
   864 Note: DeactivateActiveViewIfOwnerMatch should be used instead of this function
       
   865       where it is appropriate.
       
   866       
       
   867 Deactivates the active view. This is required before exiting an application
       
   868 with an active view.
       
   869 
       
   870 Establishes a connection to the view server if necessary.
       
   871 
       
   872 If this thread has an active environment the method returns when view
       
   873 deactivation completes. Otherwise the method returns immediately after creating
       
   874 a deactivation event in the view server.
       
   875 
       
   876 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   877 
       
   878 @see CVwsSessionWrapper::DeactivateActiveViewIfOwnerMatch
       
   879 */
       
   880 EXPORT_C TInt CVwsSessionWrapper::DeactivateActiveView()
       
   881 	{
       
   882 	CONNECT_AS_REQUIRED
       
   883 
       
   884 	if (!IsSchedulerRunning())
       
   885 		{
       
   886 		return iVwsSession->DeactivateActiveView();
       
   887 		}
       
   888 	else
       
   889 		{
       
   890 		TRequestStatus status;
       
   891 		iVwsSession->DeactivateActiveView(status);
       
   892 		TInt error=KErrNone;
       
   893 		for (;;)
       
   894 			{
       
   895 			if (iViewEventHandler)
       
   896 				{
       
   897 				User::WaitForRequest(status, iViewEventHandler->iStatus);
       
   898 				}
       
   899 			else
       
   900 				{
       
   901 				User::WaitForRequest(status);
       
   902 				}
       
   903 			if (status!=KRequestPending)
       
   904 				break;
       
   905 			if (iViewEventHandler && iViewEventHandler->iStatus!=KRequestPending)
       
   906 				{
       
   907 				// Set the event handler active object to inactive to avoid it running
       
   908 				// a second time if the DoRunL call results in a new active scheduler
       
   909 				// loop being started.
       
   910 				TRequestStatus* eventHandlerStatus = &iViewEventHandler->iStatus;
       
   911 				User::RequestComplete(eventHandlerStatus, iViewEventHandler->iStatus.Int());
       
   912 				iViewEventHandler->Cancel();
       
   913 				TRAP(error,iViewEventHandler->DoRunL(););	// Run event handler directly and request new view event.
       
   914 				if (error != KErrNone)
       
   915 					{
       
   916 					break;
       
   917 					}
       
   918 				}
       
   919 			}
       
   920 		return (error != KErrNone) ? error : status.Int();
       
   921 		}
       
   922 	}
       
   923 
       
   924 /**
       
   925 Deactivates the active view, but only if the active view is owned by this session.
       
   926  This is required before exiting an application with an active view.
       
   927  
       
   928  Establishes a connection to the view server if necessary.
       
   929  
       
   930  If this thread has an active environment the method returns when view
       
   931  deactivation completes. Otherwise the method returns immediately after creating
       
   932  a deactivation event in the view server.
       
   933  
       
   934  @return KErrNone if the active view was deactivated or is owned by another session, otherwise one of the system-wide error codes. 
       
   935   */
       
   936  EXPORT_C TInt CVwsSessionWrapper::DeactivateActiveViewIfOwnerMatch()
       
   937  	{
       
   938  	CONNECT_AS_REQUIRED
       
   939  
       
   940  	if (!IsSchedulerRunning())
       
   941  		{
       
   942  		return iVwsSession->DeactivateActiveViewIfOwnerMatch();
       
   943 		}
       
   944  	else
       
   945  		{
       
   946  		TRequestStatus status;
       
   947  		iVwsSession->DeactivateActiveViewIfOwnerMatch(status);
       
   948  		TInt error=KErrNone;
       
   949  		for (;;)
       
   950  			{
       
   951  			if (iViewEventHandler)
       
   952  				{
       
   953  				User::WaitForRequest(status, iViewEventHandler->iStatus);
       
   954  				}
       
   955  			else
       
   956  				{
       
   957  				User::WaitForRequest(status);
       
   958  				}
       
   959  			if (status!=KRequestPending)
       
   960  				break;
       
   961  			if (iViewEventHandler && iViewEventHandler->iStatus!=KRequestPending)
       
   962  				{
       
   963 				// Set the event handler active object to inactive to avoid it running
       
   964  				// a second time if the DoRunL call results in a new active scheduler
       
   965  				// loop being started.
       
   966  				TRequestStatus* eventHandlerStatus = &iViewEventHandler->iStatus;
       
   967  				User::RequestComplete(eventHandlerStatus, iViewEventHandler->iStatus.Int());
       
   968  				iViewEventHandler->Cancel();
       
   969  				TRAP(error,iViewEventHandler->DoRunL(););	// Run event handler directly and request new view event.
       
   970  				if (error != KErrNone)
       
   971  					{
       
   972  					break;
       
   973  					}
       
   974  				}
       
   975  			}
       
   976  		return (error != KErrNone) ? error : status.Int();
       
   977  		}
       
   978  	}
       
   979  
       
   980 /**
       
   981 
       
   982 Requests that the next deactivation of the view identified by aViewId be
       
   983 notified to this session. The request is cleared after the next notification.
       
   984 Only the last made notification request is honoured.
       
   985 
       
   986 For example, can be used when a screensaver view is deactivated by new user
       
   987 activity to reset the system state.
       
   988 
       
   989 Establishes a connection to the view server if necessary.
       
   990 
       
   991 @param aViewId The view to monitor for deactivation.
       
   992 
       
   993 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   994  */
       
   995 EXPORT_C TInt CVwsSessionWrapper::NotifyNextDeactivation(const TVwsViewId& aViewId)
       
   996 	{
       
   997 	CONNECT_AS_REQUIRED
       
   998 	return iVwsSession->NotifyNextDeactivation(aViewId);
       
   999 	}
       
  1000 
       
  1001 /**
       
  1002 Requests that the next deactivation of any view be notified to this session.
       
  1003 The request is cleared after the next notification. Only the last made
       
  1004 notification request is honoured.
       
  1005 
       
  1006 Establishes a connection to the view server if necessary.
       
  1007 
       
  1008 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
  1009  */
       
  1010 EXPORT_C TInt CVwsSessionWrapper::NotifyNextDeactivation()
       
  1011 	{
       
  1012 	return NotifyNextDeactivation(KNullViewId);
       
  1013 	}
       
  1014 
       
  1015 /**
       
  1016 Requests that the next activation of the view identified by aViewId be
       
  1017 notified to this session. The request is cleared after the next notification.
       
  1018 Only the last made notification request is honoured.
       
  1019 
       
  1020 This allows any client to track the system current active state.
       
  1021 
       
  1022 Establishes a connection to the view server if necessary.
       
  1023 
       
  1024 @param aViewId The view to monitor for activation.
       
  1025 
       
  1026 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
  1027  */
       
  1028 EXPORT_C TInt CVwsSessionWrapper::NotifyNextActivation(const TVwsViewId& aViewId)
       
  1029 	{
       
  1030 	CONNECT_AS_REQUIRED
       
  1031 	return iVwsSession->NotifyNextActivation(aViewId);
       
  1032 	}
       
  1033 
       
  1034 /**
       
  1035 Requests that the next activation of any view be notified to this session. The
       
  1036 request is cleared after the next notification. Only the last made notification
       
  1037 request is honoured.
       
  1038 
       
  1039 Establishes a connection to the view server if necessary.
       
  1040 
       
  1041 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
  1042  */
       
  1043 EXPORT_C TInt CVwsSessionWrapper::NotifyNextActivation()
       
  1044 	{
       
  1045 	return NotifyNextActivation(KNullViewId);
       
  1046 	}
       
  1047 
       
  1048 /**
       
  1049 Tests whether the thread that requested the current view switch satisfies a
       
  1050 security policy. This function can only be called from the thread of the
       
  1051 session that owns the view being activated, and only during the activation of
       
  1052 a view.
       
  1053 
       
  1054 Establishes a connection to the view server if necessary.
       
  1055 
       
  1056 @param aResult If the requesting thread satisfies the security policy, aResult
       
  1057                will be set to ETrue, otherwise it will be set to EFalse.
       
  1058                If this function does not complete successfully, aResult is
       
  1059                undefined.
       
  1060 @param aSecurityPolicy The security policy to check the requesting thread
       
  1061                        against.
       
  1062 
       
  1063 @return KErrNone if successful, KErrUnknown if this function is called from the
       
  1064         wrong session or at the wrong time, otherwise one of the system-wide
       
  1065         error codes.
       
  1066 
       
  1067 @see CCoeAppUi::CheckSourceOfViewSwitchL
       
  1068  */
       
  1069 EXPORT_C TInt CVwsSessionWrapper::CheckSourceOfViewSwitch(TBool& aResult,const TSecurityPolicy& aSecurityPolicy,const char* aDiagnostic)
       
  1070 	{
       
  1071 	CONNECT_AS_REQUIRED
       
  1072 	return iVwsSession->CheckSourceOfViewSwitch(aResult,aSecurityPolicy,aDiagnostic);
       
  1073 	}
       
  1074 
       
  1075 /**
       
  1076 Enables or disables screen blanking between screen device changes.
       
  1077 
       
  1078 If screen blanking is enabled, the screen will be covered by a solid window. The color of this blanking window
       
  1079 would be as set in CVwsSessionWrapper::SetWindowBackgroundColor method if its used, otherwise by default the 
       
  1080 color would be solid-white.
       
  1081 @see CVwsSessionWrapper::SetWindowBackgroundColor
       
  1082 
       
  1083 Establishes a connection to the view server if necessary.
       
  1084 
       
  1085 @param aEnable If aEnable is set to ETrue, screen blanking will take place as
       
  1086                described above, if aEnable is set to EFalse, screen blanking
       
  1087                will not happen.
       
  1088 
       
  1089 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
  1090  */
       
  1091 EXPORT_C TInt CVwsSessionWrapper::EnableServerBlankScreen(TBool aEnable)
       
  1092 	{
       
  1093 	CONNECT_AS_REQUIRED
       
  1094 	return iVwsSession->EnableServerBlankScreen(aEnable);
       
  1095 	}
       
  1096 
       
  1097 /**
       
  1098 Enable or disable protection from external view switches for this session.
       
  1099 
       
  1100 Views owned by protected sessions can only be activated by view activation
       
  1101 requests originating from the same session. Activation requests originating
       
  1102 from other sessions will cause a second instance of the application providing
       
  1103 the requested view to be started.
       
  1104 By default, sessions are not protected from external view switches.
       
  1105  
       
  1106 Establishes a connection to the view server if necessary.
       
  1107 
       
  1108 @param aEnable If set to ETrue, this session's views will be protected from
       
  1109                external view switches. If set to EFalse, they will have no such
       
  1110                protection.
       
  1111 
       
  1112 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
  1113  */
       
  1114 EXPORT_C TInt CVwsSessionWrapper::EnableExternalViewSwitches(TBool aEnable)
       
  1115 	{
       
  1116 	CONNECT_AS_REQUIRED
       
  1117 	return iVwsSession->SetProtected(!aEnable);
       
  1118 	}
       
  1119 
       
  1120 EXPORT_C TInt CVwsSessionWrapper::SetCrossCheckUid(const TUid& aCrossCheckUid)
       
  1121 	{
       
  1122 	CONNECT_AS_REQUIRED
       
  1123 	return iVwsSession->SetCrossCheckUid(aCrossCheckUid);
       
  1124 	}
       
  1125 
       
  1126 EXPORT_C TInt CVwsSessionWrapper::SetWindowBackgroundColor(const TRgb& aBgColor)
       
  1127 	{
       
  1128 	CONNECT_AS_REQUIRED
       
  1129 	return iVwsSession->SetWindowBackgroundColor(aBgColor);
       
  1130 	}
       
  1131 
       
  1132 EXPORT_C TInt CVwsSessionWrapper::GetCurrentActiveViewInSystem(TVwsViewId& aActiveViewId)
       
  1133 	{
       
  1134 	CONNECT_AS_REQUIRED
       
  1135 	return iVwsSession->GetCurrentActiveViewInSystem(aActiveViewId);
       
  1136 	}
       
  1137 
       
  1138 CVwsSessionWrapper::CVwsSessionWrapper()
       
  1139 	{
       
  1140 	}
       
  1141 
       
  1142 CVwsSessionWrapper::CVwsSessionWrapper(MVwsSessionWrapperObserver& aObserver) : iObserver(&aObserver)
       
  1143 	{
       
  1144 	}
       
  1145 
       
  1146 void CVwsSessionWrapper::ConstructL()
       
  1147 	{
       
  1148 	}
       
  1149 
       
  1150 TBool CVwsSessionWrapper::IsSchedulerRunning()
       
  1151 	{
       
  1152 	if (iViewEventHandler)
       
  1153 		{
       
  1154 		return ETrue;
       
  1155 		}
       
  1156 	CActiveScheduler* activeScheduler=CActiveScheduler::Current();
       
  1157 	return (activeScheduler && activeScheduler->StackDepth()>0);
       
  1158 	}
       
  1159 
       
  1160 TInt CVwsSessionWrapper::CheckCreateViewServerSession()
       
  1161 // Possible return values:
       
  1162 // KErrNone - connection suceeded.
       
  1163 // KErrNotConnected- connection failed because server was not running.
       
  1164 // KErrNoMemory - unable to allocate client side objects.
       
  1165 	{
       
  1166 	if (iVwsSession)
       
  1167 		{
       
  1168 		return KErrNone;
       
  1169 		}
       
  1170 
       
  1171 	TRAPD(err,iVwsSession=new(ELeave) RVwsSession);
       
  1172 	if(err!=KErrNone)
       
  1173 		{
       
  1174 		return err;
       
  1175 		}
       
  1176 
       
  1177 	err=iVwsSession->Connect();
       
  1178 	if (err==KErrNone)
       
  1179 		{
       
  1180 		if (iObserver) {
       
  1181 			TInt priority=iVwsSession->GetPriority();
       
  1182 			iViewEventHandler=new CVwsSessionEventHandler(*iObserver,*iVwsSession,priority);
       
  1183  			if (iViewEventHandler==NULL)
       
  1184 				{
       
  1185 				iVwsSession->Close();
       
  1186 				delete iVwsSession;
       
  1187 				iVwsSession=NULL;
       
  1188 				return KErrNoMemory;
       
  1189 				}
       
  1190 			}
       
  1191 		return KErrNone;
       
  1192 		}
       
  1193 	else
       
  1194 		{
       
  1195 		delete iVwsSession;
       
  1196 		iVwsSession=NULL;
       
  1197 		if (err==KErrNotFound)
       
  1198 			{	// It's not the view that's not found, but the server. Therefore switch to a more helpful error code.
       
  1199 			return KErrCouldNotConnect;
       
  1200 			}
       
  1201 		else 
       
  1202 			{
       
  1203 			return err;
       
  1204 			}
       
  1205 		}
       
  1206 	}
       
  1207 
       
  1208 
       
  1209 //
       
  1210 // Global functions.
       
  1211 //
       
  1212 
       
  1213 GLDEF_C TInt ViewServerThreadStart(TAny* aPtr)
       
  1214 	{
       
  1215 	RThread thread;
       
  1216 	TInt err=User::RenameThread(KVwsViewServerThreadName);
       
  1217 	if (err!=KErrNone && err!=KErrAlreadyExists)
       
  1218 		return err;
       
  1219 	User::SetCritical(User::ESystemCritical);
       
  1220 	thread.Close();
       
  1221 
       
  1222 	CActiveScheduler* scheduler=new CActiveScheduler;
       
  1223 	if (!scheduler)
       
  1224 		return KErrNoMemory;
       
  1225 	CActiveScheduler::Install(scheduler);
       
  1226 
       
  1227 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
  1228 	if (!trapCleanup)
       
  1229 		return KErrNoMemory;
       
  1230 	SVwsCommandLine* comLine=STATIC_CAST(SVwsCommandLine*,aPtr);
       
  1231 	CVwsServer* viewServer=NULL;
       
  1232 	TRAP(err,viewServer=CVwsServer::NewL(*(comLine->iAppStarter)));
       
  1233 	if (err!=KErrNone)
       
  1234 		return err;
       
  1235 	RThread::Rendezvous(KErrNone);
       
  1236 
       
  1237 	CActiveScheduler::Start();
       
  1238 	delete viewServer;
       
  1239 	delete CActiveScheduler::Current();
       
  1240 	delete trapCleanup;
       
  1241 	return KErrNone;
       
  1242 	}
       
  1243 
       
  1244 GLREF_C void Panic(TVwsPanic aPanic)
       
  1245 	{
       
  1246 	_LIT(KViewServerPanic,"View Server client panic");
       
  1247 	User::Panic(KViewServerPanic,aPanic);
       
  1248 	}