contextframework/cfw/src/cfclient/cfactionservice.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2008-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:  CCFActionService class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <s32mem.h>
       
    21 
       
    22 // USER INCLUDES
       
    23 #include "cfactionservice.h"
       
    24 #include "cftrace.h"
       
    25 #include "cfcommon.h"
       
    26 #include "CFClientSession.h"
       
    27 #include "CFActionSubscriptionImpl.h"
       
    28 #include "CFActionSubscriptionListener.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // C++ constructor.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CCFActionService::CCFActionService( RCFClientSession& aSession,
       
    37     MCFListener& aListener ) :
       
    38     CCFServiceBase( CCFServiceBase::ECFActionService, aSession, aListener )
       
    39     {
       
    40     FUNC_LOG;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Symbian 2nd phase constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 void CCFActionService::ConstructL( )
       
    48     {
       
    49     FUNC_LOG;
       
    50 
       
    51     // Create action subscription listener
       
    52     iActionSubscriptionListener = CCFActionSubscriptionListener::NewL(
       
    53         iListener,
       
    54         iSession );
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Symbian two phased constructor.
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CCFActionService* CCFActionService::NewL( RCFClientSession& aSession,
       
    62     MCFListener& aListener )
       
    63     {
       
    64     FUNC_LOG;
       
    65     
       
    66     CCFActionService* self = CCFActionService::NewLC( aSession, aListener );
       
    67     CleanupStack::Pop ( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Symbian two phased constructor.
       
    73 // Leaves pointer in the cleanup stack.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CCFActionService* CCFActionService::NewLC( RCFClientSession& aSession,
       
    77     MCFListener& aListener )
       
    78     {
       
    79     FUNC_LOG;
       
    80     
       
    81     CCFActionService* self = new( ELeave ) CCFActionService(
       
    82         aSession,
       
    83         aListener );
       
    84     CleanupStack::PushL ( self );
       
    85     self->ConstructL( );
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // C++ destructor.
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CCFActionService::~CCFActionService( )
       
    94     {
       
    95     FUNC_LOG;
       
    96     
       
    97     delete iActionSubscriptionListener;
       
    98     }
       
    99 
       
   100 //----------------------------------------------------------------------------
       
   101 // CCFActionService::SubscribeActionL
       
   102 //----------------------------------------------------------------------------
       
   103 //
       
   104 void CCFActionService::SubscribeActionL( CCFActionSubscription& aSubscription )
       
   105     {
       
   106     FUNC_LOG;
       
   107     
       
   108     TInt err = KErrNone;
       
   109     
       
   110     // Stream subscription
       
   111     HBufC8* buffer = WriteStreamActionSubscriptionLC( aSubscription );
       
   112     TIpcArgs args( buffer );
       
   113     err = iSession.SendSync( ESubscribeAction, args );
       
   114     CleanupStack::PopAndDestroy( buffer );
       
   115     
       
   116     User::LeaveIfError( err );
       
   117 
       
   118     if( err == KErrNone )
       
   119         {
       
   120         if( !iActionSubscriptionListener->IsActive() )
       
   121             {
       
   122             // Activate listening
       
   123             iActionSubscriptionListener->RequestActionIndication();
       
   124             }
       
   125         }        
       
   126     }
       
   127     
       
   128 //----------------------------------------------------------------------------
       
   129 // CCFActionService::UnsubscribeActionL
       
   130 //----------------------------------------------------------------------------
       
   131 //
       
   132 void CCFActionService::UnsubscribeActionL(
       
   133     CCFActionSubscription& aSubscription )
       
   134     {
       
   135     FUNC_LOG;
       
   136 
       
   137     TInt err = KErrNone;
       
   138     
       
   139     // Stream subscription
       
   140     HBufC8* buffer = WriteStreamActionSubscriptionLC( aSubscription );
       
   141     TIpcArgs args( buffer );
       
   142     err = iSession.SendSync( EUnsubscribeAction, args );
       
   143     CleanupStack::PopAndDestroy( buffer );
       
   144     
       
   145     User::LeaveIfError( err );
       
   146     }
       
   147 
       
   148 //----------------------------------------------------------------------------
       
   149 // CCFActionService::DefineAction
       
   150 //----------------------------------------------------------------------------
       
   151 //
       
   152 TInt CCFActionService::DefineAction( const TDesC& aActionIdentifier,
       
   153     const TSecurityPolicy& aSecurityPolicy )
       
   154     {
       
   155     FUNC_LOG;
       
   156     
       
   157     TSecurityPolicyBuf secPolicyBuf( aSecurityPolicy );
       
   158     TIpcArgs args( &aActionIdentifier, &secPolicyBuf );
       
   159     TInt err = iSession.SendSync( EDefineAction, args );
       
   160     
       
   161     return err;
       
   162     }
       
   163 
       
   164 //----------------------------------------------------------------------------
       
   165 // CCFActionService::WriteStreamActionSubscriptionLC
       
   166 //----------------------------------------------------------------------------
       
   167 //
       
   168 HBufC8* CCFActionService::WriteStreamActionSubscriptionLC(
       
   169     CCFActionSubscription& aSubscription )
       
   170     {
       
   171     FUNC_LOG;
       
   172     
       
   173     CCFActionSubscriptionImpl& subscription =
       
   174         static_cast<CCFActionSubscriptionImpl&>( aSubscription );
       
   175 
       
   176     HBufC8* buffer = HBufC8::NewLC( subscription.Size() );
       
   177     TPtr8 bufferPtr = buffer->Des();
       
   178 
       
   179     RDesWriteStream stream( bufferPtr );
       
   180     stream.PushL();
       
   181     subscription.ExternalizeL( stream );
       
   182 
       
   183     // Cleanup
       
   184     CleanupStack::PopAndDestroy( &stream );
       
   185 
       
   186     return buffer;
       
   187     }
       
   188 
       
   189 // End of file