Skip to content

Commit

Permalink
COAP-44. Enable external modules to pass socket class to use.
Browse files Browse the repository at this point in the history
  • Loading branch information
malishav committed Mar 30, 2019
1 parent dd76d1f commit d12d3d9
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions coap/coap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ def emit(self, record):
import coapTransmitter
from socketUdpDispatcher import socketUdpDispatcher
from socketUdpReal import socketUdpReal
from socketUdp import socketUdp as socketUdpAbstract

class coap(object):

def __init__(self,ipAddress='',udpPort=d.DEFAULT_UDP_PORT,testing=False,receiveCallback=None):
def __init__(self,ipAddress='',udpPort=d.DEFAULT_UDP_PORT,testing=False,socketUdp=None):

# store params
self.ipAddress = ipAddress
Expand All @@ -43,23 +44,19 @@ def __init__(self,ipAddress='',udpPort=d.DEFAULT_UDP_PORT,testing=False,receiveC
self.respTimeout = d.DFLT_RESPONSE_TIMEOUT
self.maxRetransmit = d.DFLT_MAX_RETRANSMIT
self.secContextHandler = None
if receiveCallback:
callback = receiveCallback
else:
callback = self._receive
if testing:
self.socketUdp = socketUdpDispatcher(
ipAddress = self.ipAddress,
udpPort = self.udpPort,
callback = callback,
)

if socketUdp is not None:
socketClass = socketUdp
elif testing:
socketClass = socketUdpDispatcher
else:
self.socketUdp = socketUdpReal(
ipAddress = self.ipAddress,
udpPort = self.udpPort,
callback = callback,
)
socketClass = socketUdpReal

self.socketUdp = socketClass(
ipAddress = self.ipAddress,
udpPort = self.udpPort,
callback = self._receive,
)
#======================== public ==========================================

def close(self):
Expand Down

0 comments on commit d12d3d9

Please sign in to comment.