aboutsummaryrefslogtreecommitdiffstats
path: root/voldclient.h
diff options
context:
space:
mode:
authorTom Marshall <tdm@cyngn.com>2014-11-24 16:02:04 -0800
committerTom Marshall <tdm@cyngn.com>2015-11-25 15:34:31 -0800
commit3f092f7778ed608d454df4c3dc3b3f7cb4afde3b (patch)
tree326444388672880e6ab3bf72f434e13e1d80c25e /voldclient.h
parent383f723fdb0ebba5078ccc2aabf87f0516215bf9 (diff)
downloadbootable_recovery-3f092f7778ed608d454df4c3dc3b3f7cb4afde3b.zip
bootable_recovery-3f092f7778ed608d454df4c3dc3b3f7cb4afde3b.tar.gz
bootable_recovery-3f092f7778ed608d454df4c3dc3b3f7cb4afde3b.tar.bz2
recovery: Awakening of MiniVold
A minimal vold client for recovery. Change-Id: Id25d955dc1861a910e5f5fc27d9a19e245d66833
Diffstat (limited to 'voldclient.h')
-rw-r--r--voldclient.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/voldclient.h b/voldclient.h
new file mode 100644
index 0000000..c5f568e
--- /dev/null
+++ b/voldclient.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _VOLD_CLIENT_H
+#define _VOLD_CLIENT_H
+
+#include <sys/types.h>
+#include <pthread.h>
+
+#include <string>
+#include <vector>
+
+class VoldWatcher {
+public:
+ virtual ~VoldWatcher(void) {}
+ virtual void onVolumeChanged(void) = 0;
+};
+
+class VolumeInfo {
+public:
+ std::string mId;
+ std::string mLabel;
+ std::string mPath;
+ std::string mInternalPath;
+ int mState;
+};
+
+class VoldClient
+{
+public:
+ VoldClient(VoldWatcher* watcher = nullptr);
+
+ void start(void);
+ void stop(void);
+
+ std::vector<VolumeInfo> getVolumes(void) { return mVolumes; }
+ VolumeInfo getVolume(const std::string& id);
+
+ bool isEmulatedStorage(void) { return mEmulatedStorage; }
+
+ bool reset(void);
+ bool mountAll(void);
+ bool unmountAll(void);
+
+ bool volumeMount(const std::string& id);
+ bool volumeUnmount(const std::string& id, bool detach = false);
+ bool volumeFormat(const std::string& id);
+ bool volumeAvailable(const std::string& id);
+
+private:
+ void resetVolumeState(void);
+
+ VolumeInfo* getVolumeLocked(const std::string& id);
+ bool sendCommand(unsigned int len, const char** command, bool wait = true);
+
+ void handleCommandOkay(void);
+ void handleVolumeCreated(const std::string& id, const std::string& type,
+ const std::string& disk, const std::string& guid);
+ void handleVolumeStateChanged(const std::string& id, const std::string& state);
+ void handleVolumeFsLabelChanged(const std::string& id, const std::string& label);
+ void handleVolumePathChanged(const std::string& id, const std::string& path);
+ void handleVolumeInternalPathChanged(const std::string& id, const std::string& path);
+ void handleVolumeDestroyed(const std::string& id);
+
+ void dispatch(const std::string& line);
+
+public:
+ void run(void); // INTERNAL
+
+private:
+ bool mRunning;
+ int mSock;
+ pthread_t mThread;
+ pthread_mutex_t mSockMutex;
+ pthread_cond_t mSockCond;
+ unsigned int mInFlight;
+ unsigned int mResult;
+ VoldWatcher* mWatcher;
+ pthread_rwlock_t mVolumeLock;
+ bool mVolumeChanged;
+ bool mEmulatedStorage;
+ std::vector<VolumeInfo> mVolumes;
+};
+
+extern VoldClient* vdc;
+
+#endif
+