diff -r 6757f1e2efd2 -r 5b858729772b applicationmanagement/client/src/ApplicationManagementClient.cpp --- a/applicationmanagement/client/src/ApplicationManagementClient.cpp Tue Aug 31 15:05:55 2010 +0300 +++ b/applicationmanagement/client/src/ApplicationManagementClient.cpp Wed Sep 01 12:31:32 2010 +0100 @@ -25,7 +25,7 @@ #include "debug.h" #include #include -#include + #include @@ -37,57 +37,50 @@ // Server startup code // ---------------------------------------------------------------------------------------- -static TInt StartServer() +static TInt StartAMServerL() { - RDEBUG("RApplicationManagement: Starting server..."); - - const TUidType serverUid(KNullUid, KNullUid, - KApplicationManagementServerUid); + RDEBUG("RApplicationManagement: Starting server..."); + + TInt err = KErrNone; + const TUid nameUid = TUid::Uid(KUikonUidPluginInterfaceNotifiers); + + const TUid appServerUid = TUid::Uid(KAppMgmtServerUid ); + + RApaLsSession apa; + err = apa.Connect(); + User::LeaveIfError(err); + CleanupClosePushL(apa); - // EPOC and EKA 2 is easy, we just create a new server process. Simultaneous - // launching of two such processes should be detected when the second one - // attempts to create the server object, failing with KErrAlreadyExists. - RProcess server; - //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid); - TInt r = server.Create(KApplicationManagementServerImg, KNullDesC); - if (r != KErrNone) + // Get application information + TApaAppInfo info; + + for(TInt i = 20; ((err = apa.GetAppInfo(info, + appServerUid)) == RApaLsSession::EAppListInvalid) && i > 0; i--) { - RDEBUG_2("ApplicationManagementClient: server start failed %d",r); - return r; + User::After(500000); } - TRequestStatus stat; - server.Rendezvous(stat); - if (stat != KRequestPending) - server.Kill(0); // abort startup - else - server.Resume(); // logon OK - start the server - RDEBUG("ApplicationManagementClient: Started"); - User::WaitForRequest(stat); - TInt err = RProperty::Define(KProperty, KInteger, RProperty::EInt); - RProperty ServerLaunch; - ServerLaunch.Attach(KProperty, KInteger, EOwnerThread); - TRequestStatus status; - - ServerLaunch.Subscribe(status); - //server.Resume(); - User::WaitForRequest(status); + User::LeaveIfError(err); - ServerLaunch.Close(); - RProperty::Delete(KProperty, KInteger); + TRequestStatus aRequestStatusForRendezvous; + + // Start aplication server + CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); + cmdLine->SetExecutableNameL(info.iFullName); + cmdLine->SetServerRequiredL(nameUid.iUid ); + cmdLine->SetCommandL(EApaCommandBackground); + TThreadId srvid; + err = apa.StartApp(*cmdLine, srvid, &aRequestStatusForRendezvous); + User::LeaveIfError(err); - //User::WaitForRequest(stat); // wait for start or death - // we can't use the 'exit reason' if the server panicked as this - // is the panic 'reason' and may be '0' which cannot be distinguished - // from KErrNone - r = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); - // _LIT_SECURITY_POLICY_S0(KWritePolicy,KApplicationManagementServerUid.iUid); - // _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData ); + User::WaitForRequest(aRequestStatusForRendezvous); + CleanupStack::PopAndDestroy(2, &apa); // cmdLine and apa - server.Close(); - return r; + return KErrNone; + } + +EXPORT_C RAppMgmtRfs::RAppMgmtRfs() + { } - - EXPORT_C TInt RAppMgmtRfs::Connect() { TInt retry=2; @@ -95,12 +88,28 @@ for (;;) { - TInt r=CreateSession(KApplicationManagementServerName,ver,1); + TInt r; + + const TUid nameUid = TUid::Uid(KUikonUidPluginInterfaceNotifiers); + + const TUid appServerUid = TUid::Uid(KAppMgmtServerUid ); + + _LIT(KServerNameFormat, "%08x_%08x_AppServer"); + TFullName serverName; + serverName.Format(KServerNameFormat, + nameUid, appServerUid); + TRAP(r, ConnectExistingByNameL(serverName) ); + if(r) + { + + r = CreateSession (serverName, ver); + + } if (r!=KErrNotFound && r!=KErrServerTerminated) return r; if (--retry==0) return r; - r=StartServer(); + TRAP_IGNORE(r=StartAMServerL()); if (r!=KErrNone && r!=KErrAlreadyExists) { return r; @@ -111,7 +120,7 @@ EXPORT_C void RAppMgmtRfs::Close() { - RSessionBase::Close(); //basecall + REikAppServiceBase::Close(); //basecall } // New methods @@ -120,7 +129,15 @@ User::LeaveIfError( SendReceive( EPerformRfs, TIpcArgs() ) ); } +TUid RAppMgmtRfs::ServiceUid() const + { + return TUid::Uid( KAMServiceUid); + } + +EXPORT_C RApplicationManagement::RApplicationManagement() + { + } // This is the standard retry pattern for server connection EXPORT_C TInt RApplicationManagement::Connect( ) @@ -130,12 +147,28 @@ for (;;) { - TInt r=CreateSession(KApplicationManagementServerName,ver,1); + TInt r; + + const TUid nameUid = TUid::Uid(KUikonUidPluginInterfaceNotifiers); + + const TUid appServerUid = TUid::Uid(KAppMgmtServerUid ); + + _LIT(KServerNameFormat, "%08x_%08x_AppServer"); + TFullName serverName; + serverName.Format(KServerNameFormat, + nameUid, appServerUid); + TRAP(r, ConnectExistingByNameL(serverName) ); + if(r) + { + + r = CreateSession (serverName, ver); + + } if (r!=KErrNotFound && r!=KErrServerTerminated) return r; if (--retry==0) return r; - r=StartServer(); + TRAP_IGNORE(r=StartAMServerL()) if (r!=KErrNone && r!=KErrAlreadyExists) { return r; @@ -157,7 +190,7 @@ EXPORT_C void RApplicationManagement::Close() { - RSessionBase::Close(); //basecall + REikAppServiceBase::Close(); }