adhearsion 2.0.0.alpha2 → 2.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.gitignore +16 -14
  2. data/CHANGELOG.md +17 -1
  3. data/adhearsion.gemspec +14 -13
  4. data/features/cli_basic.feature +30 -0
  5. data/features/cli_create.feature +24 -0
  6. data/features/cli_daemon.feature +21 -0
  7. data/features/cli_generate.feature +9 -0
  8. data/features/cli_start.feature +33 -0
  9. data/features/cli_stop.feature +38 -0
  10. data/features/controller_generator.feature +19 -0
  11. data/features/plugin_generator.feature +55 -0
  12. data/lib/adhearsion.rb +5 -1
  13. data/lib/adhearsion/call.rb +57 -51
  14. data/lib/adhearsion/call_controller.rb +4 -20
  15. data/lib/adhearsion/call_controller/dial.rb +34 -4
  16. data/lib/adhearsion/calls.rb +4 -1
  17. data/lib/adhearsion/cli_commands.rb +31 -6
  18. data/lib/adhearsion/configuration.rb +2 -6
  19. data/lib/adhearsion/console.rb +56 -17
  20. data/lib/adhearsion/generators.rb +53 -2
  21. data/lib/adhearsion/generators/app/app_generator.rb +2 -24
  22. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +1 -1
  23. data/lib/adhearsion/generators/controller/controller_generator.rb +18 -0
  24. data/lib/adhearsion/generators/controller/templates/lib/controller.rb +4 -0
  25. data/lib/adhearsion/generators/controller/templates/spec/controller_spec.rb +3 -0
  26. data/lib/adhearsion/generators/generator.rb +77 -0
  27. data/lib/adhearsion/generators/plugin/plugin_generator.rb +33 -0
  28. data/lib/adhearsion/generators/plugin/templates/.gitignore +9 -0
  29. data/lib/adhearsion/generators/plugin/templates/Gemfile.tt +4 -0
  30. data/lib/adhearsion/generators/plugin/templates/README.md.tt +2 -0
  31. data/lib/adhearsion/generators/plugin/templates/Rakefile.tt +1 -0
  32. data/lib/adhearsion/generators/plugin/templates/lib/plugin-template.rb.tt +5 -0
  33. data/lib/adhearsion/generators/plugin/templates/lib/plugin-template/controller_methods.rb.tt +10 -0
  34. data/lib/adhearsion/generators/plugin/templates/lib/plugin-template/plugin.rb.tt +29 -0
  35. data/lib/adhearsion/generators/plugin/templates/lib/plugin-template/version.rb.tt +3 -0
  36. data/lib/adhearsion/generators/plugin/templates/plugin-template.gemspec.tt +35 -0
  37. data/lib/adhearsion/generators/plugin/templates/spec/plugin-template/controller_methods_spec.rb.tt +26 -0
  38. data/lib/adhearsion/generators/plugin/templates/spec/spec_helper.rb.tt +13 -0
  39. data/lib/adhearsion/initializer.rb +14 -22
  40. data/lib/adhearsion/logging.rb +25 -16
  41. data/lib/adhearsion/outbound_call.rb +3 -3
  42. data/lib/adhearsion/plugin.rb +14 -0
  43. data/lib/adhearsion/punchblock_plugin.rb +6 -1
  44. data/lib/adhearsion/punchblock_plugin/initializer.rb +8 -8
  45. data/lib/adhearsion/tasks/configuration.rb +1 -1
  46. data/lib/adhearsion/version.rb +1 -1
  47. data/spec/adhearsion/call_controller/dial_spec.rb +108 -17
  48. data/spec/adhearsion/call_controller_spec.rb +7 -64
  49. data/spec/adhearsion/call_spec.rb +48 -29
  50. data/spec/adhearsion/calls_spec.rb +7 -0
  51. data/spec/adhearsion/configuration_spec.rb +14 -14
  52. data/spec/adhearsion/console_spec.rb +124 -4
  53. data/spec/adhearsion/generators_spec.rb +17 -0
  54. data/spec/adhearsion/initializer_spec.rb +22 -18
  55. data/spec/adhearsion/logging_spec.rb +78 -48
  56. data/spec/adhearsion/outbound_call_spec.rb +6 -15
  57. data/spec/adhearsion/plugin_spec.rb +18 -0
  58. data/spec/adhearsion/process_spec.rb +10 -1
  59. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +8 -6
  60. data/spec/spec_helper.rb +5 -2
  61. data/spec/support/call_controller_test_helpers.rb +1 -1
  62. data/spec/support/initializer_stubs.rb +1 -1
  63. metadata +106 -66
  64. data/features/cli.feature +0 -108
  65. data/lib/adhearsion/initializer/logging.rb +0 -33
  66. data/spec/adhearsion/initializer/logging_spec.rb +0 -55
