This repository has been archived by the owner on Jan 28, 2023. It is now read-only.
/
plugin_manager.rb
115 lines (93 loc) · 2.88 KB
/
plugin_manager.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
class SiriProxy::PluginManager
attr_accessor :plugins
def initialize()
load_plugins()
@blockNextObjectsFromServer = 0
@blockNextObjectsFromClient = 0
@blockRestOfSessionFromServer = false
end
def load_plugins()
@plugins = []
if APP_CONFIG.plugins
APP_CONFIG.plugins.each do |pluginConfig|
if pluginConfig.is_a? String
className = pluginConfig
requireName = "siriproxy-#{className.downcase}"
else
className = pluginConfig['name']
requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}"
end
require requireName
plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig)
plugin.plugin_manager = self
@plugins << plugin
end
end
puts "Plugins laoded: #{@plugins}"
end
def object_from_guzzoni(object, connection)
if(@blockRestOfSessionFromServer)
if(connection.last_ref_id == object["refId"])
puts "[Info - Dropping Object from Guzzoni] #{object["class"]}"
return nil
else
@blockRestOfSessionFromServer = false
end
end
if(@blockNextObjectsFromServer > 0)
puts "[Info - Dropping Object from Guzzoni] #{object["class"]}"
@blockNextObjectsFromServer -= 1
return nil
end
plugins.each { |plugin|
object = plugin.object_from_guzzoni(object, connection)
}
object
end
def object_from_client(object, connection)
if(@blockNextObjectsFromClient > 0)
puts "[Info - Dropping Object from iPhone] #{object["class"]}"
@blockNextObjectsFromClient -= 1
return nil
end
##Often this indicates a bug in OUR code. So let's not send it to Apple. :-)
if(object["class"] == "CommandIgnored")
pp object
return nil
end
plugins.each { |plugin|
object = plugin.object_from_client(object, connection)
}
# This is used for commands from phone that should not be sent back to Apple,
# and will be interpreted by plugins directly
if(object && object["properties"] && object['properties']['proxyOnly'])
puts "[Info - Not forwarding Object from iPhone because proxyOnly flag was set] #{object["class"]}"
return nil
end
object
end
def unknown_command(object, connection, command)
puts "[UnknownCommand] #{command}"
plugins.each { |plugin|
object = plugin.unknown_command(object, connection, command)
}
object
end
def speech_recognized(object, connection, phrase)
puts "[Recognized Speech] #{phrase}"
plugins.each { |plugin|
object = plugin.speech_recognized(object, connection, phrase)
}
object
end
def block_next_objects_from_server(count=1)
@blockNextObjectsFromServer += count
end
def block_next_objects_from_client(count=1)
@blockNextObjectsFromClient += count
end
#Blocks everything from server until a new refId is seen
def block_rest_of_session_from_server
@blockRestOfSessionFromServer = true
end
end