examples/ForumNokia/BluetoothPMPExample/src/BluetoothPMPExampleEngine.cpp

00001 /*
00002  * Copyright (c) 2009-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 // INCLUDE FILES
00031 #include <aknquerydialog.h> // for input dialogs
00032 #include <utf.h>
00033 #include "Common.h"
00034 #include "BluetoothPMPExampleEngine.h"
00035 #include "DeviceDiscoverer.h"
00036 #include "ServiceAdvertiser.h"
00037 #include "ServiceDiscoverer.h"
00038 #include "Listener.h"
00039 #include "Connector.h"
00040 #include <BtPmpEx.rsg>
00041 
00042 CBluetoothPMPExampleEngine* CBluetoothPMPExampleEngine::NewL(
00043     CBluetoothPMPExampleAppUi& aAppUi)
00044     {
00045     CBluetoothPMPExampleEngine* self =
00046         CBluetoothPMPExampleEngine::NewLC(aAppUi);
00047     CleanupStack::Pop(self);
00048     return self;
00049     }
00050 
00051 
00052 CBluetoothPMPExampleEngine* CBluetoothPMPExampleEngine::NewLC(
00053     CBluetoothPMPExampleAppUi& aAppUi)
00054     {
00055     CBluetoothPMPExampleEngine* self =
00056         new (ELeave) CBluetoothPMPExampleEngine(aAppUi);
00057     CleanupStack::PushL(self);
00058     self->ConstructL();
00059     return self;
00060     }
00061 
00062 
00063 // Standard EPOC 2nd phase constructor
00064 void CBluetoothPMPExampleEngine::ConstructL()
00065     {
00066     // get socket server session
00067     User::LeaveIfError(iSocketServ.Connect());
00068 
00069     // init listener
00070     iListener = CListener::NewL(*this, iSocketServ);
00071     // init device discoverer
00072     iDeviceDiscoverer = CDeviceDiscoverer::NewL(iSocketServ, *this);
00073 
00074 #ifdef ENABLE_LIAC
00075     // Set default LIAC to OFF
00076     iLIAC = ETrue;
00077     // set current LIAC state
00078     iDeviceDiscoverer->SetLIAC( iLIAC );
00079 #endif
00080     // init service advertiser
00081     iServiceAdvertiser = CServiceAdvertiser::NewL();
00082     // init service discoverer
00083     iServiceDiscoverer = CServiceDiscoverer::NewL(*this);
00084 
00085     // clean connections table to begin with
00086     for ( TInt idx=0; idx<KMaxConnectedDevices; idx++ )
00087         {
00088         iConnectedDevices[idx] = NULL;
00089         }
00090     
00091     #ifdef ENABLE_LIAC
00092     // The key to control whether the local device is in Limited Discoverable 
00093     // mode The P&S value will contain a boolean: ETrue if in limited discoverable mode,
00094     // otherwise EFalse
00095     TInt attErr = iProperty.Define(KPropertyUidBluetoothControlCategory, 
00096             KPropertyKeyBluetoothSetLimitedDiscoverableStatus,RProperty::EInt);
00097     if (attErr != KErrNone && attErr != KErrAlreadyExists)
00098         {
00099         User::Leave(attErr);
00100         }
00101     
00102     
00103     // Set LIAC value
00104     SetLIAC(iLIAC);
00105     #endif
00106     }
00107 
00108 
00109 // ----------------------------------------------------------------------------
00110 // CBluetoothPMPExampleEngine::CBluetoothPMPExampleEngine(
00111 //     CBluetoothPMPExampleAppUi* aAppUi)
00112 //
00113 // constructor
00114 // ----------------------------------------------------------------------------
00115 CBluetoothPMPExampleEngine::CBluetoothPMPExampleEngine(
00116     CBluetoothPMPExampleAppUi& aAppUi):
00117     iIsSlave(EFalse),
00118     iAppUi(aAppUi)
00119     {
00120     //Nothing to do
00121     }
00122 
00123 // ----------------------------------------------------------------------------
00124 // CBluetoothPMPExampleEngine::~CBluetoothPMPExampleEngine()
00125 //
00126 // destructor
00127 // ----------------------------------------------------------------------------
00128 CBluetoothPMPExampleEngine::~CBluetoothPMPExampleEngine()
00129     {
00130     #ifdef ENABLE_LIAC
00131     SetLIAC(EFalse);
00132     iProperty.Close();
00133     #endif
00134 
00135     // disconnect all devices and clean up connections table
00136     DisconnectDevices();
00137     // stop and kill helpers
00138 
00139     delete iServiceAdvertiser;
00140     iServiceAdvertiser=NULL;
00141 
00142     delete iListener;
00143     iListener=NULL;
00144     
00145     iDeviceDiscoverer->Cancel();
00146     delete iDeviceDiscoverer;
00147     iDeviceDiscoverer = NULL;
00148 
00149     delete iServiceDiscoverer;
00150     iServiceDiscoverer=NULL;
00151 
00152     iSocketServ.Close();
00153 
00154     // wipe device data list
00155     iDevDataList.ResetAndDestroy();
00156     }
00157 
00158 
00159 
00160 // ----------------------------------------------------------------------------
00161 // ShowMessageL(
00162 //     const TDesC& aMsg, TBool aDrawLine=EFalse)
00163 //
00164 // displays text referenced by aMsg in the label, will append the aMsg in the
00165 // existing text
00166 // ----------------------------------------------------------------------------
00167 void CBluetoothPMPExampleEngine::ShowMessageL(const TDesC& aMsg,
00168                                               TBool aDrawLine=EFalse)
00169     {
00170     if (iAppUi.Container())
00171         {
00172         if( aDrawLine )
00173             iAppUi.Container()->DrawLineL();
00174         
00175         iAppUi.Container()->ShowMessageL(aMsg);
00176         }
00177     }
00178 
00179 
00180 
00181 // ----------------------------------------------------------------------------
00182 // CBluetoothPMPExampleEngine::DiscoverDevicesL()
00183 //
00184 // discover bluetooth devices within range.
00185 // ----------------------------------------------------------------------------
00186 void CBluetoothPMPExampleEngine::DiscoverDevicesL()
00187     {
00188     //timing:
00189     iStartTime.HomeTime();
00190     ShowMessageL(KDiscDevicesTxt, ETrue);
00191     TRAPD(err,iDeviceDiscoverer->DiscoverDevicesL(&iDevDataList));
00192     if (err)
00193         {
00194         HandleDeviceDiscoveryComplete(err);
00195         }
00196     }
00197 
00198 
00199 // ----------------------------------------------------------------------------
00200 // CBluetoothPMPExampleEngine::DiscoverServicesL()
00201 //
00202 // discover services provided by the discovered devices.
00203 // ----------------------------------------------------------------------------
00204 void CBluetoothPMPExampleEngine::DiscoverServicesL()
00205     {
00206     iStartTime.HomeTime();
00207     ShowMessageL(KDiscServicesTxt, ETrue);
00208     iServiceDiscoverer->DiscoverServicesL(&iDevDataList);
00209     }
00210 
00211 
00212 // ----------------------------------------------------------------------------
00213 // CBluetoothPMPExampleEngine::StartSlaveL()
00214 //
00215 // set application in slave mode.  the device will be set to listen to
00216 // a bluetooth channel, and advertise its service on the channel.
00217 // ----------------------------------------------------------------------------
00218 void CBluetoothPMPExampleEngine::StartSlaveL()
00219     {
00220     if ( iIsSlave )
00221         return;
00222 
00223     ShowMessageL(KSlaveInitTxt, ETrue);
00224 
00225     TInt channel;
00226     iListener->StartListenerL(channel);
00227     TBuf<KThirty> msg;
00228     msg.AppendFormat(KListeningTxt, channel);
00229     ShowMessageL(msg, EFalse);
00230 
00231     iServiceAdvertiser->StartAdvertiserL(channel);
00232     ShowMessageL(KSlaveInitCompTxt, EFalse);
00233     iIsSlave=ETrue;
00234     }
00235 
00236 // ----------------------------------------------------------------------------
00237 // CBluetoothPMPExampleEngine::StopSlaveL()
00238 //
00239 // Stop slave mode
00240 // 
00241 // ----------------------------------------------------------------------------
00242 void CBluetoothPMPExampleEngine::StopSlaveL()
00243     {
00244     if ( !iIsSlave )
00245         return;
00246 
00247     ShowMessageL(KNullDesC, ETrue);
00248 
00249     iListener->StopListener();
00250     iServiceAdvertiser->StopAdvertiserL();
00251     iIsSlave=EFalse;
00252     }
00253 
00254 
00255 // ----------------------------------------------------------------------------
00256 // CBluetoothPMPExampleEngine::DisconnectDevices()
00257 //
00258 // disconnect connected devices and clean up connections table
00259 // ----------------------------------------------------------------------------
00260 void CBluetoothPMPExampleEngine::DisconnectDevices()
00261     {
00262     for ( TInt idx=0; idx<KMaxConnectedDevices; idx++ )
00263         {
00264         if ( iConnectedDevices[idx] )
00265             {
00266             delete iConnectedDevices[idx];
00267             iConnectedDevices[idx]=NULL;
00268             }
00269         }
00270     ShowMessageL(KDisconnDevicesTxt, ETrue);
00271     iIsMaster = EFalse;
00272     }
00273 
00274 
00275 // ----------------------------------------------------------------------------
00276 // CBluetoothPMPExampleEngine::ConnectDevicesL()
00277 //
00278 // attempt to connect on all discovered devices (up to 7)
00279 // ----------------------------------------------------------------------------
00280 void CBluetoothPMPExampleEngine::ConnectDevicesL()
00281      {
00282      // close and delete all existing connections
00283      DisconnectDevices();
00284 
00285      iIsMaster = ETrue;
00286      ShowMessageL(KConnectingTxt, ETrue);
00287      // now attempt to connect
00288      for ( TInt idx=0; idx<(iDevDataList.Count()); idx++ )
00289          {
00290          if ( iConnectedDeviceCount>=KMaxConnectedDevices )
00291              return;
00292 
00293          TDeviceData *dev = iDevDataList[idx];
00294 
00295          // if matching service on remote device was found, the service port
00296          // is set and will be > 0.  if so, we can attempt to connect.
00297          if ( dev->iDeviceServicePort>0 )
00298              {
00299              CConnector* connector = CConnector::NewLC(*this, iSocketServ);
00300              if ( (connector->ConnectL(dev->iDeviceName,
00301                                        dev->iDeviceAddr,
00302                                        dev->iDeviceServicePort))==KErrNone )
00303                  {
00304                  iConnectedDevices[iConnectedDeviceCount] = connector;
00305                  iConnectedDeviceCount++;
00306                  CleanupStack::Pop(connector);
00307                  }
00308              else
00309                  {
00310                  // connection to device failed!!
00311                  CleanupStack::PopAndDestroy();
00312                  }
00313              }
00314          }
00315 
00316      ShowConnectedDevicesL();
00317      }
00318 
00319 // ----------------------------------------------------------------------------
00320 // CBluetoothPMPExampleEngine::ShowConnectedDevicesL()
00321 //
00322 // display the devices we are connected to
00323 // ----------------------------------------------------------------------------
00324 void CBluetoothPMPExampleEngine::ShowConnectedDevicesL()
00325     {
00326     TInt count=0;
00327     ShowMessageL(KConnDevicesTxt, ETrue);
00328     for (TInt idx=0; idx<KMaxConnectedDevices; idx++)
00329         {
00330         if ( iConnectedDevices[idx] )
00331             {
00332             THostName name;
00333             name = iConnectedDevices[idx]->iName;
00334             name.Append(KNewLine);
00335             ShowMessageL(name, EFalse);
00336             count++;
00337             }
00338         }
00339     if ( count==0 )
00340         {
00341         // no connections!
00342         // this may be because of no devices has been discovered,
00343         // or no devices are offering the requested service.
00344         ShowMessageL(KNoConns, EFalse);
00345         }
00346     }
00347 
00348 
00349 // ----------------------------------------------------------------------------
00350 // CBluetoothPMPExampleEngine::SendMessageL()
00351 //
00352 // send a message to all connected devices.  user will be prompted to enter
00353 // the message text.
00354 // ----------------------------------------------------------------------------
00355 void CBluetoothPMPExampleEngine::SendMessageL()
00356     {
00357     iMsgtext.Zero();
00358     CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(iMsgtext);
00359     if(!dlg->ExecuteLD(R_BLUETOOTHEXAMPLE_MESSAGEINPUT))
00360         {
00361         // Cancel
00362         return;
00363         }
00364     
00365     // explicitly convert from 16bit to 8bit character set
00366     CnvUtfConverter::ConvertFromUnicodeToUtf8(iMsgtext8, iMsgtext);
00367 
00368     TBuf<KEighty> msg;
00369     if ( iIsSlave )
00370         {
00371         // slave sending data
00372         iListener->SendData(iMsgtext8);
00373         msg.Format(KFormatStr3, &iMsgtext);
00374         ShowMessageL(msg, EFalse);
00375         }
00376     else
00377         {
00378         // master sending data
00379         for (TInt idx=0; idx<KMaxConnectedDevices; idx++)
00380             {
00381             if ( iConnectedDevices[idx])
00382                 {
00383                 iConnectedDevices[idx]->SendData(iMsgtext8);
00384                 THostName name;
00385                 name=iConnectedDevices[idx]->iName;
00386                 msg.Format(KFormatStr2, &name, &iMsgtext);
00387                 ShowMessageL(msg, EFalse);
00388                 }
00389             }
00390         }
00391     }
00392 
00393 
00394 // ----------------------------------------------------------------------------
00395 // CBluetoothPMPExampleEngine::HandleListenerDataReceivedL(TDesC& aData)
00396 //
00397 // display data the slave listener receives from the master.  this is a
00398 // callback that CListener class will invoke when it receives new data.
00399 // ----------------------------------------------------------------------------
00400 void CBluetoothPMPExampleEngine::HandleListenerDataReceivedL(const TDesC& aData)
00401     {
00402     // display received message
00403     TBuf<KEighty> msg;
00404     msg.Format(KFormatStr1, &aData);
00405     ShowMessageL(msg, EFalse);
00406     }
00407 
00408 
00409 // ----------------------------------------------------------------------------
00410 // CBluetoothPMPExampleEngine::HandleListenerConnectedL()
00411 //
00412 // a callback received from CListener to indicate that it has been connected to
00413 // ----------------------------------------------------------------------------
00414 void CBluetoothPMPExampleEngine::HandleListenerConnectedL()
00415     {
00416     ShowMessageL(KConnMsg, ETrue);
00417     }
00418 
00419 
00420 // ----------------------------------------------------------------------------
00421 // CBluetoothPMPExampleEngine::HandleListenerDisconnectedL()
00422 //
00423 // a callback received from CListener to indicate that it has been disconnected
00424 // ----------------------------------------------------------------------------
00425 void CBluetoothPMPExampleEngine::HandleListenerDisconnectedL()
00426     {
00427     if ( !iIsSlave )
00428         return;
00429 
00430     // Stop listener and advertiser
00431     // Set app to init mode
00432     StopSlaveL();
00433     ShowMessageL(KDisconMsg, ETrue);
00434     }
00435 
00436 
00437 // ----------------------------------------------------------------------------
00438 // CBluetoothPMPExampleEngine::HandleConnectorDataReceivedL(THostName aName,
00439 //                                                          TDesC& aData)
00440 //
00441 // display data the master receives from a connected slave.  this is a
00442 // callback that CConnector class will invoke when it receives data from slave.
00443 // Also echo the message to other slaves.
00444 // ----------------------------------------------------------------------------
00445 void CBluetoothPMPExampleEngine::HandleConnectorDataReceivedL(THostName aName,
00446                                                               const TDesC& aData)
00447     {
00448     // display received message
00449     TBuf<KEighty> msg;
00450     msg.Format(KFormatStr, &aName, &aData);
00451     ShowMessageL(msg, EFalse);
00452 
00453     // echo the message to other slaves
00454     _LIT8(KSeparator, ":");
00455 
00456     TBuf8<KEighty> buf; //should use HBufC so the size will be big enough
00457     TPtr8 msgtext8((TUint8*)buf.Ptr(), aData.Size()+KSeparator().Length() + aName.Size());
00458     CnvUtfConverter::ConvertFromUnicodeToUtf8(msgtext8, aData);
00459 
00460     //convert name to UTF8 so other slaves see
00461     //the sender name
00462     TBuf8<KEighty> bufName;
00463     TPtr8 name8((TUint8*)bufName.Ptr(), aName.Size());
00464     CnvUtfConverter::ConvertFromUnicodeToUtf8(name8, aName);
00465 
00466     //add the separator and name in the beginning;
00467     msgtext8.Insert(0, KSeparator );
00468     msgtext8.Insert(0, name8);
00469 
00470     for (TInt idx=0; idx<KMaxConnectedDevices; idx++)
00471         {
00472         if ( iConnectedDevices[idx])
00473             {
00474             THostName name;
00475             name=iConnectedDevices[idx]->iName;
00476 
00477             //echo to other slaves than the sender
00478             if( name.Compare(aName) != 0)
00479                 iConnectedDevices[idx]->SendData(msgtext8);
00480             }
00481         }
00482     }
00483 
00484 // ----------------------------------------------------------------------------
00485 // CBluetoothPMPExampleEngine::HandleConnectorErrorL(THostName aName,TInt aError)
00486 //
00487 // ----------------------------------------------------------------------------
00488 void CBluetoothPMPExampleEngine::HandleConnectorErrorL(THostName aName, TInt aError)
00489     {
00490     if (aError)
00491         {
00492         // display received message
00493         TBuf<KEighty> msg;
00494         msg.Format(KDeviceDisconMsg, &aName);
00495         ShowMessageL(msg, EFalse);
00496 
00497         for (TInt idx=0; idx<KMaxConnectedDevices; idx++)
00498             {
00499             if ( iConnectedDevices[idx])
00500                 {
00501                 THostName name;
00502                 name=iConnectedDevices[idx]->iName;
00503 
00504                 //echo to other slaves than the sender
00505                 if( name.Compare(aName) == 0)
00506                     {
00507                     delete iConnectedDevices[idx];
00508                     iConnectedDevices[idx] = NULL;
00509                     }
00510                 }
00511             }
00512 
00513         // Is there more connection running?
00514         iIsMaster = EFalse;
00515         for (TInt idx=0; idx<KMaxConnectedDevices; idx++)
00516             {
00517             if ( iConnectedDevices[idx])
00518                 {
00519                 iIsMaster = ETrue;
00520                 break;
00521                 }
00522             }
00523         }
00524     }
00525 
00526 // ----------------------------------------------------------------------------
00527 // CBluetoothPMPExampleEngine::HandleDeviceDiscoveryComplete()
00528 //
00529 // a callback received from device discoverer to indicate that the device
00530 // discovery has completed.
00531 // ----------------------------------------------------------------------------
00532 void CBluetoothPMPExampleEngine::HandleDeviceDiscoveryComplete(TInt aError)
00533     {
00534     if (aError)
00535         {
00536         iIsMaster = EFalse;
00537         }
00538     else
00539         {
00540         iIsMaster = ETrue;
00541         }
00542     
00543     iEndTime.HomeTime();
00544 
00545     TTimeIntervalSeconds seconds;
00546     iEndTime.SecondsFrom(iStartTime, seconds);
00547 
00548     TInt time = seconds.Int();
00549     TBuf<KTwelve> temp = KTimeTxt();
00550     temp.AppendNum(time);
00551     temp.Append(KSecTxt);
00552     TRAPD(err,ShowMessageL(temp,EFalse));
00553 
00554     // iterate and display found devices, if any
00555     if ( iDevDataList.Count()> 0 )
00556         {
00557         TBuf<KTwenty> count = KFoundTxt();
00558         count.AppendNum( iDevDataList.Count() );
00559         count.Append( KDevices );
00560         TRAP(err,ShowMessageL(count));
00561         }
00562     else
00563         {
00564         // no devices found
00565         TRAP(err,ShowMessageL(KNoDevFound, EFalse));
00566         }
00567     }
00568 
00569 // ----------------------------------------------------------------------------
00570 // CBluetoothPMPExampleEngine::HandleServiceDiscoveryCompleteL()
00571 //
00572 // a callback received from service discoverer to indicate that the service
00573 // discovery has completed.
00574 // ----------------------------------------------------------------------------
00575 void CBluetoothPMPExampleEngine::HandleServiceDiscoveryCompleteL()
00576     {
00577     iEndTime.HomeTime();
00578 
00579     TTimeIntervalSeconds seconds;
00580     iEndTime.SecondsFrom(iStartTime, seconds);
00581 
00582     TInt time = seconds.Int();
00583     TBuf<KTwelve> temp = KTimeTxt();
00584     temp.AppendNum(time);
00585     temp.Append(KSecTxt);
00586     ShowMessageL(temp,ETrue);
00587 
00588     TInt count=0;
00589     // display devices with service we can use
00590     for ( TInt idx=0; idx<(iDevDataList.Count()); idx++ )
00591         {
00592         TDeviceData *dev = iDevDataList[idx];
00593         if ( dev->iDeviceServicePort>0 )
00594             {
00595             THostName name = dev->iDeviceName;
00596             name.Append(KNewLine);
00597             ShowMessageL(name, EFalse);
00598             count++;
00599             }
00600         }
00601     if ( count==0 )
00602         {
00603         ShowMessageL(KNoServiceFound, EFalse);
00604         }
00605     else
00606         {
00607         ShowMessageL(KServiceFound, EFalse);
00608         }
00609     }
00610 
00611 
00612 // ----------------------------------------------------------------------------
00613 // CBluetoothPMPExampleEngine::HasConnections()
00614 //
00615 // returns true if master has any connections to slave(s)
00616 // ----------------------------------------------------------------------------
00617 TBool CBluetoothPMPExampleEngine::HasConnections()
00618     {
00619     TBool exists = EFalse;
00620     for (TInt idx=0; idx<KMaxConnectedDevices; idx++)
00621         {
00622         if ( iConnectedDevices[idx])
00623             {
00624             exists = ETrue;
00625             break;
00626             }
00627         }
00628     return exists;
00629     }
00630 
00631 
00632 // ----------------------------------------------------------------------------
00633 // CBluetoothPMPExampleEngine::DeviceDiscovered
00634 // ----------------------------------------------------------------------------
00635 //a callback to indicate that a device has been found
00636 //main reason for this is that the UI can react so user
00637 //knows that something is going on and the app is not "frozen"
00638 void CBluetoothPMPExampleEngine::DeviceDiscovered(const TDeviceData &aDevice)
00639     {
00640     TBuf<KForty> name = aDevice.iDeviceName;
00641     name.Trim();
00642 
00643     if( name.Length() == 0 )
00644         name.Append(KDeviceWithNoName);
00645 
00646     TRAPD(err,ShowMessageL(name, EFalse));
00647     }
00648 
00649 // ----------------------------------------------------------------------------
00650 // CBluetoothPMPExampleEngine::ReportServiceDiscoveryErrorL
00651 // ----------------------------------------------------------------------------
00652 void CBluetoothPMPExampleEngine::ReportServiceDiscoveryErrorL(TInt aError)
00653     {
00654     TBuf<KThirty> discError = KServiceDiscoveryError();
00655     discError.AppendNum(aError);
00656     iAppUi.Container()->ShowMessageL(discError);
00657     }
00658 
00659 // ----------------------------------------------------------------------------
00660 // CBluetoothPMPExampleEngine::TurnBtOnL
00661 // ----------------------------------------------------------------------------
00662 //Uses the Notifier API to ask the user to turn on Bluetooth
00663 //if it's not on already.
00664 void CBluetoothPMPExampleEngine::TurnBtOnL()
00665     {
00666     //the constant is from btnotifierapi.h which is not in all SDKs
00667     //so it's hard coded here
00668     const TUid KPowerModeSettingNotifierUid = {0x100059E2};
00669     //const TUid KBTPowerStateNotifierUid = {0x101F808E}; //S80 and 7710
00670     
00671     RNotifier notifier;
00672     User::LeaveIfError( notifier.Connect() );
00673     TPckgBuf<TBool> dummy(ETrue);
00674     TPckgBuf<TBool> reply(EFalse);
00675     TRequestStatus stat;
00676     notifier.StartNotifierAndGetResponse(stat, KPowerModeSettingNotifierUid, dummy, reply);
00677     User::WaitForRequest(stat);
00678     notifier.CancelNotifier(KPowerModeSettingNotifierUid);
00679     notifier.Close();
00680     }
00681 
00682 #ifdef ENABLE_LIAC
00683 // ----------------------------------------------------------------------------
00684 // CBluetoothPMPExampleEngine::SetLIAC
00685 // ----------------------------------------------------------------------------
00686 void CBluetoothPMPExampleEngine::SetLIAC( TBool aState )
00687     {
00688     TInt err = KErrNone;
00689 
00690     // Set LIAC for the system    
00691     err = iProperty.Set(KPropertyUidBluetoothControlCategory,
00692             KPropertyKeyBluetoothSetLimitedDiscoverableStatus, 
00693             aState);
00694     
00695     TBuf<KEighty> myMessage;
00696 
00697     myMessage.Zero();
00698 
00699     if ( KErrNone == err )
00700         {
00701         if ( aState )
00702             {
00703             myMessage.Append( KLIACOn );
00704             }
00705         else
00706             {
00707             myMessage.Append( KLIACOff );
00708             }        
00709         iLIAC = aState;
00710 
00711         iDeviceDiscoverer->SetLIAC( iLIAC );
00712 
00713         }
00714     else
00715         {
00716         myMessage.AppendFormat( KLIACError, err );
00717         }
00718 
00719     TRAP( err, ShowMessageL( myMessage, ETrue ));
00720     }
00721 
00722 // ----------------------------------------------------------------------------
00723 // CBluetoothPMPExampleEngine::LIAC
00724 // ----------------------------------------------------------------------------
00725 TBool CBluetoothPMPExampleEngine::LIAC()
00726     {
00727     return iLIAC;
00728     }
00729 #endif
00730 
00731 // ----------------------------------------------------------------------------
00732 // CBluetoothPMPExampleEngine::IsDiscoveryActive
00733 // ----------------------------------------------------------------------------
00734 TBool CBluetoothPMPExampleEngine::IsDiscoveryActive()
00735     {
00736     return iDeviceDiscoverer->IsActive();
00737     }
00738 
00739 // ----------------------------------------------------------------------------
00740 // CBluetoothPMPExampleEngine::StopDiscovery
00741 // ----------------------------------------------------------------------------
00742 void CBluetoothPMPExampleEngine::StopDiscovery()
00743     {
00744     if ( IsDiscoveryActive() )
00745         {
00746         iDeviceDiscoverer->StopDiscovery();
00747         } 
00748     iIsMaster = EFalse;
00749     }

Generated by  doxygen 1.6.2