Exemplo n.º 1
0
/*
 * Handle the response from calling discovery stat
 */
void DmxTriWidgetImpl::HandleDiscoverStatResponse(uint8_t return_code,
        const uint8_t *data,
        unsigned int length) {
    if (return_code == EC_NO_ERROR || return_code == EC_RESPONSE_UNEXPECTED) {
        if (return_code == EC_RESPONSE_UNEXPECTED)
            OLA_INFO << "Got an unexpected RDM response during discovery";

        if (length < 1) {
            // don't cancel the timer, try again after RDM_STATUS_INTERVAL_MS
            OLA_WARN << "DiscoStat command too short, was " << length;
            return;
        }

        if (data[1] == 0) {
            OLA_DEBUG << "Discovery process has completed, " <<
                      static_cast<int>(data[0]) << " devices found";
            StopDiscovery();
            m_uid_count = data[0];
            m_uid_index_map.clear();
            if (m_uid_count) {
                FetchNextUID();
            } else {
                RDMDiscoveryCallback *callback = m_discovery_callback;
                m_discovery_callback= NULL;
                RunDiscoveryCallback(callback);
            }
        }
    } else {
        // These are all fatal
        switch (return_code) {
        case EC_RESPONSE_MUTE:
            OLA_WARN << "Failed to mute device, aborting discovery";
            break;
        case EC_RESPONSE_DISCOVERY:
            OLA_WARN <<
                     "Duplicated or erroneous device detected, aborting discovery";
            break;
        default:
            OLA_WARN << "DMX_TRI discovery returned error " <<
                     static_cast<int>(return_code);
            break;
        }
        // clear out the old map
        m_uid_index_map.clear();
        StopDiscovery();
        RDMDiscoveryCallback *callback = m_discovery_callback;
        m_discovery_callback = NULL;
        RunDiscoveryCallback(callback);
    }
}
// nsIObserver
NS_IMETHODIMP
MulticastDNSDeviceProvider::Observe(nsISupports* aSubject,
                                    const char* aTopic,
                                    const char16_t* aData)
{
  MOZ_ASSERT(NS_IsMainThread());

  NS_ConvertUTF16toUTF8 data(aData);
  LOG_I("Observe: topic = %s, data = %s", aTopic, data.get());

  if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
    if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERY)) {
      OnDiscoveryChanged(Preferences::GetBool(PREF_PRESENTATION_DISCOVERY));
    } else if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS)) {
      OnDiscoveryTimeoutChanged(Preferences::GetUint(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS));
    } else if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERABLE)) {
      OnDiscoverableChanged(Preferences::GetBool(PREF_PRESENTATION_DISCOVERABLE));
    } else if (data.EqualsLiteral(PREF_PRESENTATION_DEVICE_NAME)) {
      OnServiceNameChanged(Preferences::GetCString(PREF_PRESENTATION_DEVICE_NAME));
    }
  } else if (!strcmp(aTopic, NS_TIMER_CALLBACK_TOPIC)) {
    StopDiscovery(NS_OK);
  }

  return NS_OK;
}
NS_IMETHODIMP
MulticastDNSDeviceProvider::ForceDiscovery()
{
  LOG_I("ForceDiscovery (%d)", mDiscoveryEnabled);
  MOZ_ASSERT(NS_IsMainThread());

  if (!mDiscoveryEnabled) {
    return NS_OK;
  }

  MOZ_ASSERT(mDiscoveryTimer);
  MOZ_ASSERT(mMulticastDNS);

  // if it's already discovering, extend existing discovery timeout.
  if (mIsDiscovering) {
    unused << mDiscoveryTimer->Cancel();

    NS_WARN_IF(NS_FAILED(mDiscoveryTimer->Init(this,
                                               mDiscveryTimeoutMs,
                                               nsITimer::TYPE_ONE_SHOT)));
    return NS_OK;
  }

  StopDiscovery(NS_OK);

  nsresult rv;
  if (NS_WARN_IF(NS_FAILED(rv = mMulticastDNS->StartDiscovery(
      NS_LITERAL_CSTRING(SERVICE_TYPE),
      mWrappedListener,
      getter_AddRefs(mDiscoveryRequest))))) {
    return rv;
  }

  return NS_OK;
}
nsresult
MulticastDNSDeviceProvider::Uninit()
{
  MOZ_ASSERT(NS_IsMainThread());

  if (!mInitialized) {
    return NS_OK;
  }

  ClearDevices();

  Preferences::RemoveObservers(this, kObservedPrefs);

  StopDiscovery(NS_OK);
  UnregisterService(NS_OK);

  mMulticastDNS = nullptr;

  if (mWrappedListener) {
    mWrappedListener->SetListener(nullptr);
    mWrappedListener = nullptr;
  }

  mInitialized = false;
  return NS_OK;
}
NS_IMETHODIMP
nsDNSServiceDiscovery::StartDiscovery(const nsACString& aServiceType,
                                      nsIDNSServiceDiscoveryListener* aListener,
                                      nsICancelable** aRetVal)
{
  MOZ_ASSERT(aRetVal);

  nsresult rv;
  if (NS_WARN_IF(NS_FAILED(rv = StopDiscovery(aListener)))) {
    return rv;
  }

  nsRefPtr<BrowseOperator> browserOp = new BrowseOperator(aServiceType,
                                                          aListener);
  if (NS_WARN_IF(NS_FAILED(rv = browserOp->Start()))) {
    return rv;
  }

  mDiscoveryMap.Put(aListener, browserOp);

  nsCOMPtr<nsICancelable> req = new DiscoveryRequest(this, aListener);
  req.forget(aRetVal);

  return NS_OK;
}
nsresult
MulticastDNSDeviceProvider::OnDiscoveryChanged(bool aEnabled)
{
  LOG_I("DiscoveryEnabled = %d\n", aEnabled);
  MOZ_ASSERT(NS_IsMainThread());

  mDiscoveryEnabled = aEnabled;

  if (mDiscoveryEnabled) {
    return ForceDiscovery();
  }

  return StopDiscovery(NS_OK);
}
Exemplo n.º 7
0
/*
 * Handle the response from calling DiscoAuto
 */
void DmxTriWidgetImpl::HandleDiscoveryAutoResponse(uint8_t return_code,
        const uint8_t *data,
        unsigned int length) {
    if (return_code != EC_NO_ERROR) {
        if (return_code == EC_UNKNOWN_COMMAND)
            OLA_INFO << "This DMX-TRI doesn't support RDM";
        else
            OLA_WARN << "DMX_TRI discovery returned error " <<
                     static_cast<int>(return_code);
        StopDiscovery();
    }
    (void) data;
    (void) length;
}
// ---------------------------------------------------------
// QBtDeviceDiscovererPrivate::~QBtDeviceDiscovererPrivate()
// Destructor
// ---------------------------------------------------------
//
QBtDeviceDiscovererPrivate::~QBtDeviceDiscovererPrivate()
{
	StopDiscovery();

	BtSdkCallbackStru cb;
	cb.type = BTSDK_INQUIRY_COMPLETE_IND;
	cb.func = NULL;	
	Btsdk_RegisterCallback4ThirdParty(&cb);

	cb.type = BTSDK_INQUIRY_RESULT_IND;
	cb.func = NULL;
	Btsdk_RegisterCallback4ThirdParty(&cb);

	Btsdk_RegisterGetStatusInfoCB4ThirdParty(NULL);

	QBtAuxFunctions::DeinitBthSdk();
}