Unix socket client for Mesen2-OoS fork. More...
#include <mesen_socket_client.h>

Public Member Functions | |
| MesenSocketClient () | |
| ~MesenSocketClient () | |
| MesenSocketClient (const MesenSocketClient &)=delete | |
| MesenSocketClient & | operator= (const MesenSocketClient &)=delete |
| absl::Status | Connect () |
| Auto-discover and connect to first available Mesen2 socket. | |
| absl::Status | Connect (const std::string &socket_path) |
| Connect to a specific socket path. | |
| void | Disconnect () |
| Disconnect from Mesen2. | |
| bool | IsConnected () const |
| Check if connected to Mesen2. | |
| const std::string & | GetSocketPath () const |
| Get the current socket path. | |
| absl::Status | Ping () |
| Ping Mesen2 to check connectivity. | |
| absl::StatusOr< MesenState > | GetState () |
| Get current emulation state. | |
| absl::Status | Pause () |
| Pause emulation. | |
| absl::Status | Resume () |
| Resume emulation. | |
| absl::Status | Reset () |
| Reset the console. | |
| absl::Status | Frame () |
| Run exactly one frame. | |
| absl::Status | Step (int count=1, const std::string &mode="into") |
| Step N CPU instructions (default 1) | |
| absl::Status | SetButton (emu::input::SnesButton button, bool pressed) |
| Set controller button state. | |
| absl::Status | SetButtons (const emu::input::ControllerState &state) |
| Set all buttons at once. | |
| absl::StatusOr< uint8_t > | ReadByte (uint32_t addr) |
| Read a single byte from memory. | |
| absl::StatusOr< uint16_t > | ReadWord (uint32_t addr) |
| Read a 16-bit word from memory. | |
| absl::StatusOr< std::vector< uint8_t > > | ReadBlock (uint32_t addr, size_t len) |
| Read a block of bytes from memory. | |
| absl::Status | WriteByte (uint32_t addr, uint8_t value) |
| Write a single byte to memory. | |
| absl::Status | WriteWord (uint32_t addr, uint16_t value) |
| Write a 16-bit word to memory. | |
| absl::Status | WriteBlock (uint32_t addr, const std::vector< uint8_t > &data) |
| Write a block of bytes to memory. | |
| absl::StatusOr< CpuState > | GetCpuState () |
| Get CPU register state. | |
| absl::StatusOr< std::string > | Disassemble (uint32_t addr, int count=10) |
| Disassemble instructions at address. | |
| absl::StatusOr< int > | AddBreakpoint (uint32_t addr, BreakpointType type, const std::string &condition="") |
| Add a breakpoint. | |
| absl::Status | RemoveBreakpoint (int id) |
| Remove a breakpoint by ID. | |
| absl::Status | ClearBreakpoints () |
| Clear all breakpoints. | |
| absl::StatusOr< std::string > | GetTrace (int count=20) |
| Get execution trace log. | |
| absl::StatusOr< GameState > | GetGameState () |
| Get comprehensive ALTTP game state. | |
| absl::StatusOr< std::vector< SpriteInfo > > | GetSprites (bool all=false) |
| Get active sprites. | |
| absl::Status | SetCollisionOverlay (bool enable, const std::string &colmap="A") |
| Enable/disable collision overlay. | |
| absl::Status | SaveState (int slot) |
| Save state to slot. | |
| absl::Status | LoadState (int slot) |
| Load state from slot. | |
| absl::StatusOr< std::string > | Screenshot () |
| Take a screenshot. | |
| absl::Status | Subscribe (const std::vector< std::string > &events) |
| Subscribe to events. | |
| absl::Status | Unsubscribe () |
| Unsubscribe from events. | |
| void | SetEventCallback (EventCallback callback) |
| Set callback for received events. | |
| EventListenerId | AddEventListener (EventCallback callback) |
| Add an event listener without replacing existing listeners. | |
| void | RemoveEventListener (EventListenerId id) |
| Remove a previously added event listener. | |
| absl::StatusOr< std::string > | SendCommand (const std::string &json) |
| Send a raw JSON command and get raw response. | |
Static Public Member Functions | |
| static std::vector< std::string > | ListAvailableSockets () |
| List available Mesen2 sockets on the system. | |
Private Member Functions | |
| absl::StatusOr< std::string > | ParseResponse (const std::string &response) |
| Parse JSON response for success/error. | |
| absl::StatusOr< std::string > | SendCommandOnSocket (int fd, const std::string &json, bool update_connection_state) |
| Send a command using a specific socket descriptor. | |
| void | EventLoop () |
| Event listening thread function. | |
Static Private Member Functions | |
| static std::vector< std::string > | FindSocketPaths () |
| Find available Mesen2 socket paths. | |
Private Attributes | |
| int | socket_fd_ = -1 |
| int | event_socket_fd_ = -1 |
| std::string | socket_path_ |
| std::atomic< bool > | connected_ {false} |
| std::mutex | command_mutex_ |
| std::mutex | event_callback_mutex_ |
| EventCallback | event_callback_ |
| std::unordered_map< EventListenerId, EventCallback > | event_listeners_ |
| EventListenerId | next_event_listener_id_ = 1 |
| std::thread | event_thread_ |
| std::atomic< bool > | event_thread_running_ {false} |
| std::string | pending_event_payload_ |
| emu::input::ControllerState | current_input_ |
Unix socket client for Mesen2-OoS fork.
Connects to Mesen2's socket API at /tmp/mesen2-<pid>.sock and provides type-safe wrapper methods for all commands.
Definition at line 136 of file mesen_socket_client.h.
|
default |
| yaze::emu::mesen::MesenSocketClient::~MesenSocketClient | ( | ) |
Definition at line 238 of file mesen_socket_client.cc.
References Disconnect().

