~indicator-multiload/indicator-multiload/trunk

« back to all changes in this revision

Viewing changes to src/providers.vala

  • Committer: Michael Hofmann
  • Date: 2011-09-09 08:37:55 UTC
  • Revision ID: mh21@piware.de-20110909083755-4jfuqq417w2hl9kd
Split function in their own class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
public class Providers : Object {
20
20
    public Provider[] providers { get; private set; }
 
21
    public Function[] functions { get; private set; }
21
22
 
22
23
    construct {
23
24
        this.providers = {
25
26
            new SwapProvider(), new LoadProvider(), new DiskProvider()
26
27
        };
27
28
        this.update();
 
29
        this.functions = {
 
30
            new DecimalsFunction(), new SizeFunction(),
 
31
            new SpeedFunction(), new PercentFunction()
 
32
        };
28
33
    }
29
34
 
30
 
    public double value(string variable, out bool found)
 
35
    // TODO: use exceptions
 
36
    public double value(string name, out bool found)
31
37
    {
32
 
        var varparts = variable.split(".");
 
38
        var varparts = name.split(".");
33
39
        return_val_if_fail(varparts.length == 2, 0);
34
40
 
35
41
        found = true;
47
53
        return 0;
48
54
    }
49
55
 
 
56
    public string call(string name, string[] parameters, out bool found) throws Error
 
57
    {
 
58
        found = true;
 
59
        foreach (var function in this.functions) {
 
60
            if (function.id != name)
 
61
                continue;
 
62
            return function.call(parameters);
 
63
        }
 
64
 
 
65
        found = false;
 
66
        return "";
 
67
    }
 
68
 
50
69
    public void update() {
51
70
        foreach (var provider in this.providers)
52
71
            provider.update();