examples/ForumNokia/BluetoothPMPExample/inc/Connector.h

00001 /*
00002  * Copyright © 2009 Nokia Corporation.
00003  */
00004 
00005 #ifndef CONNECTOR_H
00006 #define CONNECTOR_H
00007 
00008 // INCLUDES
00009 #include <e32base.h>
00010 
00011 #include <es_sock.h>
00012 #include <btdevice.h>
00013 #include <bt_sock.h>
00014 
00015 
00016 class MConnectorObserver
00017 {
00018 
00019 public:
00025     virtual void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData)=0;
00026     virtual void HandleConnectorErrorL(THostName aName, TInt aError)=0;
00027 };
00028 
00029 
00030 class CConnector : public CActive
00031 {
00032 public:
00033 
00040     static CConnector* NewL(MConnectorObserver& aObserver,
00041                             RSocketServ& aSocketServ);
00042 
00047     static CConnector* NewLC(MConnectorObserver& aObserver,
00048                              RSocketServ& aSocketServ);
00049 
00055     ~CConnector();
00056 
00068     TRequestStatus ConnectL(THostName aName, TBTDevAddr aAddr, TInt aPort);
00069 
00075     void Disconnect();
00076 
00084     void SendData(const TDesC8& /*aData*/);
00085 
00086 protected:
00087 
00093     void RunL();
00094 
00100     void DoCancel();
00101 
00102     TInt RunError(TInt aError);
00103     
00104 private:
00105 
00114     CConnector(MConnectorObserver& aObserver, RSocketServ& aSocketServ);
00115 
00120     void ConstructL();
00121 
00131     void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData);
00132 
00138     void WaitAndReceive();
00139 
00140 public: // data
00141 
00142     // name of the device connector connects
00143     THostName iName;
00144     // address of the device connector connects
00145     TBTDevAddr iAddr;
00146     // port of the device connector connects
00147     TInt iPort;
00148     // connecting socket
00149     RSocket iSock;
00150     // buffer holding received data
00151     TBuf8<40> iBuffer;
00152     // length of received data
00153     TSockXfrLength iLen;
00154     // reference to observer
00155     MConnectorObserver& iObserver;
00156     // socket server handle
00157     RSocketServ& iSocketServ;
00158     // the state of the connector
00159     enum TState
00160         {
00161         ENone = 1,
00162         EConnecting,
00163         EWaiting,
00164         ESending
00165         };
00166 
00167     TState iState;
00168 };
00169 
00170 #endif

Generated by  doxygen 1.6.2