Skip to content

Commit 493cf2e

Browse files
committed
Move system library to fly::system namespace
Also changes fly::System class to be free functions, rather than a class.
1 parent 94a342a commit 493cf2e

30 files changed

+134
-227
lines changed

build/nix/Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ $(eval $(call EXCLUDE_FROM_STYLE_ENFORCEMENT, extern/))
1919
# 1. Ignore test files.
2020
# 2. Ignore benchmarking files.
2121
# 3. Ignore external third-party files.
22-
# 4. Ignore system_impl.hpp - this file is entirely constexpr functions that do not execute at
23-
# runtime, which llvm-cov doesn't seem to recognize.
24-
# 5. Ignore literal_parser.hpp - this file is entirely constexpr functions that do not execute at
22+
# 4. Ignore literal_parser.hpp - this file is entirely constexpr functions that do not execute at
2523
# runtime, which llvm-cov doesn't seem to recognize.
2624
$(eval $(call EXCLUDE_FROM_COVERAGE, test/))
2725
$(eval $(call EXCLUDE_FROM_COVERAGE, bench/))
2826
$(eval $(call EXCLUDE_FROM_COVERAGE, extern/))
29-
$(eval $(call EXCLUDE_FROM_COVERAGE, fly/system/nix/system_impl.hpp))
3027
$(eval $(call EXCLUDE_FROM_COVERAGE, fly/types/numeric/detail/literal_parser.hpp))
3128

3229
# Paths to exclude from generation of compilation database.

build/win/libfly/libfly.vcxproj

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@
199199
<ClInclude Include="..\..\..\fly\system\system.hpp" />
200200
<ClInclude Include="..\..\..\fly\system\system_config.hpp" />
201201
<ClInclude Include="..\..\..\fly\system\system_monitor.hpp" />
202-
<ClInclude Include="..\..\..\fly\system\win\system_impl.hpp" />
203202
<ClInclude Include="..\..\..\fly\system\win\system_monitor_impl.hpp" />
204203
<ClInclude Include="..\..\..\fly\task\task_manager.hpp" />
205204
<ClInclude Include="..\..\..\fly\task\task_runner.hpp" />

build/win/libfly/libfly.vcxproj.filters

-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@
208208
<ClInclude Include="..\..\..\fly\system\system_monitor.hpp">
209209
<Filter>system</Filter>
210210
</ClInclude>
211-
<ClInclude Include="..\..\..\fly\system\win\system_impl.hpp">
212-
<Filter>system\win</Filter>
213-
</ClInclude>
214211
<ClInclude Include="..\..\..\fly\system\win\system_monitor_impl.hpp">
215212
<Filter>system\win</Filter>
216213
</ClInclude>

fly/logger/detail/console_sink.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool ConsoleSink::stream(fly::Log &&log)
4747

4848
{
4949
auto styler = color ? fly::Styler(std::move(style), *std::move(color)) : fly::Styler(style);
50-
*stream << styler << String::format("{} {}", fly::System::local_time(), log.m_trace);
50+
*stream << styler << String::format("{} {}", fly::system::local_time(), log.m_trace);
5151
}
5252

5353
*stream << ": " << log.m_message << std::endl;

fly/logger/detail/file_sink.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool FileSink::create_log_file()
7070
}
7171

7272
const std::string random = fly::String::generate_random_string(10);
73-
std::string time = fly::System::local_time();
73+
std::string time = fly::system::local_time();
7474

7575
fly::String::replace_all(time, ":", '-');
7676
fly::String::replace_all(time, " ", '_');

fly/logger/logger.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
fly::Logger::get_default_logger()->warn( \
8080
{__FILE__, __FUNCTION__, static_cast<std::uint32_t>(__LINE__)}, \
8181
FLY_FORMAT_STRING(__VA_ARGS__) ": {}" FLY_FORMAT_ARGS(__VA_ARGS__), \
82-
fly::System::get_error_string()); \
82+
fly::system::get_error_string()); \
8383
} while (0)
8484

