Merge lp:~abreu-alexandre/unity-js-scopes/registry into lp:unity-js-scopes
- registry
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Marcus Tomlinson | ||||
Approved revision: | 103 | ||||
Merged at revision: | 103 | ||||
Proposed branch: | lp:~abreu-alexandre/unity-js-scopes/registry | ||||
Merge into: | lp:unity-js-scopes | ||||
Diff against target: |
869 lines (+697/-21) 10 files modified
examples/simple/simple.js (+75/-0) src/bindings/index.js (+13/-1) src/bindings/src/addon.cc (+47/-20) src/bindings/src/registry.cc (+147/-0) src/bindings/src/registry.h (+121/-0) src/bindings/src/scope-base.cc (+4/-0) src/bindings/src/scope-base.h (+4/-0) src/bindings/src/scope-metadata.h (+132/-0) src/bindings/src/variant.cc (+102/-0) src/bindings/src/variant.h (+52/-0) |
||||
To merge this branch: | bzr merge lp:~abreu-alexandre/unity-js-scopes/registry | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marcus Tomlinson (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+274942@code.launchpad.net |
Commit message
Registry API handling
Description of the change
Registry API handling
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:90
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Marcus Tomlinson (marcustomlinson) wrote : | # |
These doc updates amongst impl is really horrible. Please could you split this branch into an impl MP and a doc MP? It is really tough to read this diff.
- 103. By Alexandre Abreu
-
Registry handling
Alexandre Abreu (abreu-alexandre) wrote : | # |
updated
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:103
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Marcus Tomlinson (marcustomlinson) wrote : | # |
Very nice!
Preview Diff
1 | === modified file 'examples/simple/simple.js' |
2 | --- examples/simple/simple.js 2015-10-27 06:38:13 +0000 |
3 | +++ examples/simple/simple.js 2015-10-29 14:09:08 +0000 |
4 | @@ -18,6 +18,80 @@ |
5 | |
6 | var scopes = require('unity-js-scopes') |
7 | |
8 | +var SCOPE_NAME = 'simple' |
9 | + |
10 | +function dump_scope_metadata(metadata) { |
11 | + console.log('Scope info'); |
12 | + console.log(' ' + metadata.scope_id()); |
13 | + console.log(' ' + metadata.display_name()); |
14 | + console.log(' ' + metadata.description()); |
15 | + console.log(' ' + metadata.author()); |
16 | + console.log(' ' + metadata.art()); |
17 | + console.log(' ' + metadata.icon()); |
18 | + console.log(' ' + metadata.search_hint()); |
19 | + console.log(' ' + metadata.hot_key()); |
20 | + console.log(' ' + metadata.invisible()); |
21 | + console.log(' ' + metadata.scope_directory()); |
22 | + console.log(' ' + metadata.location_data_needed()); |
23 | +} |
24 | + |
25 | +function dump_scope_registry_data() { |
26 | + try { |
27 | + console.log('Registry data ' + |
28 | + scopes.self.registry.is_scope_running(SCOPE_NAME)); |
29 | + } catch (e) { |
30 | + console.log(' ' + e); |
31 | + } |
32 | + |
33 | + try { |
34 | + var scopes_metadata = scopes.self.registry.list() |
35 | + |
36 | + for (var s in scopes_metadata) { |
37 | + dump_scope_metadata(scopes_metadata[s]) |
38 | + } |
39 | + } catch (e) { |
40 | + console.log(e); |
41 | + } |
42 | + |
43 | + try { |
44 | + console.log('First pass') |
45 | + var scopes_metadata = scopes.self.registry.list_if(function(info) { |
46 | + return info.scope_id() == 'forth' |
47 | + }) |
48 | + |
49 | + for (var s in scopes_metadata) { |
50 | + dump_scope_metadata(scopes_metadata[s]) |
51 | + } |
52 | + |
53 | + console.log('Second pass') |
54 | + scopes_metadata = scopes.self.registry.list_if(function(info) { |
55 | + return info.scope_id() == 'simple' |
56 | + }) |
57 | + |
58 | + for (var s in scopes_metadata) { |
59 | + dump_scope_metadata(scopes_metadata[s]) |
60 | + } |
61 | + } catch (e) { |
62 | + console.log(e); |
63 | + } |
64 | + |
65 | + try { |
66 | + var scopes_metadata = scopes.self.registry.list() |
67 | + |
68 | + for (var s in scopes_metadata) { |
69 | + scopes.self.registry.set_scope_state_callback( |
70 | + scopes_metadata[s].scope_id(), |
71 | + function(is_running) { |
72 | + console.log('I am possibly running ' |
73 | + + (is_running ? '(yes) ' : '(no) ') |
74 | + + scopes_metadata[s].scope_id()) |
75 | + }) |
76 | + } |
77 | + } catch (e) { |
78 | + console.log(e); |
79 | + } |
80 | +} |
81 | + |
82 | scopes.self.initialize( |
83 | {} |
84 | , |
85 | @@ -30,6 +104,7 @@ |
86 | + scope_id |
87 | + ', ' |
88 | + scopes.self.scope_config) |
89 | + dump_scope_registry_data(); |
90 | }, |
91 | search: function(canned_query, metadata) { |
92 | return new scopes.lib.SearchQuery( |
93 | |
94 | === modified file 'src/bindings/index.js' |
95 | --- src/bindings/index.js 2015-10-27 06:38:13 +0000 |
96 | +++ src/bindings/index.js 2015-10-29 14:09:08 +0000 |
97 | @@ -154,7 +154,7 @@ |
98 | * @property registry |
99 | */ |
100 | get registry() { |
101 | - return null |
102 | + return this._base.registry(); |
103 | }, |
104 | /** |
105 | * Returns a dictionary with the scope's current settings |
106 | @@ -172,6 +172,17 @@ |
107 | Disconnected: "Disconnected" |
108 | }; |
109 | |
110 | +var VariantType = { |
111 | + Null: "Null", |
112 | + Int: "Int", |
113 | + Int64: "Int64", |
114 | + Bool: "Bool", |
115 | + String: "String", |
116 | + Double: "Double", |
117 | + Dict: "Dict", |
118 | + Array: "Array" |
119 | +}; |
120 | + |
121 | var PostLoginAction = { |
122 | Unknown: "Unknown", |
123 | DoNothing: "DoNothing", |
124 | @@ -196,6 +207,7 @@ |
125 | lib: lib, |
126 | defs: { |
127 | PostLoginAction: PostLoginAction, |
128 | + VariantType: VariantType, |
129 | ConnectivityStatus: ConnectivityStatus, |
130 | OperationInfo: OperationInfo |
131 | } |
132 | |
133 | === modified file 'src/bindings/src/addon.cc' |
134 | --- src/bindings/src/addon.cc 2015-10-27 06:38:13 +0000 |
135 | +++ src/bindings/src/addon.cc 2015-10-29 14:09:08 +0000 |
136 | @@ -47,7 +47,9 @@ |
137 | #include "search-query.h" |
138 | #include "search-reply.h" |
139 | #include "search-metadata.h" |
140 | +#include "registry.h" |
141 | #include "result.h" |
142 | +#include "variant.h" |
143 | |
144 | // TODO static |
145 | JavascriptScopeRuntime* new_scope(const std::string& runtime_config) { |
146 | @@ -82,23 +84,19 @@ |
147 | { |
148 | v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
149 | |
150 | - v8cpp::Class<unity::scopes::VariantMap> variant_map(isolate); |
151 | - v8cpp::Class<unity::scopes::VariantArray> variant_array(isolate); |
152 | - |
153 | // TODO: which enum should be bound |
154 | - v8cpp::Class<unity::scopes::Variant> variant(isolate); |
155 | + v8cpp::Class<Variant> variant(isolate); |
156 | variant |
157 | - .add_method("get_int", &unity::scopes::Variant::get_int) |
158 | - .add_method("get_double", &unity::scopes::Variant::get_double) |
159 | - .add_method("get_bool", &unity::scopes::Variant::get_bool) |
160 | - .add_method("get_string", &unity::scopes::Variant::get_string) |
161 | - .add_method("get_dict", &unity::scopes::Variant::get_dict) |
162 | - .add_method("get_array", &unity::scopes::Variant::get_array) |
163 | - .add_method("is_null", &unity::scopes::Variant::is_null) |
164 | - .add_method("which", &unity::scopes::Variant::which) |
165 | - .add_method("serialize_json", &unity::scopes::Variant::serialize_json) |
166 | - .add_method("deserialize_json", &unity::scopes::Variant::deserialize_json) |
167 | - .add_method("which", &unity::scopes::Variant::which); |
168 | + .set_constructor<v8::Local<v8::Value>>() |
169 | + .add_method("get_int", &Variant::get_int) |
170 | + .add_method("get_double", &Variant::get_double) |
171 | + .add_method("get_bool", &Variant::get_bool) |
172 | + .add_method("get_string", &Variant::get_string) |
173 | + .add_method("get_dict", &Variant::get_dict) |
174 | + .add_method("get_array", &Variant::get_array) |
175 | + .add_method("is_null", &Variant::is_null) |
176 | + .add_method("which", &Variant::which) |
177 | + .add_method("serialize_json", &Variant::serialize_json); |
178 | |
179 | v8cpp::Class<JavascriptScopeRuntime> js_scope(isolate); |
180 | js_scope |
181 | @@ -114,12 +112,12 @@ |
182 | .add_method("onrun", &ScopeBase::onrun) |
183 | .add_method("onsearch", &ScopeBase::onsearch) |
184 | .add_method("onpreview", &ScopeBase::onpreview) |
185 | + .add_method("registry", &ScopeBase::get_registry) |
186 | // unity::scopes::ScopeBase |
187 | .add_method("scope_directory", &unity::scopes::ScopeBase::scope_directory) |
188 | .add_method("cache_directory", &unity::scopes::ScopeBase::cache_directory) |
189 | .add_method("tmp_directory", &unity::scopes::ScopeBase::tmp_directory) |
190 | - .add_method("settings", &unity::scopes::ScopeBase::settings) |
191 | - .add_method("registry", &unity::scopes::ScopeBase::registry); |
192 | + .add_method("settings", &unity::scopes::ScopeBase::settings); |
193 | |
194 | v8cpp::Class<ActionMetaData> action_metadata(isolate); |
195 | action_metadata |
196 | @@ -352,6 +350,36 @@ |
197 | .add_method("onrun", &SearchQuery::onrun) |
198 | .add_method("oncancelled", &SearchQuery::oncancelled); |
199 | |
200 | + v8cpp::Class<Registry> registry(isolate); |
201 | + registry |
202 | + // Registry |
203 | + .add_method("get_metadata", &Registry::get_metadata) |
204 | + .add_method("list", &Registry::list) |
205 | + .add_method("list_if", &Registry::list_if) |
206 | + .add_method("is_scope_running", &Registry::is_scope_running) |
207 | + .add_method("set_scope_state_callback", &Registry::set_scope_state_callback) |
208 | + .add_method("set_list_update_callback", &Registry::set_list_update_callback); |
209 | + |
210 | + v8cpp::Class<unity::scopes::ScopeMetadata> scope_metadata(isolate); |
211 | + scope_metadata |
212 | + // unity::scopes::ScopeMetadata |
213 | + .add_method("scope_id", &unity::scopes::ScopeMetadata::scope_id) |
214 | + // .add_method("scope_proxy", &unity::scopes::ScopeMetadata::scope_proxy) |
215 | + .add_method("display_name", &unity::scopes::ScopeMetadata::display_name) |
216 | + .add_method("description", &unity::scopes::ScopeMetadata::description) |
217 | + .add_method("author", &unity::scopes::ScopeMetadata::author) |
218 | + .add_method("art", &unity::scopes::ScopeMetadata::art) |
219 | + .add_method("icon", &unity::scopes::ScopeMetadata::icon) |
220 | + .add_method("search_hint", &unity::scopes::ScopeMetadata::search_hint) |
221 | + .add_method("hot_key", &unity::scopes::ScopeMetadata::hot_key) |
222 | + .add_method("invisible", &unity::scopes::ScopeMetadata::invisible) |
223 | + // .add_method("appearance_attributes", &unity::scopes::ScopeMetadata::appearance_attributes) |
224 | + .add_method("scope_directory", &unity::scopes::ScopeMetadata::scope_directory) |
225 | + // .add_method("serialize", &unity::scopes::ScopeMetadata::serialize) |
226 | + // .add_method("results_ttl_type", &unity::scopes::ScopeMetadata::results_ttl_type) |
227 | + // .add_method("settings_definitions", &unity::scopes::ScopeMetadata::settings_definitions) |
228 | + .add_method("location_data_needed", &unity::scopes::ScopeMetadata::location_data_needed); |
229 | + |
230 | v8cpp::Class<SearchMetadata> search_metadata(isolate); |
231 | search_metadata |
232 | .set_constructor<v8::FunctionCallbackInfo<v8::Value>>() |
233 | @@ -400,7 +428,6 @@ |
234 | v8cpp::Module module(isolate); |
235 | module.add_class("js_scope", js_scope); |
236 | module.add_class("scope_base", scope_base); |
237 | - |
238 | module.add_class("ActionMetadata", action_metadata); |
239 | module.add_class("ActivationQuery", activation_query); |
240 | module.add_class("Category", category); |
241 | @@ -420,13 +447,13 @@ |
242 | module.add_class("PreviewWidget", preview_widget); |
243 | module.add_class("PreviewQuery", preview_query); |
244 | module.add_class("PreviewReply", preview_reply); |
245 | + module.add_class("Registry", registry); |
246 | module.add_class("Result", result); |
247 | + module.add_class("ScopeMetadata", scope_metadata); |
248 | module.add_class("SearchReply", search_reply); |
249 | module.add_class("SearchQuery", search_query); |
250 | module.add_class("SearchMetadata", search_metadata); |
251 | module.add_class("Variant", variant); |
252 | - module.add_class("Variant_map", variant_map); |
253 | - module.add_class("Variant_array", variant_array); |
254 | |
255 | // Factory functions |
256 | module.add_function("new_scope", &new_scope); |
257 | |
258 | === added file 'src/bindings/src/registry.cc' |
259 | --- src/bindings/src/registry.cc 1970-01-01 00:00:00 +0000 |
260 | +++ src/bindings/src/registry.cc 2015-10-29 14:09:08 +0000 |
261 | @@ -0,0 +1,147 @@ |
262 | +/* |
263 | + * Copyright 2015 Canonical Ltd. |
264 | + * |
265 | + * This file is part of unity-js-scopes. |
266 | + * |
267 | + * unity-js-scopes is free software; you can redistribute it and/or modify |
268 | + * it under the terms of the GNU General Public License as published by |
269 | + * the Free Software Foundation; version 3. |
270 | + * |
271 | + * unity-js-scopes is distributed in the hope that it will be useful, |
272 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
273 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
274 | + * GNU General Public License for more details. |
275 | + * |
276 | + * You should have received a copy of the GNU General Public License |
277 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
278 | + */ |
279 | + |
280 | +#include "registry.h" |
281 | + |
282 | +#include "event_queue.h" |
283 | + |
284 | +namespace { |
285 | + |
286 | +// Moveable v8::UniquePersistent |
287 | +template <typename T> |
288 | +struct MoveablePersistent : public v8::UniquePersistent<T> |
289 | +{ |
290 | + using BaseClass = v8::UniquePersistent<T>; |
291 | + using BaseClass::BaseClass; |
292 | + |
293 | + MoveablePersistent(MoveablePersistent&& src) |
294 | + : BaseClass(src.Pass()) |
295 | + { |
296 | + } |
297 | + |
298 | + MoveablePersistent(MoveablePersistent const&) = delete; |
299 | +}; |
300 | + |
301 | +std::map<std::shared_ptr<Registry>, |
302 | + std::pair<core::ScopedConnection, |
303 | + MoveablePersistent<v8::Function>>> active_scope_state_connections_; |
304 | + |
305 | +std::map<std::shared_ptr<Registry>, |
306 | + std::pair<core::ScopedConnection, |
307 | + MoveablePersistent<v8::Function>>> active_list_update_connections_; |
308 | + |
309 | +} |
310 | + |
311 | +Registry::Registry(unity::scopes::RegistryProxy proxy) |
312 | + : isolate_(v8::Isolate::GetCurrent()) |
313 | + , proxy_(proxy) { |
314 | +} |
315 | + |
316 | +unity::scopes::ScopeMetadata Registry::get_metadata(std::string const &scope_id) { |
317 | + return proxy_->get_metadata(scope_id); |
318 | +} |
319 | + |
320 | +unity::scopes::MetadataMap Registry::list() { |
321 | + return proxy_->list(); |
322 | +} |
323 | + |
324 | +unity::scopes::MetadataMap Registry::list_if(v8::Local<v8::Function> predicate) { |
325 | + return proxy_->list_if([this, predicate] (unity::scopes::ScopeMetadata const& item) -> bool { |
326 | + v8::Handle<v8::Value> result = |
327 | + v8cpp::call_v8_with_receiver( |
328 | + isolate_, |
329 | + v8cpp::to_v8(isolate_, shared_from_this()), |
330 | + predicate, |
331 | + v8cpp::to_v8(isolate_, item) |
332 | + ); |
333 | + return v8cpp::from_v8<bool>(isolate_, result); |
334 | + }); |
335 | +} |
336 | + |
337 | +bool Registry::is_scope_running(const std::string& scope_id) { |
338 | + return proxy_->is_scope_running(scope_id); |
339 | +} |
340 | + |
341 | +void Registry::set_scope_state_callback(const std::string& scope_id, |
342 | + v8::Local<v8::Function> callback) { |
343 | + { |
344 | + auto it = active_scope_state_connections_.find(shared_from_this()); |
345 | + if (it != active_scope_state_connections_.end()) { |
346 | + active_scope_state_connections_.erase(it); |
347 | + } |
348 | + } |
349 | + |
350 | + core::ScopedConnection connection = |
351 | + proxy_->set_scope_state_callback(scope_id, [this, callback] (bool is_running) { |
352 | + EventQueue::instance().run(isolate_, [this, callback, is_running] { |
353 | + auto it = active_scope_state_connections_.find(shared_from_this()); |
354 | + v8::Local<v8::Function> cb = |
355 | + v8cpp::to_local<v8::Function>(isolate_, it->second.second); |
356 | + |
357 | + v8cpp::call_v8_with_receiver( |
358 | + isolate_, |
359 | + v8cpp::to_v8(isolate_, shared_from_this()), |
360 | + cb, |
361 | + v8cpp::to_v8(isolate_, is_running) |
362 | + ); |
363 | + }); |
364 | + }); |
365 | + |
366 | + MoveablePersistent<v8::Function> persistent_callback(isolate_, callback); |
367 | + |
368 | + active_scope_state_connections_.insert( |
369 | + std::make_pair( |
370 | + shared_from_this(), |
371 | + std::make_pair( |
372 | + core::ScopedConnection(std::move(connection)), |
373 | + std::move(persistent_callback)))); |
374 | +} |
375 | + |
376 | +void Registry::set_list_update_callback(v8::Local<v8::Function> callback) { |
377 | + { |
378 | + auto it = active_list_update_connections_.find(shared_from_this()); |
379 | + if (it != active_list_update_connections_.end()) { |
380 | + active_list_update_connections_.erase(it); |
381 | + } |
382 | + } |
383 | + |
384 | + core::ScopedConnection connection = |
385 | + proxy_->set_list_update_callback([this, callback] () { |
386 | + EventQueue::instance().run(isolate_, [this, callback] { |
387 | + auto it = active_list_update_connections_.find(shared_from_this()); |
388 | + v8::Local<v8::Function> cb = |
389 | + v8cpp::to_local<v8::Function>(isolate_, it->second.second); |
390 | + |
391 | + v8cpp::call_v8_with_receiver( |
392 | + isolate_, |
393 | + v8cpp::to_v8(isolate_, shared_from_this()), |
394 | + cb |
395 | + ); |
396 | + }); |
397 | + }); |
398 | + |
399 | + MoveablePersistent<v8::Function> persistent_callback(isolate_, callback); |
400 | + |
401 | + active_list_update_connections_.insert( |
402 | + std::make_pair( |
403 | + shared_from_this(), |
404 | + std::make_pair( |
405 | + core::ScopedConnection(std::move(connection)), |
406 | + std::move(persistent_callback)))); |
407 | +} |
408 | + |
409 | |
410 | === added file 'src/bindings/src/registry.h' |
411 | --- src/bindings/src/registry.h 1970-01-01 00:00:00 +0000 |
412 | +++ src/bindings/src/registry.h 2015-10-29 14:09:08 +0000 |
413 | @@ -0,0 +1,121 @@ |
414 | +/* |
415 | + * Copyright 2015 Canonical Ltd. |
416 | + * |
417 | + * This file is part of unity-js-scopes. |
418 | + * |
419 | + * unity-js-scopes is free software; you can redistribute it and/or modify |
420 | + * it under the terms of the GNU General Public License as published by |
421 | + * the Free Software Foundation; version 3. |
422 | + * |
423 | + * unity-js-scopes is distributed in the hope that it will be useful, |
424 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
425 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
426 | + * GNU General Public License for more details. |
427 | + * |
428 | + * You should have received a copy of the GNU General Public License |
429 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
430 | + */ |
431 | + |
432 | +#ifndef _UNITY_JS_REGISTRY_H_ |
433 | +#define _UNITY_JS_REGISTRY_H_ |
434 | + |
435 | +#include <unity/scopes/Registry.h> |
436 | + |
437 | +#include <v8-cpp.h> |
438 | + |
439 | +/** |
440 | + |
441 | +--doc:class Registry |
442 | + * |
443 | + * White pages service for available scopes |
444 | + * |
445 | + * @module ScopeJS |
446 | + * |
447 | + * @class Registry |
448 | +--/doc:class |
449 | + |
450 | +--doc:prototype Registry |
451 | + |
452 | +--doc:member |
453 | + * Returns the metadata for the scope with the given ID |
454 | + * @method get_metadata |
455 | + * @param id {String} Attribute definition |
456 | + * @return {ScopeMetadata} |
457 | +--doc:/member |
458 | +get_metadata: function(id) { |
459 | +} |
460 | +--/doc:member |
461 | + |
462 | +--doc:member |
463 | + * Returns a map containing the metadata for all scopes |
464 | + * @method list |
465 | + * @return {Dictionary of String -> ScopeMetadata} |
466 | +--doc:/member |
467 | +list: function() { |
468 | +} |
469 | +--/doc:member |
470 | + |
471 | +--doc:member |
472 | + * Returns a map containing only those scopes for which predicate returns true |
473 | + * @method list_if |
474 | + * @param predicate {Function(ScopeMetadata)} a function that must return true for each metadata item to be included in the map. |
475 | + * @return {Dictionary of String -> ScopeMetadata} |
476 | +--doc:/member |
477 | +list_if: function(predicate) { |
478 | +} |
479 | +--/doc:member |
480 | + |
481 | +--doc:member |
482 | + * Returns whether a scope is currently running or not |
483 | + * @method is_scope_running |
484 | + * @param scope_id {String} The ID of the scope from which we wish to retrieve state |
485 | + * @return {Boolean} True if the scope is running, and False if it is not running |
486 | +--doc:/member |
487 | +is_scope_running: function(scope_id) { |
488 | +} |
489 | +--/doc:member |
490 | + |
491 | +--doc:member |
492 | + * Assigns a callback method to be executed when a scope's running state (started / stopped) changes |
493 | + * @method set_scope_state_callback |
494 | + * @param scope_id {String} The ID of the scope from which we wish to retrieve state changes |
495 | + * @param callback {Function(is_running: Boolean)} The function that is invoked when a scope changes running state |
496 | +--doc:/member |
497 | +set_scope_state_callback: function(scope_id, callback) { |
498 | +} |
499 | +--/doc:member |
500 | + |
501 | +--doc:member |
502 | + * Assigns a callback method to be executed when the registry's scope list changes |
503 | + * |
504 | + * Note: Upon receiving this callback, you should retrieve the updated scopes list via the list() method if you wish to retain synchronisation between client and server |
505 | + * @method set_list_update_callback |
506 | + * @param callback {Function()} The function that is invoked when an update occurs |
507 | +--doc:/member |
508 | +set_list_update_callback: function(callback) { |
509 | +} |
510 | +--/doc:member |
511 | + |
512 | +--/doc:prototype |
513 | + */ |
514 | + |
515 | +class Registry : public std::enable_shared_from_this<Registry> |
516 | +{ |
517 | + public: |
518 | + Registry(unity::scopes::RegistryProxy proxy); |
519 | + |
520 | + unity::scopes::ScopeMetadata get_metadata(std::string const &scope_id); |
521 | + unity::scopes::MetadataMap list(); |
522 | + unity::scopes::MetadataMap list_if(v8::Local<v8::Function> predicate); |
523 | + bool is_scope_running(const std::string& scope_id); |
524 | + void set_scope_state_callback(const std::string& scope_id, |
525 | + v8::Local<v8::Function> callback); |
526 | + void set_list_update_callback(v8::Local<v8::Function> callback); |
527 | + |
528 | + private: |
529 | + |
530 | + v8::Isolate * isolate_; |
531 | + unity::scopes::RegistryProxy proxy_; |
532 | +}; |
533 | + |
534 | +#endif // _UNITY_IS_REGISTRY_ |
535 | |
536 | === modified file 'src/bindings/src/scope-base.cc' |
537 | --- src/bindings/src/scope-base.cc 2015-10-22 19:50:35 +0000 |
538 | +++ src/bindings/src/scope-base.cc 2015-10-29 14:09:08 +0000 |
539 | @@ -319,3 +319,7 @@ |
540 | v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]); |
541 | preview_callback_.Reset(args.GetIsolate(), cb); |
542 | } |
543 | + |
544 | +std::shared_ptr<Registry> ScopeBase::get_registry() const { |
545 | + return std::shared_ptr<Registry>(new Registry(registry())); |
546 | +} |
547 | |
548 | === modified file 'src/bindings/src/scope-base.h' |
549 | --- src/bindings/src/scope-base.h 2015-10-08 17:58:18 +0000 |
550 | +++ src/bindings/src/scope-base.h 2015-10-29 14:09:08 +0000 |
551 | @@ -23,6 +23,8 @@ |
552 | |
553 | #include <unity/scopes/ScopeBase.h> |
554 | |
555 | +#include "registry.h" |
556 | + |
557 | class ScopeBase : public unity::scopes::ScopeBase |
558 | { |
559 | public: |
560 | @@ -39,6 +41,8 @@ |
561 | void onactivate(v8::FunctionCallbackInfo<v8::Value> const& args); |
562 | void onperform_action(v8::FunctionCallbackInfo<v8::Value> const& args); |
563 | |
564 | + std::shared_ptr<Registry> get_registry() const; |
565 | + |
566 | // unity::scopes::ScopeBase implementation |
567 | void start(std::string const& scope_id) override; |
568 | void stop() override; |
569 | |
570 | === added file 'src/bindings/src/scope-metadata.h' |
571 | --- src/bindings/src/scope-metadata.h 1970-01-01 00:00:00 +0000 |
572 | +++ src/bindings/src/scope-metadata.h 2015-10-29 14:09:08 +0000 |
573 | @@ -0,0 +1,132 @@ |
574 | +/* |
575 | + * Copyright 2015 Canonical Ltd. |
576 | + * |
577 | + * This file is part of unity-js-scopes. |
578 | + * |
579 | + * unity-js-scopes is free software; you can redistribute it and/or modify |
580 | + * it under the terms of the GNU General Public License as published by |
581 | + * the Free Software Foundation; version 3. |
582 | + * |
583 | + * unity-js-scopes is distributed in the hope that it will be useful, |
584 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
585 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
586 | + * GNU General Public License for more details. |
587 | + * |
588 | + * You should have received a copy of the GNU General Public License |
589 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
590 | + */ |
591 | + |
592 | +/** |
593 | + |
594 | +--doc:class ScopeMetadata |
595 | + * |
596 | + * Holds scope attributes such as name, description, icon etc |
597 | + * |
598 | + * @module ScopeJS |
599 | + * |
600 | + * @class ScopeMetadata |
601 | +--/doc:class |
602 | + |
603 | +--doc:prototype ScopeMetadata |
604 | + |
605 | +--doc:member |
606 | + * Get the scope identifier |
607 | + * @method scope_id |
608 | + * @return {String} |
609 | +--doc:/member |
610 | +scope_id: function() { |
611 | +} |
612 | +--/doc:member |
613 | + |
614 | +--doc:member |
615 | + * Get the scope display name |
616 | + * @method display_name |
617 | + * @return {String} |
618 | +--doc:/member |
619 | +display_name: function() { |
620 | +} |
621 | +--/doc:member |
622 | + |
623 | +--doc:member |
624 | + * Get the scope description |
625 | + * @method description |
626 | + * @return {String} |
627 | +--doc:/member |
628 | +description: function() { |
629 | +} |
630 | +--/doc:member |
631 | + |
632 | +--doc:member |
633 | + * Get the scope author |
634 | + * @method author |
635 | + * @return {String} |
636 | +--doc:/member |
637 | +author: function() { |
638 | +} |
639 | +--/doc:member |
640 | + |
641 | +--doc:member |
642 | + * Get the scope art |
643 | + * @method art |
644 | + * @return {String} |
645 | +--doc:/member |
646 | +art: function() { |
647 | +} |
648 | +--/doc:member |
649 | + |
650 | +--doc:member |
651 | + * Get the scope icon |
652 | + * @method icon |
653 | + * @return {String} |
654 | +--doc:/member |
655 | +icon: function() { |
656 | +} |
657 | +--/doc:member |
658 | + |
659 | +--doc:member |
660 | + * Get the scope search_hint |
661 | + * @method search_hint |
662 | + * @return {String} |
663 | +--doc:/member |
664 | +search_hint: function() { |
665 | +} |
666 | +--/doc:member |
667 | + |
668 | +--doc:member |
669 | + * Get the scope hot key |
670 | + * @method hot_key |
671 | + * @return {String} |
672 | +--doc:/member |
673 | +hot_key: function() { |
674 | +} |
675 | +--/doc:member |
676 | + |
677 | +--doc:member |
678 | + * Checks if the scope is invisible |
679 | + * @method invisible |
680 | + * @return {Boolean} |
681 | +--doc:/member |
682 | +invisible: function() { |
683 | +} |
684 | +--/doc:member |
685 | + |
686 | +--doc:member |
687 | + * Gets the scope directory |
688 | + * @method scope_directory |
689 | + * @return {String} |
690 | +--doc:/member |
691 | +scope_directory: function() { |
692 | +} |
693 | +--/doc:member |
694 | + |
695 | +--doc:member |
696 | + * Checks if the scope needs location data |
697 | + * @method location_data_needed |
698 | + * @return {Boolean} |
699 | +--doc:/member |
700 | +location_data_needed: function() { |
701 | +} |
702 | +--/doc:member |
703 | + |
704 | +--/doc:prototype |
705 | + */ |
706 | |
707 | === added file 'src/bindings/src/variant.cc' |
708 | --- src/bindings/src/variant.cc 1970-01-01 00:00:00 +0000 |
709 | +++ src/bindings/src/variant.cc 2015-10-29 14:09:08 +0000 |
710 | @@ -0,0 +1,102 @@ |
711 | +/* |
712 | + * Copyright 2015 Canonical Ltd. |
713 | + * |
714 | + * This file is part of unity-js-scopes. |
715 | + * |
716 | + * unity-js-scopes is free software; you can redistribute it and/or modify |
717 | + * it under the terms of the GNU General Public License as published by |
718 | + * the Free Software Foundation; version 3. |
719 | + * |
720 | + * unity-js-scopes is distributed in the hope that it will be useful, |
721 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
722 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
723 | + * GNU General Public License for more details. |
724 | + * |
725 | + * You should have received a copy of the GNU General Public License |
726 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
727 | + */ |
728 | + |
729 | +#include "variant.h" |
730 | + |
731 | +#include "common.h" |
732 | + |
733 | +namespace { |
734 | + |
735 | +std::string |
736 | +variant_string_from_type(unity::scopes::Variant::Type type) { |
737 | + switch(type) { |
738 | + case unity::scopes::Variant::Null: |
739 | + return "Null"; |
740 | + case unity::scopes::Variant::Int: |
741 | + return "Int"; |
742 | + case unity::scopes::Variant::Bool: |
743 | + return "Bool"; |
744 | + case unity::scopes::Variant::String: |
745 | + return "String"; |
746 | + case unity::scopes::Variant::Double: |
747 | + return "Double"; |
748 | + case unity::scopes::Variant::Dict: |
749 | + return "Dict"; |
750 | + case unity::scopes::Variant::Array: |
751 | + return "Array"; |
752 | + case unity::scopes::Variant::Int64: |
753 | + return "Int64"; |
754 | + } |
755 | + throw std::runtime_error("Invalid Variant type value"); |
756 | +} |
757 | + |
758 | +} |
759 | + |
760 | + |
761 | +Variant::Variant(unity::scopes::Variant const &variant) |
762 | + : variant_(new unity::scopes::Variant(variant)) { |
763 | +} |
764 | + |
765 | +Variant::Variant(v8::Local<v8::Value> arg) |
766 | + : variant_(new unity::scopes::Variant(unity::scopesjs::to_variant(arg))) { |
767 | +} |
768 | + |
769 | +std::string Variant::serialize_json() const { |
770 | + return variant_->serialize_json(); |
771 | +} |
772 | + |
773 | +int Variant::get_int() const { |
774 | + return variant_->get_int(); |
775 | +} |
776 | + |
777 | +double Variant::get_double() const { |
778 | + return variant_->get_double(); |
779 | +} |
780 | + |
781 | +bool Variant::get_bool() const { |
782 | + return variant_->get_bool(); |
783 | +} |
784 | + |
785 | +std::string Variant::get_string() const { |
786 | + return variant_->get_string(); |
787 | +} |
788 | + |
789 | +Variant::VariantMap Variant::get_dict() const { |
790 | + VariantMap vm; |
791 | + for(auto &v: variant_->get_dict()) { |
792 | + vm[v.first] = std::make_shared<Variant>(v.second); |
793 | + } |
794 | + return vm; |
795 | +} |
796 | + |
797 | +Variant::VariantArray Variant::get_array() const { |
798 | + VariantArray va; |
799 | + for(auto &v: variant_->get_array()) { |
800 | + va.push_back(std::make_shared<Variant>(v)); |
801 | + } |
802 | + return va; |
803 | +} |
804 | + |
805 | +bool Variant::is_null() const { |
806 | + return variant_->is_null(); |
807 | +} |
808 | + |
809 | +std::string Variant::which() { |
810 | + return variant_string_from_type(variant_->which()); |
811 | +} |
812 | + |
813 | |
814 | === added file 'src/bindings/src/variant.h' |
815 | --- src/bindings/src/variant.h 1970-01-01 00:00:00 +0000 |
816 | +++ src/bindings/src/variant.h 2015-10-29 14:09:08 +0000 |
817 | @@ -0,0 +1,52 @@ |
818 | +/* |
819 | + * Copyright 2015 Canonical Ltd. |
820 | + * |
821 | + * This file is part of unity-js-scopes. |
822 | + * |
823 | + * unity-js-scopes is free software; you can redistribute it and/or modify |
824 | + * it under the terms of the GNU General Public License as published by |
825 | + * the Free Software Foundation; version 3. |
826 | + * |
827 | + * unity-js-scopes is distributed in the hope that it will be useful, |
828 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
829 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
830 | + * GNU General Public License for more details. |
831 | + * |
832 | + * You should have received a copy of the GNU General Public License |
833 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
834 | + */ |
835 | + |
836 | +#ifndef _UNITY_JS_VARIANT_H_ |
837 | +#define _UNITY_JS_VARIANT_H_ |
838 | + |
839 | +#include <unity/scopes/Variant.h> |
840 | + |
841 | +#include <v8-cpp.h> |
842 | + |
843 | +class Variant |
844 | +{ |
845 | + public: |
846 | + |
847 | + typedef std::map<std::string, std::shared_ptr<Variant>> VariantMap; |
848 | + typedef std::vector<std::shared_ptr<Variant>> VariantArray; |
849 | + |
850 | + public: |
851 | + Variant(unity::scopes::Variant const &variant); |
852 | + Variant(v8::Local<v8::Value> arg); |
853 | + |
854 | + // v8 bindings |
855 | + std::string serialize_json() const; |
856 | + int get_int() const; |
857 | + double get_double() const; |
858 | + bool get_bool() const; |
859 | + std::string get_string() const; |
860 | + VariantMap get_dict() const; |
861 | + VariantArray get_array() const; |
862 | + bool is_null() const; |
863 | + std::string which(); |
864 | + |
865 | + private: |
866 | + std::shared_ptr<unity::scopes::Variant> variant_; |
867 | +}; |
868 | + |
869 | +#endif // _UNITY_JS_VARIANT_H_ |
PASSED: Continuous integration, rev:89 jenkins. qa.ubuntu. com/job/ unity-js- scopes- ci/44/ jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-amd64- ci/45 jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-armhf- ci/45 jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-armhf- ci/45/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-i386- ci/44
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- js-scopes- ci/44/rebuild
http://