Skip to content

Commit

Permalink
Small step further - commit just to synchronize between computers
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Jul 9, 2023
1 parent 2cfed29 commit 556b200
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/lib/orionld/kjTree/kjTreeToSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/orionld/pernot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

SET (SOURCES
pernotLoop.cpp
pernotTreat.cpp
)

# Include directories
Expand Down
42 changes: 42 additions & 0 deletions src/lib/orionld/pernot/PernotSubCache.h
Original file line number Diff line number Diff line change
@@ -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_
8 changes: 8 additions & 0 deletions src/lib/orionld/pernot/PernotSubscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
*
* Author: Ken Zangelin
*/
#include <stdint.h> // types: uint64_t, ...
#include <curl/curl.h> // CURL

extern "C"
{
#include "kjson/KjNode.h" // KjNode
}




Expand Down
14 changes: 5 additions & 9 deletions src/lib/orionld/pernot/pernotLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -143,6 +138,7 @@ static void* pernotLoop(void* vP)



pthread_t pernotThreadID;
// -----------------------------------------------------------------------------
//
// pernotLoopStart -
Expand Down
10 changes: 5 additions & 5 deletions src/lib/orionld/pernot/pernotLoop.h
Original file line number Diff line number Diff line change
@@ -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_

/*
*
Expand Down Expand Up @@ -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_
37 changes: 37 additions & 0 deletions src/lib/orionld/pernot/pernotTreat.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 38 additions & 0 deletions src/lib/orionld/pernot/pernotTreat.h
Original file line number Diff line number Diff line change
@@ -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_
74 changes: 74 additions & 0 deletions test/functionalTest/cases/0000_ngsild/ngsild_pernot.test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 556b200

Please sign in to comment.