connectivitymodules/SeCon/cntparser/src/cntparserserversession.cpp
branchRCL_3
changeset 42 0aa8cc770c8a
parent 40 453dfc402455
child 43 4a793f564d72
equal deleted inserted replaced
40:453dfc402455 42:0aa8cc770c8a
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  CCntParserServerSession implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cntparserserversession.h"
       
    20 #include <cntdb.h>
       
    21 #include "cntparsercollector.h"
       
    22 #include "cntparserinfolog.h"
       
    23 #include "irmcconsts.h"
       
    24 
       
    25 #include "debug.h"
       
    26 
       
    27 //------------------------------------------------------------
       
    28 // CCntParserServerSession::CCntParserServerSession()
       
    29 //------------------------------------------------------------
       
    30 CCntParserServerSession::CCntParserServerSession()
       
    31     {
       
    32     }
       
    33 //------------------------------------------------------------
       
    34 // CCntParserServerSession::NewL(CCntParserServer* aServer)
       
    35 //------------------------------------------------------------
       
    36 CCntParserServerSession* CCntParserServerSession::NewL( CCntParserServer* aServer )
       
    37     {
       
    38     LOGGER_ENTERFN( "CntParserServerSession::NewL()" );
       
    39 
       
    40     CCntParserServerSession* self = new( ELeave ) CCntParserServerSession();
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL( aServer );
       
    43     CleanupStack::Pop( self );
       
    44     LOGGER_LEAVEFN( "CntParserServerSession::NewL()" );
       
    45     return self;
       
    46     }
       
    47 //------------------------------------------------------------
       
    48 // CCntParserServerSession::ConstructL( CCntParserServer* aServer )
       
    49 //------------------------------------------------------------
       
    50 void CCntParserServerSession::ConstructL( CCntParserServer* aServer )
       
    51     {
       
    52     iContactsParserSrv = aServer;
       
    53     iContactsParserSrv->IncreaseSessionCountL();
       
    54     }
       
    55 //------------------------------------------------------------
       
    56 // CCntParserServerSession::~CCntParserServerSession()
       
    57 //------------------------------------------------------------
       
    58 CCntParserServerSession::~CCntParserServerSession()
       
    59     {
       
    60     LOGGER_ENTERFN( "CntParserServerSession::~CCntParserServerSession()" );
       
    61     if ( iContactsParserSrv )
       
    62         {
       
    63         iContactsParserSrv->DecreaseSessionCount();
       
    64         }
       
    65     LOGGER_LEAVEFN( "CntParserServerSession::~CCntParserServerSession()" );
       
    66     }
       
    67 //------------------------------------------------------------
       
    68 // CCntParserServerSession::ServiceL( const RMessage2& aMessage )
       
    69 //------------------------------------------------------------
       
    70 void CCntParserServerSession::ServiceL( const RMessage2& aMessage )
       
    71     {
       
    72     LOGGER_WRITE( "CntParserServerSession: ServiceL" );
       
    73 
       
    74     TInt err( KErrNone );
       
    75     TInt ret( KErrNone );
       
    76 
       
    77     TRAP( err, ret = DispatchMessageL( aMessage ) );
       
    78 
       
    79     if ( err != KErrNone )
       
    80         {
       
    81         LOGGER_WRITE_1( "CntParserServerSession: ServiceL: Error trapped, complete with ERR code %d", err );
       
    82 
       
    83         iPhoneBookRequest = EFalse; //If requested, then clear request flag
       
    84         iContactsParserSrv->SetRequests( 0 );   //Reset requests count in server to allow new requests to start..
       
    85         aMessage.Complete( err ); //If trap error, complete with it
       
    86         return;
       
    87         }   
       
    88 
       
    89     if ( ret == KErrNone )
       
    90         {
       
    91         LOGGER_WRITE( "CntParserServerSession: ServiceL: No complete" );
       
    92         return;
       
    93         }
       
    94 
       
    95     if ( ret == KPerformComplete )
       
    96         {
       
    97         LOGGER_WRITE( "CntParserServerSession: ServiceL: Normal complete" );
       
    98 
       
    99         aMessage.Complete( KErrNone );
       
   100         return;
       
   101         }
       
   102 
       
   103     if ( ret == KPBNotUpdated )
       
   104         {
       
   105         LOGGER_WRITE( "CntParserServerSession: ServiceL: Complete (PB not updated)" );
       
   106 
       
   107         iPhoneBookRequest = EFalse;
       
   108         aMessage.Complete( KPBNotUpdated );
       
   109         return;
       
   110         }
       
   111     LOGGER_WRITE( "CntParserServerSession: ServiceL: Error, should never come here" );
       
   112     aMessage.Complete( KErrGeneral );
       
   113     }
       
   114 //------------------------------------------------------------
       
   115 // CCntParserServerSession::CompletePhoneBookRequest( TInt aErr )
       
   116 //------------------------------------------------------------
       
   117 void CCntParserServerSession::CompletePhoneBookRequest( TInt aErr )
       
   118     {
       
   119     LOGGER_WRITE( "CntParserServerSession: CompletePhoneBookRequest" );
       
   120 
       
   121     if ( iPhoneBookRequest ) //If this session has requested phonebook, then the completion should be done here, as it was not done in ServiceL
       
   122         {
       
   123         LOGGER_WRITE( "CntParserServerSession: CompletePhoneBookRequest: collector or cancel" );
       
   124         iPhoneBookRequest = EFalse;
       
   125         iPhoneBookRequestMessage.Complete( aErr );
       
   126         }
       
   127     else
       
   128         {
       
   129         LOGGER_WRITE( "CntParserServerSession: CompletePhoneBookRequest: No complete for this session" );
       
   130         }
       
   131     }
       
   132 //------------------------------------------------------------
       
   133 // CCntParserServerSession::DispatchMessageL( const RMessage2 &aMessage )
       
   134 //------------------------------------------------------------
       
   135 TInt CCntParserServerSession::DispatchMessageL( const RMessage2 &aMessage )
       
   136     {
       
   137     LOGGER_WRITE( "CntParserServerSession: DispatchMessageL" );
       
   138 
       
   139     TInt res( KPerformComplete );
       
   140 
       
   141     switch( aMessage.Function() )
       
   142         {
       
   143         case ECntParserServerCreateIrMCL2:  //Create pb.vcf file
       
   144             {
       
   145             res = ETrue;
       
   146 
       
   147             if ( iPhoneBookRequest == EFalse )
       
   148                 {
       
   149                 iPhoneBookRequestMessage = aMessage;
       
   150                 iPhoneBookRequest = ETrue;
       
   151 
       
   152                 TInt sid=aMessage.SecureId();
       
   153                 TInt MaxNumOfContacts = aMessage.Int0();
       
   154                 TBool Forced = aMessage.Int1();
       
   155                 TBuf<8> sidLit;
       
   156                 sidLit.AppendNumFixedWidth( sid, EHex, 8);
       
   157                 TBuf<255> path;
       
   158                 path.Insert( 0, KPhoneBookFilename );
       
   159 
       
   160                 res = iContactsParserSrv->CreateIrMCL2PhoneBookL( path, (TInt) MaxNumOfContacts, Forced );
       
   161                 }
       
   162             break;
       
   163             }
       
   164         case ECntParserServerCntParsed: //How many contacts already parsed
       
   165             {
       
   166             TPckgBuf<TInt> p((TInt) iContactsParserSrv->ContactsParsed());
       
   167             aMessage.WriteL( 0, p, 0 );
       
   168             break;
       
   169             }
       
   170         case ECntParserServerTotalNumOfContacts: //How many contacts total?
       
   171             {
       
   172             TPckgBuf<TInt> p((TInt) iContactsParserSrv->TotalNumOfContacts());
       
   173             aMessage.WriteL( 0, p, 0 );
       
   174             break;
       
   175             }
       
   176         case ECntParserServerDisconnect:    //Disconnect session from server
       
   177             {
       
   178             iContactsParserSrv->Disconnect();
       
   179             break;
       
   180             }
       
   181         case ECntParserServerCancel:    //Cancel phone book request
       
   182             {
       
   183             if (iPhoneBookRequest)
       
   184                 {
       
   185                 iContactsParserSrv->CancelPhoneBookRequest();
       
   186                 CompletePhoneBookRequest( KErrCancel );
       
   187                 }
       
   188             break;
       
   189             }
       
   190         case ECntParserServerCntSaved: //How many contacts total?
       
   191             {
       
   192             TPckgBuf<TInt> p((TInt) iContactsParserSrv->ContactsSaved());
       
   193             aMessage.WriteL( 0, p, 0 );
       
   194             break;
       
   195             }
       
   196         case ECntParserServerCancelAll: //Cancel all requests, not just current?
       
   197             {
       
   198             iContactsParserSrv->CancelAllPhoneBookRequests();
       
   199             break;
       
   200             }
       
   201         // requests we don't understand
       
   202         // so panic the client here, this function also completes the message
       
   203         default:
       
   204             {
       
   205             PanicClient( EBadRequest );
       
   206             break;
       
   207             }
       
   208         }
       
   209     return res;
       
   210     }
       
   211 //------------------------------------------------------------
       
   212 // CCntParserServerSession::PanicClient(TInt aPanic) const
       
   213 //------------------------------------------------------------
       
   214 void CCntParserServerSession::PanicClient(TInt aPanic) const
       
   215     {
       
   216     User::Panic( KTxtServer,aPanic );
       
   217     }
       
   218     
       
   219 // end of file