Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDS Copnfig File - first draft #1631

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 89 additions & 85 deletions src/app/orionld/orionld.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/lib/orionld/common/traceLevels.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ typedef enum OrionldTraceLevels
StDds = 201,
StDdsPublish = 202,
StDump = 203,
StDdsDump = 204
StDdsDump = 204,
StDdsConfig = 205
} OrionldTraceLevels;

#endif // SRC_LIB_ORIONLD_COMMON_TRACELEVELS_H_
2 changes: 2 additions & 0 deletions src/lib/orionld/dds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ SET (SOURCES
ddsNotification.cpp
ddsInit.cpp
kjTreeLog.cpp
ddsConfigTopicToAttribute.cpp
ddsConfigLoad.cpp
)

# Include directories
Expand Down
55 changes: 55 additions & 0 deletions src/lib/orionld/dds/ddsConfigLoad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* Copyright 2024 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
*/
extern "C"
{
#include "kbase/kFileRead.h" // kFileRead
#include "kjson/kjson.h" // Kjson
#include "kjson/kjParse.h" // kjParse
#include "ktrace/kTrace.h" // trace messages - ktrace library
}

#include "orionld/dds/ddsConfigLoad.h" // Own interface



KjNode* ddsConfigTree = NULL;
// -----------------------------------------------------------------------------
//
// ddsConfigLoad -
//
int ddsConfigLoad(Kjson* kjP, const char* configFile)
{
char* buf = NULL;
int bufLen = 0;

if (kFileRead((char*) "", (char*) configFile, &buf, &bufLen) != 0)
KT_RE(1, ("Error reading the DDS configuration file"));

ddsConfigTree = kjParse(kjP, buf);
if (ddsConfigTree == NULL)
KT_RE(1, ("Error parsing the DDS configuration file"));

return 0;
}
41 changes: 41 additions & 0 deletions src/lib/orionld/dds/ddsConfigLoad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef SRC_LIB_ORIONLD_DDS_DDSCONFIGLOAD_H_
#define SRC_LIB_ORIONLD_DDS_DDSCONFIGLOAD_H_

/*
*
* Copyright 2024 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
*/
extern "C"
{
#include "kjson/kjson.h" // Kjson
}



// -----------------------------------------------------------------------------
//
// ddsConfigLoad -
//
extern int ddsConfigLoad(Kjson* kjP, const char* configFile);

#endif // SRC_LIB_ORIONLD_DDS_DDSCONFIGLOAD_H_
82 changes: 82 additions & 0 deletions src/lib/orionld/dds/ddsConfigTopicToAttribute.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
*
* Copyright 2024 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
*/
extern "C"
{
#include "kjson/KjNode.h" // KjNode
#include "kjson/kjLookup.h" // kjLookup
#include "ktrace/kTrace.h" // trace messages - ktrace library
}

#include "orionld/common/orionldState.h" // ddsConfigTree
#include "orionld/kjTree/kjNavigate.h" // kjNavigate
#include "orionld/dds/ddsConfigTopicToAttribute.h" // Own interface



// -----------------------------------------------------------------------------
//
// ddsConfigTree - "hidden" external variable
//
// It's the KjNode tree of the DDS config file
//
extern KjNode* ddsConfigTree; // Better not to put this variable in any header file ...



// -----------------------------------------------------------------------------
//
// ddsConfigTopicToAttribute -
//
char* ddsConfigTopicToAttribute(const char* topic, char** entityIdPP, char** entityTypePP)
{
if (ddsConfigTree == NULL)
return NULL; // No error - it's OK to not have a DDS Config File

const char* path[3] = { "dds", "topics", NULL };
static KjNode* topicsP = kjNavigate(ddsConfigTree, path, NULL, NULL);
KjNode* topicP = kjLookup(topicsP, topic);

if (topicP == NULL)
KT_RE(NULL, "topic '%s' not found in DDS config file", topic);

KjNode* attributeP = kjLookup(topicP, "attribute");

if (attributeP == NULL)
KT_RE(NULL, "topic '%s' without 'attribute' member in DDS config file", topic);

if (entityIdPP != NULL)
{
KjNode* entityIdNodeP = kjLookup(topicP, "entityId");
*entityIdPP = (entityIdNodeP != NULL)? entityIdNodeP->value.s : NULL;
}

if (entityTypePP != NULL)
{
KjNode* entityTypeNodeP = kjLookup(topicP, "entityType");
*entityTypePP = (entityTypeNodeP != NULL)? entityTypeNodeP->value.s : NULL;
}

return attributeP->value.s;
}
37 changes: 37 additions & 0 deletions src/lib/orionld/dds/ddsConfigTopicToAttribute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SRC_LIB_ORIONLD_DDS_DDSCONFIGTOPICTOATTRIBUTE_H_
#define SRC_LIB_ORIONLD_DDS_DDSCONFIGTOPICTOATTRIBUTE_H_

