michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_system_volume_h__ michael@0: #define mozilla_system_volume_h__ michael@0: michael@0: #include "VolumeCommand.h" michael@0: #include "nsIVolume.h" michael@0: #include "nsString.h" michael@0: #include "mozilla/Observer.h" michael@0: #include "nsISupportsImpl.h" michael@0: #include "nsWhitespaceTokenizer.h" michael@0: michael@0: namespace mozilla { michael@0: namespace system { michael@0: michael@0: /*************************************************************************** michael@0: * michael@0: * There is an instance of the Volume class for each volume reported michael@0: * from vold. michael@0: * michael@0: * Each volume originates from the /system/etv/vold.fstab file. michael@0: * michael@0: ***************************************************************************/ michael@0: michael@0: class Volume MOZ_FINAL michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_REFCOUNTING(Volume) michael@0: michael@0: Volume(const nsCSubstring& aVolumeName); michael@0: michael@0: typedef long STATE; // States are now defined in nsIVolume.idl michael@0: michael@0: static const char* StateStr(STATE aState) { return NS_VolumeStateStr(aState); } michael@0: const char* StateStr() const { return StateStr(mState); } michael@0: STATE State() const { return mState; } michael@0: michael@0: const nsCString& Name() const { return mName; } michael@0: const char* NameStr() const { return mName.get(); } michael@0: michael@0: // The mount point is the name of the directory where the volume is mounted. michael@0: // (i.e. path that leads to the files stored on the volume). michael@0: const nsCString& MountPoint() const { return mMountPoint; } michael@0: michael@0: int32_t MountGeneration() const { return mMountGeneration; } michael@0: bool IsMountLocked() const { return mMountLocked; } michael@0: bool MediaPresent() const { return mMediaPresent; } michael@0: bool CanBeShared() const { return mCanBeShared; } michael@0: bool CanBeFormatted() const { return CanBeShared(); } michael@0: bool CanBeMounted() const { return CanBeShared(); } michael@0: bool IsSharingEnabled() const { return mCanBeShared && mSharingEnabled; } michael@0: bool IsFormatRequested() const { return CanBeFormatted() && mFormatRequested; } michael@0: bool IsMountRequested() const { return CanBeMounted() && mMountRequested; } michael@0: bool IsUnmountRequested() const { return CanBeMounted() && mUnmountRequested; } michael@0: bool IsSharing() const { return mIsSharing; } michael@0: bool IsFormatting() const { return mIsFormatting; } michael@0: michael@0: void SetSharingEnabled(bool aSharingEnabled); michael@0: void SetFormatRequested(bool aFormatRequested); michael@0: void SetMountRequested(bool aMountRequested); michael@0: void SetUnmountRequested(bool aUnmountRequested); michael@0: michael@0: typedef mozilla::Observer EventObserver; michael@0: typedef mozilla::ObserverList EventObserverList; michael@0: michael@0: // NOTE: that observers must live in the IOThread. michael@0: static void RegisterObserver(EventObserver* aObserver); michael@0: static void UnregisterObserver(EventObserver* aObserver); michael@0: michael@0: private: michael@0: friend class AutoMounter; // Calls StartXxx michael@0: friend class nsVolume; // Calls UpdateMountLock michael@0: friend class VolumeManager; // Calls HandleVoldResponse michael@0: friend class VolumeListCallback; // Calls SetMountPoint, SetState michael@0: michael@0: // The StartXxx functions will queue up a command to the VolumeManager. michael@0: // You can queue up as many commands as you like, and aCallback will michael@0: // be called as each one completes. michael@0: void StartMount(VolumeResponseCallback* aCallback); michael@0: void StartUnmount(VolumeResponseCallback* aCallback); michael@0: void StartFormat(VolumeResponseCallback* aCallback); michael@0: void StartShare(VolumeResponseCallback* aCallback); michael@0: void StartUnshare(VolumeResponseCallback* aCallback); michael@0: michael@0: void SetIsSharing(bool aIsSharing); michael@0: void SetIsFormatting(bool aIsFormatting); michael@0: void SetState(STATE aNewState); michael@0: void SetMediaPresent(bool aMediaPresent); michael@0: void SetMountPoint(const nsCSubstring& aMountPoint); michael@0: void StartCommand(VolumeCommand* aCommand); michael@0: michael@0: void HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer); michael@0: michael@0: static void UpdateMountLock(const nsACString& aVolumeName, michael@0: const int32_t& aMountGeneration, michael@0: const bool& aMountLocked); michael@0: michael@0: bool mMediaPresent; michael@0: STATE mState; michael@0: const nsCString mName; michael@0: nsCString mMountPoint; michael@0: int32_t mMountGeneration; michael@0: bool mMountLocked; michael@0: bool mSharingEnabled; michael@0: bool mFormatRequested; michael@0: bool mMountRequested; michael@0: bool mUnmountRequested; michael@0: bool mCanBeShared; michael@0: bool mIsSharing; michael@0: bool mIsFormatting; michael@0: michael@0: static EventObserverList mEventObserverList; michael@0: }; michael@0: michael@0: } // system michael@0: } // mozilla michael@0: michael@0: #endif // mozilla_system_volumemanager_h__