Classes
Principle
Classes are essentials namespaces or domains for applications. On their own, classes have no real use or value, but when paired up with applications; classes can provide a powerful ecosystem to automate tasks in NTFX and perform otherwise not possible feats.
Schematic
Top Level Class
Top level classes are registered directly with the NTFX Registration Service ntfxcore.services.classregistrar
. This registration service is a local sub-process that runs on the Host OS
// Class Scheme
[ITR registrar]
mdl::_ntfx_srv->create_proto((mpdl3*) => {
int *rfClassIns = mpdl3->ntfx_core(0, "classregistrar", true);
power});
Creating a top level class is easy. Simply import the NTFX Api into the language of your choice. For supported languages we have a custom made API, for other langauges you can use the native managed or unmanaged API's.
Supported langauges with pacakges:
C/C++
C#
JavaScript
Other languages:
Common unmanaged DLL (ntfxapi.dll)
Common managed DLL (com.ntfx.api.dll)
Creating a class and sample application:
using NTFX.Api;
namespace MyApp {
[NTFXPublic]
[NTFXTopLevel]
public class MyCustomApp : IClassModelDiscrete
{
public string Name => "MyCustomApp";
public string FullName => "MyCustomApp";
public string Description => "Does stuff";
public string Version => new Version("1.0.0");
public List<IApplication> Applications { get; set; } = new()
{
new MyCustomAppInfo()
};
public List<IClass> Classes { get; set; } = null;
public static async Task<IClassRoute> GetBasicRoute(AppContext _context)
{
return new ClassRootTree()
{
{"MyCustomAppInfo", typeof(MyCustomAppInfo)}
};
}
}
[NTFXPublic]
public class MyCustomAppInfo : IApplicationModelStandard
{
public static async Task<IApplicationOutput> Execute(AppContext _context)
{
if (_context.SystemRunner.ZeroOp.InstructionOrigin === "host")
{
// Check if system runner has a zero op.
_context.IO.WriteFormatted("SystemRunner Info");
_context.IO.WriteFormatted("\repeat{=}{12}");
// Prints: "============"
_context.IO.WriteFormatted("Enabled: \green{true}");
// Prints: "Enabled: true"
// NTFX requires apps to exit rather than just return
return _context.ReturnVoid();
}
// Request NTFX to let this app run in the background
if (await _context.RequestBackgroundAccess())
{
_context.SetBackgroundThread(async (_ctx) => {
// This runs in the background
// The new context does not have write features and stuff
await _ctx.Wait(3000);
let res = await _ctx.RequestImmediateAttention();
if (res.Success)
{
// Our current app is now focused
res.context.WriteFormatted("Writing from a background app");
return res.context.Return(("My", "Sample", "Object"));
}
else
{
return _ctx.ReturnVoid();
}
});
return _context.ReturnStaleOutput();
}
return _context.ReturnVoid();
}
}
}
Last updated