javaextensions/bluetooth/omjbluetooth/src.s60/bluetoothdevicediscoverer.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef BLUETOOTHDEVICEDISCOVERER_H
       
    20 #define BLUETOOTHDEVICEDISCOVERER_H
       
    21 
       
    22 #include <bt_sock.h>
       
    23 #include <e32base.h>
       
    24 #include <queue>
       
    25 
       
    26 #include "logger.h"
       
    27 #include "monitor.h"
       
    28 #include "bluetoothstructs.h"
       
    29 #include "bluetoothfunctionserver.h"
       
    30 #include "scopedlocks.h"
       
    31 
       
    32 namespace java
       
    33 {
       
    34 namespace bluetooth
       
    35 {
       
    36 
       
    37 class BluetoothDeviceDiscoverer: public CActive
       
    38 {
       
    39 public:
       
    40 
       
    41     /**
       
    42      * @param aFunctionServer Pointer to BluetoothFunctionServer
       
    43      */
       
    44     static BluetoothDeviceDiscoverer* NewL(
       
    45         BluetoothFunctionServer *aFunctionServer);
       
    46 
       
    47     ~BluetoothDeviceDiscoverer();
       
    48 
       
    49     /**
       
    50      * Starts device inquiry
       
    51      */
       
    52     void DiscoverDevicesL(int aAccessCode);
       
    53 
       
    54     /**
       
    55      * Searches for the next device
       
    56      */
       
    57     int getNextDevice(DiscoveredDevice &aDiscoveredDevice);
       
    58 
       
    59     /**
       
    60      *
       
    61      */
       
    62     void RunL();
       
    63 
       
    64     /**
       
    65      * Cancels device inquiry
       
    66      */
       
    67     void DoCancel();
       
    68 
       
    69     inline void cancel()
       
    70     {
       
    71         Cancel();
       
    72     }
       
    73 
       
    74 private:
       
    75 
       
    76     BluetoothDeviceDiscoverer(BluetoothFunctionServer *aFunctionServer);
       
    77 
       
    78     BluetoothDeviceDiscoverer() : CActive(EPriorityStandard)
       
    79     {
       
    80     };
       
    81 
       
    82     void ConstructL();
       
    83 
       
    84     void setNext();
       
    85 
       
    86     void fillDeviceInfo(DiscoveredDevice &aDiscoveredDevice);
       
    87 
       
    88     void enqueue(DiscoveredDevice *aDiscoveredDevice);
       
    89 
       
    90     void dequeue(DiscoveredDevice& aDiscoveredDevice);
       
    91 
       
    92     void clearQueue();
       
    93 
       
    94 private:
       
    95 
       
    96     bool mWaiting;
       
    97     int mStatus;
       
    98     int mSocketServerStatus;
       
    99 
       
   100     pthread_mutex_t  mMutex;
       
   101     pthread_cond_t   mCondVar;
       
   102     TNameEntry mNameEntry;
       
   103     RSocketServ mSocketServer;
       
   104     RHostResolver mHostResolver;
       
   105     TFullName mThreadName;
       
   106 
       
   107     std::queue<DiscoveredDevice*> mDiscoveredDevicesQueue;
       
   108 
       
   109     java::util::Monitor* mDeviceDiscoveryMonitor;
       
   110     BluetoothFunctionServer* mFunctionServer;
       
   111 };
       
   112 
       
   113 } //end namespace bluetooth
       
   114 } //end namespace java
       
   115 
       
   116 #endif // BLUETOOTHDEVICEDISCOVERER_H