Rev 749 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 749 | Rev 750 | ||
|---|---|---|---|
| Line 12... | Line 12... | ||
| 12 | from ConfigParser import ConfigParser |
12 | from ConfigParser import ConfigParser |
| 13 | import filters |
13 | import filters |
| 14 | import statespaces |
14 | import statespaces |
| 15 | from CanPktHandlerBase import CanPktHandlerBase |
15 | from CanPktHandlerBase import CanPktHandlerBase |
| 16 | from CanPktHandler1 import CanPktHandler1 |
16 | from CanPktHandler1 import CanPktHandler1 |
| - | 17 | ||
| - | 18 | from NodeIfSerial import NodeIfSerial |
|
| - | 19 | from NodeIfTCP import NodeIfTCP |
|
| - | 20 | from NodeIfUDP import NodeIfUDP |
|
| - | 21 | from NodeIfTCPTLS import NodeIfTCPTLS |
|
| - | 22 | from NodeIfCanStim import NodeIfCanStim |
|
| 17 | 23 | ||
| 18 | class DynamicModuleCfg: |
24 | class DynamicModuleCfg: |
| 19 | """Dynamic module manager""" |
25 | """Dynamic module manager""" |
| 20 | 26 | ||
| 21 | modSubDir = None |
27 | modSubDir = None |
| Line 156... | Line 162... | ||
| 156 | self.__saveFilter(className, self.filterModules[className]) |
162 | self.__saveFilter(className, self.filterModules[className]) |
| 157 | 163 | ||
| 158 | def importFilter(self, className): |
164 | def importFilter(self, className): |
| 159 | """Imports a given filter definition """ |
165 | """Imports a given filter definition """ |
| 160 | classObj = self.dynamicModuleCfg.importModule(className, self.REQUIRED_ATTRIBUTES) |
166 | classObj = self.dynamicModuleCfg.importModule(className, self.REQUIRED_ATTRIBUTES) |
| 161 | if classObj is not None: |
167 | if classObj is not None: |
| 162 | print 'Imported: ' + classObj.DESCRIPTIVE_NAME |
168 | print 'Imported: ' + classObj.DESCRIPTIVE_NAME |
| 163 | return True |
169 | return True |
| 164 | else: |
170 | else: |
| 165 | return False |
171 | return False |
| 166 | 172 | ||
| 167 | 173 | ||
| Line 215... | Line 221... | ||
| 215 | 221 | ||
| 216 | filterChain = [] |
222 | filterChain = [] |
| 217 | nodeInterfaces = [] |
223 | nodeInterfaces = [] |
| 218 | nodeInterfaceMap = {} |
224 | nodeInterfaceMap = {} |
| 219 | 225 | ||
| - | 226 | INTERFACE_TYPES = {'serial' : NodeIfSerial, 'tcp' : NodeIfTCP, |
|
| - | 227 | 'udp' : NodeIfUDP, 'sim' : NodeIfCanStim, |
|
| - | 228 | 'tcptls' : NodeIfTCPTLS} |
|
| - | 229 | ||
| 220 | def __init__ (self): |
230 | def __init__ (self): |
| 221 | self.filterCfg = FilterCfg() |
231 | self.filterCfg = FilterCfg() |
| 222 | self.stateSpaceCfg = StateSpaceCfg() |
232 | self.stateSpaceCfg = StateSpaceCfg() |
| 223 | self.pktHandler = CanPktHandler1() |
233 | self.pktHandler = CanPktHandler1(self) |
| 224 | 234 | ||
| 225 | def load(self): |
235 | def load(self): |
| 226 | self.stateSpaceCfg.loadSpaces() |
236 | self.stateSpaceCfg.loadSpaces() |
| 227 | self. |
237 | self.filterCfg.loadFilters() |
| 228 | __setupFilterBindings() |
238 | self.__setupFilterBindings() |
| - | 239 | self.__setupStateSpaceRelations() |
|
| 229 | __setupFilterChain() |
240 | self.__setupFilterChain() |
| 230 | 241 | ||
| 231 | def save(self): |
242 | def save(self): |
| 232 | self.stateSpaceCfg.saveSpaces() |
243 | self.stateSpaceCfg.saveSpaces() |
| 233 | self.filterCfg.saveFilters() |
244 | self.filterCfg.saveFilters() |
| - | 245 | ||
| - | 246 | def addInterface(self, type, cfg = None): |
|
| - | 247 | """ addInterface |
|
| - | 248 | type - a valid interface type name |
|
| - | 249 | cfg - interface configuration |
|
| - | 250 | returns: True on success, False otherwise """ |
|
| - | 251 | ||
| - | 252 | if not self.INTERFACE_TYPES.has_key(type): |
|
| - | 253 | log.debug('addInterface called with invalid interface type') |
|
| - | 254 | return False |
|
| - | 255 | ||
| - | 256 | cfg = self.INTERFACE_TYPES[type].DEFAULT_CONFIG |
|
| - | 257 | print cfg |
|
| - | 258 | nodeIf = self.INTERFACE_TYPES[type](self.pktHandler, cfg) |
|
| - | 259 | print nodeIf |
|
| - | 260 | self.nodeInterfaces.append(nodeIf) |
|
| - | 261 | ||
| - | 262 | def remInterface(self, name): |
|
| - | 263 | pass |
|
| 234 | 264 | ||
| 235 | def __setupFilterChain(self): |
265 | def __setupFilterChain(self): |
| 236 | self.filterChain = ['DefaultFilter'] |
266 | self.filterChain = ['DefaultFilter'] |
| 237 | 267 | ||
| 238 | def __setupFilterBindings(self): |
268 | def __setupFilterBindings(self): |
| Line 242... | Line 272... | ||
| 242 | if self.stateSpaceCfg.spaceModules.has_key(s): |
272 | if self.stateSpaceCfg.spaceModules.has_key(s): |
| 243 | assocSpaces.append(self.stateSpaceCfg.spaceModules[s]) |
273 | assocSpaces.append(self.stateSpaceCfg.spaceModules[s]) |
| 244 | else: |
274 | else: |
| 245 | print 'WARNING: Reference to undefined state space: ' + s |
275 | print 'WARNING: Reference to undefined state space: ' + s |
| 246 | setattr(f, '__ASSOCIATED_SPACES__', assocSpaces) |
276 | setattr(f, '__ASSOCIATED_SPACES__', assocSpaces) |
| 247 | - | ||
| 248 | 277 | ||
| 249 | def |
278 | def __setupStateSpaceRelations(self): |
| 250 | for sm in self.stateSpaceCfg.spaceModules: |
279 | for sm in self.stateSpaceCfg.spaceModules: |
| 251 | relatedSpaceNames = self.stateSpaceCfg.spaceModules[sm].RELATED_SPACES |
280 | relatedSpaceNames = self.stateSpaceCfg.spaceModules[sm].RELATED_SPACES |
| 252 | relatedSpaces = {} |
281 | relatedSpaces = {} |
| 253 | for rsname in relatedSpaceNames: |
282 | for rsname in relatedSpaceNames: |
| 254 | relatedSpaces[rsname] = self.stateSpaceCfg.spaceModules[rsname] |
283 | relatedSpaces[rsname] = self.stateSpaceCfg.spaceModules[rsname] |
| 255 | setattr(sm, '__RELATED_SPACES__', relatedSpaces) |
284 | setattr(self.stateSpaceCfg.spaceModules[sm], '__RELATED_SPACES__', relatedSpaces) |
| 256 | 285 | ||