htiui/HtiCommPlugins/HtiBtCommPlugin/BtEngine/src/messageservicesearcher.cpp
changeset 0 d6fe6244b863
child 3 2703485a934c
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     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:  Message service searcher.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <bt_sock.h>
       
    21 
       
    22 #include "MessageServiceSearcher.h"
       
    23 #include "BTServiceSearcher.pan"
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // TSdpAttributeParser::SSdpAttributeNode[]
       
    30 // Construct a TSdpAttributeParser.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 static const TSdpAttributeParser::SSdpAttributeNode gSerialPortProtocolArray[] =
       
    34     {
       
    35         { TSdpAttributeParser::ECheckType, ETypeDES },
       
    36         { TSdpAttributeParser::ECheckType, ETypeDES },
       
    37         { TSdpAttributeParser::ECheckValue, ETypeUUID, KL2CAP },
       
    38         { TSdpAttributeParser::ECheckEnd },
       
    39         { TSdpAttributeParser::ECheckType, ETypeDES },
       
    40         { TSdpAttributeParser::ECheckValue, ETypeUUID, KRFCOMM }, // KRFCOMM defined in bt_sock.h
       
    41         { TSdpAttributeParser::EReadValue, ETypeUint, KRfcommChannel }, // KRfcommChannel is custom key value used in FoundElementL. If there were more than one value to be read, the key value would be usefull
       
    42         { TSdpAttributeParser::ECheckEnd },
       
    43         { TSdpAttributeParser::ECheckEnd },
       
    44         { TSdpAttributeParser::EFinished }
       
    45     };
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // TStaticArrayC
       
    49 // Provides a type and size, safe method of using static arrays.
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 static const TStaticArrayC<TSdpAttributeParser
       
    53 ::SSdpAttributeNode> gSerialPortProtocolList = CONSTRUCT_STATIC_ARRAY_C(
       
    54                                                gSerialPortProtocolArray );
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CMessageServiceSearcher::NewL()
       
    58 // Two-phased constructor.
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 CMessageServiceSearcher* CMessageServiceSearcher::NewL()
       
    62     {
       
    63     CMessageServiceSearcher* self = CMessageServiceSearcher::NewLC();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CMessageServiceSearcher::NewLC()
       
    70 // Two-phased constructor.
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 CMessageServiceSearcher* CMessageServiceSearcher::NewLC()
       
    74     {
       
    75     CMessageServiceSearcher* self = new (ELeave) CMessageServiceSearcher();
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ----------------------------------------------------------------------------
       
    82 // CMessageServiceSearcher::CMessageServiceSearcher()
       
    83 // Construcor.
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CMessageServiceSearcher::CMessageServiceSearcher()
       
    87 : CBTServiceSearcher(),
       
    88   iServiceClass( KServiceClass )
       
    89     {
       
    90     }
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // CMessageServiceSearcher::~CMessageServiceSearcher()
       
    94 // Destructor.
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 CMessageServiceSearcher::~CMessageServiceSearcher()
       
    98     {
       
    99     iPortNumbers.Close();
       
   100     }
       
   101 
       
   102 // ----------------------------------------------------------------------------
       
   103 // CMessageServiceSearcher::ConstructL()
       
   104 // Symbian 2nd phase constructor can leave.
       
   105 // ----------------------------------------------------------------------------
       
   106 //
       
   107 void CMessageServiceSearcher::ConstructL()
       
   108     {
       
   109     // no implementation required
       
   110     }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // CMessageServiceSearcher::ServiceClass()
       
   114 // The service class to search.
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 const TUUID& CMessageServiceSearcher::ServiceClass() const
       
   118     {
       
   119     return iServiceClass;
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // CMessageServiceSearcher::ProtocolList()
       
   124 // The list of Protocols required by the service.
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 const TSdpAttributeParser::TSdpAttributeList& CMessageServiceSearcher
       
   128 ::ProtocolList() const
       
   129     {
       
   130     return gSerialPortProtocolList;
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CMessageServiceSearcher::FoundElementL()
       
   135 // Read the data element.
       
   136 // ----------------------------------------------------------------------------
       
   137 //
       
   138 void CMessageServiceSearcher::FoundElementL( TInt aKey, CSdpAttrValue& aValue )
       
   139     {
       
   140     __ASSERT_ALWAYS( aKey == static_cast<TInt>( KRfcommChannel ),
       
   141         Panic( EBTServiceSearcherProtocolRead ) );
       
   142     AppendPort( aValue.Uint() );
       
   143     }
       
   144 
       
   145 // ----------------------------------------------------------------------------
       
   146 // CMessageServiceSearcher::Port()
       
   147 // Port connection on the remote machine.
       
   148 // ----------------------------------------------------------------------------
       
   149 //
       
   150 TInt CMessageServiceSearcher::Port( TInt aIndex )
       
   151     {
       
   152     if ( aIndex < 0 || aIndex >= iPortNumbers.Count() )
       
   153         {
       
   154         return KErrNotFound;
       
   155         }
       
   156     return iPortNumbers[aIndex];
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CMessageServiceSearcher::AppendPort()
       
   161 // Adds a new port number to the port number array. If the port number
       
   162 // already exists in the array a duplicate is not added.
       
   163 // ----------------------------------------------------------------------------
       
   164 //
       
   165 void CMessageServiceSearcher::AppendPort( TInt aPort )
       
   166     {
       
   167     if ( iPortNumbers.Find( aPort ) == KErrNotFound )
       
   168         {
       
   169         iPortNumbers.Append( aPort );
       
   170         }
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------------------------------
       
   174 // CMessageServiceSearcher::ServiceCount()
       
   175 // The amount of requested services found from the remote machine.
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 TInt CMessageServiceSearcher::ServiceCount()
       
   179     {
       
   180     return iPortNumbers.Count();
       
   181     }
       
   182 
       
   183 // End of File