8585
/**

fly/net/socket/detail/nix/socket_operations.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ accept(fly::net::socket_type handle, EndpointType &endpoint, bool &would_block)
301301

302302
if (client == invalid_socket())
303303
{
304-
would_block = fly::System::get_error_code() == EWOULDBLOCK;
304+
would_block = fly::system::get_error_code() == EWOULDBLOCK;
305305
SLOGS(handle, "Error accepting");
306306

307307
return std::nullopt;
@@ -325,7 +325,7 @@ fly::net::ConnectedState connect(fly::net::socket_type handle, const EndpointTyp
325325

326326
if (::connect(handle, base(address), sizeof(address)) == -1)
327327
{
328-
const int error = fly::System::get_error_code();
328+
const int error = fly::system::get_error_code();
329329
SLOGS(handle, "Error connecting");
330330

331331
if ((error == EINTR) || (error == EINPROGRESS))
@@ -371,7 +371,7 @@ std::size_t send(fly::net::socket_type handle, std::string_view message, bool &w
371371

372372
if (status == -1)
373373
{
374-
would_block = fly::System::get_error_code() == EWOULDBLOCK;
374+
would_block = fly::system::get_error_code() == EWOULDBLOCK;
375375
SLOGS(handle, "Error sending");
376376
}
377377
}
@@ -416,7 +416,7 @@ std::size_t send_to(
416416

417417
if (status == -1)
418418
{
419-
would_block = fly::System::get_error_code() == EWOULDBLOCK;
419+
would_block = fly::system::get_error_code() == EWOULDBLOCK;
420420
SLOGS(handle, "Error sending");
421421
}
422422
}
@@ -455,7 +455,7 @@ std::string recv(fly::net::socket_type handle, std::size_t packet_size, bool &wo
455455
{
456456
if (status == -1)
457457
{
458-
would_block = fly::System::get_error_code() == EWOULDBLOCK;
458+
would_block = fly::system::get_error_code() == EWOULDBLOCK;
459459
SLOGS(handle, "Error receiving");
460460
}
461461

@@ -491,7 +491,7 @@ std::string recv_from(
491491
{
492492
if (status == -1)
493493
{
494-
would_block = fly::System::get_error_code() == EWOULDBLOCK;
494+
would_block = fly::system::get_error_code() == EWOULDBLOCK;
495495
SLOGS(handle, "Error receiving");
496496
}
497497

fly/net/socket/detail/win/socket_operations.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ accept(fly::net::socket_type handle, EndpointType &endpoint, bool &would_block)
311311

312312
if (client == invalid_socket())
313313
{
314-
const int error = fly::System::get_error_code();
314+
const int error = fly::system::get_error_code();
315315

316316
would_block = (error == WSAEWOULDBLOCK) || (error == WSAEINPROGRESS);
317317
SLOGS(handle, "Error accepting");
@@ -337,7 +337,7 @@ fly::net::ConnectedState connect(fly::net::socket_type handle, const EndpointTyp
337337

338338
if (::connect(handle, base(address), sizeof(address)) == SOCKET_ERROR)
339339
{
340-
const int error = fly::System::get_error_code();
340+
const int error = fly::system::get_error_code();
341341
SLOGS(handle, "Error connecting");
342342

343343
if ((error == WSAEWOULDBLOCK) || (error == WSAEINPROGRESS))
@@ -388,7 +388,7 @@ std::size_t send(fly::net::socket_type handle, std::string_view message, bool &w
388388

389389
if (status == SOCKET_ERROR)
390390
{
391-
would_block = fly::System::get_error_code() == WSAEWOULDBLOCK;
391+
would_block = fly::system::get_error_code() == WSAEWOULDBLOCK;
392392
SLOGS(handle, "Error sending");
393393
}
394394
}
@@ -433,7 +433,7 @@ std::size_t send_to(
433433

434434
if (status == SOCKET_ERROR)
435435
{
436-
would_block = fly::System::get_error_code() == WSAEWOULDBLOCK;
436+
would_block = fly::system::get_error_code() == WSAEWOULDBLOCK;
437437
SLOGS(handle, "Error sending");
438438
}
439439
}
@@ -473,7 +473,7 @@ std::string recv(fly::net::socket_type handle, std::size_t packet_size, bool &wo
473473
{
474474
if (status == SOCKET_ERROR)
475475
{
476-
would_block = fly::System::get_error_code() == WSAEWOULDBLOCK;
476+
would_block = fly::system::get_error_code() == WSAEWOULDBLOCK;
477477
SLOGS(handle, "Error receiving");
478478
}
479479

@@ -509,7 +509,7 @@ std::string recv_from(
509509
{
510510
if (status == SOCKET_ERROR)
511511
{
512-
would_block = fly::System::get_error_code() == WSAEWOULDBLOCK;
512+
would_block = fly::system::get_error_code() == WSAEWOULDBLOCK;
513513
SLOGS(handle, "Error receiving");
514514
}
515515

fly/path/nix/path_monitor_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ bool PathMonitorImpl::read_events()
8787

8888
if (size <= 0)
8989
{
90-
if ((size == -1) && (System::get_error_code() != EAGAIN))
90+
if ((size == -1) && (fly::system::get_error_code() != EAGAIN))
9191
{
9292
LOGS("Could not read polled event");
9393
}

fly/system/mac/mach_api.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <mach/mach.h>
44

5-
namespace fly::detail {
5+
namespace fly::system::detail {
66

77
/**
88
* Fetch basic information about this macOS host. Uses the following structures and methods:
@@ -110,4 +110,4 @@ bool task_basic_info(task_basic_info_64_data_t &task_info);
110110
*/
111111
bool task_thread_times(task_thread_times_info_data_t &thread_times);
112112

