1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/Volume.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_system_volume_h__ 1.9 +#define mozilla_system_volume_h__ 1.10 + 1.11 +#include "VolumeCommand.h" 1.12 +#include "nsIVolume.h" 1.13 +#include "nsString.h" 1.14 +#include "mozilla/Observer.h" 1.15 +#include "nsISupportsImpl.h" 1.16 +#include "nsWhitespaceTokenizer.h" 1.17 + 1.18 +namespace mozilla { 1.19 +namespace system { 1.20 + 1.21 +/*************************************************************************** 1.22 +* 1.23 +* There is an instance of the Volume class for each volume reported 1.24 +* from vold. 1.25 +* 1.26 +* Each volume originates from the /system/etv/vold.fstab file. 1.27 +* 1.28 +***************************************************************************/ 1.29 + 1.30 +class Volume MOZ_FINAL 1.31 +{ 1.32 +public: 1.33 + NS_INLINE_DECL_REFCOUNTING(Volume) 1.34 + 1.35 + Volume(const nsCSubstring& aVolumeName); 1.36 + 1.37 + typedef long STATE; // States are now defined in nsIVolume.idl 1.38 + 1.39 + static const char* StateStr(STATE aState) { return NS_VolumeStateStr(aState); } 1.40 + const char* StateStr() const { return StateStr(mState); } 1.41 + STATE State() const { return mState; } 1.42 + 1.43 + const nsCString& Name() const { return mName; } 1.44 + const char* NameStr() const { return mName.get(); } 1.45 + 1.46 + // The mount point is the name of the directory where the volume is mounted. 1.47 + // (i.e. path that leads to the files stored on the volume). 1.48 + const nsCString& MountPoint() const { return mMountPoint; } 1.49 + 1.50 + int32_t MountGeneration() const { return mMountGeneration; } 1.51 + bool IsMountLocked() const { return mMountLocked; } 1.52 + bool MediaPresent() const { return mMediaPresent; } 1.53 + bool CanBeShared() const { return mCanBeShared; } 1.54 + bool CanBeFormatted() const { return CanBeShared(); } 1.55 + bool CanBeMounted() const { return CanBeShared(); } 1.56 + bool IsSharingEnabled() const { return mCanBeShared && mSharingEnabled; } 1.57 + bool IsFormatRequested() const { return CanBeFormatted() && mFormatRequested; } 1.58 + bool IsMountRequested() const { return CanBeMounted() && mMountRequested; } 1.59 + bool IsUnmountRequested() const { return CanBeMounted() && mUnmountRequested; } 1.60 + bool IsSharing() const { return mIsSharing; } 1.61 + bool IsFormatting() const { return mIsFormatting; } 1.62 + 1.63 + void SetSharingEnabled(bool aSharingEnabled); 1.64 + void SetFormatRequested(bool aFormatRequested); 1.65 + void SetMountRequested(bool aMountRequested); 1.66 + void SetUnmountRequested(bool aUnmountRequested); 1.67 + 1.68 + typedef mozilla::Observer<Volume *> EventObserver; 1.69 + typedef mozilla::ObserverList<Volume *> EventObserverList; 1.70 + 1.71 + // NOTE: that observers must live in the IOThread. 1.72 + static void RegisterObserver(EventObserver* aObserver); 1.73 + static void UnregisterObserver(EventObserver* aObserver); 1.74 + 1.75 +private: 1.76 + friend class AutoMounter; // Calls StartXxx 1.77 + friend class nsVolume; // Calls UpdateMountLock 1.78 + friend class VolumeManager; // Calls HandleVoldResponse 1.79 + friend class VolumeListCallback; // Calls SetMountPoint, SetState 1.80 + 1.81 + // The StartXxx functions will queue up a command to the VolumeManager. 1.82 + // You can queue up as many commands as you like, and aCallback will 1.83 + // be called as each one completes. 1.84 + void StartMount(VolumeResponseCallback* aCallback); 1.85 + void StartUnmount(VolumeResponseCallback* aCallback); 1.86 + void StartFormat(VolumeResponseCallback* aCallback); 1.87 + void StartShare(VolumeResponseCallback* aCallback); 1.88 + void StartUnshare(VolumeResponseCallback* aCallback); 1.89 + 1.90 + void SetIsSharing(bool aIsSharing); 1.91 + void SetIsFormatting(bool aIsFormatting); 1.92 + void SetState(STATE aNewState); 1.93 + void SetMediaPresent(bool aMediaPresent); 1.94 + void SetMountPoint(const nsCSubstring& aMountPoint); 1.95 + void StartCommand(VolumeCommand* aCommand); 1.96 + 1.97 + void HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer); 1.98 + 1.99 + static void UpdateMountLock(const nsACString& aVolumeName, 1.100 + const int32_t& aMountGeneration, 1.101 + const bool& aMountLocked); 1.102 + 1.103 + bool mMediaPresent; 1.104 + STATE mState; 1.105 + const nsCString mName; 1.106 + nsCString mMountPoint; 1.107 + int32_t mMountGeneration; 1.108 + bool mMountLocked; 1.109 + bool mSharingEnabled; 1.110 + bool mFormatRequested; 1.111 + bool mMountRequested; 1.112 + bool mUnmountRequested; 1.113 + bool mCanBeShared; 1.114 + bool mIsSharing; 1.115 + bool mIsFormatting; 1.116 + 1.117 + static EventObserverList mEventObserverList; 1.118 +}; 1.119 + 1.120 +} // system 1.121 +} // mozilla 1.122 + 1.123 +#endif // mozilla_system_volumemanager_h__