data/.gitignore CHANGED
@@ -1,25 +1,27 @@
1
1
  # Gem related stuff
2
2
  *.gem
3
- pkg
4
- .bundle
5
- Gemfile.lock
6
- vendor
3
+ /pkg
4
+ /.bundle
5
+ /Gemfile.lock
6
+ /vendor
7
7
 
8
8
  # Testing stuff
9
- coverage
10
- spec/reports
11
- example.log
12
- adhearsion.pid
9
+ /coverage
10
+ /spec/reports
11
+ *.log
12
+ /adhearsion.pid
13
13
 
14
14
  # RBX stuff
15
+ /.rbx/
16
+
17
+ # Editor temp/backup files
15
18
  *~
16
19
  .*.sw?
17
- nbproject
18
- /.rbx/
19
20
 
20
21
  # General
22
+ /nbproject
21
23
  .DS_Store
22
- .rvmrc
23
- .yardoc
24
- doc
25
- tmp
24
+ /.rvmrc
25
+ /.yardoc
26
+ /doc
27
+ /tmp
@@ -1,4 +1,20 @@
1
- # develop (2.0.0.head)
1
+ # 2.0.0.alpha3 - 2012-02-21
2
+ * Feature: Add `ahn generate` command to allow invocation of generators
3
+ * Feature: Add simple generator for call controllers
4
+ * Feature: Add simple generator for plugins
5
+ * Feature: Allow plugins to register their generator classes
6
+ * Feature: Add log level helper methods to Console
7
+ * Feature: Console's shutdown/exit method initiates the shutdown routine
8
+ * Bugfix: Remove config option for auto-accept - hard-coded to true
9
+ * Bugfix: AHN_ENV and RAILS_ENV now do not interfere with each other when both are set, and ahn will boot in the RAILS_ENV if AHN_ENV is not set
10
+ * Feature: The console can take control of a call
11
+ * Bugfix: CallController#dial now blocks until all outbound calls complete
12
+ * Bugfix: Call commands timing out now raise a timeout exception in the caller, but do not crash the actor
13
+ * Bugfix: CallController#dial now unblocks immediately if the original call ends
14
+ * Bugfix: CallController#dial now unblocks when the connected outbound call unjoins, rather than ending, incase post-processing on the outbound call is required
15
+ * Bugfix: CallController#dial now hangs up outbound legs when it unblocks
16
+ * Feature: CallController#dial now defaults the outbound caller ID to that of the controller's call
17
+ * Change: The command to take control of a call is now 'take' rather than 'use'. 'take' called without a call ID present a list of currently running calls
2
18
 
3
19
  # 2.0.0.alpha2 - 2012-01-30
4
20
  * Change: Plugins no longer load dialplan/event/rpc/console methods using corresponding class methods
@@ -19,27 +19,28 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # Runtime dependencies
22
- s.add_runtime_dependency "bundler", [">= 1.0.10"]
22
+ s.add_runtime_dependency 'bundler', [">= 1.0.10"]
23
23
  s.add_runtime_dependency 'punchblock', [">= 0.9.1"]
24
- s.add_runtime_dependency "logging", [">= 1.6.1"]
25
- s.add_runtime_dependency "adhearsion-loquacious", [">= 1.9.0"]
26
- s.add_runtime_dependency "activesupport", [">= 3.0.10"]
24
+ s.add_runtime_dependency 'logging', [">= 1.6.1"]
25
+ s.add_runtime_dependency 'adhearsion-loquacious', [">= 1.9.0"]
26
+ s.add_runtime_dependency 'activesupport', [">= 3.0.10"]
27
27
  # i18n is only strictly a dependency for ActiveSupport >= 3.0.0
28
28
  # Since it doesn't conflict with <3.0.0 we'll require it to be
