Merge lp:~rainct/zeitgeist/matches-template into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Approved by: Michal Hruby
Approved revision: 406
Merged at revision: 406
Proposed branch: lp:~rainct/zeitgeist/matches-template
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 304 lines (+147/-32)
3 files modified
src/datamodel.vala (+69/-31)
test/direct/Makefile.am (+8/-1)
test/direct/datamodel-test.vala (+70/-0)
To merge this branch: bzr merge lp:~rainct/zeitgeist/matches-template
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+93279@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

115 + // FIXME: change this to va_list once Vala bug #647097 is fixed
116 + public Event.full (string? interpretation=null,
117 + string? manifestation=null, string? actor=null,
118 + string? origin=null, GenericArray<Subject>? subjects=null)

This is very close to public API, I'd prefer this didn't change, so if we want a variant with a PtrArray, let's call it something else (for example full_from_ptrarray)

328 + // FIXME: figure out how we want to treat multiple subjects in the template

Same way engine does, ie AND them within one event.

review: Needs Fixing
Revision history for this message
Siegfried Gevatter (rainct) wrote :

2012/2/17 Michal Hruby <email address hidden>:
> This is very close to public API, I'd prefer this didn't change, so if we want a variant with a PtrArray, let's call it something else (for example full_from_ptrarray)

I don't want PtrArray, it's just a workaround since Vala is br0ken.

> 328     +    // FIXME: figure out how we want to treat multiple subjects in the template
> Same way engine does, ie AND them within one event.

Yeah, that's not what I mean, but rather: if there's two empty
subjects, does that mean anything (ie. I want events with exactly two
subject) or are they just ignored? But I retract the question, the
former would just be confusing.

Revision history for this message
Michal Hruby (mhr3) wrote :

> I don't want PtrArray, it's just a workaround since Vala is br0ken.

Then don't add that method yet.

406. By Siegfried Gevatter

Leave va_list there but don't use it.

