summaryrefslogtreecommitdiffstats
path: root/BrowserSource/Proxy/ScopeGuard.h
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2023-07-03 18:44:43 -0700
committeryum <yum.food.vr@gmail.com>2023-07-03 19:36:13 -0700
commit76ae7c28ea6224b2c919122d5dc71bcc00a0ecaa (patch)
tree9723fd02715d747cfc439d1f66d36821a56069e9 /BrowserSource/Proxy/ScopeGuard.h
parent7888ccc96d001512dd3bdc01f299856e86c876f5 (diff)
Begin work on proxy server
Create a simple server with 3 endpoints: * /create_session: Create a session and return its identifier. * /set_transcript: Update a session's transcript. * /get_transcript: Fetch a session's transcript. Right now the session ID provides authentication *and* authorization. There is no public/private ID so you have to trust whoever you share your ID with. IDs are long and generated by the server, so it should be somewhat secure against low-effort hacking. Other updates: * Drop whisper_requirements.txt - no longer needed. * Vendor curl to make it easier to interact with the server. TODO: * Fuzz test the server.
Diffstat (limited to 'BrowserSource/Proxy/ScopeGuard.h')
-rw-r--r--BrowserSource/Proxy/ScopeGuard.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/BrowserSource/Proxy/ScopeGuard.h b/BrowserSource/Proxy/ScopeGuard.h
new file mode 100644
index 0000000..61bb64d
--- /dev/null
+++ b/BrowserSource/Proxy/ScopeGuard.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <functional>
+#include <utility>
+
+class ScopeGuard {
+public:
+ ScopeGuard(std::function<void()>&& cb) : cb_(std::move(cb)), active_(true) {}
+ ~ScopeGuard() {
+ Invoke();
+ }
+
+ ScopeGuard() = delete;
+ ScopeGuard(ScopeGuard&) = delete;
+ ScopeGuard(const ScopeGuard&) = delete;
+ ScopeGuard(ScopeGuard&&) = delete;
+ ScopeGuard& operator=(ScopeGuard&) = delete;
+ ScopeGuard& operator=(const ScopeGuard&) = delete;
+
+ void Cancel() { active_ = false; }
+
+ void Invoke() {
+ if (active_) {
+ cb_();
+ active_ = false;
+ }
+ }
+
+private:
+ const std::function<void()> cb_;
+ bool active_;
+};