durable_rules 2.0.6 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/rules/events.c +115 -84
- data/src/rules/json.c +1 -1
- data/src/rules/rete.c +2 -15
- data/src/rules/rete.h +2 -5
- data/src/rules/rules.h +9 -8
- data/src/rules/state.c +14 -16
- data/src/rules/state.h +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c08ea6baf1f7ff23b7b360cbc0a4f5d27361524
|
4
|
+
data.tar.gz: c6e839c804df85c3aa26d752d42ed965c78382f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 042ada520d5d8434ccfaeeff78603af18efe209fc80b8033f595e2e521064cb2ff54d1e45edace0bb64cab912f8a6b822c172794ff7f9c039fa088e1b13522e3
|
7
|
+
data.tar.gz: d3f6b93ff29efcdcd1b5c90825965c73aa780a807f47a37c489e6134f660048a657042d63692aa33ea4ea6e1adf45fe6f44632e57dd6289929139c9c47675d7f
|
data/src/rules/events.c
CHANGED
@@ -776,11 +776,16 @@ static unsigned int handleBetaFrame(ruleset *tree,
|
|
776
776
|
node *oldNode,
|
777
777
|
node *currentNode,
|
778
778
|
leftFrameNode *oldFrame,
|
779
|
-
leftFrameNode *currentFrame
|
779
|
+
leftFrameNode *currentFrame,
|
780
|
+
unsigned char sideEffect) {
|
780
781
|
frameLocation currentFrameLocation;
|
781
782
|
unsigned int frameType = LEFT_FRAME;
|
782
783
|
|
783
784
|
if (currentNode->type == NODE_ACTION) {
|
785
|
+
if (!sideEffect) {
|
786
|
+
return RULES_OK;
|
787
|
+
}
|
788
|
+
|
784
789
|
CHECK_RESULT(createActionFrame(state,
|
785
790
|
currentNode,
|
786
791
|
currentFrame,
|
@@ -898,7 +903,8 @@ static unsigned int handleBetaFrame(ruleset *tree,
|
|
898
903
|
currentNode,
|
899
904
|
nextNode,
|
900
905
|
NULL,
|
901
|
-
currentFrame
|
906
|
+
currentFrame,
|
907
|
+
sideEffect);
|
902
908
|
|
903
909
|
} else if (currentNode->type == NODE_BETA) {
|
904
910
|
// Find all messages for frame
|
@@ -926,7 +932,8 @@ static unsigned int handleBetaFrame(ruleset *tree,
|
|
926
932
|
currentNode,
|
927
933
|
nextNode,
|
928
934
|
NULL,
|
929
|
-
currentFrame
|
935
|
+
currentFrame,
|
936
|
+
sideEffect));
|
930
937
|
}
|
931
938
|
|
932
939
|
unsigned int rightFrameOffset = rightFrame->prevOffset;
|
@@ -959,7 +966,8 @@ static unsigned int handleBetaFrame(ruleset *tree,
|
|
959
966
|
currentNode,
|
960
967
|
nextNode,
|
961
968
|
connectorFrame,
|
962
|
-
currentFrame
|
969
|
+
currentFrame,
|
970
|
+
sideEffect));
|
963
971
|
|
964
972
|
connectorFrameOffset = connectorFrame->prevOffset;
|
965
973
|
if (connectorFrameOffset == UNDEFINED_HASH_OFFSET) {
|
@@ -983,7 +991,8 @@ static unsigned int handleBetaFrame(ruleset *tree,
|
|
983
991
|
currentNode,
|
984
992
|
nextNode,
|
985
993
|
NULL,
|
986
|
-
currentFrame
|
994
|
+
currentFrame,
|
995
|
+
sideEffect));
|
987
996
|
}
|
988
997
|
|
989
998
|
return RULES_OK;
|
@@ -1073,7 +1082,8 @@ static unsigned int handleDeleteMessage(ruleset *tree,
|
|
1073
1082
|
currentNode,
|
1074
1083
|
nextNode,
|
1075
1084
|
NULL,
|
1076
|
-
NULL
|
1085
|
+
NULL,
|
1086
|
+
1));
|
1077
1087
|
}
|
1078
1088
|
} else {
|
1079
1089
|
unsigned int messageHash;
|
@@ -1109,7 +1119,8 @@ static unsigned int handleDeleteMessage(ruleset *tree,
|
|
1109
1119
|
currentNode,
|
1110
1120
|
nextNode,
|
1111
1121
|
NULL,
|
1112
|
-
currentFrame
|
1122
|
+
currentFrame,
|
1123
|
+
1));
|
1113
1124
|
}
|
1114
1125
|
|
1115
1126
|
unsigned int currentFrameOffset = currentFrame->prevOffset;
|
@@ -1285,7 +1296,8 @@ static unsigned int handleMatchFrames(ruleset *tree,
|
|
1285
1296
|
node *currentNode,
|
1286
1297
|
jsonObject *messageObject,
|
1287
1298
|
unsigned int currentMessageOffset,
|
1288
|
-
unsigned int messageHash
|
1299
|
+
unsigned int messageHash,
|
1300
|
+
unsigned char sideEffect) {
|
1289
1301
|
// Find frames for message
|
1290
1302
|
leftFrameNode *currentFrame = NULL;
|
1291
1303
|
node *nextNode = &tree->nodePool[currentNode->value.b.nextOffset];
|
@@ -1311,7 +1323,8 @@ static unsigned int handleMatchFrames(ruleset *tree,
|
|
1311
1323
|
currentNode,
|
1312
1324
|
nextNode,
|
1313
1325
|
NULL,
|
1314
|
-
currentFrame
|
1326
|
+
currentFrame,
|
1327
|
+
sideEffect));
|
1315
1328
|
}
|
1316
1329
|
|
1317
1330
|
unsigned int currentFrameOffset = currentFrame->prevOffset;
|
@@ -1336,7 +1349,8 @@ static unsigned int handleMatchFrames(ruleset *tree,
|
|
1336
1349
|
currentNode,
|
1337
1350
|
nextNode,
|
1338
1351
|
NULL,
|
1339
|
-
NULL
|
1352
|
+
NULL,
|
1353
|
+
sideEffect);
|
1340
1354
|
}
|
1341
1355
|
|
1342
1356
|
return RULES_OK;
|
@@ -1346,7 +1360,8 @@ static unsigned int handleBetaMessage(ruleset *tree,
|
|
1346
1360
|
stateNode *state,
|
1347
1361
|
node *betaNode,
|
1348
1362
|
jsonObject *messageObject,
|
1349
|
-
unsigned int currentMessageOffset
|
1363
|
+
unsigned int currentMessageOffset,
|
1364
|
+
unsigned char sideEffect) {
|
1350
1365
|
if (betaNode->value.b.isFirst && !betaNode->value.b.not) {
|
1351
1366
|
node *nextNode = &tree->nodePool[betaNode->value.b.nextOffset];
|
1352
1367
|
return handleBetaFrame(tree,
|
@@ -1355,7 +1370,8 @@ static unsigned int handleBetaMessage(ruleset *tree,
|
|
1355
1370
|
betaNode,
|
1356
1371
|
nextNode,
|
1357
1372
|
NULL,
|
1358
|
-
NULL
|
1373
|
+
NULL,
|
1374
|
+
sideEffect);
|
1359
1375
|
}
|
1360
1376
|
|
1361
1377
|
frameLocation rightFrameLocation;
|
@@ -1397,7 +1413,8 @@ static unsigned int handleBetaMessage(ruleset *tree,
|
|
1397
1413
|
betaNode,
|
1398
1414
|
messageObject,
|
1399
1415
|
currentMessageOffset,
|
1400
|
-
messageHash
|
1416
|
+
messageHash,
|
1417
|
+
sideEffect);
|
1401
1418
|
}
|
1402
1419
|
|
1403
1420
|
static unsigned int isArrayMatch(ruleset *tree,
|
@@ -1589,7 +1606,8 @@ static unsigned int handleAlpha(ruleset *tree,
|
|
1589
1606
|
jsonObject *jo,
|
1590
1607
|
unsigned char messageType,
|
1591
1608
|
alpha *alphaNode,
|
1592
|
-
unsigned int *messageOffset
|
1609
|
+
unsigned int *messageOffset,
|
1610
|
+
unsigned char sideEffect) {
|
1593
1611
|
unsigned short top = 1;
|
1594
1612
|
unsigned int entry;
|
1595
1613
|
unsigned char messageStored = 0;
|
@@ -1671,6 +1689,7 @@ static unsigned int handleAlpha(ruleset *tree,
|
|
1671
1689
|
mid,
|
1672
1690
|
jo,
|
1673
1691
|
messageType,
|
1692
|
+
sideEffect,
|
1674
1693
|
messageOffset));
|
1675
1694
|
|
1676
1695
|
messageStored = 1;
|
@@ -1683,7 +1702,8 @@ static unsigned int handleAlpha(ruleset *tree,
|
|
1683
1702
|
state,
|
1684
1703
|
&tree->nodePool[betaList[entry]],
|
1685
1704
|
jo,
|
1686
|
-
*messageOffset
|
1705
|
+
*messageOffset,
|
1706
|
+
sideEffect));
|
1687
1707
|
}
|
1688
1708
|
}
|
1689
1709
|
}
|
@@ -1695,7 +1715,8 @@ static unsigned int handleMessageCore(ruleset *tree,
|
|
1695
1715
|
jsonObject *jo,
|
1696
1716
|
unsigned char actionType,
|
1697
1717
|
unsigned int *messageOffset,
|
1698
|
-
unsigned int *stateOffset
|
1718
|
+
unsigned int *stateOffset,
|
1719
|
+
unsigned char sideEffect) {
|
1699
1720
|
stateNode *sidState;
|
1700
1721
|
jsonProperty *sidProperty = &jo->properties[jo->sidIndex];
|
1701
1722
|
jsonProperty *midProperty = &jo->properties[jo->idIndex];
|
@@ -1763,7 +1784,8 @@ static unsigned int handleMessageCore(ruleset *tree,
|
|
1763
1784
|
jo,
|
1764
1785
|
MESSAGE_TYPE_FACT,
|
1765
1786
|
&tree->nodePool[NODE_M_OFFSET].value.a,
|
1766
|
-
messageOffset
|
1787
|
+
messageOffset,
|
1788
|
+
sideEffect);
|
1767
1789
|
if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED) {
|
1768
1790
|
return result;
|
1769
1791
|
} else if (result == ERR_EVENT_NOT_HANDLED) {
|
@@ -1771,7 +1793,8 @@ static unsigned int handleMessageCore(ruleset *tree,
|
|
1771
1793
|
sidState,
|
1772
1794
|
mid,
|
1773
1795
|
jo,
|
1774
|
-
|
1796
|
+
MESSAGE_TYPE_STATE,
|
1797
|
+
sideEffect,
|
1775
1798
|
messageOffset));
|
1776
1799
|
}
|
1777
1800
|
|
@@ -1794,10 +1817,11 @@ static unsigned int handleMessageCore(ruleset *tree,
|
|
1794
1817
|
jo,
|
1795
1818
|
(actionType == ACTION_ASSERT_FACT ? MESSAGE_TYPE_FACT : MESSAGE_TYPE_EVENT),
|
1796
1819
|
&tree->nodePool[NODE_M_OFFSET].value.a,
|
1797
|
-
messageOffset
|
1820
|
+
messageOffset,
|
1821
|
+
sideEffect);
|
1798
1822
|
|
1799
1823
|
if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
|
1800
|
-
if (sidState->factOffset == UNDEFINED_HASH_OFFSET) {
|
1824
|
+
if (sideEffect && (sidState->factOffset == UNDEFINED_HASH_OFFSET)) {
|
1801
1825
|
#ifdef _WIN32
|
1802
1826
|
char *stateMessage = (char *)_alloca(sizeof(char)*(50 + sidProperty->valueLength * 2));
|
1803
1827
|
sprintf_s(stateMessage, sizeof(char)*(50 + sidProperty->valueLength * 2), "{ \"sid\":\"%s\", \"id\":\"sid-%s\", \"$s\":1}", sid, sid);
|
@@ -1846,7 +1870,8 @@ static unsigned int handleMessage(ruleset *tree,
|
|
1846
1870
|
&jo,
|
1847
1871
|
actionType,
|
1848
1872
|
messageOffset,
|
1849
|
-
stateOffset
|
1873
|
+
stateOffset,
|
1874
|
+
1);
|
1850
1875
|
}
|
1851
1876
|
|
1852
1877
|
static unsigned int handleMessages(ruleset *tree,
|
@@ -1886,7 +1911,8 @@ static unsigned int handleMessages(ruleset *tree,
|
|
1886
1911
|
&jo,
|
1887
1912
|
actionType,
|
1888
1913
|
&messageOffset,
|
1889
|
-
stateOffset
|
1914
|
+
stateOffset,
|
1915
|
+
1);
|
1890
1916
|
|
1891
1917
|
*last = lastTemp;
|
1892
1918
|
if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED && result != ERR_EVENT_OBSERVED) {
|
@@ -1941,7 +1967,7 @@ unsigned int assertFacts(unsigned int handle,
|
|
1941
1967
|
ruleset *tree;
|
1942
1968
|
RESOLVE_HANDLE(handle, &tree);
|
1943
1969
|
|
1944
|
-
return handleMessages(tree,
|
1970
|
+
return handleMessages(tree, ACTION_ASSERT_FACT, messages, stateOffset);
|
1945
1971
|
}
|
1946
1972
|
|
1947
1973
|
unsigned int retractFact(unsigned int handle,
|
@@ -1979,7 +2005,8 @@ unsigned int updateState(unsigned int handle,
|
|
1979
2005
|
|
1980
2006
|
static unsigned int replayMessages(ruleset *tree,
|
1981
2007
|
char *messages,
|
1982
|
-
unsigned int *stateOffset
|
2008
|
+
unsigned int *stateOffset,
|
2009
|
+
unsigned char sideEffect) {
|
1983
2010
|
unsigned int result;
|
1984
2011
|
unsigned int messageOffset;
|
1985
2012
|
jsonObject jo;
|
@@ -1993,7 +2020,6 @@ static unsigned int replayMessages(ruleset *tree,
|
|
1993
2020
|
&first,
|
1994
2021
|
&last,
|
1995
2022
|
&type) == PARSE_OK) {
|
1996
|
-
|
1997
2023
|
if (type != JSON_INT) {
|
1998
2024
|
return ERR_UNEXPECTED_TYPE;
|
1999
2025
|
}
|
@@ -2028,13 +2054,15 @@ static unsigned int replayMessages(ruleset *tree,
|
|
2028
2054
|
--last;
|
2029
2055
|
}
|
2030
2056
|
|
2057
|
+
|
2031
2058
|
lastTemp = *last;
|
2032
2059
|
*last = '\0';
|
2033
2060
|
result = handleMessageCore(tree,
|
2034
2061
|
&jo,
|
2035
2062
|
actionType,
|
2036
2063
|
&messageOffset,
|
2037
|
-
stateOffset
|
2064
|
+
stateOffset,
|
2065
|
+
sideEffect);
|
2038
2066
|
|
2039
2067
|
*last = lastTemp;
|
2040
2068
|
if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED && result != ERR_EVENT_OBSERVED) {
|
@@ -2048,78 +2076,81 @@ static unsigned int replayMessages(ruleset *tree,
|
|
2048
2076
|
}
|
2049
2077
|
|
2050
2078
|
|
2051
|
-
static unsigned int
|
2079
|
+
static unsigned int startQueuedActions(ruleset *tree) {
|
2052
2080
|
if (tree->getIdleStateCallback) {
|
2053
|
-
char *sid;
|
2054
2081
|
CHECK_RESULT(tree->getIdleStateCallback(tree->getIdleStateCallbackContext,
|
2055
|
-
&tree->stringPool[tree->nameOffset]
|
2056
|
-
&sid));
|
2057
|
-
if (sid) {
|
2058
|
-
stateNode *state;
|
2059
|
-
unsigned int result = getStateNode(tree,
|
2060
|
-
sid,
|
2061
|
-
&state);
|
2062
|
-
if (result != RULES_OK && result != ERR_SID_NOT_FOUND) {
|
2063
|
-
return result;
|
2064
|
-
} else if (result == RULES_OK) {
|
2065
|
-
CHECK_RESULT(deleteStateNode(tree,
|
2066
|
-
state));
|
2067
|
-
}
|
2068
|
-
|
2069
|
-
CHECK_RESULT(createStateNode(tree,
|
2070
|
-
sid,
|
2071
|
-
&state));
|
2072
|
-
|
2073
|
-
free(sid);
|
2074
|
-
if (tree->getStoredMessagesCallback) {
|
2075
|
-
char *messages;
|
2076
|
-
unsigned int stateOffset;
|
2077
|
-
CHECK_RESULT(tree->getStoredMessagesCallback(tree->getStoredMessagesCallbackContext,
|
2078
|
-
&tree->stringPool[tree->nameOffset],
|
2079
|
-
state->sid,
|
2080
|
-
&messages));
|
2081
|
-
if (messages) {
|
2082
|
-
result = replayMessages(tree,
|
2083
|
-
messages,
|
2084
|
-
&stateOffset);
|
2085
|
-
|
2086
|
-
free(messages);
|
2087
|
-
if (result != RULES_OK) {
|
2088
|
-
return result;
|
2089
|
-
}
|
2090
|
-
|
2091
|
-
}
|
2092
|
-
}
|
2093
|
-
}
|
2082
|
+
&tree->stringPool[tree->nameOffset]));
|
2094
2083
|
}
|
2095
2084
|
|
2096
|
-
|
2097
2085
|
if (tree->getQueuedMessagesCallback) {
|
2098
2086
|
for (unsigned int index = 0; index < tree->statePool.count; ++index) {
|
2099
2087
|
unsigned int nodeOffset = tree->reverseStateIndex[index];
|
2100
2088
|
stateNode *currentState = STATE_NODE(tree, nodeOffset);
|
2101
2089
|
|
2102
|
-
char *messages;
|
2103
|
-
unsigned int stateOffset;
|
2104
2090
|
CHECK_RESULT(tree->getQueuedMessagesCallback(tree->getQueuedMessagesCallbackContext,
|
2105
2091
|
&tree->stringPool[tree->nameOffset],
|
2106
|
-
currentState->sid
|
2107
|
-
&messages));
|
2108
|
-
if (messages) {
|
2109
|
-
unsigned int result = replayMessages(tree,
|
2110
|
-
messages,
|
2111
|
-
&stateOffset);
|
2112
|
-
free(messages);
|
2113
|
-
if (result != RULES_OK) {
|
2114
|
-
return result;
|
2115
|
-
}
|
2116
|
-
}
|
2092
|
+
currentState->sid));
|
2117
2093
|
}
|
2118
2094
|
}
|
2119
2095
|
|
2120
2096
|
return RULES_OK;
|
2121
2097
|
}
|
2122
2098
|
|
2099
|
+
unsigned int completeGetIdleState(unsigned int handle,
|
2100
|
+
char *sid,
|
2101
|
+
char *storedMessages) {
|
2102
|
+
ruleset *tree;
|
2103
|
+
RESOLVE_HANDLE(handle, &tree);
|
2104
|
+
stateNode *state;
|
2105
|
+
unsigned int result = getStateNode(tree,
|
2106
|
+
sid,
|
2107
|
+
&state);
|
2108
|
+
if (result != RULES_OK && result != ERR_SID_NOT_FOUND) {
|
2109
|
+
return result;
|
2110
|
+
} else if (result == RULES_OK) {
|
2111
|
+
CHECK_RESULT(deleteStateNode(tree,
|
2112
|
+
state));
|
2113
|
+
}
|
2114
|
+
|
2115
|
+
CHECK_RESULT(createStateNode(tree,
|
2116
|
+
sid,
|
2117
|
+
&state));
|
2118
|
+
|
2119
|
+
|
2120
|
+
if (storedMessages) {
|
2121
|
+
unsigned int stateOffset;
|
2122
|
+
CHECK_RESULT(replayMessages(tree,
|
2123
|
+
storedMessages,
|
2124
|
+
&stateOffset,
|
2125
|
+
0));
|
2126
|
+
}
|
2127
|
+
|
2128
|
+
if (tree->getQueuedMessagesCallback) {
|
2129
|
+
CHECK_RESULT(tree->getQueuedMessagesCallback(tree->getQueuedMessagesCallbackContext,
|
2130
|
+
&tree->stringPool[tree->nameOffset],
|
2131
|
+
sid));
|
2132
|
+
}
|
2133
|
+
|
2134
|
+
return RULES_OK;
|
2135
|
+
}
|
2136
|
+
|
2137
|
+
unsigned int completeGetQueuedMessages(unsigned int handle,
|
2138
|
+
char *sid,
|
2139
|
+
char *queuedMessages) {
|
2140
|
+
ruleset *tree;
|
2141
|
+
RESOLVE_HANDLE(handle, &tree);
|
2142
|
+
stateNode *state;
|
2143
|
+
CHECK_RESULT(getStateNode(tree,
|
2144
|
+
sid,
|
2145
|
+
&state));
|
2146
|
+
|
2147
|
+
unsigned int stateOffset;
|
2148
|
+
return replayMessages(tree,
|
2149
|
+
queuedMessages,
|
2150
|
+
&stateOffset,
|
2151
|
+
1);
|
2152
|
+
}
|
2153
|
+
|
2123
2154
|
unsigned int startAction(unsigned int handle,
|
2124
2155
|
char **stateFact,
|
2125
2156
|
char **messages,
|
@@ -2133,8 +2164,8 @@ unsigned int startAction(unsigned int handle,
|
|
2133
2164
|
unsigned int resultFrameOffset;
|
2134
2165
|
time_t currentTime = time(NULL);
|
2135
2166
|
|
2136
|
-
CHECK_RESULT(
|
2137
|
-
|
2167
|
+
CHECK_RESULT(startQueuedActions(tree));
|
2168
|
+
|
2138
2169
|
CHECK_RESULT(getNextResult(tree,
|
2139
2170
|
currentTime,
|
2140
2171
|
&resultState,
|
@@ -2152,7 +2183,7 @@ unsigned int startAction(unsigned int handle,
|
|
2152
2183
|
CHECK_RESULT(serializeState(resultState,
|
2153
2184
|
&resultState->context.stateFact));
|
2154
2185
|
|
2155
|
-
|
2186
|
+
|
2156
2187
|
resultState->context.actionStateIndex = actionStateIndex;
|
2157
2188
|
resultState->context.resultCount = resultCount;
|
2158
2189
|
resultState->context.resultFrameOffset = resultFrameOffset;
|
data/src/rules/json.c
CHANGED
@@ -114,7 +114,7 @@ unsigned int readNextString(char *start, char **first, char **last, unsigned int
|
|
114
114
|
|
115
115
|
unsigned int readNextArrayValue(char *start, char **first, char **last, unsigned char *type) {
|
116
116
|
unsigned char state = ST_OBJECT_PROP_PARSE;
|
117
|
-
if (start[0] == '[') {
|
117
|
+
if (start[0] == '[' || start[0] == ',') {
|
118
118
|
state = ST_OBJECT_PROP_VAL;
|
119
119
|
}
|
120
120
|
++start;
|
data/src/rules/rete.c
CHANGED
@@ -1860,8 +1860,6 @@ unsigned int createRuleset(unsigned int *handle, char *name, char *rules) {
|
|
1860
1860
|
tree->queueMessageCallbackContext = NULL;
|
1861
1861
|
tree->getQueuedMessagesCallback = NULL;
|
1862
1862
|
tree->getQueuedMessagesCallbackContext = NULL;
|
1863
|
-
tree->getStoredMessagesCallback = NULL;
|
1864
|
-
tree->getStoredMessagesCallbackContext = NULL;
|
1865
1863
|
tree->getIdleStateCallback = NULL;
|
1866
1864
|
tree->getIdleStateCallbackContext = NULL;
|
1867
1865
|
|
@@ -1939,7 +1937,7 @@ unsigned int setQueueMessageCallback(unsigned int handle,
|
|
1939
1937
|
|
1940
1938
|
unsigned int setGetQueuedMessagesCallback(unsigned int handle,
|
1941
1939
|
void *context,
|
1942
|
-
unsigned int (*callback)(void *, char *, char
|
1940
|
+
unsigned int (*callback)(void *, char *, char *)) {
|
1943
1941
|
ruleset *tree;
|
1944
1942
|
RESOLVE_HANDLE(handle, &tree);
|
1945
1943
|
|
@@ -1948,20 +1946,9 @@ unsigned int setGetQueuedMessagesCallback(unsigned int handle,
|
|
1948
1946
|
return RULES_OK;
|
1949
1947
|
}
|
1950
1948
|
|
1951
|
-
unsigned int setGetStoredMessagesCallback(unsigned int handle,
|
1952
|
-
void *context,
|
1953
|
-
unsigned int (*callback)(void *, char *, char *, char **)) {
|
1954
|
-
ruleset *tree;
|
1955
|
-
RESOLVE_HANDLE(handle, &tree);
|
1956
|
-
|
1957
|
-
tree->getStoredMessagesCallbackContext = context;
|
1958
|
-
tree->getStoredMessagesCallback = callback;
|
1959
|
-
return RULES_OK;
|
1960
|
-
}
|
1961
|
-
|
1962
1949
|
unsigned int setGetIdleStateCallback(unsigned int handle,
|
1963
1950
|
void *context,
|
1964
|
-
unsigned int (*callback)(void *, char
|
1951
|
+
unsigned int (*callback)(void *, char *)) {
|
1965
1952
|
ruleset *tree;
|
1966
1953
|
RESOLVE_HANDLE(handle, &tree);
|
1967
1954
|
|
data/src/rules/rete.h
CHANGED
@@ -157,13 +157,10 @@ typedef struct ruleset {
|
|
157
157
|
unsigned int (*queueMessageCallback)(void *, char *, char *, unsigned char, char *);
|
158
158
|
void *queueMessageCallbackContext;
|
159
159
|
|
160
|
-
unsigned int (*getQueuedMessagesCallback)(void *, char *, char
|
160
|
+
unsigned int (*getQueuedMessagesCallback)(void *, char *, char *);
|
161
161
|
void *getQueuedMessagesCallbackContext;
|
162
162
|
|
163
|
-
unsigned int (*
|
164
|
-
void *getStoredMessagesCallbackContext;
|
165
|
-
|
166
|
-
unsigned int (*getIdleStateCallback)(void *, char *, char **);
|
163
|
+
unsigned int (*getIdleStateCallback)(void *, char *);
|
167
164
|
void *getIdleStateCallbackContext;
|
168
165
|
|
169
166
|
|
data/src/rules/rules.h
CHANGED
@@ -109,9 +109,6 @@ extern char entriesInitialized;
|
|
109
109
|
if (!firstEmptyEntry) firstEmptyEntry = lastEmptyEntry; \
|
110
110
|
} while(0)
|
111
111
|
|
112
|
-
|
113
|
-
unsigned int cloneString(char **target, char *source);
|
114
|
-
|
115
112
|
unsigned int createRuleset(unsigned int *handle,
|
116
113
|
char *name,
|
117
114
|
char *rules);
|
@@ -130,15 +127,19 @@ unsigned int setQueueMessageCallback(unsigned int handle,
|
|
130
127
|
|
131
128
|
unsigned int setGetQueuedMessagesCallback(unsigned int handle,
|
132
129
|
void *context,
|
133
|
-
unsigned int (*callback)(void *, char *, char
|
130
|
+
unsigned int (*callback)(void *, char *, char *));
|
134
131
|
|
135
|
-
unsigned int
|
136
|
-
|
137
|
-
|
132
|
+
unsigned int completeGetQueuedMessages(unsigned int handle,
|
133
|
+
char *sid,
|
134
|
+
char *queuedMessages);
|
138
135
|
|
139
136
|
unsigned int setGetIdleStateCallback(unsigned int handle,
|
140
137
|
void *context,
|
141
|
-
unsigned int (*callback)(void *, char
|
138
|
+
unsigned int (*callback)(void *, char *));
|
139
|
+
|
140
|
+
unsigned int completeGetIdleState(unsigned int handle,
|
141
|
+
char *sid,
|
142
|
+
char *storedMessages);
|
142
143
|
|
143
144
|
unsigned int deleteRuleset(unsigned int handle);
|
144
145
|
|
data/src/rules/state.c
CHANGED
@@ -154,17 +154,6 @@ int asprintf(char** ret, char* format, ...){
|
|
154
154
|
--pool.count; \
|
155
155
|
} while (0)
|
156
156
|
|
157
|
-
unsigned int cloneString(char **target, char *source) {
|
158
|
-
unsigned int length = (strlen(source) + 1) * sizeof(char);
|
159
|
-
*target = malloc(length);
|
160
|
-
if (!*target) {
|
161
|
-
return ERR_OUT_OF_MEMORY;
|
162
|
-
}
|
163
|
-
memcpy(*target, source, length);
|
164
|
-
|
165
|
-
return RULES_OK;
|
166
|
-
}
|
167
|
-
|
168
157
|
unsigned int fnv1Hash32(char *str, unsigned int length) {
|
169
158
|
unsigned int hash = FNV_32_OFFSET_BASIS;
|
170
159
|
for(unsigned int i = 0; i < length; str++, i++) {
|
@@ -750,6 +739,7 @@ unsigned int storeMessage(void *tree,
|
|
750
739
|
char *mid,
|
751
740
|
jsonObject *message,
|
752
741
|
unsigned char messageType,
|
742
|
+
unsigned char sideEffect,
|
753
743
|
unsigned int *valueOffset) {
|
754
744
|
unsigned int hash = fnv1Hash32(mid, strlen(mid));
|
755
745
|
*valueOffset = UNDEFINED_HASH_OFFSET;
|
@@ -787,12 +777,20 @@ unsigned int storeMessage(void *tree,
|
|
787
777
|
CHECK_RESULT(copyMessage(&node->jo, message));
|
788
778
|
|
789
779
|
ruleset *rulesetTree = (ruleset*)tree;
|
790
|
-
if (rulesetTree->storeMessageCallback) {
|
791
|
-
unsigned char actionType
|
792
|
-
|
793
|
-
|
780
|
+
if (sideEffect && rulesetTree->storeMessageCallback) {
|
781
|
+
unsigned char actionType;
|
782
|
+
switch (messageType) {
|
783
|
+
case MESSAGE_TYPE_EVENT:
|
784
|
+
actionType = ACTION_ASSERT_EVENT;
|
785
|
+
break;
|
786
|
+
case MESSAGE_TYPE_FACT:
|
787
|
+
actionType = ACTION_ASSERT_FACT;
|
788
|
+
break;
|
789
|
+
case MESSAGE_TYPE_STATE:
|
790
|
+
actionType = ACTION_UPDATE_STATE;
|
791
|
+
break;
|
794
792
|
}
|
795
|
-
|
793
|
+
|
796
794
|
return rulesetTree->storeMessageCallback(rulesetTree->storeMessageCallbackContext,
|
797
795
|
&rulesetTree->stringPool[rulesetTree->nameOffset],
|
798
796
|
state->sid,
|
data/src/rules/state.h
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
|
10
10
|
#define MESSAGE_TYPE_EVENT 0
|
11
11
|
#define MESSAGE_TYPE_FACT 1
|
12
|
+
#define MESSAGE_TYPE_STATE 2
|
12
13
|
|
13
14
|
#define ACTION_ASSERT_FACT 1
|
14
15
|
#define ACTION_ASSERT_EVENT 2
|
@@ -326,6 +327,7 @@ unsigned int storeMessage(void *tree,
|
|
326
327
|
char *mid,
|
327
328
|
jsonObject *message,
|
328
329
|
unsigned char messageType,
|
330
|
+
unsigned char sideEffect,
|
329
331
|
unsigned int *valueOffset);
|
330
332
|
|
331
333
|
unsigned int getStateNode(void *tree,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: durable_rules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesus Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|