| 454 | |
| 455 | |
| 456 | class MethodService(object): |
| 457 | |
| 458 | def __init__(self, aspace): |
| 459 | self.logger = logging.getLogger(__name__) |
| 460 | self._aspace = aspace |
| 461 | |
| 462 | def call(self, methods): |
| 463 | results = [] |
| 464 | for method in methods: |
| 465 | results.append(self._call(method)) |
| 466 | return results |
| 467 | |
| 468 | def _call(self, method): |
| 469 | res = ua.CallMethodResult() |
| 470 | if method.ObjectId not in self._aspace or method.MethodId not in self._aspace: |
| 471 | res.StatusCode = ua.StatusCode(ua.StatusCodes.BadNodeIdInvalid) |
| 472 | else: |
| 473 | node = self._aspace[method.MethodId] |
| 474 | if node.call is None: |
| 475 | res.StatusCode = ua.StatusCode(ua.StatusCodes.BadNothingToDo) |
| 476 | else: |
| 477 | try: |
| 478 | result = node.call(method.ObjectId, *method.InputArguments) |
| 479 | if isinstance(result, ua.CallMethodResult): |
| 480 | res = result |
| 481 | elif isinstance(result, ua.StatusCode): |
| 482 | res.StatusCode = result |
| 483 | else: |
| 484 | res.OutputArguments = result |
| 485 | while len(res.InputArgumentResults) < len(method.InputArguments): |
| 486 | res.InputArgumentResults.append(ua.StatusCode()) |
| 487 | except Exception: |
| 488 | self.logger.exception("Error executing method call %s, an exception was raised: ", method) |
| 489 | res.StatusCode = ua.StatusCode(ua.StatusCodes.BadUnexpectedError) |
| 490 | return res |
| 491 | |
| 492 | |
| 493 | class AddressSpace(object): |