|
delete |
|
delete |
| absl::Status yaze::emu::mesen::MesenSocketClient::Connect | ( | ) |
Auto-discover and connect to first available Mesen2 socket.
Definition at line 242 of file mesen_socket_client.cc.
References Connect(), and FindSocketPaths().
Referenced by Connect().

| absl::Status yaze::emu::mesen::MesenSocketClient::Connect | ( | const std::string & | socket_path | ) |
Connect to a specific socket path.
| socket_path | Full path to Unix socket (e.g., /tmp/mesen2-12345.sock) |
Definition at line 251 of file mesen_socket_client.cc.
References connected_, Disconnect(), IsConnected(), Ping(), socket_fd_, and socket_path_.

| void yaze::emu::mesen::MesenSocketClient::Disconnect | ( | ) |
Disconnect from Mesen2.
Definition at line 276 of file mesen_socket_client.cc.
References connected_, socket_fd_, socket_path_, and Unsubscribe().
Referenced by Connect(), and ~MesenSocketClient().

| bool yaze::emu::mesen::MesenSocketClient::IsConnected | ( | ) | const |
Check if connected to Mesen2.
Definition at line 288 of file mesen_socket_client.cc.
References connected_.
Referenced by Connect(), SendCommand(), and Subscribe().
|
inline |
Get the current socket path.
Definition at line 174 of file mesen_socket_client.h.
References socket_path_.
|
static |
List available Mesen2 sockets on the system.
Definition at line 340 of file mesen_socket_client.cc.
References FindSocketPaths().
Referenced by yaze::editor::MesenDebugPanel::RefreshSocketList(), yaze::editor::MesenScreenshotPanel::RefreshSocketList(), and yaze::editor::SramViewerPanel::RefreshSocketList().

| absl::Status yaze::emu::mesen::MesenSocketClient::Ping | ( | ) |
Ping Mesen2 to check connectivity.
Definition at line 439 of file mesen_socket_client.cc.
References SendCommand().
Referenced by Connect().

