installationservices/swi/test/tuiscriptadaptors/sisregistryaccess_server_session.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
    30 #include "sisregistryaccess_common.h"
    30 #include "sisregistryaccess_common.h"
    31 #include "dessisdataprovider.h"
    31 #include "dessisdataprovider.h"
    32 #include "siscontroller.h"
    32 #include "siscontroller.h"
    33 #include "application.h"
    33 #include "application.h"
    34 #include "userselections.h"
    34 #include "userselections.h"
    35 #include "sislauncherclient.h"
       
    36 
    35 
    37 /////////////////////// Utility functions //////////////////////////////
    36 /////////////////////// Utility functions //////////////////////////////
    38 void StartTimer(TTime& aTimer)
    37 void StartTimer(TTime& aTimer)
    39 	{
    38 	{
    40 	aTimer.HomeTime();
    39 	aTimer.HomeTime();
   109 	Server().DropSession();
   108 	Server().DropSession();
   110 	}
   109 	}
   111 
   110 
   112 void CSisRegistryAccessSession::ServiceL(const RMessage2& aMessage)
   111 void CSisRegistryAccessSession::ServiceL(const RMessage2& aMessage)
   113 	{
   112 	{
   114     TSisRegistryAccessMessages f = static_cast<TSisRegistryAccessMessages>(aMessage.Function());
   113 	// create transaction on SCR for mutable operations
   115     TTime timer;
   114 	Server().RegistrySession().CreateTransactionL();
   116     StartTimer(timer);
   115 	// SWI regsitry needs a transaction to cover updates to logs during package add/update/removal
   117     TInt err(0);
   116 	Usif::RStsSession stsSession;
   118     if(f == EAddAppRegInfo)
   117 	TInt64 transactionID = stsSession.CreateTransactionL();
   119         {
   118 	CleanupClosePushL(stsSession);
   120         TUint regFileNameLen = aMessage.GetDesLengthL(0);
   119 	TInt err(0);
   121         HBufC* regFileName = HBufC::NewLC(regFileNameLen);
   120 	
   122         TPtr namePtr = regFileName->Des();
   121 	TTime timer;
   123         aMessage.ReadL(0, namePtr);
   122 	StartTimer(timer);
   124         TUid appUid = TUid::Uid(aMessage.Int1());
   123 	
   125         Swi::RSisRegistrySession sisRegistryWritableSession;
   124 	TSisRegistryAccessMessages f = static_cast<TSisRegistryAccessMessages>(aMessage.Function());
   126         CleanupClosePushL(sisRegistryWritableSession);
   125 	switch (f)
   127         TRAP(err, sisRegistryWritableSession.Connect());
   126 		{
   128         TRAP(err, sisRegistryWritableSession.AddAppRegInfoL(*regFileName););
   127 		case EAddEntry:
   129         CleanupStack::PopAndDestroy(2, regFileName);
   128 		case EUpdateEntry:
   130         }
   129 			{
   131     else if(f == ERemoveAppRegInfo)
   130 			TInt len = aMessage.GetDesLengthL(0);
   132         {
   131 			HBufC8 *controllerData = HBufC8::NewLC(len);
   133         TUint regFileNameLen = aMessage.GetDesLengthL(0);
   132 			TPtr8 ptrControllerData(controllerData->Des());
   134         HBufC* regFileName = HBufC::NewLC(regFileNameLen);
   133 			aMessage.ReadL(0, ptrControllerData);
   135         TPtr namePtr = regFileName->Des();
   134 			
   136         aMessage.ReadL(0, namePtr);
   135 			// create the controller
   137         TUid appUid = TUid::Uid(aMessage.Int1());
   136 			Swi::CDesDataProvider *desProvider = Swi::CDesDataProvider::NewLC(ptrControllerData);
   138         Swi::RSisRegistrySession sisRegistryWritableSession;
   137 			Swi::Sis::CController *controller = Swi::Sis::CController::NewLC(*desProvider, Swi::Sis::EAssumeType);
   139         CleanupClosePushL(sisRegistryWritableSession);
   138 			// setup the application
   140         TRAP(err, sisRegistryWritableSession.Connect());
   139 			Swi::CApplication *app = Swi::CApplication::NewLC();
   141         TRAP(err, sisRegistryWritableSession.RemoveAppRegInfoL(*regFileName););
   140 			app->SetInstall(*controller);
   142         CleanupStack::PopAndDestroy(2, regFileName);
   141 			// since the attributes chosen by the user don't have impact on the adding/updating entry tests,
   143         }
   142 			// they are set with the constant values.
   144     else
   143 			app->UserSelections().SetLanguage(ELangEnglish);
   145         {
   144 			app->UserSelections().SetDrive(2);
   146         // create transaction on SCR for mutable operations
   145 			
   147         Server().RegistrySession().CreateTransactionL();
   146 			if(EAddEntry == f)
   148         // SWI regsitry needs a transaction to cover updates to logs during package add/update/removal
   147 				{
   149         Usif::RStsSession stsSession;
   148 				TRAP(err, Server().RegistrySession().AddEntryL(*app, ptrControllerData, transactionID));
   150         TInt64 transactionID = stsSession.CreateTransactionL();
   149 				}
   151         CleanupClosePushL(stsSession);
   150 			else
   152         
   151 				{
   153         switch (f)
   152 				TRAP(err, Server().RegistrySession().UpdateEntryL(*app, ptrControllerData, transactionID));
   154             {
   153 				}
   155             case EAddEntry:
   154 			CleanupStack::PopAndDestroy(4, controllerData); // controllerData, desProvider, controller, app
   156             case EUpdateEntry:
   155 			break;
   157                 {
   156 			}
   158                 TInt len = aMessage.GetDesLengthL(0);
   157 		case EDeleteEntry:
   159                 HBufC8 *controllerData = HBufC8::NewLC(len);
   158 			{
   160                 TPtr8 ptrControllerData(controllerData->Des());
   159 			// Get Uid and index
   161                 aMessage.ReadL(0, ptrControllerData);
   160 			// Augmentation index - argument 0
   162                 
   161 			TInt packageIndex = aMessage.Int0();
   163                 // create the controller
   162 
   164                 Swi::CDesDataProvider *desProvider = Swi::CDesDataProvider::NewLC(ptrControllerData);
   163 			// Uid (ipc argument 1)
   165                 Swi::Sis::CController *controller = Swi::Sis::CController::NewLC(*desProvider, Swi::Sis::EAssumeType);
   164 			TUid uid;
   166                 // setup the application
   165 			TPckg<TUid> packageUid(uid);
   167                 Swi::CApplication *app = Swi::CApplication::NewLC();
   166 			aMessage.ReadL(1, packageUid);
   168                 app->SetInstall(*controller);
   167 			
   169                 // since the attributes chosen by the user don't have impact on the adding/updating entry tests,
   168 			// Invoke SisRegistry server API using SisRegistryClient
   170                 // they are set with the constant values.
   169 			Swi::CSisRegistryPackage* package = Swi::CSisRegistryPackage::NewLC(uid, KNullDesC, KNullDesC); // For the delete API, the name and the vendor of the package are irrelevant
   171                 app->UserSelections().SetLanguage(ELangEnglish);
   170 			package->SetIndex(packageIndex);
   172                 app->UserSelections().SetDrive(2);
   171 			TRAP(err, Server().RegistrySession().DeleteEntryL(*package, transactionID));
   173                 
   172 
   174                 if(EAddEntry == f)
   173 			CleanupStack::PopAndDestroy(package);
   175                     {
   174 			break;
   176                     TRAP(err, Server().RegistrySession().AddEntryL(*app, ptrControllerData, transactionID));
   175 			}
   177                     }
   176 		default:
   178                 else
   177 			{
   179                     {
   178 			PanicClient(aMessage, EPanicIllegalFunction);
   180                     TRAP(err, Server().RegistrySession().UpdateEntryL(*app, ptrControllerData, transactionID));
   179 			break;
   181                     }
   180 			}
   182                 CleanupStack::PopAndDestroy(4, controllerData); // controllerData, desProvider, controller, app
   181 		}
   183                 break;
   182 	
   184                 }
   183 	stsSession.CommitL();
   185             case EDeleteEntry:
   184 	CleanupStack::PopAndDestroy(&stsSession);
   186                 {
   185 
   187                 // Get Uid and index
   186 	Server().RegistrySession().CommitTransactionL();
   188                 // Augmentation index - argument 0
   187 	
   189                 TInt packageIndex = aMessage.Int0();
       
   190     
       
   191                 // Uid (ipc argument 1)
       
   192                 TUid uid;
       
   193                 TPckg<TUid> packageUid(uid);
       
   194                 aMessage.ReadL(1, packageUid);
       
   195                 
       
   196                 // Invoke SisRegistry server API using SisRegistryClient
       
   197                 Swi::CSisRegistryPackage* package = Swi::CSisRegistryPackage::NewLC(uid, KNullDesC, KNullDesC); // For the delete API, the name and the vendor of the package are irrelevant
       
   198                 package->SetIndex(packageIndex);
       
   199                 TRAP(err, Server().RegistrySession().DeleteEntryL(*package, transactionID));
       
   200     
       
   201                 CleanupStack::PopAndDestroy(package);
       
   202                 break;
       
   203                 }
       
   204             default:
       
   205                 {
       
   206                 PanicClient(aMessage, EPanicIllegalFunction);
       
   207                 break;
       
   208                 }
       
   209             }
       
   210         
       
   211         stsSession.CommitL();
       
   212         CleanupStack::PopAndDestroy(&stsSession);
       
   213         Server().RegistrySession().CommitTransactionL();
       
   214         }	
       
   215 	TPckg<TInt> timePckg(StopTimer(timer));
   188 	TPckg<TInt> timePckg(StopTimer(timer));
   216 	if(EDeleteEntry == f)
   189 	if(EDeleteEntry == f)
   217 		aMessage.WriteL(2, timePckg);
   190 		aMessage.WriteL(2, timePckg);
   218 	else
   191 	else
   219 		aMessage.WriteL(1, timePckg);
   192 		aMessage.WriteL(1, timePckg);