siriproxypm-clientstatecache 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
10
10
|
#initialization
|
11
11
|
###############################################
|
12
12
|
|
13
|
-
@@client_state = nil
|
13
|
+
# @@client_state = nil
|
14
14
|
|
15
15
|
#intialization
|
16
16
|
def initialize()
|
@@ -28,25 +28,27 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
28
28
|
|
29
29
|
|
30
30
|
def init_client
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@@client_state = {}
|
35
|
-
end
|
31
|
+
#create hash of array of stack states: key is client (e.g. ipaddress) value is hash with
|
32
|
+
#only used key is :activity, which gives the last time activity was registered from this client
|
33
|
+
@client_state = {}
|
36
34
|
end
|
37
35
|
|
38
36
|
def set_client_state(symbol,val)
|
39
37
|
client = get_client()
|
40
|
-
if client != nil
|
41
|
-
|
38
|
+
if client != nil
|
39
|
+
if !@client_state.has_key?(client) \
|
40
|
+
|| @client_state[client] == nil
|
41
|
+
@client_state[client] = {}
|
42
|
+
end
|
43
|
+
@client_state[client][symbol] = val
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def get_client_state(symbol)
|
46
48
|
result = nil
|
47
49
|
client = get_client()
|
48
|
-
if client != nil
|
49
|
-
result =
|
50
|
+
if client != nil && @client_state.has_key?(client)
|
51
|
+
result = @client_state[client][symbol]
|
50
52
|
end
|
51
53
|
return result
|
52
54
|
end
|
@@ -79,7 +81,7 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
79
81
|
result = nil
|
80
82
|
plugins = get_plugin_list
|
81
83
|
plugins.each do |plugin|
|
82
|
-
plugin_obj =
|
84
|
+
plugin_obj = instantiate_plugin(plugin)
|
83
85
|
if plugin_obj == nil || !plugin_obj.is_a?(SiriProxy::Plugin)
|
84
86
|
next
|
85
87
|
end
|
@@ -146,12 +148,21 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
146
148
|
end
|
147
149
|
|
148
150
|
|
149
|
-
def text_matches(text,list, default_list = [],post =false)
|
151
|
+
def text_matches(text,list, default_list = [],post =false)
|
152
|
+
text = text.strip
|
153
|
+
if post
|
154
|
+
result = nil
|
155
|
+
else
|
156
|
+
result = false
|
157
|
+
end
|
158
|
+
if text == nil
|
159
|
+
return result
|
160
|
+
end
|
150
161
|
if list == nil
|
151
162
|
list = default_list
|
152
163
|
elsif list.is_a?(String)
|
153
164
|
list = [list]
|
154
|
-
elsif !list.
|
165
|
+
elsif !list.respond_to?('each')
|
155
166
|
list = default_list
|
156
167
|
end
|
157
168
|
list.each do |regexp|
|
@@ -163,7 +174,7 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
163
174
|
#try to make it into a regexp
|
164
175
|
regexp = eval regexp
|
165
176
|
elsif
|
166
|
-
regexp = Regexp.new("^\s*#{regexp}
|
177
|
+
regexp = Regexp.new("^\s*#{regexp}",true);
|
167
178
|
end
|
168
179
|
end
|
169
180
|
if regexp == nil || !regexp.is_a?(Regexp)
|
@@ -171,15 +182,17 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
171
182
|
end
|
172
183
|
if post
|
173
184
|
if (match_data = regexp.match(text)) != nil
|
174
|
-
|
185
|
+
result = match_data.post_match
|
186
|
+
break
|
175
187
|
end
|
176
188
|
else
|
177
189
|
if text.match(regexp)
|
178
|
-
|
190
|
+
result = true
|
191
|
+
break
|
179
192
|
end
|
180
193
|
end
|
181
194
|
end
|
182
|
-
return
|
195
|
+
return result
|
183
196
|
end
|
184
197
|
|
185
198
|
|
@@ -197,10 +210,9 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
197
210
|
|
198
211
|
|
199
212
|
def has_open_connection
|
200
|
-
|
201
|
-
|
202
|
-
&& activity
|
203
|
-
&& activity + open >= Time.now.to_i
|
213
|
+
open = get_app_config("pluginManager","open")
|
214
|
+
activity = get_client_state(:activity)
|
215
|
+
result = open != nil && activity != nil && open.is_a?(Integer) && activity.is_a?(Integer) && (activity + open >= Time.now.to_i )
|
204
216
|
end
|
205
217
|
|
206
218
|
|
@@ -211,13 +223,13 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
211
223
|
def get_app_config(*args)
|
212
224
|
result = $APP_CONFIG
|
213
225
|
if args != nil \
|
214
|
-
&& (first_arg = args.
|
215
|
-
|
226
|
+
&& (first_arg = args.shift) != nil
|
227
|
+
eval "result = result.#{first_arg}"
|
216
228
|
args.each do |arg|
|
217
229
|
if arg == nil \
|
218
|
-
||
|
219
|
-
|| !
|
220
|
-
|| !
|
230
|
+
|| result == nil \
|
231
|
+
|| !result.respond_to?('has_key?')\
|
232
|
+
|| !result.has_key?(arg)
|
221
233
|
result = nil
|
222
234
|
break
|
223
235
|
end
|
@@ -238,22 +250,24 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
238
250
|
result = nil
|
239
251
|
log "Processing '#{text}'"
|
240
252
|
do_call_backs
|
253
|
+
proc_text = requested(text)
|
254
|
+
log "Processing proc '#{text}'"
|
241
255
|
if has_open_connection
|
242
256
|
log "Connection is still open"
|
243
|
-
if
|
244
|
-
#
|
245
|
-
proc_text = text
|
246
|
-
end
|
247
|
-
else
|
248
|
-
if (proc_text = requested(text)) == nil
|
249
|
-
no_matches
|
250
|
-
return nil
|
257
|
+
if proc_text == nil
|
258
|
+
#there was not request to honey made, so we need to process the original text
|
259
|
+
proc_text = text
|
251
260
|
end
|
261
|
+
elsif proc_text == nil
|
262
|
+
log "No open connection -- passing back to siri"
|
263
|
+
no_matches
|
264
|
+
return nil
|
252
265
|
end
|
253
266
|
log "Got Honey Command: #{proc_text}"
|
254
267
|
keep_open_connection
|
255
|
-
if
|
256
|
-
|
268
|
+
if proc_text \
|
269
|
+
&& (result = is_goodbye(proc_text) \
|
270
|
+
|| result = process_plugins(proc_text))
|
257
271
|
self.guzzoni_conn.block_rest_of_session
|
258
272
|
else
|
259
273
|
log "No matches for '#{proc_text}' on honey"
|
@@ -286,7 +300,9 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
286
300
|
result = false
|
287
301
|
goodbyes = get_app_config("pluginManager","goodbye")
|
288
302
|
if (result = text_matches(text,goodbyes))
|
303
|
+
log "Saying goodbye"
|
289
304
|
close_connection
|
305
|
+
result = true
|
290
306
|
end
|
291
307
|
return result
|
292
308
|
end
|
@@ -297,7 +313,7 @@ class SiriProxy::PluginManager::ClientStateCache < SiriProxy::PluginManager
|
|
297
313
|
#returns nil if we need to ignore this text. otherwise it returns the
|
298
314
|
#remainder of the text to be processed
|
299
315
|
def requested(text)
|
300
|
-
return text_matches(get_app_config("pluginManager","identifier"),['honey'],true)
|
316
|
+
return text_matches(text,get_app_config("pluginManager","identifier"),['honey'],true)
|
301
317
|
end
|
302
318
|
|
303
319
|
|