Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge! #1460

Merged
merged 4 commits into from
Dec 1, 2023
Merged

Merge! #1460

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 73 additions & 17 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
},
"externalConsole": false,
"linux": {
"name": "Local Debug WPEFramework on Linux",
"program": "${config:thunder.installPath}/usr/bin/WPEFramework",
"type":"cppdbg",
"request": "launch",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
Expand All @@ -34,11 +31,16 @@
"ignoreFailures": true
}
],
"sourceFileMap": {
},
"sourceFileMap": {},
"environment": [
{ "name": "LD_LIBRARY_PATH", "value": "${config:thunder.installPath}/usr/lib" },
{ "name": "PATH", "value": "${config:thunder.installPath}/usr/bin"},
{
"name": "LD_LIBRARY_PATH",
"value": "${config:thunder.installPath}/usr/lib"
},
{
"name": "PATH",
"value": "${config:thunder.installPath}/usr/bin"
},
],
"additionalSOLibSearchPath": "${config:thunder.installPath}/usr/lib;/usr/local/lib;/usr/lib;/lib",
},
Expand All @@ -55,21 +57,17 @@
"trace": false,
"traceResponse": false,
"engineLogging": false,
},
},
"linux": {
"name": "Remote Debug WPEFramework on Linux",
"program": "${config:thunder.installPath}/usr/bin/WPEFramework",
"type":"cppdbg",
"request": "launch",
"MIMode": "gdb",
"miDebuggerServerAddress": "${config:thunder.remoteTargetHost}:${config:thunder.remoteTargetDebugPort}",
"miDebuggerPath": "${config:thunder.crossToolsPath}/${config:thunder.crossToolsPrefix}gdb",
"miDebuggerArgs": "",
"setupCommands": [
{"text": "-enable-pretty-printing"},
// commands if gdbserver is started with --multi
// {"text": "target extended-remote ${config:thunder.remoteTargetHost}:${config:thunder.remoteTargetDebugPort}"},
// {"text": "set remote exec-file WPEFramework"}
{
"text": "-enable-pretty-printing"
},
],
"sourceFileMap": {
// "remote": "local"
Expand All @@ -80,6 +78,64 @@
"preLaunchTask": "Prepare WPEFramework for remote gdb debugging",
"postDebugTask": "Clean debugging run"
}
}
},
// Start GBD on target with:
// sshpass -v -p <password> ssh -t <user>:<address> "killall -9 gdbserver; gdbserver --multi :55550"
// or with a certificate:
// ssh -i <path/to/private/key> -t <user>:<address> "killall -9 gdbserver; gdbserver --multi :55550"
{
"name": "Remote GDB (multi) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${config:thunder.installPath}/usr/bin/WPEFramework-1.0.0",
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"stopAtEntry": false,
"targetArchitecture": "arm",
"MIMode": "gdb",
"miDebuggerPath": "${config:thunder.crossToolsPath}/${config:thunder.crossToolsPrefix}gdb",
"miDebuggerServerAddress": "${config:thunder.remoteTargetHost}:${config:thunder.remoteTargetDebugPort}",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
],
"customLaunchSetupCommands": [
{
"text": "file ${config:thunder.installPath}/usr/bin/WPEFramework-1.0.0",
"description": "Load symbols",
"ignoreFailures": false
},
{
"text": "target extended-remote ${config:thunder.remoteTargetHost}:${config:thunder.remoteTargetDebugPort}",
"description": "Connect to gdbserver",
"ignoreFailures": false
},
{
"text": "remote put ${config:thunder.installPath}/usr/bin/WPEFramework-1.0.0 /usr/bin/WPEFramework-1.0.0",
"description": "Copy the locally cross-compiled executable to the target",
"ignoreFailures": false
},
{
"text": "set remote exec-file /usr/bin/WPEFramework-1.0.0",
"description": "Set the executable to be debugged",
"ignoreFailures": false
},
{
"text": "set args -c/etc/WPEFramework/config.json",
"description": "Set Arguments for the executable",
"ignoreFailures": false
},
{
"text": "tbreak main",
"description": "Set temporary breakpoint @main()",
"ignoreFailures": false
}
],
"launchCompleteCommand": "exec-run"
},
]
}
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"PORT":"55555",
"BINDING":"127.0.0.1",
"IDLE_TIME":"180",
"BUILD_SHARED_LIBS" : "ON"
}
}
32 changes: 32 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@
"focus": true,
"close": true
}
},
{
"label": "Start multi gdbserver",
"type": "process",
"command": "ssh",
"args": [
"-i",
"${config:thunder.remoteTargetID}",
"${config:thunder.remoteTargetUser}@${config:thunder.remoteTargetHost}",
"killall -9 gdbserver; gdbserver --multi :55550"
],
"isBackground": true,
"problemMatcher": {
"pattern": {
"regexp": ".*",
"file": 1,
"line": 1,
"message": 1
},
"background": {
"activeOnStart": true,
"beginsPattern": "^.*Listening on port*",
"endsPattern": "^.*"
}
},
"presentation": {
"reveal": "always",
"panel": "dedicated",
"clear": true,
"focus": true,
"close": true
}
}
],
}
10 changes: 8 additions & 2 deletions Source/WPEFramework/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ POP_WARNING()
#endif

Messaging::MessageUnit::Instance().Close();
Messaging::ConsoleStandardError::Instance().Close();
if (_background == true) {
Messaging::ConsoleStandardOut::Instance().Close();
}

