~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/xvidcap-dbus-client.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file xvidcap-dbus-client.c
 
3
 *
 
4
 * This file contains a command line application for remote controlling
 
5
 * xvidcap itself through dbus remote function calls.
 
6
 *
 
7
 */
 
8
 
 
9
/*
 
10
 * Copyright (C) 2004-07 Karl, Frankfurt
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or modify
 
13
 * it under the terms of the GNU General Public License as published by
 
14
 * the Free Software Foundation; either version 2 of the License, or
 
15
 * (at your option) any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
25
 */
 
26
 
 
27
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
28
#ifdef HAVE_CONFIG_H
 
29
#include <config.h>
 
30
#endif     // HAVE_CONFIG_H
 
31
#endif     // DOXYGEN_SHOULD_SKIP_THIS
 
32
 
 
33
#include <getopt.h>
 
34
#include <stdlib.h>
 
35
#include <stdio.h>
 
36
#include <strings.h>
 
37
#include <dbus/dbus-glib-bindings.h>
 
38
 
 
39
#include "xvidcap-client-bindings.h"
 
40
#include "xvidcap-intl.h"
 
41
 
 
42
/**
 
43
 * \brief enumeration of types of actions supported to be used in a switch
 
44
 */
 
45
enum ACTION_TYPES
 
46
{
 
47
    ACTION_START,
 
48
    ACTION_STOP,
 
49
    ACTION_PAUSE
 
50
};
 
51
 
 
52
/**
 
53
 * \brief displays command line usage
 
54
 *
 
55
 * @param prog a string containing the name of the program
 
56
 */
 
57
void
 
58
usage (char *prog)
 
59
{
 
60
    printf (_("Usage: %s, ver %s, khb (c) 2003-07\n"), prog, VERSION);
 
61
    printf
 
62
        (_
 
63
         ("[--action #]      action to perform (\"start\"|\"stop\"|\"pause\")\n"));
 
64
 
 
65
    exit (1);
 
66
}
 
67
 
 
68
/**
 
69
 * \brief main function of the application to do the remote function invocation
 
70
 *
 
71
 * @return completion status
 
72
 */
 
73
 
 
74
int
 
75
main (int argc, char *argv[])
 
76
{
 
77
    // there's one one argument supported
 
78
    struct option options[] = {
 
79
        {"action", required_argument, NULL, 0}
 
80
    };
 
81
    int action = -1;
 
82
    int opt_index = 0, c;
 
83
 
 
84
    DBusGProxy *proxy;
 
85
    DBusGConnection *connection;
 
86
    GError *error = NULL;
 
87
 
 
88
    while ((c = getopt_long (argc, argv, "v", options, &opt_index)) != -1) {
 
89
        switch (c) {
 
90
        case 0:                       // it's a long option
 
91
            switch (opt_index) {
 
92
            case 0:                   // action
 
93
                if (strcasecmp (optarg, "start") == 0) {
 
94
                    action = ACTION_START;
 
95
                } else if (strcasecmp (optarg, "stop") == 0) {
 
96
                    action = ACTION_STOP;
 
97
                } else if (strcasecmp (optarg, "pause") == 0) {
 
98
                    action = ACTION_PAUSE;
 
99
                }
 
100
                break;
 
101
            }
 
102
        }
 
103
    }
 
104
    if (action < 0) {
 
105
        usage (argv[0]);
 
106
    }
 
107
 
 
108
    g_type_init ();
 
109
 
 
110
    connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
111
    if (connection == NULL) {
 
112
        g_warning ("Unable to connect to dbus: %sn", error->message);
 
113
        g_error_free (error);
 
114
        // Basically here, there is a problem, since there is no dbus :)
 
115
    }
 
116
    // This won't trigger activation!
 
117
    proxy = dbus_g_proxy_new_for_name (connection,
 
118
                                       "net.jarre_de_the.Xvidcap",
 
119
                                       "/net/jarre_de_the/Xvidcap",
 
120
                                       "net.jarre_de_the.Xvidcap");
 
121
 
 
122
    switch (action) {
 
123
    case ACTION_START:
 
124
 
 
125
        if (!net_jarre_de_the_Xvidcap_start (proxy, &error)) {
 
126
            g_warning (_("Could not send start command to xvidcap: %s"),
 
127
                       error->message);
 
128
            g_error_free (error);
 
129
        }
 
130
        break;
 
131
    case ACTION_STOP:
 
132
 
 
133
        if (!net_jarre_de_the_Xvidcap_stop (proxy, &error)) {
 
134
            g_warning (_("Could not send stop command to xvidcap: %s"),
 
135
                       error->message);
 
136
            g_error_free (error);
 
137
        }
 
138
        break;
 
139
    case ACTION_PAUSE:
 
140
 
 
141
        if (!net_jarre_de_the_Xvidcap_pause (proxy, &error)) {
 
142
            g_warning (_("Could not pause/unpause xvidcap: %s"),
 
143
                       error->message);
 
144
            g_error_free (error);
 
145
        }
 
146
        break;
 
147
    }
 
148
 
 
149
    // Cleanup
 
150
    g_object_unref (proxy);
 
151
 
 
152
    // The DBusGConnection should never be unreffed, it lives once and is
 
153
    // shared amongst the process
 
154
 
 
155
    return 0;
 
156
}