High-level service integrating version management with networking. More...
#include <collaboration_service.h>
Classes | |
struct | Config |
Public Member Functions | |
CollaborationService (Rom *rom) | |
~CollaborationService () | |
absl::Status | Initialize (const Config &config, RomVersionManager *version_mgr, ProposalApprovalManager *approval_mgr) |
absl::Status | Connect (const std::string &host, int port=8765) |
void | Disconnect () |
absl::Status | HostSession (const std::string &session_name, const std::string &username, bool ai_enabled=true) |
absl::Status | JoinSession (const std::string &session_code, const std::string &username) |
absl::Status | LeaveSession () |
absl::Status | SubmitChangesAsProposal (const std::string &description, const std::string &username) |
absl::Status | ApplyRomSync (const std::string &diff_data, const std::string &rom_hash, const std::string &sender) |
absl::Status | HandleIncomingProposal (const std::string &proposal_id, const nlohmann::json &proposal_data, const std::string &sender) |
absl::Status | VoteOnProposal (const std::string &proposal_id, bool approved, const std::string &username) |
absl::Status | ApplyApprovedProposal (const std::string &proposal_id) |
bool | IsConnected () const |
absl::StatusOr< SessionInfo > | GetSessionInfo () const |
WebSocketClient * | GetClient () |
void | SetAutoSync (bool enabled) |
Private Member Functions | |
void | OnRomSyncReceived (const nlohmann::json &payload) |
void | OnProposalReceived (const nlohmann::json &payload) |
void | OnProposalUpdated (const nlohmann::json &payload) |
void | OnParticipantJoined (const nlohmann::json &payload) |
void | OnParticipantLeft (const nlohmann::json &payload) |
std::string | GenerateDiff (const std::string &from_hash, const std::string &to_hash) |
absl::Status | ApplyDiff (const std::string &diff_data) |
bool | ShouldAutoSync () |
Private Attributes | |
Rom * | rom_ |
RomVersionManager * | version_mgr_ |
ProposalApprovalManager * | approval_mgr_ |
std::unique_ptr< WebSocketClient > | client_ |
Config | config_ |
std::string | last_sync_hash_ |
bool | sync_in_progress_ |
High-level service integrating version management with networking.
Bridges the gap between:
Features:
Definition at line 32 of file collaboration_service.h.
|
explicit |
Definition at line 12 of file collaboration_service.cc.
yaze::net::CollaborationService::~CollaborationService | ( | ) |
Definition at line 20 of file collaboration_service.cc.
References Disconnect().
absl::Status yaze::net::CollaborationService::Initialize | ( | const Config & | config, |
RomVersionManager * | version_mgr, | ||
ProposalApprovalManager * | approval_mgr | ||
) |
Initialize the service
Definition at line 24 of file collaboration_service.cc.
References approval_mgr_, client_, config_, yaze::net::RomVersionManager::GetCurrentHash(), yaze::Rom::is_loaded(), last_sync_hash_, OnParticipantJoined(), OnParticipantLeft(), OnProposalReceived(), OnProposalUpdated(), OnRomSyncReceived(), rom_, and version_mgr_.
absl::Status yaze::net::CollaborationService::Connect | ( | const std::string & | host, |
int | port = 8765 |
||
) |
Connect to collaboration server
Definition at line 74 of file collaboration_service.cc.
References client_.
void yaze::net::CollaborationService::Disconnect | ( | ) |
Disconnect from server
Definition at line 78 of file collaboration_service.cc.
References client_.
Referenced by ~CollaborationService().
absl::Status yaze::net::CollaborationService::HostSession | ( | const std::string & | session_name, |
const std::string & | username, | ||
bool | ai_enabled = true |
||
) |
Host a new session
Definition at line 84 of file collaboration_service.cc.
References client_, yaze::net::RomVersionManager::CreateSnapshot(), yaze::net::RomVersionManager::GetCurrentHash(), yaze::Rom::is_loaded(), last_sync_hash_, yaze::net::RomVersionManager::MarkAsSafePoint(), rom_, and version_mgr_.
absl::Status yaze::net::CollaborationService::JoinSession | ( | const std::string & | session_code, |
const std::string & | username | ||
) |
Join existing session
Definition at line 128 of file collaboration_service.cc.
References client_, yaze::net::RomVersionManager::CreateSnapshot(), yaze::net::RomVersionManager::GetCurrentHash(), yaze::Rom::is_loaded(), last_sync_hash_, yaze::net::RomVersionManager::MarkAsSafePoint(), rom_, and version_mgr_.
absl::Status yaze::net::CollaborationService::LeaveSession | ( | ) |
absl::Status yaze::net::CollaborationService::SubmitChangesAsProposal | ( | const std::string & | description, |
const std::string & | username | ||
) |
Submit local changes as proposal
Definition at line 171 of file collaboration_service.cc.
References client_, config_, GenerateDiff(), yaze::net::RomVersionManager::GetCurrentHash(), yaze::Rom::is_loaded(), last_sync_hash_, yaze::net::CollaborationService::Config::require_approval_for_sync, rom_, and version_mgr_.
absl::Status yaze::net::CollaborationService::ApplyRomSync | ( | const std::string & | diff_data, |
const std::string & | rom_hash, | ||
const std::string & | sender | ||
) |
Apply received ROM sync
Definition at line 211 of file collaboration_service.cc.
References ApplyDiff(), config_, yaze::net::CollaborationService::Config::create_snapshot_before_sync, yaze::net::RomVersionManager::CreateSnapshot(), yaze::net::RomVersionManager::GetSnapshots(), yaze::Rom::is_loaded(), last_sync_hash_, yaze::net::RomVersionManager::RestoreSnapshot(), rom_, sync_in_progress_, and version_mgr_.
Referenced by OnRomSyncReceived().
absl::Status yaze::net::CollaborationService::HandleIncomingProposal | ( | const std::string & | proposal_id, |
const nlohmann::json & | proposal_data, | ||
const std::string & | sender | ||
) |
Handle incoming proposal
Definition at line 259 of file collaboration_service.cc.
References approval_mgr_, and yaze::net::ProposalApprovalManager::SubmitProposal().
Referenced by OnProposalReceived().
absl::Status yaze::net::CollaborationService::VoteOnProposal | ( | const std::string & | proposal_id, |
bool | approved, | ||
const std::string & | username | ||
) |
Vote on proposal
Definition at line 277 of file collaboration_service.cc.
References approval_mgr_, client_, and yaze::net::ProposalApprovalManager::VoteOnProposal().
absl::Status yaze::net::CollaborationService::ApplyApprovedProposal | ( | const std::string & | proposal_id | ) |
Apply approved proposal
Definition at line 297 of file collaboration_service.cc.
References approval_mgr_, client_, yaze::net::RomVersionManager::CreateSnapshot(), yaze::net::ProposalApprovalManager::GetProposalStatus(), yaze::net::ProposalApprovalManager::IsProposalApproved(), and version_mgr_.
bool yaze::net::CollaborationService::IsConnected | ( | ) | const |
absl::StatusOr< SessionInfo > yaze::net::CollaborationService::GetSessionInfo | ( | ) | const |
|
inline |
Get WebSocket client (for advanced usage)
Definition at line 131 of file collaboration_service.h.
References client_.
void yaze::net::CollaborationService::SetAutoSync | ( | bool | enabled | ) |
Enable/disable auto-sync
Definition at line 333 of file collaboration_service.cc.
References yaze::net::CollaborationService::Config::auto_sync_enabled, and config_.
|
private |
Definition at line 339 of file collaboration_service.cc.
References ApplyRomSync().
Referenced by Initialize().
|
private |
Definition at line 351 of file collaboration_service.cc.
References HandleIncomingProposal().
Referenced by Initialize().
|
private |
Definition at line 359 of file collaboration_service.cc.
References approval_mgr_.
Referenced by Initialize().
|
private |
Definition at line 378 of file collaboration_service.cc.
Referenced by Initialize().
|
private |
Definition at line 383 of file collaboration_service.cc.
Referenced by Initialize().
|
private |
Definition at line 390 of file collaboration_service.cc.
References yaze::Rom::is_loaded(), and rom_.
Referenced by SubmitChangesAsProposal().
|
private |
Definition at line 408 of file collaboration_service.cc.
References yaze::Rom::is_loaded(), and rom_.
Referenced by ApplyRomSync().
|
private |
Definition at line 419 of file collaboration_service.cc.
References yaze::net::CollaborationService::Config::auto_sync_enabled, client_, config_, and sync_in_progress_.
|
private |
Definition at line 139 of file collaboration_service.h.
Referenced by ApplyDiff(), ApplyRomSync(), GenerateDiff(), HostSession(), Initialize(), JoinSession(), and SubmitChangesAsProposal().
|
private |
Definition at line 140 of file collaboration_service.h.
Referenced by ApplyApprovedProposal(), ApplyRomSync(), HostSession(), Initialize(), JoinSession(), and SubmitChangesAsProposal().
|
private |
Definition at line 141 of file collaboration_service.h.
Referenced by ApplyApprovedProposal(), HandleIncomingProposal(), Initialize(), OnProposalUpdated(), and VoteOnProposal().
|
private |
Definition at line 142 of file collaboration_service.h.
Referenced by ApplyApprovedProposal(), Connect(), Disconnect(), GetClient(), GetSessionInfo(), HostSession(), Initialize(), IsConnected(), JoinSession(), LeaveSession(), ShouldAutoSync(), SubmitChangesAsProposal(), and VoteOnProposal().
|
private |
Definition at line 143 of file collaboration_service.h.
Referenced by ApplyRomSync(), Initialize(), SetAutoSync(), ShouldAutoSync(), and SubmitChangesAsProposal().
|
private |
Definition at line 146 of file collaboration_service.h.
Referenced by ApplyRomSync(), HostSession(), Initialize(), JoinSession(), and SubmitChangesAsProposal().
|
private |
Definition at line 147 of file collaboration_service.h.
Referenced by ApplyRomSync(), and ShouldAutoSync().