2012-05-24 21:03:07 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_system_volume_h__
|
|
|
|
#define mozilla_system_volume_h__
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "VolumeCommand.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "nsIVolume.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "nsString.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "mozilla/Observer.h"
|
2012-05-24 21:03:07 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2012-05-24 21:03:07 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace system {
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* There is an instance of the Volume class for each volume reported
|
|
|
|
* from vold.
|
|
|
|
*
|
|
|
|
* Each volume originates from the /system/etv/vold.fstab file.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
class Volume : public RefCounted<Volume>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Volume(const nsCSubstring &aVolumeName);
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
typedef long STATE; // States are now defined in nsIVolume.idl
|
|
|
|
|
|
|
|
static const char *StateStr(STATE aState) { return NS_VolumeStateStr(aState); }
|
2012-05-24 21:03:07 -07:00
|
|
|
const char *StateStr() const { return StateStr(mState); }
|
|
|
|
STATE State() const { return mState; }
|
|
|
|
|
|
|
|
const nsCString &Name() const { return mName; }
|
|
|
|
const char *NameStr() const { return mName.get(); }
|
|
|
|
|
|
|
|
// The mount point is the name of the directory where the volume is mounted.
|
|
|
|
// (i.e. path that leads to the files stored on the volume).
|
|
|
|
const nsCString &MountPoint() const { return mMountPoint; }
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
bool MediaPresent() const { return mMediaPresent; }
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
typedef mozilla::Observer<Volume *> EventObserver;
|
|
|
|
typedef mozilla::ObserverList<Volume *> EventObserverList;
|
|
|
|
|
|
|
|
// NOTE: that observers must live in the IOThread.
|
2012-07-16 09:38:18 -07:00
|
|
|
static void RegisterObserver(EventObserver *aObserver);
|
|
|
|
static void UnregisterObserver(EventObserver *aObserver);
|
2012-07-16 09:38:18 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class AutoMounter; // Calls StartXxx
|
2012-07-16 09:38:18 -07:00
|
|
|
friend class VolumeManager; // Calls HandleVoldResponse
|
2012-07-16 09:38:18 -07:00
|
|
|
friend class VolumeListCallback; // Calls SetMountPoint, SetState
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
// The StartXxx functions will queue up a command to the VolumeManager.
|
|
|
|
// You can queue up as many commands as you like, and aCallback will
|
|
|
|
// be called as each one completes.
|
|
|
|
void StartMount(VolumeResponseCallback *aCallback);
|
|
|
|
void StartUnmount(VolumeResponseCallback *aCallback);
|
|
|
|
void StartShare(VolumeResponseCallback *aCallback);
|
|
|
|
void StartUnshare(VolumeResponseCallback *aCallback);
|
|
|
|
|
|
|
|
void SetState(STATE aNewState);
|
2012-07-16 09:38:18 -07:00
|
|
|
void SetMediaPresent(bool aMediaPresent);
|
2012-05-24 21:03:07 -07:00
|
|
|
void SetMountPoint(const nsCSubstring &aMountPoint);
|
|
|
|
void StartCommand(VolumeCommand *aCommand);
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
void HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer &aTokenizer);
|
|
|
|
|
|
|
|
bool mMediaPresent;
|
2012-05-24 21:03:07 -07:00
|
|
|
STATE mState;
|
|
|
|
const nsCString mName;
|
|
|
|
nsCString mMountPoint;
|
2012-07-16 09:38:18 -07:00
|
|
|
|
|
|
|
static EventObserverList mEventObserverList;
|
2012-05-24 21:03:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // system
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_system_volumemanager_h__
|