This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,080 additions
and
1 deletion.
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
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,46 @@ | ||
# Hardware | ||
|
||
## Tentative API | ||
|
||
### Motherboard | ||
|
||
#### Action | ||
|
||
|
||
|
||
#### Query | ||
|
||
- get_resources(mobo_id) :: %{cpu: %{clock: x}, hdd: %{size: y, iops: z}} | ||
|
||
|
||
### Component | ||
|
||
#### Action | ||
|
||
#### Query | ||
|
||
- fetch(comp_id) | ||
|
||
- fetch_spec(spec_id) | ||
|
||
### Comments | ||
|
||
- components are global (can be used by any mobo) | ||
- mobos are specific per type of server | ||
- they (mobo) define most custom behaviour | ||
- components may receive server_type to further customize behaviour | ||
|
||
o Mainframe | ||
|
||
- main PC. must always be online. Must not be disassembled/taken offline | ||
|
||
o Durability | ||
|
||
- affects effective power for each resource (percentage multiplier *per component*) | ||
- consumption based on TOP's processed info (updated on ProcessCompletedEvent) | ||
|
||
o Orphaned components | ||
|
||
- orphaned components must be linked to their entity | ||
- effective power of the component must be persisted alongside it | ||
|
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,32 @@ | ||
defmodule Helix.Server.Componentable do | ||
|
||
use Helix.Server.Component.Flow | ||
|
||
component CPU do | ||
|
||
defstruct [:clock] | ||
|
||
def new(cpu = %{type: :cpu}) do | ||
%CPU{ | ||
clock: cpu.clock | ||
} | ||
end | ||
|
||
resource :clock | ||
end | ||
|
||
component HDD do | ||
|
||
defstruct [:size, :iops] | ||
|
||
def new(hdd = %{type: :hdd}) do | ||
%HDD{ | ||
size: hdd.size, | ||
iops: hdd.iops | ||
} | ||
end | ||
|
||
resource :size | ||
resource :iops | ||
end | ||
end |
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,83 @@ | ||
defmodule Helix.Server.Component.Flow do | ||
|
||
import HELL.Macros.Utils | ||
|
||
alias HELL.Utils | ||
|
||
defmacro __using__(_) do | ||
quote location: :keep do | ||
|
||
import unquote(__MODULE__) | ||
|
||
Module.register_attribute(__MODULE__, :components, accumulate: true) | ||
|
||
@before_compile unquote(__MODULE__) | ||
end | ||
end | ||
|
||
defmacro __before_compile__(_) do | ||
quote location: :keep do | ||
|
||
unquote(components_functions()) | ||
|
||
end | ||
end | ||
|
||
defp components_functions do | ||
quote do | ||
|
||
def get_resources(component) do | ||
dispatch(component.type, :new, [component]) | ||
end | ||
|
||
def dispatch(type, fun, args) do | ||
component_module = get_module_name(type) | ||
|
||
module = | ||
__MODULE__ | ||
|> Utils.concat_atom(".") | ||
|> Utils.concat_atom(component_module) | ||
|
||
apply(module, fun, args) | ||
end | ||
|
||
defp get_module_name(type) do | ||
type | ||
|> Atom.to_string() | ||
|> String.upcase() | ||
|> String.to_atom() | ||
end | ||
end | ||
end | ||
|
||
defmacro component(name, do: block) do | ||
comp_name = atomize_module_name(name) | ||
|
||
quote do | ||
|
||
Module.put_attribute( | ||
unquote(__CALLER__.module), | ||
:components, | ||
unquote(comp_name) | ||
) | ||
|
||
defmodule unquote(name) do | ||
|
||
unquote(block) | ||
end | ||
|
||
end | ||
end | ||
|
||
# Default behaviour is to get the given resource field directly. For custom | ||
# implementation, use `resource/2` | ||
defmacro resource(name) when is_atom(name) do | ||
quote do | ||
|
||
def unquote(:"get_#{name}")(component) do | ||
Map.fetch!(component, unquote(name)) | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.