durable_rules 0.34.05 → 0.34.06
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/librb/engine.rb +14 -14
- data/librb/interface.rb +4 -2
- data/src/rules/events.c +29 -56
- data/src/rules/net.c +20 -7
- data/src/rules/rules.h +4 -15
- data/src/rulesrb/rules.c +26 -125
- 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: 298dc30af9fa87b5556c63f3e9053887fdcec4c7
         | 
| 4 | 
            +
              data.tar.gz: 47c61f7ada560539a88ce3dc1166b535c0f70604
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3f753cbf98f4486f7a08d551d32d7509f9a039ba0b2038e808a9d2ece43ba9c0bc7b9f8e3b1b15791998975e701744f6c80d090f951d33b96f239dd1a4afbf3a
         | 
| 7 | 
            +
              data.tar.gz: 946c9b9283724ded8302763689de2d41d333c2dc869742c07e63464a8d3998e6521aae09a5ba70677b2c850fb7bac3691fb983ec58f8deff9652d14d06c1ad75
         | 
    
        data/librb/engine.rb
    CHANGED
    
    | @@ -436,7 +436,7 @@ module Engine | |
| 436 436 | 
             
                end
         | 
| 437 437 |  | 
| 438 438 | 
             
                def start_assert_event(message)
         | 
| 439 | 
            -
                   | 
| 439 | 
            +
                  Rules.start_assert_event @handle, JSON.generate(message)
         | 
| 440 440 | 
             
                end
         | 
| 441 441 |  | 
| 442 442 | 
             
                def assert_events(messages)
         | 
| @@ -444,7 +444,7 @@ module Engine | |
| 444 444 | 
             
                end
         | 
| 445 445 |  | 
| 446 446 | 
             
                def start_assert_events(messages)
         | 
| 447 | 
            -
                   | 
| 447 | 
            +
                  Rules.start_assert_events @handle, JSON.generate(messages)
         | 
| 448 448 | 
             
                end
         | 
| 449 449 |  | 
| 450 450 | 
             
                def start_timer(sid, timer, timer_duration)
         | 
| @@ -464,7 +464,7 @@ module Engine | |
| 464 464 | 
             
                end
         | 
| 465 465 |  | 
| 466 466 | 
             
                def start_assert_fact(fact)
         | 
| 467 | 
            -
                   | 
| 467 | 
            +
                  Rules.start_assert_fact @handle, JSON.generate(fact)
         | 
| 468 468 | 
             
                end
         | 
| 469 469 |  | 
| 470 470 | 
             
                def assert_facts(facts)
         | 
| @@ -472,7 +472,7 @@ module Engine | |
| 472 472 | 
             
                end
         | 
| 473 473 |  | 
| 474 474 | 
             
                def start_assert_facts(facts)
         | 
| 475 | 
            -
                   | 
| 475 | 
            +
                  Rules.start_assert_facts @handle, JSON.generate(facts)
         | 
| 476 476 | 
             
                end
         | 
| 477 477 |  | 
| 478 478 | 
             
                def retract_fact(fact)
         | 
| @@ -484,7 +484,7 @@ module Engine | |
| 484 484 | 
             
                end
         | 
| 485 485 |  | 
| 486 486 | 
             
                def start_retract_fact(fact)
         | 
| 487 | 
            -
                   | 
| 487 | 
            +
                  Rules.start_retract_fact @handle, JSON.generate(fact)
         | 
| 488 488 | 
             
                end
         | 
| 489 489 |  | 
| 490 490 | 
             
                def retract_facts(facts)
         | 
| @@ -492,7 +492,7 @@ module Engine | |
| 492 492 | 
             
                end
         | 
| 493 493 |  | 
| 494 494 | 
             
                def start_retract_facts(facts)
         | 
| 495 | 
            -
                   | 
| 495 | 
            +
                  Rules.start_retract_facts @handle, JSON.generate(facts)
         | 
| 496 496 | 
             
                end
         | 
| 497 497 |  | 
| 498 498 | 
             
                def assert_state(state)
         | 
| @@ -883,9 +883,9 @@ module Engine | |
| 883 883 | 
             
                    started = true
         | 
| 884 884 |  | 
| 885 885 | 
             
                    if parent_name
         | 
