sysstatemgmt/systemstatemgr/sus/src/susmiscadaptation.cpp
changeset 0 4e1aa6a622a0
child 59 0f7422b6b602
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2008-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 <e32debug.h>
       
    17 #include <ssm/ssmadaptation.h>
       
    18 #include <s32mem.h> 
       
    19 #include "susmiscadaptation.h"
       
    20 
       
    21 /**
       
    22 @internalComponent
       
    23 */
       
    24 
       
    25 void CMiscAdaptation::SubmitOrQueueL(const RMessage2 &aMessage)
       
    26 	{
       
    27 
       
    28 	CAdaptationMessage *messageCopy = new(ELeave) CAdaptationMessage(aMessage);
       
    29 
       
    30 	if(!IsActive())
       
    31 		{
       
    32 		Submit(messageCopy);
       
    33 		}
       
    34 	else 
       
    35 		{
       
    36 		CleanupStack::PushL(messageCopy);
       
    37 		DEBUGPRINT2A("CMiscAdaptationRequests queuing request with function id: %d", aMessage.Function());
       
    38 		User::LeaveIfError(iPendingRequestsQueue.Queue(messageCopy));
       
    39 		CleanupStack::Pop(messageCopy);
       
    40 		}
       
    41 	}
       
    42 
       
    43 void CMiscAdaptation::Submit(CAdaptationMessage*& aMessage)
       
    44 	{
       
    45 	DEBUGPRINT2A("CMiscAdaptationRequests immediate submission of request with function id: %d", aMessage->Function());
       
    46 	iCurrentMessage = aMessage;
       
    47 	switch(aMessage->Function())
       
    48 		{
       
    49 		case ESecurityStateChange :
       
    50 			{
       
    51 			TInt state = aMessage->Int0 ( );
       
    52 			iMiscAdaptation.SecurityStateChange(state,iResponsePckg,iStatus);
       
    53 			break;
       
    54 			}
       
    55 		case EGetGlobalStartupMode :
       
    56 			{
       
    57 			iMiscAdaptation.GetGlobalStartupMode(iModePckg,iStatus);
       
    58 			break;
       
    59 			}
       
    60 		case EPrepareSimLanguages :
       
    61 			{
       
    62 			TSsmLanguageListPriority priority = (TSsmLanguageListPriority)aMessage->Int0();
       
    63 			iMiscAdaptation.PrepareSimLanguages(priority,iSizePckg,iStatus);
       
    64 			break;
       
    65 			}
       
    66 		case EGetHiddenReset :
       
    67 			{
       
    68 			iMiscAdaptation.GetHiddenReset(iHiddenResetPckg, iStatus);
       
    69 			break;	
       
    70 			}
       
    71 		default :
       
    72 			{
       
    73 			break;
       
    74 			}
       
    75 		}
       
    76 	SetActive();
       
    77 	}
       
    78 
       
    79 
       
    80 /**
       
    81 CMiscAdaptation implements Miscellaneous Adaptation related functionality as part of 
       
    82 CSsmAdaptationServer.CSsmAdaptationServer loads Misc Adaptation plugin and creates
       
    83 CMiscAdaptation using the NewL. From then the loaded Misc Adaptation plugin will be owned 
       
    84 by CMiscAdaptation.
       
    85 
       
    86 @internalComponent
       
    87 */
       
    88 CMiscAdaptation* CMiscAdaptation::NewL(MMiscAdaptation& aAdaptation)
       
    89 	{
       
    90 	CMiscAdaptation* self = new(ELeave) CMiscAdaptation(aAdaptation);
       
    91 	return self;	
       
    92 	}
       
    93 
       
    94 CMiscAdaptation::~CMiscAdaptation()
       
    95 	{
       
    96 	iPendingRequestsQueue.NotifyAndRemoveAll();
       
    97 	Cancel();
       
    98 	iPendingRequestsQueue.Close();
       
    99 	Release();
       
   100 	}
       
   101 
       
   102 CMiscAdaptation::CMiscAdaptation(MMiscAdaptation& aAdaptation) :CActive(EPriorityStandard),
       
   103 iMiscAdaptation(aAdaptation),iResponsePckg(0),iModePckg(0),iSizePckg(0),iListPckg(0)
       
   104 	{
       
   105 	CActiveScheduler::Add(this);	
       
   106 	}
       
   107 
       
   108 void CMiscAdaptation::Release()
       
   109 	{
       
   110 	iMiscAdaptation.Release();
       
   111 	}
       
   112 
       
   113 void CMiscAdaptation::DoSecurityStateChangeL(const RMessage2& aMessage)
       
   114 	{
       
   115 	SubmitOrQueueL(aMessage);
       
   116 	}
       
   117 	
       
   118 void CMiscAdaptation::DoGetGlobalStartupModeL(const RMessage2& aMessage)
       
   119 	{
       
   120 	SubmitOrQueueL(aMessage);
       
   121 	}
       
   122 
       
   123 void CMiscAdaptation::DoPrepareSimLanguagesL(const RMessage2& aMessage)
       
   124 	{
       
   125 	SubmitOrQueueL(aMessage);
       
   126 	}
       
   127 
       
   128 void CMiscAdaptation::DoGetSimLanguagesArrayL(const RMessage2& aMessage)
       
   129 	{
       
   130 	const TInt simLanguageCount = aMessage.Int1();
       
   131 	CBufFlat* const buf=CBufFlat::NewL(simLanguageCount * sizeof(TInt32));
       
   132 	CleanupStack::PushL(buf);
       
   133 
       
   134 	iMiscAdaptation.GetSimLanguagesL(buf, simLanguageCount);
       
   135 
       
   136 	aMessage.WriteL(0, buf->Ptr(0));
       
   137 	
       
   138 	CleanupStack::PopAndDestroy(buf);
       
   139 	}
       
   140 
       
   141 void CMiscAdaptation::DoMiscAdaptationCancelL(const RMessage2& aMessage)
       
   142 	{
       
   143 	if(iCurrentMessage != NULL)	
       
   144 		{
       
   145 		if(aMessage.Session() == iCurrentMessage->Session())
       
   146 			{
       
   147 			DEBUGPRINT1A("CMiscAdaptationRequests cancelling current request as requested");
       
   148 			iMiscAdaptation.Cancel();
       
   149 			}
       
   150 		iPendingRequestsQueue.RemoveFromQueueAndComplete(aMessage);  	
       
   151 		aMessage.Complete(KErrNone);
       
   152 		}
       
   153 	else
       
   154 		{
       
   155 		DEBUGPRINT1A("CMiscAdaptationRequests nothing to cancel, but cancel requested");
       
   156 		aMessage.Complete(KErrNone);				
       
   157 		}	
       
   158 	}
       
   159 
       
   160 void CMiscAdaptation::DoMiscAdaptationHiddenResetL(const RMessage2& aMessage)
       
   161 	{
       
   162 	SubmitOrQueueL(aMessage);
       
   163 	}
       
   164 
       
   165 // from CActive
       
   166 void CMiscAdaptation::RunL()
       
   167 	{
       
   168 	
       
   169 	DEBUGPRINT2A("CMiscAdaptation processed the request with funtion id: %d", iCurrentMessage->Function());
       
   170 	WriteResponseDataToClientMessageL();
       
   171 	iCurrentMessage->Complete(iStatus.Int());
       
   172 	delete iCurrentMessage;
       
   173 	iCurrentMessage = NULL;  
       
   174 
       
   175 	if( (iPendingRequestsQueue.IsEmpty()) == EFalse )
       
   176 		{
       
   177 		CAdaptationMessage *messageCopy = NULL;
       
   178 		iPendingRequestsQueue.Dequeue(messageCopy);
       
   179 		Submit(messageCopy);
       
   180 		} 
       
   181 	}
       
   182 
       
   183 
       
   184 
       
   185 void CMiscAdaptation::WriteResponseDataToClientMessageL()
       
   186 	{
       
   187 	switch(iCurrentMessage->Function())
       
   188 		{
       
   189 			case ESecurityStateChange:
       
   190 				{
       
   191 				iCurrentMessage->WriteL(1,iResponsePckg);
       
   192 				break;					
       
   193 				}
       
   194 			case EGetGlobalStartupMode:
       
   195 				{
       
   196 				iCurrentMessage->WriteL(0,iModePckg);
       
   197 				break;					
       
   198 				}
       
   199 			case EPrepareSimLanguages:
       
   200 				{
       
   201 				iCurrentMessage->WriteL(1,iSizePckg);
       
   202 				break;					
       
   203 				}
       
   204 			case EGetHiddenReset :
       
   205 				{
       
   206 				iCurrentMessage->WriteL(0,iHiddenResetPckg);
       
   207 				}				
       
   208 			default:
       
   209 				{
       
   210 				break;					
       
   211 				}				
       
   212 		}
       
   213 	}
       
   214 
       
   215 
       
   216 TInt CMiscAdaptation::RunError( TInt aError)
       
   217 	{
       
   218 
       
   219 	if(iCurrentMessage != NULL)	
       
   220 		{
       
   221 		iCurrentMessage->Complete(aError);
       
   222 		delete iCurrentMessage;
       
   223 		iCurrentMessage = NULL;
       
   224 		}
       
   225 	
       
   226 	while( (iPendingRequestsQueue.IsEmpty()) == EFalse )
       
   227 		{
       
   228 		iPendingRequestsQueue.Dequeue(iCurrentMessage);
       
   229 		iCurrentMessage->Complete(aError);
       
   230 		delete iCurrentMessage;
       
   231 		iCurrentMessage = NULL;
       
   232 		}
       
   233 	
       
   234 	return KErrNone;
       
   235 		
       
   236 	}
       
   237 
       
   238 void CMiscAdaptation::DoCancel()
       
   239 	{
       
   240 	if(iCurrentMessage != NULL)	
       
   241 		{
       
   242 		iCurrentMessage->Complete(KErrCancel);
       
   243 		delete iCurrentMessage;
       
   244 		iCurrentMessage = NULL;
       
   245 		}
       
   246 		
       
   247 	while( (iPendingRequestsQueue.IsEmpty()) == EFalse )
       
   248 		{
       
   249 		iPendingRequestsQueue.Dequeue(iCurrentMessage);
       
   250 		iCurrentMessage->Complete(KErrCancel);
       
   251 		delete iCurrentMessage;
       
   252 		iCurrentMessage = NULL;
       
   253 		}
       
   254 	}
       
   255 
       
   256