Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/tcf/channel/__init__.py')
-rw-r--r--python/src/tcf/channel/__init__.py60
1 files changed, 43 insertions, 17 deletions
diff --git a/python/src/tcf/channel/__init__.py b/python/src/tcf/channel/__init__.py
index 1e89c0bbe..7ac9ccb54 100644
--- a/python/src/tcf/channel/__init__.py
+++ b/python/src/tcf/channel/__init__.py
@@ -1,5 +1,5 @@
-# *******************************************************************************
-# * Copyright (c) 2011 Wind River Systems, Inc. and others.
+# *****************************************************************************
+# * Copyright (c) 2011, 2013 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
@@ -7,25 +7,30 @@
# *
# * Contributors:
# * Wind River Systems - initial API and implementation
-# *******************************************************************************
+# *****************************************************************************
-import cStringIO, json, binascii, types
+import binascii
+import cStringIO
+import json
+import types
# channel states
STATE_OPENING = 0
STATE_OPEN = 1
STATE_CLOSED = 2
+
class TraceListener(object):
- def onMessageReceived(self, type, token, service, name, data):
+ def onMessageReceived(self, t, token, service, name, data):
pass
- def onMessageSent(self, type, token, service, name, data):
+ def onMessageSent(self, t, token, service, name, data):
pass
def onChannelClosed(self, error):
pass
+
class Proxy(object):
def onCommand(self, token, service, name, data):
pass
@@ -37,23 +42,29 @@ class Proxy(object):
pass
_token_cnt = 0
+
+
class Token(object):
- def __init__(self, id=None, listener=None):
- if id is None:
+ def __init__(self, tokenID=None, listener=None):
+ if tokenID is None:
global _token_cnt
- id = str(_token_cnt)
+ tokenID = str(_token_cnt)
_token_cnt += 1
else:
- id = str(id)
- self.id = id
+ tokenID = str(tokenID)
+ self.id = tokenID
self.listener = listener
+
def getID(self):
return self.id
+
def getListener(self):
return self.listener
+
def cancel(self):
return False
+
class ChannelListener(object):
"""
Channel listener interface.
@@ -76,12 +87,14 @@ class ChannelListener(object):
def congestionLevel(self, level):
"""
- Notifies listeners about channel out-bound traffic congestion level changes.
+ Notifies listeners about channel out-bound traffic congestion level
+ changes.
When level > 0 client should delay sending more messages.
@param level - current congestion level
"""
pass
+
class EventListener(object):
"""
A generic interface for service event listener.
@@ -91,6 +104,7 @@ class EventListener(object):
unless no such interface is defined.
"""
svc_name = "<unknown>"
+
def event(self, name, data):
"""
Called when service event message is received
@@ -99,6 +113,7 @@ class EventListener(object):
"""
pass
+
class CommandServer(object):
"""
Command server interface.
@@ -113,6 +128,7 @@ class CommandServer(object):
"""
pass
+
class CommandListener(object):
"""
Command listener interface. Clients implement this interface to
@@ -126,22 +142,26 @@ class CommandListener(object):
@param data - progress message arguments encoded into array of bytes
"""
pass
+
def result(self, token, data):
"""
Called when command result received from remote peer.
@param token - command handle
- @param data - command result message arguments encoded into array of bytes
+ @param data - command result message arguments encoded into array of
+ bytes
"""
pass
+
def terminated(self, token, error):
"""
- Called when command is terminated because communication channel was closed or
- command is not recognized by remote peer.
+ Called when command is terminated because communication channel was
+ closed or command is not recognized by remote peer.
@param token - command handle
@param error - exception that forced the channel to close
"""
pass
+
def toJSONSequence(args):
if args is None:
return None
@@ -151,6 +171,7 @@ def toJSONSequence(args):
buf.write('\0')
return buf.getvalue()
+
def fromJSONSequence(byteArray):
if byteArray[-1] == 0:
del byteArray[-1]
@@ -164,19 +185,24 @@ def fromJSONSequence(byteArray):
objects.append(None)
return objects
+
def dumpJSONObject(obj, buf):
json.dump(obj, buf, separators=(',', ':'), cls=TCFJSONEncoder)
+
def toByteArray(data):
- if data is None: return None
+ if data is None:
+ return None
t = type(data)
- if t is bytearray: return data
+ if t is bytearray:
+ return data
elif t is str:
return binascii.a2b_base64(data)
elif t is unicode:
return binascii.a2b_base64(str(data))
raise TypeError(str(t))
+
class TCFJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, bytearray):

Back to the top