Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readability - node.server is in fact an InternalSession instance #754

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

brubbel
Copy link
Contributor

@brubbel brubbel commented Nov 23, 2018

code readability.

It is highly confusing to understand the code flow for the Node.server attribute, as the server is actually an "InternalSession (server)" instance. Replaced all occurrences of node.server by node.isession.

There is a fallback property which redirects the server attribute to node.isession, with a one-shot deprecation warning.

@oroulet
Copy link
Member

oroulet commented Nov 23, 2018 via email

@brubbel
Copy link
Contributor Author

brubbel commented Nov 23, 2018

Yes, I did not thought about that.
But server is also confusing, because server can be an InternalSession or an UaClient instance. Neither of which is a Server which many people (including myself) will suppose that this attribute refers to.

You are right about the name isession, maybe it is better to find a common basis for InternalSession and UaClient.

activeSession for example could point to a server or client session.
At server side, InternalSession could inherit from activeSession base class.
At client side, the UaClient could inherit from activeSession ABC.

For me, it was a useful insight that a Node instance is related to a session, rather than to a server.
Nothing will be broken, if there is still a property that redirects the node.server to the activeSession attribute.

e.g. (isession then becomes activeSession of course)

@property
def server(self):
warnings.warn("Node.server attribute is deprecated. Use isession instead", DeprecationWarning)
return self.isession

Also, activeSession would nicely blend with the "activate_session" method in UaClient.py.

@brubbel
Copy link
Contributor Author

brubbel commented Nov 23, 2018

proposed scheme:
image

@brubbel brubbel changed the title readability: node.server is in fact an InternalSession instance WIP: readability - node.server is in fact an InternalSession instance Nov 24, 2018
…erences

Fixed confusion between (Internal)Server <-> InternalSession. A lot of methods
require an 'InternalSession server' instance where the latter is referenced to
as 'server', which makes it quite difficult to understand the code flow.
@brubbel
Copy link
Contributor Author

brubbel commented Nov 27, 2018

Settled for session_server, because it was already used here:

class DataTypeDictionaryBuilder:
def __init__(self, server, idx, idx_name, dict_name):
self._server = server
self._session_server = server.get_root_node().server
self._idx = idx
# Risk of bugs using a fixed number without checking
self._id_counter = 8000
self.dict_id = self._add_dictionary(dict_name)
self._type_dictionary = OPCTypeDictionaryBuilder(idx_name)

Retained a property 'server' linking session_server for backwards compatibility.
Up to you to decide to merge or not 👍

@brubbel brubbel changed the title WIP: readability - node.server is in fact an InternalSession instance readability - node.server is in fact an InternalSession instance Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants