telephonyserverplugins/multimodetsy/Multimode/Mphbook.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 // \file MPHBOOK.CPP
       
    15 // Mulimode TSY Phone book access Implementation file.
       
    16 // This file contains the implementation of the CMobilePhonebookStore 
       
    17 // class which is used for GSM phone book access. 
       
    18 // 
       
    19 //
       
    20 
       
    21 #include "mSLOGGER.H"
       
    22 #include "mPHBOOK.H"
       
    23 #include "Mphbkcom.h"
       
    24 #include "ATINIT.H"
       
    25 #include "NOTIFY.H"
       
    26 #include <etelmm.h>
       
    27 
       
    28 //
       
    29 // CPhoneBook definitions
       
    30 //
       
    31 
       
    32 CMobilePhonebookStore* CMobilePhonebookStore::NewL(CATIO* aATIO,CATInit* aInit,CPhoneGlobals* aPhoneGlobals,const TDesC8& aStorageType)
       
    33 /**
       
    34  * Standard 2 phase constructor.
       
    35  */
       
    36 	{
       
    37 	CMobilePhonebookStore* subsession=new(ELeave) CMobilePhonebookStore(aATIO,aInit,aPhoneGlobals,aStorageType);
       
    38 	CleanupStack::PushL(subsession);
       
    39 	subsession->ConstructL();
       
    40 	CleanupStack::Pop();
       
    41 	return subsession;
       
    42 	}
       
    43 
       
    44 CMobilePhonebookStore::CMobilePhonebookStore(CATIO* aATIO,CATInit* aInit,CPhoneGlobals* aMmGlobals,const TDesC8& aStorageType)
       
    45 	: iIo(aATIO), iInit(aInit), iPhoneGlobals(aMmGlobals), iStorageType(aStorageType)
       
    46 	{	
       
    47 	}
       
    48 
       
    49 void CMobilePhonebookStore::ConstructL()
       
    50 /**
       
    51  * ConstructL() function. Creates CATPhoneBookInit, CATPhoneBookWrite, CATPhoneBookDelete
       
    52  * objects.
       
    53  */
       
    54 	{
       
    55 	iInfo=CATPhoneBookInfo::NewL(iIo,this,iInit,iPhoneGlobals);
       
    56 	iRead=CATPhoneBookRead::NewL(iIo,this,iInit,iPhoneGlobals,iInfo);
       
    57 	iWrite=CATPhoneBookWrite::NewL(iIo,this,iInit,iPhoneGlobals);
       
    58 	iDelete=CATPhoneBookDelete::NewL(iIo,this,iInit,iPhoneGlobals);
       
    59 
       
    60 	// Assume that all phone books have at least read access
       
    61 	iReadWriteAccess|=RMobilePhoneStore::KCapsReadAccess;
       
    62 
       
    63 	// Check if phone book should have write access	
       
    64 	if (CPhoneGlobals::IsWriteAccess(iStorageType))
       
    65 		iReadWriteAccess |= RMobilePhoneStore::KCapsWriteAccess | RMobilePhoneStore::KCapsReadAccess;
       
    66 	}
       
    67 
       
    68 CMobilePhonebookStore::~CMobilePhonebookStore()
       
    69 /**
       
    70  * Destructor.
       
    71  */
       
    72 	{
       
    73 	if (iPhoneGlobals != NULL)
       
    74 		iPhoneGlobals->iNotificationStore->RemoveClientFromLastEvents(this); //Joe
       
    75 	delete iRead;
       
    76 	delete iWrite;
       
    77 	delete iDelete;
       
    78 	delete iInfo;
       
    79 	}
       
    80 
       
    81 CTelObject::TReqMode CMobilePhonebookStore::ReqModeL(const TInt aIpc)
       
    82 /**
       
    83  * This function is basically a switch statement which describes the flow control
       
    84  * capabilities for each request dealt with by the CPhoneBook sub-session extension.
       
    85  */
       
    86 	{
       
    87 	CTelObject::TReqMode ret(0);
       
    88 
       
    89 	switch (aIpc)
       
    90 		{
       
    91 	case EMobilePhoneStoreGetInfo:
       
    92 		ret=KReqModeFlowControlObeyed|KReqModeMultipleCompletionEnabled;
       
    93 		break;
       
    94 
       
    95 	case EMobilePhoneBookStoreWrite:
       
    96 	case EMobilePhoneBookStoreRead:
       
    97 	case EMobilePhoneStoreDelete:
       
    98 		ret=KReqModeFlowControlObeyed;
       
    99 		break;
       
   100 
       
   101 	default:
       
   102 		User::Leave(KErrNotSupported);
       
   103 		}
       
   104 
       
   105 	// Check if the data port is currently loaned. If it is and the requested IPC
       
   106 	// is flow controlled then block Etel calling the IPC by leaving with KErrInUse
       
   107 	if((ret&KReqModeFlowControlObeyed) && iPhoneGlobals->iPhoneStatus.iDataPortLoaned)
       
   108 		{
       
   109 		LOGTEXT2(_L8("ReqModeL Leaving with KErrInUse as data port is loaned (aIpc=%d)"),aIpc);
       
   110 		User::Leave(KErrInUse);
       
   111 		}
       
   112 	
       
   113 	return ret;	
       
   114 	}
       
   115 
       
   116 TInt CMobilePhonebookStore::NumberOfSlotsL(const TInt /*aIpc*/)
       
   117 /**
       
   118  * This function returns the number of slots (buffered in server) for any 
       
   119  * KReqRepostImmediately Ipc calls in the ReqModeL() function.
       
   120  */
       
   121 	{
       
   122 	return 1;
       
   123 	}
       
   124 
       
   125 TInt CMobilePhonebookStore::RegisterNotification(const TInt /*aIpc*/)
       
   126 /**
       
   127  * This function is not supported.
       
   128  */
       
   129 	{
       
   130 	return KErrNone;
       
   131 	}
       
   132 
       
   133 TInt CMobilePhonebookStore::DeregisterNotification(const TInt /*aIpc*/)
       
   134 /**
       
   135  * This function is not supported.
       
   136  */
       
   137 	{
       
   138 	return KErrNone;
       
   139 	}
       
   140 
       
   141 void CMobilePhonebookStore::Init()
       
   142 	{
       
   143 	LOGTEXT(_L8("CMobilePhonebookStore::Init() called"));
       
   144 	}
       
   145 
       
   146 TInt CMobilePhonebookStore::CancelService(const TInt aIpcToCancel,const TTsyReqHandle aTsyReqHandle)
       
   147 /**
       
   148  * This function is called when an asynchronous request has passed to the TSY module
       
   149  * but is yet to be completed. It's used to cancel a client's service request.
       
   150  */
       
   151 	{
       
   152 	switch (aIpcToCancel)
       
   153 		{
       
   154 	case EMobilePhoneBookStoreWrite:
       
   155 		iWrite->CancelCommand(aTsyReqHandle); 
       
   156 		break;
       
   157 	case EMobilePhoneBookStoreRead:
       
   158 		iRead->CancelCommand(aTsyReqHandle);
       
   159 		break;
       
   160 	case EMobilePhoneStoreDelete:
       
   161 		iDelete->CancelCommand(aTsyReqHandle);
       
   162 		break; 
       
   163 	case EMobilePhoneStoreGetInfo: 
       
   164 		iInfo->CancelCommand(aTsyReqHandle); 
       
   165 		break;
       
   166 	default:	// & synchronous functions, nothing to cancel
       
   167 		break;
       
   168 		}
       
   169 	return KErrNone;
       
   170 	}
       
   171 
       
   172 CTelObject* CMobilePhonebookStore::OpenNewObjectByNameL(const TDesC& /*aName*/)
       
   173 /**
       
   174  * This function is not supported.
       
   175  */
       
   176 	{
       
   177 	User::Leave(KErrNotSupported);
       
   178 	return NULL;
       
   179 	}
       
   180 	
       
   181 CTelObject* CMobilePhonebookStore::OpenNewObjectL(TDes& /*aName*/)
       
   182 /**
       
   183  * This function is not supported.
       
   184  */
       
   185 	{	
       
   186 	User::Leave(KErrNotSupported);
       
   187 	return NULL;
       
   188 	}
       
   189 	
       
   190 
       
   191 TInt CMobilePhonebookStore::ExtFunc(const TTsyReqHandle aTsyReqHandle, const TInt aIpc,const TDataPackage& aPackage)
       
   192 /**
       
   193  * This function is responsible for dealing with IPC requests the server doesn't support.
       
   194  */
       
   195 	{
       
   196 	// Can't initialise if the port is tied up...
       
   197 	if((iPhoneGlobals->iPhoneStatus.iPortAccess==EPortAccessDenied) || (iPhoneGlobals->iPhoneStatus.iMode == RPhone::EModeOnlineData))
       
   198 		{
       
   199 		LOGTEXT2(_L8("CMobilePhonebookStore::ExtFunc (aIpc=%d)"),aIpc);
       
   200 		LOGTEXT(_L8("CMobilePhonebookStore::ExtFunc\tPort Access Denied/Mode Online flag detected, returning KErrAccessDenied error"));
       
   201 
       
   202 		return KErrAccessDenied;
       
   203 		}
       
   204 
       
   205 	// we can handle the request now
       
   206 	return HandleExtFunc(aTsyReqHandle,aIpc,aPackage);
       
   207 	}
       
   208 
       
   209 TInt CMobilePhonebookStore::HandleExtFunc(TTsyReqHandle aTsyReqHandle,TInt aIpc,const TDataPackage& aPackage)
       
   210 /**
       
   211  * Handle the requested function. The phone book data is now fully live.
       
   212  */
       
   213 	{
       
   214 	// We're in a state to execute commands...
       
   215 	TAny* dataPtr1=aPackage.Ptr1();
       
   216 	TAny* dataPtr2=aPackage.Ptr2();
       
   217 
       
   218 	switch (aIpc)
       
   219 		{
       
   220 	case EMobilePhoneStoreGetInfo:
       
   221 		return GetInfo(aTsyReqHandle, aPackage.Des1n());
       
   222 
       
   223 	case EMobilePhoneBookStoreRead:
       
   224 		return Read(aTsyReqHandle, reinterpret_cast<RMobilePhoneBookStore::TPBIndexAndNumEntries*>(dataPtr1), aPackage.Des2n());
       
   225 
       
   226 	case EMobilePhoneBookStoreWrite:
       
   227 		return Write(aTsyReqHandle, aPackage.Des1n(), reinterpret_cast<TInt*>(dataPtr2));
       
   228 
       
   229 	case EMobilePhoneStoreDelete:
       
   230 		return Delete(aTsyReqHandle,reinterpret_cast<TInt*>(dataPtr1));	
       
   231 	
       
   232 	default:
       
   233 		return KErrNotSupported;
       
   234 		}
       
   235 	}
       
   236 
       
   237 TInt CMobilePhonebookStore::GetInfo(TTsyReqHandle aTsyReqHandle, TDes8* aInfoPckg)
       
   238 /** Get Phone Book Storage Information
       
   239  *
       
   240  * This function queries the phone for storage information on the current phone book
       
   241  * store. 
       
   242  * It returns the related storage information only if supported by the phone.
       
   243  * @param aTsyReqHandle Handle to the request ID .
       
   244  * @param aInfoPckg Pointer to the struct that contains information about the phone book.
       
   245  * @return error code. 
       
   246  */
       
   247 	{
       
   248 	LOGTEXT(_L8("CMobilePhonebookStore::GetInfo called"));
       
   249 
       
   250 	// Have to send AT+CPBR=? to get the phonebook information
       
   251 	// This command is sent every time to ensure we have up-to-date knowledge
       
   252 	// of used number of entries
       
   253 	iInfo->SetStorageType(iStorageType);
       
   254 	iInfo->ExecuteCommand(aTsyReqHandle, aInfoPckg);
       
   255 	
       
   256 	return KErrNone;
       
   257 	}
       
   258 
       
   259 TInt CMobilePhonebookStore::Read(TTsyReqHandle aTsyReqHandle, RMobilePhoneBookStore::TPBIndexAndNumEntries* aIndexAndEntries, TDes8* aPBData)
       
   260 /** Read one or a number of Phone Book Enties
       
   261  *
       
   262  * This function reads the phone book entries from the current
       
   263  * phone book store.
       
   264  * @param aTsyReqHandle Handle to the request ID.
       
   265  * @param aIndexAndEntries is a pointer to an index and a number of entries.
       
   266  * @param aPBData is a pointer to a packet.
       
   267  * @return error code. 
       
   268  */
       
   269 	{
       
   270   LOGTEXT(_L8("CMobilePhonebookStore::Read called"));
       
   271 
       
   272 	if (!(iReadWriteAccess&RMobilePhoneStore::KCapsReadAccess)) 
       
   273 		{ 
       
   274 	  LOGTEXT(_L8("CMobilePhonebookStore::Read Completing with KErrAccessDenied as read access is not allowed"));
       
   275 		ReqCompleted(aTsyReqHandle,KErrAccessDenied); 
       
   276 		return KErrNone;  
       
   277 		}	
       
   278 
       
   279 	iRead->SetPBData(aPBData);
       
   280 
       
   281 	// Store index & number of entries so we can modify/truncate it if required
       
   282 	iIndexAndEntries=*aIndexAndEntries;
       
   283 
       
   284 	// If we already have information about this phonebook
       
   285 	// Check client has supplied valid locations - otherwise send command anyway
       
   286 	if (iInfo->Completed())
       
   287 		{
       
   288 		// Allow CATPhoneBookInfo to map our clients index value (1..x)
       
   289 		// the this specific phone store index values (1+y..x+y)
       
   290 		// For the Motorola T260 SM phone book store y will be 100
       
   291 		LOGTEXT(_L8("CMobilePhonebookStore::Read Mapping clients index to phone index"));
       
   292 		iInfo->MapClientIndexToPhoneIndex(iIndexAndEntries.iIndex);
       
   293 
       
   294 		if (iInfo->IsValidPhoneIndex(iIndexAndEntries.iIndex))
       
   295 			{
       
   296 			if (!iInfo->IsValidPhoneIndex(iIndexAndEntries.iIndex+iIndexAndEntries.iNumSlots-1)) 
       
   297 				{
       
   298 				// Invalid finishing index - truncate to last valid one
       
   299 				iIndexAndEntries.iNumSlots = iInfo->TotalEntries()-iIndexAndEntries.iIndex+1 ; 
       
   300 				}
       
   301 			}
       
   302 		else
       
   303 			{
       
   304 			// Invalid starting index - complete request with error
       
   305 			LOGTEXT(_L8("CMobilePhonebookStore::Read\t Index out of range"));
       
   306 			ReqCompleted(aTsyReqHandle,KErrArgument); // The Index is out of range.
       
   307 			return KErrNone;
       
   308 			}
       
   309 		}
       
   310 
       
   311 	// We either have valid index or entries - or are trying anyway
       
   312 	iRead->ExecuteCommand(aTsyReqHandle, &iIndexAndEntries);   
       
   313 	return KErrNone;
       
   314 	}
       
   315 
       
   316 
       
   317 TInt CMobilePhonebookStore::Write(TTsyReqHandle aTsyReqHandle, TDes8* aPBData, TInt* aIndex)
       
   318 /**  Write a Phone Book Entry
       
   319  *
       
   320  * This function checks to see if the current phone book has Write Access; if it
       
   321  * does, an entry is written to the phone book store.
       
   322  * The function first creates the entry, then ensures there is space in the data 
       
   323  * object, before writing the entry. 
       
   324  * @param aTsyReqHandle Handle to the request ID.
       
   325  * @param aPBData is a pointer to a packet.
       
   326  * @param aIndex is a pointer to an entry in the phone book. 
       
   327  * @return error code. 
       
   328  */
       
   329 	{
       
   330 	LOGTEXT(_L8("CMobilePhonebookStore::Write called"));
       
   331 	
       
   332 	if(!(iReadWriteAccess&RMobilePhoneStore::KCapsWriteAccess))
       
   333 		{
       
   334 		ReqCompleted(aTsyReqHandle,KErrAccessDenied);
       
   335 		return KErrNone;
       
   336 		}
       
   337 
       
   338 	// Take copy of clients data, as we do not want changes that we make here
       
   339 	// to be reflected in the clients space.
       
   340 	iIndex=*aIndex;
       
   341 
       
   342 	iWrite->SetPBData(aPBData);
       
   343 
       
   344 	// If we already have information about this phonebook
       
   345 	// Check client has supplied valid location - otherwise send command anyway
       
   346 	if (iInfo->Completed()) 
       
   347 		{
       
   348 		// Allow CATPhoneBookInfo to map our clients index value (1..x)
       
   349 		// the this specific phone store index values (1+y..x+y)
       
   350 		// For the Motorola T260 SM phone book store y will be 100
       
   351 		LOGTEXT(_L8("CMobilePhonebookStore::Write Mapping clients index to phone index"));
       
   352 		iInfo->MapClientIndexToPhoneIndex(iIndex);
       
   353 	
       
   354 		if(!iInfo->IsValidPhoneIndex(iIndex))
       
   355 			{
       
   356 			LOGTEXT(_L8("CMobilePhonebookStore::Write\t Index out of range"));
       
   357 			ReqCompleted(aTsyReqHandle,KErrArgument); // The Index is out of range.
       
   358 			return KErrNone;
       
   359 			}
       
   360 		}
       
   361 
       
   362 	iWrite->ExecuteCommand(aTsyReqHandle, &iIndex); 
       
   363 	return KErrNone;
       
   364 	}
       
   365 
       
   366 
       
   367 TInt CMobilePhonebookStore::Delete(TTsyReqHandle aTsyReqHandle,TInt* aIndex)
       
   368 /** Delete a Phonebook Entry
       
   369  *
       
   370  * This function deletes a phonebook entry.
       
   371  * The data object is only updated when the AT command completes successfully.
       
   372  * @param aTsyReqHandle Handle to the request ID.
       
   373  * @param aIndex is a pointer to an entry in the phone book. 
       
   374  * @return error code. 
       
   375  */
       
   376 	{ 
       
   377 	LOGTEXT(_L8("CMobilePhonebookStore::Delete called"));	
       
   378 	if(!(iReadWriteAccess & RMobilePhoneStore::KCapsWriteAccess)) 
       
   379 		{	
       
   380 		ReqCompleted(aTsyReqHandle,KErrAccessDenied); 
       
   381 		return KErrNone; 	
       
   382 		}
       
   383 
       
   384 	// Take copy of clients data, as we do not want changes that we make here
       
   385 	// to be relected in the clients space.
       
   386 	iIndex=*aIndex;
       
   387 
       
   388 	// If we already have information about this phonebook
       
   389 	// Check client has supplied valid location - otherwise send command anyway
       
   390 	if (iInfo->Completed()) 
       
   391 		{
       
   392 		// Allow CATPhoneBookInfo to map our clients index value (1..x)
       
   393 		// the this specific phone store index values (1+y..x+y)
       
   394 		// For the Motorola T260 SM phone book store y will be 100
       
   395 		LOGTEXT(_L8("CMobilePhonebookStore::Delete Mapping clients index to phone index"));
       
   396 		iInfo->MapClientIndexToPhoneIndex(iIndex);
       
   397 
       
   398 		if(!iInfo->IsValidPhoneIndex(iIndex))
       
   399 			{
       
   400 			LOGTEXT(_L8("CMobilePhonebookStore::Delete\t Index out of range"));
       
   401 			ReqCompleted(aTsyReqHandle,KErrArgument); // The Index is out of range.
       
   402 			return KErrNone;
       
   403 			}
       
   404 		}
       
   405 
       
   406 	iDelete->ExecuteCommand(aTsyReqHandle,&iIndex);
       
   407 	return KErrNone;
       
   408 	}
       
   409 
       
   410