Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 35cec5c5b33074558f1b8d42758a018391b3e9f6 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# *******************************************************************************
# * Copyright (c) 2011 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
# *******************************************************************************

import exceptions
from tcf import channel
from tcf.services import breakpoints
from tcf.channel.Command import Command

class BPCommand(Command):
    def __init__(self, service, cmd, cb, *args):
        super(BPCommand, self).__init__(service.channel, service, cmd, args)
        self.__cb = cb
    def done(self, error, args):
        if not error:
            assert len(args) == 1
            error = self.toError(args[0])
        self.__cb.doneCommand(self.token, error)


class ChannelEventListener(channel.EventListener):
    def __init__(self, service, listener):
        self.service = service
        self.listener = listener
    def event(self, name, data):
        try:
            args = channel.fromJSONSequence(data)
            if name == "status":
                assert len(args) == 2
                self.listener.breakpointStatusChanged(args[0], args[1])
            elif name == "contextAdded":
                assert len(args) == 1
                self.listener.contextAdded(args[0])
            elif name == "contextChanged":
                assert len(args) == 1
                self.listener.contextChanged(args[0])
            elif name == "contextRemoved":
                assert len(args) == 1
                self.listener.contextRemoved(args[0])
            else:
                raise IOError("Breakpoints service: unknown event: " + name);
        except exceptions.Exception as x:
            self.service.channel.terminate(x)

class BreakpointsProxy(breakpoints.BreakpointsService):
    def __init__(self, channel):
        self.channel = channel
        self.listeners = {}

    def set(self, properties, done):
        done = self._makeCallback(done)
        return BPCommand(self, "set", done, properties).token

    def add(self, properties, done):
        done = self._makeCallback(done)
        return BPCommand(self, "add", done, properties).token

    def change(self, properties, done):
        done = self._makeCallback(done)
        return BPCommand(self, "change", done, properties).token

    def disable(self, ids, done):
        done = self._makeCallback(done)
        return BPCommand(self, "disable", done, ids).token

    def enable(self, ids, done):
        done = self._makeCallback(done)
        return BPCommand(self, "enable", done, ids).token

    def remove(self, ids, done):
        done = self._makeCallback(done)
        return BPCommand(self, "remove", done, ids).token

    def getIDs(self, done):
        done = self._makeCallback(done)
        service = self
        class GetIDsCommand(Command):
            def __init__(self):
                super(GetIDsCommand, self).__init__(service.channel, service, "getIDs", None)
            def done(self, error, args):
                ids = None
                if not error:
                    assert len(args) == 2
                    error = self.toError(args[0])
                    ids = args[1]
                done.doneGetIDs(self.token, error, ids)
        return GetIDsCommand().token

    def getProperties(self, id, done):
        done = self._makeCallback(done)
        service = self
        class GetPropertiesCommand(Command):
            def __init__(self):
                super(GetPropertiesCommand, self).__init__(service.channel, service, "getProperties", (id,))
            def done(self, error, args):
                map = None
                if not error:
                    assert len(args) == 2
                    error = self.toError(args[0])
                    map = args[1]
                done.doneGetProperties(self.token, error, map)
        return GetPropertiesCommand().token

    def getStatus(self, id, done):
        done = self._makeCallback(done)
        service = self
        class GetStatusCommand(Command):
            def __init__(self):
                super(GetStatusCommand, self).__init__(service.channel, service, "getStatus", (id,))
            def done(self, error, args):
                map = None
                if not error:
                    assert len(args) == 2
                    error = self.toError(args[0])
                    map = args[1]
                done.doneGetStatus(self.token, error, map)
        return GetStatusCommand().token

    def getCapabilities(self, id, done):
        done = self._makeCallback(done)
        service = self
        class GetCapabilitiesCommand(Command):
            def __init__(self):
                super(GetCapabilitiesCommand, self).__init__(service.channel, service, "getCapabilities", (id,))
            def done(self, error, args):
                map = None
                if not error:
                    assert len(args) == 2
                    error = self.toError(args[0])
                    map = args[1]
                done.doneGetCapabilities(self.token, error, map)
        return GetCapabilitiesCommand().token

    def addListener(self, listener):
        l = ChannelEventListener(self, listener)
        self.channel.addEventListener(self, l)
        self.listeners[listener] = l

    def removeListener(self, listener):
        l = self.listeners.get(listener)
        if l:
            del self.listeners[listener]
            self.channel.removeEventListener(self, l)

Back to the top