| absl::StatusOr< MesenState > yaze::emu::mesen::MesenSocketClient::GetState | ( | ) |
Get current emulation state.
Definition at line 446 of file mesen_socket_client.cc.
References yaze::emu::mesen::MesenState::console_type, yaze::emu::mesen::MesenState::debugging, yaze::emu::mesen::MesenState::fps, yaze::emu::mesen::MesenState::frame, yaze::emu::mesen::MesenState::paused, yaze::emu::mesen::MesenState::running, and SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::Pause | ( | ) |
Pause emulation.
Definition at line 461 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::Resume | ( | ) |
Resume emulation.
Definition at line 466 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::Reset | ( | ) |
Reset the console.
Definition at line 471 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::Frame | ( | ) |
Run exactly one frame.
Definition at line 476 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::Step | ( | int | count = 1, |
| const std::string & | mode = "into" ) |
Step N CPU instructions (default 1)
| count | Number of steps |
| mode | Step mode: "into", "over", "out" |
Definition at line 481 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::SetButton | ( | emu::input::SnesButton | button, |
| bool | pressed ) |
Set controller button state.
| button | SNES button |
| pressed | True to press, false to release |
Definition at line 491 of file mesen_socket_client.cc.
References current_input_, yaze::emu::input::ControllerState::SetButton(), and SetButtons().

| absl::Status yaze::emu::mesen::MesenSocketClient::SetButtons | ( | const emu::input::ControllerState & | state | ) |
Set all buttons at once.
Definition at line 497 of file mesen_socket_client.cc.
References yaze::emu::input::A, yaze::emu::input::B, current_input_, yaze::emu::input::DOWN, yaze::emu::input::ControllerState::IsPressed(), yaze::emu::input::L, yaze::emu::input::LEFT, yaze::emu::input::R, yaze::emu::input::RIGHT, yaze::emu::input::SELECT, SendCommand(), yaze::emu::input::START, yaze::emu::input::UP, yaze::emu::input::X, and yaze::emu::input::Y.
Referenced by SetButton().

| absl::StatusOr< uint8_t > yaze::emu::mesen::MesenSocketClient::ReadByte | ( | uint32_t | addr | ) |
Read a single byte from memory.
Definition at line 531 of file mesen_socket_client.cc.
References SendCommand().

| absl::StatusOr< uint16_t > yaze::emu::mesen::MesenSocketClient::ReadWord | ( | uint32_t | addr | ) |
Read a 16-bit word from memory.
Definition at line 539 of file mesen_socket_client.cc.
References SendCommand().

| absl::StatusOr< std::vector< uint8_t > > yaze::emu::mesen::MesenSocketClient::ReadBlock | ( | uint32_t | addr, |
| size_t | len ) |
Read a block of bytes from memory.
Definition at line 547 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::WriteByte | ( | uint32_t | addr, |
| uint8_t | value ) |
Write a single byte to memory.
Definition at line 577 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::WriteWord | ( | uint32_t | addr, |
| uint16_t | value ) |
Write a 16-bit word to memory.
Definition at line 584 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::WriteBlock | ( | uint32_t | addr, |
| const std::vector< uint8_t > & | data ) |
Write a block of bytes to memory.
Definition at line 591 of file mesen_socket_client.cc.
References SendCommand().

| absl::StatusOr< CpuState > yaze::emu::mesen::MesenSocketClient::GetCpuState | ( | ) |
Get CPU register state.
Definition at line 607 of file mesen_socket_client.cc.
References yaze::emu::mesen::CpuState::A, yaze::emu::mesen::CpuState::D, yaze::emu::mesen::CpuState::DBR, yaze::emu::mesen::CpuState::emulation_mode, yaze::emu::mesen::CpuState::K, yaze::emu::mesen::CpuState::P, yaze::emu::mesen::CpuState::PC, SendCommand(), yaze::emu::mesen::CpuState::SP, yaze::emu::mesen::CpuState::X, and yaze::emu::mesen::CpuState::Y.

| absl::StatusOr< std::string > yaze::emu::mesen::MesenSocketClient::Disassemble | ( | uint32_t | addr, |
| int | count = 10 ) |
Disassemble instructions at address.
Definition at line 626 of file mesen_socket_client.cc.
References SendCommand().

