Skip to content

Commit

Permalink
Merge fe67f88 into 024d1b8
Browse files Browse the repository at this point in the history
  • Loading branch information
d-bohls committed Apr 25, 2018
2 parents 024d1b8 + fe67f88 commit 17dbd04
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 196 deletions.
4 changes: 2 additions & 2 deletions docs/api_reference/database/lin_sched.rst
@@ -1,5 +1,5 @@
nixnet.database.linsched
========================
nixnet.database.lin_sched
=========================

.. automodule:: nixnet.database._lin_sched
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/api_reference/database/lin_sched_entry.rst
@@ -1,5 +1,5 @@
nixnet.database.linsched_entry
==============================
nixnet.database.lin_sched_entry
===============================

.. automodule:: nixnet.database._lin_sched_entry
:members:
Expand Down
21 changes: 20 additions & 1 deletion nixnet/database/__init__.py
Expand Up @@ -3,7 +3,26 @@
from __future__ import print_function


from nixnet.database._cluster import Cluster
from nixnet.database._database_object import DatabaseObject
from nixnet.database._ecu import Ecu
from nixnet.database._frame import Frame
from nixnet.database._lin_sched import LinSched
from nixnet.database._lin_sched_entry import LinSchedEntry
from nixnet.database._pdu import Pdu
from nixnet.database._signal import Signal
from nixnet.database._subframe import SubFrame
from nixnet.database.database import Database


__all__ = ["Database"]
__all__ = [
"Cluster",
"Database",
"DatabaseObject",
"Ecu",
"Frame",
"LinSched",
"LinSchedEntry",
"Pdu",
"Signal",
"SubFrame"]
36 changes: 14 additions & 22 deletions nixnet/database/_cluster.py
Expand Up @@ -11,21 +11,24 @@
from nixnet import constants

from nixnet.database import _collection
from nixnet.database import _database_object
from nixnet.database import _dbc_attributes
from nixnet.database import _find_object
from nixnet.database import _signal


class Cluster(object):
class Cluster(_database_object.DatabaseObject):
"""Database cluster"""

def __init__(self, handle):
# type: (int) -> None
_database_object.DatabaseObject.__init__(self, handle)
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]

