Class: DGD::Manifest::DGDRuntimeConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/dgd-tools/manifest.rb

Constant Summary collapse

DEFAULT_CONFIG =
{
    users: 100,
    editors: 40,
    swap_size: 1048576,
    sector_size: 512,
    swap_fragment: 4096,
    static_chunk: 64512,
    dynamic_chunk: 261120,
    dump_interval: 3600,
    typechecking: 2,
    include_file: "/include/std.h",
    include_dirs: ["/include", "~/include"],
    auto_object: "/kernel/lib/auto",
    driver_object: "/kernel/sys/driver",
    create: "_F_create",
    array_size: 16384,
    objects: 262144,
    call_outs: 16384,
}
CONFIG_KEYS =
DEFAULT_CONFIG.keys.map(&:to_s) + [ "app_root", "ports", "telnet_ports", "dump_file", "statedir" ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_data) ⇒ DGDRuntimeConfig

Returns a new instance of DGDRuntimeConfig.



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/dgd-tools/manifest.rb', line 545

def initialize(config_data)
    @app_root = config_data["app_root"] || "app"
    @ports = {
        "*" => 50100,
    }
    @telnet_ports = {
        "*" => 50110,
    }
    @statedir = config_data["statedir"] || "state"
    @dump_file = if config_data["dump_file"]
            "../" + config_data["dump_file"]
        else
            "../#{@statedir}/dump"
        end
    @config = DEFAULT_CONFIG.dup

    @raw_data = config_data
    @config.keys.each do |prop|
        # For now, assume and require that JSON data is the correct type if present
        @config[prop] = config_data[prop.to_s] if config_data[prop.to_s]
    end
    unexpected_config_keys = config_data.keys - CONFIG_KEYS
    unless unexpected_config_keys.empty?
        raise "Unexpected key names in DGD configuration: #{unexpected_config_keys.inspect}!"
    end

    if config_data["telnet_ports"]
        @telnet_ports = config_to_ports(config_data["telnet_ports"])
    end
    if config_data["ports"]
        @ports = config_to_ports(config_data["ports"])
    end
end

Instance Attribute Details

#app_rootObject (readonly)

Returns the value of attribute app_root.



522
523
524
# File 'lib/dgd-tools/manifest.rb', line 522

def app_root
  @app_root
end

Instance Method Details

#as_fileObject



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/dgd-tools/manifest.rb', line 597

def as_file
    return <<DGD_CONFIG
telnet_port = ([
    #{@telnet_ports.map { |ip, p| "#{ip.inspect}:#{p}" }.join(",\n    ") }
]);   /* legacy telnet ports */
binary_port = ([
    #{@ports.map { |ip, p| "#{ip.inspect}:#{p}" }.join(",\n    ") }
]);   /* binary ports */
directory       = "./#{GENERATED_ROOT}";

users           = #{@config[:users]}; /* max # of connections */
editors         = #{@config[:editors]}; /* max # of built-in-editor sessions */
ed_tmpfile      = "../#{@statedir}/ed"; /* proto editor tmpfile */
swap_file       = "../#{@statedir}/swap"; /* swap file */
swap_size       = #{@config[:swap_size]}; /* # sectors in swap file */
sector_size     = #{@config[:sector_size]}; /* swap sector size */
swap_fragment   = #{@config[:swap_fragment]}; /* fragment to swap out */
static_chunk    = #{@config[:static_chunk]}; /* static memory chunk */
dynamic_chunk   = #{@config[:dynamic_chunk]}; /* dynamic memory chunk */
dump_file       = #{@dump_file.inspect}; /* dump file */
dump_interval   = #{@config[:dump_interval]}; /* expected statedump interval in seconds */

typechecking    = #{@config[:typechecking]}; /* level of typechecking (2 is highest) */
include_file    = #{@config[:include_file].inspect}; /* standard include file */
include_dirs    = ({ #{@config[:include_dirs].map(&:inspect).join(", ")} }); /* directories to search */
auto_object     = #{@config[:auto_object].inspect}; /* auto inherited object */
driver_object   = #{@config[:driver_object].inspect}; /* driver object */
create          = #{@config[:create].inspect}; /* name of create function */

array_size      = #{@config[:array_size]}; /* max array size */
objects         = #{@config[:objects]}; /* max # of objects */
call_outs       = #{@config[:call_outs]}; /* max # of callouts */
DGD_CONFIG
end

#config_to_ports(data) ⇒ Object



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/dgd-tools/manifest.rb', line 579

def config_to_ports(data)
    if data.is_a?(Hash)
        return data.map { |ip, port| [ip, Integer(port) ] }
    elsif data.is_a?(Array)
        if data[0].is_a?(Array)
            ports = data.map { |ip, port| [ip, Integer(port) ] }
            return ports
        end

        ports = data.map { |p| [ "*", Integer(p) ] }
        return ports
    elsif data.is_a?(Integer)
        return [ [ "*", data ] ]
    else
        raise "dgd-manifest: not sure how to get port data from a #{data.class.name} -- #{data.inspect}!"
    end
end