Class: Wamupd::AvahiService

Inherits:
Object
  • Object
show all
Defined in:
lib/wamupd/avahi_service.rb

Overview

A single <service> entry from a service record. A given service file (representated by an AvahiServiceFile) may contain many AvahiServices.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, param) ⇒ AvahiService

Initialize

Argument: Either an XML node or a hash with some useful subset of the parameters :type, :subtype, :hostname, :port, :txt, and :domainname



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/wamupd/avahi_service.rb', line 91

def initialize(name, param)
    @name = name
    mapping = {:type=>:@type,
        :subtype=>:@subtype,
        :hostname=>:@hostname,
        :port=>:@port,
        :txt=>:@txt,
        :domainname=>:@domainname
    }
    mapping.each {|k,v|
        if (param.has_key?(k))
            self.instance_variable_set(v, param[k])
        end
    }
end

Instance Attribute Details

#domainnameObject (readonly)

Returns the value of attribute domainname.



27
28
29
# File 'lib/wamupd/avahi_service.rb', line 27

def domainname
  @domainname
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



25
26
27
# File 'lib/wamupd/avahi_service.rb', line 25

def hostname
  @hostname
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/wamupd/avahi_service.rb', line 28

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



26
27
28
# File 'lib/wamupd/avahi_service.rb', line 26

def port
  @port
end

#subtypeObject (readonly)

Returns the value of attribute subtype.



24
25
26
# File 'lib/wamupd/avahi_service.rb', line 24

def subtype
  @subtype
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/wamupd/avahi_service.rb', line 23

def type
  @type
end

Instance Method Details

#identifierObject

A key that can be used to identify this service. Is the subtype-type followed by a - followed by the port



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wamupd/avahi_service.rb', line 49

def identifier
    retval = ""
    if (@subtype)
        retval += @subtype
        retval += "."
    end
    if (@type)
        retval += @type
        retval += "-"
    end
    retval += @port.to_s
    return retval
end

#subtype_displayObject

Get the subtype as Apple displays it



31
32
33
# File 'lib/wamupd/avahi_service.rb', line 31

def subtype_display
    "#{@type},#{@subtype}"
end

#targetObject

The target of this service



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/wamupd/avahi_service.rb', line 64

def target
    t = ""
    sa = MainSettings.instance
    if (@hostname.nil?)
        t += sa.hostname
    else
        t += @hostname
    end
    t += "."
    if (@domainname.nil?)
        t += sa.zone
    else
        t += @domainname
    end
end

#to_sObject

String coercer



108
109
110
# File 'lib/wamupd/avahi_service.rb', line 108

def to_s
    "<AvahiService name='#{@name}' type=#{@type} txt=#{self.txt}>"
end

#txtObject

TXT record



81
82
83
# File 'lib/wamupd/avahi_service.rb', line 81

def txt
    return (@txt.nil? || @txt == "") ? false : @txt
end

#type_in_zoneObject

The full type in this zone. Goes in the PTR



42
43
44
45
# File 'lib/wamupd/avahi_service.rb', line 42

def type_in_zone
    sa = MainSettings.instance
    return @type + "." + sa.zone
end

#type_in_zone_with_nameObject

The type and name in this zone. Name of the SRV and TXT records



36
37
38
39
# File 'lib/wamupd/avahi_service.rb', line 36

def type_in_zone_with_name
    sa = MainSettings.instance
    return sa.hostname + "." + @type + "."+ sa.zone
end