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

[Draft] FileType implementation #4436

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

opcua-tsn-team-kalycito
Copy link
Contributor

This pull request implements file implementation.

  • Methods implemented:
    • Open, Close, Read, Write
    • TODO: SetPosition, GetPosition
  • Properties supported
    • Size, OpenCount

@opcua-tsn-team-kalycito opcua-tsn-team-kalycito force-pushed the fileType_object_implementation branch 3 times, most recently from 8adb120 to 5945e09 Compare May 27, 2021 08:52
@opcua-tsn-team-kalycito opcua-tsn-team-kalycito changed the title [WIP] File implementation [REVIEW] FileType implementation May 27, 2021
Copy link
Member

@jpfr jpfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feature!
See the inline comments.

include/open62541/server.h Outdated Show resolved Hide resolved
include/open62541/server.h Show resolved Hide resolved
@opcua-tsn-team-kalycito opcua-tsn-team-kalycito changed the title [REVIEW] FileType implementation [WIP] FileType implementation May 28, 2021
@opcua-tsn-team-kalycito opcua-tsn-team-kalycito force-pushed the fileType_object_implementation branch 2 times, most recently from df6e19d to a133a29 Compare June 8, 2021 13:52
@opcua-tsn-team-kalycito opcua-tsn-team-kalycito changed the title [WIP] FileType implementation [REVIEW] FileType implementation Jun 8, 2021
Copy link
Member

@jpfr jpfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on a good way.
See above for a new batch of comments.

* @return UA_STATUSCODE_GOOD on success
*/
UA_StatusCode UA_EXPORT
UA_Server_addFile(UA_Server *server, const UA_NodeId requestedNewNodeId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with registerFileNode, rename this to UA_Server_addFileNode.

@@ -0,0 +1,419 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to ua_file_nodes.c.


static UA_StatusCode
updateOpenCountProperty(UA_Server *server, UA_FileType* fileObject)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the usual conventions of the entire library with curly brackets on the same line.

UA_NODEID_NUMERIC(0, UA_NS0ID_FILETYPE),
attr, nodeContext, outNewNodeId);

UA_file *sampleFile = UA_file_open((char*)filePath.data, "w");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error-check everywhere.
This should fail when the file does not exist.
Use proper logging,

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can only log an error and return the invalid UA_file* to the caller.

}

//else use the NodeId requested by user
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail if the user does not provider outNewNodeId and if the NodeId has identifier.numeric==0.
That is the convention to ask the nodestore to generate a new numeric nodeid.
Use a temporary newNodeId variable.

