yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
collaboration_service.h
Go to the documentation of this file.
1#ifndef YAZE_APP_NET_COLLABORATION_SERVICE_H_
2#define YAZE_APP_NET_COLLABORATION_SERVICE_H_
3
4#include <memory>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
11#include "app/rom.h"
12
13namespace yaze {
14
15namespace net {
16
33 public:
34 struct Config {
35 bool auto_sync_enabled = true;
36 int sync_interval_ms = 5000; // 5 seconds
39 };
40
41 explicit CollaborationService(Rom* rom);
43
47 absl::Status Initialize(
48 const Config& config,
49 RomVersionManager* version_mgr,
50 ProposalApprovalManager* approval_mgr);
51
55 absl::Status Connect(const std::string& host, int port = 8765);
56
60 void Disconnect();
61
65 absl::Status HostSession(
66 const std::string& session_name,
67 const std::string& username,
68 bool ai_enabled = true);
69
73 absl::Status JoinSession(
74 const std::string& session_code,
75 const std::string& username);
76
80 absl::Status LeaveSession();
81
85 absl::Status SubmitChangesAsProposal(
86 const std::string& description,
87 const std::string& username);
88
92 absl::Status ApplyRomSync(
93 const std::string& diff_data,
94 const std::string& rom_hash,
95 const std::string& sender);
96
100 absl::Status HandleIncomingProposal(
101 const std::string& proposal_id,
102 const nlohmann::json& proposal_data,
103 const std::string& sender);
104
108 absl::Status VoteOnProposal(
109 const std::string& proposal_id,
110 bool approved,
111 const std::string& username);
112
116 absl::Status ApplyApprovedProposal(const std::string& proposal_id);
117
121 bool IsConnected() const;
122
126 absl::StatusOr<SessionInfo> GetSessionInfo() const;
127
131 WebSocketClient* GetClient() { return client_.get(); }
132
136 void SetAutoSync(bool enabled);
137
138 private:
142 std::unique_ptr<WebSocketClient> client_;
144
145 // Sync state
146 std::string last_sync_hash_;
148
149 // Callbacks for network events
150 void OnRomSyncReceived(const nlohmann::json& payload);
151 void OnProposalReceived(const nlohmann::json& payload);
152 void OnProposalUpdated(const nlohmann::json& payload);
153 void OnParticipantJoined(const nlohmann::json& payload);
154 void OnParticipantLeft(const nlohmann::json& payload);
155
156 // Helper functions
157 std::string GenerateDiff(const std::string& from_hash, const std::string& to_hash);
158 absl::Status ApplyDiff(const std::string& diff_data);
159 bool ShouldAutoSync();
160};
161
162} // namespace net
163
164} // namespace yaze
165
166#endif // YAZE_APP_NET_COLLABORATION_SERVICE_H_
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
High-level service integrating version management with networking.
std::unique_ptr< WebSocketClient > client_
absl::Status ApplyApprovedProposal(const std::string &proposal_id)
void OnProposalUpdated(const nlohmann::json &payload)
absl::Status VoteOnProposal(const std::string &proposal_id, bool approved, const std::string &username)
absl::Status HandleIncomingProposal(const std::string &proposal_id, const nlohmann::json &proposal_data, const std::string &sender)
absl::Status Initialize(const Config &config, RomVersionManager *version_mgr, ProposalApprovalManager *approval_mgr)
void OnProposalReceived(const nlohmann::json &payload)
void OnRomSyncReceived(const nlohmann::json &payload)
absl::Status ApplyRomSync(const std::string &diff_data, const std::string &rom_hash, const std::string &sender)
absl::StatusOr< SessionInfo > GetSessionInfo() const
absl::Status SubmitChangesAsProposal(const std::string &description, const std::string &username)
ProposalApprovalManager * approval_mgr_
void OnParticipantJoined(const nlohmann::json &payload)
absl::Status Connect(const std::string &host, int port=8765)
absl::Status JoinSession(const std::string &session_code, const std::string &username)
absl::Status ApplyDiff(const std::string &diff_data)
absl::Status HostSession(const std::string &session_name, const std::string &username, bool ai_enabled=true)
void OnParticipantLeft(const nlohmann::json &payload)
std::string GenerateDiff(const std::string &from_hash, const std::string &to_hash)
Manages proposal approval workflow for collaborative sessions.
Manages ROM versioning, snapshots, and rollback capabilities.
WebSocket client for connecting to yaze-server.
Main namespace for the application.