pimprotocols/pbap/server/pbapfoldernode.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-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 "pbapfolderclient.h"
       
    17 #include "pbapappheader.h"
       
    18 #include "pbapfoldernode.h"
       
    19 #include "pbapexporter.h"
       
    20 #include "pbaperrorreporter.h"
       
    21 #include "pbapserver.h"
       
    22 
       
    23 #include "btaccesshostlog.h"
       
    24 
       
    25 
       
    26 
       
    27 CFolderNode::CFolderNode(MVirtualFolderClient& aClient, const TDesC& aFolderName)
       
    28 : CFolderBase(aClient, aFolderName)
       
    29 	{
       
    30 	LOG_FUNC
       
    31 	}
       
    32 	
       
    33 	
       
    34 CFolderNode::~CFolderNode()
       
    35 	{
       
    36 	LOG_FUNC
       
    37 	delete iAppHeader;
       
    38 	}
       
    39 
       
    40 
       
    41 /**
       
    42  Implements base class Get function, calls inteface to handle each type of
       
    43  supported get request. The concrete phonebook folder subclasses classes 
       
    44  implement this interface.
       
    45  
       
    46  Takes ownership of aGetData.
       
    47 */	
       
    48 TInt CFolderNode::Get(const TDesC& aObjectName, CPbapAppHeader* aGetData)
       
    49 	{
       
    50 	LOG_FUNC
       
    51 	if(!aGetData)
       
    52 		{
       
    53 		__ASSERT_DEBUG(EFalse, Panic(EVirtualFolderNullAppHeader));
       
    54 		return KErrBadHandle;
       
    55 		}
       
    56 	if(iAppHeader)
       
    57 		{
       
    58 		__ASSERT_DEBUG(EFalse, Panic(EVirtualFolderAppHeaderExists));
       
    59 		return KErrAlreadyExists;
       
    60 		}
       
    61 	
       
    62 	
       
    63 	// take ownership of the app header to allow get requests handlers to be asynchronous
       
    64 	iAppHeader = aGetData;
       
    65 
       
    66 	TInt error = KErrNone;
       
    67 	
       
    68 	switch (iAppHeader->Operation())
       
    69 		{
       
    70 		case EPullVCard:
       
    71 			{
       
    72 			// convert hexadecimal string representation of handle to integer
       
    73 			TLex lex(aObjectName);
       
    74 			TUint handle;
       
    75 			error = lex.Val(handle, EHex);
       
    76 			if (error == KErrNone)
       
    77 				{
       
    78 				error = DoGetItem(handle);
       
    79 				}	
       
    80 			break;
       
    81 			}
       
    82 		case EPullPhoneBook:
       
    83 			{
       
    84 			error = DoGetFolder();
       
    85 			break;
       
    86 			}
       
    87 		case EPullVCardListing:
       
    88 			{
       
    89 			// if trying to pull a listing from non-existing folder, return KErrNotFound
       
    90 			if(aObjectName.Size() != NULL)
       
    91 				{
       
    92 				error = KErrNotFound;
       
    93 				}
       
    94 			else
       
    95 				{
       
    96 				error = DoGetListing();
       
    97 				}
       
    98 			break;
       
    99 			}
       
   100 		case ERequestPhoneBookSize:
       
   101 			{
       
   102 			error = DoGetCount();
       
   103 			break;
       
   104 			}
       
   105 		default:
       
   106 			{
       
   107 			error = KErrNotSupported;
       
   108 			break;
       
   109 			}
       
   110 		}		
       
   111 
       
   112 	if (error != KErrNone)
       
   113 		{
       
   114 		// if an error occured then delete the app header as export is not in progress
       
   115 		delete iAppHeader;
       
   116 		iAppHeader = NULL;		
       
   117 		}
       
   118 		
       
   119 	return error;
       
   120 	}