void QuteMessenger::newSerialServiceFound(const QBtDevice& dev, const QBtService& serv)
{
    QString exprectedServiceName("Messenger Protocol ");
    exprectedServiceName += dev.getName();

    qDebug() << exprectedServiceName;
    qDebug() << serv.getName();

    if (QString::compare(exprectedServiceName, serv.getName()) == 0)
    {
        serviceDisc->stopDiscovery();
        selectedService = serv;

        QChatWidgetClient* tmpChat;
        tmpChat = new QChatWidgetClient(this);
        tmpChat->SetName(deviceQueriedForServices.getName());

        ui.tabWidget->addTab(tmpChat, deviceQueriedForServices.getName());
        chatTabs.append((QChatWidget*) tmpChat);

        connect(this, SIGNAL(serialParamRetreived(QBtDevice, QBtService)),
                tmpChat, SLOT(setParameters(QBtDevice, QBtService)));

        emit serialParamRetreived(dev, serv);
    }
}
void QuteMessenger::newServiceFound(const QBtDevice& dev, const QBtService& serv)
{
    //since we need only the first available service with the given ClassID
    //when the first service is reported, the service discovery stops
    disconnect(serviceDisc, SIGNAL(newServiceFound(const QBtDevice&, const QBtService&)), this,
               SLOT(newServiceFound(const QBtDevice&, const QBtService&)));

    qDebug() << "Service to connect: " << serv.getName();
    qDebug() << "UUID: " << serv.getClass().get();
    qDebug() << "Dev: " << dev.getName();
    qDebug() << "Dev Addr: " << dev.getAddress().toString();

    if(obexClient)
    {
        delete obexClient;
        obexClient = NULL;
    }

    obexClient = new QBtObjectExchangeClient(this);

    connect(obexClient, SIGNAL(connectedToServer()), this, SLOT(connectedToRemoteOBEXServer()));
    connect(obexClient, SIGNAL(objectSent()), this, SLOT(fileSent()));
    connect(obexClient, SIGNAL(error (QBtObjectExchangeClient::ErrorCode)),
            this, SLOT(reportObexError(QBtObjectExchangeClient::ErrorCode)) );

    selectedService = serv;

    obexClient->connectToServer(deviceQueriedForServices, selectedService);
}
/**
* ConnectToServer
* Connect to the server
* @param remoteDevice the remote server to connect to
* @param remoteServive the remote service of the server
*/
void QBtObjectExchangeClientPrivate::ConnectToServer(const QBtDevice& remoteDevice, const QBtService& remoteService)
{
	//check
	if( !remoteDevice.getAddress().isValid())
	{
		emit p_ptr->error(QBtObjectExchangeClient::OBEXClientNoSelectedDevice);
		return;
	}
	if( remoteService.getClass()  == QBtConstants::UndefinedClass &&
		remoteService.getHandle() == 0)
	{
		emit p_ptr->error(QBtObjectExchangeClient::OBEXClientNoSelectedService);
		return;
	}
	
	server = new QBtDevice(remoteDevice);
	connectingService = new QBtService(remoteService);
	
	BTDEVHDL devHandle = GetDeviceHandle(server->getAddress());

	BTINT32 result = BTSDK_FALSE;

	if(connectionHandle != BTSDK_INVALID_HANDLE)
		result = Btsdk_Connect(connectingService->getHandle(), 0, &connectionHandle);
	else
		result = Btsdk_ConnectEx(devHandle, connectingService->getClass(), 0, &connectionHandle);

	if(result != BTSDK_OK)
		emit p_ptr->error(QBtObjectExchangeClient::OBEXClientConnectionError);
	else
		emit p_ptr->connectedToServer();
}
void QBtServiceDiscovererPrivate::ProcessFoundServices(BTSVCHDL* foundServices, int numOfServices)
{
	BTUINT32 result = BTSDK_FALSE;
	BtSdkRemoteServiceAttrStru serviceInfo;
	serviceInfo.mask = BTSDK_RSAM_SERVICENAME;

	for(int i=0; i<numOfServices; i++)
	{
		result = Btsdk_GetRemoteServiceAttributes(foundServices[i], &serviceInfo);
		if(result != BTSDK_OK)
			return;

		QBtService newService;
		newService.setHandle(foundServices[i]);
		newService.setName(QString::fromUtf8((const char*)serviceInfo.svc_name));
		newService.setClass((QBtConstants::ServiceClass)serviceInfo.service_class);
		
		if(serviceInfo.service_class == BTSDK_CLS_SERIAL_PORT)
			RetrieveSPPAttributes(&newService, foundServices[i]);
			
		p_ptr->_remoteDevice.addNewService(newService);
		emit p_ptr->newServiceFound(p_ptr->_remoteDevice, newService);
	}
}
// ----------------------------------------------------------------------------
// QBtServiceAdvertiserPrivate::StartAdvertiser(const QBtService& service)
//
// start service advertiser on given channel.  an entry to service discovery
// database will be entered describing our advertised service.
// ----------------------------------------------------------------------------
void QBtServiceAdvertiserPrivate::StartAdvertiser (const QBtService& service)
{
   //localService = new QBtService(service);

   // open sdp session
   User::LeaveIfError(iSdp.Connect());

   // open sdp database session
   User::LeaveIfError(iSdpDB.Open(iSdp));

   // create a record of the correct service class
   //QBtUuid uuid = service.getClass();

   TUUID uuid = QBtUuidToSymbianUuid (service.getClass() );
   iSdpDB.CreateServiceRecordL (uuid, iRecord);


   // add a protocol to the record
   CSdpAttrValueDES* protocolDescriptorList = CSdpAttrValueDES::NewDESL(NULL);
   CleanupStack::PushL(protocolDescriptorList);

   TBuf8<1> channel;
   channel.Append((TChar)service.getPort());

   // create protocol list for our service
   MSdpElementBuilder* e = protocolDescriptorList->StartListL();

      QBtService::ProtocolList protocolList = service.getProtocols();
      for (int i=0; i < protocolList.size(); i++)
      {
         e = e->BuildDESL();
         e = e->StartListL();

            TUUID u = QBtUuidToSymbianUuid (protocolList[i]);
            e = e->BuildUUIDL (u);

            if (u == TUUID (KRFCOMM) )
               e = e->BuildUintL(channel);

         e = e->EndListL();
       }

   e->EndListL();

   // set protocol list to the record
   iSdpDB.UpdateAttributeL(iRecord, KSdpAttrIdProtocolDescriptorList,
         *protocolDescriptorList);
   CleanupStack::PopAndDestroy(protocolDescriptorList);


   // add a name to the record
   TPtrC16 servName(service.getName().utf16());

   iSdpDB.UpdateAttributeL(iRecord,
         KSdpAttrIdBasePrimaryLanguage +
         KSdpAttrIdOffsetServiceName,
         servName);


   // add a description to the record
   TPtrC16 servDescr(service.getDescription().utf16());

   iSdpDB.UpdateAttributeL(iRecord,
         KSdpAttrIdBasePrimaryLanguage +
         KSdpAttrIdOffsetServiceDescription,
         servDescr);

   // set service available
   UpdateAvailability(ETrue);

   // notify
   QT_TRYCATCH_LEAVING (emit p_ptr->advertisingStarted(service) );


}