class Smpp::Pdu::Base

Constants

BIND_RECEIVER
BIND_RECEIVER_RESP
BIND_TRANSCEIVER
BIND_TRANSCEIVER_RESP
BIND_TRANSMITTER
BIND_TRANSMITTER_RESP
CANCEL_SM
CANCEL_SM_RESP
DELIVER_SM
DELIVER_SM_RESP
ESME_RALYBND
ESME_RBINDFAIL
ESME_RCANCELFAIL
ESME_RCNTSUBDL
ESME_RINVBNDSTS
ESME_RINVCMDID
ESME_RINVCMDLEN
ESME_RINVDESTFLAG
ESME_RINVDLNAME
ESME_RINVDSTADR
ESME_RINVDSTNPI
ESME_RINVDSTTON
ESME_RINVESMCLASS
ESME_RINVMSGID
ESME_RINVMSGLEN
ESME_RINVNUMDESTS
ESME_RINVNUMMSGS
ESME_RINVPASWD
ESME_RINVPRTFLG
ESME_RINVREGDLVFLG
ESME_RINVREPFLAG
ESME_RINVSERTYP
ESME_RINVSRCADR
ESME_RINVSRCNPI
ESME_RINVSRCTON
ESME_RINVSUBREP
ESME_RINVSYSID
ESME_RINVSYSTYP
ESME_RMSGQFUL
ESME_ROK

Error constants

ESME_RREPLACEFAIL
ESME_RSUBMITFAIL
ESME_RSYSERR
ESME_RTHROTTLED
ESME_RX_T_APPN
GENERIC_NACK

PDU types

OPTIONAL_MESSAGE_STATE
OPTIONAL_RECEIPTED_MESSAGE_ID
PROTOCOL_VERSION

Protocol Version

QUERY_SM
QUERY_SM_RESP
REPLACE_SM
REPLACE_SM_RESP
SEQUENCE_MAX
SUBMIT_MULTI
SUBMIT_MULTI_RESP
SUBMIT_SM
SUBMIT_SM_RESP
UNBIND
UNBIND_RESP

Attributes

body[R]
command_id[R]
command_status[R]
data[R]
sequence_number[R]

Public Class Methods

create(data) click to toggle source

PDU factory method for common client PDUs (used to create PDUs from wire data)

# File lib/smpp/pdu/base.rb, line 148
def Base.create(data)
  header = data[0..15]
  if !header
    return nil
  end
  len, cmd, status, seq = header.unpack('N4')
  body = data[16..-1]

  #if a class has been registered to handle this command_id, try
  #to create an instance from the wire data
  if @@cmd_map[cmd]
    @@cmd_map[cmd].from_wire_data(seq, status, body)
  else
    Smpp::Base.logger.error "Unknown PDU: #{"0x%08x" % cmd}"
    return nil
  end
end
fixed_int(value) click to toggle source

return int as binary string of 4 octets

# File lib/smpp/pdu/base.rb, line 105
def Base.fixed_int(value)
  arr = [value >> 24, value >> 16, value >> 8, value & 0xff]
  arr.pack("cccc")
end
from_wire_data(seq, status, body) click to toggle source

This factory should be implemented in every subclass that can create itself from wire data. The subclass should also register itself with the ‘handles_cmd’ class method.

# File lib/smpp/pdu/base.rb, line 143
def Base.from_wire_data(seq, status, body)
  raise Exception.new("#{self.class} claimed to handle wire data, but doesn't.")
end
handles_cmd(command_id) click to toggle source

maps a subclass as the handler for a particulular pdu

# File lib/smpp/pdu/base.rb, line 167
def Base.handles_cmd(command_id)
  @@cmd_map[command_id] = self
end
new(command_id, command_status, seq, body='') click to toggle source
# File lib/smpp/pdu/base.rb, line 85
def initialize(command_id, command_status, seq, body='')    
  length = 16 + body.length
  @command_id = command_id
  @command_status = command_status
  @body = body
  @sequence_number = seq
  @data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body.force_encoding('binary')
end
next_sequence_number() click to toggle source
# File lib/smpp/pdu/base.rb, line 135
def Base.next_sequence_number
  @@seq.synchronize do
    (@@seq[0] += 1) % SEQUENCE_MAX
  end
end
optional_parameters_to_buffer(optionals) click to toggle source

expects a hash like {tag => Smpp::OptionalParameter}

# File lib/smpp/pdu/base.rb, line 115
def Base.optional_parameters_to_buffer(optionals)
  output = ""
  optionals.each do |tag, optional_param|
    length = optional_param.value.to_s.length
    buffer = []
    buffer += [tag >> 8, tag & 0xff]
    buffer += [length >> 8, length & 0xff]
    output << buffer.pack('cccc') << optional_param.value.force_encoding('binary')
  end
  output
end
parse_optional_parameters(remaining_bytes) click to toggle source
# File lib/smpp/pdu/base.rb, line 171
def Base.parse_optional_parameters(remaining_bytes)
  optionals = {}
  while not remaining_bytes.empty?
    optional = {}
    optional_parameter, remaining_bytes = Smpp::OptionalParameter.from_wire_data(remaining_bytes)
    optionals[optional_parameter.tag] = optional_parameter
  end
  
  return optionals
end

Public Instance Methods

fixed_int(value) click to toggle source
# File lib/smpp/pdu/base.rb, line 110
def fixed_int(value)
  Base.fixed_int(value)
end
logger() click to toggle source
# File lib/smpp/pdu/base.rb, line 94
def logger
  Smpp::Base.logger
end
next_sequence_number() click to toggle source
# File lib/smpp/pdu/base.rb, line 131
def next_sequence_number
  Base.next_sequence_number
end
optional_parameters_to_buffer(optionals) click to toggle source
# File lib/smpp/pdu/base.rb, line 127
def optional_parameters_to_buffer(optionals)
  Base.optional_parameters_to_buffer(optionals)
end
to_human() click to toggle source
# File lib/smpp/pdu/base.rb, line 98
def to_human
  # convert header (4 bytes) to array of 4-byte ints
  a = @data.to_s.unpack('N4')
  sprintf("(%22s) len=%3d cmd=%8s status=%1d seq=%03d (%s)", self.class.to_s[11..-1], a[0], a[1].to_s(16), a[2], a[3], @body)
end