| absl::StatusOr< int > yaze::emu::mesen::MesenSocketClient::AddBreakpoint | ( | uint32_t | addr, |
| BreakpointType | type, | ||
| const std::string & | condition = "" ) |
Add a breakpoint.
Definition at line 636 of file mesen_socket_client.cc.
References yaze::emu::mesen::kExecute, yaze::emu::mesen::kRead, yaze::emu::mesen::kReadWrite, yaze::emu::mesen::kWrite, and SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::RemoveBreakpoint | ( | int | id | ) |
Remove a breakpoint by ID.
Definition at line 670 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::ClearBreakpoints | ( | ) |
Clear all breakpoints.
Definition at line 676 of file mesen_socket_client.cc.
References SendCommand().

| absl::StatusOr< std::string > yaze::emu::mesen::MesenSocketClient::GetTrace | ( | int | count = 20 | ) |
Get execution trace log.
Definition at line 682 of file mesen_socket_client.cc.
References SendCommand().

| absl::StatusOr< GameState > yaze::emu::mesen::MesenSocketClient::GetGameState | ( | ) |
Get comprehensive ALTTP game state.
Definition at line 694 of file mesen_socket_client.cc.
References yaze::emu::mesen::GameItems::arrows, yaze::emu::mesen::GameItems::bombs, yaze::emu::mesen::GameItems::current_health, yaze::emu::mesen::LinkState::direction, yaze::emu::mesen::GameState::game, yaze::emu::mesen::GameMode::indoors, yaze::emu::mesen::GameState::items, yaze::emu::mesen::LinkState::layer, yaze::emu::mesen::GameState::link, yaze::emu::mesen::GameItems::magic, yaze::emu::mesen::GameItems::max_health, yaze::emu::mesen::GameMode::mode, yaze::emu::mesen::GameMode::overworld_area, yaze::emu::mesen::LinkState::pose, yaze::emu::mesen::GameMode::room_id, yaze::emu::mesen::GameItems::rupees, SendCommand(), yaze::emu::mesen::LinkState::state, yaze::emu::mesen::GameMode::submode, yaze::emu::mesen::LinkState::x, and yaze::emu::mesen::LinkState::y.

| absl::StatusOr< std::vector< SpriteInfo > > yaze::emu::mesen::MesenSocketClient::GetSprites | ( | bool | all = false | ) |
Get active sprites.
| all | If true, include inactive sprites |
Definition at line 741 of file mesen_socket_client.cc.
References yaze::emu::mesen::SpriteInfo::health, SendCommand(), yaze::emu::mesen::SpriteInfo::slot, yaze::emu::mesen::SpriteInfo::state, yaze::emu::mesen::SpriteInfo::subtype, yaze::emu::mesen::SpriteInfo::type, yaze::emu::mesen::SpriteInfo::x, and yaze::emu::mesen::SpriteInfo::y.

| absl::Status yaze::emu::mesen::MesenSocketClient::SetCollisionOverlay | ( | bool | enable, |
| const std::string & | colmap = "A" ) |
Enable/disable collision overlay.
Definition at line 792 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::SaveState | ( | int | slot | ) |
Save state to slot.
Definition at line 804 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::LoadState | ( | int | slot | ) |
Load state from slot.
Definition at line 810 of file mesen_socket_client.cc.
References SendCommand().

| absl::StatusOr< std::string > yaze::emu::mesen::MesenSocketClient::Screenshot | ( | ) |
Take a screenshot.
Definition at line 816 of file mesen_socket_client.cc.
References SendCommand().

| absl::Status yaze::emu::mesen::MesenSocketClient::Subscribe | ( | const std::vector< std::string > & | events | ) |
Subscribe to events.
| events | Event types: "breakpoint_hit", "frame_complete", "all", etc. |
Definition at line 827 of file mesen_socket_client.cc.
References event_socket_fd_, event_thread_, event_thread_running_, EventLoop(), IsConnected(), ParseResponse(), pending_event_payload_, socket_path_, and Unsubscribe().

