accessoryservices/accessoryserver/src/Server/AccSrvSubConnection.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:  Server-side sub-session of Accessory Connection
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "AccSrvSubConnection.h"
       
    22 #include "AccSrvMainSession.h"
       
    23 #include "AccClientServerMessages.h"
       
    24 #include "AccSrvServerModel.h"
       
    25 #include "acc_debug.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 
       
    37 // MODULE DATA STRUCTURES
       
    38 
       
    39 // LOCAL FUNCTION PROTOTYPES
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 
       
    43 // ============================= LOCAL FUNCTIONS ===============================
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CAccSrvSubConnection::CAccSrvSubConnection
       
    49 // C++ default constructor can NOT contain any code, that
       
    50 // might leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CAccSrvSubConnection::CAccSrvSubConnection(
       
    54     CASYProxyAPI* aProxy,
       
    55     CAccSrvConnectionController* aConnectionController,
       
    56     CAccSrvServerModel* aServerModel )
       
    57     : CAccSrvSubConnectionBase ( aProxy, aConnectionController, aServerModel )
       
    58     {
       
    59     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::CAccSrvSubConnection()" );
       
    60 
       
    61     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::CAccSrvSubConnection - return void" );
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CAccSrvSubConnection::ConstructL
       
    66 // Symbian 2nd phase constructor can leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CAccSrvSubConnection::ConstructL()
       
    70     {
       
    71     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::ConstructL" );
       
    72 
       
    73     CAccSrvSubConnectionBase::ConstructL();
       
    74 
       
    75     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::ConstructL - return void" );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CAccSrvSubConnection::NewL
       
    80 // Two-phased constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CAccSrvSubConnection* CAccSrvSubConnection::NewL( 
       
    84     CASYProxyAPI* aProxy,
       
    85     CAccSrvConnectionController* aConnectionController,
       
    86     CAccSrvServerModel* aServerModel )
       
    87     {
       
    88     if ( !aProxy )
       
    89         {
       
    90         User::Leave( KErrArgument );
       
    91         }
       
    92 
       
    93     CAccSrvSubConnection* self = new (ELeave) CAccSrvSubConnection( aProxy,
       
    94                                                                     aConnectionController,
       
    95                                                                     aServerModel );
       
    96 
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     CleanupStack::Pop( self );
       
   100 
       
   101     return self;
       
   102     }
       
   103 
       
   104 // Destructor
       
   105 CAccSrvSubConnection::~CAccSrvSubConnection()
       
   106     {
       
   107     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::~CAccSrvSubConnection()" );
       
   108     
       
   109     RMessage2 dummy;
       
   110     
       
   111     CAccSrvSubConnection::CancelNotifyAccessoryConnectionStatusChanged( dummy );//For iNotifyAccessoryConnectionStatusChanged
       
   112     CAccSrvSubConnection::CancelGetAccessoryConnectionStatus( dummy );//For iGetAccessoryConnectionStatus        
       
   113 
       
   114     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::~CAccSrvSubConnection - return void" );
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CAccSrvSubConnection::GetAccessoryConnectionStatusL
       
   119 //
       
   120 // Accessory connection status is valid when
       
   121 // ASY(s) initialization is done (ECmdProcessCommandInit)
       
   122 // i.e. ASY(s) informs AccessorySerever about possible connected accessory(/ies).
       
   123 // Initialization is done during boot.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CAccSrvSubConnection::GetAccessoryConnectionStatusL( const RMessage2& aMessage )
       
   127     {
       
   128     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::GetAccessoryConnectionStatusL()" );
       
   129 
       
   130     if ( iServerModel->ASYsLoadCompleted() )
       
   131         {
       
   132         TAccPolGenericIDArray sourceGIDArray;
       
   133         iServerModel->CurrentConnectionStatusL( sourceGIDArray );
       
   134         TAccSrvGenericIDArrayPckg genericIdArrayPckg( sourceGIDArray );
       
   135         aMessage.WriteL( KAccServParamPosFirst, genericIdArrayPckg );
       
   136         }
       
   137     else
       
   138         {
       
   139         User::Leave( KErrNotReady );
       
   140         }
       
   141 
       
   142     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::GetAccessoryConnectionStatusL - return void" );
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CAccSrvSubConnection::GetAccessoryConnectionStatusAsyncL
       
   147 //
       
   148 // Asynchronous getter for Accessory connection status. If ASY(s) initialization
       
   149 // is done, this request can be completed immediatelly.
       
   150 // See CAccSrvSubConnection::GetAccessoryConnectionStatusL (synchronous).
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CAccSrvSubConnection::GetAccessoryConnectionStatusAsyncL( const RMessage2& aMessage )
       
   154     {
       
   155     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::GetAccessoryConnectionStatusAsyncL()" );
       
   156 
       
   157     if ( iServerModel->ASYsLoadCompleted() )
       
   158         {
       
   159         TAccPolGenericIDArray sourceGIDArray;
       
   160         iServerModel->CurrentConnectionStatusL( sourceGIDArray );
       
   161         TAccSrvGenericIDArrayPckg genericIdArrayPckg( sourceGIDArray );
       
   162         aMessage.WriteL( KAccServParamPosFirst, genericIdArrayPckg );
       
   163         Write( aMessage, KAccSrvGetAccessoryConnectionStatusBit );
       
   164         aMessage.Complete( KErrNone );
       
   165         }
       
   166     else
       
   167         {
       
   168         iGetAccessoryConnectionStatus = aMessage;//Store RMessage2 for future completion
       
   169         iConnectionController->NotificationQueue().RegisterControlMessage( 
       
   170                                                         EAccessoryConnectionStatusAsyncChanged,
       
   171                                                         this );
       
   172         }
       
   173 
       
   174     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::GetAccessoryConnectionStatusAsyncL - return void" );
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CAccSrvSubConnection::NotifyAccessoryConnectionStatusChanged
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CAccSrvSubConnection::NotifyAccessoryConnectionStatusChanged( const RMessage2& aMessage )
       
   182     {
       
   183     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::NotifyAccessoryConnectionStatusChanged()" );
       
   184 
       
   185     iConnectionController->NotificationQueue().RegisterControlMessage( 
       
   186                                                         EAccessoryConnectionStatusChanged,
       
   187                                                         this );
       
   188     iNotifyAccessoryConnectionStatusChanged = aMessage;//Store RMessage2 for future completion
       
   189 
       
   190     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::NotifyAccessoryConnectionStatusChanged - return void" );
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CancelNotifyAccessoryConnectionStatusChanged
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CAccSrvSubConnection::CancelNotifyAccessoryConnectionStatusChanged(
       
   198     const RMessage2& /*aMessage*/ )
       
   199     {
       
   200     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::CancelNotifyAccessoryConnectionStatusChanged()" );
       
   201 
       
   202     // If request is Null, there is nothing to cancel
       
   203     if ( !iNotifyAccessoryConnectionStatusChanged.IsNull() )
       
   204         {
       
   205         iConnectionController->NotificationQueue().CancelControlMessage( 
       
   206                                                         EAccessoryConnectionStatusChanged,
       
   207                                                         this );
       
   208         Write( iNotifyAccessoryConnectionStatusChanged, KAccSrvNotifyAccConnStatusChangedBit );
       
   209         iNotifyAccessoryConnectionStatusChanged.Complete( KErrCancel );
       
   210         }
       
   211 
       
   212     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::CancelNotifyAccessoryConnectionStatusChanged - return void" );
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CAccSrvSubConnection::CancelGetAccessoryConnectionStatus
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CAccSrvSubConnection::CancelGetAccessoryConnectionStatus(
       
   220     const RMessage2& /*aMessage*/ )
       
   221     {
       
   222     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::CancelGetAccessoryConnectionStatus()" );
       
   223 
       
   224     // If request is Null, there is nothing to cancel
       
   225     if ( !iGetAccessoryConnectionStatus.IsNull() )
       
   226         {
       
   227         iConnectionController->NotificationQueue().CancelControlMessage( 
       
   228                                                         EAccessoryConnectionStatusAsyncChanged,
       
   229                                                         this );
       
   230         Write( iGetAccessoryConnectionStatus, KAccSrvGetAccessoryConnectionStatusBit );
       
   231         iGetAccessoryConnectionStatus.Complete( KErrCancel );
       
   232         }
       
   233 
       
   234     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::CancelGetAccessoryConnectionStatus - return void" );
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CAccSrvSubConnection::DispatchMessageL
       
   239 // Handles client request. If request is not handled here, it is passed to 
       
   240 // parent class for handling
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CAccSrvSubConnection::DispatchMessageL( const RMessage2& aMessage )
       
   244     {
       
   245     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::DispatchMessageL()" );
       
   246 
       
   247     TInt function = aMessage.Function();
       
   248 
       
   249     switch ( function )
       
   250         {
       
   251         case EAccSrvGetAccessoryConnectionStatus:
       
   252             {
       
   253             GetAccessoryConnectionStatusL( aMessage );
       
   254             break;
       
   255             }
       
   256         case EAccSrvGetAccessoryConnectionStatusAsync:
       
   257             {
       
   258             GetAccessoryConnectionStatusAsyncL( aMessage );
       
   259             break;
       
   260             }
       
   261         case EAccSrvNotifyAccessoryConnectionStatusChanged:
       
   262             {
       
   263             NotifyAccessoryConnectionStatusChanged( aMessage );
       
   264             break;
       
   265             }
       
   266         case EAccSrvCancelNotifyAccessoryConnectionStatusChanged:
       
   267             {
       
   268             CancelNotifyAccessoryConnectionStatusChanged( aMessage );
       
   269             break;
       
   270             }
       
   271         case EAccSrvCancelGetAccessoryConnectionStatus:
       
   272             {
       
   273             CancelGetAccessoryConnectionStatus( aMessage );
       
   274             break;
       
   275             }
       
   276         default:
       
   277             {
       
   278             // Not handled here, pass to base class
       
   279             CAccSrvSubConnectionBase::DispatchMessageL( aMessage );
       
   280             break;
       
   281             }
       
   282         } // switch( function )
       
   283 
       
   284     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::DispatchMessageL - return void" );
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CAccSrvSubConnection::CompleteMessageL
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 TBool CAccSrvSubConnection::CompleteMessageL( TMsgID aMsgID,
       
   292                                               TInt aErrorCode,
       
   293                                               TInt /*aUniqueID*/ )
       
   294     {
       
   295     COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubConnection::CompleteMessageL(%d)", aMsgID );
       
   296 
       
   297     if ( EAccessoryConnectionStatusChanged == aMsgID ) 
       
   298         {
       
   299         //Write new generic ID array and
       
   300         //complete outstanding AccessoryConnectionStatusChanged notification
       
   301         //CAccSrvSubBaseConnection::WriteL( iMessageArray[0], aGenericIDArray )
       
   302         TAccPolGenericIDArray genericIDArray;
       
   303         iServerModel->CurrentConnectionStatusL( genericIDArray );
       
   304         TPckg<TAccPolGenericIDArray> genericIDArrayPckg( genericIDArray );
       
   305 
       
   306         iNotifyAccessoryConnectionStatusChanged.WriteL( KAccServParamPosFirst, genericIDArrayPckg );
       
   307         Write( iNotifyAccessoryConnectionStatusChanged, KAccSrvNotifyAccConnStatusChangedBit );
       
   308         iNotifyAccessoryConnectionStatusChanged.Complete( aErrorCode );
       
   309         }
       
   310     else if ( EAccessoryConnectionStatusAsyncChanged == aMsgID )
       
   311         {
       
   312         //Write new generic ID array and
       
   313         //complete outstanding GetAccessoryConnectionStatus ( Async )
       
   314         TAccPolGenericIDArray genericIDArray;
       
   315         iServerModel->CurrentConnectionStatusL( genericIDArray );
       
   316         TAccSrvGenericIDArrayPckg genericIDArrayPckg( genericIDArray );
       
   317 
       
   318         iGetAccessoryConnectionStatus.WriteL( KAccServParamPosFirst, genericIDArrayPckg );
       
   319         Write( iGetAccessoryConnectionStatus, KAccSrvGetAccessoryConnectionStatusBit );
       
   320         iGetAccessoryConnectionStatus.Complete( aErrorCode );
       
   321         }
       
   322     else
       
   323         {
       
   324         TRACE_ASSERT_ALWAYS;
       
   325         User::Leave( KErrGeneral );
       
   326         }
       
   327 
       
   328     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubConnection::CompleteMessageL - return" );
       
   329 
       
   330     return ETrue; // if it gets here, return ETrue
       
   331     }
       
   332 
       
   333 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   334 
       
   335 //  End of File