contentstorage/caclient/s60/src/cahandlerproxy.cpp
changeset 61 8e5041d13c84
child 66 32469d7d46ff
equal deleted inserted replaced
60:f62f87b200ec 61:8e5041d13c84
       
     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 
       
    23 /*!
       
    24     \class CaHandlerProxy
       
    25     \ingroup 
       
    26     \brief Forwards execute request to an implemenation provided by specific handler loader.
       
    27 
       
    28     \sa CaHandlerLoader
       
    29 */
       
    30 
       
    31 /*!
       
    32   Destructor.
       
    33 */
       
    34 CaHandlerProxy::~CaHandlerProxy()
       
    35 {
       
    36 }
       
    37 
       
    38 
       
    39 /*!
       
    40   Constructs handler proxy.
       
    41   \param loader Provides handler implementations. It has to be pointer to a valid object.
       
    42 */
       
    43 CaHandlerProxy::CaHandlerProxy(CaHandlerLoader *loader):
       
    44     mLoader(loader)
       
    45 {
       
    46     Q_ASSERT(!mLoader.isNull());
       
    47 }
       
    48 
       
    49 /*!
       
    50   Forwards execute request to an appropriate handler if found otherwise ignores the request.
       
    51   \param entry Subject for the requested command.
       
    52   \param commandName Name of the command to be executed.
       
    53   \return KErrNone (i.e. 0) on succes, error code otherwise.
       
    54   \sa e32err.h for KErrNone definition.
       
    55 */
       
    56 TInt CaHandlerProxy::execute(const CaEntry &entry, const QString &commandName)
       
    57 {
       
    58     CaHandler *const handler = getHandler(entry, commandName);
       
    59 
       
    60     TInt result = KErrNotFound;
       
    61 
       
    62     if (handler != NULL) {
       
    63         result = handler->execute(entry, commandName);
       
    64     }
       
    65 
       
    66     return result;
       
    67 }
       
    68 
       
    69 /*!
       
    70   Looks for handler implementation in local cache or if not found, request it from
       
    71   handler loader.
       
    72   \param entry The entry being a subject for the requested command.
       
    73   \param commandName Name of the command to be executed.
       
    74   \return Pointer to a handler instance if available, NULL otherwise.
       
    75 */
       
    76 CaHandler *CaHandlerProxy::getHandler(const CaEntry &entry,
       
    77                                       const QString &commandName)
       
    78 {
       
    79     CaHandler *implementation(0);
       
    80 
       
    81     const QString entryTypeName(entry.entryTypeName());
       
    82 
       
    83     const ImplementationMapIterator it(
       
    84         mImplementationMap.find(entryTypeName));
       
    85 
       
    86     if (it != mImplementationMap.end()) {
       
    87         implementation = it->data();
       
    88     } else {
       
    89         implementation = mLoader->loadHandler(entryTypeName, commandName);
       
    90         mImplementationMap[entryTypeName] = QSharedPointer<CaHandler>(implementation);
       
    91     }
       
    92 
       
    93     return implementation;
       
    94 }