/*
*
* Copyright 2024 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
*/



// -----------------------------------------------------------------------------
//
// ddsConfigTopicToAttribute -
//
extern char* ddsConfigTopicToAttribute(const char* topic, char** entityIdPP, char** entityTypePP);

#endif // SRC_LIB_ORIONLD_DDS_DDSCONFIGTOPICTOATTRIBUTE_H_
61 changes: 58 additions & 3 deletions src/lib/orionld/dds/ddsInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@
*
* Author: Ken Zangelin
*/
#include <unistd.h> // access

extern "C"
{
#include "ktrace/kTrace.h" // trace messages - ktrace library
#include "kbase/kStringSplit.h" // kStringSplit
#include "kjson/kjson.h" // Kjson
#include "kjson/KjNode.h" // KjNode
}

#include "orionld/common/orionldState.h" // orionldState, kjTreeLog
#include "orionld/common/traceLevels.h" // kjTreeLog2
#include "orionld/kjTree/kjNavigate.h" // kjNavigate
#include "orionld/dds/ddsSubscribe.h" // ddsSubscribe
#include "orionld/dds/ddsNotification.h" // ddsNotification
#include "orionld/dds/ddsConfigLoad.h" // ddsConfigLoad
#include "orionld/dds/ddsConfigTopicToAttribute.h" // ddsConfigTopicToAttribute - TMP: debugging
#include "orionld/dds/kjTreeLog.h" // kjTreeLog2
#include "orionld/dds/ddsInit.h" // Own interface


Expand All @@ -52,10 +60,57 @@ DdsOperationMode ddsOpMode;
// * ddsSubsTopics
// * mode - the DDS mode the broker is working in
//
int ddsInit(const char* ddsTopicType, char* ddsSubsTopics, DdsOperationMode _ddsOpMode)
int ddsInit(Kjson* kjP, const char* ddsConfigFile, const char* ddsTopicType, char* ddsSubsTopics, DdsOperationMode _ddsOpMode)
{
ddsOpMode = _ddsOpMode;
ddsOpMode = _ddsOpMode; // Not yet in use ... invent usage or remove !

//
// DDS Configuration File
//
errno = 0;
if (access(ddsConfigFile, R_OK) == 0)
{
if (ddsConfigLoad(kjP, ddsConfigFile) != 0)
KT_X(1, "Error reading/parsing the DDS config file '%s'", ddsConfigFile);

#ifdef DEBUG
extern KjNode* ddsConfigTree;
kjTreeLog2(ddsConfigTree, "DDS Config", StDdsConfig);
KT_T(StDdsConfig, "Topics:");
const char* path[3] = { "dds", "topics", NULL };
KjNode* topics = kjNavigate(ddsConfigTree, path , NULL, NULL);

if (topics != NULL)
{
for (KjNode* topicP = topics->value.firstChildP; topicP != NULL; topicP = topicP->next)
{
char* entityId = (char*) "N/A";
char* entityType = (char*) "N/A";
char* attribute = ddsConfigTopicToAttribute(topicP->name, &entityId, &entityType);

KT_T(StDdsConfig, "Topic: '%s':", topicP->name);
KT_T(StDdsConfig, " Attribute: '%s'", attribute);
KT_T(StDdsConfig, " Entity ID: '%s'", entityId);
KT_T(StDdsConfig, " Entity Type: '%s'", entityType);
}
}
#endif
}
// else
// KT_X(1, ("Unable to read the DDS config file '%s' (%s)", ddsConfigFile, strerror(errno));


//
// DDS Subscriptions
//
// For now, the topics to subscribe to is input to the broker, as a CLI parameter with
// the topics as a comma-separated list.
// This is temporary, just to be able to test things.
//
// I imagine in the end, all DDS topics will be found via dicovery and the broker will
// subscribe to all of them. Or, perhaps some filter. We'll see.
// For now, just a CSV.
//
if (ddsSubsTopics[0] == 0)
return 0;

Expand Down
6 changes: 5 additions & 1 deletion src/lib/orionld/dds/ddsInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
*
* Author: Ken Zangelin
*/
extern "C"
{
#include "kjson/kjson.h" // Kjson
}



Expand All @@ -42,6 +46,6 @@ typedef enum DdsOperationMode
//
// ddsInit -
//
extern int ddsInit(const char* ddsTopicType, char* ddsSubsTopics, DdsOperationMode ddsOpMode);
extern int ddsInit(Kjson* kjP, const char* ddsConfigFile, const char* ddsTopicType, char* ddsSubsTopics, DdsOperationMode ddsOpMode);

#endif // SRC_LIB_ORIONLD_DDS_DDSINIT_H_
Loading
Loading