summaryrefslogtreecommitdiff
path: root/Source/Android/jni/NetPlay/NetPlayUICallbacks.h
blob: 946948d2db862612b53914b9d6f4869487b1085e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2026 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <memory>
#include <span>
#include <string>
#include <vector>

#include <jni.h>

#include "Common/HookableEvent.h"
#include "Core/NetPlayClient.h"
#include "UICommon/GameFile.h"
#include "jni/AndroidCommon/IDCache.h"

namespace NetPlay
{

class NetPlayUICallbacks : public NetPlay::NetPlayUI
{
public:
  NetPlayUICallbacks(jobject netplay_session,
                     std::vector<std::shared_ptr<const UICommon::GameFile>> games);
  ~NetPlayUICallbacks() override;

  void BootGame(const std::string& filename,
                std::unique_ptr<BootSessionData> boot_session_data) override;
  void StopGame() override;
  bool IsHosting() const override;
  void Update() override;
  void AppendChat(const std::string& msg) override;
  void OnMsgChangeGame(const NetPlay::SyncIdentifier& sync_identifier,
                       const std::string& netplay_name) override;
  void OnMsgChangeGBARom(int pad, const NetPlay::GBAConfig& config) override;
  void OnMsgStartGame() override;
  void OnMsgStopGame() override;
  void OnMsgPowerButton() override;
  void OnPlayerConnect(const std::string& player) override;
  void OnPlayerDisconnect(const std::string& player) override;
  void OnPadBufferChanged(u32 buffer) override;
  void OnHostInputAuthorityChanged(bool enabled) override;
  void OnDesync(u32 frame, const std::string& player) override;
  void OnConnectionLost() override;
  void OnConnectionError(const std::string& message) override;
  void OnTraversalError(Common::TraversalClient::FailureReason error) override;
  void OnTraversalStateChanged(Common::TraversalClient::State state) override;
  void OnGameStartAborted() override;
  void OnGolferChanged(bool is_golfer, const std::string& golfer_name) override;
  void OnTtlDetermined(u8 ttl) override;
  void OnIndexAdded(bool success, std::string error) override;
  void OnIndexRefreshFailed(std::string error) override;
  bool IsRecording() override;
  std::shared_ptr<const UICommon::GameFile>
  FindGameFile(const NetPlay::SyncIdentifier& sync_identifier,
               NetPlay::SyncIdentifierComparison* found = nullptr) override;
  std::string FindGBARomPath(const std::array<u8, 20>& hash, std::string_view title,
                             int device_number) override;
  void ShowGameDigestDialog(const std::string& title) override;
  void SetGameDigestProgress(int pid, int progress) override;
  void SetGameDigestResult(int pid, const std::string& result) override;
  void AbortGameDigest() override;
  void ShowChunkedProgressDialog(const std::string& title, u64 data_size,
                                 std::span<const int> players) override;
  void HideChunkedProgressDialog() override;
  void SetChunkedProgress(int pid, u64 progress) override;
  void SetHostWiiSyncData(std::vector<u64> titles, std::string redirect_folder) override;

private:
  jobject GetNetplaySessionLocalRef(JNIEnv* env) const;

  template <typename F>
  void WithSession(F&& callback) const
  {
    JNIEnv* env = IDCache::GetEnvForThread();
    jobject netplay_session = GetNetplaySessionLocalRef(env);
    if (!netplay_session)
      return;
    callback(env, netplay_session);
    env->DeleteLocalRef(netplay_session);
  }

  jweak m_netplay_session;
  std::vector<std::shared_ptr<const UICommon::GameFile>> m_games;
  NetPlay::SyncIdentifier m_current_game_identifier;
  std::string m_current_game_name;
  Common::EventHook m_state_changed_hook;
  bool m_got_stop_request = true;
};

}  // namespace NetPlay