from nixnet.database import _ecu
from nixnet.database import _frame
from nixnet.database import _lin_sched
from nixnet.database import _pdu
self._handle = handle
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]
self._ecus = _collection.DbCollection(
self._handle, constants.ObjectClass.ECU, _cconsts.NX_PROP_CLST_ECU_REFS, _ecu.Ecu)
self._frames = _collection.DbCollection(
Expand All @@ -35,25 +38,6 @@ def __init__(self, handle):
self._pdus = _collection.DbCollection(
self._handle, constants.ObjectClass.PDU, _cconsts.NX_PROP_CLST_PDU_REFS, _pdu.Pdu)

def __eq__(self, other):
if isinstance(other, self.__class__):
return self._handle == other._handle
else:
return NotImplemented

def __ne__(self, other):
result = self.__eq__(other)
if result is NotImplemented:
return result
else:
return not result

def __hash__(self):
return hash(self._handle)

def __repr__(self):
return '{}(handle={})'.format(type(self).__name__, self._handle)

def check_config_status(self):
# type: () -> None
"""Check this cluster's configuration status.
Expand Down Expand Up @@ -86,6 +70,14 @@ def export(self, db_filepath):
"""
_funcs.nxdb_save_database(self._handle, db_filepath)

def find(
self,
object_class, # type: typing.Type[_database_object.DatabaseObject]
object_name, # type: typing.Text
):
# type: (...) -> _database_object.DatabaseObject
return _find_object.find_object(self._handle, object_class, object_name)

def merge(
self,
source_obj,
Expand Down
31 changes: 31 additions & 0 deletions nixnet/database/_database_object.py
@@ -0,0 +1,31 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import typing # NOQA: F401


class DatabaseObject(object):
"""Database object base."""

def __init__(self, handle):
self._handle = handle

def __eq__(self, other):
if isinstance(other, self.__class__):
return self._handle == typing.cast(DatabaseObject, other)._handle
else:
return NotImplemented

def __ne__(self, other):
result = self.__eq__(other)
if result is NotImplemented:
return result
else:
return not result

def __hash__(self):
return hash(self._handle)

def __repr__(self):
return '{}(handle={})'.format(type(self).__name__, self._handle)
24 changes: 3 additions & 21 deletions nixnet/database/_ecu.py
Expand Up @@ -9,37 +9,19 @@
from nixnet import constants

from nixnet.database import _cluster
from nixnet.database import _database_object
from nixnet.database import _dbc_attributes
from nixnet.database import _frame


class Ecu(object):
class Ecu(_database_object.DatabaseObject):
"""Database ECU"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
_database_object.DatabaseObject.__init__(self, handle)
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]

def __eq__(self, other):
if isinstance(other, self.__class__):
return self._handle == other._handle
else:
return NotImplemented

def __ne__(self, other):
result = self.__eq__(other)
if result is NotImplemented:
return result
else:
return not result

def __hash__(self):
return hash(self._handle)

def __repr__(self):
return '{}(handle={})'.format(type(self).__name__, self._handle)

def check_config_status(self):
# type: () -> None
"""Check this ECU's configuration status.
Expand Down
54 changes: 54 additions & 0 deletions nixnet/database/_find_object.py
@@ -0,0 +1,54 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import typing # NOQA: F401

from nixnet import _cconsts
from nixnet import _errors
from nixnet import _funcs
from nixnet import constants
from nixnet.database import _database_object # NOQA: F401


def find_object(
parent_handle, # type: int
object_class, # type: typing.Type[_database_object.DatabaseObject]
object_name, # type: typing.Text
):
# type: (...) -> _database_object.DatabaseObject
from nixnet.database._cluster import Cluster
from nixnet.database._ecu import Ecu
from nixnet.database._frame import Frame
from nixnet.database._lin_sched import LinSched
from nixnet.database._lin_sched_entry import LinSchedEntry
from nixnet.database._pdu import Pdu
from nixnet.database._signal import Signal
from nixnet.database._subframe import SubFrame

class_enum = constants.ObjectClass.CLUSTER # arbitrary default value

if object_class is Cluster:
class_enum = constants.ObjectClass.CLUSTER
elif object_class is Ecu:
class_enum = constants.ObjectClass.ECU
elif object_class is Frame:
class_enum = constants.ObjectClass.FRAME
elif object_class is LinSched:
class_enum = constants.ObjectClass.LIN_SCHED
elif object_class is LinSchedEntry:
class_enum = constants.ObjectClass.LIN_SCHED_ENTRY
elif object_class is Pdu:
class_enum = constants.ObjectClass.PDU
elif object_class is Signal:
class_enum = constants.ObjectClass.SIGNAL
elif object_class is SubFrame:
class_enum = constants.ObjectClass.SUBFRAME
else:
_errors.raise_xnet_error(_cconsts.NX_ERR_INVALID_PROPERTY_VALUE)

found_handle = _funcs.nxdb_find_object(parent_handle, class_enum, object_name)
if found_handle == 0:
_errors.raise_xnet_error(_cconsts.NX_ERR_DATABASE_OBJECT_NOT_FOUND)

return object_class(found_handle)
36 changes: 14 additions & 22 deletions nixnet/database/_frame.py
Expand Up @@ -13,42 +13,26 @@

from nixnet.database import _cluster
from nixnet.database import _collection
from nixnet.database import _database_object
from nixnet.database import _dbc_attributes
from nixnet.database import _find_object
from nixnet.database import _signal


class Frame(object):
class Frame(_database_object.DatabaseObject):
"""Database frame"""

def __init__(self, handle):
# type: (int) -> None
from nixnet.database import _subframe
self._handle = handle
_database_object.DatabaseObject.__init__(self, handle)
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection]

from nixnet.database import _subframe
self._mux_static_signals = _collection.DbCollection(
self._handle, constants.ObjectClass.SIGNAL, _cconsts.NX_PROP_FRM_MUX_STATIC_SIG_REFS, _signal.Signal)
self._mux_subframes = _collection.DbCollection(
self._handle, constants.ObjectClass.SUBFRAME, _cconsts.NX_PROP_FRM_MUX_SUBFRAME_REFS, _subframe.SubFrame)

def __eq__(self, other):
if isinstance(other, self.__class__):
return self._handle == other._handle
else:
return NotImplemented

def __ne__(self, other):
result = self.__eq__(other)
if result is NotImplemented:
return result
else:
return not result

def __hash__(self):
return hash(self._handle)

def __repr__(self):
return '{}(handle={})'.format(type(self).__name__, self._handle)

def check_config_status(self):
# type: () -> None
"""Check this frame's configuration status.
Expand All @@ -66,6 +50,14 @@ def check_config_status(self):
status_code = _props.get_frame_config_status(self._handle)
_errors.check_for_error(status_code)

def find(
self,
object_class, # type: typing.Type[_database_object.DatabaseObject]
object_name, # type: typing.Text
):
# type: (...) -> _database_object.DatabaseObject
return _find_object.find_object(self._handle, object_class, object_name)

@property
def application_protocol(self):
# type: () -> constants.AppProtocol
Expand Down
34 changes: 13 additions & 21 deletions nixnet/database/_lin_sched.py
Expand Up @@ -11,40 +11,24 @@

from nixnet.database import _cluster
from nixnet.database import _collection
from nixnet.database import _database_object
from nixnet.database import _find_object


class LinSched(object):
class LinSched(_database_object.DatabaseObject):
"""Database LIN schedule"""

def __init__(self, handle):
# type: (int) -> None
_database_object.DatabaseObject.__init__(self, handle)

from nixnet.database import _lin_sched_entry
self._handle = handle
self._entries = _collection.DbCollection(
self._handle,
constants.ObjectClass.LIN_SCHED_ENTRY,
_cconsts.NX_PROP_LIN_SCHED_ENTRIES,
_lin_sched_entry.LinSchedEntry)

def __eq__(self, other):
if isinstance(other, self.__class__):
return self._handle == other._handle
else:
return NotImplemented

def __ne__(self, other):
result = self.__eq__(other)
if result is NotImplemented:
return result
else:
return not result

def __hash__(self):
return hash(self._handle)

def __repr__(self):
return '{}(handle={})'.format(type(self).__name__, self._handle)

def check_config_status(self):
# type: () -> None
"""Check this LIN schedule's configuration status.
Expand All @@ -62,6 +46,14 @@ def check_config_status(self):
status_code = _props.get_lin_sched_config_status(self._handle)
_errors.check_for_error(status_code)

def find(
self,
object_class, # type: typing.Type[_database_object.DatabaseObject]
object_name, # type: typing.Text
):
# type: (...) -> _database_object.DatabaseObject
return _find_object.find_object(self._handle, object_class, object_name)

@property
def clst(self):
# type: () -> _cluster.Cluster
Expand Down

0 comments on commit 17dbd04

Please sign in to comment.