Vuo
2.4.4
Loading...
Searching...
No Matches
runtime
VuoRuntimeUtilities.cc
Go to the documentation of this file.
1
10
#include "
VuoRuntimeUtilities.hh
"
11
#include "
VuoRuntimeState.hh
"
12
16
unsigned
long
VuoRuntimeUtilities::hash
(
const
char
*str)
17
{
18
// sdbm algorithm (http://www.cse.yorku.ca/~oz/hash.html) —
19
// very low probability of collisions (https://programmers.stackexchange.com/a/145633/38390)
20
21
unsigned
long
hash
= 0;
22
int
c;
23
24
while
((c = *str++))
25
hash
= c + (
hash
<< 6) + (
hash
<< 16) -
hash
;
26
27
return
hash
;
28
}
29
30
extern
"C"
31
{
32
36
uint64_t
vuoGetCompositionUniqueIdentifier
(
const
struct
VuoCompositionState
*compositionState)
37
{
38
if
(compositionState)
39
return
(uint64_t)((
VuoRuntimeState
*)compositionState->
runtimeState
)->persistentState;
40
else
41
return
0;
42
}
43
47
void
*
vuoCreateTriggerWorkerContext
(
VuoCompositionState
*compositionState,
void
*dataCopy,
unsigned
long
*eventIdCopy)
48
{
49
void
**context = (
void
**)malloc(3 *
sizeof
(
void
*));
50
context[0] = (
void
*)compositionState;
51
context[1] = dataCopy;
52
context[2] = (
void
*)eventIdCopy;
53
return
(
void
*)context;
54
}
55
59
void
vuoFreeTriggerWorkerContext
(
void
*context)
60
{
61
void
**contextArray = (
void
**)context;
62
free(contextArray[1]);
63
free(contextArray[2]);
64
free(contextArray);
65
}
66
70
void
*
vuoCreatePublishedInputWorkerContext
(
VuoCompositionState
*compositionState,
const
char
*inputPortIdentifier,
const
char
*valueAsString,
71
bool
isCompositionRunning)
72
{
73
void
**context = (
void
**)malloc(4 *
sizeof
(
void
*));
74
context[0] = (
void
*)compositionState;
75
context[1] = (
void
*)inputPortIdentifier;
76
context[2] = (
void
*)valueAsString;
77
context[3] = (
void
*)isCompositionRunning;
78
return
(
void
*)context;
79
}
80
84
char
*
vuoConcatenateStrings2
(
const
char
*s0,
const
char
*s1)
85
{
86
size_t
bufferLength = strlen(s0) + strlen(s1) + 1;
87
char
*buffer = (
char
*)malloc(bufferLength);
88
buffer[0] = 0;
89
strlcat(buffer, s0, bufferLength);
90
strlcat(buffer, s1, bufferLength);
91
return
buffer;
92
}
93
97
char
*
vuoConcatenateStrings3
(
const
char
*s0,
const
char
*s1,
const
char
*s2)
98
{
99
size_t
bufferLength = strlen(s0) + strlen(s1) + strlen(s2) + 1;
100
char
*buffer = (
char
*)malloc(bufferLength);
101
buffer[0] = 0;
102
strlcat(buffer, s0, bufferLength);
103
strlcat(buffer, s1, bufferLength);
104
strlcat(buffer, s2, bufferLength);
105
return
buffer;
106
}
107
111
char
*
vuoConcatenateStrings
(
const
char
**strings,
size_t
stringCount)
112
{
113
size_t
bufferLength = 1;
114
for
(
size_t
i = 0; i < stringCount; ++i)
115
bufferLength += strlen(strings[i]);
116
char
*buffer = (
char
*)malloc(bufferLength);
117
buffer[0] = 0;
118
for
(
size_t
i = 0; i < stringCount; ++i)
119
strlcat(buffer, strings[i], bufferLength);
120
return
buffer;
121
}
122
123
}
// extern "C"
Generated on Thu Nov 9 2023 16:59:30 for Vuo by
1.9.8