~ubuntu-branches/ubuntu/trusty/rygel/trusty

« back to all changes in this revision

Viewing changes to src/rygel/rygel-http-response.vala

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2011-12-16 15:21:25 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111216152125-qgn31dkfmhouhrf0
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
using Soup;
26
26
 
27
27
internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
28
 
    public Soup.Server server { get; private set; }
 
28
    public unowned Soup.Server server { get; private set; }
29
29
    public Soup.Message msg;
30
30
 
31
31
    public Cancellable cancellable { get; set; }
59
59
 
60
60
    private Pipeline pipeline;
61
61
    private uint bus_watch_id;
 
62
    private bool unref_soup_server;
62
63
 
63
64
    public HTTPResponse (HTTPGet        request,
64
65
                         HTTPGetHandler request_handler,
68
69
        this.cancellable = request_handler.cancellable;
69
70
        this.seek = request.seek;
70
71
 
71
 
        if (this.seek != null && this.seek.length < this.seek.total_length) {
72
 
            this.msg.set_status (Soup.KnownStatusCode.PARTIAL_CONTENT);
73
 
        } else {
74
 
            this.msg.set_status (Soup.KnownStatusCode.OK);
75
 
        }
76
 
 
77
 
        if (this.seek != null && this.seek is HTTPByteSeek) {
78
 
            this.msg.response_headers.set_encoding (Encoding.CONTENT_LENGTH);
79
 
        } else {
80
 
            this.msg.response_headers.set_encoding (Encoding.EOF);
81
 
        }
82
 
 
83
72
        if (this.cancellable != null) {
84
73
            this.cancellable.cancelled.connect (this.on_cancelled);
85
74
        }
87
76
        this.msg.response_body.set_accumulate (false);
88
77
 
89
78
        this.prepare_pipeline ("RygelHTTPGstResponse", src);
 
79
        this.server.weak_ref (this.on_server_weak_ref);
 
80
        this.unref_soup_server = true;
 
81
    }
 
82
 
 
83
    ~HTTPResponse () {
 
84
        if (this.unref_soup_server) {
 
85
            this.server.weak_unref (this.on_server_weak_ref);
 
86
        }
90
87
    }
91
88
 
92
89
    public async void run () {
137
134
        this.end (true, Soup.KnownStatusCode.CANCELLED);
138
135
    }
139
136
 
 
137
    private void on_server_weak_ref (GLib.Object object) {
 
138
        this.unref_soup_server = false;
 
139
        this.cancellable.cancel ();
 
140
    }
 
141
 
140
142
    private void prepare_pipeline (string name, Element src) throws Error {
141
143
        var sink = new HTTPGstSink (this);
142
144
 
264
266
        if (this.seek is HTTPTimeSeek) {
265
267
            format = Format.TIME;
266
268
 
267
 
            if (this.seek.stop > 0) {
268
 
                stop_type = Gst.SeekType.SET;
269
 
            }
270
269
        } else {
271
270
            format = Format.BYTES;
272
271
        }
273
272
 
 
273
        if (this.seek.stop > 0) {
 
274
            stop_type = Gst.SeekType.SET;
 
275
        }
 
276
 
274
277
        if (!this.pipeline.seek (1.0,
275
278
                                 format,
276
279
                                 SeekFlags.FLUSH | SeekFlags.ACCURATE,
277
280
                                 Gst.SeekType.SET,
278
281
                                 this.seek.start,
279
282
                                 stop_type,
280
 
                                 this.seek.stop)) {
 
283
                                 this.seek.stop + 1)) {
281
284
            warning (_("Failed to seek to offset %lld"), this.seek.start);
282
285
 
283
286
            this.end (false, KnownStatusCode.REQUESTED_RANGE_NOT_SATISFIABLE);