PyNDN: Bug fixing and API unification
diff --git a/PyNDN/Face.py b/PyNDN/Face.py
index 6186569..3f76f5d 100644
--- a/PyNDN/Face.py
+++ b/PyNDN/Face.py
@@ -1,12 +1,12 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-#
+#
# Copyright (c) 2011-2013, Regents of the University of California
# Alexander Afanasyev
-#
+#
# GNU 3.0 license, See the LICENSE file for more information
-#
+#
# Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
-#
+#
#
# Based on PyCCN code, copyrighted and licensed as follows
@@ -22,6 +22,7 @@
import ns.ndnSIM
from Data import Data
from Interest import Interest
+from Name import Name
import functools
@@ -40,7 +41,7 @@
def defer_verification (self, deferVerification = True):
pass
- def expressInterestSimple (self, name, onData, onTimeout, template = None):
+ def expressInterest (self, name, onData, onTimeout, template = None):
"""
onData: void <interest, name>
onTimeout: void <interest>
@@ -55,7 +56,7 @@
def __call__ (self, interest, data):
if self.onData:
return self.onData (Interest (interest=interest), Data (data = data))
-
+
class OnTimeoutConvert:
def __init__ (self, onTimeout):
self.onTimeout = onTimeout
@@ -63,9 +64,9 @@
if self.onTimeout:
self.onTimeout (Interest (interest=interest))
- self.ExpressInterest (interest, OnDataConvert (onData), OnTimeoutConvert (onTimeout))
+ self.ExpressInterest (interest._interest, OnDataConvert (onData), OnTimeoutConvert (onTimeout))
- def setInterestFilterSimple (self, name, onInterest, flags = None):
+ def setInterestFilter (self, name, onInterest, flags = None):
"""
onInterest: void <name, interest>
"""
@@ -77,27 +78,27 @@
if self.onInterest:
self.onInterest (Name (name = name), Interest (interest = interest))
+ if isinstance (name, Name):
+ name = name._name
+ elif isinstance (name, ns.ndnSIM.ndn.Name):
+ pass
+ else:
+ raise TypeError ("Wrong type for 'name' parameter [%s]" % type (name))
+
self.SetInterestFilter (name, OnInterestConvert (onInterest))
def clearInterestFilter (self, name):
- if type (name) is Name:
- self.ClearInterestFilter (name._name)
- elif type (name) is ns.ndnSIM.ndn.Name:
- self.ClearInterestFilter (name)
+ if isinstance (name, Name):
+ name = name._name
+ elif isinstance (name, ns.ndnSIM.ndn.Name):
+ pass
else:
raise TypeError ("Wrong type for 'name' parameter [%s]" % type (name))
+ self.ClearInterestFilter (name)
+
def get (self, name, template = None, timeoutms = 3000):
raise NotImplementedError ("NS-3 simulation cannot have syncrhonous operations")
def put (self, data):
self.Put (data)
-
-class EventLoop(object):
- def execute (self, event):
- ns.core.Simulator.ScheduleNow (event)
-
- def run (self, timeoutMs):
- ns.core.Simulator.Stop (ns.core.MilliSeconds (timeoutMs))
- ns.core.Simulator.Run ()
- ns.core.Simulator.Destroy ()