29
29
  # on the safe side.
30
- s.add_runtime_dependency "i18n", ">= 0.5.0"
31
- s.add_runtime_dependency "json"
32
- s.add_runtime_dependency "thor"
33
- s.add_runtime_dependency "rake"
34
- s.add_runtime_dependency "pry"
35
- s.add_runtime_dependency "uuid"
36
- s.add_runtime_dependency "future-resource", [">= 0.0.2"]
37
- s.add_runtime_dependency "ruby_speech", [">= 0.4.0"]
30
+ s.add_runtime_dependency 'i18n', [">= 0.5.0"]
31
+ s.add_runtime_dependency 'json'
32
+ s.add_runtime_dependency 'thor'
33
+ s.add_runtime_dependency 'rake'
34
+ s.add_runtime_dependency 'pry'
35
+ s.add_runtime_dependency 'uuid'
36
+ s.add_runtime_dependency 'future-resource', [">= 0.0.2"]
37
+ s.add_runtime_dependency 'ruby_speech', [">= 0.4.0"]
38
38
  s.add_runtime_dependency 'countdownlatch'
39
39
  s.add_runtime_dependency 'has-guarded-handlers', [">= 1.1.0"]
40
40
  s.add_runtime_dependency 'girl_friday'
41
41
  s.add_runtime_dependency 'jruby-openssl' if RUBY_PLATFORM == 'java'
42
- s.add_runtime_dependency "ffi", [">= 1.0.11"]
42
+ s.add_runtime_dependency 'ffi', [">= 1.0.11"]
43
+ s.add_runtime_dependency 'celluloid', [">= 0.9.0"]
43
44
 
44
45
  # Development dependencies
45
46
  s.add_development_dependency 'rspec', ["~> 2.7.0"]
