Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a590841d561c847ea95b51a54b113fba276bd69f (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
/*******************************************************************************
 * Copyright (c) 2013 Xilinx, 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:
 *     Xilinx - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.services.remote;

import java.util.Collection;
import java.util.Map;

import org.eclipse.tcf.core.Command;
import org.eclipse.tcf.protocol.IChannel;
import org.eclipse.tcf.protocol.IToken;
import org.eclipse.tcf.services.IProfiler;

public class ProfilerProxy implements IProfiler {

    private final IChannel channel;

    public ProfilerProxy(IChannel channel) {
        this.channel = channel;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public IToken configure(String ctx, Map<String, Object> params, final DoneConfigure done) {
        return new Command(channel, this, "configure", new Object[]{ ctx, params }) {
            @Override
            public void done(Exception error, Object[] args) {
                if (error == null) {
                    assert args.length == 1;
                    error = toError(args[0]);
                }
                done.doneConfigure(token, error);
            }
        }.token;
    }

    @Override
    public IToken read(String ctx, final DoneRead done) {
        return new Command(channel, this, "read", new Object[]{ ctx }) {
            @Override
            public void done(Exception error, Object[] args) {
                Map<String,Object>[] data = null;
                if (error == null) {
                    assert args.length == 2;
                    error = toError(args[0]);
                    data = toDataArray(args[1]);
                }
                done.doneRead(token, error, data);
            }
        }.token;
    }

    @SuppressWarnings("unchecked")
    private Map<String,Object>[] toDataArray(Object o) {
        if (o == null) return null;
        Collection<Map<String,Object>> c = (Collection<Map<String,Object>>)o;
        return c.toArray(new Map[c.size()]);
    }
}

Back to the top