Skip to content

Commit

Permalink
Merge pull request #921 from fledge-iot/2.1.0RC
Browse files Browse the repository at this point in the history
2.1.0RC
  • Loading branch information
Mohit04tomar authored Jan 4, 2023
2 parents 3132fef + 239aa91 commit bffa41f
Show file tree
Hide file tree
Showing 97 changed files with 3,957 additions and 1,156 deletions.
73 changes: 61 additions & 12 deletions C/common/config_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ string ConfigCategory::getItemAttribute(const string& itemName,
return m_items[i]->m_mandatory;
case FILE_ATTR:
return m_items[i]->m_file;
case VALIDITY_ATTR:
return m_items[i]->m_validity;
case GROUP_ATTR:
return m_items[i]->m_group;
default:
throw new ConfigItemAttributeNotFound();
}
Expand Down Expand Up @@ -514,6 +518,12 @@ bool ConfigCategory::setItemAttribute(const string& itemName,
case LENGTH_ATTR:
m_items[i]->m_length = value;
return true;
case VALIDITY_ATTR:
m_items[i]->m_validity = value;
return true;
case GROUP_ATTR:
m_items[i]->m_group = value;
return true;
default:
return false;
}
Expand Down Expand Up @@ -946,7 +956,7 @@ ConfigCategory::CategoryItem::CategoryItem(const string& name,
m_order = "";
}

if (item.HasMember("length"))
if (item.HasMember("length"))
{
m_length = item["length"].GetString();
}
Expand Down Expand Up @@ -1030,6 +1040,23 @@ ConfigCategory::CategoryItem::CategoryItem(const string& name,
m_displayName = "";
}

if (item.HasMember("validity"))
{
m_validity = item["validity"].GetString();
}
else
{
m_validity = "";
}
if (item.HasMember("group"))
{
m_group = item["group"].GetString();
}
else
{
m_group = "";
}

if (item.HasMember("options"))
{
const Value& options = item["options"];
Expand Down Expand Up @@ -1310,12 +1337,14 @@ ConfigCategory::CategoryItem::CategoryItem(const CategoryItem& rhs)
}
m_file = rhs.m_file;
m_itemType = rhs.m_itemType;
m_validity = rhs.m_validity;
m_group = rhs.m_group;
}

/**
* Create a JSON representation of the configuration item
*
* @param full false is the deafult, true evaluates all the members of the CategoryItem
* @param full false is the default, true evaluates all the members of the CategoryItem
*
*/
string ConfigCategory::CategoryItem::toJSON(const bool full) const
Expand Down Expand Up @@ -1365,7 +1394,7 @@ ostringstream convert;
convert << ", \"order\" : \"" << m_order << "\"";
}

if (!m_length.empty())
if (!m_length.empty())
{
convert << ", \"length\" : \"" << m_length << "\"";
}
Expand All @@ -1385,10 +1414,20 @@ ostringstream convert;
convert << ", \"readonly\" : \"" << m_readonly << "\"";
}

if (!m_mandatory.empty())
{
convert << ", \"mandatory\" : \"" << m_mandatory << "\"";
}
if (!m_mandatory.empty())
{
convert << ", \"mandatory\" : \"" << m_mandatory << "\"";
}

if (!m_validity.empty())
{
convert << ", \"validity\" : \"" << JSONescape(m_validity) << "\"";
}

if (!m_group.empty())
{
convert << ", \"group\" : \"" << m_group << "\"";
}

if (!m_file.empty())
{
Expand Down Expand Up @@ -1432,7 +1471,7 @@ ostringstream convert;
convert << ", \"displayName\" : \"" << m_displayName << "\"";
}

if (!m_length.empty())
if (!m_length.empty())
{
convert << ", \"length\" : \"" << m_length << "\"";
}
Expand All @@ -1452,10 +1491,20 @@ ostringstream convert;
convert << ", \"readonly\" : \"" << m_readonly << "\"";
}