Revision history for this message
Michal Hruby (mhr3) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala 2012-02-15 18:27:21 +0000
+++ src/datamodel.vala 2012-02-18 21:37:18 +0000
@@ -4,6 +4,8 @@
4 * By Seif Lotfy <seif@lotfy.com>4 * By Seif Lotfy <seif@lotfy.com>
5 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>5 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
6 * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>6 * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>
7 * Copyright © 2012 Canonical Ltd.
8 * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk>
7 *9 *
8 * This program is free software: you can redistribute it and/or modify10 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by11 * it under the terms of the GNU Lesser General Public License as published by
@@ -262,15 +264,18 @@
262 ANY = 2 // The event subjects may or may not be available264 ANY = 2 // The event subjects may or may not be available
263 }265 }
264266
265 private bool check_field_match (string property,267 private bool check_field_match (string? property,
266 string template_property, bool is_symbol = false,268 string? template_property, bool is_symbol = false,
267 bool can_wildcard = false)269 bool can_wildcard = false)
268 {270 {
269 var matches = false;271 var matches = false;
272 var is_negated = false;
270 var parsed = template_property;273 var parsed = template_property;
271 var is_negated = Utils.parse_negation (ref parsed);274
272275 if (parsed != null)
273 if (parsed == "")276 is_negated = Utils.parse_negation (ref parsed);
277
278 if (Utils.is_empty_string (parsed))
274 {279 {
275 return true;280 return true;
276 }281 }
@@ -278,14 +283,15 @@
278 {283 {
279 matches = true;284 matches = true;
280 }285 }
281 else if (is_symbol &&286 else if (is_symbol && property != null &&
282 Symbol.get_all_parents (property).find_custom (parsed, strcmp) != null)287 Symbol.get_all_parents (property).find_custom (parsed, strcmp) != null)
283 {288 {
284 matches = true;289 matches = true;
285 }290 }
286 else if (can_wildcard && Utils.parse_wildcard (ref parsed))291 else if (can_wildcard && Utils.parse_wildcard (ref parsed))
287 {292 {
288 if (property.has_prefix (parsed)) matches = true;293 if (property != null && property.has_prefix (parsed))
294 matches = true;
289 }295 }
290296
291 return (is_negated) ? !matches : matches;297 return (is_negated) ? !matches : matches;
@@ -297,27 +303,27 @@
297303
298 public uint32 id { get; set; }304 public uint32 id { get; set; }
299 public int64 timestamp { get; set; }305 public int64 timestamp { get; set; }
300 public string origin { get; set; }306 public string? origin { get; set; }
301307
302 public string actor308 public string? actor
303 {309 {
304 get { return _actor; }310 get { return _actor; }
305 set { _actor = url_store.insert_const (value); }311 set { _actor = (value != null) ? url_store.insert_const (value) : null; }
306 }312 }
307 public string interpretation313 public string? interpretation
308 {314 {
309 get { return _interpretation; }315 get { return _interpretation; }
310 set { _interpretation = url_store.insert_const (value); }316 set { _interpretation = (value != null) ? url_store.insert_const (value) : null; }
311 }317 }
312 public string manifestation318 public string? manifestation
313 {319 {
314 get { return _manifestation; }320 get { return _manifestation; }
315 set { _manifestation = url_store.insert_const (value); }321 set { _manifestation = (value != null) ? url_store.insert_const (value) : null; }
316 }322 }
317323
318 private unowned string _actor;324 private unowned string? _actor;
319 private unowned string _interpretation;325 private unowned string? _interpretation;
320 private unowned string _manifestation;326 private unowned string? _manifestation;
321327
322 public GenericArray<Subject> subjects { get; set; }328 public GenericArray<Subject> subjects { get; set; }
323 public ByteArray? payload { get; set; }329 public ByteArray? payload { get; set; }
@@ -342,6 +348,24 @@
342 subjects.add (subject);348 subjects.add (subject);
343 }349 }
344350
351 public Event.full (string? interpretation=null,
352 string? manifestation=null, string? actor=null,
353 string? origin=null, ...)
354 {
355 this.interpretation = interpretation;
356 this.manifestation = manifestation;
357 this.actor = actor;
358 this.origin = origin;
359
360 // FIXME: We can't use this until Vala bug #647097 is fixed
361 /*
362 var subjects = va_list ();
363 unowned Subject subject;
364 while ((subject = subjects.arg ()) != null)
365 add_subject (subject);
366 */
367 }
368
345 public Event.from_variant (Variant event_variant) throws EngineError {369 public Event.from_variant (Variant event_variant) throws EngineError {
346 assert_sig (event_variant.get_type_string () == "(" +370 assert_sig (event_variant.get_type_string () == "(" +
347 Utils.SIG_EVENT + ")", "Invalid D-Bus signature.");371 Utils.SIG_EVENT + ")", "Invalid D-Bus signature.");
@@ -560,39 +584,53 @@
560 {584 {
561 private static StringChunk url_store;585 private static StringChunk url_store;
562586
563 public string uri { get; set; }587 public string? uri { get; set; }
564 public string origin { get; set; }588 public string? origin { get; set; }
565 public string text { get; set; }589 public string? text { get; set; }
566 public string storage { get; set; }590 public string? storage { get; set; }
567 // FIXME: current_uri is often the same as uri, we don't need to waste591 // FIXME: current_uri is often the same as uri, we don't need to waste
568 // memory for it592 // memory for it
569 public string current_uri { get; set; }593 public string? current_uri { get; set; }
570594
571 public string mimetype595 public string? mimetype
572 {596 {
573 get { return _mimetype; }597 get { return _mimetype; }
574 set { _mimetype = url_store.insert_const (value); }598 set { _mimetype = (value != null) ? url_store.insert_const (value) : null; }
575 }599 }
576 public string interpretation600 public string? interpretation
577 {601 {
578 get { return _interpretation; }602 get { return _interpretation; }
579 set { _interpretation = url_store.insert_const (value); }603 set { _interpretation = (value != null) ? url_store.insert_const (value) : null; }
580 }604 }
581 public string manifestation605 public string? manifestation
582 {606 {
583 get { return _manifestation; }607 get { return _manifestation; }
584 set { _manifestation = url_store.insert_const (value); }608 set { _manifestation = (value != null) ? url_store.insert_const (value) : null; }
585 }609 }
586610
587 private unowned string _mimetype;611 private unowned string? _mimetype;
588 private unowned string _interpretation;612 private unowned string? _interpretation;
589 private unowned string _manifestation;613 private unowned string? _manifestation;
590614
591 static construct615 static construct
592 {616 {
593 url_store = new StringChunk (4096);617 url_store = new StringChunk (4096);
594 }618 }
595619
620 public Subject.full (string? uri=null,
621 string? interpretation=null, string? manifestation=null,
622 string? mimetype=null, string? origin=null, string? text=null,
623 string? storage=null, string? current_uri=null)
624 {
625 this.interpretation = interpretation;
626 this.manifestation = manifestation;
627 this.mimetype = mimetype;
628 this.origin = origin;
629 this.text = text;
630 this.storage = storage;
631 this.current_uri = current_uri;
632 }
633
596 public Subject.from_variant (Variant subject_variant)634 public Subject.from_variant (Variant subject_variant)
597 throws EngineError635 throws EngineError
598 {636 {
599637
=== modified file 'test/direct/Makefile.am'
--- test/direct/Makefile.am 2012-02-13 19:43:15 +0000
+++ test/direct/Makefile.am 2012-02-18 21:37:18 +0000
@@ -6,9 +6,11 @@
6 --pkg gmodule-2.0 \6 --pkg gmodule-2.0 \
7 $(srcdir)/assertions.vapi \7 $(srcdir)/assertions.vapi \
8 --Xcc=-w \8 --Xcc=-w \
9 -g \
9 $(NULL)10 $(NULL)
1011
11TESTS = \12TESTS = \
13 datamodel-test \
12 marshalling-test \14 marshalling-test \
13 mimetype-test \15 mimetype-test \
14 query-operators-test \16 query-operators-test \
@@ -36,6 +38,9 @@
36 $(top_srcdir)/src/mimetype.vala \38 $(top_srcdir)/src/mimetype.vala \
37 $(NULL)39 $(NULL)
3840
41datamodel-test: datamodel-test.vala $(SRC_FILES)
42 $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^
43
39marshalling-test: marshalling-test.vala $(SRC_FILES)44marshalling-test: marshalling-test.vala $(SRC_FILES)
40 $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^45 $(VALA_V)$(VALAC) $(VALAFLAGS) -o $@ $^
4146
@@ -54,7 +59,8 @@
54clean-local:59clean-local:
55 rm -f *.~[0-9]~60 rm -f *.~[0-9]~
5661
57DISTCLEANFILES = \62CLEANFILES = \
63 datamodel-test \
58 marshalling-test \64 marshalling-test \
59 mimetype-test \65 mimetype-test \
60 query-operators-test \66 query-operators-test \
@@ -64,6 +70,7 @@
6470
65EXTRA_DIST = \71EXTRA_DIST = \
66 assertions.vapi \72 assertions.vapi \
73 datamodel-test.vala \
67 marshalling-test.vala \74 marshalling-test.vala \
68 mimetype-test.vala \75 mimetype-test.vala \
69 query-operators-test.vala \76 query-operators-test.vala \
7077
=== added file 'test/direct/datamodel-test.vala'
--- test/direct/datamodel-test.vala 1970-01-01 00:00:00 +0000
+++ test/direct/datamodel-test.vala 2012-02-18 21:37:18 +0000
@@ -0,0 +1,70 @@
1/* datamodel-test.vala
2 *
3 * Copyright © 2012 Canonical Ltd.
4 * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21using Zeitgeist;
22
23int main (string[] argv)
24{
25 Test.init (ref argv);
26
27 Test.add_func ("/Datamodel/MatchesTemplate/anything", matches_template_anything_test);
28
29 return Test.run ();
30}
31
32void matches_template_anything_test ()
33{
34 // Let's get a template with everything null
35 var templ = new Event.full ();
36 var event = new Event.full ("interp", "manif", "actor", "origin");
37
38 // Test with zero subjects
39 assert (templ.matches_template (templ));
40 assert (event.matches_template (templ));
41
42 var subject = new Subject.full ();
43 event.add_subject (subject);
44
45 // Test with one subject
46 assert (event.matches_template (templ));
47
48 var subject2 = new Subject.full ("uri", "interp", "manif", "mimetype",
49 "origin", "text", "storage", "current_uri");
50 event.add_subject (subject2);
51
52 // Test with two subjects
53 assert (event.matches_template (templ));
54
55 // Let's ensure that empty strings are also working...
56 templ.interpretation = "";
57 assert (event.matches_template (templ));
58
59 // As well as just a wildcard
60 templ.actor = "*";
61 assert (event.matches_template (templ));
62
63 // FIXME: figure out how we want to treat multiple subjects in the template
64
65 // Now check something that doesn't match
66 templ.manifestation = "No thanks!";
67 assert (!event.matches_template (templ));
68}
69
70// vim:expandtab:ts=4:sw=4

Subscribers

People subscribed via source and target branches