Skip to content

Commit

Permalink
Backport Time Sync changes to WUTS (#24)
Browse files Browse the repository at this point in the history
* created upstream branch

--HG--
branch : upstream

* backported changes to upstream

--HG--
branch : upstream

* fixed a typo, now the sync option should work properly

--HG--
branch : upstream

* backported changes to upstream

--HG--
branch : upstream

* Backported to upstream.

--HG--
branch : upstream

* Backported to upstream.

--HG--
branch : upstream

* Backported changes.

--HG--
branch : upstream

* Backported changes to upstream.

--HG--
branch : upstream

* Merged libcurlwrapper and timezone service changes.

--HG--
branch : upstream

* Forgot to add curl-related sources.

--HG--
branch : upstream

* Backported Time Sync changes to upstream.

--HG--
branch : upstream

* Update workflow to use git submodules.

--HG--
branch : upstream

---------

Co-authored-by: Daniel K. O. (dkosmari) <none@none>
  • Loading branch information
dkosmari and Daniel K. O. (dkosmari) authored Sep 14, 2024
1 parent a931797 commit 52ee4d7
Show file tree
Hide file tree
Showing 76 changed files with 1,259 additions and 2,625 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 1
submodules: true

- name: Build Binary
run: |
Expand All @@ -21,4 +22,4 @@ jobs:
with:
name: Wii_U_Time_Sync.wps
path: "*.wps"
if-no-files-found: error
if-no-files-found: error
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/libwupsxx"]
path = external/libwupsxx
url = https://github.com/dkosmari/libwupsxx.git
16 changes: 5 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ WUT_ROOT := $(DEVKITPRO)/wut
# PLUGIN_AUTHOR sets the author of the plugin.
# PLUGIN_LICENSE sets the license of the plugin.
#-------------------------------------------------------------------------------
PLUGIN_NAME := Wii U Time Sync
PLUGIN_DESCRIPTION := A plugin that synchronizes the system clock to the Internet.
PLUGIN_VERSION := v3.1.0
PLUGIN_AUTHOR := Nightkingale, Daniel K. O.
PLUGIN_LICENSE := MIT
PLUGIN_NAME := Wii U Time Sync
PLUGIN_VERSION := v3.1.0+

#-------------------------------------------------------------------------------
# TARGET is the name of the output.
Expand All @@ -35,9 +32,9 @@ PLUGIN_LICENSE := MIT
#-------------------------------------------------------------------------------
TARGET := Wii_U_Time_Sync
BUILD := build
SOURCES := source source/net source/wupsxx
SOURCES := source source/net external/libwupsxx/src
DATA := data
INCLUDES := include
INCLUDES := include external/libwupsxx/include

#-------------------------------------------------------------------------------
# DEBUG sets the debug flag for the plugin.
Expand Down Expand Up @@ -65,10 +62,7 @@ CFLAGS := $(WARN_FLAGS) $(OPTFLAGS) $(MACHDEP)
CXXFLAGS := $(CFLAGS) -std=c++23

DEFINES := '-DPLUGIN_NAME="$(PLUGIN_NAME)"' \
'-DPLUGIN_DESCRIPTION="$(PLUGIN_DESCRIPTION)"' \
'-DPLUGIN_VERSION="$(PLUGIN_VERSION)"' \
'-DPLUGIN_AUTHOR="$(PLUGIN_AUTHOR)"' \
'-DPLUGIN_LICENSE="$(PLUGIN_LICENSE)"'
'-DPLUGIN_VERSION="$(PLUGIN_VERSION)"'

# Note: INCLUDE will be defined later, so CPPFLAGS has to be of the recursive flavor.
CPPFLAGS = $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ $(DEFINES)
Expand Down
1 change: 1 addition & 0 deletions external/libwupsxx
Submodule libwupsxx added at 806e94
8 changes: 7 additions & 1 deletion include/async_queue.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef ASYNC_QUEUE_HPP
#define ASYNC_QUEUE_HPP
Expand Down
56 changes: 13 additions & 43 deletions include/cfg.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
* Copyright (C) 2024 Nightkingale
*
* SPDX-License-Identifier: MIT
*/

#ifndef CFG_HPP
#define CFG_HPP
Expand All @@ -9,62 +16,25 @@

namespace cfg {

namespace key {
extern const char* auto_tz;
extern const char* msg_duration;
extern const char* notify;
extern const char* server;
extern const char* sync;
extern const char* threads;
extern const char* timeout;
extern const char* tolerance;
extern const char* tz_service;
extern const char* utc_offset;
}


namespace label {
extern const char* auto_tz;
extern const char* msg_duration;
extern const char* notify;
extern const char* server;
extern const char* sync;
extern const char* threads;
extern const char* timeout;
extern const char* tolerance;
extern const char* tz_service;
extern const char* utc_offset;
}

namespace defaults {
extern const bool auto_tz;
extern const std::chrono::seconds msg_duration;
extern const int notify;
extern const std::string server;
extern const bool sync;
extern const int threads;
extern const std::chrono::seconds timeout;
extern const std::chrono::milliseconds tolerance;
extern const int tz_service;
}


extern bool auto_tz;
extern std::chrono::seconds msg_duration;
extern int notify;
extern std::string server;
extern bool sync;
extern bool sync_on_boot;
extern bool sync_on_changes;
extern int threads;
extern std::chrono::seconds timeout;
extern std::chrono::milliseconds tolerance;
extern int tz_service;
extern std::chrono::minutes utc_offset;

void save_important_vars();

void init();

void load();
void reload();
void save();
void migrate_old_config();

void set_and_store_utc_offset(std::chrono::minutes tz_offset);

Expand Down
37 changes: 25 additions & 12 deletions include/clock_item.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef CLOCK_ITEM_HPP
#define CLOCK_ITEM_HPP
Expand All @@ -7,35 +13,42 @@
#include <memory> // unique_ptr<>
#include <string>

#include "wupsxx/text_item.hpp"
#include <wupsxx/button_item.hpp>
#include <wupsxx/text_item.hpp>


struct clock_item : wups::config::text_item {
struct clock_item : wups::config::button_item {

struct server_info {
text_item* name = nullptr;
text_item* correction = nullptr;
text_item* latency = nullptr;
wups::config::text_item* name = nullptr;
wups::config::text_item* correction = nullptr;
wups::config::text_item* latency = nullptr;
};


std::string now_str;
std::string stats_str;
std::string diff_str;
std::map<std::string, server_info> server_infos;


clock_item();

static
std::unique_ptr<clock_item> create();
std::unique_ptr<clock_item>
create();


virtual
void
on_started() override;

void on_input(WUPSConfigSimplePadData input,
WUPS_CONFIG_SIMPLE_INPUT repeat) override;

void
update_status_msg();

void refresh_now_str();

void run();
void
run();

};

Expand Down
11 changes: 0 additions & 11 deletions include/config_screen.hpp

This file was deleted.

16 changes: 13 additions & 3 deletions include/core.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef CORE_HPP
#define CORE_HPP

#include <stop_token>
#include <string>
#include <utility> // pair<>

Expand All @@ -14,9 +21,12 @@ namespace core {

using time_utils::dbl_seconds;

std::pair<dbl_seconds, dbl_seconds> ntp_query(net::address address);
std::pair<dbl_seconds, dbl_seconds> ntp_query(std::stop_token token,
net::address address);

void run();
void
run(std::stop_token token,
bool silent);

std::string local_clock_to_string();

Expand Down
8 changes: 7 additions & 1 deletion include/curl.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef CURL_HPP
#define CURL_HPP
Expand Down
8 changes: 7 additions & 1 deletion include/http_client.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef HTTP_CLIENT_HPP
#define HTTP_CLIENT_HPP
Expand Down
18 changes: 0 additions & 18 deletions include/logging.hpp

This file was deleted.

8 changes: 7 additions & 1 deletion include/net/address.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef NET_ADDRESS_HPP
#define NET_ADDRESS_HPP
Expand Down
8 changes: 7 additions & 1 deletion include/net/addrinfo.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef NET_ADDRINFO_HPP
#define NET_ADDRINFO_HPP
Expand Down
8 changes: 7 additions & 1 deletion include/net/error.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef NET_ERROR_HPP
#define NET_ERROR_HPP
Expand Down
12 changes: 9 additions & 3 deletions include/net/socket.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: MIT
/*
* Wii U Time Sync - A NTP client plugin for the Wii U.
*
* Copyright (C) 2024 Daniel K. O.
*
* SPDX-License-Identifier: MIT
*/

#ifndef NET_SOCKET_HPP
#define NET_SOCKET_HPP
Expand All @@ -13,8 +19,8 @@
#include <poll.h>
#include <sys/socket.h> // SO_*, MSG_*

#include "net/address.hpp"
#include "net/error.hpp"
#include "address.hpp"
#include "error.hpp"


// Note: very simplified socket class, only what the Wii U supports.
Expand Down
Loading

0 comments on commit 52ee4d7

Please sign in to comment.