examples/Qt/qtbluetoothapp/connector.h

00001 /*
00002  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #ifndef CONNECTOR_H
00031 #define CONNECTOR_H
00032 
00033 // INCLUDES
00034 #include <e32base.h>
00035 
00036 #include <es_sock.h>
00037 #include <btdevice.h>
00038 #include <bt_sock.h>
00039 
00040 
00041 class MConnectorObserver
00042 {
00043 
00044 public:
00050     virtual void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData)=0;
00051     virtual void HandleConnectorErrorL(THostName aName, TInt aError)=0;
00052 };
00053 
00054 
00055 class CConnector : public CActive
00056 {
00057 public:
00058 
00065     static CConnector* NewL(MConnectorObserver& aObserver,
00066                             RSocketServ& aSocketServ);
00067 
00072     static CConnector* NewLC(MConnectorObserver& aObserver,
00073                              RSocketServ& aSocketServ);
00074 
00080     ~CConnector();
00081 
00093     TRequestStatus ConnectL(THostName aName, TBTDevAddr aAddr, TInt aPort);
00094 
00100     void Disconnect();
00101 
00109     void SendData(const TDesC8& /*aData*/);
00110 
00111 protected:
00112 
00118     void RunL();
00119 
00125     void DoCancel();
00126 
00127     TInt RunError(TInt aError);
00128     
00129 private:
00130 
00139     CConnector(MConnectorObserver& aObserver, RSocketServ& aSocketServ);
00140 
00145     void ConstructL();
00146 
00156     void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData);
00157 
00163     void WaitAndReceive();
00164 
00165 public: // data
00166 
00167     // name of the device connector connects
00168     THostName iName;
00169     // address of the device connector connects
00170     TBTDevAddr iAddr;
00171     // port of the device connector connects
00172     TInt iPort;
00173     // connecting socket
00174     RSocket iSock;
00175     // buffer holding received data
00176     TBuf8<40> iBuffer;
00177     // length of received data
00178     TSockXfrLength iLen;
00179     // reference to observer
00180     MConnectorObserver& iObserver;
00181     // socket server handle
00182     RSocketServ& iSocketServ;
00183     // the state of the connector
00184     enum TState
00185         {
00186         ENone = 1,
00187         EConnecting,
00188         EWaiting,
00189         ESending
00190         };
00191 
00192     TState iState;
00193 };
00194 
00195 #endif

Generated by  doxygen 1.6.2