Class: TIPCName

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

Overview

Represents a TIPC name address of the form <type, instance>.

From the TIPC Programmer’s Guide:

The basic unit of functional addressing within TIPC is the "port name", which 
is typically denoted as {type,instance}.  A port name consists of a 32-bit 
type field and a 32-bit instance field, both of which are chosen by the 
application.  Typically, the type field is used to indicate the class of 
service provided by the port, while the instance field can be used as a sub-
class indicator.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, instance, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE, domain = 0) ⇒ TIPCName

Create a new TIPCName instance.

Parameters

* type     - arbitrary 32 bit type value
* instance - arbitrary 32 bit instance value
* scope    - the scope (zone, cluster, or node) to use when packing
             this name as a TIPC address (optional)
* domain   - indicates the search domain used during the name lookup
             process (optional)


116
117
118
119
120
121
122
123
# File 'lib/tipcsocket.rb', line 116

def initialize(type, instance, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE, domain = 0)
  @family   = Socket::Constants::AF_TIPC
  @addrtype = TIPCSocket::Constants::TIPC_ADDR_NAME
  @type     = type
  @instance = instance
  @scope    = scope
  @domain   = 0
end

Instance Attribute Details

#addrtypeObject (readonly)

Returns the value of attribute addrtype.



104
105
106
# File 'lib/tipcsocket.rb', line 104

def addrtype
  @addrtype
end

#domainObject

Returns the value of attribute domain.



105
106
107
# File 'lib/tipcsocket.rb', line 105

def domain
  @domain
end

#familyObject (readonly)

Returns the value of attribute family.



104
105
106
# File 'lib/tipcsocket.rb', line 104

def family
  @family
end

#instanceObject

Returns the value of attribute instance.



105
106
107
# File 'lib/tipcsocket.rb', line 105

def instance
  @instance
end

#scopeObject

Returns the value of attribute scope.



105
106
107
# File 'lib/tipcsocket.rb', line 105

def scope
  @scope
end

#typeObject

Returns the value of attribute type.



105
106
107
# File 'lib/tipcsocket.rb', line 105

def type
  @type
end

Class Method Details

.unpack(bytes) ⇒ Object

Create a new TIPCName instance from an 8 byte binary string containing a TIPC name.

Parameters

* bytes - 8 byte string containing TIPC name


173
174
175
176
# File 'lib/tipcsocket.rb', line 173

def self.unpack(bytes)
  data = bytes.unpack("L2")
  self.new(data[0], data[1])
end

.unpack_addr(bytes) ⇒ Object

Create a new TIPCName instance from a 16 byte binary string containing a TIPC address.

Parameters

* bytes - 16 byte string containing TIPC address


163
164
165
166
# File 'lib/tipcsocket.rb', line 163

def self.unpack_addr(bytes)
  data = bytes.unpack("SCcL3")
  self.new(data[3], data[4], data[2], data[5])
end

Instance Method Details

#packObject

Pack an instance of a TIPCName.

Produces an 8 byte string with the following format:

* type     - uint32 (4 bytes)
* instance - uint32 (4 bytes)


151
152
153
154
155
156
# File 'lib/tipcsocket.rb', line 151

def pack
  [
    self.type,
    self.instance
  ].pack("L2")
end

#pack_addrObject

Pack an instance of a TIPCName as a 16 byte TIPC network address suitable for passing to one of the standard Socket methods (connect, send, etc.).

Produces a 16 byte binary string with the following format:

* family   - unsigned short (2 bytes)
* addrtype - unsigned char  (1 byte)
* scope    - signed char    (1 byte)
* type     - uint32         (4 bytes)
* instance - uint32         (4 bytes)
* domain   - uint32         (4 bytes)


135
136
137
138
139
140
141
142
143
144
# File 'lib/tipcsocket.rb', line 135

def pack_addr
  [
    self.family,
    self.addrtype,
    self.scope,
    self.type,
    self.instance,
    self.domain
  ].pack("SCcL3")
end