2020-04-05 21:16:16 +02:00
|
|
|
// ftpd is a server implementation based on the following:
|
|
|
|
// - RFC 959 (https://tools.ietf.org/html/rfc959)
|
|
|
|
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
|
|
|
|
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
|
|
|
|
//
|
|
|
|
// Copyright (C) 2020 Michael Theall
|
|
|
|
//
|
|
|
|
// 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, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// 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 for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "platform.h"
|
|
|
|
|
|
|
|
#include "imgui_deko3d.h"
|
|
|
|
#include "imgui_nx.h"
|
|
|
|
|
|
|
|
#include "imgui.h"
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
bool platform::init ()
|
|
|
|
{
|
|
|
|
if (!imgui::nx::init ())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
imgui::deko3d::init ();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool platform::loop ()
|
|
|
|
{
|
|
|
|
if (!appletMainLoop ())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
hidScanInput ();
|
|
|
|
|
|
|
|
auto const keysDown = hidKeysDown (CONTROLLER_P1_AUTO);
|
|
|
|
if (keysDown & KEY_PLUS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
imgui::nx::newFrame ();
|
|
|
|
imgui::deko3d::newFrame ();
|
|
|
|
ImGui::NewFrame ();
|
|
|
|
|
|
|
|
imgui::deko3d::test ();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform::render ()
|
|
|
|
{
|
|
|
|
ImGui::Render ();
|
|
|
|
|
|
|
|
imgui::deko3d::render ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform::exit ()
|
|
|
|
{
|
|
|
|
imgui::nx::exit ();
|
|
|
|
imgui::deko3d::exit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2020-04-06 07:36:03 +02:00
|
|
|
/// \brief Platform thread pimpl
|
2020-04-05 21:16:16 +02:00
|
|
|
class platform::Thread::privateData_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
privateData_t () = default;
|
|
|
|
|
2020-04-06 07:36:03 +02:00
|
|
|
/// \brief Parameterized constructor
|
|
|
|
/// \param func_ Thread entry point
|
2020-04-05 21:16:16 +02:00
|
|
|
privateData_t (std::function<void ()> func_) : thread (func_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-06 07:36:03 +02:00
|
|
|
/// \brief Underlying thread
|
2020-04-05 21:16:16 +02:00
|
|
|
std::thread thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
platform::Thread::~Thread () = default;
|
|
|
|
|
|
|
|
platform::Thread::Thread () : m_d (new privateData_t ())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
platform::Thread::Thread (std::function<void ()> func_) : m_d (new privateData_t (func_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
platform::Thread::Thread (Thread &&that_) : m_d (new privateData_t ())
|
|
|
|
{
|
|
|
|
std::swap (m_d, that_.m_d);
|
|
|
|
}
|
|
|
|
|
|
|
|
platform::Thread &platform::Thread::operator= (Thread &&that_)
|
|
|
|
{
|
|
|
|
std::swap (m_d, that_.m_d);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform::Thread::join ()
|
|
|
|
{
|
|
|
|
m_d->thread.join ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform::Thread::sleep (std::chrono::milliseconds const timeout_)
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for (timeout_);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
#define USE_STD_MUTEX 1
|
2020-04-06 07:36:03 +02:00
|
|
|
|
|
|
|
/// \brief Platform mutex pimpl
|
2020-04-05 21:16:16 +02:00
|
|
|
class platform::Mutex::privateData_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
#if USE_STD_MUTEX
|
2020-04-06 07:36:03 +02:00
|
|
|
/// \brief Underlying mutex
|
2020-04-05 21:16:16 +02:00
|
|
|
std::mutex mutex;
|
|
|
|
#else
|
2020-04-06 07:36:03 +02:00
|
|
|
/// \brief Underlying mutex
|
2020-04-05 21:16:16 +02:00
|
|
|
::Mutex mutex;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
platform::Mutex::~Mutex () = default;
|
|
|
|
|
|
|
|
platform::Mutex::Mutex () : m_d (new privateData_t ())
|
|
|
|
{
|
|
|
|
#if !USE_STD_MUTEX
|
|
|
|
mutexInit (&m_d->mutex);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform::Mutex::lock ()
|
|
|
|
{
|
|
|
|
#if USE_STD_MUTEX
|
|
|
|
m_d->mutex.lock ();
|
|
|
|
#else
|
|
|
|
mutexLock (&m_d->mutex);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform::Mutex::unlock ()
|
|
|
|
{
|
|
|
|
#if USE_STD_MUTEX
|
|
|
|
m_d->mutex.unlock ();
|
|
|
|
#else
|
|
|
|
mutexUnlock (&m_d->mutex);
|
|
|
|
#endif
|
|
|
|
}
|