contentstorage/caclient/src/cahandlerproxy.cpp
changeset 83 156f692b1687
child 98 d2f833ab7940
equal deleted inserted replaced
80:397d00875918 83:156f692b1687
       
     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 
       
    20 #include "cahandler.h"
       
    21 #include "cahandlerproxy.h"
       
    22 #include "cahandlerloader.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(const QSharedPointer<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 ErrorCode CaHandlerProxy::execute(const CaEntry &entry, const QString &commandName)
       
    59 {
       
    60     CaHandler *const handler = getHandler(entry, commandName);
       
    61     ErrorCode result = NotFoundErrorCode;
       
    62 
       
    63     if (handler) {
       
    64             result = CaObjectAdapter::convertErrorCode(
       
    65                 handler->execute(entry, commandName));
       
    66     }
       
    67     return result;
       
    68 }
       
    69 
       
    70 /*!
       
    71   Looks for handler implementation in local cache or if not found, request it from
       
    72   handler loader.
       
    73   \param entry The entry being a subject for the requested command.
       
    74   \param commandName Name of the command to be executed.
       
    75   \return Pointer to a handler instance if available, NULL otherwise.
       
    76 */
       
    77 CaHandler *CaHandlerProxy::getHandler(const CaEntry &entry,
       
    78                                       const QString &commandName)
       
    79 {
       
    80     CaHandler *implementation(0);
       
    81 
       
    82     const QString entryTypeName(entry.entryTypeName());
       
    83 
       
    84     const ImplementationMapIterator it(
       
    85         mImplementationMap.find(entryTypeName));
       
    86 
       
    87     if (it != mImplementationMap.end()) {
       
    88         implementation = it->data();
       
    89     } else {
       
    90         implementation = mLoader->loadHandler(entryTypeName, commandName);
       
    91         mImplementationMap[entryTypeName] = QSharedPointer<CaHandler>(implementation);
       
    92     }
       
    93 
       
    94     return implementation;
       
    95 }