| 886 | 
            -
                      rules[parent_name + "$start"] = {:all => [{:chart_context => {:$and => [{:label => parent_name}, {:chart => 1}]}}], run | 
| 886 | 
            +
                      rules[parent_name + "$start"] = {:all => [{:chart_context => {:$and => [{:label => parent_name}, {:chart => 1}]}}], :run => To.new(nil, state_name, false)};
         | 
| 887 887 | 
             
                    else
         | 
| 888 | 
            -
                      rules[:$start] = {:all => [{:chart_context => {:$and => [{:$nex => {:running => 1}}, {:$s => 1}]}}], run | 
| 888 | 
            +
                      rules[:$start] = {:all => [{:chart_context => {:$and => [{:$nex => {:running => 1}}, {:$s => 1}]}}], :run => To.new(nil, state_name, false)};
         | 
| 889 889 | 
             
                    end
         | 
| 890 890 | 
             
                  end
         | 
| 891 891 |  | 
| @@ -1123,7 +1123,7 @@ module Engine | |
| 1123 1123 | 
             
                end
         | 
| 1124 1124 |  | 
| 1125 1125 | 
             
                def start_post_batch(ruleset_name, *events)
         | 
| 1126 | 
            -
                   | 
| 1126 | 
            +
                  get_ruleset(ruleset_name).start_assert_events events
         | 
| 1127 1127 | 
             
                end
         | 
| 1128 1128 |  | 
| 1129 1129 | 
             
                def post(ruleset_name, event)
         | 
| @@ -1131,7 +1131,7 @@ module Engine | |
| 1131 1131 | 
             
                end
         | 
| 1132 1132 |  | 
| 1133 1133 | 
             
                def start_post(ruleset_name, event)
         | 
| 1134 | 
            -
                   | 
| 1134 | 
            +
                  get_ruleset(ruleset_name).start_assert_event event
         | 
| 1135 1135 | 
             
                end
         | 
| 1136 1136 |  | 
| 1137 1137 | 
             
                def assert(ruleset_name, fact)
         | 
| @@ -1139,7 +1139,7 @@ module Engine | |
| 1139 1139 | 
             
                end
         | 
| 1140 1140 |  | 
| 1141 1141 | 
             
                def start_assert(ruleset_name, fact)
         | 
| 1142 | 
            -
                   | 
| 1142 | 
            +
                  get_ruleset(ruleset_name).start_assert_fact fact
         | 
| 1143 1143 | 
             
                end
         | 
| 1144 1144 |  | 
| 1145 1145 | 
             
                def assert_facts(ruleset_name, *facts)
         | 
| @@ -1147,7 +1147,7 @@ module Engine | |
| 1147 1147 | 
             
                end
         | 
| 1148 1148 |  | 
| 1149 1149 | 
             
                def start_assert_facts(ruleset_name, *facts)
         | 
| 1150 | 
            -
                   | 
| 1150 | 
            +
                  get_ruleset(ruleset_name).start_assert_facts facts
         | 
| 1151 1151 | 
             
                end
         | 
| 1152 1152 |  | 
| 1153 1153 | 
             
                def retract(ruleset_name, fact)
         | 
| @@ -1155,7 +1155,7 @@ module Engine | |
| 1155 1155 | 
             
                end
         | 
| 1156 1156 |  | 
| 1157 1157 | 
             
                def start_retract(ruleset_name, fact)
         | 
| 1158 | 
            -
                   | 
| 1158 | 
            +
                  get_ruleset(ruleset_name).start_retract_fact fact
         | 
| 1159 1159 | 
             
                end
         | 
| 1160 1160 |  | 
| 1161 1161 | 
             
                def retract_facts(ruleset_name, *facts)
         | 
| @@ -1163,7 +1163,7 @@ module Engine | |
| 1163 1163 | 
             
                end
         | 
| 1164 1164 |  | 
| 1165 1165 | 
             
                def start_retract_facts(ruleset_name, *facts)
         | 
| 1166 | 
            -
                   | 
| 1166 | 
            +
                  get_ruleset(ruleset_name).start_retract_facts facts
         | 
| 1167 1167 | 
             
                end
         | 
| 1168 1168 |  | 
| 1169 1169 | 
             
                def patch_state(ruleset_name, state)
         | 
    
        data/librb/interface.rb
    CHANGED
    
    | @@ -23,7 +23,8 @@ module Interface | |
| 23 23 | 
             
                    request.body.rewind
         | 
| 24 24 | 
             
                    message = JSON.parse request.body.read
         | 
| 25 25 | 
             
                    message["sid"] = params["sid"]
         | 
| 26 | 
            -
                    @@host.post | 
| 26 | 
            +
                    result = @@host.post(params["ruleset_name"], message)
         | 
| 27 | 
            +
                    JSON.generate({:outcome => result})
         | 
| 27 28 | 
             
                  rescue Exception => e
         | 
| 28 29 | 
             
                    status 500
         | 
| 29 30 | 
             
                    e.to_s
         | 
| @@ -35,7 +36,8 @@ module Interface | |
| 35 36 | 
             
                    request.body.rewind
         | 
| 36 37 | 
             
                    state = JSON.parse request.body.read
         | 
| 37 38 | 
             
                    state["id"] = params["sid"]
         | 
| 38 | 
            -
                    @@host.patch_state | 
| 39 | 
            +
                    result = @@host.patch_state(params["ruleset_name"], state)
         | 
| 40 | 
            +
                    JSON.generate({:outcome => result})
         | 
| 39 41 | 
             
                  rescue Exception => e
         | 
| 40 42 | 
             
                    status 500
         | 
| 41 43 | 
             
                    e.to_s
         | 
    
        data/src/rules/events.c
    CHANGED
    
    | @@ -1293,18 +1293,9 @@ static unsigned int handleMessages(void *handle, | |
| 1293 1293 | 
             
                                               char *messages, 
         | 
| 1294 1294 | 
             
                                               char **commands,
         | 
| 1295 1295 | 
             
                                               unsigned int *commandCount,
         | 
| 1296 | 
            -
                                               unsigned int *resultsLength,  
         | 
| 1297 | 
            -
                                               unsigned int **results,
         | 
| 1298 1296 | 
             
                                               void **rulesBinding) {
         | 
| 1299 | 
            -
                unsigned int messagesLength = 64;
         | 
| 1300 | 
            -
                unsigned int *resultsArray = malloc(sizeof(unsigned int) * messagesLength);
         | 
| 1301 | 
            -
                if (!resultsArray) {
         | 
| 1302 | 
            -
                    return ERR_OUT_OF_MEMORY;
         | 
| 1303 | 
            -
                }
         | 
| 1304 | 
            -
             | 
| 1305 | 
            -
                *results = resultsArray;
         | 
| 1306 | 
            -
                *resultsLength = 0;
         | 
| 1307 1297 | 
             
                unsigned int result;
         | 
| 1298 | 
            +
                unsigned int returnResult = RULES_OK;
         | 
| 1308 1299 | 
             
                jsonProperty properties[MAX_EVENT_PROPERTIES];
         | 
| 1309 1300 | 
             
                unsigned int propertiesLength = 0;
         | 
| 1310 1301 | 
             
                unsigned int propertiesMidIndex = UNDEFINED_INDEX;
         | 
| @@ -1348,21 +1339,13 @@ static unsigned int handleMessages(void *handle, | |
| 1348 1339 |  | 
| 1349 1340 | 
             
                    *last = lastTemp;
         | 
| 1350 1341 | 
             
                    if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED) {
         | 
| 1351 | 
            -
                        free(resultsArray);
         | 
| 1352 1342 | 
             
                        return result;
         | 
| 1353 1343 | 
             
                    }
         | 
| 1354 1344 |  | 
| 1355 | 
            -
                    if ( | 
| 1356 | 
            -
                         | 
| 1357 | 
            -
                        resultsArray = realloc(resultsArray, sizeof(unsigned int) * messagesLength);
         | 
| 1358 | 
            -
                        if (!resultsArray) {
         | 
| 1359 | 
            -
                            return ERR_OUT_OF_MEMORY;
         | 
| 1360 | 
            -
                        }
         | 
| 1361 | 
            -
                        *results = resultsArray;
         | 
| 1345 | 
            +
                    if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 1346 | 
            +
                        returnResult = ERR_EVENT_NOT_HANDLED;
         | 
| 1362 1347 | 
             
                    }
         | 
| 1363 1348 |  | 
| 1364 | 
            -
                    resultsArray[*resultsLength] = result;
         | 
| 1365 | 
            -
                    ++*resultsLength;
         | 
| 1366 1349 | 
             
                    propertiesLength = 0;
         | 
| 1367 1350 | 
             
                    propertiesMidIndex = UNDEFINED_INDEX;
         | 
| 1368 1351 | 
             
                    propertiesSidIndex = UNDEFINED_INDEX;        
         | 
| @@ -1373,7 +1356,7 @@ static unsigned int handleMessages(void *handle, | |
| 1373 1356 | 
             
                    }
         | 
| 1374 1357 | 
             
                }
         | 
| 1375 1358 |  | 
| 1376 | 
            -
                return  | 
| 1359 | 
            +
                return returnResult;
         | 
| 1377 1360 | 
             
            }
         | 
| 1378 1361 |  | 
| 1379 1362 | 
             
            static unsigned int handleState(ruleset *tree, 
         | 
| @@ -1523,8 +1506,6 @@ static unsigned int executeHandleMessage(void *handle, | |
| 1523 1506 | 
             
            static unsigned int startHandleMessages(void *handle, 
         | 
| 1524 1507 | 
             
                                                    char *messages, 
         | 
| 1525 1508 | 
             
                                                    unsigned char actionType,
         | 
| 1526 | 
            -
                                                    unsigned int *resultsLength, 
         | 
| 1527 | 
            -
                                                    unsigned int **results,
         | 
| 1528 1509 | 
             
                                                    void **rulesBinding,
         | 
| 1529 1510 | 
             
                                                    unsigned int *replyCount) {
         | 
| 1530 1511 | 
             
                char *commands[MAX_COMMAND_COUNT];
         | 
| @@ -1534,8 +1515,6 @@ static unsigned int startHandleMessages(void *handle, | |
| 1534 1515 | 
             
                                                     messages,
         | 
| 1535 1516 | 
             
                                                     commands,
         | 
| 1536 1517 | 
             
                                                     &commandCount,
         | 
| 1537 | 
            -
                                                     resultsLength,
         | 
| 1538 | 
            -
                                                     results,
         | 
| 1539 1518 | 
             
                                                     rulesBinding);
         | 
| 1540 1519 | 
             
                if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED) {
         | 
| 1541 1520 | 
             
                    freeCommands(commands, commandCount);
         | 
| @@ -1552,9 +1531,7 @@ static unsigned int startHandleMessages(void *handle, | |
| 1552 1531 |  | 
| 1553 1532 | 
             
            static unsigned int executeHandleMessages(void *handle, 
         | 
| 1554 1533 | 
             
                                                      char *messages, 
         | 
| 1555 | 
            -
                                                      unsigned char actionType | 
| 1556 | 
            -
                                                      unsigned int *resultsLength, 
         | 
| 1557 | 
            -
                                                      unsigned int **results) {
         | 
| 1534 | 
            +
                                                      unsigned char actionType) {
         | 
| 1558 1535 | 
             
                char *commands[MAX_COMMAND_COUNT];
         | 
| 1559 1536 | 
             
                unsigned int commandCount = 0;
         | 
| 1560 1537 | 
             
                void *rulesBinding = NULL;
         | 
| @@ -1563,8 +1540,6 @@ static unsigned int executeHandleMessages(void *handle, | |
| 1563 1540 | 
             
                                                     messages,
         | 
| 1564 1541 | 
             
                                                     commands,
         | 
| 1565 1542 | 
             
                                                     &commandCount,
         | 
| 1566 | 
            -
                                                     resultsLength,
         | 
| 1567 | 
            -
                                                     results,
         | 
| 1568 1543 | 
             
                                                     &rulesBinding);
         | 
| 1569 1544 | 
             
                if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED) {
         | 
| 1570 1545 | 
             
                    freeCommands(commands, commandCount);
         | 
| @@ -1580,7 +1555,12 @@ static unsigned int executeHandleMessages(void *handle, | |
| 1580 1555 | 
             
            }
         | 
| 1581 1556 |  | 
| 1582 1557 | 
             
            unsigned int complete(void *rulesBinding, unsigned int replyCount) {
         | 
| 1583 | 
            -
                 | 
| 1558 | 
            +
                unsigned int result = completeNonBlockingBatch(rulesBinding, replyCount);
         | 
| 1559 | 
            +
                if (result != RULES_OK && result != ERR_EVENT_OBSERVED) {
         | 
| 1560 | 
            +
                    return result;
         | 
| 1561 | 
            +
                }
         | 
| 1562 | 
            +
             | 
| 1563 | 
            +
                return RULES_OK;
         | 
| 1584 1564 | 
             
            }
         | 
| 1585 1565 |  | 
| 1586 1566 | 
             
            unsigned int assertEvent(void *handle, char *message) {
         | 
| @@ -1595,19 +1575,15 @@ unsigned int startAssertEvent(void *handle, | |
| 1595 1575 | 
             
            }
         | 
| 1596 1576 |  | 
| 1597 1577 | 
             
            unsigned int assertEvents(void *handle, 
         | 
| 1598 | 
            -
                                      char *messages | 
| 1599 | 
            -
             | 
| 1600 | 
            -
                                      unsigned int **results) {
         | 
| 1601 | 
            -
                return executeHandleMessages(handle, messages, ACTION_ASSERT_EVENT, resultsLength, results);
         | 
| 1578 | 
            +
                                      char *messages) {
         | 
| 1579 | 
            +
                return executeHandleMessages(handle, messages, ACTION_ASSERT_EVENT);
         | 
| 1602 1580 | 
             
            }
         | 
| 1603 1581 |  | 
| 1604 1582 | 
             
            unsigned int startAssertEvents(void *handle, 
         | 
| 1605 1583 | 
             
                                          char *messages, 
         | 
| 1606 | 
            -
                                          unsigned int *resultsLength, 
         | 
| 1607 | 
            -
                                          unsigned int **results, 
         | 
| 1608 1584 | 
             
                                          void **rulesBinding, 
         | 
| 1609 1585 | 
             
                                          unsigned int *replyCount) {
         | 
| 1610 | 
            -
                return startHandleMessages(handle, messages, ACTION_ASSERT_EVENT,  | 
| 1586 | 
            +
                return startHandleMessages(handle, messages, ACTION_ASSERT_EVENT, rulesBinding, replyCount);
         | 
| 1611 1587 | 
             
            }
         | 
| 1612 1588 |  | 
| 1613 1589 | 
             
            unsigned int retractEvent(void *handle, char *message) {
         | 
| @@ -1627,18 +1603,14 @@ unsigned int assertFact(void *handle, char *message) { | |
| 1627 1603 |  | 
| 1628 1604 | 
             
            unsigned int startAssertFacts(void *handle, 
         | 
| 1629 1605 | 
             
                                          char *messages, 
         | 
| 1630 | 
            -
                                          unsigned int *resultsLength, 
         | 
| 1631 | 
            -
                                          unsigned int **results, 
         | 
| 1632 1606 | 
             
                                         void **rulesBinding, 
         | 
| 1633 1607 | 
             
                                         unsigned int *replyCount) {
         | 
| 1634 | 
            -
                return startHandleMessages(handle, messages, ACTION_ASSERT_FACT,  | 
| 1608 | 
            +
                return startHandleMessages(handle, messages, ACTION_ASSERT_FACT, rulesBinding, replyCount);
         | 
| 1635 1609 | 
             
            }
         | 
| 1636 1610 |  | 
| 1637 1611 | 
             
            unsigned int assertFacts(void *handle, 
         | 
| 1638 | 
            -
                                      char *messages | 
| 1639 | 
            -
             | 
| 1640 | 
            -
                                      unsigned int **results) {
         | 
| 1641 | 
            -
                return executeHandleMessages(handle, messages, ACTION_ASSERT_FACT, resultsLength, results);
         | 
| 1612 | 
            +
                                      char *messages) {
         | 
| 1613 | 
            +
                return executeHandleMessages(handle, messages, ACTION_ASSERT_FACT);
         | 
| 1642 1614 | 
             
            }
         | 
| 1643 1615 |  | 
| 1644 1616 | 
             
            unsigned int retractFact(void *handle, char *message) {
         | 
| @@ -1653,19 +1625,15 @@ unsigned int startRetractFact(void *handle, | |
| 1653 1625 | 
             
            }
         | 
| 1654 1626 |  | 
| 1655 1627 | 
             
            unsigned int retractFacts(void *handle, 
         | 
| 1656 | 
            -
                                      char *messages | 
| 1657 | 
            -
             | 
| 1658 | 
            -
                                      unsigned int **results) {
         | 
| 1659 | 
            -
                return executeHandleMessages(handle, messages, ACTION_REMOVE_FACT, resultsLength, results);
         | 
| 1628 | 
            +
                                      char *messages) {
         | 
| 1629 | 
            +
                return executeHandleMessages(handle, messages, ACTION_REMOVE_FACT);
         | 
| 1660 1630 | 
             
            }
         | 
| 1661 1631 |  | 
| 1662 1632 | 
             
            unsigned int startRetractFacts(void *handle, 
         | 
| 1663 1633 | 
             
                                          char *messages, 
         | 
| 1664 | 
            -
                                          unsigned int *resultsLength, 
         | 
| 1665 | 
            -
                                          unsigned int **results, 
         | 
| 1666 1634 | 
             
                                          void **rulesBinding, 
         | 
| 1667 1635 | 
             
                                          unsigned int *replyCount) {
         | 
| 1668 | 
            -
                return startHandleMessages(handle, messages, ACTION_REMOVE_FACT,  | 
| 1636 | 
            +
                return startHandleMessages(handle, messages, ACTION_REMOVE_FACT, rulesBinding, replyCount);
         | 
| 1669 1637 | 
             
            }
         | 
| 1670 1638 |  | 
| 1671 1639 | 
             
            unsigned int assertState(void *handle, char *state) {
         | 
| @@ -1703,7 +1671,12 @@ unsigned int assertTimers(void *handle) { | |
| 1703 1671 | 
             
                    return result;
         | 
| 1704 1672 | 
             
                }
         | 
| 1705 1673 |  | 
| 1706 | 
            -
                 | 
| 1674 | 
            +
                result = executeBatch(rulesBinding, commands, commandCount);
         | 
| 1675 | 
            +
                if (result != RULES_OK && result != ERR_EVENT_OBSERVED) {
         | 
| 1676 | 
            +
                    return result;
         | 
| 1677 | 
            +
                }
         | 
| 1678 | 
            +
             | 
| 1679 | 
            +
                return RULES_OK;
         | 
| 1707 1680 | 
             
            }
         | 
| 1708 1681 |  | 
| 1709 1682 | 
             
            unsigned int startAction(void *handle, 
         | 
| @@ -1786,14 +1759,14 @@ unsigned int completeAction(void *handle, | |
| 1786 1759 | 
             
                }
         | 
| 1787 1760 |  | 
| 1788 1761 | 
             
                result = executeBatch(rulesBinding, commands, commandCount); 
         | 
| 1789 | 
            -
                if (result != RULES_OK) {
         | 
| 1762 | 
            +
                if (result != RULES_OK && result != ERR_EVENT_OBSERVED) {
         | 
| 1790 1763 | 
             
                    //reply object should be freed by the app during abandonAction
         | 
| 1791 1764 | 
             
                    return result;
         | 
| 1792 1765 | 
             
                }
         | 
| 1793 1766 |  | 
| 1794 1767 | 
             
                freeReplyObject(reply);
         | 
| 1795 1768 | 
             
                free(actionHandle);
         | 
| 1796 | 
            -
                return  | 
| 1769 | 
            +
                return RULES_OK;
         | 
| 1797 1770 | 
             
            }
         | 
| 1798 1771 |  | 
| 1799 1772 | 
             
            unsigned int completeAndStartAction(void *handle, 
         | 
| @@ -1837,7 +1810,7 @@ unsigned int completeAndStartAction(void *handle, | |
| 1837 1810 | 
             
                                               commands, 
         | 
| 1838 1811 | 
             
                                               commandCount, 
         | 
| 1839 1812 | 
             
                                               &newReply);  
         | 
| 1840 | 
            -
                if (result != RULES_OK) {
         | 
| 1813 | 
            +
                if (result != RULES_OK && result != ERR_EVENT_OBSERVED) {
         | 
| 1841 1814 | 
             
                    //reply object should be freed by the app during abandonAction
         | 
| 1842 1815 | 
             
                    return result;
         | 
| 1843 1816 | 
             
                }
         | 
    
        data/src/rules/net.c
    CHANGED
    
    | @@ -667,11 +667,11 @@ static unsigned int loadAddMessageCommand(ruleset *tree, binding *rulesBinding) | |
| 667 667 | 
             
            "if redis.call(\"hsetnx\", visited_hashset, message[\"id\"], 1) == 0 then\n"
         | 
| 668 668 | 
             
            "    if assert_fact == 0 then\n"
         | 
| 669 669 | 
             
            "        if not redis.call(\"hget\", events_hashset, mid) then\n"
         | 
| 670 | 
            -
            "            return  | 
| 670 | 
            +
            "            return %d\n"
         | 
| 671 671 | 
             
            "        end\n"
         | 
| 672 672 | 
             
            "    else\n"
         | 
| 673 673 | 
             
            "        if not redis.call(\"hget\", facts_hashset, mid) then\n"
         | 
| 674 | 
            -
            "            return  | 
| 674 | 
            +
            "            return %d\n"
         | 
| 675 675 | 
             
            "        end\n"
         | 
| 676 676 | 
             
            "    end\n"
         | 
| 677 677 | 
             
            "end\n"
         | 
| @@ -692,7 +692,9 @@ static unsigned int loadAddMessageCommand(ruleset *tree, binding *rulesBinding) | |
| 692 692 | 
             
            "end\n",
         | 
| 693 693 | 
             
                            name,
         | 
| 694 694 | 
             
                            name,
         | 
| 695 | 
            -
                            name, | 
| 695 | 
            +
                            name,
         | 
| 696 | 
            +
                            ERR_EVENT_OBSERVED,
         | 
| 697 | 
            +
                            ERR_EVENT_OBSERVED,
         | 
| 696 698 | 
             
                            addMessageLua)  == -1) {
         | 
| 697 699 | 
             
                    return ERR_OUT_OF_MEMORY;
         | 
| 698 700 | 
             
                }
         | 
| @@ -1988,11 +1990,11 @@ static unsigned int loadEvalMessageCommand(ruleset *tree, binding *rulesBinding) | |
| 1988 1990 | 
             
            "if redis.call(\"hsetnx\", visited_hashset, mid, 1) == 0 then\n"
         | 
| 1989 1991 | 
             
            "    if assert_fact == 0 then\n"
         | 
| 1990 1992 | 
             
            "        if message and redis.call(\"hexists\", events_hashset, mid) == 0 then\n"
         | 
| 1991 | 
            -
            "            return  | 
| 1993 | 
            +
            "            return %d\n"
         | 
| 1992 1994 | 
             
            "        end\n"
         | 
| 1993 1995 | 
             
            "    else\n"
         | 
| 1994 1996 | 
             
            "        if message and redis.call(\"hexists\", facts_hashset, mid) == 0 then\n"
         | 
| 1995 | 
            -
            "            return  | 
| 1997 | 
            +
            "            return %d\n"
         | 
| 1996 1998 | 
             
            "        end\n"
         | 
| 1997 1999 | 
             
            "    end\n"
         | 
| 1998 2000 | 
             
            "end\n"
         | 
| @@ -2025,13 +2027,14 @@ static unsigned int loadEvalMessageCommand(ruleset *tree, binding *rulesBinding) | |
| 2025 2027 | 
             
            "    if not redis.call(\"zscore\", actions_key, sid) then\n"
         | 
| 2026 2028 | 
             
            "        redis.call(\"zadd\", actions_key , score, sid)\n"
         | 
| 2027 2029 | 
             
            "    end\n"
         | 
| 2028 | 
            -
            "end\n"
         | 
| 2029 | 
            -
            "return nil\n",
         | 
| 2030 | 
            +
            "end\n",
         | 
| 2030 2031 | 
             
                             name,
         | 
| 2031 2032 | 
             
                             name,
         | 
| 2032 2033 | 
             
                             name,
         | 
| 2033 2034 | 
             
                             name,
         | 
| 2034 2035 | 
             
                             name,
         | 
| 2036 | 
            +
                             ERR_EVENT_OBSERVED,
         | 
| 2037 | 
            +
                             ERR_EVENT_OBSERVED,
         | 
| 2035 2038 | 
             
                             lua)  == -1) {
         | 
| 2036 2039 | 
             
                    return ERR_OUT_OF_MEMORY;
         | 
| 2037 2040 | 
             
                }
         | 
| @@ -2662,6 +2665,10 @@ unsigned int completeNonBlockingBatch(void *rulesBinding, | |
| 2662 2665 | 
             
                        if (reply->type == REDIS_REPLY_ERROR) {
         | 
| 2663 2666 | 
             
                            printf("complete non blocking batch error %d %s\n", i, reply->str);
         | 
| 2664 2667 | 
             
                            result = ERR_REDIS_ERROR;
         | 
| 2668 | 
            +
                        } else if (reply->type == REDIS_REPLY_INTEGER) {
         | 
| 2669 | 
            +
                            if (reply->integer == ERR_EVENT_OBSERVED && result == RULES_OK) {
         | 
| 2670 | 
            +
                                result = ERR_EVENT_OBSERVED;
         | 
| 2671 | 
            +
                            }
         | 
| 2665 2672 | 
             
                        }
         | 
| 2666 2673 |  | 
| 2667 2674 | 
             
                        freeReplyObject(reply);    
         | 
| @@ -2725,6 +2732,12 @@ unsigned int executeBatchWithReply(void *rulesBinding, | |
| 2725 2732 |  | 
| 2726 2733 | 
             
                                *lastReply = reply;
         | 
| 2727 2734 | 
             
                            }
         | 
| 2735 | 
            +
                        } else if (reply->type == REDIS_REPLY_INTEGER) {
         | 
| 2736 | 
            +
                            if (reply->integer == ERR_EVENT_OBSERVED && result == RULES_OK) {
         | 
| 2737 | 
            +
                                result = ERR_EVENT_OBSERVED;
         | 
| 2738 | 
            +
                            }
         | 
| 2739 | 
            +
             | 
| 2740 | 
            +
                            freeReplyObject(reply);
         | 
| 2728 2741 | 
             
                        } else {
         | 
| 2729 2742 | 
             
                            freeReplyObject(reply);    
         | 
| 2730 2743 | 
             
                        }
         | 
    
        data/src/rules/rules.h
    CHANGED
    
    | @@ -26,6 +26,7 @@ | |
| 26 26 | 
             
            #define ERR_MAX_COMMAND_COUNT 209
         | 
| 27 27 | 
             
            #define ERR_MAX_ADD_COUNT 210
         | 
| 28 28 | 
             
            #define ERR_MAX_EVAL_COUNT 211
         | 
| 29 | 
            +
            #define ERR_EVENT_OBSERVED 212
         | 
| 29 30 | 
             
            #define ERR_CONNECT_REDIS 301
         | 
| 30 31 | 
             
            #define ERR_REDIS_ERROR 302
         | 
| 31 32 | 
             
            #define ERR_NO_ACTION_AVAILABLE 303
         | 
| @@ -81,14 +82,10 @@ unsigned int startAssertEvent(void *handle, | |
| 81 82 | 
             
                                         unsigned int *replyCount);
         | 
| 82 83 |  | 
| 83 84 | 
             
            unsigned int assertEvents(void *handle, 
         | 
| 84 | 
            -
                                      char *messages | 
| 85 | 
            -
                                      unsigned int *resultsLength, 
         | 
| 86 | 
            -
                                      unsigned int **results);
         | 
| 85 | 
            +
                                      char *messages);
         | 
| 87 86 |  | 
| 88 87 | 
             
            unsigned int startAssertEvents(void *handle, 
         | 
| 89 88 | 
             
                                          char *messages, 
         | 
| 90 | 
            -
                                          unsigned int *resultsLength, 
         | 
| 91 | 
            -
                                          unsigned int **results, 
         | 
| 92 89 | 
             
                                          void **rulesBinding, 
         | 
| 93 90 | 
             
                                          unsigned int *replyCount);
         | 
| 94 91 |  | 
| @@ -105,15 +102,11 @@ unsigned int assertFact(void *handle, | |
| 105 102 |  | 
| 106 103 | 
             
            unsigned int startAssertFacts(void *handle, 
         | 
| 107 104 | 
             
                                          char *messages, 
         | 
| 108 | 
            -
                                          unsigned int *resultsLength, 
         | 
| 109 | 
            -
                                          unsigned int **results, 
         | 
| 110 105 | 
             
                                          void **rulesBinding, 
         | 
| 111 106 | 
             
                                          unsigned int *replyCount);
         | 
| 112 107 |  | 
| 113 108 | 
             
            unsigned int assertFacts(void *handle, 
         | 
| 114 | 
            -
                                     char *messages | 
| 115 | 
            -
                                     unsigned int *resultsLength, 
         | 
| 116 | 
            -
                                     unsigned int **results);
         | 
| 109 | 
            +
                                     char *messages);
         | 
| 117 110 |  | 
| 118 111 | 
             
            unsigned int retractFact(void *handle, 
         | 
| 119 112 | 
             
                                     char *message);
         | 
| @@ -124,14 +117,10 @@ unsigned int startRetractFact(void *handle, | |
| 124 117 | 
             
                                         unsigned int *replyCount);
         | 
| 125 118 |  | 
| 126 119 | 
             
            unsigned int retractFacts(void *handle, 
         | 
| 127 | 
            -
                                      char *messages | 
| 128 | 
            -
                                      unsigned int *resultsLength, 
         | 
| 129 | 
            -
                                      unsigned int **results);
         | 
| 120 | 
            +
                                      char *messages);
         | 
| 130 121 |  | 
| 131 122 | 
             
            unsigned int startRetractFacts(void *handle, 
         | 
| 132 123 | 
             
                                          char *messages, 
         | 
| 133 | 
            -
                                          unsigned int *resultsLength, 
         | 
| 134 | 
            -
                                          unsigned int **results, 
         | 
| 135 124 | 
             
                                          void **rulesBinding, 
         | 
| 136 125 | 
             
                                          unsigned int *replyCount);
         | 
| 137 126 |  | 
    
        data/src/rulesrb/rules.c
    CHANGED
    
    | @@ -115,16 +115,11 @@ static VALUE rbStartAssertEvent(VALUE self, VALUE handle, VALUE event) { | |
| 115 115 | 
             
                unsigned int replyCount;
         | 
| 116 116 | 
             
                void *rulesBinding = NULL;
         | 
| 117 117 | 
             
                unsigned int result = startAssertEvent((void *)FIX2LONG(handle), RSTRING_PTR(event), &rulesBinding, &replyCount);
         | 
| 118 | 
            -
                if (result == RULES_OK) {
         | 
| 118 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
         | 
| 119 119 | 
             
                    VALUE output = rb_ary_new(); 
         | 
| 120 120 | 
             
                    rb_ary_push(output, INT2FIX(rulesBinding));
         | 
| 121 121 | 
             
                    rb_ary_push(output, INT2FIX(replyCount));
         | 
| 122 122 | 
             
                    return output;  
         | 
| 123 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 124 | 
            -
                    VALUE output = rb_ary_new(); 
         | 
| 125 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 126 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 127 | 
            -
                    return output; 
         | 
| 128 123 | 
             
                } else {
         | 
| 129 124 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 130 125 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -141,10 +136,8 @@ static VALUE rbAssertEvent(VALUE self, VALUE handle, VALUE event) { | |
| 141 136 | 
             
                Check_Type(event, T_STRING);
         | 
| 142 137 |  | 
| 143 138 | 
             
                unsigned int result = assertEvent((void *)FIX2LONG(handle), RSTRING_PTR(event));
         | 
| 144 | 
            -
                if (result == RULES_OK) {
         | 
| 145 | 
            -
                    return INT2FIX( | 
| 146 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 147 | 
            -
                    return INT2FIX(0);    
         | 
| 139 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED || result == ERR_EVENT_OBSERVED) {
         | 
| 140 | 
            +
                    return INT2FIX(result);    
         | 
| 148 141 | 
             
                } else {
         | 
| 149 142 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 150 143 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -178,31 +171,18 @@ static VALUE rbStartAssertEvents(VALUE self, VALUE handle, VALUE events) { | |
| 178 171 | 
             
                Check_Type(handle, T_FIXNUM);
         | 
| 179 172 | 
             
                Check_Type(events, T_STRING);
         | 
| 180 173 |  | 
| 181 | 
            -
                unsigned int *results = NULL;
         | 
| 182 | 
            -
                unsigned int resultsLength = 0;
         | 
| 183 174 | 
             
                unsigned int replyCount;
         | 
| 184 175 | 
             
                void *rulesBinding = NULL;
         | 
| 185 | 
            -
                unsigned int result = startAssertEvents((void *)FIX2LONG(handle), RSTRING_PTR(events), & | 
| 186 | 
            -
                if (result == RULES_OK) {
         | 
| 187 | 
            -
                    if (results) {
         | 
| 188 | 
            -
                        free(results);
         | 
| 189 | 
            -
                    }
         | 
| 176 | 
            +
                unsigned int result = startAssertEvents((void *)FIX2LONG(handle), RSTRING_PTR(events), &rulesBinding, &replyCount);
         | 
| 177 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
         | 
| 190 178 | 
             
                    VALUE output = rb_ary_new(); 
         | 
| 191 179 | 
             
                    rb_ary_push(output, INT2FIX(rulesBinding));
         | 
| 192 180 | 
             
                    rb_ary_push(output, INT2FIX(replyCount));
         | 
| 193 181 | 
             
                    return output;  
         | 
| 194 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 195 | 
            -
                    VALUE output = rb_ary_new(); 
         | 
| 196 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 197 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 198 | 
            -
                    return output; 
         | 
| 199 182 | 
             
                } else {
         | 
| 200 183 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 201 184 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| 202 185 | 
             
                    } else { 
         | 
| 203 | 
            -
                        if (results) {
         | 
| 204 | 
            -
                            free(results);
         | 
| 205 | 
            -
                        }
         | 
| 206 186 | 
             
                        rb_raise(rb_eException, "Could not assert events, error code: %d", result);
         | 
| 207 187 | 
             
                    }
         | 
| 208 188 | 
             
                }
         | 
| @@ -214,21 +194,11 @@ static VALUE rbAssertEvents(VALUE self, VALUE handle, VALUE events) { | |
| 214 194 | 
             
                Check_Type(handle, T_FIXNUM);
         | 
| 215 195 | 
             
                Check_Type(events, T_STRING);
         | 
| 216 196 |  | 
| 217 | 
            -
                unsigned int  | 
| 218 | 
            -
                 | 
| 219 | 
            -
                unsigned int result = assertEvents((void *)FIX2LONG(handle), RSTRING_PTR(events), &resultsLength, &results);
         | 
| 220 | 
            -
                if (result == RULES_OK) {
         | 
| 221 | 
            -
                    if (results) {
         | 
| 222 | 
            -
                        free(results);
         | 
| 223 | 
            -
                    }
         | 
| 224 | 
            -
                    return INT2FIX(resultsLength);   
         | 
| 225 | 
            -
                } else {
         | 
| 197 | 
            +
                unsigned int result = assertEvents((void *)FIX2LONG(handle), RSTRING_PTR(events));
         | 
| 198 | 
            +
                if (result != RULES_OK) {
         | 
| 226 199 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 227 200 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| 228 201 | 
             
                    } else { 
         | 
| 229 | 
            -
                        if (results) {
         | 
| 230 | 
            -
                            free(results);
         | 
| 231 | 
            -
                        }
         | 
| 232 202 | 
             
                        rb_raise(rb_eException, "Could not assert events, error code: %d", result);
         | 
| 233 203 | 
             
                    }
         | 
| 234 204 | 
             
                }
         | 
| @@ -241,10 +211,8 @@ static VALUE rbRetractEvent(VALUE self, VALUE handle, VALUE event) { | |
| 241 211 | 
             
                Check_Type(event, T_STRING);
         | 
| 242 212 |  | 
| 243 213 | 
             
                unsigned int result = retractEvent((void *)FIX2LONG(handle), RSTRING_PTR(event));
         | 
| 244 | 
            -
                if (result == RULES_OK) {
         | 
| 245 | 
            -
                    return INT2FIX( | 
| 246 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 247 | 
            -
                    return INT2FIX(0);    
         | 
| 214 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED || result == ERR_EVENT_OBSERVED) {
         | 
| 215 | 
            +
                    return INT2FIX(result);    
         | 
| 248 216 | 
             
                } else {
         | 
| 249 217 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 250 218 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -263,16 +231,11 @@ static VALUE rbStartAssertFact(VALUE self, VALUE handle, VALUE fact) { | |
| 263 231 | 
             
                unsigned int replyCount;
         | 
| 264 232 | 
             
                void *rulesBinding = NULL;
         | 
| 265 233 | 
             
                unsigned int result = startAssertFact((void *)FIX2LONG(handle), RSTRING_PTR(fact), &rulesBinding, &replyCount);
         | 
| 266 | 
            -
                if (result == RULES_OK) {
         | 
| 234 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
         | 
| 267 235 | 
             
                    VALUE output = rb_ary_new(); 
         | 
| 268 236 | 
             
                    rb_ary_push(output, INT2FIX(rulesBinding));
         | 
| 269 237 | 
             
                    rb_ary_push(output, INT2FIX(replyCount));
         | 
| 270 238 | 
             
                    return output;  
         | 
| 271 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 272 | 
            -
                    VALUE output = rb_ary_new(); 
         | 
| 273 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 274 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 275 | 
            -
                    return output; 
         | 
| 276 239 | 
             
                } else {
         | 
| 277 240 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 278 241 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -289,10 +252,8 @@ static VALUE rbAssertFact(VALUE self, VALUE handle, VALUE fact) { | |
| 289 252 | 
             
                Check_Type(fact, T_STRING);
         | 
| 290 253 |  | 
| 291 254 | 
             
                unsigned int result = assertFact((void *)FIX2LONG(handle), RSTRING_PTR(fact));
         | 
| 292 | 
            -
                if (result == RULES_OK) {
         | 
| 293 | 
            -
                    return INT2FIX( | 
| 294 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 295 | 
            -
                    return INT2FIX(0);    
         | 
| 255 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED || result == ERR_EVENT_OBSERVED) {
         | 
| 256 | 
            +
                    return INT2FIX(result);    
         | 
| 296 257 | 
             
                } else {
         | 
| 297 258 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 298 259 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -326,31 +287,18 @@ static VALUE rbStartAssertFacts(VALUE self, VALUE handle, VALUE facts) { | |
| 326 287 | 
             
                Check_Type(handle, T_FIXNUM);
         | 
| 327 288 | 
             
                Check_Type(facts, T_STRING);
         | 
| 328 289 |  | 
| 329 | 
            -
                unsigned int *results = NULL;
         | 
| 330 | 
            -
                unsigned int resultsLength = 0;
         | 
| 331 290 | 
             
                unsigned int replyCount;
         | 
| 332 291 | 
             
                void *rulesBinding = NULL;
         | 
| 333 | 
            -
                unsigned int result = startAssertFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts), & | 
| 334 | 
            -
                if (result == RULES_OK) {
         | 
| 335 | 
            -
                    if (results) {
         | 
| 336 | 
            -
                        free(results);
         | 
| 337 | 
            -
                    }
         | 
| 292 | 
            +
                unsigned int result = startAssertFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts), &rulesBinding, &replyCount);
         | 
| 293 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
         | 
| 338 294 | 
             
                    VALUE output = rb_ary_new(); 
         | 
| 339 295 | 
             
                    rb_ary_push(output, INT2FIX(rulesBinding));
         | 
| 340 296 | 
             
                    rb_ary_push(output, INT2FIX(replyCount));
         | 
| 341 297 | 
             
                    return output;  
         | 
| 342 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 343 | 
            -
                    VALUE output = rb_ary_new(); 
         | 
| 344 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 345 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 346 | 
            -
                    return output; 
         | 
| 347 298 | 
             
                } else {
         | 
| 348 299 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 349 300 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| 350 301 | 
             
                    } else { 
         | 
| 351 | 
            -
                        if (results) {
         | 
| 352 | 
            -
                            free(results);
         | 
| 353 | 
            -
                        }
         | 
| 354 302 | 
             
                        rb_raise(rb_eException, "Could not assert facts, error code: %d", result);
         | 
| 355 303 | 
             
                    }
         | 
| 356 304 | 
             
                }
         | 
| @@ -362,21 +310,11 @@ static VALUE rbAssertFacts(VALUE self, VALUE handle, VALUE facts) { | |
| 362 310 | 
             
                Check_Type(handle, T_FIXNUM);
         | 
| 363 311 | 
             
                Check_Type(facts, T_STRING);
         | 
| 364 312 |  | 
| 365 | 
            -
                unsigned int  | 
| 366 | 
            -
                 | 
| 367 | 
            -
                unsigned int result = assertFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts), &resultsLength, &results);
         | 
| 368 | 
            -
                if (result == RULES_OK) {
         | 
| 369 | 
            -
                    if (results) {
         | 
| 370 | 
            -
                        free(results);
         | 
| 371 | 
            -
                    }
         | 
| 372 | 
            -
                    return INT2FIX(resultsLength);   
         | 
| 373 | 
            -
                } else {
         | 
| 313 | 
            +
                unsigned int result = assertFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts));
         | 
| 314 | 
            +
                if (result != RULES_OK) {
         | 
| 374 315 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 375 316 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| 376 317 | 
             
                    } else { 
         | 
| 377 | 
            -
                        if (results) {
         | 
| 378 | 
            -
                            free(results);
         | 
| 379 | 
            -
                        }
         | 
| 380 318 | 
             
                        rb_raise(rb_eException, "Could not assert facts, error code: %d", result);
         | 
| 381 319 | 
             
                    }
         | 
| 382 320 | 
             
                }
         | 
| @@ -391,16 +329,11 @@ static VALUE rbStartRetractFact(VALUE self, VALUE handle, VALUE fact) { | |
| 391 329 | 
             
                unsigned int replyCount;
         | 
| 392 330 | 
             
                void *rulesBinding = NULL;
         | 
| 393 331 | 
             
                unsigned int result = startRetractFact((void *)FIX2LONG(handle), RSTRING_PTR(fact), &rulesBinding, &replyCount);
         | 
| 394 | 
            -
                if (result == RULES_OK) {
         | 
| 332 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
         | 
| 395 333 | 
             
                    VALUE output = rb_ary_new(); 
         | 
| 396 334 | 
             
                    rb_ary_push(output, INT2FIX(rulesBinding));
         | 
| 397 335 | 
             
                    rb_ary_push(output, INT2FIX(replyCount));
         | 
| 398 336 | 
             
                    return output;  
         | 
| 399 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 400 | 
            -
                    VALUE output = rb_ary_new(); 
         | 
| 401 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 402 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 403 | 
            -
                    return output; 
         | 
| 404 337 | 
             
                } else {
         | 
| 405 338 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 406 339 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -417,10 +350,8 @@ static VALUE rbRetractFact(VALUE self, VALUE handle, VALUE fact) { | |
| 417 350 | 
             
                Check_Type(fact, T_STRING);
         | 
| 418 351 |  | 
| 419 352 | 
             
                unsigned int result = retractFact((void *)FIX2LONG(handle), RSTRING_PTR(fact));
         | 
| 420 | 
            -
                if (result == RULES_OK) {
         | 
| 421 | 
            -
                    return INT2FIX( | 
| 422 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 423 | 
            -
                    return INT2FIX(0);    
         | 
| 353 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED || result == ERR_EVENT_OBSERVED) {
         | 
| 354 | 
            +
                    return INT2FIX(result);    
         | 
| 424 355 | 
             
                } else {
         | 
| 425 356 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 426 357 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -454,31 +385,18 @@ static VALUE rbStartRetractFacts(VALUE self, VALUE handle, VALUE facts) { | |
| 454 385 | 
             
                Check_Type(handle, T_FIXNUM);
         | 
| 455 386 | 
             
                Check_Type(facts, T_STRING);
         | 
| 456 387 |  | 
| 457 | 
            -
                unsigned int *results = NULL;
         | 
| 458 | 
            -
                unsigned int resultsLength = 0;
         | 
| 459 388 | 
             
                unsigned int replyCount;
         | 
| 460 389 | 
             
                void *rulesBinding = NULL;
         | 
| 461 | 
            -
                unsigned int result = startRetractFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts), & | 
| 462 | 
            -
                if (result == RULES_OK) {
         | 
| 463 | 
            -
                    if (results) {
         | 
| 464 | 
            -
                        free(results);
         | 
| 465 | 
            -
                    }
         | 
| 390 | 
            +
                unsigned int result = startRetractFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts), &rulesBinding, &replyCount);
         | 
| 391 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
         | 
| 466 392 | 
             
                    VALUE output = rb_ary_new(); 
         | 
| 467 393 | 
             
                    rb_ary_push(output, INT2FIX(rulesBinding));
         | 
| 468 394 | 
             
                    rb_ary_push(output, INT2FIX(replyCount));
         | 
| 469 395 | 
             
                    return output;  
         | 
| 470 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 471 | 
            -
                    VALUE output = rb_ary_new(); 
         | 
| 472 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 473 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 474 | 
            -
                    return output; 
         | 
| 475 396 | 
             
                } else {
         | 
| 476 397 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 477 398 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| 478 399 | 
             
                    } else { 
         | 
| 479 | 
            -
                        if (results) {
         | 
| 480 | 
            -
                            free(results);
         | 
| 481 | 
            -
                        }
         | 
| 482 400 | 
             
                        rb_raise(rb_eException, "Could not retract facts, error code: %d", result);
         | 
| 483 401 | 
             
                    }
         | 
| 484 402 | 
             
                }
         | 
| @@ -490,21 +408,11 @@ static VALUE rbRetractFacts(VALUE self, VALUE handle, VALUE facts) { | |
| 490 408 | 
             
                Check_Type(handle, T_FIXNUM);
         | 
| 491 409 | 
             
                Check_Type(facts, T_STRING);
         | 
| 492 410 |  | 
| 493 | 
            -
                unsigned int  | 
| 494 | 
            -
                 | 
| 495 | 
            -
                unsigned int result = retractFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts), &resultsLength, &results);
         | 
| 496 | 
            -
                if (result == RULES_OK) {
         | 
| 497 | 
            -
                    if (results) {
         | 
| 498 | 
            -
                        free(results);
         | 
| 499 | 
            -
                    }
         | 
| 500 | 
            -
                    return INT2FIX(resultsLength);   
         | 
| 501 | 
            -
                } else {
         | 
| 411 | 
            +
                unsigned int result = retractFacts((void *)FIX2LONG(handle), RSTRING_PTR(facts));
         | 
| 412 | 
            +
                if (result != RULES_OK) {
         | 
| 502 413 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 503 414 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| 504 415 | 
             
                    } else { 
         | 
| 505 | 
            -
                        if (results) {
         | 
| 506 | 
            -
                            free(results);
         | 
| 507 | 
            -
                        }
         | 
| 508 416 | 
             
                        rb_raise(rb_eException, "Could not retract facts, error code: %d", result);
         | 
| 509 417 | 
             
                    }
         | 
| 510 418 | 
             
                }
         | 
| @@ -517,10 +425,8 @@ static VALUE rbAssertState(VALUE self, VALUE handle, VALUE state) { | |
| 517 425 | 
             
                Check_Type(state, T_STRING);
         | 
| 518 426 |  | 
| 519 427 | 
             
                unsigned int result = assertState((void *)FIX2LONG(handle), RSTRING_PTR(state));
         | 
| 520 | 
            -
                if (result == RULES_OK) {
         | 
| 521 | 
            -
                    return INT2FIX( | 
| 522 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 523 | 
            -
                    return INT2FIX(0);    
         | 
| 428 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED || result == ERR_EVENT_OBSERVED) {
         | 
| 429 | 
            +
                    return INT2FIX(result);    
         | 
| 524 430 | 
             
                } else {
         | 
| 525 431 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 526 432 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
| @@ -540,16 +446,11 @@ static VALUE rbStartUpdateState(VALUE self, VALUE handle, VALUE actionHandle, VA | |
| 540 446 | 
             
                unsigned int replyCount;
         | 
| 541 447 | 
             
                void *rulesBinding = NULL;
         | 
| 542 448 | 
             
                unsigned int result = startUpdateState((void *)FIX2LONG(handle), (void *)FIX2LONG(actionHandle), RSTRING_PTR(state), &rulesBinding, &replyCount);
         | 
| 543 | 
            -
                if (result == RULES_OK) {
         | 
| 449 | 
            +
                if (result == RULES_OK || result == ERR_EVENT_NOT_HANDLED) {
         | 
| 544 450 | 
             
                    VALUE output = rb_ary_new(); 
         | 
| 545 451 | 
             
                    rb_ary_push(output, INT2FIX(rulesBinding));
         | 
| 546 452 | 
             
                    rb_ary_push(output, INT2FIX(replyCount));
         | 
| 547 453 | 
             
                    return output;  
         | 
| 548 | 
            -
                } else if (result == ERR_EVENT_NOT_HANDLED) {
         | 
| 549 | 
            -
                    VALUE output = rb_ary_new(); 
         | 
| 550 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 551 | 
            -
                    rb_ary_push(output, INT2FIX(0));
         | 
| 552 | 
            -
                    return output;   
         | 
| 553 454 | 
             
                } else {
         | 
| 554 455 | 
             
                    if (result == ERR_OUT_OF_MEMORY) {
         | 
| 555 456 | 
             
                        rb_raise(rb_eNoMemError, "Out of memory");
         | 
    
        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: 0.34. | 
| 4 | 
            +
              version: 0.34.06
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jesus Ruiz
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-08-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rake
         |