- Create a new folder in
src/app/system
example:src/app/system/TestSystem
- Create a main typescript file for your system example:
src/app/system/TestSystem/system.ts
- Create a main class with a kernel
export class TestSystem extends Kernel { }
- Implements all members:
import {Kernel} from "@Napicu/System/Kernel/NapicuKernel";
import {CookiesConfigurator} from "@Napicu/System/Kernel/core/CookiesConfigurator";
import {SystemCookiesKernelDataInterface} from "@Napicu/System/Kernel/interface/Kernel";
export class TestSystem extends Kernel {
protected readonly system_name: string = "system";
public system_config: CookiesConfigurator<SystemCookiesKernelDataInterface<any>> =
new CookiesConfigurator<SystemCookiesKernelDataInterface<any>>("config", {data: {}});
protected main(): void { }
}
- Add a new system to the bootloader config in
src/app/config/hardware/ComputerHardware.ts
:
partitions: [
{
flag: "Boot",
data: {
files: {},
folders: {
data: {
boot: {
files: {
grub: {data: new Grub([new TestSystem()])} //<----- Here
},
folders: {}
}
}
}
}
}
]
- Create a new folder for processes example:
src/app/system/TestSystem/programs
- Creat a new typescript class
src/app/system/TestSystem/programs/TestProgram.ts
example:
import {Process} from "@Napicu/System/Kernel/core/Process";
export class TestProgram extends Process {
protected process_name: string = "Program";
protected on_kill = (): void => { }
protected main(): void { }
}
- Implement a new process into the system:
import {Kernel} from "@Napicu/System/Kernel/NapicuKernel";
import {CookiesConfigurator} from "@Napicu/System/Kernel/core/CookiesConfigurator";
import {SystemCookiesKernelDataInterface} from "@Napicu/System/Kernel/interface/Kernel";
import {TestProgram} from "./programs/program";
import {ProcessManagerProcessTable} from "@Napicu/System/Kernel/interface/Process";
export class TestSystem extends Kernel {
protected readonly system_name: string = "system";
public system_config: CookiesConfigurator<SystemCookiesKernelDataInterface<any>> =
new CookiesConfigurator<SystemCookiesKernelDataInterface<any>>("config", {data: {}});
public readonly initialized_system_process_table: ProcessManagerProcessTable[] = [
{ process: TestProgram, program_id: 1 },
]
protected main(): void {
//Init processes
this.init_process_table(this.initialized_system_process_table);
}
}
- Run a process:
protected main(): void {
//Init processes
this.init_process_table(this.initialized_system_process_table);
//Run a process with program_id 1
this.process_manager.run(1);
}
protected main(): void {
let p: TestProgram | null = this.get_process_manager().get_running_process_class<TestProgram>(TestProgram);
if(p) {
// Do something...
}
}
- Create a new folder for processes example:
src/app/system/TestSystem/commands
- Creat a new typescript class
src/app/system/TestSystem/commands/HelloWorld.ts
example:
import {Command} from "@Napicu/System/Kernel/core/Command";
import {Kernel} from "@Napicu/System/Kernel/NapicuKernel";
import {CommandsResolveCodes} from "@Napicu/System/Kernel/interface/CommandResolve";
import {CommandResolve} from "@Napicu/System/Kernel/core/CommandResolve";
export class HelloWorldCommand extends Command {
protected main(kernel: Kernel, args: string[]): CommandPromise {
return new Promise<CommandResolve>((resolve, reject) => {
console.log("Hello World");
resolve(new CommandResolve({code: CommandsResolveCodes.success}));
});
}
}
- Implement a new command into the system:
import {Kernel} from "@Napicu/System/Kernel/NapicuKernel";
import {CookiesConfigurator} from "@Napicu/System/Kernel/core/CookiesConfigurator";
import {SystemCookiesKernelDataInterface} from "@Napicu/System/Kernel/interface/Kernel";
import {TestProgram} from "./programs/program";
import {ProcessManagerProcessTable} from "@Napicu/System/Kernel/interface/Process";
import {HelloWorldCommand} from "./commands/HelloWorld"
export class TestSystem extends Kernel{
protected readonly system_name: string = "system";
public system_config: CookiesConfigurator<SystemCookiesKernelDataInterface<any>> =
new CookiesConfigurator<SystemCookiesKernelDataInterface<any>>("config", {data: {}});
public readonly initialized_system_process_table: ProcessManagerProcessTable[] = [
{ process: TestProgram, program_id: 1 },
]
public readonly initialized_system_command_table: CommandManagerTable[] = [
{ command: HelloWorldCommand, call: "helloworld" },
]
protected main(): void {
//Init processes
this.init_process_table(this.initialized_system_process_table);
//Init commands
this.init_commands_table(this.initialized_system_command_table);
}
}
- Run a command:
protected main(): void {
//Init commands
this.init_commands_table(this.initialized_system_command_table);
//Run a helloworld command
this.run_command("helloworld");
}
- Import
CommandsResolveCodes
andCommandResolve
:
import {CommandsResolveCodes} from "@Napicu/System/Kernel/interface/CommandResolve";
import {CommandResolve} from "@Napicu/System/Kernel/core/CommandResolve";
Example:
protected main(): void {
this.run_command("hello_world").then((value: CommandResolve) => {}, (value: CommandResolve) => {
if(value.code == CommandsResolveCodes.command_not_found) {
console.log("Command does not exist!");
}
});
}
export class HelloWorldCommand extends Command {
protected main(kernel: Kernel, args: string[]): CommandPromise {
return new Promise<CommandResolve>((resolve, reject) => {
console.log(args) //Example: ["-a"]
this.get_param(args, "-a", () => {
resolve(new CommandResolve({code: CommandsResolveCodes.success, message: "Hello World #1"}));
});
console.log(args) //Example: [] - Now the 'args' array does not contain '-a'.
resolve(new CommandResolve({code: CommandsResolveCodes.success, message: "Hello World #2"}));
});
}
}
Now when you add -a
to the command, you get a different output.