Skip to content

Commit

Permalink
Merge pull request #413 from fledge-iot/main.1.9.1RC
Browse files Browse the repository at this point in the history
1.9.1RC to main
  • Loading branch information
YashTatkondawar authored Jun 3, 2021
2 parents b726089 + 66cb61e commit 5c5340a
Show file tree
Hide file tree
Showing 236 changed files with 19,341 additions and 4,984 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Data / cache files
data/etc/storage.json
data/etc/sqlite.json
data/etc/sqlitelb.json
data/etc/certs/*
data/var
data/support
Expand Down
99 changes: 87 additions & 12 deletions C/common/datapoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::string DatapointValue::toString() const
}

/**
* Delete the DatapointValue alongwith possibly nested Datapoint objects
* Delete the DatapointValue along with possibly nested Datapoint objects
*/
void DatapointValue::deleteNestedDPV()
{
Expand All @@ -103,33 +103,108 @@ void DatapointValue::deleteNestedDPV()
delete m_value.a;
m_value.a = NULL;
}
else if (m_type == T_DP_DICT || m_type == T_DP_LIST)
else if (m_type == T_DP_DICT ||
m_type == T_DP_LIST)
{
for (auto it = m_value.dpa->begin(); // std::vector<Datapoint *>* dpa;
it != m_value.dpa->end();
++it)
{
delete (*it);
if (m_value.dpa) {
for (auto it = m_value.dpa->begin();
it != m_value.dpa->end();
++it)
{
// Call DatapointValue destructor
delete(*it);
}

// Remove vector pointer
delete m_value.dpa;
m_value.dpa = NULL;
}
delete m_value.dpa;
}
}

/**
* DatapointValue class destructor
*/
DatapointValue::~DatapointValue()
{
// Remove memory allocated by datapoints
// along with possibly nested Datapoint objects
deleteNestedDPV();
}

/**
* Copy constructor
*/
DatapointValue::DatapointValue(const DatapointValue& obj)
{
m_type = obj.m_type;
switch (m_type)
{
case T_STRING:
m_value.str = new std::string(*(obj.m_value.str));
break;
case T_FLOAT_ARRAY:
m_value.a = new std::vector<double>(*(obj.m_value.a));
break;
case T_DP_DICT:
case T_DP_LIST:
m_value.dpa = new std::vector<Datapoint*>();
for (auto it = obj.m_value.dpa->begin();
it != obj.m_value.dpa->end();
++it)
{
Datapoint *d = *it;
// Add new allocated datapoint to the vector
// using copy constructor
m_value.dpa->push_back(new Datapoint(*d));
}

break;
default:
m_value = obj.m_value;
break;
}
}

/**
* Assignment Operator
*/
DatapointValue& DatapointValue::operator=(const DatapointValue& rhs)
{
if (m_type == T_STRING)
{
// Remove previous value
delete m_value.str;
m_value.str = NULL;
}
if (m_type == T_FLOAT_ARRAY)
{
// Remove previous value
delete m_value.a;
m_value.a = NULL;
}
// For nested DPV, d'tor is always called from holding Datapoint object's destructor
}
if (m_type == T_DP_DICT || m_type == T_DP_LIST)
{
// Remove previous value
delete m_value.dpa;
}

m_type = rhs.m_type;

switch (m_type)
{
case T_STRING:
m_value.str = new std::string(*(rhs.m_value.str));
break;
case T_FLOAT_ARRAY:
m_value.a = new std::vector<double>(*(rhs.m_value.a));
break;
case T_DP_DICT:
case T_DP_LIST:
m_value.dpa = new std::vector<Datapoint*>(*(rhs.m_value.dpa));
break;
default:
m_value = rhs.m_value;
break;
}