113-
} // namespace fly::detail
113+
} // namespace fly::system::detail

fly/system/mac/mach_api.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "fly/logger/logger.hpp"
44

5-
namespace fly::detail {
5+
namespace fly::system::detail {
66

77
namespace {
88

fly/system/mac/system_impl.hpp

-4
This file was deleted.

fly/system/mac/system_monitor_impl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace fly::task {
99
class SequencedTaskRunner;
1010
} // namespace fly::task
1111

12-
namespace fly {
12+
namespace fly::system {
1313

1414
class SystemConfig;
1515

@@ -49,4 +49,4 @@ class SystemMonitorImpl : public SystemMonitor
4949
std::chrono::steady_clock::time_point m_prev_time;
5050
};
5151

52-
} // namespace fly
52+
} // namespace fly::system

fly/system/mac/system_monitor_impl.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#import <Foundation/Foundation.h>
88

9-
namespace fly {
9+
namespace fly::system {
1010

1111
namespace {
1212

fly/system/nix/system_impl.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "fly/system/nix/system_impl.hpp"
1+
#include "fly/system/system.hpp"
22

33
#include <execinfo.h>
44
#include <unistd.h>
@@ -7,10 +7,10 @@
77
#include <chrono>
88
#include <cstring>
99

10-
namespace fly {
10+
namespace fly::system {
1111

1212
//==================================================================================================
13-
void SystemImpl::print_backtrace()
13+
void print_backtrace()
1414
{
1515
void *trace[10];
1616
int trace_size = ::backtrace(trace, 10);
@@ -22,7 +22,7 @@ void SystemImpl::print_backtrace()
2222
}
2323

2424
//==================================================================================================
25-
std::string SystemImpl::local_time(const char *fmt)
25+
std::string local_time()
2626
{
2727
auto sys = std::chrono::system_clock::now();
2828
time_t now = std::chrono::system_clock::to_time_t(sys);
@@ -34,7 +34,7 @@ std::string SystemImpl::local_time(const char *fmt)
3434
{
3535
char time_str[32];
3636

37-
if (::strftime(time_str, sizeof(time_str), fmt, &time_val) != 0)
37+
if (::strftime(time_str, sizeof(time_str), "%m-%d-%Y %H:%M:%S", &time_val) != 0)
3838
{
3939
result = std::string(time_str);
4040
}
@@ -44,9 +44,9 @@ std::string SystemImpl::local_time(const char *fmt)
4444
}
4545

4646
//==================================================================================================
47-
int SystemImpl::get_error_code()
47+
int get_error_code()
4848
{
4949
return errno;
5050
}
5151

52-
} // namespace fly
52+
} // namespace fly::system

fly/system/nix/system_impl.hpp

-28
This file was deleted.

fly/system/nix/system_monitor_impl.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "fly/logger/logger.hpp"
44
#include "fly/system/system_config.hpp"
55
#include "fly/task/task_runner.hpp"
6-
#include "fly/types/string/string.hpp"
76

87
#include <sys/sysinfo.h>
98
#include <sys/times.h>
@@ -13,7 +12,7 @@
1312
#include <fstream>
1413
#include <string>
1514

16-
namespace fly {
15+
namespace fly::system {
1716

1817
namespace {
1918

@@ -175,4 +174,4 @@ void SystemMonitorImpl::update_process_memory_usage()
175174
}
176175
}
177176

178-
} // namespace fly
177+
} // namespace fly::system

fly/system/nix/system_monitor_impl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace fly::task {
99
class SequencedTaskRunner;
1010
} // namespace fly::task
1111

12-
namespace fly {
12+
namespace fly::system {
1313

1414
class SystemConfig;
1515

@@ -49,4 +49,4 @@ class SystemMonitorImpl : public SystemMonitor
4949
clock_t m_prev_time {0};
5050
};
5151

52-
} // namespace fly
52+
} // namespace fly::system

0 commit comments

Comments
 (0)