| absl::Status yaze::emu::mesen::MesenSocketClient::Unsubscribe | ( | ) |
Unsubscribe from events.
Definition at line 919 of file mesen_socket_client.cc.
References event_socket_fd_, event_thread_, event_thread_running_, and pending_event_payload_.
Referenced by Disconnect(), and Subscribe().
| void yaze::emu::mesen::MesenSocketClient::SetEventCallback | ( | EventCallback | callback | ) |
Set callback for received events.
Definition at line 935 of file mesen_socket_client.cc.
References event_callback_, and event_callback_mutex_.
| EventListenerId yaze::emu::mesen::MesenSocketClient::AddEventListener | ( | EventCallback | callback | ) |
Add an event listener without replacing existing listeners.
Definition at line 940 of file mesen_socket_client.cc.
References event_callback_mutex_, event_listeners_, and next_event_listener_id_.
| void yaze::emu::mesen::MesenSocketClient::RemoveEventListener | ( | EventListenerId | id | ) |
Remove a previously added event listener.
Definition at line 950 of file mesen_socket_client.cc.
References event_callback_mutex_, and event_listeners_.
| absl::StatusOr< std::string > yaze::emu::mesen::MesenSocketClient::SendCommand | ( | const std::string & | json | ) |
Send a raw JSON command and get raw response.
Definition at line 411 of file mesen_socket_client.cc.
References command_mutex_, IsConnected(), SendCommandOnSocket(), and socket_fd_.
Referenced by AddBreakpoint(), ClearBreakpoints(), Disassemble(), Frame(), GetCpuState(), GetGameState(), GetSprites(), GetState(), GetTrace(), LoadState(), Pause(), Ping(), ReadBlock(), ReadByte(), ReadWord(), RemoveBreakpoint(), Reset(), Resume(), SaveState(), Screenshot(), SetButtons(), SetCollisionOverlay(), Step(), WriteBlock(), WriteByte(), and WriteWord().

|
staticprivate |
Find available Mesen2 socket paths.
Definition at line 292 of file mesen_socket_client.cc.
Referenced by Connect(), and ListAvailableSockets().
|
private |
Parse JSON response for success/error.
Definition at line 421 of file mesen_socket_client.cc.
Referenced by SendCommandOnSocket(), and Subscribe().
|
private |
Send a command using a specific socket descriptor.
Definition at line 344 of file mesen_socket_client.cc.
References connected_, and ParseResponse().
Referenced by SendCommand().

|
private |
Event listening thread function.
Definition at line 958 of file mesen_socket_client.cc.
References event_callback_, event_callback_mutex_, event_listeners_, event_socket_fd_, event_thread_running_, pending_event_payload_, yaze::emu::mesen::MesenEvent::raw_json, and yaze::emu::mesen::MesenEvent::type.
Referenced by Subscribe().
|
private |
Definition at line 411 of file mesen_socket_client.h.
Referenced by Connect(), Disconnect(), and SendCommand().
|
private |
Definition at line 412 of file mesen_socket_client.h.
Referenced by EventLoop(), Subscribe(), and Unsubscribe().
|
private |
Definition at line 413 of file mesen_socket_client.h.
Referenced by Connect(), Disconnect(), GetSocketPath(), and Subscribe().
|
private |
Definition at line 414 of file mesen_socket_client.h.
Referenced by Connect(), Disconnect(), IsConnected(), and SendCommandOnSocket().
|
private |
Definition at line 415 of file mesen_socket_client.h.
Referenced by SendCommand().
|
private |
Definition at line 416 of file mesen_socket_client.h.
Referenced by AddEventListener(), EventLoop(), RemoveEventListener(), and SetEventCallback().
|
private |
Definition at line 419 of file mesen_socket_client.h.
Referenced by EventLoop(), and SetEventCallback().
|
private |
Definition at line 420 of file mesen_socket_client.h.
Referenced by AddEventListener(), EventLoop(), and RemoveEventListener().
|
private |
Definition at line 421 of file mesen_socket_client.h.
Referenced by AddEventListener().
|
private |
Definition at line 422 of file mesen_socket_client.h.
Referenced by Subscribe(), and Unsubscribe().
|
private |
Definition at line 423 of file mesen_socket_client.h.
Referenced by EventLoop(), Subscribe(), and Unsubscribe().
|
private |
Definition at line 424 of file mesen_socket_client.h.
Referenced by EventLoop(), Subscribe(), and Unsubscribe().
|
private |
Definition at line 427 of file mesen_socket_client.h.
Referenced by SetButton(), and SetButtons().