예제 #1
0
/* void connect (); */
NS_IMETHODIMP sbMockDevice::Connect()
{
  NS_ENSURE_STATE(!mIsConnected);
  nsresult rv;

  // Invoke the super-class.
  rv = sbBaseDevice::Connect();
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<sbIDeviceContent> deviceContent;
  rv = GetContent(getter_AddRefs(deviceContent));
  NS_ENSURE_SUCCESS(rv, rv);

  // Start the request processing.
  rv = ReqProcessingStart();
  NS_ENSURE_SUCCESS(rv, rv);

  mIsConnected = PR_TRUE;
  return NS_OK;
}
nsresult
sbIPDDevice::ConnectInternal()
{
  nsresult rv;

  // Do nothing if device is already connected.  If the device is not connected,
  // nothing should be accessing the "connect lock" fields.
  {
    sbAutoReadLock autoConnectLock(mConnectLock);
    if (mConnected)
      return NS_OK;
  }

  // Invoke the super-class.
  rv = sbBaseDevice::Connect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the device properties.
  nsCOMPtr<nsIPropertyBag2> properties = do_QueryInterface(mCreationProperties,
                                                           &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the device mount path.
  rv = properties->GetPropertyAsAString(NS_LITERAL_STRING("MountPath"),
                                        mMountPath);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the Firewire GUID.
  rv = properties->GetPropertyAsAString(NS_LITERAL_STRING("FirewireGUID"),
                                        mFirewireGUID);
  if (NS_SUCCEEDED(rv)) {
    FIELD_LOG
      (("Connect %s\n", NS_LossyConvertUTF16toASCII(mFirewireGUID).get()));
  } else {
    FIELD_LOG(("Connect could not get iPod Firewire GUID.\n"));
  }

  // Connect the device capabilities.
  rv = CapabilitiesConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the iPod database.
  rv = DBConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the iPod preference services.
  rv = PrefConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the Songbird device library.
  rv = LibraryConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Connect the FairPlay services.
  rv = FPConnect();
  NS_ENSURE_SUCCESS(rv, rv);

  // Mark the device as connected.  After this, "connect lock" fields may be
  // used.
  {
    sbAutoWriteLock autoConnectLock(mConnectLock);
    mConnected = PR_TRUE;
  }

  // Start the iPod request processing.
  rv = ReqProcessingStart();
  NS_ENSURE_SUCCESS(rv, rv);

  // Mount the device.
  //XXXeps Do in DBConnect
  rv = PushRequest(TransferRequest::REQUEST_MOUNT, nsnull, mDeviceLibrary);
  NS_ENSURE_SUCCESS(rv, rv);

  // Set up the iPod for the first time if needed
  rv = SetUpIfNeeded();
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}