cmmanager/connection_settings_shim/src/cmdestination_shim_s60.cpp
changeset 20 9c97ad6591ae
child 23 7ec726f93df1
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
       
     1 /*
       
     2  * Copyright (c) 2010 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  * Private implementation of Wrapper for CM Manager Symbian interface.
       
    16  */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <cmdestination.h>
       
    21 #include <cmmanager.h>
       
    22 #include <cmconnectionmethod.h>
       
    23 #include <cmdestination_shim.h>
       
    24 #include <cmconnectionmethod_shim.h>
       
    25 
       
    26 // User includes
       
    27 
       
    28 #include "cmdestination_shim_s60_p.h"
       
    29 #include "cmconnectionmethod_shim_s60_p.h"
       
    30 #include "OstTraceDefinitions.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "cmdestination_shim_s60Traces.h"
       
    33 #endif
       
    34 
       
    35 
       
    36 /*!
       
    37     \class CmDestinationShimPrivate
       
    38     \brief Private implementation class for CM Manager Destination Shim.
       
    39 
       
    40     Wrapper for CM Manager Symbian interface. Symbian leaves are converted to
       
    41     standard C++ exceptions.
       
    42     
       
    43     Wrapper functions are identical to those in CmDestinationShim class, so
       
    44     refer to cmdestination_shim.h for descriptions. Private functions in this
       
    45     class are just leaving versions of the same wrapper functions.
       
    46 */
       
    47 
       
    48 // External function prototypes
       
    49 
       
    50 // Local constants
       
    51 
       
    52 // ======== LOCAL FUNCTIONS ========
       
    53 
       
    54 // ======== MEMBER FUNCTIONS ========
       
    55 
       
    56 /*!
       
    57  *  Constructor.
       
    58  *  
       
    59  *  @param[in] destination CM Manager destination object.
       
    60  */
       
    61 
       
    62 CmDestinationShimPrivate::CmDestinationShimPrivate(
       
    63     RCmDestination &destination) :
       
    64     iDestination(destination)
       
    65 {
       
    66     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_CMDESTINATIONSHIMPRIVATE_ENTRY);
       
    67     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_CMDESTINATIONSHIMPRIVATE_EXIT);
       
    68 }
       
    69 
       
    70 /*!
       
    71  *  Destructor.
       
    72  */
       
    73 
       
    74 CmDestinationShimPrivate::~CmDestinationShimPrivate()
       
    75 {
       
    76     OstTraceFunctionEntry0(DUP1_CMDESTINATIONSHIMPRIVATE_CMDESTINATIONSHIMPRIVATE_ENTRY);
       
    77     
       
    78     iDestination.Close();
       
    79 
       
    80     OstTraceFunctionExit0(DUP1_CMDESTINATIONSHIMPRIVATE_CMDESTINATIONSHIMPRIVATE_EXIT);
       
    81 }
       
    82                  
       
    83 int CmDestinationShimPrivate::ConnectionMethodCount() const
       
    84 {
       
    85     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_CONNECTIONMETHODCOUNT_ENTRY);
       
    86     
       
    87     int count = iDestination.ConnectionMethodCount();
       
    88     
       
    89     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_CONNECTIONMETHODCOUNT_EXIT);
       
    90     return count;
       
    91 }
       
    92 
       
    93 CmConnectionMethodShim *CmDestinationShimPrivate::ConnectionMethod(
       
    94     int index) const
       
    95 {
       
    96     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_CONNECTIONMETHOD_ENTRY);
       
    97     
       
    98     RCmConnectionMethod cm;
       
    99     TRAPD(error, cm = iDestination.ConnectionMethodL(index));
       
   100     TraceIfError(error);
       
   101     qt_symbian_throwIfError(error);
       
   102     
       
   103     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_CONNECTIONMETHOD_EXIT);
       
   104     return new CmConnectionMethodShim(cm);
       
   105 }
       
   106 
       
   107 CmConnectionMethodShim *CmDestinationShimPrivate::ConnectionMethodByID(
       
   108     uint cmId) const
       
   109 {    
       
   110     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_CONNECTIONMETHODBYID_ENTRY);
       
   111     
       
   112     RCmConnectionMethod cm;
       
   113     TRAPD(error, cm = iDestination.ConnectionMethodByIDL(cmId));
       
   114     TraceIfError(error);
       
   115     qt_symbian_throwIfError(error);
       
   116     
       
   117     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_CONNECTIONMETHODBYID_EXIT);
       
   118     return new CmConnectionMethodShim(cm);
       
   119 }
       
   120 
       
   121 uint CmDestinationShimPrivate::Priority(CmConnectionMethodShim *cmItem) const
       
   122 {
       
   123     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_PRIORITY_ENTRY);
       
   124     
       
   125     uint priority;
       
   126     TRAPD(error, PriorityL(cmItem, priority));
       
   127     TraceIfError(error);
       
   128     qt_symbian_throwIfError(error);
       
   129     
       
   130     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_PRIORITY_EXIT);
       
   131     return priority;
       
   132 }
       
   133 
       
   134 QString CmDestinationShimPrivate::Name() const
       
   135 {    
       
   136     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_NAME_ENTRY);
       
   137     
       
   138     QString name;
       
   139     TRAPD(error, NameL(name));
       
   140     TraceIfError(error);
       
   141     qt_symbian_throwIfError(error);
       
   142     
       
   143     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_NAME_EXIT);
       
   144     return name;
       
   145 }
       
   146 
       
   147 uint CmDestinationShimPrivate::Id() const
       
   148 {
       
   149     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_ID_ENTRY);
       
   150     
       
   151     uint id = iDestination.Id();
       
   152     
       
   153     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_ID_EXIT);
       
   154     return id;
       
   155 }
       
   156 
       
   157 uint CmDestinationShimPrivate::Metadata(
       
   158     CMManagerShim::SnapMetadataField metadataField) const
       
   159 {
       
   160     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_METADATA_ENTRY);
       
   161     
       
   162     uint metadata = 0;
       
   163     TRAPD(
       
   164         error,
       
   165         metadata = iDestination.MetadataL((CMManager::TSnapMetadataField)metadataField));
       
   166     TraceIfError(error);
       
   167     qt_symbian_throwIfError(error);
       
   168     
       
   169     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_METADATA_EXIT);
       
   170     return metadata;
       
   171 }
       
   172 
       
   173 CMManagerShim::CmmProtectionLevel CmDestinationShimPrivate::ProtectionLevel() const
       
   174 {
       
   175     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_PROTECTIONLEVEL_ENTRY);
       
   176     
       
   177     CMManager::TProtectionLevel protectionlvl = CMManager::EProtLevel3;
       
   178     TRAPD(error, protectionlvl = iDestination.ProtectionLevel());
       
   179     TraceIfError(error);
       
   180     qt_symbian_throwIfError(error);
       
   181 
       
   182     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_PROTECTIONLEVEL_EXIT);
       
   183     return mapCmmProtectionLevel(protectionlvl);
       
   184 }
       
   185 
       
   186 bool CmDestinationShimPrivate::IsHidden() const
       
   187 {
       
   188     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_ISHIDDEN_ENTRY);
       
   189     
       
   190     bool hidden = iDestination.IsHidden(); 
       
   191     
       
   192     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_ISHIDDEN_EXIT);
       
   193     return hidden;
       
   194 }
       
   195 
       
   196 int CmDestinationShimPrivate::AddConnectionMethod(
       
   197     CmConnectionMethodShim *cm)
       
   198 {
       
   199     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_ADDCONNECTIONMETHOD_ENTRY);
       
   200     
       
   201     int index;
       
   202     TRAPD(error, AddConnectionMethodL(cm, index));
       
   203     TraceIfError(error);
       
   204     qt_symbian_throwIfError(error);
       
   205     
       
   206     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_ADDCONNECTIONMETHOD_EXIT);
       
   207     return index;
       
   208 }
       
   209 
       
   210 void CmDestinationShimPrivate::DeleteConnectionMethod(
       
   211     CmConnectionMethodShim *cm)
       
   212 {
       
   213     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_DELETECONNECTIONMETHOD_ENTRY);
       
   214     
       
   215     TRAPD(error, DeleteConnectionMethodL(cm));
       
   216     TraceIfError(error);
       
   217     qt_symbian_throwIfError(error);
       
   218     
       
   219     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_DELETECONNECTIONMETHOD_EXIT);
       
   220 }
       
   221 
       
   222 void CmDestinationShimPrivate::RemoveConnectionMethod(
       
   223     CmConnectionMethodShim *cm)
       
   224 {
       
   225     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_REMOVECONNECTIONMETHOD_ENTRY);
       
   226     
       
   227     TRAPD(error, RemoveConnectionMethodL(cm));
       
   228     TraceIfError(error);
       
   229     qt_symbian_throwIfError(error);
       
   230     
       
   231     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_REMOVECONNECTIONMETHOD_EXIT);
       
   232 }
       
   233 
       
   234 void CmDestinationShimPrivate::ModifyPriority(
       
   235     CmConnectionMethodShim *cm,
       
   236     int index)
       
   237 {
       
   238     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_MODIFYPRIORITY_ENTRY);
       
   239     
       
   240     TRAPD(error, ModifyPriorityL(cm, index));
       
   241     TraceIfError(error);
       
   242     qt_symbian_throwIfError(error);
       
   243 
       
   244     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_MODIFYPRIORITY_EXIT);
       
   245 }
       
   246 
       
   247 void CmDestinationShimPrivate::SetName(QString name)
       
   248 {
       
   249     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_SETNAME_ENTRY);
       
   250     
       
   251     TRAPD(error, SetNameL(name));
       
   252     TraceIfError(error);
       
   253     qt_symbian_throwIfError(error);
       
   254 
       
   255     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_SETNAME_EXIT);
       
   256 }
       
   257 
       
   258 void CmDestinationShimPrivate::Update()
       
   259 {
       
   260     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_UPDATE_ENTRY);
       
   261     
       
   262     TRAPD(error, iDestination.UpdateL());
       
   263     TraceIfError(error);
       
   264     qt_symbian_throwIfError(error);
       
   265     
       
   266     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_UPDATE_EXIT);
       
   267 }
       
   268 
       
   269 void CmDestinationShimPrivate::Refresh()
       
   270 {
       
   271     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_REFRESH_ENTRY);
       
   272     
       
   273     TRAPD(error, iDestination.RefreshL());
       
   274     TraceIfError(error);
       
   275     qt_symbian_throwIfError(error);
       
   276     
       
   277     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_REFRESH_EXIT);
       
   278 }
       
   279 
       
   280 void CmDestinationShimPrivate::DeleteDestination()
       
   281 {
       
   282     OstTraceFunctionEntry0(CMDESTINATIONSHIMPRIVATE_DELETEDESTINATION_ENTRY);
       
   283     
       
   284     TRAPD(error, iDestination.DeleteLD());
       
   285     TraceIfError(error);
       
   286     qt_symbian_throwIfError(error);
       
   287 
       
   288     OstTraceFunctionExit0(CMDESTINATIONSHIMPRIVATE_DELETEDESTINATION_EXIT);
       
   289 }
       
   290 
       
   291 void CmDestinationShimPrivate::PriorityL(
       
   292     CmConnectionMethodShim *cmShim,
       
   293     uint &priority) const
       
   294 {
       
   295     RCmConnectionMethod cm;
       
   296     cm = iDestination.ConnectionMethodByIDL(
       
   297         cmShim->getIntAttribute(CMManagerShim::CmId));
       
   298     priority = iDestination.PriorityL(cm);
       
   299 }
       
   300     
       
   301 void CmDestinationShimPrivate::NameL(QString &name) const
       
   302 {
       
   303     HBufC* iapName;
       
   304     iapName = iDestination.NameLC();
       
   305     name = QString::fromUtf16(iapName->Ptr(), iapName->Length());
       
   306     CleanupStack::PopAndDestroy(); // iapName
       
   307 }
       
   308            
       
   309 void CmDestinationShimPrivate::AddConnectionMethodL(
       
   310     CmConnectionMethodShim *cmShim,
       
   311     int &index)
       
   312 {
       
   313     index = iDestination.AddConnectionMethodL(cmShim->d_ptr->iCm);
       
   314     iDestination.UpdateL();
       
   315 }
       
   316        
       
   317 void CmDestinationShimPrivate::DeleteConnectionMethodL(
       
   318     CmConnectionMethodShim *cmShim)
       
   319 {
       
   320     RCmConnectionMethod cm;
       
   321     cm = iDestination.ConnectionMethodByIDL(
       
   322         cmShim->getIntAttribute(CMManagerShim::CmId));
       
   323     iDestination.DeleteConnectionMethodL(cm);
       
   324     iDestination.UpdateL();
       
   325 }
       
   326        
       
   327 void CmDestinationShimPrivate::RemoveConnectionMethodL(
       
   328     CmConnectionMethodShim *cmShim)
       
   329 {
       
   330     RCmConnectionMethod cm;
       
   331     cm = iDestination.ConnectionMethodByIDL(
       
   332         cmShim->getIntAttribute(CMManagerShim::CmId));
       
   333     iDestination.RemoveConnectionMethodL(cm);
       
   334     iDestination.UpdateL();
       
   335 }
       
   336              
       
   337 void CmDestinationShimPrivate::ModifyPriorityL(
       
   338     CmConnectionMethodShim *cmShim,
       
   339     int index)
       
   340 {
       
   341     RCmConnectionMethod cm;
       
   342     cm = iDestination.ConnectionMethodByIDL(
       
   343         cmShim->getIntAttribute(CMManagerShim::CmId));
       
   344     iDestination.ModifyPriorityL(cm, index);
       
   345     iDestination.UpdateL();
       
   346 }
       
   347            
       
   348 void CmDestinationShimPrivate::SetNameL(QString name)
       
   349 {
       
   350     TPtrC16 namePtr(reinterpret_cast<const TUint16*>(name.utf16()));
       
   351     iDestination.SetNameL(namePtr);
       
   352     iDestination.UpdateL();
       
   353 }
       
   354 
       
   355 /*!
       
   356  * Maps CM Manager protection levels to those defined by the shim.
       
   357  * 
       
   358  * @param[in] protectionlvl CM Manager protection level.
       
   359  * @return CM Manager Shim protection level.
       
   360  */
       
   361 
       
   362 CMManagerShim::CmmProtectionLevel CmDestinationShimPrivate::mapCmmProtectionLevel( 
       
   363     CMManager::TProtectionLevel protectionlvl) const
       
   364 {
       
   365     CMManagerShim::CmmProtectionLevel retval = CMManagerShim::ProtLevel3;
       
   366     
       
   367     switch (protectionlvl) {
       
   368     case CMManager::EProtLevel0:
       
   369         retval = CMManagerShim::ProtLevel0;
       
   370         break;
       
   371         
       
   372     case CMManager::EProtLevel1:
       
   373         retval = CMManagerShim::ProtLevel1;
       
   374         break;
       
   375         
       
   376     case CMManager::EProtLevel2:
       
   377         retval = CMManagerShim::ProtLevel2;
       
   378         break;
       
   379         
       
   380     case CMManager::EProtLevel3:
       
   381         retval = CMManagerShim::ProtLevel3;
       
   382         break;
       
   383 
       
   384 #ifndef QT_NO_DEBUG
       
   385     default:
       
   386         Q_ASSERT( 0 );
       
   387         break;
       
   388 #endif            
       
   389     }
       
   390     
       
   391     return retval;
       
   392 }
       
   393 
       
   394 /*!
       
   395  * Traces given error code if it is not KErrNone. 
       
   396  * 
       
   397  * @param[in] error Symbian error code.
       
   398  */
       
   399 
       
   400 void CmDestinationShimPrivate::TraceIfError(TInt error) const
       
   401 {
       
   402     if (error != KErrNone) {
       
   403         OstTrace1(
       
   404             TRACE_WARNING,
       
   405             CMDESTINATIONSHIMPRIVATE_TRACEIFERROR,
       
   406             "CmDestinationShimPrivate::TraceIfError;Error code=%d",
       
   407             error);
       
   408     }
       
   409 }