#ifndef __WINDOWS__
if (_background) {
Expand All @@ -251,7 +255,10 @@ POP_WARNING()
fprintf(stdout, EXPAND_AND_QUOTE(APPLICATION_NAME) " completely stopped.\n");
fflush(stderr);
}

_atExitActive = false;

exit(0);
}

private:
Expand Down Expand Up @@ -326,7 +333,6 @@ POP_WARNING()
sigaction(SIGSEGV, &_originalSegmentationHandler, nullptr);
sigaction(SIGABRT, &_originalAbortHandler, nullptr);


ExitHandler::DumpMetadata();

if (_background) {
Expand All @@ -336,7 +342,7 @@ POP_WARNING()
fflush(stderr);
}

ExitHandler::StartShutdown();
raise(signo);
}
else if (signo == SIGUSR1) {
ExitHandler::DumpMetadata();
Expand Down
60 changes: 60 additions & 0 deletions docs/utils/time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Time

Time as a non-constant continues to progress while existence of various events is being linked to each instance of time irrespective of the nature of such an event. Thunder has many types of events in which instances of time play a role. Their nature may be in the field of (process) communication by exchanging various messages, it may be related to the scheduling of (future) tasks or it may play some other role. The list of options is non-exhaustive.

## (Internal) representation

Thunder models time with instances described by elements of the [Gregorian calendar](https://en.wikipedia.org/wiki/Gregorian_calendar) with its epoch defined by [Unix time](https://en.wikipedia.org/wiki/Unix_time). That is, it models time as (strictly) monotomic increasing integer values. The elements year, month, day, hour, second, and millisecond allow for unique descriptions of Gregorian calendar time instances.

Set values can be individually retrieved. Time instances can be used in calculations and these instances can also be adjusted in millisecond decrements and increments.

Values are depicted with respect to the [UTC timezone](https://en.wikipedia.org/wiki/Coordinated_Universal_Time) unless otherwise specified. Alternatively, a derived convenience model incorporates local time and date offset by the timezone configured for the platform. The user conveniently can ignore any (underlying) offset.

```c++
// Local time instead of UTC
Core::Time past(/*year*/ 2023, /*month*/ 10, /*day*/ 13, /*hours*/ 18, /*minutes*/ 02, /*seconds*/ 0 ,/* milliseconds*/ 0, /*local time*/ true);
// Implicitly UTC
const Core::Time now(Core::Time::Now());

if (past.Add(1000) < now()) {
std::cout << "More than second has elapsed since "
<< past.WeekDayName() << ", "
<< past.MonthName() << " "
<< past.Day() << ", "
<< past.Hours() << ":"
<< past.Minutes() << ":"
<< past.Seconds() << "."
<< std::endl;
}

// Internally represent the past with our local timezone instead of UTC
TimeAsLocal local(past);
```

In the given example a time object is intialized to October 10 of the year 2023 at 18:02h and a second time object is initialized to the value of the system time. Note that the second object does not specify local time and hence it is silently set to reflect values for the UTC timezone. A final check is executed to test if past time is more than a second ago. For completeness a local time object is created from the object representing the past.

## Date and time conversion options

The external representation of time is a string formatted in a predefined pattern unless a single integer valued element is represented. Such patterns are intrinsically applied for the various conversions methods made available. It allows users to conveniently convert 'From' one representation 'To' another by using correspondingly named methods. Among such conversions are the [RFC2311](https://www.rfc-editor.org/rfc/rfc2311) time and date specification, [RFC1036](https://www.rfc-editor.org/rfc/rfc1036) date specification, the [ISO8601]() date and time formats, and, [ANSI](https://webstore.ansi.org/standards/incits/ansiincits301997) date representation.

Users that are interested in a format other than any provided by the Gregorian calendar representations may use *clock ticks*. Ticks are merely a conversion unit given from the multiplication of a constant value and the milliseconds value. Historically, it was a measure of runtime code execution on a CPU. Thunder has defined the multiplier constant equal to 1000.

Although most people typically work with a Gregorian scheme time values can be easily converted to [Julian calendar](https://en.wikipedia.org/wiki/Julian_calendar) representation, and, back. With its corresponding [Julian days](https://en.wikipedia.org/wiki/Julian_day) being analogous to elapsed seconds since the epoch of Unix time.

Finally, NTP conversions allows for incorporation of a different epoch. NTP epoch equals to 25567 seconds offset from its Unix time equivalent.

```c++
if (past.ToISO8601() == past.ToRFC1123()) {
std::cout << "It is very surprising to get here." << std::endl;
} else {
std::cout << "This is more likley to happen." << std::endl;
}

past.FromString("Sun Nov 6 08:49:00 1994");

if (past.JulianDate()) == 94310) {
std::cout << "The Julian date is equivalent to " << past.Ticks() / Core::Time::TicksPerMilliSecond / Core::Time::MilliSecondsPerSecond << " seconds from the epoch of Unix Time." << std::endl;"
}

```
The depicted example continues the previous example. Here, the different strings from the conversion methods typically have different patterns and do not equate equal. In addition, the past time object is re-inialized using the ANSI pattern to November 6 of the year 1994 at 08:49h which is equivalent to 94310 Julian days.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ nav:
- Threading:
- Worker Pool: utils/threading/worker-pool.md
- Mutexes: utils/threading/mutex.md
- Time: utils/time.md
- Timers: utils/timers.md
- Web Requests: utils/web.md
- Sockets: utils/sockets.md
Expand Down
Loading