omadm/omadmextensions/adapters/lawmodmadapter/src/lawmodmadapter.cpp
branchRCL_3
changeset 70 5d5344402085
parent 65 450d1facd418
child 73 5042b6604f6f
equal deleted inserted replaced
65:450d1facd418 70:5d5344402085
     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:  DCMO DM Adapter implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE
       
    19 #include <implementationproxy.h>
       
    20 #include <smldmadapter.h>
       
    21 #include <centralrepository.h>
       
    22 #include <e32base.h>
       
    23 #include <ecom.h>
       
    24 #include <utf.h>
       
    25 #include <lawmoadaptercrkeys.h>
       
    26 #include <DevManInternalCRKeys.h>
       
    27 #include <SyncMLClientDM.h>  // syncmlclientapi.lib
       
    28 #include <NSmlPrivateAPI.h> // Generic alert
       
    29 #include <nsmlconstants.h>
       
    30 #include <TerminalControl3rdPartyAPI.h>
       
    31 #include <coreapplicationuisdomainpskeys.h>
       
    32 #include <lawmointerface.h>
       
    33 //User Include
       
    34 #include "lawmodmadapter.h"
       
    35 #include "nsmldebug.h"
       
    36 #include "nsmldmuri.h"
       
    37 #include "TPtrC8I.h"
       
    38 #include "lawmodebug.h"
       
    39 // CONSTANTS
       
    40 const TInt KSyncCmdStatus (200);
       
    41 #define MAXBUFLEN 255
       
    42 
       
    43 // ============================= MEMBER FUNCTIONS =============================
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CLawmoDMAdapter::NewL
       
    47 // Symbian 1st phase contructor
       
    48 // (static, may leave)
       
    49 // Status : Draft
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 CLawmoDMAdapter* CLawmoDMAdapter::NewL( MSmlDmCallback* aCallback )
       
    53     {
       
    54     RDEBUG( "CLawmoDMAdapter NewL: begin"  );
       
    55     CLawmoDMAdapter* self = NewLC( aCallback );
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CLawmoDMAdapter::NewLC
       
    62 // Symbian 1st phase contructor. Push object to cleanup-stack
       
    63 // (static, may leave)
       
    64 // Status : Draft
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 CLawmoDMAdapter* CLawmoDMAdapter::NewLC( MSmlDmCallback* aCallback )
       
    68     {
       
    69     	RDEBUG( "CLawmoDMAdapter NewLC : begin"  );
       
    70     	CLawmoDMAdapter* self = new ( ELeave ) CLawmoDMAdapter( aCallback );
       
    71     	CleanupStack::PushL( self );
       
    72     	self->ConstructL();
       
    73     	RDEBUG( "CLawmoDMAdapter NewLC : end"  );
       
    74     	return self;
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // CLawmoDMAdapter::CLawmoDMAdapter()
       
    79 // C++ Constructor
       
    80 // Status : Draft
       
    81 // ----------------------------------------------------------------------------
       
    82 CLawmoDMAdapter::CLawmoDMAdapter( TAny* aEcomArguments )
       
    83     : CSmlDmAdapter::CSmlDmAdapter( aEcomArguments )
       
    84     {
       
    85     	RDEBUG( "CLawmoDMAdapter default constructor"  );
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // CLawmoDMAdapter::ConstructL
       
    90 // 2nd phase contructor
       
    91 // (may leave)
       
    92 // Status : Draft
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 void CLawmoDMAdapter::ConstructL()
       
    96     {
       
    97     	RDEBUG( "CLawmoDMAdapter::ConstructL"  );
       
    98         User::LeaveIfError( ilawmoSession.Connect() );
       
    99         RDEBUG( "CLawmoDMAdapter::session connected"  );
       
   100         iRootNode.Zero();
       
   101         TBuf<MAXBUFLEN> temp; 
       
   102         CRepository *repository=CRepository::NewLC ( KCRUidLawmoAdapter );
       
   103         repository->Get(KLawmoRootNode,temp);
       
   104         iRootNode.Copy(temp);
       
   105         CleanupStack::PopAndDestroy();
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CLawmoDMAdapter::~CLawmoDMAdapter()
       
   110 // C++ Destructor
       
   111 // Status : Draft
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 CLawmoDMAdapter::~CLawmoDMAdapter()
       
   115     {
       
   116     	RDEBUG( "CLawmoDMAdapter Destructor"  );
       
   117     	ilawmoSession.Close();
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // CLawmoDMAdapter::DDFVersionL
       
   122 // Return DM plug-in version
       
   123 // (may leave)
       
   124 // Status : Draft
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 void CLawmoDMAdapter::DDFVersionL( CBufBase& aDDFVersion )
       
   128     {
       
   129     // Insert version information
       
   130     RDEBUG( "CLawmoDMAdapter::DDFVersionL" );
       
   131     aDDFVersion.InsertL( 0, KLAWMODMAdapterVersion );
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CLawmoDMAdapter::DDFStructureL
       
   136 // Return DM plug-in structure
       
   137 // (may leave)
       
   138 // Status : Draft
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 void CLawmoDMAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
   142     {
       
   143     // Declare accesses
       
   144     RDEBUG( "CLawmoDMAdapter::DDFStructureL begin" );
       
   145     TSmlDmAccessTypes accessTypes;
       
   146     accessTypes.SetGet();    
       
   147     
       
   148     // Create root node 
       
   149     MSmlDmDDFObject& root = aDDF.AddChildObjectL( iRootNode );
       
   150     FillNodeInfoL( root,
       
   151                    accessTypes,
       
   152                    MSmlDmDDFObject::EPermanent,
       
   153                    MSmlDmDDFObject::ENode,
       
   154                    MSmlDmDDFObject::EOne,
       
   155                    KNullDesC8(),
       
   156                    KMimeType );
       
   157                    
       
   158    	root.SetDFTitleL( KNSmlLAWMOAdapterTitle );
       
   159                    
       
   160    	FillLAWMODDFL(root);
       
   161    	RDEBUG( "CLawmoDMAdapter::DDFStructureL end" );
       
   162 
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CLawmoDMAdapter::StreamingSupport
       
   167 // Return streaming support status, set supported item size
       
   168 // Status : Draft
       
   169 // ----------------------------------------------------------------------------
       
   170 //
       
   171 TBool CLawmoDMAdapter::StreamingSupport( TInt& /* aItemSize */ )
       
   172     {
       
   173     // Not supported
       
   174     RDEBUG( "CLawmoDMAdapter::StreamingSupport"  );
       
   175     return EFalse;
       
   176     }
       
   177     
       
   178 // ----------------------------------------------------------------------------
       
   179 // CLawmoDMAdapter::StreamCommittedL
       
   180 // Commit stream buffer
       
   181 // (may leave)
       
   182 // Status : Draft
       
   183 // ----------------------------------------------------------------------------
       
   184 //
       
   185 void CLawmoDMAdapter::StreamCommittedL()
       
   186     {        
       
   187     RDEBUG("CLawmoDMAdapter::StreamCommitted"  );
       
   188     // Intentionally left empty 
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CLawmoDMAdapter::CompleteOutstandingCmdsL
       
   193 // Complete outstanding commands
       
   194 // (may leave)
       
   195 // Status : Draft
       
   196 // ----------------------------------------------------------------------------
       
   197 //
       
   198 void CLawmoDMAdapter::CompleteOutstandingCmdsL()
       
   199     {
       
   200     RDEBUG( "CLawmoDMAdapter::CompleteOutstandingCmdsL"  );
       
   201     }
       
   202 
       
   203 // ----------------------------------------------------------------------------
       
   204 // CLawmoDMAdapter::FillNodeInfoL
       
   205 // Fill node info
       
   206 // (may leave)
       
   207 // Status : Draft
       
   208 // ----------------------------------------------------------------------------
       
   209 //
       
   210 void CLawmoDMAdapter::FillNodeInfoL( MSmlDmDDFObject& aDDFObject, 
       
   211                                      TSmlDmAccessTypes& aAccessTypes, 
       
   212                                      MSmlDmDDFObject::TScope aScope,
       
   213                                      MSmlDmDDFObject::TDFFormat aFormat, 
       
   214                                      MSmlDmDDFObject::TOccurence aOccurence,
       
   215                                      const TDesC8& aDescription,
       
   216                                      const TDesC8& aMIMEType )
       
   217     {
       
   218     RDEBUG( "CLawmoDMAdapter::FillNodeInfoL - begin"  );
       
   219     aDDFObject.SetAccessTypesL( aAccessTypes );
       
   220     aDDFObject.SetScopeL( aScope );
       
   221     aDDFObject.SetOccurenceL( aOccurence );
       
   222     aDDFObject.SetDFFormatL( aFormat );
       
   223     aDDFObject.SetDescriptionL( aDescription );
       
   224     if ( aFormat != MSmlDmDDFObject::ENode )
       
   225         {
       
   226         aDDFObject.AddDFTypeMimeTypeL( aMIMEType );
       
   227         }
       
   228     RDEBUG( "CLawmoDMAdapter::FillNodeInfoL - end"  );    
       
   229     }
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // CLawmoDMAdapter::CopyCommandL
       
   233 // Copy object
       
   234 // (may leave)
       
   235 // Status : Draft
       
   236 // ----------------------------------------------------------------------------
       
   237 //
       
   238 void CLawmoDMAdapter::CopyCommandL( const TDesC8& /*aTargetURI*/, 
       
   239                                     const TDesC8& /*aTargetLUID*/,
       
   240                                     const TDesC8& /*aSourceURI*/, 
       
   241                                     const TDesC8& /*aSourceLUID*/,
       
   242                                     const TDesC8& /*aType*/, 
       
   243                                     TInt aStatusRef )
       
   244     {
       
   245     // Not supported
       
   246     RDEBUG( "CLawmoDMAdapter::CopyCommandL"  );
       
   247     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // DeleteObjectL
       
   252 // Delete object
       
   253 // (may leave)
       
   254 // Status : Draft
       
   255 // ----------------------------------------------------------------------------
       
   256 //
       
   257 void CLawmoDMAdapter::DeleteObjectL( const TDesC8& /* aURI */, 
       
   258                                      const TDesC8& /* aLUID */,
       
   259                                      TInt aStatusRef )
       
   260 
       
   261     {
       
   262     // Not supported
       
   263     RDEBUG( "CLawmoDMAdapter::DeleteObjectL"  );
       
   264     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   265     }
       
   266     
       
   267 // ----------------------------------------------------------------------------
       
   268 // CLawmoDMAdapter::FetchLeafObjectL
       
   269 // Fetch leaf
       
   270 // (may leave)
       
   271 // Status : Draft
       
   272 // ----------------------------------------------------------------------------
       
   273 //
       
   274 void CLawmoDMAdapter::FetchLeafObjectL( const TDesC8& aURI, 
       
   275                                         const TDesC8& aLUID,
       
   276 								        const TDesC8& aType, 
       
   277 								        TInt aResultsRef,
       
   278 								        TInt aStatusRef )
       
   279     {
       
   280     RDEBUG("CLawmoDMAdapter::FetchLeafObjectL() Begin");
       
   281     
       
   282     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   283     CBufFlat *lObject = CBufFlat::NewL( MAXBUFLEN );
       
   284     CleanupStack::PushL( lObject );
       
   285     lObject->Reset();
       
   286     
       
   287     TInt err = InternalFetchObjectL( uriPtrc, aLUID, aType, lObject, aStatusRef );
       
   288     
       
   289     if((err == ELawMoSuccess)||(err == ELawMoOk))
       
   290     Callback().SetResultsL( aResultsRef, *lObject, aType );
       
   291     
       
   292     CSmlDmAdapter::TError status =  MapErrorToStatus( err );
       
   293 
       
   294     Callback().SetStatusL( aStatusRef, status );
       
   295     CleanupStack::PopAndDestroy( lObject );
       
   296     RDEBUG("CLawmoDMAdapter::FetchLeafObjectL() End");
       
   297     }
       
   298 
       
   299 // ----------------------------------------------------------------------------
       
   300 //InternalFetchObjectL
       
   301 // ----------------------------------------------------------------------------
       
   302 
       
   303 TInt CLawmoDMAdapter::InternalFetchObjectL( const TDesC8& aURI, 
       
   304                                               const TDesC8& /*aLUID*/,
       
   305                                               const TDesC8& /*aType*/, 
       
   306                                               CBufFlat* aObject,
       
   307                                               TInt aStatusRef )
       
   308     {    
       
   309     RDEBUG("CLawmoDMAdapter::InternalFetchObjectL() Begin");
       
   310     CLawmoDMAdapter::TNodeIdentifier identifier = GetNodeIdentifier(aURI);
       
   311     TInt numOfSegs = NSmlDmURI::NumOfURISegs( aURI ) ;
       
   312     TInt err (ELawMoInvalid);
       
   313 
       
   314     switch(identifier)
       
   315        {
       
   316        
       
   317        case CLawmoDMAdapter::ENodeState:
       
   318             {
       
   319             RDEBUG("CLawmoDMAdapter::InternalFetchObjectL ENodeState");
       
   320             TInt state;
       
   321             err = GetStateL(state);
       
   322             TBuf8<MAXBUFLEN> tmp;
       
   323             tmp.Num(state);
       
   324             aObject->InsertL(aObject->Size(),tmp);
       
   325             }
       
   326        break;
       
   327         
       
   328        case CLawmoDMAdapter::ENodeItemName:
       
   329            {
       
   330            RDEBUG("CLawmoDMAdapter::InternalFetchObjectL ENodeItemName");
       
   331            TBuf<MAXBUFLEN> val;
       
   332            TBuf<MAXBUFLEN> property;
       
   333            TPtrC8 seg = NSmlDmURI::URISeg(aURI, numOfSegs-2);
       
   334 		   property.Copy(seg);
       
   335            err = ilawmoSession.GetListItemName(property, val);
       
   336            TBuf8<MAXBUFLEN> tmp;
       
   337            tmp.Copy(val);
       
   338            aObject->InsertL(aObject->Size(),tmp);
       
   339            }
       
   340        break;
       
   341        
       
   342        case CLawmoDMAdapter::ENodeToBeWiped:
       
   343            {
       
   344            RDEBUG("CLawmoDMAdapter::InternalFetchObjectL ENodeToBeWiped");
       
   345            TBool val;
       
   346            TBuf<MAXBUFLEN> property;
       
   347            TPtrC8 seg = NSmlDmURI::URISeg(aURI, numOfSegs-2);
       
   348 		   property.Copy(seg);
       
   349            err = ilawmoSession.GetToBeWipedValue(property, val);
       
   350            TBuf8<MAXBUFLEN> tmp;           
       
   351            if(val)
       
   352                tmp.Copy(KNSmlTrue);
       
   353            else
       
   354                tmp.Copy(KNSmlFalse);
       
   355            aObject->InsertL(aObject->Size(),tmp);
       
   356            }
       
   357        break;
       
   358        
       
   359        case CLawmoDMAdapter::ENodeWipe:
       
   360            {
       
   361            RDEBUG("CLawmoDMAdapter::InternalFetchObjectL ENodeWipe");
       
   362            err = ELawMoSuccess;
       
   363            TBuf8<MAXBUFLEN> tmp;
       
   364            tmp.Zero();
       
   365            RDEBUG("CLawmoDMAdapter::InternalFetchObjectL Null value return");
       
   366            aObject->InsertL(aObject->Size(),tmp);
       
   367            }
       
   368            break;
       
   369        default:
       
   370            err = ELawMoUnknown;
       
   371        break;
       
   372        
       
   373        }
       
   374      RDEBUG("CLawmoDMAdapter::InternalFetchObjectL() End");
       
   375      return err;     
       
   376     }
       
   377     
       
   378 // ----------------------------------------------------------------------------
       
   379 // CLawmoDMAdapter::FetchLeafObjectSizeL
       
   380 // Calculate leaf object size
       
   381 // (may leave)
       
   382 // Status : Draft
       
   383 // ----------------------------------------------------------------------------
       
   384 //
       
   385 void CLawmoDMAdapter::FetchLeafObjectSizeL( const TDesC8& /* aURI */, 
       
   386                                             const TDesC8& /* aLUID */,
       
   387 									        const TDesC8& /* aType */, 
       
   388 									        TInt /* aResultsRef */,
       
   389 									        TInt aStatusRef )
       
   390     {
       
   391     RDEBUG( "CLawmoDMAdapter::FetchLeafObjectSizeL"  );
       
   392     MSmlDmAdapter::TError retValue = CSmlDmAdapter::EOk;
       
   393     // Respond
       
   394     Callback().SetStatusL( aStatusRef, retValue );
       
   395     }    
       
   396 
       
   397 // ----------------------------------------------------------------------------
       
   398 // CLawmoDMAdapter::ChildURIListL
       
   399 // Create child URI list
       
   400 // (may leave)
       
   401 // Status : Draft
       
   402 // ----------------------------------------------------------------------------
       
   403 //
       
   404 void CLawmoDMAdapter::ChildURIListL( const TDesC8& aURI, 
       
   405                                      const TDesC8& /* aLUID */,
       
   406 					                 const CArrayFix<TSmlDmMappingInfo>& /* aPreviousURISegmentList */,
       
   407             					     TInt aResultsRef, 
       
   408             					     TInt aStatusRef )
       
   409     {
       
   410     RDEBUG( "CLawmoDMAdapter::ChildURIListL - begin"  );
       
   411     MSmlDmAdapter::TError retValue = CSmlDmAdapter::EOk;
       
   412     CBufBase *currentURISegmentList = CBufFlat::NewL( MAXBUFLEN );
       
   413 	CleanupStack::PushL( currentURISegmentList );
       
   414 	// Bcoz root node is configurable, remove the node for this operation.
       
   415     TPtrC8 uriPtrc = NSmlDmURI::RemoveFirstSeg(aURI);
       
   416     
       
   417     if( uriPtrc == KNullDesC8)
       
   418     {	
       
   419         currentURISegmentList->InsertL( currentURISegmentList->Size(), KSegmLawmo );
       
   420         Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   421         Callback().SetResultsL( aResultsRef, *currentURISegmentList, KNullDesC8 );
       
   422         CleanupStack::PopAndDestroy(  ); // currentURISegmentList
       
   423         RDEBUG( "CLawmoDMAdapter::ChildURIListL(): end" );
       
   424         return;
       
   425     }
       
   426     else if( ( aURI.Match( KLawmoAvWipe ) != KErrNotFound ) &&
       
   427             (aURI.Match( KLawmoAvWipe2 ) == KErrNotFound ))
       
   428         {
       
   429           currentURISegmentList->InsertL( currentURISegmentList->Size(), KSegmLawmo2 );
       
   430         }
       
   431     else if( ( aURI.Match( KLawmoAvWipe2 ) != KErrNotFound ))
       
   432         {
       
   433           currentURISegmentList->InsertL( currentURISegmentList->Size(), KSegmLawmo3 );
       
   434         }
       
   435     // Operations    
       
   436     else if(( aURI.Match( KLawmoOperationsMatch ) != KErrNotFound ))
       
   437         {
       
   438           currentURISegmentList->InsertL( currentURISegmentList->Size(), KSegmLawmoOperations );
       
   439         } 
       
   440     // Ext    
       
   441     else if(( aURI.Match(KLawmoOperationsExtMatch) != KErrNotFound))
       
   442         {
       
   443           currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDdfOpExtWipeAll );
       
   444         }        
       
   445     else
       
   446         {
       
   447         retValue = CSmlDmAdapter::ENotFound;
       
   448         }
       
   449 
       
   450     Callback().SetStatusL( aStatusRef, retValue );
       
   451     CleanupStack::PopAndDestroy(); // currentURISegmentList
       
   452     RDEBUG( "CLawmoDMAdapter::ChildURIListL - end"  );
       
   453     }    
       
   454 
       
   455 // ----------------------------------------------------------------------------
       
   456 // CLawmoDMAdapter::AddNodeObjectL
       
   457 // Add node
       
   458 // (may leave)
       
   459 // Status : Draft
       
   460 // ----------------------------------------------------------------------------
       
   461 //
       
   462 void CLawmoDMAdapter::AddNodeObjectL( const TDesC8& /* aURI */,
       
   463                                      const TDesC8& /* aParentLUID */,
       
   464 								     TInt aStatusRef )
       
   465     {
       
   466     // Not supported
       
   467     RDEBUG( "CLawmoDMAdapter::AddNodeObjectL - begin"  );
       
   468     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   469     RDEBUG( "CLawmoDMAdapter::AddNodeObjectL - end"  );
       
   470     }    
       
   471 
       
   472 // ----------------------------------------------------------------------------
       
   473 // CLawmoDMAdapter::ExecuteCommandL
       
   474 // Execute command
       
   475 // (may leave)
       
   476 // Status : Draft
       
   477 // ----------------------------------------------------------------------------
       
   478 //
       
   479 void CLawmoDMAdapter::ExecuteCommandL( const TDesC8&  aURI , 
       
   480                                       const TDesC8& /* aLUID */,
       
   481 							          const TDesC8&  aArgument, 
       
   482 							          const TDesC8& /* aType */,
       
   483 								      TInt aStatusRef )
       
   484     {
       
   485     RDEBUG("CLawmoDMAdapter::ExecuteCommandL() Begin");
       
   486     CSmlDmAdapter::TError status;
       
   487     if(IsFactoryProfileL())
       
   488         {
       
   489         RDEBUG("CLawmoDMAdapter::ExecuteCommandL() its factory prof");
       
   490         SetCurrentServerIdL();
       
   491         TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   492         CLawmoDMAdapter::TNodeIdentifier identifier = GetNodeIdentifier(uriPtrc);
       
   493         TLawMoStatus err(ELawMoSuccess);
       
   494         RDEBUG_2("ExecuteCommandL executing %d", identifier);
       
   495         switch(identifier)
       
   496             {
       
   497             case ENodePartLock:
       
   498             err = LockDeviceL();
       
   499             break;
       
   500     
       
   501             case ENodeUnlock:
       
   502             err = UnLockDeviceL();
       
   503             break;
       
   504             
       
   505             case ENodeWipe:
       
   506             {
       
   507             //Write correlator id into the cenrep            
       
   508             /********* disable this comment after correlator is added
       
   509             CRepository* crep = NULL;
       
   510             crep = CRepository::NewLC( KCRUidLawmoAdapter );
       
   511             RDEBUG("CLawmoDMAdapter::SetCurrentServerId() cenrep1");
       
   512             TInt reterr = crep->Set( KLawmoCorrelator, aArgument );
       
   513             CleanupStack::PopAndDestroy(crep);*/            
       
   514             err = ilawmoSession.DeviceWipe();
       
   515             }
       
   516             break;
       
   517             
       
   518             case ENodeWipeAll:
       
   519             err = ilawmoSession.DeviceWipeAll();
       
   520             break;  
       
   521             
       
   522             default:
       
   523             err = ELawMoUnknown;
       
   524             break;           
       
   525             }        
       
   526 
       
   527         CRepository* crepository = NULL;
       
   528         crepository = CRepository::NewLC( KCRUidLawmoAdapter );
       
   529         // Do the operations based on Sync or Nonsync Exec command
       
   530         if((identifier == ENodeWipe)||(identifier == ENodeWipeAll))
       
   531             {            
       
   532             TInt reterr(KErrNone);
       
   533             TBuf<MAXBUFLEN> argument;
       
   534             TBuf<MAXBUFLEN> opURI;
       
   535             argument.Copy(aArgument);
       
   536             opURI.Copy(aURI);            
       
   537             if(argument.Length()!=0)
       
   538             reterr = crepository->Set( KLawmoCorrelator, argument );
       
   539             RDEBUG_2("CLawmoDMAdapter write correlator %d", reterr);
       
   540             reterr = crepository->Set( KLawmoSourceURI, opURI);
       
   541             RDEBUG_2("CLawmoDMAdapter write sourceURI %d", reterr);
       
   542             }   
       
   543         else
       
   544             {        
       
   545             CRepository* crep = NULL;
       
   546             _LIT8(KNsmlNull,"null");
       
   547             crep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys );
       
   548             RDEBUG("CLawmoDMAdapter::ExecuteCommandL Sourceref Crep");
       
   549             TInt reterr = crep->Set( KNSmlDMSCOMOTargetRef, KNsmlNull ); 
       
   550             RDEBUG_2("CLawmoDMAdapter::cenrep set for SourceRef, %d",reterr);
       
   551             CleanupStack::PopAndDestroy();
       
   552             if(err==ELawMoSuccess)
       
   553                 {
       
   554                 TInt resCode;
       
   555                 RDEBUG("CLawmoDMAdapter check for the synchronous result code");
       
   556                 //check the cenrep to determine which sync result code to send
       
   557                 reterr = crepository->Get(KLawmoSyncRetVal, resCode);
       
   558                 if(resCode==KSyncCmdStatus)
       
   559                 	{
       
   560                 		RDEBUG("CLawmoDMAdapter Lock return status 200");
       
   561                     err = ELawMoOk;
       
   562                   }
       
   563                 }
       
   564             }
       
   565         CleanupStack::PopAndDestroy(crepository);
       
   566         status = MapErrorToStatus( err );       //map lawmo/syncml error codes     
       
   567         }
       
   568     else
       
   569         {
       
   570         RDEBUG("CLawmoDMAdapter::ExecuteCommandL() NOT factory prof");
       
   571         status = CSmlDmAdapter::ENotAllowed; //405
       
   572         }
       
   573     Callback().SetStatusL( aStatusRef, status );
       
   574     RDEBUG( "CLawmoDMAdapter::ExecuteCommandL - end"  );
       
   575     }    
       
   576 
       
   577 // ----------------------------------------------------------------------------
       
   578 // CLawmoDMAdapter::ExecuteCommandL
       
   579 // Execute command, streaming enabled
       
   580 // (may leave)
       
   581 // Status : Draft
       
   582 // ----------------------------------------------------------------------------
       
   583 //
       
   584 void CLawmoDMAdapter::ExecuteCommandL( const TDesC8& /* aURI */, 
       
   585                                       const TDesC8& /* aLUID */,
       
   586 								      RWriteStream*& /* aStream */,
       
   587 								      const TDesC8& /* aType */,
       
   588 								      TInt aStatusRef )
       
   589     {
       
   590     // Not supported
       
   591     RDEBUG( "CLawmoDMAdapter::ExecuteCommandL Streaming"  );
       
   592     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   593     }    
       
   594     
       
   595 // ----------------------------------------------------------------------------
       
   596 // CLawmoDMAdapter::UpdateLeafObjectL
       
   597 // Update leaf object
       
   598 // (may leave)
       
   599 // Status : Draft
       
   600 // ----------------------------------------------------------------------------
       
   601 //
       
   602 void CLawmoDMAdapter::UpdateLeafObjectL( const TDesC8&  aURI,
       
   603                                         const TDesC8&   aLUID,
       
   604                                         const TDesC8&   aObject,
       
   605                                         const TDesC8&   aType,
       
   606                                         TInt aStatusRef )
       
   607     {
       
   608     RDEBUG( "CLawmoDMAdapter::UpdateLeafObjectL - begin"  );
       
   609     CSmlDmAdapter::TError status;
       
   610     if(IsFactoryProfileL())
       
   611        {
       
   612         RDEBUG("CLawmoDMAdapter::UpdateLeafObjectL() is factory prof");
       
   613         TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
   614         TInt err = InternalUpdateObjectL( uriPtrc, aLUID, aObject, aType, aStatusRef );        
       
   615         status = MapErrorToStatus( err );
       
   616        }
       
   617     else
       
   618         {
       
   619         RDEBUG("CLawmoDMAdapter::UpdateLeafObjectL() NOT factory prof");
       
   620         status = CSmlDmAdapter::ENotAllowed;//405
       
   621         }
       
   622     
       
   623     Callback().SetStatusL( aStatusRef, status );    
       
   624     RDEBUG( "CLawmoDMAdapter::UpdateLeafObjectL - end"  );
       
   625     }
       
   626 
       
   627 	// ----------------------------------------------------------------------------
       
   628 //InternalFetchObjectL
       
   629 // ----------------------------------------------------------------------------
       
   630 
       
   631 TInt CLawmoDMAdapter::InternalUpdateObjectL( const TDesC8& aURI, 
       
   632                                               const TDesC8& /*aLUID*/,
       
   633                                               const TDesC8& aObject, 
       
   634                                               const TDesC8& /*aType*/,
       
   635                                               TInt aStatusRef )
       
   636     { 		
       
   637       RDEBUG( "CLawmoDMAdapter::InternalUpdateObjectL - begin"  );
       
   638       CLawmoDMAdapter::TNodeIdentifier identifier = GetNodeIdentifier(aURI);
       
   639       TInt numOfSegs = NSmlDmURI::NumOfURISegs( aURI ) ;
       
   640       TInt err (ELawMoInvalid);
       
   641       RDEBUG_2("UpdateCommand updating %d", identifier);      
       
   642       switch(identifier)
       
   643          {         
       
   644          case CLawmoDMAdapter::ENodeToBeWiped:
       
   645            {
       
   646            TInt value;
       
   647            HBufC8 *object = HBufC8::NewLC( aObject.Length() );
       
   648            TPtr8 objPtr = object->Des();
       
   649            objPtr.Format( aObject );
       
   650            objPtr.LowerCase();
       
   651            if(objPtr.Compare(KNSmlTrue) == 0)
       
   652            value = 1;
       
   653            else if(objPtr.Compare(KNSmlFalse) == 0)
       
   654            value = 0;
       
   655            else
       
   656                {
       
   657                 TLex8 lex( aObject );                
       
   658                 RDEBUG( "CLawmoDMAdapter::InternalUpdateObjectL lexing"  );
       
   659                 User::LeaveIfError( lex.Val( value ) );                
       
   660                }
       
   661            CleanupStack::PopAndDestroy(); // object
       
   662 
       
   663            if(value<0||value>1)
       
   664                {
       
   665                RDEBUG_2("value to set %d", value);
       
   666                return ELawMoInvalid;
       
   667                }
       
   668            
       
   669            RDEBUG_2("value to set %d", value);
       
   670            TPtrC8 seg = NSmlDmURI::URISeg(aURI, numOfSegs-2);
       
   671 		   TBuf<MAXBUFLEN> property;
       
   672 		   property.Copy(seg);
       
   673 		   RDEBUG_2("category %s", property.PtrZ());
       
   674            err = ilawmoSession.SetToBeWipedValue(property, value);
       
   675            }
       
   676            break;
       
   677            
       
   678          default:
       
   679              err = ELawMoUnknown;
       
   680              break;
       
   681          
       
   682          }
       
   683     RDEBUG( "CLawmoDMAdapter::InternalUpdateObjectL - End"  );
       
   684 	return err;
       
   685 	}
       
   686 // ----------------------------------------------------------------------------
       
   687 // CLawmoDMAdapter::UpdateLeafObjectL
       
   688 // Update leaf object, streaming enabled
       
   689 // (may leave)
       
   690 // Status : Draft
       
   691 // ----------------------------------------------------------------------------
       
   692 //
       
   693 void CLawmoDMAdapter::UpdateLeafObjectL( const TDesC8& /* aURI */, 
       
   694                                          const TDesC8& /* aLUID */,
       
   695 									     RWriteStream*& /* aStream */, 
       
   696 									     const TDesC8& /* aType */,
       
   697 		 							     TInt aStatusRef )
       
   698     {
       
   699     
       
   700     // Not supported
       
   701     RDEBUG( "CLawmoDMAdapter::UpdateLeafObjectL - Streaming"  );
       
   702     Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );//500
       
   703     }
       
   704     
       
   705 // ----------------------------------------------------------------------------
       
   706 // CLawmoDMAdapter::StartAtomicL
       
   707 // Start atomic
       
   708 // (may leave)
       
   709 // Status : Draft
       
   710 // ----------------------------------------------------------------------------
       
   711 //
       
   712 void CLawmoDMAdapter::StartAtomicL()
       
   713     {
       
   714     }
       
   715     
       
   716 // ----------------------------------------------------------------------------
       
   717 // CLawmoDMAdapter::CommitAtomicL
       
   718 // Commit atomic commands
       
   719 // (may leave)
       
   720 // Status : Draft
       
   721 // ----------------------------------------------------------------------------
       
   722 //
       
   723 void CLawmoDMAdapter::CommitAtomicL()
       
   724     {
       
   725     }
       
   726 
       
   727 // ----------------------------------------------------------------------------
       
   728 // CLawmoDMAdapter::RollbackAtomicL
       
   729 // Lose all modifications after 'StartAtomicL' command
       
   730 // (may leave)
       
   731 // Status : Draft
       
   732 // ----------------------------------------------------------------------------
       
   733 //
       
   734 void CLawmoDMAdapter::RollbackAtomicL()
       
   735     {
       
   736     }    
       
   737 
       
   738 // ---------------------------------------------------------------------------
       
   739 // CNSmlDmFotaAdapter::MapStatusToError()
       
   740 // Returns a status code corresponding to the system error code given 
       
   741 // as parameter.
       
   742 // ---------------------------------------------------------------------------
       
   743 //
       
   744 CSmlDmAdapter::TError CLawmoDMAdapter::MapErrorToStatus( TInt aError ) const
       
   745  {
       
   746     RDEBUG( "CLawmoDMAdapter::MapErrorToStatus - Begin"  );
       
   747     CSmlDmAdapter::TError err;
       
   748     
       
   749     switch( aError )
       
   750         {
       
   751         case ELawMoSuccess:
       
   752             err = CSmlDmAdapter::EExecSuccess; //1200
       
   753             break;
       
   754         case ELawMoOk:
       
   755             err = CSmlDmAdapter::EOk; //200
       
   756             break;
       
   757         case ELawMoFail:
       
   758             err = CSmlDmAdapter::EExecClientError; //1400
       
   759             break;    
       
   760         case ELawMoUserCancelled:
       
   761             err = CSmlDmAdapter::EExecUserCancelled; //1401
       
   762             break;
       
   763         case ELawMoFullyLockFailed:
       
   764             err = CSmlDmAdapter::EExecDownloadFailed; //1402
       
   765             break;
       
   766         case ELawMoPartialLockFailed:
       
   767             err = CSmlDmAdapter::EExecAltDwnldAuthFail; //1403
       
   768             break; 
       
   769         case ELawMoUnlockFailed:
       
   770             err = CSmlDmAdapter::EExecDownFailOOM; //1404
       
   771             break;            
       
   772         case ELawMoWipeFailed:
       
   773             err = CSmlDmAdapter::EExecInstallFailed; //1405
       
   774             break;    
       
   775         case ELawMoWipeNotPerformed:
       
   776             err = CSmlDmAdapter::EExecInstallOOM; //1406
       
   777             break; 
       
   778         case ELawMoWipeSuccess:
       
   779             err = CSmlDmAdapter::EExecDownFailOOM; //1201 ??????
       
   780             break;            
       
   781         case ELawMoAccepted:
       
   782             err = CSmlDmAdapter::EAcceptedForProcessing; //202
       
   783             break;
       
   784         case ELawMoUnknown:
       
   785             err = CSmlDmAdapter::ENotFound; //404
       
   786             break;
       
   787         case ELawMoInvalid:
       
   788             err = CSmlDmAdapter::EError; //500
       
   789             break;
       
   790         default :
       
   791         		err = CSmlDmAdapter::EExecClientError;//1400        
       
   792         }
       
   793     
       
   794     return err;
       
   795  }
       
   796       
       
   797 // ========================= OTHER EXPORTED FUNCTIONS =========================
       
   798 
       
   799 void CleanupEComArray(TAny* aArray)
       
   800 	{
       
   801 	(static_cast<RImplInfoPtrArray*> (aArray))->ResetAndDestroy();
       
   802 	(static_cast<RImplInfoPtrArray*> (aArray))->Close();
       
   803 	}
       
   804 
       
   805 // ----------------------------------------------------------------------------
       
   806 // CLawmoDMAdapter::FillLAWMODDFL
       
   807 // This function constructs the DDFnode with the details
       
   808 // ----------------------------------------------------------------------------
       
   809 //	
       
   810 void CLawmoDMAdapter::FillLAWMODDFL(MSmlDmDDFObject& aDDF)
       
   811 {
       
   812 	RDEBUG("CLawmoDMAdapter::FillDCMPDDFL(): begin");
       
   813 		
       
   814 	TSmlDmAccessTypes accessTypesG;
       
   815     accessTypesG.SetGet();
       
   816     
       
   817     MSmlDmDDFObject& nStateDDF = aDDF.AddChildObjectL( KNSmlDdfState );			// State
       
   818     FillNodeInfoL( nStateDDF, accessTypesG,  
       
   819                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EInt, MSmlDmDDFObject::EOne,
       
   820                         KNSmlDdfStateDescription, KMimeType );
       
   821 
       
   822     FillDynamicNodeL(aDDF);
       
   823         
       
   824     MSmlDmDDFObject& nOperationsDDF = aDDF.AddChildObjectL( KNSmlDdfOperations );
       
   825     FillNodeInfoL( nOperationsDDF, accessTypesG,  
       
   826                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode, MSmlDmDDFObject::EOne,
       
   827                         KNSmlDdfOperationsDescription, KMimeType ); 
       
   828     
       
   829     TSmlDmAccessTypes accessTypesE;   
       
   830     accessTypesE.SetExec();
       
   831         
       
   832     MSmlDmDDFObject& nPartLockDDF = nOperationsDDF.AddChildObjectL( KNSmlDdfPartLock );     // Partial Lock
       
   833     FillNodeInfoL( nPartLockDDF, accessTypesE,  
       
   834                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENull, MSmlDmDDFObject::EOne,
       
   835                         KNSmlDdfPartLockDescription, KMimeType );
       
   836     
       
   837     MSmlDmDDFObject& nUnlockDDF = nOperationsDDF.AddChildObjectL( KNSmlDdfUnlock );     // Unlock
       
   838     FillNodeInfoL( nUnlockDDF, accessTypesE,  
       
   839                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENull, MSmlDmDDFObject::EOne,
       
   840                         KNSmlDdfUnlockDescription, KMimeType );
       
   841 
       
   842     TSmlDmAccessTypes accessTypesEG;   
       
   843     accessTypesEG.SetExec();
       
   844     accessTypesEG.SetGet();
       
   845     
       
   846     MSmlDmDDFObject& nWipeDDF = nOperationsDDF.AddChildObjectL( KNSmlDdfWipe );     // Wipe
       
   847     FillNodeInfoL( nWipeDDF, accessTypesEG,  
       
   848                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENull, MSmlDmDDFObject::EOne,
       
   849                         KNSmlDdfWipeDescription, KMimeType ); 
       
   850     
       
   851     MSmlDmDDFObject& nExtDDF = aDDF.AddChildObjectL( KNSmlDdfOpExt );       // Ext
       
   852     FillNodeInfoL( nExtDDF, accessTypesG,  
       
   853                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode, MSmlDmDDFObject::EOne,
       
   854                         KNSmlDdfExtDescription, KMimeType );
       
   855     
       
   856     MSmlDmDDFObject& nOpExtDDF = nExtDDF.AddChildObjectL( KNSmlDdfOpExtWipeAll );      // WipeAll
       
   857     FillNodeInfoL( nOpExtDDF, accessTypesE, 
       
   858                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENull, MSmlDmDDFObject::EOne, 
       
   859                         KNSmlDdfOpExtDescription, KMimeType ); 
       
   860     //Check for any generic alerts and send
       
   861     RDEBUG("CLawmoDMAdapter::FillDCMPDDFL(): send generic alert");
       
   862     SendGenericAlertL();
       
   863 	RDEBUG("CLawmoDMAdapter::FillDCMPDDFL(): end");
       
   864 }    
       
   865 
       
   866 void CLawmoDMAdapter::FillDynamicNodeL(MSmlDmDDFObject& aDDF)
       
   867     {
       
   868     RDEBUG("CDCMOServer::FillDynamicNode(): start");
       
   869     RImplInfoPtrArray infoArray;
       
   870     // Note that a special cleanup function is required to reset and destroy
       
   871     // all items in the array, and then close it.
       
   872     TCleanupItem cleanup(CleanupEComArray, &infoArray);
       
   873     CleanupStack::PushL(cleanup);
       
   874     REComSession::ListImplementationsL(KLAWMOPluginInterfaceUid, infoArray);
       
   875     RDEBUG("CDCMOServer::GetPluginUids(): listImpl");
       
   876     
       
   877     TSmlDmAccessTypes accessTypesG;
       
   878     accessTypesG.SetGet();    
       
   879     
       
   880     TSmlDmAccessTypes accessTypesSR;
       
   881     accessTypesSR.SetGet();
       
   882     accessTypesSR.SetReplace();
       
   883     
       
   884     MSmlDmDDFObject& nAwlDDF = aDDF.AddChildObjectL( KNSmlDdfAvailWipeList );                   // AWL
       
   885     FillNodeInfoL( nAwlDDF, accessTypesG,  
       
   886                         MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode, MSmlDmDDFObject::EOne,
       
   887                         KNSmlDdfAWLDescription, KMimeType ); 
       
   888     
       
   889     // Loop through each info for each implementation
       
   890     for (TInt i=0; i< infoArray.Count(); i++)
       
   891         {
       
   892         RDEBUG("CDCMOServer::FillDynamicNode(): for loop");
       
   893         MSmlDmDDFObject& nDynamicNodeDDF = nAwlDDF.AddChildObjectL(infoArray[i]->OpaqueData());
       
   894         FillNodeInfoL( nDynamicNodeDDF, accessTypesG,  
       
   895                             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode, MSmlDmDDFObject::EOne,
       
   896                             KNSmlDdfDynNodeDescription, KMimeType ); 
       
   897         RDEBUG("CDCMOServer::FillDynamicNode(): fill dyn node");
       
   898         
       
   899         MSmlDmDDFObject& nListItemDDF = nDynamicNodeDDF.AddChildObjectL( KNSmlDdfListItemName );     // ListItemName
       
   900         FillNodeInfoL( nListItemDDF, accessTypesG, 
       
   901                             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr, MSmlDmDDFObject::EOne, 
       
   902                             KNSmlDdfListDescription, KMimeType );
       
   903    
       
   904         
       
   905         MSmlDmDDFObject& nToWipeDDF = nDynamicNodeDDF.AddChildObjectL( KNSmlDdfToBeWiped );     // ToBeWiped
       
   906         FillNodeInfoL( nToWipeDDF, accessTypesSR, 
       
   907                             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EBool, MSmlDmDDFObject::EOne, 
       
   908                             KNSmlDdfToWipeDescription, KMimeType );
       
   909         RDEBUG("CDCMOServer::FillDynamicNode(): loop done");
       
   910         }
       
   911     CleanupStack::PopAndDestroy(); //cleanup
       
   912     }
       
   913 
       
   914 TBool CLawmoDMAdapter::IsFactoryProfileL()
       
   915     {
       
   916     RDEBUG("CLawmoDMAdapter::IsFactoryProfile() begin");
       
   917     TBool retval(EFalse);
       
   918     RSyncMLSession ses;
       
   919     ses.OpenL() ;
       
   920     CleanupClosePushL(ses);
       
   921     TSmlJobId jid;
       
   922     TSmlUsageType jtype;
       
   923     ses.CurrentJobL(jid, jtype);
       
   924     RSyncMLDevManJob job;
       
   925     job.OpenL(ses, jid);
       
   926     CleanupClosePushL(job) ;
       
   927     
       
   928     TSmlProfileId pid(job.Profile() ); 
       
   929     TInt fpid(-1);//factory profile id
       
   930     RDEBUG("CLawmoDMAdapter::IsFactoryProfile() before cenrep");
       
   931     
       
   932     CRepository* crep = NULL;
       
   933     crep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys );
       
   934     RDEBUG("CLawmoDMAdapter::IsFactoryProfile() CRep1");
       
   935     TInt reterr = crep->Get( KMaxFactoryDMProfileId, fpid ); 
       
   936     RDEBUG("CLawmoDMAdapter::IsFactoryProfile() CRep2");
       
   937     fpid =fpid + KMaxDataSyncID; //fpid in cenrep needs to be updated
       
   938     RDEBUG_2("factprofidStored %d", fpid);
       
   939     
       
   940     if( pid <= fpid )
       
   941         {
       
   942         RDEBUG("CLawmoDMAdapter::IsFactoryProfile() pid is factory");
       
   943         retval = ETrue;
       
   944         }
       
   945     else
       
   946         {
       
   947         RDEBUG("CLawmoDMAdapter::IsFactoryProfile() pid not factory");
       
   948         }
       
   949     CleanupStack::PopAndDestroy(crep);  
       
   950     CleanupStack::PopAndDestroy( &job) ;
       
   951     CleanupStack::PopAndDestroy( &ses) ;
       
   952     
       
   953     RDEBUG("CLawmoDMAdapter::IsFactoryProfile() end");    
       
   954     return retval;
       
   955     }
       
   956 
       
   957 void CLawmoDMAdapter::SetCurrentServerIdL()
       
   958     {
       
   959     RDEBUG("CLawmoDMAdapter::SetCurrentServerId() begin");
       
   960     TBuf<MAXBUFLEN> tsrvrid;
       
   961     TBuf<MAXBUFLEN> tsrvrname;
       
   962     RSyncMLSession ses;
       
   963     ses.OpenL() ;
       
   964     CleanupClosePushL(ses);
       
   965     
       
   966     TSmlJobId jid;
       
   967     TSmlUsageType jtype;
       
   968     ses.CurrentJobL(jid, jtype);
       
   969     
       
   970     RSyncMLDevManJob job;
       
   971     job.OpenL(ses, jid);
       
   972     CleanupClosePushL(job) ;
       
   973     TSmlProfileId pid(job.Profile() ); 
       
   974     
       
   975     RDEBUG("CLawmoDMAdapter::SetCurrentServerId() syncprofile");
       
   976     RSyncMLDevManProfile syncProfile;
       
   977     syncProfile.OpenL(ses, pid);    
       
   978     CleanupClosePushL(syncProfile);    
       
   979     tsrvrid.Copy(syncProfile.ServerId());
       
   980     tsrvrname.Copy(syncProfile.DisplayName());
       
   981     TInt tempPid = (TInt) syncProfile.Identifier();
       
   982     
       
   983     RDEBUG_2("CLawmoDMAdapter::SetCurrentServerId() ProfileId 1 %d",tempPid);
       
   984     RDEBUG_2("CLawmoDMAdapter::SetCurrentServerId() ProfileId 2 %d",(TInt) pid);
       
   985     RDEBUG_2("CLawmoDMAdapter::SetCurrentServerId() Srvrid %s",tsrvrid.PtrZ());  
       
   986     RDEBUG_2("CLawmoDMAdapter::SetCurrentServerId() srvrname %s",tsrvrname.PtrZ());
       
   987     
       
   988     CRepository* crep = NULL;
       
   989     crep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys );
       
   990     TInt reterr = crep->Set( KLAWMOfactoryDmProfileID, (TInt)pid ); 
       
   991     RDEBUG_2("CLawmoDMAdapter::setProfile() %d",reterr);
       
   992     reterr = crep->Set( KLAWMOfactoryDmServerID, tsrvrid ); 
       
   993     RDEBUG_2("CLawmoDMAdapter::SetCurrentServerId() %d",reterr);
       
   994     reterr = crep->Set(KLAWMOfactoryDmServerName,tsrvrname);
       
   995     RDEBUG_2("CLawmoDMAdapter::servername() %d",reterr);
       
   996     
       
   997     CleanupStack::PopAndDestroy( &syncProfile);
       
   998     CleanupStack::PopAndDestroy( &job) ;
       
   999     CleanupStack::PopAndDestroy( &ses) ;
       
  1000     CleanupStack::PopAndDestroy() ;//cenrep
       
  1001     
       
  1002     RDEBUG("CLawmoDMAdapter::SetCurrentServerId() end");
       
  1003     }
       
  1004 
       
  1005 CLawmoDMAdapter::TNodeIdentifier CLawmoDMAdapter::GetNodeIdentifier(const TDesC8& aURI)
       
  1006     {
       
  1007     RDEBUG("CLawmoDMAdapter::GetNodeIdentifier() begin");
       
  1008 
       
  1009     TInt    numOfSegs = NSmlDmURI::NumOfURISegs( aURI ) ;
       
  1010     TPtrC8I seg1 = NSmlDmURI::URISeg(aURI, 0);
       
  1011 
       
  1012     if (seg1 == iRootNode)
       
  1013         {
       
  1014         if(numOfSegs == 1) return CLawmoDMAdapter::ENodeLawMo;
       
  1015 
       
  1016         TPtrC8I seg2 = NSmlDmURI::URISeg(aURI, 1);
       
  1017 
       
  1018         if (seg2 == KNSmlDdfState)
       
  1019             {
       
  1020                 return CLawmoDMAdapter::ENodeState;
       
  1021             }            
       
  1022         else if (seg2 == KNSmlDdfAvailWipeList)
       
  1023             {               
       
  1024                 if (numOfSegs == 2)
       
  1025                 {
       
  1026                     return CLawmoDMAdapter::ENodeAvWipeList;
       
  1027                 }
       
  1028                 else if (numOfSegs == 3) 
       
  1029                 {            
       
  1030                     // We are not using dynamic node name to do any decision making
       
  1031                     return CLawmoDMAdapter::ENodeDynamic;
       
  1032                 }
       
  1033                 else if (numOfSegs == 4) 
       
  1034                 {
       
  1035                     TPtrC8I seg4 = NSmlDmURI::URISeg(aURI, 3);
       
  1036                     
       
  1037                     if (seg4 == KNSmlDdfListItemName)
       
  1038                         {
       
  1039                         return CLawmoDMAdapter::ENodeItemName;
       
  1040                         }
       
  1041                     else if (seg4 == KNSmlDdfToBeWiped)
       
  1042                         {
       
  1043                         return CLawmoDMAdapter::ENodeToBeWiped;
       
  1044                         }
       
  1045                     else
       
  1046                         {
       
  1047                         return CLawmoDMAdapter::ENodeNotUsedAndAlwaysLast;
       
  1048                         }
       
  1049                 }
       
  1050                 else
       
  1051                 {
       
  1052                 return CLawmoDMAdapter::ENodeNotUsedAndAlwaysLast;
       
  1053                 }
       
  1054             }            
       
  1055         else if (seg2 == KNSmlDdfOperations)                    
       
  1056             {
       
  1057                 if(numOfSegs == 2)
       
  1058                     {
       
  1059                      return CLawmoDMAdapter::ENodeOperations;
       
  1060                     }
       
  1061                 else if(numOfSegs == 3)
       
  1062                     {
       
  1063                     TPtrC8I seg3 = NSmlDmURI::URISeg(aURI, 2);
       
  1064                 
       
  1065                     if(seg3 == KNSmlDdfPartLock)
       
  1066                         {
       
  1067                         return CLawmoDMAdapter::ENodePartLock;
       
  1068                         }  
       
  1069                     else if(seg3 == KNSmlDdfUnlock)
       
  1070                         {
       
  1071                         return CLawmoDMAdapter::ENodeUnlock;
       
  1072                         } 
       
  1073                     else if(seg3 == KNSmlDdfWipe)
       
  1074                         {
       
  1075                         return CLawmoDMAdapter::ENodeWipe;
       
  1076                         } 
       
  1077                     }
       
  1078                 else
       
  1079                     { 
       
  1080                     return CLawmoDMAdapter::ENodeNotUsedAndAlwaysLast;
       
  1081                     }
       
  1082             }
       
  1083         else if (seg2 == KNSmlDdfOpExt)
       
  1084             {
       
  1085                 if(numOfSegs == 2)
       
  1086                 {
       
  1087                     return CLawmoDMAdapter::ENodeExt;
       
  1088                 }
       
  1089                 else if(numOfSegs == 3)
       
  1090                 {
       
  1091                 TPtrC8I seg3 = NSmlDmURI::URISeg(aURI, 2);
       
  1092 
       
  1093                 if(seg3 == KNSmlDdfOpExtWipeAll)
       
  1094                     {
       
  1095                     return CLawmoDMAdapter::ENodeWipeAll;
       
  1096                     } 
       
  1097                 else
       
  1098                     {
       
  1099                     return CLawmoDMAdapter::ENodeNotUsedAndAlwaysLast;
       
  1100                     }
       
  1101                 }
       
  1102                 else
       
  1103                 {
       
  1104                 return CLawmoDMAdapter::ENodeNotUsedAndAlwaysLast;
       
  1105                 }
       
  1106             }
       
  1107         }
       
  1108     RDEBUG("CLawmoDMAdapter::GetNodeIdentifier() End");
       
  1109     return CLawmoDMAdapter::ENodeNotUsedAndAlwaysLast;
       
  1110     }
       
  1111 
       
  1112 void CLawmoDMAdapter::SendGenericAlertL()
       
  1113 {
       
  1114     RDEBUG("CLawmoDMAdapter::SendGenericAlert(): begin");    
       
  1115     // check if wipe generic alert needs to be sent ?
       
  1116     TInt wipeStatus;
       
  1117     CRepository *repository=CRepository::NewLC ( KCRUidLawmoAdapter );
       
  1118     repository->Get(KLawmoWipeStatus,wipeStatus);
       
  1119     RDEBUG("CDCMOServer::SendGenericAlert(): chkin wipestatus");
       
  1120     if(wipeStatus!=-1)
       
  1121         {
       
  1122         //Wipe Alert needs tobe sent
       
  1123         RNSmlPrivateAPI privateAPI;
       
  1124         privateAPI.OpenL();
       
  1125         RDEBUG("CLawmoDMAdapter::SendGenericAlert(): OpenL");
       
  1126         CleanupClosePushL(privateAPI);
       
  1127         RArray<CNSmlDMAlertItem> iItemArray;
       
  1128         CNSmlDMAlertItem* item = new (ELeave) CNSmlDMAlertItem ;
       
  1129         RDEBUG("CLawmoDMAdapter::SendGenericAlert(): alertItem");
       
  1130         TBuf<MAXBUFLEN> targetURI;
       
  1131         targetURI.Append(KNullDesC);
       
  1132         TBuf<MAXBUFLEN> correlator;
       
  1133         correlator.Append(KNullDesC);
       
  1134         TBuf<MAXBUFLEN> sourceURI;
       
  1135         sourceURI.Append(KNullDesC);
       
  1136         RDEBUG("CLawmoDMAdapter::SendGenericAlert(): bfore cenrep");
       
  1137         // Construct generic alert message
       
  1138         TInt reterr = repository->Get(KLawmoCorrelator,correlator );
       
  1139         reterr = repository->Get(KLawmoSourceURI,sourceURI);
       
  1140         RDEBUG("CLawmoDMAdapter::SendGenericAlert(): after cenrep");
       
  1141         
       
  1142         HBufC8 *descorrelator = HBufC8::NewL(MAXBUFLEN);
       
  1143         (descorrelator->Des()).Copy(correlator);
       
  1144         
       
  1145         HBufC8 *aSourceuri = HBufC8::NewL(MAXBUFLEN);
       
  1146         (aSourceuri->Des()).Copy(sourceURI);   
       
  1147         item->iSource = aSourceuri;    
       
  1148         
       
  1149         HBufC8 *aTargeturi = HBufC8::NewL(MAXBUFLEN);   
       
  1150         (aTargeturi->Des()).Copy(targetURI);    
       
  1151         item->iTarget = aTargeturi; 
       
  1152         if(item->iTarget->Des().Compare(KNullDesC8)==0)
       
  1153             RDEBUG("CLawmoDMAdapter::SendGenericAlert() targeturi is NULL");
       
  1154         RDEBUG("CLawmoDMAdapter::SendGenericAlert(): targeturidone");
       
  1155         
       
  1156         HBufC8 *aMetatype = HBufC8::NewL(MAXBUFLEN); 
       
  1157         (aMetatype->Des()).Copy(KLawmoMetatype);               
       
  1158         item->iMetaType = aMetatype;     
       
  1159         
       
  1160         HBufC8 *aMetaformat = HBufC8::NewL(MAXBUFLEN); 
       
  1161         (aMetaformat->Des()).Copy(KLawmoMetaformat);         
       
  1162         item->iMetaFormat = aMetaformat;
       
  1163         
       
  1164         HBufC8 *aMetamark = HBufC8::NewL(MAXBUFLEN); 
       
  1165         (aMetamark->Des()).Copy(KLawmoMetamark);               
       
  1166         item->iMetaMark = aMetamark;
       
  1167         
       
  1168         //appending result code
       
  1169         HBufC8 *data = HBufC8::NewL(MAXBUFLEN);
       
  1170         (data->Des()).Num(wipeStatus);
       
  1171         item->iData = data;
       
  1172         
       
  1173         repository->Set(KLawmoWipeStatus,-1);//reset the wipestatus
       
  1174         
       
  1175         TInt genericStatus(KErrNone);
       
  1176         RDEBUG("CLawmoDMAdapter::SendGenericAlert(): Appending data");
       
  1177         iItemArray.AppendL(*item);
       
  1178         RDEBUG("CLawmoDMAdapter::SendGenericAlert(): Issuing request");
       
  1179         TRAP_IGNORE(genericStatus=privateAPI.AddDMGenericAlertRequestL(*descorrelator, iItemArray ));
       
  1180         RDEBUG_2("CLawmoDMAdapter::SendGenericAlert(): Api call done %d", genericStatus);
       
  1181         delete data;    
       
  1182         delete aMetamark;    
       
  1183         delete aMetaformat;    
       
  1184         delete aMetatype;  
       
  1185 		delete aTargeturi;
       
  1186         delete aSourceuri;
       
  1187         delete item;
       
  1188         delete descorrelator;		
       
  1189         iItemArray.Reset();         
       
  1190         iItemArray.Close();
       
  1191         CleanupStack::PopAndDestroy( &privateAPI);
       
  1192         }
       
  1193     
       
  1194     CleanupStack::PopAndDestroy();
       
  1195     RDEBUG("CLawmoDMAdapter::SendGenericAlert(): end");    
       
  1196 }
       
  1197 
       
  1198 TLawMoStatus CLawmoDMAdapter::LockDeviceL()
       
  1199     {
       
  1200     RDEBUG("CLawmoDMAdapter::LockDevice(): begin");
       
  1201     TInt lockValue(0);
       
  1202     TInt currentLawmoState(0);
       
  1203     TLawMoStatus lawmostatus(ELawMoSuccess);
       
  1204     RDEBUG("CLawmoDMAdapter::LockDevice(): 1");
       
  1205     CRepository* crep = NULL;
       
  1206     crep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys );
       
  1207     RDEBUG("CLawmoDMAdapter::LockDevice(): 2");
       
  1208 
       
  1209     User::LeaveIfError(RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus,lockValue));
       
  1210     RDEBUG("CLawmoDMAdapter::LockDevice(): 3");  
       
  1211     
       
  1212     // If Locked already by Tarm/autolock, set LawmoState.
       
  1213     if(lockValue>EAutolockOff)
       
  1214         {
       
  1215         RDEBUG("CLawmoDMAdapter::LockDevice(): 3.0");
       
  1216         TInt err = crep->Set( KLAWMOPhoneLock, EPartialLocked );
       
  1217         CleanupStack::PopAndDestroy(crep);  
       
  1218         if(err==KErrNone)   return lawmostatus;
       
  1219         else 
       
  1220         return ELawMoPartialLockFailed;
       
  1221         }
       
  1222 
       
  1223     TInt reterr = crep->Get( KLAWMOPhoneLock, currentLawmoState );     
       
  1224     if(reterr!= KErrNone)
       
  1225         lawmostatus = ELawMoPartialLockFailed;
       
  1226     RDEBUG("CLawmoDMAdapter::LockDevice(): 3.1");
       
  1227     
       
  1228     if(currentLawmoState==EUnlocked)
       
  1229         {
       
  1230         RTerminalControl tc;
       
  1231         RTerminalControl3rdPartySession ts;
       
  1232         
       
  1233         User::LeaveIfError( tc.Connect() );
       
  1234         CleanupClosePushL( tc );
       
  1235 
       
  1236         User::LeaveIfError( ts.Open( tc ) );
       
  1237         CleanupClosePushL( ts );
       
  1238         RDEBUG("CLawmoDMAdapter::LockDevice(): 3.5");
       
  1239         TBuf8<8> data;
       
  1240         data.Copy(_L8("1"));
       
  1241         TInt status = ts.SetDeviceLockParameter(RTerminalControl3rdPartySession::ELock, data);        
       
  1242         RDEBUG_2("CLawmoDMAdapter::LockDevice() %d", status );        
       
  1243         if (status == KErrNone)    
       
  1244             {
       
  1245             reterr = crep->Set( KLAWMOPhoneLock, EPartialLocked );
       
  1246             if (reterr!= KErrNone)
       
  1247                 lawmostatus = ELawMoPartialLockFailed;
       
  1248             }
       
  1249         else if (status == KErrCancel)
       
  1250             lawmostatus = ELawMoUserCancelled;
       
  1251         else
       
  1252             lawmostatus = ELawMoPartialLockFailed;
       
  1253         
       
  1254         ts.Close();
       
  1255         tc.Close();
       
  1256         RDEBUG("CLawmoDMAdapter::LockDevice(): set val to 20");       
       
  1257         CleanupStack::PopAndDestroy( &ts );
       
  1258         CleanupStack::PopAndDestroy( &tc );
       
  1259         RDEBUG("CLawmoDMAdapter::LockDevice(): 5");
       
  1260         }
       
  1261     
       
  1262     CleanupStack::PopAndDestroy(crep);  
       
  1263     RDEBUG("CLawmoDMAdapter::LockDevice(): End");
       
  1264     return lawmostatus;
       
  1265     }
       
  1266 
       
  1267 TLawMoStatus CLawmoDMAdapter::UnLockDeviceL()
       
  1268     {
       
  1269     RDEBUG("CDCMOServer::UnLockDevice(): begin");
       
  1270     CRepository* crep = NULL;
       
  1271     TInt currentLawmoState =0;
       
  1272     TLawMoStatus lawmostat(ELawMoSuccess);    
       
  1273     TBool currentLockState(EFalse);
       
  1274     TInt lockValue(0);
       
  1275     User::LeaveIfError(RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus,lockValue));
       
  1276     RDEBUG("CDCMOServer::unLockDevice(): 0");
       
  1277 
       
  1278     if(lockValue>EAutolockOff)
       
  1279         currentLockState = ETrue;
       
  1280     
       
  1281     RDEBUG("CDCMOServer::UnLockDevice(): 1");
       
  1282     crep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys );
       
  1283     RDEBUG("CDCMOServer::UnLockDevice(): 2");
       
  1284     TInt reterr = crep->Get( KLAWMOPhoneLock, currentLawmoState ); 
       
  1285     RDEBUG("CDCMOServer::UnLockDevice(): 2.1");
       
  1286     
       
  1287     if(reterr!= KErrNone)
       
  1288         lawmostat = ELawMoUnlockFailed;
       
  1289     
       
  1290     if((currentLawmoState != EUnlocked) ||(currentLockState))
       
  1291         {
       
  1292         RTerminalControl tc;
       
  1293         RTerminalControl3rdPartySession ts;
       
  1294         RDEBUG("CDCMOServer::UnLockDevice(): 3");
       
  1295         User::LeaveIfError( tc.Connect() );
       
  1296         CleanupClosePushL( tc );  
       
  1297         User::LeaveIfError( ts.Open( tc ) );
       
  1298         CleanupClosePushL( ts );
       
  1299         RDEBUG("CDCMOServer::UnLockDevice(): 4");
       
  1300         TBuf8<8> data;
       
  1301         data.Copy(_L8("0"));
       
  1302         TInt status = ts.SetDeviceLockParameter(RTerminalControl3rdPartySession::ELock, data);       
       
  1303         RDEBUG_2("CDCMOServer::UnLockDevice() %d", status );
       
  1304         if (status == KErrNone)    
       
  1305             {
       
  1306             reterr = crep->Set( KLAWMOPhoneLock, EUnlocked );
       
  1307             if (reterr!= KErrNone)
       
  1308                 lawmostat = ELawMoPartialLockFailed;
       
  1309             }
       
  1310         else if (status == KErrCancel)
       
  1311             lawmostat = ELawMoUserCancelled;
       
  1312         else
       
  1313             lawmostat = ELawMoUnlockFailed;
       
  1314         
       
  1315         ts.Close();
       
  1316         tc.Close();
       
  1317         RDEBUG("CDCMOServer::UnLockDevice(): set to 30");
       
  1318         CleanupStack::PopAndDestroy( &ts );
       
  1319         CleanupStack::PopAndDestroy( &tc );
       
  1320         }
       
  1321     
       
  1322     if(!currentLockState)
       
  1323         {
       
  1324         reterr = crep->Set( KLAWMOPhoneLock, EUnlocked );
       
  1325         if(reterr!=KErrNone)   
       
  1326             lawmostat = ELawMoUnlockFailed;
       
  1327         }
       
  1328 
       
  1329     CleanupStack::PopAndDestroy(crep); 
       
  1330     RDEBUG("CDCMOServer::UnLockDevice(): End");
       
  1331     return lawmostat;    
       
  1332     }
       
  1333 
       
  1334 TLawMoStatus CLawmoDMAdapter::GetStateL(TInt& aState)
       
  1335 {
       
  1336     RDEBUG("CDCMOServer::GetState(): begin");
       
  1337     TLawMoStatus lawmostat(ELawMoOk);
       
  1338     CRepository* crep = NULL;
       
  1339     crep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys );
       
  1340     RDEBUG("CDCMOServer::GetState(): created cenrep");
       
  1341     TInt reterr = crep->Get( KLAWMOPhoneLock, aState );
       
  1342     RDEBUG("CDCMOServer::GetState(): get on cenrep");
       
  1343     if(reterr!= KErrNone)
       
  1344     {
       
  1345             RDEBUG("CDCMOServer::GetLocalCategoryL(): centrep Get error");
       
  1346             lawmostat = ELawMoInvalid;
       
  1347     }
       
  1348     RDEBUG("CDCMOServer::GetState(): writing the int val");
       
  1349     CleanupStack::PopAndDestroy(crep); 
       
  1350     RDEBUG("CDCMOServer::GetState(): End");
       
  1351     return lawmostat;
       
  1352 }
       
  1353 
       
  1354 // End of File