{
UA_UInt32 fileHandle = *(UA_UInt32 *)input[0].data;
UA_Int32 value = *(UA_Int32 *)input[1].data;
UA_UInt64 requestedLengthToRead = (UA_UInt64)value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use size_t for lengthToRead etc.

size_t inputSize, const UA_Variant *input,
size_t outputSize, UA_Variant *output)
{
return UA_STATUSCODE_BADNOTIMPLEMENTED;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of a file is to transport content that is larger than what fits inside a single message.
You can only do that if you preserve the position in the file across different calls to read.

So you need some persistency of that information stored in the user session.
There is a way to get there in a clean fashion. The new PR #4463 adds a key-value configuration system.
Add key-value parameters to the session struct.
And select a nice key-name under which the position for each particular file is stored.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also limit the number of open files per session.
Or this can be a way to consume arbitrary amounts of memory.

Copy link

@daniel-petrovic daniel-petrovic Jul 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be the recommended default value for max open files per session ?

Copy link

@daniel-petrovic daniel-petrovic Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of a file is to transport content that is larger than what fits inside a single message. You can only do that if you preserve the position in the file across different calls to read.

So you need some persistency of that information stored in the user session. There is a way to get there in a clean fashion. The new PR #4463 adds a key-value configuration system. Add key-value parameters to the session struct. And select a nice key-name under which the position for each particular file is stored.

Is the persistency of the current position of file descriptor in the session really needed here ? Because this seems to be implied by the current implementation anyway. As long the Close is not called, each subsequent call to Read from the same FileHandle will read from the it's underlying FILE* stream starting from it's current stream position, which is advanced by every read operation.

@@ -171,6 +171,24 @@ void UA_Server_delete(UA_Server *server) {
}
UA_Array_delete(server->namespaces, server->namespacesSize, &UA_TYPES[UA_TYPES_STRING]);

#ifdef UA_ENABLE_FILETYPE_OBJECT_SUPPORT
UA_FileType *fileObject, *fileObject_tmp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this as much out of ua_server.c as possible.
Set up destructor set for the FileType object type.
So the cleanup happens automatically when the node is deleted.


typedef struct UA_FileType {
LIST_ENTRY(UA_FileType) listEntry;
UA_NodeId fileTypeObjectNodeId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileTypeObjectNodeId or fileNodeId?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a list of filetyeobjects in the ua_server_internal.h is necessary?

@opcua-tsn-team-kalycito opcua-tsn-team-kalycito changed the title [REVIEW] FileType implementation [WIP] FileType implementation Jun 10, 2021
@jpfr
Copy link
Member

jpfr commented Jun 11, 2021

You can now use this facility to attach data to session:
https://github.com/open62541/open62541/blob/master/include/open62541/server.h#L434

@ZidCode
Copy link

ZidCode commented Sep 15, 2021

Hi,

just wanted to ask what is the current status of this ticket?

Cheers

result |= getFieldNodeId(server, &fileObjectNodeId, &fieldSetPositionQN, &setPositionNodeId);
result |= getFieldNodeId(server, &fileObjectNodeId, &fieldGetPositionQN, &getPositionNodeId);
result |= getFieldNodeId(server, &fileObjectNodeId, &fieldWriteQN, &writeNodeId);
result |= getFieldNodeId(server, &fileObjectNodeId, &fieldCloseQN, &closeNodeId);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always returns the NodeIds of the Type Object. Shouldn't it be the NodeID of the Object itself? Is it necessary to add explicitly the methods to the Object?

 - Includes support for open, read, write, close
   file methods operations
 - TODO: GetPosition and setPosition method implementation

Signed-off-by: Jayanth Velusamy <[email protected]>
@andreasebner andreasebner changed the title [WIP] FileType implementation [Draft] FileType implementation May 10, 2022
@andreasebner andreasebner marked this pull request as draft May 10, 2022 14:28
}
readBuffer->length = (size_t)lengthToRead;
readBuffer->data = (UA_Byte*) UA_malloc(readBuffer->length * sizeof(UA_Byte));
UA_file_read(readBuffer->data, (readBuffer->length + 1), 1, fileInfo->file);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error check of UA_file_read missing

@daniel-petrovic
Copy link

Hi,

just wanted to ask what is the current status of this ticket?

Cheers

Would also like to know that ... have addressed some of the open issues in this PR but I'm not sure if it's still maintained

@pberginkonsult
Copy link

Hi,
just wanted to ask what is the current status of this ticket?
Cheers

Would also like to know that ... have addressed some of the open issues in this PR but I'm not sure if it's still maintained

And another one that wants to know the status of this PR. Is it something that can be accepted or is it rejected for inclusion in the project?

UA_FileType *fileObject, *fileObject_tmp;
LIST_FOREACH_SAFE(fileObject, &server->fileObjects, listEntry, fileObject_tmp)
{
UA_Server_deleteNode(server, fileObject->fileNodeId, true);
Copy link

@daniel-petrovic daniel-petrovic Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely cause the UA_assert(++(lock->mutexCounter) == 1); in UA_LOCK which is called in UA_Server_deleteNode to fail. ( Note: The UA_LOCK_INIT sets the mutex attribute PTHREAD_MUTEX_RECURSIVE).

@giokara-oqton
Copy link

One more interested party here. Kudos to @daniel-petrovic for making the PR. Would really appreciate seeing this merged.

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.

None yet

7 participants