~ubuntu-branches/ubuntu/saucy/xmms2/saucy-proposed

« back to all changes in this revision

Viewing changes to doc/tutorial/vala/tut2.vala

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2011-10-22 23:53:00 UTC
  • mto: (38.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20111022235300-u50pdo3g341jvk7q
ImportĀ upstreamĀ versionĀ 0.8+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
public class Tutorial1 {
 
2
        public static int main (string[] args) {
 
3
                /*
 
4
                 * The first part of this program is
 
5
                 * commented in tut1.c See that one for
 
6
                 * instructions
 
7
                 */
 
8
                var xc = new Xmms.Client("tutorial2");
 
9
 
 
10
                var path = GLib.Environment.get_variable("XMMS_PATH");
 
11
                if (!xc.connect(path)) {
 
12
                        GLib.stderr.printf("Could not connect: %s\n", xc.get_last_error());
 
13
                        return 1;
 
14
                }
 
15
 
 
16
                /*
 
17
                 * Now we send a command that will return
 
18
                 * a result. Let's find out which entry
 
19
                 * is currently playing.
 
20
                 *
 
21
                 * Note that this program has be run while
 
22
                 * xmms2 is playing something, otherwise
 
23
                 * Xmms.Client.playback_current_id will return 0.
 
24
                 */
 
25
                var result = xc.playback_current_id();
 
26
 
 
27
                /*
 
28
                 * We are still doing sync operations, wait for the
 
29
                 * answer and block.
 
30
                 */
 
31
                result.wait();
 
32
 
 
33
                /*
 
34
                 * Also this time we need to check for errors.
 
35
                 * Errors can occur on all commands, but not signals
 
36
                 * and broadcasts. We will talk about these later.
 
37
                 */
 
38
                var value = result.get_value();
 
39
 
 
40
                if (value.is_error()) {
 
41
                        unowned string error = null;
 
42
                        if (value.get_error(out error)) {
 
43
                                GLib.stderr.printf("Xmms.Client.playback_current_id returned error: %s\n", error);
 
44
                        }
 
45
                        return 1;
 
46
                }
 
47
 
 
48
                /*
 
49
                 * Let's retrieve the value from the result struct.
 
50
                 * The caveat here is that you have to know what type
 
51
                 * of value is returned in response to each command.
 
52
                 *
 
53
                 * In this case we know that Xmms.Client.playback_current_id
 
54
                 * will return a INT
 
55
                 *
 
56
                 * Know that all Xmms.Result.get* calls can return FALSE
 
57
                 * and that means that the value you are requesting is
 
58
                 * not in the result struct.
 
59
                 *
 
60
                 * Values are stored in the pointer passed to result_get
 
61
                 */
 
62
                int id;
 
63
                if (!value.get_int(out id)) {
 
64
                        GLib.stderr.printf("Xmms.Client.playback_current_id didn't return int as expected\n");
 
65
                        return 1;
 
66
                }
 
67
 
 
68
                /* Print the value */
 
69
                GLib.stdout.printf("Currently playing id is %d\n", id);
 
70
 
 
71
                return 0;
 
72
        }
 
73
}