diff --git a/src/lib/orionld/kjTree/kjTreeToSubscription.cpp b/src/lib/orionld/kjTree/kjTreeToSubscription.cpp index 1d539f5cbd..1af156d43b 100644 --- a/src/lib/orionld/kjTree/kjTreeToSubscription.cpp +++ b/src/lib/orionld/kjTree/kjTreeToSubscription.cpp @@ -256,8 +256,14 @@ bool kjTreeToSubscription(ngsiv2::Subscription* subP, char** subIdPP, KjNode** e } else if (strcmp(kNodeP->name, "timeInterval") == 0) { - orionldError(OrionldBadRequestData, "Not Implemented", "Subscription::timeInterval is not implemented", 501); - return false; + DUPLICATE_CHECK(timeIntervalP, "Subscription::timeInterval", kNodeP); + INTEGER_CHECK(timeIntervalP, "Subscription::timeInterval"); + subP->timeInterval = timeIntervalP->value.i; + if (subP->timeInterval <= 0) + { + orionldError(OrionldBadRequestData, "Invalid value for Subscription::timeInterval", "must be an integer value > 0", 400); + return false; + } } else if ((kNodeP->name[0] == 'q') && (kNodeP->name[1] == 0)) { diff --git a/src/lib/orionld/pernot/CMakeLists.txt b/src/lib/orionld/pernot/CMakeLists.txt index 6d92b4a5b2..304a5e8347 100644 --- a/src/lib/orionld/pernot/CMakeLists.txt +++ b/src/lib/orionld/pernot/CMakeLists.txt @@ -22,6 +22,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.5) SET (SOURCES pernotLoop.cpp + pernotTreat.cpp ) # Include directories diff --git a/src/lib/orionld/pernot/PernotSubCache.h b/src/lib/orionld/pernot/PernotSubCache.h new file mode 100644 index 0000000000..b4a6fd9e2f --- /dev/null +++ b/src/lib/orionld/pernot/PernotSubCache.h @@ -0,0 +1,42 @@ +#ifndef SRC_LIB_ORIONLD_PERNOT_PERNOTSUBCACHE_H_ +#define SRC_LIB_ORIONLD_PERNOT_PERNOTSUBCACHE_H_ + +/* +* +* Copyright 2023 FIWARE Foundation e.V. +* +* This file is part of Orion-LD Context Broker. +* +* Orion-LD Context Broker is free software: you can redistribute it and/or +* modify it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* Orion-LD Context Broker is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +* General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. +* +* For those usages not covered by this license please contact with +* orionld at fiware dot org +* +* Author: Ken Zangelin +*/ +#include "orionld/pernot/PernotSubscription.h" // PernotSubscription + + + +// ----------------------------------------------------------------------------- +// +// PernotSubCache - +// +typedef struct PernotSubCache +{ + PernotSubscription* head; + PernotSubscription* tail; +} PernotSubCache; + +#endif // SRC_LIB_ORIONLD_PERNOT_PERNOTSUBCACHE_H_ diff --git a/src/lib/orionld/pernot/PernotSubscription.h b/src/lib/orionld/pernot/PernotSubscription.h index 4db3c7635d..b1c91e6347 100644 --- a/src/lib/orionld/pernot/PernotSubscription.h +++ b/src/lib/orionld/pernot/PernotSubscription.h @@ -25,6 +25,14 @@ * * Author: Ken Zangelin */ +#include // types: uint64_t, ... +#include // CURL + +extern "C" +{ +#include "kjson/KjNode.h" // KjNode +} + diff --git a/src/lib/orionld/pernot/pernotLoop.cpp b/src/lib/orionld/pernot/pernotLoop.cpp index ff0eb8e019..7e5506db40 100644 --- a/src/lib/orionld/pernot/pernotLoop.cpp +++ b/src/lib/orionld/pernot/pernotLoop.cpp @@ -30,21 +30,16 @@ #include "orionld/common/orionldState.h" // orionldState #include "orionld/pernot/PernotSubscription.h" // PernotSubscription +#include "orionld/pernot/PernotSubCache.h" // PernotSubCache +#include "orionld/pernot/pernotTreat.h" // pernotTreat #include "orionld/pernot/pernotLoop.h" // Own interface // ----------------------------------------------------------------------------- // -// PernotSubCache - move to pernot/PernotSubCache.h +// pernotSubCache - // -typedef struct PernotSubCache -{ - PernotSubscription* head; - PernotSubscription* tail; -} PernotSubCache; - - PernotSubCache pernotSubCache; @@ -104,7 +99,7 @@ static void* pernotLoop(void* vP) continue; if (subP->expiresAt <= now) - subP->state = SubExpired; + subP->state = SubExpired; // Should it be removed? if (subP->state == SubExpired) continue; @@ -143,6 +138,7 @@ static void* pernotLoop(void* vP) +pthread_t pernotThreadID; // ----------------------------------------------------------------------------- // // pernotLoopStart - diff --git a/src/lib/orionld/pernot/pernotLoop.h b/src/lib/orionld/pernot/pernotLoop.h index 6936c2858a..9587f07583 100644 --- a/src/lib/orionld/pernot/pernotLoop.h +++ b/src/lib/orionld/pernot/pernotLoop.h @@ -1,5 +1,5 @@ -#ifndef SRC_LIB_ORIONLD_PERNOT_PERNOTSTART_H_ -#define SRC_LIB_ORIONLD_PERNOT_PERNOTSTART_H_ +#ifndef SRC_LIB_ORIONLD_PERNOT_PERNOTLOOP_H_ +#define SRC_LIB_ORIONLD_PERNOT_PERNOTLOOP_H_ /* * @@ -30,8 +30,8 @@ // ----------------------------------------------------------------------------- // -// pernotStart - +// pernotLoopStart - // -extern void pernotStart(void); +extern void pernotLoopStart(void); -#endif // SRC_LIB_ORIONLD_PERNOT_PERNOTSTART_H_ +#endif // SRC_LIB_ORIONLD_PERNOT_PERNOTLOOP_H_ diff --git a/src/lib/orionld/pernot/pernotTreat.cpp b/src/lib/orionld/pernot/pernotTreat.cpp new file mode 100644 index 0000000000..a126923dab --- /dev/null +++ b/src/lib/orionld/pernot/pernotTreat.cpp @@ -0,0 +1,37 @@ +/* +* +* Copyright 2023 FIWARE Foundation e.V. +* +* This file is part of Orion-LD Context Broker. +* +* Orion-LD Context Broker is free software: you can redistribute it and/or +* modify it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* Orion-LD Context Broker is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +* General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. +* +* For those usages not covered by this license please contact with +* orionld at fiware dot org +* +* Author: Ken Zangelin +*/ +#include "orionld/pernot/PernotSubscription.h" // PernotSubscription +#include "orionld/pernot/pernotTreat.h" // Own interface + + + +// ----------------------------------------------------------------------------- +// +// pernotTreat - +// +bool pernotTreat(PernotSubscription* subP) +{ + return false; +} diff --git a/src/lib/orionld/pernot/pernotTreat.h b/src/lib/orionld/pernot/pernotTreat.h new file mode 100644 index 0000000000..dc43fbe4f1 --- /dev/null +++ b/src/lib/orionld/pernot/pernotTreat.h @@ -0,0 +1,38 @@ +#ifndef SRC_LIB_ORIONLD_PERNOT_PERNOTTREAT_H_ +#define SRC_LIB_ORIONLD_PERNOT_PERNOTTREAT_H_ + +/* +* +* Copyright 2023 FIWARE Foundation e.V. +* +* This file is part of Orion-LD Context Broker. +* +* Orion-LD Context Broker is free software: you can redistribute it and/or +* modify it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* Orion-LD Context Broker is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +* General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. +* +* For those usages not covered by this license please contact with +* orionld at fiware dot org +* +* Author: Ken Zangelin +*/ +#include "orionld/pernot/PernotSubscription.h" // PernotSubscription + + + +// ----------------------------------------------------------------------------- +// +// pernotTreat - +// +extern bool pernotTreat(PernotSubscription* subP); + +#endif // SRC_LIB_ORIONLD_PERNOT_PERNOTTREAT_H_ diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_pernot.test b/test/functionalTest/cases/0000_ngsild/ngsild_pernot.test new file mode 100644 index 0000000000..1ab6bff6b2 --- /dev/null +++ b/test/functionalTest/cases/0000_ngsild/ngsild_pernot.test @@ -0,0 +1,74 @@ +# Copyright 2023 FIWARE Foundation e.V. +# +# This file is part of Orion-LD Context Broker. +# +# Orion-LD Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion-LD Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# orionld at fiware dot org + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Pernot Subscription - periodic notifications + +--SHELL-INIT-- +dbInit CB +orionldStart CB + +--SHELL-- + +# +# 01. Create a subscription urn:S1 with timeInterval +# 02. See urn:S1 in the database +# 03. GET urn:S1 from cache +# 04. GET urn:S1 from database +# 05. Restart broker +# 06. GET urn:S1 from cache +# 07. GET urn:S1 from database +# + +echo "01. Create a subscription urn:S1 with timeInterval" +echo "==================================================" +payload='{ + "id": "urn:S1", + "type": "Subscription", + "entities": [ + { + "type": "T" + } + ], + "timeInterval": 2, + "notification": { + "endpoint": { + "uri": "http://127.0.0.1:'${LISTENER_PORT}'/notify" + } + } +}' +orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload" +echo +echo + + +echo "02. See urn:S1 in the database" +echo "==============================" +mongoCmd2 ftest "db.csubs.findOne()" +echo +echo + + +--REGEXPECT-- +--TEARDOWN-- +brokerStop CB +dbDrop CB