-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Add ashell example and a tag to detect that a process shou…
…ld run only once
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
/* SPDX-License-Identifier: GPL-3.0-or-later */ | ||
|
||
#include <functional> | ||
#include <string> | ||
#include <thread> | ||
namespace examples | ||
{ | ||
struct Shell | ||
{ | ||
static consteval auto name() { return "Shell command"; } | ||
static consteval auto c_name() { return "avnd_shell"; } | ||
static consteval auto category() { return "Script"; } | ||
static consteval auto uuid() { return "7e4ae744-1825-4f1c-9fc9-675e41f316bc"; } | ||
|
||
// This tag is an indication that the operator() should only called on | ||
// the first tick, not on every tick | ||
enum | ||
{ | ||
single_exec | ||
}; | ||
|
||
struct | ||
{ | ||
struct | ||
{ | ||
static constexpr auto name() { return "Script"; } | ||
static constexpr auto language() { return "shell"; } | ||
enum widget | ||
{ | ||
textedit | ||
}; | ||
|
||
struct range | ||
{ | ||
const std::string_view init = "#!/bin/bash\n"; | ||
}; | ||
std::string value; | ||
} command; | ||
} inputs; | ||
|
||
struct | ||
{ | ||
} outputs; | ||
|
||
void operator()() { worker.request(std::move(inputs.command.value)); } | ||
|
||
struct worker | ||
{ | ||
std::function<void(std::string)> request; | ||
static void work(std::string&& s) | ||
{ | ||
std::thread{[code = std::move(s)] { ::system(code.c_str()); }}.detach(); | ||
} | ||
} worker; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
/* SPDX-License-Identifier: GPL-3.0-or-later OR BSL-1.0 OR CC0-1.0 OR CC-PDCC OR 0BSD */ | ||
|
||
#include <avnd/common/concepts_polyfill.hpp> | ||
#include <avnd/common/enums.hpp> | ||
#include <avnd/concepts/generic.hpp> | ||
|
||
namespace avnd | ||
{ | ||
/** | ||
* @brief single_exec tag: the 'process' method should only be called once | ||
* per execution. | ||
* | ||
* Example: in ossia, this means that the processor can be assigned to a state. | ||
*/ | ||
AVND_DEFINE_TAG(single_exec) | ||
} |