Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 662fd062d06e1227c7c7e49a992c9c2b655fd606 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*******************************************************************************
 * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.debug.ui.model;

import org.eclipse.debug.core.IRequest;
import org.eclipse.tcf.debug.ui.ITCFPresentationProvider;
import org.eclipse.tcf.internal.debug.ui.Activator;
import org.eclipse.tcf.protocol.Protocol;

/**
 * TCFRunnable is a wrapper for IRequest.
 * It implements Runnable interface and is used by TCFModel to handle the request.
 */
public abstract class TCFRunnable implements Runnable {

    private final IRequest request;
    private final Iterable<ITCFPresentationProvider> listeners;

    protected boolean done;

    public TCFRunnable(TCFModel model, IRequest request) {
        this.request = request;
        listeners = model.view_request_listeners;
        if (Protocol.isDispatchThread()) {
            if (listeners != null) {
                for (ITCFPresentationProvider l : listeners) {
                    try {
                        if (!l.updateStarted(TCFRunnable.this.request)) return;
                    }
                    catch (Throwable x) {
                        Activator.log("Unhandled exception in a presentation provider", x);
                    }
                }
            }
            run();
            return;
        }
        if (listeners == null) {
            Protocol.invokeLater(this);
            return;
        }
        Protocol.invokeLater(new Runnable() {
            @Override
            public void run() {
                assert !done;
                for (ITCFPresentationProvider l : listeners) {
                    try {
                        if (!l.updateStarted(TCFRunnable.this.request)) return;
                    }
                    catch (Throwable x) {
                        Activator.log("Unhandled exception in a presentation provider", x);
                    }
                }
                TCFRunnable.this.run();
            }
        });
    }

    public void done() {
        assert !done;
        done = true;
        if (listeners != null) {
            for (ITCFPresentationProvider l : listeners) {
                try {
                    if (!l.updateComplete(request)) return;
                }
                catch (Throwable x) {
                    Activator.log("Unhandled exception in a presentation provider", x);
                }
            }
        }
        // Don't call Display.asyncExec: display thread can be blocked waiting for the request.
        // For example, display thread is blocked for action state update requests.
        // Calling back into Eclipse on TCF thread is dangerous too - if Eclipse blocks TCF thread
        // we can get deadlocked. Might need a new thread (or Job) to make this call safe.
        request.done();
    }
}

Back to the top