return *this;
}
8 changes: 5 additions & 3 deletions C/common/filter_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ bool FilterPipeline::setupFiltersPipeline(void *passToOnwardFilter, void *useFil

ConfigHandler *configHandler = ConfigHandler::getInstance(mgtClient);
configHandler->registerCategory((ServiceHandler *)ingest, filterCategoryName);
m_serviceHandler = (ServiceHandler *)ingest;

m_filterCategories[filterCategoryName] = (*it);
}
Expand Down Expand Up @@ -346,9 +347,10 @@ void FilterPipeline::cleanupFilters(const string& categoryName)
for (auto it = m_filters.rbegin(); it != m_filters.rend(); ++it)
{
FilterPlugin* filter = *it;
//string filterCategoryName = categoryName + "_" + filter->getName();
//mgtClient->unregisterCategory(filterCategoryName);
//Logger::getLogger()->info("FilterPipeline::cleanupFilters(): unregistered category %s", filterCategoryName.c_str());
string filterCategoryName = categoryName + "_" + filter->getName();
ConfigHandler *configHandler = ConfigHandler::getInstance(mgtClient);
configHandler->unregisterCategory(m_serviceHandler, filterCategoryName);
Logger::getLogger()->info("FilterPipeline::cleanupFilters(): unregistered category %s", filterCategoryName.c_str());

// If plugin has SP_PERSIST_DATA option:
if (filter->m_plugin_data)
Expand Down
82 changes: 20 additions & 62 deletions C/common/include/datapoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,76 +70,18 @@ class DatapointValue {
/**
* Copy constructor
*/
DatapointValue(const DatapointValue& obj)
{
m_type = obj.m_type;
switch (m_type)
{
case T_STRING:
m_value.str = new std::string(*(obj.m_value.str));
break;
case T_FLOAT_ARRAY:
m_value.a = new std::vector<double>(*(obj.m_value.a));
break;
case T_DP_DICT:
case T_DP_LIST:
m_value.dpa = obj.m_value.dpa; // TODO: need to fix this, need to do nested copying in newly allocated memory
break;
default:
m_value = obj.m_value;
break;
}
}
DatapointValue(const DatapointValue& obj);

/**
* Assignment Operator
*/
DatapointValue& operator=(const DatapointValue& rhs)
{
if (m_type == T_STRING)
{
// Remove previous value
delete m_value.str;
}
if (m_type == T_FLOAT_ARRAY)
{
// Remove previous value
delete m_value.a;
}
if (m_type == T_DP_DICT || m_type == T_DP_LIST)
{
// Remove previous value
delete m_value.dpa;
}

m_type = rhs.m_type;
DatapointValue& operator=(const DatapointValue& rhs);

switch (m_type)
{
case T_STRING:
m_value.str = new std::string(*(rhs.m_value.str));
break;
case T_FLOAT_ARRAY:
m_value.a = new std::vector<double>(*(rhs.m_value.a));
break;
case T_DP_DICT:
case T_DP_LIST:
m_value.dpa = new std::vector<Datapoint*>(*(rhs.m_value.dpa));
break;
default:
m_value = rhs.m_value;
break;
}

return *this;
}

/**
* Destructor
*/
~DatapointValue();

void deleteNestedDPV();

/**
* Set the value of a datapoint, this may
Expand Down Expand Up @@ -168,6 +110,11 @@ class DatapointValue {
*/
std::string toString() const;

/**
* Return string value without trailing/leading quotes
*/
std::string toStringValue() const { return *m_value.str; };

/**
* Return long value
*/
Expand Down Expand Up @@ -210,12 +157,24 @@ class DatapointValue {
}
}

/**
* Return array of datapoints
*/
std::vector<Datapoint*>*& getDpVec()
{
return m_value.dpa;
}


/**
* Return array of float
*/
std::vector<double>*& getDpArr()
{
return m_value.a;
}

private:
void deleteNestedDPV();
union data_t {
std::string* str;
long i;
Expand All @@ -241,7 +200,6 @@ class Datapoint {

~Datapoint()
{
m_value.deleteNestedDPV();
}
/**
* Return asset reading data point as a JSON
Expand Down
2 changes: 2 additions & 0 deletions C/common/include/filter_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <plugin_data.h>
#include <reading_set.h>
#include <filter_plugin.h>
#include <service_handler.h>

typedef void (*filterReadingSetFn)(OUTPUT_HANDLE *outHandle, READINGSET* readings);

Expand Down Expand Up @@ -65,6 +66,7 @@ class FilterPipeline
m_filterCategories;
std::string m_pipeline;
bool m_ready;
ServiceHandler *m_serviceHandler;
};

#endif
4 changes: 4 additions & 0 deletions C/common/include/management_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ManagementClient {
bool addAuditEntry(const std::string& serviceName,
const std::string& severity,
const std::string& details);
std::string& getBearerToken() { return m_bearer_token; };

private:
std::ostringstream m_urlbase;
Expand All @@ -59,6 +60,9 @@ class ManagementClient {
std::string *m_uuid;
Logger *m_logger;
std::map<std::string, std::string> m_categories;
// Bearer token returned by service registration
// if the service startup token has been passed in registration payload
std::string m_bearer_token;

public:
// member template must be here and not in .cpp file
Expand Down
4 changes: 3 additions & 1 deletion C/common/include/service_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ServiceRecord : public JSONProvider {
const std::string& protocol,
const std::string& address,
const unsigned short port,
const unsigned short managementPort);
const unsigned short managementPort,
const std::string& token = "");
void asJSON(std::string &) const;
const std::string& getName() const
{
Expand Down Expand Up @@ -72,6 +73,7 @@ class ServiceRecord : public JSONProvider {
std::string m_address;
unsigned short m_port;
unsigned short m_managementPort;
std::string m_token; // token set by core server at service start
};

#endif
13 changes: 12 additions & 1 deletion C/common/include/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@ string StringSlashFix(const string& stringToFix);
std::string evaluateParentPath(const std::string& path, char separator);
std::string extractLastLevel(const std::string& path, char separator);

void StringStripCRLF(std::string& StringToManage);
void StringStripCRLF(std::string& StringToManage);
string StringStripWhiteSpacesAll(const std::string& original);
string StringStripWhiteSpacesExtra(const std::string& original);

string urlEncode(const string& s);
string urlDecode(const string& s);
void StringEscapeQuotes(string& s);

char *trim(char *str);
std::string StringLTrim(const std::string& str);
std::string StringRTrim(const std::string& str);
std::string StringTrim(const std::string& str);

bool IsRegex(const string &str);


#endif
20 changes: 16 additions & 4 deletions C/common/management_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,28 @@ string payload;
doc.Parse(response.c_str());
if (doc.HasParseError())
{
bool httpError = (isdigit(response[0]) && isdigit(response[1]) && isdigit(response[2]) && response[3]==':');
bool httpError = (isdigit(response[0]) &&
isdigit(response[1]) &&
isdigit(response[2]) &&
response[3]==':');
m_logger->error("%s service registration: %s\n",
httpError?"HTTP error during":"Failed to parse result of",
response.c_str());
httpError?"HTTP error during":"Failed to parse result of",
response.c_str());
return false;
}
if (doc.HasMember("id"))
{
m_uuid = new string(doc["id"].GetString());
m_logger->info("Registered service %s.\n", m_uuid->c_str());
m_logger->info("Registered service '%s' with UUID %s.\n",
service.getName().c_str(),
m_uuid->c_str());
if (doc.HasMember("bearer_token")){
m_bearer_token = string(doc["bearer_token"].GetString());
m_logger->debug("Bearer token issued for service '%s': %s",
service.getName().c_str(),
m_bearer_token.c_str());
}

return true;
}
else if (doc.HasMember("message"))
Expand Down
Loading

0 comments on commit 5c5340a

Please sign in to comment.