@@ -0,0 +1,30 @@
1
+ Feature: Adhearsion Ahn CLI (Basic)
2
+ As an Adhearsion user
3
+ I want a cli command (ahn)
4
+ So that I can perform actions against adhearsion apps and interact with adhearsion
5
+
6
+ Scenario: No arguments given
7
+ When I run `ahn`
8
+ Then I should see the usage message
9
+ And the exit status should be 0
10
+
11
+ Scenario: Unrecognized commands
12
+ When I run `ahn alpha beta`
13
+ Then the output should contain:
14
+ """
15
+ Unknown command: alpha beta
16
+ """
17
+ And the exit status should be 1
18
+
19
+ Scenario: Command version should print the version
20
+ When I run `ahn version`
21
+ Then the output should contain:
22
+ """
23
+ Adhearsion v
24
+ """
25
+ And the exit status should be 0
26
+
27
+ Scenario: Command help
28
+ When I run `ahn help`
29
+ Then I should see the usage message
30
+ And the exit status should be 0
@@ -0,0 +1,24 @@
1
+ Feature: Adhearsion Ahn CLI (Create)
2
+ As an Adhearsion user
3
+ I want the ahn command to allow creating an app
4
+ So that I can write an Adhearsion app
5
+
6
+ Scenario: Command create with correct arguments
7
+ When I run `ahn create path/somewhere`
8
+ And I cd to "path/somewhere"
9
+ Then the following files should exist:
10
+ | Gemfile |
11
+ | README.md |
12
+ | Rakefile |
13
+ | config/adhearsion.rb |
14
+ | config/environment.rb |
15
+ And the file "config/adhearsion.rb" should contain "Adhearsion.router"
16
+ Then the exit status should be 0
17
+
18
+ Scenario: Running create with no arguments
19
+ When I run `ahn create`
20
+ Then the output should contain:
21
+ """
22
+ "create" was called incorrectly. Call as "ahn create /path/to/directory".
23
+ """
24
+ And the exit status should be 1
@@ -0,0 +1,21 @@
1
+ Feature: Adhearsion Ahn CLI (daemon)
2
+ As an Adhearsion user
3
+ I want the ahn command to provide a 'daemon' command
4
+ So that I can start my adhearsion app as a daemon
5
+
6
+ Scenario: Command daemon with path works correctly
7
+ Given JRuby skip test
8
+ Given that I create a valid app under "path/somewhere"
9
+ When I run `ahn daemon path/somewhere`
10
+ And I cd to "path/somewhere"
11
+ And I terminate the process using the pid file "adhearsion.pid"
12
+ Then the output should contain "Daemonizing now"
13
+ And the exit status should be 0
14
+
15
+ Scenario: Command daemon with pid option
16
+ Given JRuby skip test
17
+ Given that I create a valid app under "path/somewhere"
18
+ When I run `ahn daemon path/somewhere --pid-file=ahn.pid`
19
+ And I cd to "path/somewhere"
20
+ And I terminate the process using the pid file "ahn.pid"
21
+ Then the output should contain "Daemonizing now"
@@ -0,0 +1,9 @@
1
+ Feature: Adhearsion Ahn CLI (generate)
2
+ As an Adhearsion user
3
+ I want the ahn command to be able to run generators
4
+ So that I can generate useful code
5
+
6
+ Scenario: Listing generators
7
+ When I run `ahn generate`
8
+ Then the output should contain "Please choose a generator below."
9
+ And the output should contain "controller"
@@ -0,0 +1,33 @@
1
+ Feature: Adhearsion Ahn CLI (start)
2
+ As an Adhearsion user
3
+ I want the ahn command to provide a 'start' command
4
+ So that I can start an interactive Adhearsion application
5
+
6
+ Scenario: Command start with no path outside of the app directory
7
+ When I run `ahn start`
8
+ Then the output should contain:
9
+ """
10
+ A valid path is required for start, unless run from an Adhearson app directory
11
+ """
12
+ And the exit status should be 1
13
+
14
+ Scenario: Command start with no path inside of the app directory
15
+ Given JRuby skip test
16
+ Given that I create a valid app under "path/somewhere"
17
+ When I cd to "path/somewhere"
18
+ And I run `ahn start` interactively
19
+ And I wait for output to contain "Starting connection to server"
20
+ And I terminate the interactive process
21
+ Then the output should contain "Adhearsion::Console: Starting up..."
22
+ And the output should contain "AHN>"
23
+ And the output should contain "Transitioning from booting to force_stop"
24
+
25
+ Scenario: Command start with only path works properly
26
+ Given JRuby skip test
27
+ Given that I create a valid app under "path/somewhere"
28
+ When I run `ahn start path/somewhere` interactively
29
+ And I wait for output to contain "Starting connection to server"
30
+ And I terminate the interactive process
31
+ Then the output should contain "Adhearsion::Console: Starting up..."
32
+ And the output should contain "AHN>"
33
+ And the output should contain "Transitioning from booting to force_stop"
@@ -0,0 +1,38 @@
1
+ Feature: Adhearsion Ahn CLI (stop)
2
+ As an Adhearsion user
3
+ I want the ahn command to provide a 'stop' command
4
+ So that I can stop a running Adhearsion daemon
5
+
6
+ Scenario: Command stop with valid path and pid option
7
+ Given JRuby skip test
8
+ Given that I create a valid app under "path/somewhere"
9
+ When I run `ahn daemon path/somewhere --pid-file=ahn.pid`
10
+ And I run `ahn stop path/somewhere --pid-file=ahn.pid`
11
+ Then the output should contain:
12
+ """
13
+ Stopping Adhearsion
14
+ """
15
+ And the file "ahn.pid" should not exist
16
+
17
+ Scenario: Command stop with valid path and no pid option
18
+ Given JRuby skip test
19
+ Given that I create a valid app under "path/somewhere"
20
+ When I run `ahn daemon path/somewhere`
21
+ And I run `ahn stop path/somewhere`
22
+ Then the output should contain:
23
+ """
24
+ Stopping Adhearsion
25
+ """
26
+ And the file "path/somewhere/adhearsion.pid" should not exist
27
+
28
+ Scenario: Command stop with no options inside the app directory
29
+ Given JRuby skip test
30
+ Given that I create a valid app under "path/somewhere"
31
+ And I cd to "path/somewhere"
32
+ When I run `ahn daemon`
33
+ And I run `ahn stop`
34
+ Then the output should contain:
35
+ """
36
+ Stopping Adhearsion
37
+ """
38
+ And the file "adhearsion.pid" should not exist
@@ -0,0 +1,19 @@
1
+ Feature: Adhearsion controller generator
2
+ In order to speed up development of an Adhearsion app
3
+ As an Adhearsion developer
4
+ I want to generate a controller and its tests
5
+
6
+ Scenario: Generate a controller and a test file
7
+ When I run `ahn create path/somewhere`
8
+ And I cd to "path/somewhere"
9
+ And I run `ahn generate controller TestController`
10
+ Then the following directories should exist:
11
+ | lib |
12
+ | spec |
13
+
14
+ And the following files should exist:
15
+ | lib/test_controller.rb |
16
+ | spec/test_controller_spec.rb |
17
+
18
+ And the file "lib/test_controller.rb" should contain "class TestController < Adhearsion::CallController"
19
+ And the file "spec/test_controller_spec.rb" should contain "describe TestController"
@@ -0,0 +1,55 @@
1
+ Feature: Adhearsion plugin generator
2
+ In order to speed up development of an Adhearsion plugin
3
+ As an Adhearsion plugin developer
4
+ I want to generate a plugin and its basic structure
5
+
6
+ Scenario: Generate the basic structure for a plugin
7
+ When I run `ahn generate plugin TestPlugin`
8
+ Then the following directories should exist:
9
+ | test_plugin |
10
+ | test_plugin/lib |
11
+ | test_plugin/lib/test_plugin |
12
+ | test_plugin/spec |
13
+ And the following files should exist:
14
+ | test_plugin/test_plugin.gemspec |
15
+ | test_plugin/Rakefile |
16
+ | test_plugin/README.md |
17
+ | test_plugin/Gemfile |
18
+ | test_plugin/lib/test_plugin.rb |
19
+ | test_plugin/lib/test_plugin/version.rb |
20
+ | test_plugin/lib/test_plugin/plugin.rb |
21
+ | test_plugin/lib/test_plugin/controller_methods.rb |
22
+ | test_plugin/spec/spec_helper.rb |
23
+ | test_plugin/spec/test_plugin/controller_methods_spec.rb |
24
+ And the file "test_plugin/test_plugin.gemspec" should contain "test_plugin/version"
25
+ And the file "test_plugin/README.md" should contain "TestPlugin"
26
+ And the file "test_plugin/lib/test_plugin.rb" should contain each of these content parts:
27
+ """
28
+ module TestPlugin
29
+ test_plugin/version
30
+ test_plugin/plugin
31
+ test_plugin/controller_methods
32
+ """
33
+ And the file "test_plugin/lib/test_plugin/version.rb" should contain each of these content parts:
34
+ """
35
+ module TestPlugin
36
+ VERSION
37
+ """
38
+ And the file "test_plugin/lib/test_plugin/plugin.rb" should contain each of these content parts:
39
+ """
40
+ module TestPlugin
41
+ init :test_plugin
42
+ config :test_plugin
43
+ namespace :test_plugin
44
+ """
45
+ And the file "test_plugin/lib/test_plugin/controller_methods.rb" should contain each of these content parts:
46
+ """
47
+ module TestPlugin
48
+ def greet
49
+ """
50
+ And the file "test_plugin/spec/spec_helper.rb" should contain "require 'test_plugin'"
51
+ And the file "test_plugin/spec/test_plugin/controller_methods_spec.rb" should contain each of these content parts:
52
+ """
53
+ module TestPlugin
54
+ include TestPlugin::ControllerMethods
55
+ """
@@ -13,6 +13,7 @@ abort "ERROR: You are running Adhearsion on an unsupported version of Ruby (Ruby
13
13
  has_guarded_handlers
14
14
  girl_friday
15
15
  loquacious
16
+ celluloid
16
17
 
17
18
  adhearsion/version
18
19
  adhearsion/foundation/all
@@ -30,6 +31,7 @@ module Adhearsion
30
31
  autoload :Conveniences
31
32
  autoload :Dispatcher
32
33
  autoload :Events
34
+ autoload :Generators
33
35
  autoload :MenuDSL
34
36
  autoload :Initializer
35
37
  autoload :Logging
@@ -51,7 +53,7 @@ module Adhearsion
51
53
 
52
54
  def initialize_config
53
55
  _config = Configuration.new
54
- env = ENV['AHN_ENV']
56
+ env = ENV['AHN_ENV'] || ENV['RAILS_ENV']
55
57
  env = nil unless _config.valid_environment? env
56
58
  _config.platform.environment = env if env
57
59
  _config
@@ -87,3 +89,5 @@ module Adhearsion
87
89
  RecordError = Class.new StandardError # Represents failure to record such as when a file cannot be written.
88
90
  ConfigurationError = Class.new StandardError # Error raised while trying to configure a non existent plugin
89
91
  end
92
+
93
+ Celluloid.exception_handler { |e| Adhearsion::Events.trigger :exception, e }
@@ -1,11 +1,30 @@
1
1
  require 'thread'