if (!m_mandatory.empty())
{
convert << ", \"mandatory\" : \"" << m_mandatory << "\"";
}
if (!m_mandatory.empty())
{
convert << ", \"mandatory\" : \"" << m_mandatory << "\"";
}

if (!m_validity.empty())
{
convert << ", \"validity\" : \"" << JSONescape(m_validity) << "\"";
}

if (!m_group.empty())
{
convert << ", \"group\" : \"" << m_group << "\"";
}

if (!m_file.empty())
{
Expand Down
3 changes: 3 additions & 0 deletions C/common/include/asset_tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class AssetTrackingTuple {
{}

std::string& getAssetName() { return m_assetName; };
std::string getPluginName() { return m_pluginName;}
std::string getEventName() { return m_eventName;}
std::string getServiceName() { return m_serviceName;}
bool isDeprecated() { return m_deprecated; };
void unDeprecate() { m_deprecated = false; };

Expand Down
6 changes: 5 additions & 1 deletion C/common/include/config_category.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class ConfigCategory {
FILE_ATTR,
MINIMUM_ATTR,
MAXIMUM_ATTR,
LENGTH_ATTR};
LENGTH_ATTR,
VALIDITY_ATTR,
GROUP_ATTR};
std::string getItemAttribute(const std::string& itemName,
ItemAttribute itemAttribute) const;

Expand Down Expand Up @@ -166,6 +168,8 @@ class ConfigCategory {
m_options;
std::string m_file;
ItemType m_itemType;
std::string m_validity;
std::string m_group;
};
std::vector<CategoryItem *> m_items;
std::string m_name;
Expand Down
18 changes: 6 additions & 12 deletions C/common/include/storage_asset_tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,10 @@ namespace std

class ManagementClient;

typedef std::unordered_multiset<StorageAssetTrackingTuple*, std::hash<StorageAssetTrackingTuple*>, StorageAssetTrackingTuplePtrEqual> StorageAssetCacheSet;
typedef std::unordered_map<StorageAssetTrackingTuple*, std::set<std::string>, std::hash<StorageAssetTrackingTuple*>, StorageAssetTrackingTuplePtrEqual> StorageAssetCacheMap;

typedef std::unordered_multiset<StorageAssetTrackingTuple*, std::hash<StorageAssetTrackingTuple*>, StorageAssetTrackingTuplePtrEqual>::iterator StorageAssetCacheSetItr;
typedef std::unordered_map<StorageAssetTrackingTuple*, std::set<std::string>, std::hash<StorageAssetTrackingTuple*>, StorageAssetTrackingTuplePtrEqual>::iterator StorageAssetCacheMapItr;

struct StorageAssetCacheSetItrCmp{

bool operator ()(StorageAssetCacheSetItr x, StorageAssetCacheSetItr y)
{
return x != y;
}

};
/**
* The StorageAssetTracker class provides the asset tracking functionality.
* There are methods to populate asset tracking cache from asset_tracker DB table,
Expand All @@ -112,16 +104,18 @@ class StorageAssetTracker {
bool getFledgeConfigInfo();
static StorageAssetTracker *getStorageAssetTracker();
static void releaseStorageAssetTracker();
int compareDatapoints(const std::string& dp1, const std::string& dp2);
void updateCache(std::set<std::string> dpSet, StorageAssetTrackingTuple* ptr);
bool getDeprecated(StorageAssetTrackingTuple* ptr);

private:
static StorageAssetTracker *instance;
ManagementClient *m_mgtClient;
std::string m_fledgeService;
std::string m_service;
std::string m_event;
std::set<std::string> getDataPointsSet(std::string strDatapoints);

StorageAssetCacheSet storageAssetTrackerTuplesCache;
StorageAssetCacheMap storageAssetTrackerTuplesCache;
};

#endif
35 changes: 23 additions & 12 deletions C/common/include/storage_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <insert.h>
#include <json_properties.h>
#include <expression.h>
#include <update_modifier.h>
#include <logger.h>
#include <string>
#include <vector>
Expand Down Expand Up @@ -48,20 +49,30 @@ class StorageClient {
ResultSet *queryTable(const std::string& tablename, const Query& query);
ReadingSet *queryTableToReadings(const std::string& tableName, const Query& query);
int insertTable(const std::string& schema, const std::string& tableName, const InsertValues& values);
int updateTable(const std::string& schema, const std::string& tableName, const InsertValues& values, const Where& where);
int updateTable(const std::string& schema, const std::string& tableName, const JSONProperties& json, const Where& where);
int updateTable(const std::string& schema, const std::string& tableName, const InsertValues& values, const JSONProperties& json, const Where& where);
int updateTable(const std::string& schema, const std::string& tableName, const ExpressionValues& values, const Where& where);
int updateTable(const std::string& schema, const std::string& tableName, std::vector<std::pair<ExpressionValues *, Where *>>& updates);
int updateTable(const std::string& schema, const std::string& tableName, const InsertValues& values, const ExpressionValues& expressoins, const Where& where);
int updateTable(const std::string& schema, const std::string& tableName, const InsertValues& values,
const Where& where, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& schema, const std::string& tableName, const JSONProperties& json,
const Where& where, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& schema, const std::string& tableName, const InsertValues& values,
const JSONProperties& json, const Where& where, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& schema, const std::string& tableName, const ExpressionValues& values,
const Where& where, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& schema, const std::string& tableName,
std::vector<std::pair<ExpressionValues *, Where *>>& updates, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& schema, const std::string& tableName, const InsertValues& values,
const ExpressionValues& expressoins, const Where& where, const UpdateModifier *modifier = NULL);
int deleteTable(const std::string& schema, const std::string& tableName, const Query& query);
int insertTable(const std::string& tableName, const InsertValues& values);
int updateTable(const std::string& tableName, const InsertValues& values, const Where& where);
int updateTable(const std::string& tableName, const JSONProperties& json, const Where& where);
int updateTable(const std::string& tableName, const InsertValues& values, const JSONProperties& json, const Where& where);
int updateTable(const std::string& tableName, const ExpressionValues& values, const Where& where);
int updateTable(const std::string& tableName, std::vector<std::pair<ExpressionValues *, Where *>>& updates);
int updateTable(const std::string& tableName, const InsertValues& values, const ExpressionValues& expressoins, const Where& where);
int updateTable(const std::string& tableName, const InsertValues& values, const Where& where, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& tableName, const JSONProperties& json, const Where& where, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& tableName, const InsertValues& values, const JSONProperties& json,
const Where& where, const UpdateModifier *modifier = NULL);
int updateTable(const std::string& tableName, const ExpressionValues& values, const Where& where,
const UpdateModifier *modifier = NULL);
int updateTable(const std::string& tableName, std::vector<std::pair<ExpressionValues *, Where *>>& updates,
const UpdateModifier *modifier = NULL);
int updateTable(const std::string& tableName, const InsertValues& values, const ExpressionValues& expressions,
const Where& where, const UpdateModifier *modifier = NULL);
int deleteTable(const std::string& tableName, const Query& query);
bool readingAppend(Reading& reading);
bool readingAppend(const std::vector<Reading *> & readings);
Expand Down
32 changes: 32 additions & 0 deletions C/common/include/update_modifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef _UPDATE_MODIFIER_H
#define _UPDATE_MODIFIER_H
/*
* Fledge storage client.
*
* Copyright (c) 2022 Dianonic Systems
*
* Released under the Apache 2.0 Licence
*
* Author: Mark Riddoch
*/
#include <string>


/**
* Update modifier
*/
class UpdateModifier {
public:
UpdateModifier(const std::string& modifier) :
m_modifier(modifier)
{
};
~UpdateModifier();
const std::string toJSON() const { return m_modifier; };
private:
UpdateModifier(const UpdateModifier&);
UpdateModifier& operator=(UpdateModifier const&);
const std::string m_modifier;
};
#endif

Loading

0 comments on commit bffa41f

Please sign in to comment.