Skip to content

Commit

Permalink
Renamed RTSP::Exception to RTSP::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
turboladen committed Apr 10, 2011
1 parent 81a878b commit d9e9a58
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 31 deletions.
19 changes: 15 additions & 4 deletions lib/rtsp/capturer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'tempfile'
require 'socket'

require_relative 'exception'
require_relative 'error'

module RTSP

Expand Down Expand Up @@ -49,16 +49,27 @@ def initialize(transport_protocol=:udp, rtp_port=9000, rtp_capture_file=nil)
@rtp_file = rtp_capture_file || Tempfile.new(DEFAULT_CAPFILE_NAME)
end

# Starts capturing data on +@rtp_port+ and writes it to +@rtp_file+.
def run
# Initializes a server of the correct socket type.
#
# @return [UDPSocket, TCPSocket]
# @raise [RTSP::Error] If +@transport_protocol was not set to :udp or
# :tcp.
def init_server
if @transport_protocol == :udp
server = init_udp_server
elsif @transport_protocol == :tcp
server = init_tcp_server
else
raise RTSP::Exception, "Unknown streaming_protocol requested: #{@transport_protocol}"
raise RTSP::Error, "Unknown streaming_protocol requested: #{@transport_protocol}"
end

server
end

# Starts capturing data on +@rtp_port+ and writes it to +@rtp_file+.
def run
server = init_server

loop do
data = server.recvfrom(MAX_BYTES_TO_RECEIVE).first
RTSP::Client.log data.size
Expand Down
22 changes: 11 additions & 11 deletions lib/rtsp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require_relative 'transport_parser'
require_relative 'capturer'
require_relative 'exception'
require_relative 'error'
require_relative 'global'
require_relative 'helpers'
require_relative 'message'
Expand Down Expand Up @@ -100,7 +100,7 @@ def send_message message
RTSP::Response.new socket_data.first
end
rescue Timeout::Error
raise RTSP::Exception, "Request took more than #{@connection.timeout} seconds to send."
raise RTSP::Error, "Request took more than #{@connection.timeout} seconds to send."
end

RTSP::Client.log "Received response:"
Expand Down Expand Up @@ -330,15 +330,15 @@ def request message
reset_state
end

raise RTSP::Exception, "#{response.code}: #{response.message}"
raise RTSP::Error, "#{response.code}: #{response.message}"
else
raise RTSP::Exception, "Unknown Response code: #{response.code}"
raise RTSP::Error, "Unknown Response code: #{response.code}"
end

unless [:options, :describe, :teardown].include? message.method_type
ensure_session
end
rescue RTSP::Exception => ex
rescue RTSP::Error => ex
RTSP::Client.log "Got exception: #{ex.message}"
ex.backtrace.each { |b| RTSP::Client.log b }
end
Expand All @@ -348,11 +348,11 @@ def request message

# Ensures that +@session+ is set before continuing on.
#
# @raise [RTSP::Exception] Raises if @session isn't set.
# @raise [RTSP::Error] Raises if @session isn't set.
# @return Returns whatever the block returns.
def ensure_session
unless @session > 0
raise RTSP::Exception, "Session number not retrieved from server yet. Run SETUP first."
raise RTSP::Error, "Session number not retrieved from server yet. Run SETUP first."
end
end

Expand Down Expand Up @@ -390,11 +390,11 @@ def media_control_tracks
# server responded to a different request.
#
# @param [Fixnum] server_cseq Sequence number returned by the server.
# @raise [RTSP::Exception]
# @raise [RTSP::Error]
def compare_sequence_number server_cseq
if @cseq != server_cseq
message = "Sequence number mismatch. Client: #{@cseq}, Server: #{server_cseq}"
raise RTSP::Exception, message
raise RTSP::Error, message
end
end

Expand All @@ -403,11 +403,11 @@ def compare_sequence_number server_cseq
# the server responded to a different request.
#
# @param [Fixnum] server_session Session number returned by the server.
# @raise [RTSP::Exception]
# @raise [RTSP::Error]
def compare_session_number server_session
if @session != server_session
message = "Session number mismatch. Client: #{@session}, Server: #{server_session}"
raise RTSP::Exception, message
raise RTSP::Error, message
end
end

Expand Down
6 changes: 6 additions & 0 deletions lib/rtsp/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module RTSP

# Custom error for RTSP problems.
class Error < StandardError
end
end
4 changes: 0 additions & 4 deletions lib/rtsp/exception.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/rtsp/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def log(message)
logger.send(log_level, message) if log?
end

# Use to disable the raising of +RTSP::Exception+s.
# Use to disable the raising of +RTSP::Error+s.
attr_writer :raise_errors

# @return [Boolean] true if set to raise errors; false if not.
Expand Down
4 changes: 2 additions & 2 deletions lib/rtsp/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'uri'
require_relative 'global'
require_relative 'exception'
require_relative 'error'

module RTSP
module Helpers
Expand All @@ -21,7 +21,7 @@ def build_resource_uri_from url
resource_uri

else
raise RTSP::Exception, "url must be a String."
raise RTSP::Error, "url must be a String."
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rtsp/message.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative 'helpers'
require_relative 'exception'
require_relative 'error'
require_relative 'version'

module RTSP
Expand Down Expand Up @@ -93,7 +93,7 @@ def header(type, value)
if type.is_a? Symbol
headers[type] = value
else
raise RTSP::Exception, "Header type must be a Symbol (i.e. :cseq)."
raise RTSP::Error, "Header type must be a Symbol (i.e. :cseq)."
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rtsp/response.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rubygems'
require 'sdp'
require_relative 'exception'
require_relative 'error'

module RTSP

Expand All @@ -16,7 +16,7 @@ class Response
# server/client.
def initialize(raw_response)
if raw_response.nil? || raw_response.empty?
raise RTSP::Exception, "#{self.class} received nil string--this shouldn't happen."
raise RTSP::Error, "#{self.class} received nil string--this shouldn't happen."
end

@raw_response = raw_response
Expand Down
2 changes: 1 addition & 1 deletion rtsp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RTSP: http://www.ietf.org/rfc/rfc2326.txt}
"lib/rtsp.rb",
"lib/rtsp/capturer.rb",
"lib/rtsp/client.rb",
"lib/rtsp/exception.rb",
"lib/rtsp/error.rb",
"lib/rtsp/global.rb",
"lib/rtsp/helpers.rb",
"lib/rtsp/message.rb",
Expand Down
2 changes: 1 addition & 1 deletion spec/rtsp/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class HelperTest
it "raises if not given a String" do
lambda do
@my_object.build_resource_uri_from URI.parse "rtsp://64.202.98.91"
end.should raise_exception RTSP::Exception
end.should raise_exception RTSP::Error
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rtsp/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it "raises if the header type isn't a Symbol" do
message = RTSP::Message.options(@stream)
lambda { message.header "hi", "everyone"
}.should raise_error RTSP::Exception
}.should raise_error RTSP::Error
end

context "builds an OPTIONS string" do
Expand Down
4 changes: 2 additions & 2 deletions spec/rtsp/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
describe RTSP::Response do
describe "#initialize" do
it "expects a non-nil string on" do
lambda { RTSP::Response.new(nil) }.should raise_exception RTSP::Exception
lambda { RTSP::Response.new(nil) }.should raise_exception RTSP::Error
end

it "expects a non-empty string on" do
lambda { RTSP::Response.new("") }.should raise_exception RTSP::Exception
lambda { RTSP::Response.new("") }.should raise_exception RTSP::Error
end
end

Expand Down

0 comments on commit d9e9a58

Please sign in to comment.