2
2
 
3
+ module Celluloid
4
+ module ClassMethods
5
+ def ===(other)
6
+ other.kind_of? self
7
+ end
8
+ end
9
+
10
+ class ActorProxy
11
+ def is_a?(klass)
12
+ Actor.call @mailbox, :is_a?, klass
13
+ end
14
+
15
+ def kind_of?(klass)
16
+ Actor.call @mailbox, :kind_of?, klass
17
+ end
18
+ end
19
+ end
20
+
3
21
  module Adhearsion
4
22
  ##
5
23
  # Encapsulates call-related data and behavior.
6
24
  #
7
25
  class Call
8
26
 
27
+ include Celluloid
9
28
  include HasGuardedHandlers
10
29
 
11
30
  attr_accessor :offer, :client, :end_reason, :commands, :variables
@@ -16,39 +35,35 @@ module Adhearsion
16
35
  def initialize(offer = nil)
17
36
  register_initial_handlers
18
37
 
19
- @tag_mutex = Mutex.new
20
- @tags = []
21
- @end_reason_mutex = Mutex.new
22
- @commands = CommandRegistry.new
23
- @variables = {}
38
+ @tags = []
39
+ @commands = CommandRegistry.new
40
+ @variables = {}
24
41
 
25
42
  self << offer if offer
26
43
  end
27
44
 
28
45
  def id
29
- offer.call_id
46
+ offer.call_id if offer
30
47
  end
31
48
 
32
49
  def tags
33
- @tag_mutex.synchronize { @tags.clone }
50
+ @tags.clone
34
51
  end
35
52
 
36
53
  # This may still be a symbol, but no longer requires the tag to be a symbol although beware
37
54
  # that using a symbol would create a memory leak if used improperly
38
55
  # @param [String, Symbol] label String or Symbol with which to tag this call
39
56
  def tag(label)
40
- raise ArgumentError, "Tag must be a String or Symbol" unless [String, Symbol].include?(label.class)
41
- @tag_mutex.synchronize { @tags << label }
57
+ abort ArgumentError.new "Tag must be a String or Symbol" unless [String, Symbol].include?(label.class)
58
+ @tags << label
42
59
  end
43
60
 
44
61
  def remove_tag(symbol)
45
- @tag_mutex.synchronize do
46
- @tags.reject! { |tag| tag == symbol }
47
- end
62
+ @tags.reject! { |tag| tag == symbol }
48
63
  end
49
64
 
50
65
  def tagged_with?(symbol)
51
- @tag_mutex.synchronize { @tags.include? symbol }
66
+ @tags.include? symbol
52
67
  end
53
68
 
54
69
  def register_event_handler(*guards, &block)
@@ -56,6 +71,7 @@ module Adhearsion
56
71
  end
57
72
 
58
73
  def deliver_message(message)
74
+ logger.debug "Receiving message: #{message.inspect}"
59
75
  trigger_handler :event, message
60
76
  end
61
77
 
@@ -74,9 +90,10 @@ module Adhearsion
74
90
  end
75
91
 
76
92
  on_end do |event|
77
- hangup
78
- @end_reason_mutex.synchronize { @end_reason = event.reason }
93
+ clear_from_active_calls
94
+ @end_reason = event.reason
79
95
  commands.terminate
96
+ after(5) { current_actor.terminate! }
80
97
  end
81
98
  end
82
99
 
@@ -88,11 +105,11 @@ module Adhearsion
88
105
  end
89
106
 
90
107
  def active?
91
- @end_reason_mutex.synchronize { !end_reason }
108
+ !end_reason
92
109
  end
93
110
 
94
111
  def accept(headers = nil)
95
- write_and_await_response Punchblock::Command::Accept.new(:headers => headers)
112
+ @accept_command ||= write_and_await_response Punchblock::Command::Accept.new(:headers => headers)
96
113
  end
97
114
 
