Skip to content

Commit

Permalink
Merge 226cdb4 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 + 226cdb4 commit f50da4d
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 195 deletions.
1 change: 1 addition & 0 deletions docs/api_reference/database.rst
Expand Up @@ -7,6 +7,7 @@ nixnet.database

database/cluster
database/database
database/database_object_base
database/ecu
database/frame
database/lin_sched
Expand Down
7 changes: 7 additions & 0 deletions docs/api_reference/database/database_object_base.rst
@@ -0,0 +1,7 @@
nixnet.database.database_object_base
====================================

.. automodule:: nixnet.database._database_object_base
:members:
:inherited-members:
:show-inheritance:
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
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_base
from nixnet.database import _dbc_attributes
from nixnet.database import _find_object
from nixnet.database import _signal


class Cluster(object):
class Cluster(_database_object_base.DatabaseObjectBase):
"""Database cluster"""

def __init__(self, handle):
# type: (int) -> None
_database_object_base.DatabaseObjectBase.__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: constants.ObjectClass
object_name # type: typing.Text
):
# type: (...) -> _database_object_base.DatabaseObjectBase
return _find_object.find_object(self._handle, object_class, object_name)

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

import typing # NOQA: F401


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

def __init__(self, handle):
# type: (int) -> None
self._handle = handle

def __eq__(self, other):
if isinstance(other, self.__class__):
return self._handle == typing.cast(DatabaseObjectBase, 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_base
from nixnet.database import _dbc_attributes
from nixnet.database import _frame


class Ecu(object):
class Ecu(_database_object_base.DatabaseObjectBase):
"""Database ECU"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle
_database_object_base.DatabaseObjectBase.__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
53 changes: 53 additions & 0 deletions nixnet/database/_find_object.py
@@ -0,0 +1,53 @@
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_base # NOQA: F401


def find_object(
parent_handle, # type: int
object_class, # type: constants.ObjectClass
object_name # type: typing.Text
):
# type: (...) -> _database_object_base.DatabaseObjectBase
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

found_object = None # type: _database_object_base.DatabaseObjectBase
found_handle = _funcs.nxdb_find_object(parent_handle, object_class, object_name)

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

return found_object
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_base
from nixnet.database import _dbc_attributes
from nixnet.database import _find_object
from nixnet.database import _signal


class Frame(object):
class Frame(_database_object_base.DatabaseObjectBase):
"""Database frame"""

def __init__(self, handle):
# type: (int) -> None
from nixnet.database import _subframe
self._handle = handle
_database_object_base.DatabaseObjectBase.__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: constants.ObjectClass
object_name # type: typing.Text
):
# type: (...) -> _database_object_base.DatabaseObjectBase
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_base
from nixnet.database import _find_object


class LinSched(object):
class LinSched(_database_object_base.DatabaseObjectBase):
"""Database LIN schedule"""

def __init__(self, handle):
# type: (int) -> None
_database_object_base.DatabaseObjectBase.__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: constants.ObjectClass
object_name # type: typing.Text
):
# type: (...) -> _database_object_base.DatabaseObjectBase
return _find_object.find_object(self._handle, object_class, object_name)

@property
def clst(self):
# type: () -> _cluster.Cluster
Expand Down
24 changes: 3 additions & 21 deletions nixnet/database/_lin_sched_entry.py
Expand Up @@ -9,35 +9,17 @@
from nixnet import _props
from nixnet import constants

from nixnet.database import _database_object_base
from nixnet.database import _frame
from nixnet.database import _lin_sched


class LinSchedEntry(object):
class LinSchedEntry(_database_object_base.DatabaseObjectBase):
"""Database LIN schedule entry"""

def __init__(self, handle):
# type: (int) -> None
self._handle = handle

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)
_database_object_base.DatabaseObjectBase.__init__(self, handle)

@property
def collision_res_sched(self):
Expand Down

0 comments on commit f50da4d

Please sign in to comment.