|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef mozilla_system_volume_h__ |
|
6 #define mozilla_system_volume_h__ |
|
7 |
|
8 #include "VolumeCommand.h" |
|
9 #include "nsIVolume.h" |
|
10 #include "nsString.h" |
|
11 #include "mozilla/Observer.h" |
|
12 #include "nsISupportsImpl.h" |
|
13 #include "nsWhitespaceTokenizer.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace system { |
|
17 |
|
18 /*************************************************************************** |
|
19 * |
|
20 * There is an instance of the Volume class for each volume reported |
|
21 * from vold. |
|
22 * |
|
23 * Each volume originates from the /system/etv/vold.fstab file. |
|
24 * |
|
25 ***************************************************************************/ |
|
26 |
|
27 class Volume MOZ_FINAL |
|
28 { |
|
29 public: |
|
30 NS_INLINE_DECL_REFCOUNTING(Volume) |
|
31 |
|
32 Volume(const nsCSubstring& aVolumeName); |
|
33 |
|
34 typedef long STATE; // States are now defined in nsIVolume.idl |
|
35 |
|
36 static const char* StateStr(STATE aState) { return NS_VolumeStateStr(aState); } |
|
37 const char* StateStr() const { return StateStr(mState); } |
|
38 STATE State() const { return mState; } |
|
39 |
|
40 const nsCString& Name() const { return mName; } |
|
41 const char* NameStr() const { return mName.get(); } |
|
42 |
|
43 // The mount point is the name of the directory where the volume is mounted. |
|
44 // (i.e. path that leads to the files stored on the volume). |
|
45 const nsCString& MountPoint() const { return mMountPoint; } |
|
46 |
|
47 int32_t MountGeneration() const { return mMountGeneration; } |
|
48 bool IsMountLocked() const { return mMountLocked; } |
|
49 bool MediaPresent() const { return mMediaPresent; } |
|
50 bool CanBeShared() const { return mCanBeShared; } |
|
51 bool CanBeFormatted() const { return CanBeShared(); } |
|
52 bool CanBeMounted() const { return CanBeShared(); } |
|
53 bool IsSharingEnabled() const { return mCanBeShared && mSharingEnabled; } |
|
54 bool IsFormatRequested() const { return CanBeFormatted() && mFormatRequested; } |
|
55 bool IsMountRequested() const { return CanBeMounted() && mMountRequested; } |
|
56 bool IsUnmountRequested() const { return CanBeMounted() && mUnmountRequested; } |
|
57 bool IsSharing() const { return mIsSharing; } |
|
58 bool IsFormatting() const { return mIsFormatting; } |
|
59 |
|
60 void SetSharingEnabled(bool aSharingEnabled); |
|
61 void SetFormatRequested(bool aFormatRequested); |
|
62 void SetMountRequested(bool aMountRequested); |
|
63 void SetUnmountRequested(bool aUnmountRequested); |
|
64 |
|
65 typedef mozilla::Observer<Volume *> EventObserver; |
|
66 typedef mozilla::ObserverList<Volume *> EventObserverList; |
|
67 |
|
68 // NOTE: that observers must live in the IOThread. |
|
69 static void RegisterObserver(EventObserver* aObserver); |
|
70 static void UnregisterObserver(EventObserver* aObserver); |
|
71 |
|
72 private: |
|
73 friend class AutoMounter; // Calls StartXxx |
|
74 friend class nsVolume; // Calls UpdateMountLock |
|
75 friend class VolumeManager; // Calls HandleVoldResponse |
|
76 friend class VolumeListCallback; // Calls SetMountPoint, SetState |
|
77 |
|
78 // The StartXxx functions will queue up a command to the VolumeManager. |
|
79 // You can queue up as many commands as you like, and aCallback will |
|
80 // be called as each one completes. |
|
81 void StartMount(VolumeResponseCallback* aCallback); |
|
82 void StartUnmount(VolumeResponseCallback* aCallback); |
|
83 void StartFormat(VolumeResponseCallback* aCallback); |
|
84 void StartShare(VolumeResponseCallback* aCallback); |
|
85 void StartUnshare(VolumeResponseCallback* aCallback); |
|
86 |
|
87 void SetIsSharing(bool aIsSharing); |
|
88 void SetIsFormatting(bool aIsFormatting); |
|
89 void SetState(STATE aNewState); |
|
90 void SetMediaPresent(bool aMediaPresent); |
|
91 void SetMountPoint(const nsCSubstring& aMountPoint); |
|
92 void StartCommand(VolumeCommand* aCommand); |
|
93 |
|
94 void HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer); |
|
95 |
|
96 static void UpdateMountLock(const nsACString& aVolumeName, |
|
97 const int32_t& aMountGeneration, |
|
98 const bool& aMountLocked); |
|
99 |
|
100 bool mMediaPresent; |
|
101 STATE mState; |
|
102 const nsCString mName; |
|
103 nsCString mMountPoint; |
|
104 int32_t mMountGeneration; |
|
105 bool mMountLocked; |
|
106 bool mSharingEnabled; |
|
107 bool mFormatRequested; |
|
108 bool mMountRequested; |
|
109 bool mUnmountRequested; |
|
110 bool mCanBeShared; |
|
111 bool mIsSharing; |
|
112 bool mIsFormatting; |
|
113 |
|
114 static EventObserverList mEventObserverList; |
|
115 }; |
|
116 |
|
117 } // system |
|
118 } // mozilla |
|
119 |
|
120 #endif // mozilla_system_volumemanager_h__ |