// ----------------------------------------------------------------------------------
// CSSYControlOrientation::CreateAndRegisterChannelsL()
// ----------------------------------------------------------------------------------
//
void CSSYControlOrientation::CreateAndRegisterChannelsL(
    const TSSsyChannelInfo* aChannelConfigurations,
    const TUint aNumberofConfigurations )
    {
    SSY_TRACE_IN();

    ASSERT_ALWAYS_SSY( aChannelConfigurations );
    ASSERT_ALWAYS_SSY( aNumberofConfigurations );

    RSensrvChannelInfoList channelInfoList;

    for ( TInt index = 0; index < aNumberofConfigurations; index++ )
        {
        CSSYChannel* channel( NULL );

        TSensrvChannelInfo channelInfo
            (
            aChannelConfigurations[index].iChannelId,
            aChannelConfigurations[index].iContextType,
            aChannelConfigurations[index].iQuantity,
            aChannelConfigurations[index].iChannelType,
            aChannelConfigurations[index].iLocation,
            aChannelConfigurations[index].iVendorId,
            aChannelConfigurations[index].iDataItemSize,
            aChannelConfigurations[index].iDataTypeId
            );

        switch ( channelInfo.iChannelType )
            {
            case KSensrvChannelTypeIdOrientationData:
                // Intentional flowthrough
            case KSensrvChannelTypeIdRotationData:
                channel = CSSYChannel::NewL( iSensorProperties, iCallback, channelInfo );
                break;
            default:
                ASSERT_ALWAYS_SSY( 0 );
                break;
            }

        if ( channel )
            {
            User::LeaveIfError(iChannelArray.Append( channel ));
            User::LeaveIfError(channelInfoList.Append( channelInfo));
            }
        }

    // Register channels to the client
    SSY_TRACE_TRAP( err, iCallback->RegisterChannelsL( channelInfoList ) );

    // Update ChannelId
    for ( TInt i = 0; i < iChannelArray.Count(); i++ )
        {
        (*iChannelArray[i]).SetChannelId( channelInfoList[i].iChannelId );
        }

    channelInfoList.Reset();
    channelInfoList.Close();

    SSY_TRACE_OUT();
    }