-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: master
Are you sure you want to change the base?
[Draft] FileType implementation #4436
Conversation
8adb120
to
5945e09
Compare
There was a problem hiding this 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.
df6e19d
to
a133a29
Compare
There was a problem hiding this 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.
include/open62541/server.h
Outdated
* @return UA_STATUSCODE_GOOD on success | ||
*/ | ||
UA_StatusCode UA_EXPORT | ||
UA_Server_addFile(UA_Server *server, const UA_NodeId requestedNewNodeId, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
src/server/ua_file.c
Outdated
|
||
static UA_StatusCode | ||
updateOpenCountProperty(UA_Server *server, UA_FileType* fileObject) | ||
{ |
There was a problem hiding this comment.
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.
src/server/ua_file.c
Outdated
UA_NODEID_NUMERIC(0, UA_NS0ID_FILETYPE), | ||
attr, nodeContext, outNewNodeId); | ||
|
||
UA_file *sampleFile = UA_file_open((char*)filePath.data, "w"); |
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
src/server/ua_file.c
Outdated
{ | ||
UA_UInt32 fileHandle = *(UA_UInt32 *)input[0].data; | ||
UA_Int32 value = *(UA_Int32 *)input[1].data; | ||
UA_UInt64 requestedLengthToRead = (UA_UInt64)value; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
src/server/ua_server_internal.h
Outdated
|
||
typedef struct UA_FileType { | ||
LIST_ENTRY(UA_FileType) listEntry; | ||
UA_NodeId fileTypeObjectNodeId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileTypeObjectNodeId or fileNodeId?
There was a problem hiding this comment.
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?
You can now use this facility to attach data to session: |
Hi, just wanted to ask what is the current status of this ticket? Cheers |
src/server/ua_file.c
Outdated
result |= getFieldNodeId(server, &fileObjectNodeId, &fieldSetPositionQN, &setPositionNodeId); | ||
result |= getFieldNodeId(server, &fileObjectNodeId, &fieldGetPositionQN, &getPositionNodeId); | ||
result |= getFieldNodeId(server, &fileObjectNodeId, &fieldWriteQN, &writeNodeId); | ||
result |= getFieldNodeId(server, &fileObjectNodeId, &fieldCloseQN, &closeNodeId); |
There was a problem hiding this comment.
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?
a133a29
to
e4c11a9
Compare
- Includes support for open, read, write, close file methods operations - TODO: GetPosition and setPosition method implementation Signed-off-by: Jayanth Velusamy <[email protected]>
Signed-off-by: Jayanth Velusamy <[email protected]>
e4c11a9
to
8d34204
Compare
} | ||
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); |
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
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).
One more interested party here. Kudos to @daniel-petrovic for making the PR. Would really appreciate seeing this merged. |
This pull request implements file implementation.