ftpiiu_plugin/include/platform.h

136 lines
3.0 KiB
C
Raw Normal View History

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/>.
#pragma once
#ifdef _3DS
#include <3ds.h>
#endif
#include <chrono>
#include <cstdint>
#include <functional>
#include <memory>
namespace platform
{
2020-04-06 07:36:03 +02:00
/// \brief Initialize platform
2020-04-05 21:16:16 +02:00
bool init ();
2020-04-06 07:36:03 +02:00
/// \brief Whether network is visible
bool networkVisible ();
2020-04-06 07:36:03 +02:00
/// \brief Platform loop
2020-04-05 21:16:16 +02:00
bool loop ();
2020-04-06 07:36:03 +02:00
/// \brief Platform render
2020-04-05 21:16:16 +02:00
void render ();
2020-04-06 07:36:03 +02:00
/// \brief Deinitialize platform
2020-04-05 21:16:16 +02:00
void exit ();
#ifdef _3DS
2020-04-06 07:36:03 +02:00
/// \brief Steady clock
2020-04-05 21:16:16 +02:00
struct steady_clock
{
2020-04-06 07:36:03 +02:00
/// \brief Type representing number of ticks
using rep = std::uint64_t;
/// \brief Type representing ratio of clock period in seconds
using period = std::ratio<1, SYSCLOCK_ARM11>;
/// \brief Duration type
using duration = std::chrono::duration<rep, period>;
/// \brief Timestamp type
2020-04-05 21:16:16 +02:00
using time_point = std::chrono::time_point<steady_clock>;
2020-04-06 07:36:03 +02:00
/// \brief Whether clock is steady
2020-04-05 21:16:16 +02:00
constexpr static bool is_steady = true;
2020-04-06 07:36:03 +02:00
/// \brief Current timestamp
2020-04-05 21:16:16 +02:00
static time_point now () noexcept
{
return time_point (duration (svcGetSystemTick ()));
}
};
#else
2020-04-06 07:36:03 +02:00
/// \brief Steady clock
2020-04-05 21:16:16 +02:00
using steady_clock = std::chrono::steady_clock;
#endif
2020-04-06 07:36:03 +02:00
/// \brief Platform thread
2020-04-05 21:16:16 +02:00
class Thread
{
public:
~Thread ();
Thread ();
2020-04-06 07:36:03 +02:00
/// \brief Parameterized constructor
/// \param func_ Thread entrypoint
2020-04-07 04:17:30 +02:00
Thread (std::function<void ()> &&func_);
2020-04-05 21:16:16 +02:00
Thread (Thread const &that_) = delete;
2020-04-06 07:36:03 +02:00
/// \brief Move constructor
/// \param that_ Object to move from
2020-04-05 21:16:16 +02:00
Thread (Thread &&that_);
Thread &operator= (Thread const &that_) = delete;
2020-04-06 07:36:03 +02:00
/// \brief Move assignment
/// \param that_ Object to move from
2020-04-05 21:16:16 +02:00
Thread &operator= (Thread &&that_);
2020-04-06 07:36:03 +02:00
/// \brief Join thread
2020-04-05 21:16:16 +02:00
void join ();
2020-04-06 07:36:03 +02:00
/// \brief Suspend current thread
/// \param timeout_ Minimum time to sleep
2020-04-05 21:16:16 +02:00
static void sleep (std::chrono::milliseconds timeout_);
private:
class privateData_t;
2020-04-06 07:36:03 +02:00
/// \brief pimpl
2020-04-05 21:16:16 +02:00
std::unique_ptr<privateData_t> m_d;
};
2020-04-06 07:36:03 +02:00
/// \brief Platform mutex
2020-04-05 21:16:16 +02:00
class Mutex
{
public:
~Mutex ();
Mutex ();
2020-04-06 07:36:03 +02:00
/// \brief Lock mutex
2020-04-05 21:16:16 +02:00
void lock ();
2020-04-06 07:36:03 +02:00
/// \brief Unlock mutex
2020-04-05 21:16:16 +02:00
void unlock ();
private:
class privateData_t;
2020-04-06 07:36:03 +02:00
/// \brief pimpl
2020-04-05 21:16:16 +02:00
std::unique_ptr<privateData_t> m_d;
};
}