00001 # Copyright (C) 2008-2009 Mark Hanegraaff 00002 # 00003 # This program is free software: you can redistribute it and/or modify 00004 # it under the terms of the GNU General Public License as published by 00005 # the Free Software Foundation, either version 3 of the License, or 00006 # (at your option) any later version. 00007 # 00008 # This program is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 # GNU General Public License for more details. 00012 # 00013 # You should have received a copy of the GNU General Public License 00014 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 00016 from objects.logic.common.exception import exception 00017 00018 00019 ## Generic interface to some network capturing API. 00020 # Once the interface 'startListening' method is called notification will happen via an single observer which is 00021 # registered using the 'registerCallBack' method. 00022 # Note that since Python does not really support interfaces, this is really just an 00023 # experiment. Note how all functions simply raise a "not implemented" exception. 00024 class captureInterface(): 00025 00026 def __init__(self): 00027 self.notifyCallbackObject = None 00028 00029 # error call back function, should take 1 string parameter 00030 # representing the actual error 00031 self.errorCallBackFunc = None 00032 self.deviceName = None 00033 00034 ## Returns a list of devices. 00035 def getDeviceList(self): raise exception("not implemented", True) 00036 00037 00038 ## Queries a generic device. 00039 # @param device Generic device object, defined by its implementors 00040 def queryDevice(self, device): raise exception("not implemented", True) 00041 00042 00043 ## Opens a generic device. 00044 # @param device Generic device object, defined by its implementors 00045 def openDevice(self, device): raise exception("not implemented", True) 00046 00047 ## Closes a generic device. 00048 # @param device Generic device object, defined by its implementors 00049 def closeDevice(self, device): raise exception("not implemented", True) 00050 00051 00052 ## Starts listening to a generic device. 00053 # @param device Generic device object, defined by its implementors 00054 def startListening(self, device): raise exception("not implemented", True) 00055 00056 00057 00058 ## Stops listening to a generic device. 00059 def stopListening(self): raise exception("not implemented", True) 00060 00061 00062 00063 ## Notifies the "Single" observer of this interface. 00064 # @param header Raw DataLink header 00065 # @param data Raw DataLink frame 00066 # @param deviceName Name of the device which received the above data 00067 def notify(self, header, data, deviceName): 00068 if self.notifyCallbackObject != None: 00069 self.notifyCallbackObject.newPacketNotification(header, data, deviceName) 00070 00071 00072 00073 00074 ## Registers the observer object 00075 # @param callbackObject Observer object 00076 def registerNotifyCallBack(self, callbackObject): 00077 self.notifyCallbackObject = callbackObject 00078 00079 00080 00081 ## registers a callback function for reporting errors 00082 # This is done to separate this interface from any object intercepting error from it. 00083 # For example the mainFrame object could used here, so that errors are more easily reported back to the user. 00084 # @param callbackFunc Callback Function 00085 def registerErrorCallBackFunc(self, callbackFunc): 00086 self.errorCallBackFunc = callbackFunc 00087 00088 00089 00090 00091
1.5.8