contentstorage/caclient/s60/src/cahandlerproxy.cpp
branchGCC_SURGE
changeset 105 e7325f632549
parent 81 5ef31a21fdd5
parent 104 9b022b1f357c
equal deleted inserted replaced
81:5ef31a21fdd5 105:e7325f632549
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 
       
    18 #include <caentry.h>
       
    19 #include "cahandler.h"
       
    20 #include "cahandlerproxy.h"
       
    21 #include "cahandlerloader.h"
       
    22 #include "cainnerentry.h"
       
    23 #include "caobjectadapter.h"
       
    24 
       
    25 /*!
       
    26     \class CaHandlerProxy
       
    27     \ingroup
       
    28     \brief Forwards execute request to an implemenation provided by specific handler loader.
       
    29 
       
    30     \sa CaHandlerLoader
       
    31 */
       
    32 
       
    33 /*!
       
    34   Destructor.
       
    35 */
       
    36 CaHandlerProxy::~CaHandlerProxy()
       
    37 {
       
    38 }
       
    39 
       
    40 
       
    41 /*!
       
    42   Constructs handler proxy.
       
    43   \param loader Provides handler implementations. It has to be pointer to a valid object.
       
    44 */
       
    45 CaHandlerProxy::CaHandlerProxy(CaHandlerLoader *loader):
       
    46     mLoader(loader)
       
    47 {
       
    48     Q_ASSERT(!mLoader.isNull());
       
    49 }
       
    50 
       
    51 /*!
       
    52   Forwards execute request to an appropriate handler if found otherwise ignores the request.
       
    53   \param entry Subject for the requested command.
       
    54   \param commandName Name of the command to be executed.
       
    55   \return KErrNone (i.e. 0) on succes, error code otherwise.
       
    56   \sa e32err.h for KErrNone definition.
       
    57 */
       
    58 TInt CaHandlerProxy::execute(const CaEntry &entry, const QString &commandName)
       
    59 {
       
    60     CaHandler *const handler = getHandler(entry, commandName);
       
    61 
       
    62     TInt result = KErrNotFound;
       
    63 
       
    64     if (handler != NULL) {
       
    65         QScopedPointer<CCaInnerEntry> innerEntry(NULL);
       
    66         TRAP(result,
       
    67             innerEntry.reset(CCaInnerEntry::NewL());
       
    68             CaObjectAdapter::convertL(entry, *innerEntry);
       
    69             )
       
    70         if (result == KErrNone) {
       
    71             result = handler->execute(*innerEntry, commandName);
       
    72         }
       
    73     }
       
    74     return result;
       
    75 }
       
    76 
       
    77 /*!
       
    78   Looks for handler implementation in local cache or if not found, request it from
       
    79   handler loader.
       
    80   \param entry The entry being a subject for the requested command.
       
    81   \param commandName Name of the command to be executed.
       
    82   \return Pointer to a handler instance if available, NULL otherwise.
       
    83 */
       
    84 CaHandler *CaHandlerProxy::getHandler(const CaEntry &entry,
       
    85                                       const QString &commandName)
       
    86 {
       
    87     CaHandler *implementation(0);
       
    88 
       
    89     const QString entryTypeName(entry.entryTypeName());
       
    90 
       
    91     const ImplementationMapIterator it(
       
    92         mImplementationMap.find(entryTypeName));
       
    93 
       
    94     if (it != mImplementationMap.end()) {
       
    95         implementation = it->data();
       
    96     } else {
       
    97         implementation = mLoader->loadHandler(entryTypeName, commandName);
       
    98         mImplementationMap[entryTypeName] = QSharedPointer<CaHandler>(implementation);
       
    99     }
       
   100 
       
   101     return implementation;
       
   102 }