yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
rom_version_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_NET_ROM_VERSION_MANAGER_H_
2#define YAZE_APP_NET_ROM_VERSION_MANAGER_H_
3
4#include <map>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "app/rom.h"
12
13#ifdef YAZE_WITH_JSON
14#include "nlohmann/json.hpp"
15#endif
16
17namespace yaze {
18
19namespace net {
20
26 std::string snapshot_id;
27 std::string description;
28 int64_t timestamp;
29 std::string rom_hash;
30 std::vector<uint8_t> rom_data;
32
33 // Metadata
34 std::string creator;
35 bool is_checkpoint; // Manual checkpoint vs auto-backup
36 bool is_safe_point; // Marked as "known good" by host
37
38#ifdef YAZE_WITH_JSON
39 nlohmann::json metadata; // Custom metadata (proposals applied, etc.)
40#endif
41};
42
48 std::string from_snapshot_id;
49 std::string to_snapshot_id;
50 std::vector<std::pair<size_t, std::vector<uint8_t>>> changes; // offset, data
52 std::vector<std::string> proposals_applied; // IDs of proposals in this diff
53};
54
67 public:
68 struct Config {
69 bool enable_auto_backup = true;
70 int auto_backup_interval_seconds = 300; // 5 minutes
71 size_t max_snapshots = 50;
72 size_t max_storage_mb = 500; // 500MB max for all snapshots
73 bool compress_snapshots = true;
75 };
76
77 explicit RomVersionManager(Rom* rom);
79
83 absl::Status Initialize(const Config& config);
84
88 absl::StatusOr<std::string> CreateSnapshot(
89 const std::string& description,
90 const std::string& creator,
91 bool is_checkpoint = false);
92
96 absl::Status RestoreSnapshot(const std::string& snapshot_id);
97
101 absl::Status MarkAsSafePoint(const std::string& snapshot_id);
102
106 std::vector<RomSnapshot> GetSnapshots(bool safe_points_only = false) const;
107
111 absl::StatusOr<RomSnapshot> GetSnapshot(const std::string& snapshot_id) const;
112
116 absl::Status DeleteSnapshot(const std::string& snapshot_id);
117
121 absl::StatusOr<VersionDiff> GenerateDiff(
122 const std::string& from_id,
123 const std::string& to_id) const;
124
128 absl::StatusOr<bool> DetectCorruption();
129
133 absl::Status AutoRecover();
134
138 absl::Status ExportSnapshot(
139 const std::string& snapshot_id,
140 const std::string& filepath);
141
145 absl::Status ImportSnapshot(const std::string& filepath);
146
150 std::string GetCurrentHash() const;
151
155 absl::Status CleanupOldSnapshots();
156
169 Stats GetStats() const;
170
171 private:
174 std::map<std::string, RomSnapshot> snapshots_;
175 std::string last_known_hash_;
177
178 // Helper functions
179 std::string ComputeRomHash() const;
180 std::vector<uint8_t> CompressData(const std::vector<uint8_t>& data) const;
181 std::vector<uint8_t> DecompressData(const std::vector<uint8_t>& compressed) const;
182 absl::Status ValidateRomIntegrity() const;
183 size_t GetTotalStorageUsed() const;
185};
186
198 public:
199 enum class ApprovalMode {
200 kHostOnly, // Only host can approve
201 kMajorityVote, // Majority of participants must approve
202 kUnanimous, // All participants must approve
203 kAutoApprove // No approval needed (dangerous!)
204 };
205
207 std::string proposal_id;
208 std::string status; // "pending", "approved", "rejected", "applied"
209 std::map<std::string, bool> votes; // username -> approved
210 int64_t created_at;
211 int64_t decided_at;
212 std::string snapshot_before; // Snapshot ID before applying
213 std::string snapshot_after; // Snapshot ID after applying
214 };
215
216 explicit ProposalApprovalManager(RomVersionManager* version_mgr);
217
221 void SetApprovalMode(ApprovalMode mode);
222
226 void SetHost(const std::string& host_username);
227
231 absl::Status SubmitProposal(
232 const std::string& proposal_id,
233 const std::string& sender,
234 const std::string& description,
235 const nlohmann::json& proposal_data);
236
240 absl::Status VoteOnProposal(
241 const std::string& proposal_id,
242 const std::string& username,
243 bool approved);
244
248 absl::Status ApplyProposal(
249 const std::string& proposal_id,
250 Rom* rom);
251
255 absl::Status RejectProposal(const std::string& proposal_id);
256
260 absl::StatusOr<ApprovalStatus> GetProposalStatus(
261 const std::string& proposal_id) const;
262
266 std::vector<ApprovalStatus> GetPendingProposals() const;
267
271 bool IsProposalApproved(const std::string& proposal_id) const;
272
276 std::vector<ApprovalStatus> GetAuditLog() const;
277
278 private:
281 std::string host_username_;
282 std::map<std::string, ApprovalStatus> proposals_;
283 std::vector<std::string> participants_;
284
285 bool CheckApprovalThreshold(const ApprovalStatus& status) const;
286};
287
288} // namespace net
289
290} // namespace yaze
291
292#endif // YAZE_APP_NET_ROM_VERSION_MANAGER_H_
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
Manages proposal approval workflow for collaborative sessions.
std::vector< std::string > participants_
void SetHost(const std::string &host_username)
absl::Status RejectProposal(const std::string &proposal_id)
absl::StatusOr< ApprovalStatus > GetProposalStatus(const std::string &proposal_id) const
std::vector< ApprovalStatus > GetAuditLog() const
absl::Status VoteOnProposal(const std::string &proposal_id, const std::string &username, bool approved)
bool IsProposalApproved(const std::string &proposal_id) const
absl::Status SubmitProposal(const std::string &proposal_id, const std::string &sender, const std::string &description, const nlohmann::json &proposal_data)
std::vector< ApprovalStatus > GetPendingProposals() const
bool CheckApprovalThreshold(const ApprovalStatus &status) const
absl::Status ApplyProposal(const std::string &proposal_id, Rom *rom)
std::map< std::string, ApprovalStatus > proposals_
Manages ROM versioning, snapshots, and rollback capabilities.
absl::StatusOr< VersionDiff > GenerateDiff(const std::string &from_id, const std::string &to_id) const
std::vector< uint8_t > DecompressData(const std::vector< uint8_t > &compressed) const
absl::StatusOr< std::string > CreateSnapshot(const std::string &description, const std::string &creator, bool is_checkpoint=false)
absl::StatusOr< RomSnapshot > GetSnapshot(const std::string &snapshot_id) const
absl::Status ExportSnapshot(const std::string &snapshot_id, const std::string &filepath)
std::map< std::string, RomSnapshot > snapshots_
absl::Status ValidateRomIntegrity() const
absl::Status ImportSnapshot(const std::string &filepath)
absl::Status Initialize(const Config &config)
absl::StatusOr< bool > DetectCorruption()
absl::Status RestoreSnapshot(const std::string &snapshot_id)
absl::Status MarkAsSafePoint(const std::string &snapshot_id)
std::vector< uint8_t > CompressData(const std::vector< uint8_t > &data) const
absl::Status DeleteSnapshot(const std::string &snapshot_id)
std::vector< RomSnapshot > GetSnapshots(bool safe_points_only=false) const
Main namespace for the application.
Represents a versioned snapshot of ROM state.
std::vector< uint8_t > rom_data
Represents differences between two ROM versions.
std::vector< std::pair< size_t, std::vector< uint8_t > > > changes
std::vector< std::string > proposals_applied