From f4e2ca0359e5d2f343cbe8059394ee7b81fd275e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 3 Jul 2016 10:24:33 -0700 Subject: [PATCH] http: Add a screen under tools for the server. --- CMakeLists.txt | 1 + UI/GameSettingsScreen.cpp | 10 ++- UI/GameSettingsScreen.h | 1 + UI/RemoteISOScreen.cpp | 141 ++++++++++++++++++++++++++++++++++++++ UI/RemoteISOScreen.h | 34 +++++++++ UI/UI.vcxproj | 2 + UI/UI.vcxproj.filters | 6 ++ android/jni/Android.mk | 1 + 8 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 UI/RemoteISOScreen.cpp create mode 100644 UI/RemoteISOScreen.h diff --git a/CMakeLists.txt b/CMakeLists.txt index db814c4b2..126aced10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -893,6 +893,7 @@ set(NativeAppSource UI/GamepadEmu.cpp UI/OnScreenDisplay.cpp UI/ControlMappingScreen.cpp + UI/RemoteISOScreen.cpp UI/ReportScreen.cpp UI/SavedataScreen.cpp UI/Store.cpp diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index f8b03288a..79c76fd42 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -34,6 +34,7 @@ #include "UI/ControlMappingScreen.h" #include "UI/DevScreens.h" #include "UI/DisplayLayoutScreen.h" +#include "UI/RemoteISOScreen.h" #include "UI/SavedataScreen.h" #include "UI/TouchControlLayoutScreen.h" #include "UI/TouchControlVisibilityScreen.h" @@ -499,6 +500,7 @@ void GameSettingsScreen::CreateViews() { tools->Add(new Choice(sa->T("Savedata Manager")))->OnClick.Handle(this, &GameSettingsScreen::OnSavedataManager); tools->Add(new Choice(dev->T("System Information")))->OnClick.Handle(this, &GameSettingsScreen::OnSysInfo); tools->Add(new Choice(sy->T("Developer Tools")))->OnClick.Handle(this, &GameSettingsScreen::OnDeveloperTools); + tools->Add(new Choice(sy->T("Remote disc streaming")))->OnClick.Handle(this, &GameSettingsScreen::OnRemoteISO); // System ViewGroup *systemSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); @@ -993,11 +995,17 @@ UI::EventReturn GameSettingsScreen::OnPostProcShaderChange(UI::EventParams &e) { Reporting::UpdateConfig(); return UI::EVENT_DONE; } + UI::EventReturn GameSettingsScreen::OnDeveloperTools(UI::EventParams &e) { screenManager()->push(new DeveloperToolsScreen()); return UI::EVENT_DONE; } +UI::EventReturn GameSettingsScreen::OnRemoteISO(UI::EventParams &e) { + screenManager()->push(new RemoteISOScreen()); + return UI::EVENT_DONE; +} + UI::EventReturn GameSettingsScreen::OnControlMapping(UI::EventParams &e) { screenManager()->push(new ControlMappingScreen()); return UI::EVENT_DONE; @@ -1006,7 +1014,7 @@ UI::EventReturn GameSettingsScreen::OnControlMapping(UI::EventParams &e) { UI::EventReturn GameSettingsScreen::OnTouchControlLayout(UI::EventParams &e) { screenManager()->push(new TouchControlLayoutScreen()); return UI::EVENT_DONE; -}; +} //when the tilt event type is modified, we need to reset all tilt settings. //refer to the ResetTiltEvents() function for a detailed explanation. diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index 578dbe101..5600382e7 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -73,6 +73,7 @@ private: UI::EventReturn OnPostProcShader(UI::EventParams &e); UI::EventReturn OnPostProcShaderChange(UI::EventParams &e); UI::EventReturn OnDeveloperTools(UI::EventParams &e); + UI::EventReturn OnRemoteISO(UI::EventParams &e); UI::EventReturn OnChangeNickname(UI::EventParams &e); UI::EventReturn OnChangeproAdhocServerAddress(UI::EventParams &e); UI::EventReturn OnChangeMacAddress(UI::EventParams &e); diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp new file mode 100644 index 000000000..f347021b9 --- /dev/null +++ b/UI/RemoteISOScreen.cpp @@ -0,0 +1,141 @@ +// Copyright (c) 2014- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "i18n/i18n.h" +#include "net/http_server.h" +#include "net/resolve.h" +#include "net/sinks.h" +#include "thread/thread.h" +#include "thread/threadutil.h" +#include "Common/Common.h" +#include "Common/FileUtil.h" +#include "Core/Config.h" +#include "UI/RemoteISOScreen.h" + +using namespace UI; + +enum class ServerStatus { + STOPPED, + STARTING, + RUNNING, + STOPPING, +}; + +static std::thread *serverThread = nullptr; +static ServerStatus serverStatus; +static recursive_mutex serverStatusLock; +static condition_variable serverStatusCond; + +static void UpdateStatus(ServerStatus s) { + lock_guard guard(serverStatusLock); + serverStatus = s; + serverStatusCond.notify_one(); +} + +static ServerStatus RetrieveStatus() { + lock_guard guard(serverStatusLock); + return serverStatus; +} + +static void ExecuteServer() { + setCurrentThreadName("HTTPServer"); + + net::Init(); + auto http = new http::Server(new threading::SameThreadExecutor()); + + http->Listen(0); + // TODO: Report local IP and port. + UpdateStatus(ServerStatus::RUNNING); + + while (RetrieveStatus() == ServerStatus::RUNNING) { + http->RunSlice(5.0); + } + + net::Shutdown(); + + UpdateStatus(ServerStatus::STOPPED); +} + +RemoteISOScreen::RemoteISOScreen() { +} + +void RemoteISOScreen::CreateViews() { + I18NCategory *rp = GetI18NCategory("Reporting"); + I18NCategory *di = GetI18NCategory("Dialog"); + I18NCategory *sy = GetI18NCategory("System"); + + Margins actionMenuMargins(0, 20, 15, 0); + Margins contentMargins(0, 20, 5, 5); + ViewGroup *leftColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(WRAP_CONTENT, FILL_PARENT, 0.4f, contentMargins)); + LinearLayout *leftColumnItems = new LinearLayout(ORIENT_VERTICAL, new LayoutParams(WRAP_CONTENT, FILL_PARENT)); + ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins)); + LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL); + + leftColumnItems->Add(new TextView(sy->T("RemoteISOWifi", "Note: Connect both devices to the same wifi"), new LinearLayoutParams(Margins(12, 5, 0, 5)))); + + rightColumnItems->SetSpacing(0.0f); + rightColumnItems->Add(new Choice(rp->T("Browse Games"))); + if (serverStatus != ServerStatus::STOPPED) { + rightColumnItems->Add(new Choice(rp->T("Stop Sharing")))->OnClick.Handle(this, &RemoteISOScreen::HandleStopServer); + } else { + rightColumnItems->Add(new Choice(rp->T("Share Games (Server)")))->OnClick.Handle(this, &RemoteISOScreen::HandleStartServer); + } + + rightColumnItems->Add(new Spacer(25.0)); + rightColumnItems->Add(new Choice(di->T("Back"), "", false, new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &UIScreen::OnBack); + + root_ = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)); + root_->Add(leftColumn); + root_->Add(rightColumn); + + leftColumn->Add(leftColumnItems); + rightColumn->Add(rightColumnItems); +} + +UI::EventReturn RemoteISOScreen::HandleStartServer(UI::EventParams &e) { + lock_guard guard(serverStatusLock); + + if (serverStatus != ServerStatus::STOPPED) { + return EVENT_SKIPPED; + } + + serverStatus = ServerStatus::STARTING; + serverThread = new std::thread(&ExecuteServer); + serverThread->detach(); + + serverStatusCond.wait(serverStatusLock); + RecreateViews(); + + return EVENT_DONE; +} + +UI::EventReturn RemoteISOScreen::HandleStopServer(UI::EventParams &e) { + lock_guard guard(serverStatusLock); + + if (serverStatus != ServerStatus::RUNNING) { + return EVENT_SKIPPED; + } + + serverStatus = ServerStatus::STOPPING; + serverStatusCond.wait(serverStatusLock); + delete serverThread; + serverThread = nullptr; + + RecreateViews(); + + return EVENT_DONE; +} diff --git a/UI/RemoteISOScreen.h b/UI/RemoteISOScreen.h new file mode 100644 index 000000000..04b92722c --- /dev/null +++ b/UI/RemoteISOScreen.h @@ -0,0 +1,34 @@ +// Copyright (c) 2016- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#pragma once + +#include "base/functional.h" +#include "ui/ui_screen.h" +#include "ui/viewgroup.h" +#include "UI/MiscScreens.h" + +class RemoteISOScreen : public UIScreenWithBackground { +public: + RemoteISOScreen(); + +protected: + void CreateViews() override; + + UI::EventReturn HandleStartServer(UI::EventParams &e); + UI::EventReturn HandleStopServer(UI::EventParams &e); +}; diff --git a/UI/UI.vcxproj b/UI/UI.vcxproj index 8fbcf5c79..15093677a 100644 --- a/UI/UI.vcxproj +++ b/UI/UI.vcxproj @@ -37,6 +37,7 @@ + @@ -66,6 +67,7 @@ + diff --git a/UI/UI.vcxproj.filters b/UI/UI.vcxproj.filters index 4ee956b35..dec781d42 100644 --- a/UI/UI.vcxproj.filters +++ b/UI/UI.vcxproj.filters @@ -66,6 +66,9 @@ Screens + + Screens + @@ -133,6 +136,9 @@ + + Screens + diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 3cdb8d29b..797102bc5 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -395,6 +395,7 @@ LOCAL_SRC_FILES := \ $(SRC)/UI/EmuScreen.cpp \ $(SRC)/UI/MainScreen.cpp \ $(SRC)/UI/MiscScreens.cpp \ + $(SRC)/UI/RemoteISOScreen.cpp \ $(SRC)/UI/ReportScreen.cpp \ $(SRC)/UI/PauseScreen.cpp \ $(SRC)/UI/SavedataScreen.cpp \