messagingappbase/smsmtm/servermtm/src/SMSSERV.CPP
changeset 23 238255e8b033
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 // SmssServ.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "SMSSERV.H"
       
    19 #include "SMSSPAN.H"
       
    20 #include "SMSSOUTB.H"
       
    21 
       
    22 #include <msventry.h>
       
    23 #include <SMSS.rsg>
       
    24 #include <smscmds.h>
       
    25 #include <smut.h>
       
    26 #include <c32comm.h>
       
    27 #include "SMSSchSend.h"
       
    28 #include "SmssSimUtils.h"
       
    29 #include <centralrepository.h>
       
    30 #include <tmsvsystemprogress.h>
       
    31 
       
    32 EXPORT_C CSmsServerMtm* CSmsServerMtm::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aServerEntry)
       
    33 	{
       
    34 	CSmsServerMtm* smsservermtm=new(ELeave) CSmsServerMtm(aRegisteredMtmDll, aServerEntry);
       
    35 	CleanupStack::PushL(smsservermtm);
       
    36 	smsservermtm->ConstructL();
       
    37 	CleanupStack::Pop();
       
    38 	return smsservermtm;
       
    39 	}
       
    40 
       
    41 CSmsServerMtm::~CSmsServerMtm()
       
    42 	{
       
    43 	Cancel();
       
    44 	delete iScheduleSend;
       
    45 	delete iOutboxSend;
       
    46 	delete iSimUtils;
       
    47 	}
       
    48 
       
    49 void CSmsServerMtm::CopyToLocalL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& aStatus)
       
    50 	{
       
    51 	TRequestStatus* status=&aStatus;
       
    52 	User::RequestComplete(status,KErrNotSupported);
       
    53 	}
       
    54 
       
    55 void CSmsServerMtm::CopyFromLocalL(const CMsvEntrySelection& aSelection,TMsvId /*aDestination*/, TRequestStatus& aStatus)
       
    56 	{
       
    57 	__ASSERT_ALWAYS(iServerEntry!=NULL,Panic(ESmssEntryNotSet));
       
    58 	__ASSERT_ALWAYS(!iOutboxSend, Panic(KSmssPanicMtmAlreadyActive));
       
    59 	
       
    60 	Queue(aStatus);
       
    61 	RestoreSettingsL();
       
    62 	iOutboxSend=CSmsOutboxSend::NewL(*iServerEntry, *iScheduleSend, iFs);
       
    63 	iState=ESmsServerMtmSending;
       
    64 #if (defined SYMBIAN_USER_PROMPT_SERVICE)	
       
    65 	iOutboxSend->StartL(iStatus,aSelection, EFalse, KNullDesC8, iClientThreadId, iHasCapability);
       
    66 #else
       
    67 	iOutboxSend->Start(iStatus,aSelection, EFalse, KNullDesC8);
       
    68 #endif	
       
    69 	SetActive();
       
    70 	}
       
    71 
       
    72 void CSmsServerMtm::CopyWithinServiceL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& aStatus)
       
    73 	{
       
    74 	TRequestStatus* status=&aStatus;
       
    75 	User::RequestComplete(status,KErrNotSupported);
       
    76 	}
       
    77 
       
    78 void CSmsServerMtm::MoveToLocalL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& aStatus)
       
    79 	{
       
    80 	TRequestStatus* status=&aStatus;
       
    81 	User::RequestComplete(status,KErrNotSupported);
       
    82 	}
       
    83 
       
    84 void CSmsServerMtm::MoveFromLocalL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& aStatus)
       
    85 	{
       
    86 	TRequestStatus* status=&aStatus;
       
    87 	User::RequestComplete(status,KErrNotSupported);
       
    88 	}
       
    89 
       
    90 void CSmsServerMtm::MoveWithinServiceL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& aStatus)
       
    91 	{
       
    92 	TRequestStatus* status=&aStatus;
       
    93 	User::RequestComplete(status,KErrNotSupported);
       
    94 	}
       
    95 
       
    96 void CSmsServerMtm::DeleteAllL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus)
       
    97 	{
       
    98 	iProgress = TSmsProgress();
       
    99 	iProgress.iType = TSmsProgress::ESmsProgressTypeDeleteAll;
       
   100 	iProgress.iMsgCount = aSelection.Count();
       
   101 	User::LeaveIfError(iServerEntry->SetEntry(aSelection[0]));
       
   102 	User::LeaveIfError(iServerEntry->SetEntry(iServerEntry->Entry().Parent()));
       
   103 	CMsvEntrySelection* sel = aSelection.CopyL();
       
   104 	iProgress.iError = iServerEntry->DeleteEntries(*sel);
       
   105 	delete sel;
       
   106 
       
   107 	TRequestStatus* status = &aStatus;
       
   108 	User::RequestComplete(status, KErrNone);
       
   109 	}
       
   110 
       
   111 void CSmsServerMtm::CreateL(TMsvEntry /*aNewEntry*/, TRequestStatus& aStatus)
       
   112 	{
       
   113 	TRequestStatus* status=&aStatus;
       
   114 	User::RequestComplete(status,KErrNotSupported);
       
   115 	}
       
   116 
       
   117 void CSmsServerMtm::ChangeL(TMsvEntry /*aNewEntry*/, TRequestStatus& aStatus)
       
   118 	{
       
   119 	TRequestStatus* status=&aStatus;
       
   120 	User::RequestComplete(status,KErrNotSupported);
       
   121 	}
       
   122 
       
   123 void CSmsServerMtm::StartCommandL(CMsvEntrySelection& aSelection, TInt aCommand, const TDesC8& aParameter, TRequestStatus& aStatus)
       
   124 	{
       
   125 	__ASSERT_ALWAYS(iServerEntry!=NULL,Panic(ESmssEntryNotSet));
       
   126 	__ASSERT_ALWAYS(iState==ESmsServerMtmWaiting,Panic(KSmssPanicMtmAlreadyActive));
       
   127 
       
   128 	RestoreSettingsL();	
       
   129 	iProgress = TSmsProgress();
       
   130 	TInt err = KErrNone;
       
   131 
       
   132 	switch (aCommand)
       
   133 		{
       
   134 		case ESmsMtmCommandScheduleCopy:
       
   135 		case ESmsMtmCommandScheduleMove:
       
   136 		case ESmsMtmCommandDeleteSchedule:
       
   137 		case ESmsMtmCommandCheckSchedule:
       
   138 		case ESmsMtmCommandSendScheduledCopy:
       
   139 		case ESmsMtmCommandSendScheduledMove:
       
   140 			{
       
   141 			TRAP(err, ScheduleCommandL(aSelection, aCommand, aParameter, aStatus));
       
   142 			break;
       
   143 			}
       
   144 		case ESmsMtmCommandEnumeratePhoneStores:
       
   145 		case ESmsMtmCommandDeleteFromPhoneStore:
       
   146 		case ESmsMtmCommandCopyFromPhoneStore:
       
   147 		case ESmsMtmCommandMoveFromPhoneStore:
       
   148 		case ESmsMtmCommandReadSimParams:
       
   149 		case ESmsMtmCommandWriteSimParams:
       
   150 		case ESmsMtmCommandCopyToPhoneStore:
       
   151 		case ESmsMtmCommandMoveToPhoneStore:
       
   152 			{
       
   153 			TRAP(err, SimUtilsL(aSelection, aCommand, aParameter, aStatus));
       
   154 			break;
       
   155 			}
       
   156 		default:
       
   157 			{
       
   158 			Panic(KSmssPanicUnexpectedCommand);
       
   159 			}
       
   160 		}
       
   161 
       
   162 	if (err != KErrNone)
       
   163 		{
       
   164 		iServerEntry->SetEntry(KMsvNullIndexEntryId);
       
   165 		User::Leave(err);
       
   166 		}
       
   167 	}
       
   168 
       
   169 TBool CSmsServerMtm::CommandExpected()
       
   170 	{
       
   171 	return EFalse;
       
   172 	}
       
   173 
       
   174 const TDesC8& CSmsServerMtm::Progress()
       
   175 	{
       
   176 	switch (iState)
       
   177 		{
       
   178 		case ESmsServerMtmSending:
       
   179 			{
       
   180 			iProgress = iOutboxSend->Progress();
       
   181 			break;
       
   182 			}
       
   183 		case ESmsServerMtmSimUtils:
       
   184 			{
       
   185 			iProgress = iSimUtils->Progress();
       
   186 			break;
       
   187 			}
       
   188 		default:
       
   189 			{
       
   190 			//Do not change iProgress
       
   191 			}
       
   192 		}
       
   193 
       
   194 	iProgressBuf = TSmsProgressBuf(iProgress);
       
   195 	return iProgressBuf;
       
   196 	}
       
   197 
       
   198 void CSmsServerMtm::DoCancel()
       
   199 	{
       
   200 	switch (iState)
       
   201 		{
       
   202 		case ESmsServerMtmSending:
       
   203 			{
       
   204 			iOutboxSend->Cancel();
       
   205 			break;
       
   206 			}
       
   207 		case ESmsServerMtmSimUtils:
       
   208 			{
       
   209 			iSimUtils->Cancel();
       
   210 			break;
       
   211 			}
       
   212 		case ESmsServerMtmScheduling:
       
   213 			{
       
   214 			break;
       
   215 			}
       
   216 		default:
       
   217 			{
       
   218 			Panic(KSmssPanicUnexpectedCommand);
       
   219 			}
       
   220 		}
       
   221 	CompleteCommand(KErrCancel);
       
   222 	}
       
   223 
       
   224 void CSmsServerMtm::DoRunL()
       
   225 	{
       
   226 	DoComplete(KErrNone);
       
   227 	}
       
   228 
       
   229 void CSmsServerMtm::CompleteCommand(TInt aError)
       
   230 	{
       
   231 	if (iReport)
       
   232 		{
       
   233 		switch (iState)
       
   234 			{
       
   235 			case ESmsServerMtmSending:
       
   236 				{
       
   237 				Progress();
       
   238 				delete iOutboxSend;
       
   239 				iOutboxSend=NULL;
       
   240 				break;
       
   241 				}
       
   242 			case ESmsServerMtmScheduling:
       
   243 				{
       
   244 				break;
       
   245 				}
       
   246 			case ESmsServerMtmSimUtils:
       
   247 				{
       
   248 				Progress();
       
   249 				delete iSimUtils;
       
   250 				iSimUtils = NULL;
       
   251 				break;
       
   252 				}
       
   253 			default:
       
   254 				{
       
   255 				Panic(KSmssPanicUnexpectedState);
       
   256 				}
       
   257 			}
       
   258 		if (aError != KErrNone)         //  iProgress.iError may be recording a send error 
       
   259 			{
       
   260 			iProgress.iError = aError;  //  so it shouldn't be over-written with KErrNone
       
   261 			}
       
   262 
       
   263 		User::RequestComplete(iReport, KErrNone);
       
   264 		}
       
   265 
       
   266 	iState = ESmsServerMtmWaiting;
       
   267 	iReport = NULL;
       
   268 
       
   269 	if (iServerEntry)
       
   270 		iServerEntry->SetEntry(KMsvNullIndexEntryId); //ignore error
       
   271 	}
       
   272 
       
   273 void CSmsServerMtm::DoComplete(TInt aError)
       
   274 	{
       
   275 	CompleteCommand(aError);
       
   276 	}
       
   277 
       
   278 CSmsServerMtm::CSmsServerMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aServerEntry):
       
   279 	CScheduleBaseServerMtm(aRegisteredMtmDll, aServerEntry)
       
   280 	{
       
   281 	CActiveScheduler::Add(this);
       
   282 	}
       
   283 		
       
   284 void CSmsServerMtm::ConstructL()
       
   285 	{
       
   286 	CScheduleBaseServerMtm::ConstructL();
       
   287 
       
   288 #if defined (__WINS__)
       
   289 	TInt ret=StartC32();
       
   290 	if (ret!=KErrAlreadyExists)
       
   291 		User::LeaveIfError(ret);
       
   292 #endif
       
   293 
       
   294 	iScheduleSend = CSmsScheduleSend::NewL(*iServerEntry);
       
   295     TSmsUtilities::ServiceIdL(*iServerEntry, iSmsServiceId);
       
   296 	RestoreSettingsL();
       
   297 	}
       
   298 
       
   299 void CSmsServerMtm::RestoreSettingsL()
       
   300 	{
       
   301 	__ASSERT_ALWAYS(iServerEntry!=NULL,Panic(ESmssEntryNotSet));
       
   302 
       
   303 	User::LeaveIfError(iServerEntry->SetEntry(iSmsServiceId));
       
   304 	RestoreScheduleSettingsL();
       
   305 	User::LeaveIfError(iServerEntry->SetEntry(KMsvNullIndexEntryId));
       
   306 	}
       
   307 
       
   308 void CSmsServerMtm::LoadResourceFileL()
       
   309 	{
       
   310 	CScheduleBaseServerMtm::LoadResourceFileL(KSmsResourceFile);
       
   311 	}
       
   312 
       
   313 void CSmsServerMtm::RestoreScheduleSettingsL()
       
   314 	{
       
   315 	CRepository* repository = CRepository::NewLC(KUidMsgTypeSMS);
       
   316 	// just v2
       
   317 	CScheduleBaseServerMtm::LoadScheduleSettingsL(*repository, ETrue, ERROR_ACTIONS);
       
   318 	CleanupStack::PopAndDestroy(repository);    
       
   319 	}
       
   320 
       
   321 void CSmsServerMtm::PopulateSchedulePackage(const TDesC8& aParameter, const TBool aMove, TMsvSchedulePackage& aPackage) const
       
   322 	{
       
   323 	aPackage.iPollProgress = 3000000;
       
   324 	aPackage.iParameter = aParameter;
       
   325 	aPackage.iCommandId = aMove ? ESmsMtmCommandSendScheduledMove : ESmsMtmCommandSendScheduledCopy;
       
   326 	}
       
   327 
       
   328 void CSmsServerMtm::ScheduleCommandL(CMsvEntrySelection& aSelection, TInt aCommand, const TDesC8& aParameter, TRequestStatus& aStatus)
       
   329 	{
       
   330 	iState = ESmsServerMtmScheduling;
       
   331 	iProgress.iType = TSmsProgress::ESmsProgressTypeScheduling;
       
   332 
       
   333 	switch (aCommand)
       
   334 		{
       
   335 		case ESmsMtmCommandScheduleCopy:
       
   336 			ScheduleL(aSelection, EFalse, aParameter, aStatus);
       
   337 			break;
       
   338 		case ESmsMtmCommandScheduleMove:
       
   339 			{
       
   340 			TRequestStatus* status = &aStatus;
       
   341 			User::RequestComplete(status, KErrNotSupported);
       
   342 			break;
       
   343 			}
       
   344 		case ESmsMtmCommandDeleteSchedule:
       
   345 			iProgress.iType  = TSmsProgress::ESmsProgressTypeDeleteSchedule;
       
   346 			DeleteScheduleL(aSelection, aParameter, aStatus);
       
   347 			break;
       
   348 		case ESmsMtmCommandCheckSchedule:
       
   349 			iProgress.iType = TSmsProgress::ESmsProgressTypeCheckSchedule;
       
   350 			CheckScheduleL(aSelection, aParameter, aStatus);
       
   351 			break;
       
   352 		case ESmsMtmCommandSendScheduledCopy:
       
   353 			SendScheduledL(aSelection, EFalse, aParameter, aStatus);
       
   354 			break;
       
   355 		case ESmsMtmCommandSendScheduledMove:
       
   356 			SendScheduledL(aSelection, ETrue, aParameter, aStatus);
       
   357 			break;
       
   358 		default:
       
   359 			Panic(KSmssPanicUnexpectedCommand);
       
   360 		}
       
   361 	}
       
   362 
       
   363 void CSmsServerMtm::SimUtilsL(const CMsvEntrySelection& aSelection, TInt aCommand, const TDesC8& aParameter, TRequestStatus& aStatus)
       
   364 	{
       
   365 	__ASSERT_DEBUG(iSimUtils == NULL, Panic(KSmssPanicAlreadyUsingSimUtils));
       
   366 	
       
   367 	Queue(aStatus);
       
   368 
       
   369 	iSimUtils = CSmsSimUtils::NewL(*iServerEntry, iFs, iSmsServiceId);
       
   370 
       
   371 	iState = ESmsServerMtmSimUtils;
       
   372 
       
   373 	switch (aCommand)
       
   374 		{
       
   375 		case ESmsMtmCommandEnumeratePhoneStores:
       
   376 			iSimUtils->EnumerateL(aParameter, iStatus);
       
   377 			break;
       
   378 		case ESmsMtmCommandDeleteFromPhoneStore:
       
   379 			iSimUtils->DeleteFromPhoneStoreL(aSelection, iStatus);
       
   380 			break;
       
   381 		case ESmsMtmCommandCopyFromPhoneStore:
       
   382 			iSimUtils->CopyFromPhoneStoreL(aSelection, aParameter, iStatus);
       
   383 			break;
       
   384 		case ESmsMtmCommandMoveFromPhoneStore:
       
   385 			iSimUtils->MoveFromPhoneStoreL(aSelection, aParameter, iStatus);
       
   386 			break;
       
   387 		case ESmsMtmCommandReadSimParams:
       
   388 			iSimUtils->ReadSimParamsL(iStatus);
       
   389 			break;
       
   390 		case ESmsMtmCommandWriteSimParams:
       
   391 			iSimUtils->WriteSimParamsL(iStatus);
       
   392 			break;
       
   393 		case ESmsMtmCommandCopyToPhoneStore:
       
   394 			iSimUtils->CopyToPhoneStoreL(aSelection, aParameter, iStatus);
       
   395 			break;
       
   396 		case ESmsMtmCommandMoveToPhoneStore:
       
   397 			iSimUtils->MoveToPhoneStoreL(aSelection, aParameter, iStatus);
       
   398 			break;
       
   399 		default:
       
   400 			Panic(KSmssPanicUnexpectedCommand);
       
   401 		}
       
   402 
       
   403 	SetActive();
       
   404 	}
       
   405 
       
   406 /**
       
   407 The extension method provides a polymorphic behaviour to call the correct
       
   408 MTM.
       
   409 @param aExtensionId The Uid passed in as KUIDMsgClientThreadInfo to copy the
       
   410 					Client Thread Info.
       
   411 @return KErrNone.
       
   412 */	
       
   413 TInt CSmsServerMtm::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
       
   414 	{
       
   415 	switch(aExtensionId)
       
   416 		{
       
   417 #if (defined SYMBIAN_USER_PROMPT_SERVICE)		
       
   418 		case KUIDMsgClientThreadInfo:
       
   419 			{
       
   420 			iClientThreadId = *(TThreadId*) (a1);
       
   421 	    	iHasCapability = (TBool)*(TInt*)(a0);
       
   422 	    	return KErrNone;
       
   423 			}
       
   424 #endif			
       
   425 		case KUIDMsgMsvSystemProgress:
       
   426 		default:
       
   427 			{
       
   428 			// Chain to base class
       
   429 			return CBaseServerMtm::Extension_(aExtensionId, a0, a1);
       
   430 			}
       
   431 		}
       
   432 	}