98
115
  def answer(headers = nil)
@@ -103,14 +120,14 @@ module Adhearsion
103
120
  write_and_await_response Punchblock::Command::Reject.new(:reason => reason, :headers => headers)
104
121
  end
105
122
 
106
- def hangup!(headers = nil)
123
+ def hangup(headers = nil)
107
124
  return false unless active?
108
- @end_reason_mutex.synchronize { @end_reason = true }
125
+ @end_reason = true
109
126
  write_and_await_response Punchblock::Command::Hangup.new(:headers => headers)
110
127
  end
111
128
 
112
- def hangup
113
- Adhearsion.active_calls.remove_inactive_call self
129
+ def clear_from_active_calls
130
+ Adhearsion.active_calls.remove_inactive_call current_actor
114
131
  end
115
132
 
116
133
  ##
@@ -128,7 +145,7 @@ module Adhearsion
128
145
  when String
129
146
  options[:other_call_id] = target
130
147
  when Hash
131
- raise ArgumentError, "You cannot specify both a call ID and mixer name" if target.has_key?(:call_id) && target.has_key?(:mixer_name)
148
+ abort ArgumentError.new "You cannot specify both a call ID and mixer name" if target.has_key?(:call_id) && target.has_key?(:mixer_name)
132
149
  target.tap do |t|
133
150
  t[:other_call_id] = t[:call_id]
134
151
  t.delete :call_id
@@ -136,7 +153,7 @@ module Adhearsion
136
153
 
137
154
  options.merge! target
138
155
  else
139
- raise ArgumentError, "Don't know how to join to #{target.inspect}"
156
+ abort ArgumentError.new "Don't know how to join to #{target.inspect}"
140
157
  end
141
158
  command = Punchblock::Command::Join.new options
142
159
  write_and_await_response command
@@ -150,24 +167,22 @@ module Adhearsion
150
167
  write_and_await_response ::Punchblock::Command::Unmute.new
151
168
  end
152
169
 
153
- def with_command_lock
154
- @command_monitor ||= Monitor.new
155
- @command_monitor.synchronize { yield }
156
- end
157
-
158
170
  def write_and_await_response(command, timeout = 60)
159
- # TODO: Put this back once we figure out why it's causing CI to fail
160
- # logger.trace "Executing command #{command.inspect}"
161
171
  commands << command
162
172
  write_command command
163
- response = command.response timeout
164
- raise response if response.is_a? Exception
173
+ begin
174
+ response = command.response timeout
175
+ rescue Timeout::Error => e
176
+ abort e
177
+ end
178
+ abort response if response.is_a? Exception
165
179
  command
166
180
  end
167
181
 
168
182
  def write_command(command)
169
- raise Hangup unless active? || command.is_a?(Punchblock::Command::Hangup)
183
+ abort Hangup.new unless active? || command.is_a?(Punchblock::Command::Hangup)
170
184
  variables.merge! command.headers_hash if command.respond_to? :headers_hash
185
+ logger.trace "Executing command #{command.inspect}"
171
186
  client.execute_command command, :call_id => id
172
187
  end
173
188
 
@@ -175,13 +190,21 @@ module Adhearsion
175
190
  "#{self.class}: #{id}"
176
191
  end
177
192
 
193
+ def logger
194
+ super
195
+ end
196
+
197
+ def to_ary
198
+ [current_actor]
199
+ end
200
+
178
201
  def execute_controller(controller, latch = nil)
179
202
  Adhearsion::Process.important_threads << Thread.new do
180
203
  catching_standard_errors do
181
204
  begin
182
205
  CallController.exec controller
183
206
  ensure
184
- hangup!
207
+ hangup
185
208
  end
186
209
  latch.countdown! if latch
187
210
  end
@@ -195,22 +218,5 @@ module Adhearsion
195
218
  end
196
219
  end
197
220
 
198
- class Registry
199
- @registry = Hash.new
200
- @mutex = Mutex.new
201
-
202
- def self.[](k)
203
- @mutex.synchronize do
204
- @registry[k]
205
- end
206
- end
207
-
208
- def self.[]=(k, value)
209
- @mutex.synchronize do
210
- @registry[k] = value
211
- end
212
- end
213
- end#Registry
214
-
215
221
  end#Call
216
222
  end#Adhearsion