commonuisupport/uikon/srvsrc/EIKSRVC.CPP
changeset 0 2f259fa3e83a
child 30 56e9a0aaad89
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 1997-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 
       
    17 #include <e32std.h>
       
    18 #include <e32math.h>
       
    19 #include <centralrepository.h>
       
    20 #include "coedatastorage.h"
       
    21 #include <eiksrvc.h>
       
    22 #include <eiksvdef.h>
       
    23 #include <s32mem.h>
       
    24 #include <eikdebug.h>
       
    25 #include "eiksrvsconsts.h"
       
    26 #include "../coresrc/eikdebugprefs.h"
       
    27 
       
    28 const TUint KDefaultBufSize = 0x8;
       
    29 const TUid KServerUid3={0x10003A4A};
       
    30 #ifdef __WINS__
       
    31 _LIT(KEikSrvName,"eiksrvs.exe");
       
    32 #else // ! __WINS__
       
    33 _LIT(KEikSrvName,"z:\\system\\programs\\eiksrvs.exe");
       
    34 #endif
       
    35 
       
    36 GLDEF_C void PanicServer(TEikAppUiServPanic aPanic)
       
    37 	{
       
    38 	_LIT(KPanicCat,"EIKON-SERVER");
       
    39 	User::Panic(KPanicCat,aPanic);
       
    40 	}
       
    41 
       
    42 // REikAppUiSession::CExtension
       
    43 
       
    44 class REikAppUiSession::CExtension : public CBase
       
    45 	{
       
    46 	friend class REikAppUiSession;
       
    47 private: // but public to REikAppUiSession
       
    48 	CCoeDataStorage* iDataStorage;
       
    49 	};
       
    50 
       
    51 // REikAppUiSession
       
    52 
       
    53 /**
       
    54 Default Constructor
       
    55 @publishedPartner
       
    56 */
       
    57 EXPORT_C REikAppUiSession::REikAppUiSession()
       
    58 : iExtension(NULL)
       
    59 	{
       
    60 	}
       
    61 
       
    62 /**
       
    63 Connect to the server attempting to start it if required
       
    64 @return System error code.
       
    65 */
       
    66 EXPORT_C TInt REikAppUiSession::Connect()
       
    67 	{
       
    68 	Close();
       
    69 	TInt err=KErrNone;
       
    70 	TInt retry=KNumConnectRetries;
       
    71 	FOREVER
       
    72 		{
       
    73 		err=CreateSession(EIKAPPUI_SERVER_NAME,Version());
       
    74 		if ((--retry>0) && ((err==KErrNotFound) || (err==KErrServerTerminated)))
       
    75 			{
       
    76 			TRAP(err,StartServerL());
       
    77 			if ((err!=KErrNone) && (err!=KErrAlreadyExists))
       
    78 				{
       
    79 				break;
       
    80 				}
       
    81 			}
       
    82 		else
       
    83 			{
       
    84 			break;
       
    85 			}
       
    86 		}
       
    87 	if (err==KErrNone)
       
    88 		{
       
    89 		
       
    90 		TRAP(err,
       
    91 				iExtension=new(ELeave) CExtension;
       
    92 				iExtension->iDataStorage=CCoeDataStorage::NewL());
       
    93 		}
       
    94 	if (err!=KErrNone)
       
    95 		{
       
    96 		Close();
       
    97 		}
       
    98 	return err;
       
    99 	}
       
   100 
       
   101 
       
   102 /**
       
   103 Closes connection with server.
       
   104 @publishedPartner
       
   105 */
       
   106 EXPORT_C void REikAppUiSession::Close()
       
   107 	{
       
   108 	RSessionBase::Close();
       
   109 	if (iExtension!=NULL)
       
   110 		{
       
   111 		delete iExtension->iDataStorage;
       
   112 		delete iExtension;
       
   113 		iExtension=NULL;
       
   114 		}
       
   115 	}
       
   116 
       
   117 /**
       
   118 Creates and starts server.  Waits for success or failure.
       
   119 Doesn't leave with the 'exit reason' if the server panicked as this
       
   120 is the panic 'reason' and may be '0' which cannot be distinguished
       
   121 from KErrNone.
       
   122 @internalComponent
       
   123 */
       
   124 void REikAppUiSession::StartServerL()
       
   125 	{
       
   126 	const TUidType serverUid(KNullUid,KNullUid,KServerUid3);
       
   127 
       
   128 	RProcess server;
       
   129 	User::LeaveIfError(server.Create(KEikSrvName,KNullDesC,serverUid));
       
   130 	TRequestStatus stat;
       
   131 	server.Rendezvous(stat);
       
   132 	if (stat!=KRequestPending)
       
   133 		server.Kill(0);         // abort startup
       
   134 	else
       
   135 		server.Resume();        // logon OK - start the server
       
   136 	User::WaitForRequest(stat);             // wait for start or death
       
   137 	// we can't use the 'exit reason' if the server panicked as this
       
   138 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
   139 	// from KErrNone
       
   140 	TInt r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
   141 	server.Close();
       
   142 	User::LeaveIfError(r);
       
   143 	}
       
   144 
       
   145 /**
       
   146 @return version number.
       
   147 @publishedPartner
       
   148 */
       
   149 EXPORT_C TVersion REikAppUiSession::Version(void) const
       
   150 	{
       
   151 	return(TVersion(1,0,0));
       
   152 	}
       
   153 
       
   154 /**
       
   155 Asks server to launch the Task List
       
   156 @publishedPartner
       
   157 */
       
   158 EXPORT_C void REikAppUiSession::LaunchTaskList() const
       
   159 	{
       
   160 #if defined(_DEBUG)
       
   161 	const TInt error=
       
   162 #endif
       
   163 	SendReceive(EEikAppUiLaunchTaskList,TIpcArgs());
       
   164 	__ASSERT_DEBUG(error==KErrNone,User::Invariant());
       
   165 	}
       
   166 
       
   167 /**
       
   168 Asks the server to cycle through the tasks (in the list) by one in the specified direction
       
   169 @param aDirection EForwards or EBackwards
       
   170 @publishedPartner
       
   171 */
       
   172 EXPORT_C void REikAppUiSession::CycleTasks(TTaskCycleDirection aDirection) const
       
   173 	{
       
   174 #if defined(_DEBUG)
       
   175 	const TInt error=
       
   176 #endif
       
   177 	SendReceive(EEikAppUiCycleTasks,TIpcArgs(aDirection));
       
   178 	__ASSERT_DEBUG(error==KErrNone,User::Invariant());
       
   179 	}
       
   180 
       
   181 /**
       
   182 Asks the server to set status pane flags as specified
       
   183 @param aFlags Status pane dependant flags.
       
   184 @publishedPartner
       
   185 */
       
   186 EXPORT_C TInt REikAppUiSession::SetStatusPaneFlags(TInt aFlags) const
       
   187 	{
       
   188 	return SendReceive(EEikAppUiSetStatusPaneFlags,TIpcArgs(aFlags));
       
   189 	}
       
   190 
       
   191 /**
       
   192 Sends status pane resource layout ID to server
       
   193 @param aLayoutResId  Resource ID of status pane layout resource
       
   194 @publishedPartner
       
   195 */
       
   196 EXPORT_C TInt REikAppUiSession::SetStatusPaneLayout(TInt aLayoutResId) const
       
   197 	{
       
   198 	return SendReceive(EEikAppUiSetStatusPaneLayout,TIpcArgs(aLayoutResId));
       
   199 	}
       
   200 
       
   201 /**
       
   202 Sends blank screen message to server
       
   203 @publishedPartner
       
   204 */
       
   205 EXPORT_C TInt REikAppUiSession::BlankScreen() const
       
   206 	{
       
   207 	return SendReceive(EEikAppUiBlankScreen,TIpcArgs());
       
   208 	}
       
   209 
       
   210 /**
       
   211 Sends unblank screen message to server
       
   212 @publishedPartner
       
   213 */
       
   214 EXPORT_C TInt REikAppUiSession::UnblankScreen() const
       
   215 	{
       
   216 	return SendReceive(EEikAppUiUnblankScreen,TIpcArgs());
       
   217 	}
       
   218 
       
   219 /**
       
   220 Retrieves error text for error code (if code is valid)
       
   221 @param aText Output parameter - error message
       
   222 @param aError Standard error code
       
   223 @param aAppUid Application UID
       
   224 @return EErrorNumValid or EErrorNumInvalid
       
   225 @see CEikonEnv::TErrorValidity
       
   226 @publishedPartner
       
   227 */
       
   228 EXPORT_C CEikonEnv::TErrorValidity REikAppUiSession::ResolveError(TDes& aText,TInt aError,TUid aAppUid) const
       
   229 	{
       
   230 	return STATIC_CAST(CEikonEnv::TErrorValidity, SendReceive(EEikAppUiResolveError,TIpcArgs(&aText,aError,aAppUid.iUid)));
       
   231 	}
       
   232 
       
   233 /**
       
   234 Retrieves error text, title text, error resource ID and resource flags for the given error code (if code is valid)
       
   235 @param aErrorText Output parameter - Error Text.
       
   236 @param aError Standard Error Code
       
   237 @param aFlags Output parameter - Error Resource Flag.
       
   238 @param aTextId Output parameter - Error Text Resource Id.
       
   239 @param aTitleText Output parameter - Error Title Text.
       
   240 
       
   241 @return EErrorNumValid or EErrorNumInvalid
       
   242 @see CEikonEnv::TErrorValidity
       
   243 @released
       
   244 */
       
   245 EXPORT_C CEikonEnv::TErrorValidity REikAppUiSession::ResolveErrorWithTitleL(TDes& aErrorText, TInt aError, TInt& aTextId, TUint& aFlags, TDes& aTitleText, TBool aIsMemoryAllocatedByErrResolver) const
       
   246 	{
       
   247 	TErrorFlagAndId errInfo;
       
   248 	TPckg<TErrorFlagAndId> package(errInfo);
       
   249 	errInfo.iIsMemoryAllocatedByErrResolver = aIsMemoryAllocatedByErrResolver;
       
   250 	errInfo.iTextId = 0;
       
   251 	errInfo.iFlags = 0;
       
   252 	
       
   253 	TInt errValidity = User::LeaveIfError(SendReceive(EEikAppUiResolveErrorWithTitleText, TIpcArgs(&aErrorText, aError, &package, &aTitleText)));
       
   254 	
       
   255 	aTextId = errInfo.iTextId;
       
   256 	aFlags = errInfo.iFlags;
       
   257 	return STATIC_CAST(CEikonEnv::TErrorValidity, errValidity);
       
   258 	}
       
   259 
       
   260 /**
       
   261 Retrieves pointer descriptor of specified extension.
       
   262 @param aExtensionUid 
       
   263 @publishedPartner
       
   264 @see MEikServAppUiSessionHandler::Extension(TUid aExtensionUid,const TDesC8& aBuffer,RMessagePtr2 aMessage)
       
   265 */
       
   266 EXPORT_C void REikAppUiSession::Extension(TUid aExtensionUid,const TDesC8& aBuffer,TRequestStatus& aRequestStatus) const
       
   267 	{
       
   268 	SendReceive(EEikAppUiExtension, TIpcArgs(aExtensionUid.iUid,&aBuffer), aRequestStatus);
       
   269 	}
       
   270 
       
   271 /** Gets the identifier of the currently installed FEP. 
       
   272 
       
   273 @param aFepId On return, contains the identifier of the FEP currently installed.
       
   274 
       
   275 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   276 @deprecated
       
   277 */
       
   278 EXPORT_C TInt REikAppUiSession::GetInstalledFepName(TDes& aFepId) const
       
   279 	{
       
   280 	TRAPD(error, iExtension->iDataStorage->GetInstalledFepIdL(aFepId));
       
   281 	return error;
       
   282 	}
       
   283 
       
   284 /** Sets the identifier of the installed FEP.
       
   285 
       
   286 @param aFepId The identifier of the installed FEP.
       
   287 @param aRaiseFileError No longer used.
       
   288 
       
   289 @capability WriteDeviceData
       
   290 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   291 @deprecated Use CCoeEnv::InstallFepL instead.
       
   292 */
       
   293 EXPORT_C TInt REikAppUiSession::SetInstalledFepName(const TDesC& aFepId, TBool aRaiseFileError) const
       
   294 	{
       
   295 	(void)aRaiseFileError;
       
   296 	TRAPD(error, iExtension->iDataStorage->SetInstalledFepIdL(aFepId));
       
   297 	return error;
       
   298 	}
       
   299 	
       
   300 /** Gets the system colour list, which is a palette of standard colours used by the system.
       
   301 
       
   302 The function returns NULL if no such data exists.
       
   303 
       
   304 @return Pointer to the system colour list. 
       
   305 */
       
   306 EXPORT_C CColorList* REikAppUiSession::GetSystemColorsL() const
       
   307 	{
       
   308 	return iExtension->iDataStorage->GetSystemColorListL();	
       
   309 	}
       
   310 
       
   311 /** Sets the system colour list with the list specified.
       
   312 
       
   313 If no system colour list exists, one is created.
       
   314 
       
   315 @param aColorList The new colour list.
       
   316 */
       
   317 EXPORT_C void REikAppUiSession::SetSystemColorsL(const CColorList& aColorList) const
       
   318 	{
       
   319 	iExtension->iDataStorage->SetSystemColorListL(aColorList);
       
   320 	}
       
   321 
       
   322 /** No longer needs to do anything.
       
   323 
       
   324 @return KErrNone.
       
   325 */
       
   326 EXPORT_C TInt REikAppUiSession::OpenFepAttributes() const
       
   327 	{
       
   328 	return KErrNone;
       
   329 	}
       
   330 
       
   331 /** Gets the FEP's attributes for the given UID.
       
   332 
       
   333 @param aAttribUid The attribute UID for which the attribute data has to be queried for.
       
   334 @param aAttribData On return contains the attribute data.
       
   335 
       
   336 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   337 */
       
   338 EXPORT_C TInt REikAppUiSession::GetFepAttribute(TUid aAttribUid, TDes8& aAttribData) const
       
   339 	{
       
   340 	TRAPD(error, iExtension->iDataStorage->GetFepAttributeL(aAttribUid, aAttribData));
       
   341 	return error;
       
   342 	}
       
   343 
       
   344 /** Sets the attribute data for the specified UID.
       
   345 
       
   346 If no attribute is associated with the specified UID, then a new attribute is created.
       
   347 If an attribute is currently associated with the specified UID, then this existing
       
   348 attribute is replaced with the new attribute.
       
   349   
       
   350 @param aAttribUid The attribute UID of the new attribute data.
       
   351 @param aAttribData Attribute data to add.
       
   352 
       
   353 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   354 */
       
   355 EXPORT_C TInt REikAppUiSession::SetFepAttribute(TUid aAttribUid, const TDesC8& aAttribData) const
       
   356 	{
       
   357 	TRAPD(error, iExtension->iDataStorage->SetFepAttributeL(aAttribUid, aAttribData));
       
   358 	return error;
       
   359 	}
       
   360 
       
   361 /** No longer needs to do anything.
       
   362 @return KErrNone.
       
   363 */
       
   364 EXPORT_C TInt REikAppUiSession::CommitFepAttributes() const
       
   365 	{
       
   366 	return KErrNone;
       
   367 	}
       
   368 
       
   369 /** No longer needs to do anything.
       
   370 */
       
   371 EXPORT_C void REikAppUiSession::CloseFepAttributes() const
       
   372 	{
       
   373 	}
       
   374 
       
   375 /** Enables activation of the task list if successful.
       
   376 
       
   377 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   378 */
       
   379 EXPORT_C TInt REikAppUiSession::EnableTaskList() const
       
   380 	{
       
   381 	return SendReceive(EEikAppUiEnableTaskList);
       
   382 	}
       
   383 
       
   384 /** Reserved for future use */
       
   385 EXPORT_C void REikAppUiSession::REikAppUiSession_Reserved1()
       
   386 	{
       
   387 	}
       
   388 
       
   389 /** Reserved for future use */
       
   390 EXPORT_C void REikAppUiSession::REikAppUiSession_Reserved2()
       
   391 	{
       
   392 	}
       
   393 
       
   394 /** Gets the debug preferences object 
       
   395 
       
   396 @internalComponent
       
   397 @return pointer to the debug preferences object and transfers ownership to the caller.
       
   398 */
       
   399 EXPORT_C CEikDebugPreferences* REikAppUiSession::GetDebugPreferencesL() const
       
   400 	{
       
   401 	CBufFlat* buffer = CBufFlat::NewL(KDefaultBufSize); // allocate buffer with a default size that should be large enough in most cases
       
   402 	CleanupStack::PushL(buffer);
       
   403 	buffer->ExpandL(0,KDefaultBufSize);
       
   404 	TPtr8 bufPtr = buffer->Ptr(0);
       
   405 	const TInt sizeRequired = User::LeaveIfError(SendReceive(EEikAppUiGetDebugPreferences,TIpcArgs(buffer->Size(),&bufPtr)));
       
   406 	if (sizeRequired > 0)
       
   407 		{
       
   408 		CleanupStack::PopAndDestroy(buffer);
       
   409 		buffer = CBufFlat::NewL(sizeRequired);
       
   410 		CleanupStack::PushL(buffer);
       
   411 		buffer->ExpandL(0,sizeRequired);
       
   412 		bufPtr.Set(buffer->Ptr(0));
       
   413 #if defined(_DEBUG)
       
   414 		const TInt check = 
       
   415 #endif
       
   416 		User::LeaveIfError(SendReceive(EEikAppUiGetDebugPreferences,TIpcArgs(0,&bufPtr)));
       
   417 		__ASSERT_DEBUG(check == 0, User::Invariant());
       
   418 		}
       
   419 	CEikDebugPreferences* debugPreferences = CEikDebugPreferences::NewLC();
       
   420 	RBufReadStream readStream(*buffer);
       
   421 	CleanupClosePushL(readStream);
       
   422 	readStream >> *debugPreferences;
       
   423 	CleanupStack::PopAndDestroy(); //readStream
       
   424 	CleanupStack::Pop(); //debugPreferences
       
   425 	CleanupStack::PopAndDestroy(); //buffer
       
   426 	return debugPreferences;
       
   427 	}
       
   428 	
       
   429