Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
osie
Commits
6d326efb
Commit
6d326efb
authored
Apr 26, 2022
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: initial implementation of a dictionary.
parent
af08348a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
0 deletions
+70
-0
coupler/opc-ua-server/common.h
coupler/opc-ua-server/common.h
+61
-0
coupler/opc-ua-server/keep_alive_subscriber.h
coupler/opc-ua-server/keep_alive_subscriber.h
+1
-0
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+8
-0
No files found.
coupler/opc-ua-server/common.h
View file @
6d326efb
...
...
@@ -63,3 +63,64 @@ char *randomString(size_t length)
}
return
randomString
;
}
// XXX: dictionary implementation based on https://gist.github.com/kylef/86784/fe97567ec9baf5c0dce3c7fcbec948e21dfcce09
typedef
struct
dict_t_struct
{
char
*
key
;
void
*
value
;
struct
dict_t_struct
*
next
;
}
dict_t
;
dict_t
**
dictAlloc
(
void
)
{
return
malloc
(
sizeof
(
dict_t
));
}
void
dictDealloc
(
dict_t
**
dict
)
{
free
(
dict
);
}
void
*
getItem
(
dict_t
*
dict
,
char
*
key
)
{
dict_t
*
ptr
;
for
(
ptr
=
dict
;
ptr
!=
NULL
;
ptr
=
ptr
->
next
)
{
if
(
strcmp
(
ptr
->
key
,
key
)
==
0
)
{
return
ptr
->
value
;
}
}
return
NULL
;
}
void
delItem
(
dict_t
**
dict
,
char
*
key
)
{
dict_t
*
ptr
,
*
prev
;
for
(
ptr
=
*
dict
,
prev
=
NULL
;
ptr
!=
NULL
;
prev
=
ptr
,
ptr
=
ptr
->
next
)
{
if
(
strcmp
(
ptr
->
key
,
key
)
==
0
)
{
if
(
ptr
->
next
!=
NULL
)
{
if
(
prev
==
NULL
)
{
*
dict
=
ptr
->
next
;
}
else
{
prev
->
next
=
ptr
->
next
;
}
}
else
if
(
prev
!=
NULL
)
{
prev
->
next
=
NULL
;
}
else
{
*
dict
=
NULL
;
}
free
(
ptr
->
key
);
free
(
ptr
);
return
;
}
}
}
void
addItem
(
dict_t
**
dict
,
char
*
key
,
void
*
value
)
{
delItem
(
dict
,
key
);
/* If we already have a item with this key, delete it. */
dict_t
*
d
=
malloc
(
sizeof
(
struct
dict_t_struct
));
d
->
key
=
malloc
(
strlen
(
key
)
+
1
);
strcpy
(
d
->
key
,
key
);
d
->
value
=
value
;
d
->
next
=
*
dict
;
*
dict
=
d
;
}
coupler/opc-ua-server/keep_alive_subscriber.h
View file @
6d326efb
...
...
@@ -35,6 +35,7 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
unsigned
int
coupler_id
=
*
(
UA_UInt32
*
)
var
->
value
.
data
;
if
(
coupler_id
!=
COUPLER_ID
)
{
// care for other coupler_id NOT ourselves
addItem
(
&
SUBSCRIBER_DICT
,
"foo"
,
"bar"
);
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"ID = %d, microseconds=%ld"
,
coupler_id
,
micro_seconds
);
}
}
...
...
coupler/opc-ua-server/server.c
View file @
6d326efb
...
...
@@ -39,6 +39,9 @@ static int COUPLER_ID = 0;
// global server
UA_Server
*
server
;
// global dictionary of subscribers
dict_t
*
SUBSCRIBER_DICT
;
// The default port of OPC-UA server
const
int
DEFAULT_OPC_UA_PORT
=
4840
;
const
int
DEFAULT_MODE
=
0
;
...
...
@@ -156,6 +159,11 @@ int main(int argc, char **argv)
long
result
;
char
*
eptr
;
// init dictionary only once$
if
(
SUBSCRIBER_DICT
==
NULL
){
SUBSCRIBER_DICT
=
*
dictAlloc
();
}
// handle command line arguments
struct
arguments
arguments
;
arguments
.
port
=
DEFAULT_OPC_UA_PORT
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment