Skip to content

Commit

Permalink
REFACTOR related with #1298
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Oct 10, 2018
1 parent 068851a commit bd0108c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 65 deletions.
7 changes: 0 additions & 7 deletions src/lib/common/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@
* Macros for JSON rendering
*/
#define JSON_STR(value) std::string("\"" + std::string(value) + "\"")
#define JSON_NUMBER(value) std::string(value)
#define JSON_BOOL(bvalue) std::string((bvalue == true)? "true" : "false")

#define JSON_PROP(name) std::string("\"" + std::string(name) + "\":")
#define JSON_VALUE(name, value) std::string(JSON_PROP(name) + JSON_STR(value))
#define JSON_VALUE_NUMBER(name, value) std::string(JSON_PROP(name) + JSON_NUMBER(value))
#define JSON_VALUE_BOOL(name, value) std::string(JSON_PROP(name) + ((value == true)? "true" : "false"))



Expand Down
5 changes: 0 additions & 5 deletions src/lib/ngsi/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ std::string Metadata::toJsonV1(bool comma)

if (compoundValueP != NULL)
{
// FIXME P8: We need to to this to avoid repeat the "value" keyword. I don't
// understand why (if you look to the similar code in Metadata::toJson(), it
// is not used there). It comes from the old implementation
compoundValueP->container = compoundValueP;

out += JSON_STR("value") + ":" + compoundValueP->toJson(true);
}
else if (valueType == orion::ValueTypeString)
Expand Down
15 changes: 7 additions & 8 deletions src/lib/serviceRoutinesV2/entryPointsTreat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "common/string.h"
#include "common/globals.h"
#include "common/tag.h"
#include "common/JsonHelper.h"

#include "ngsi/ParseData.h"
#include "rest/ConnectionInfo.h"
Expand All @@ -49,15 +50,13 @@ std::string entryPointsTreat
ParseData* parseDataP
)
{
std::string out = "{";
JsonObjectHelper jh;

out += JSON_VALUE("entities_url", ENTITIES_URL) + ",";
out += JSON_VALUE("types_url", TYPES_URL) + ",";
out += JSON_VALUE("subscriptions_url", SUBSCRIPTIONS_URL) + ",";
out += JSON_VALUE("registrations_url", REGISTRATIONS_URL);

out += "}";
jh.addString("entities_url", ENTITIES_URL);
jh.addString("types_url", TYPES_URL);
jh.addString("subscriptions_url", SUBSCRIPTIONS_URL);
jh.addString("registrations_url", REGISTRATIONS_URL);

ciP->httpStatusCode = SccOk;
return out;
return jh.str();
}
65 changes: 20 additions & 45 deletions src/lib/serviceRoutinesV2/semStateTreat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "common/statistics.h"
#include "common/clockFunctions.h"
#include "common/tag.h"
#include "common/JsonHelper.h"

#include "ngsi/ParseData.h"
#include "rest/ConnectionInfo.h"
Expand All @@ -47,21 +48,12 @@
*
* semRender -
*
* NOTE: in the current implementation, 'toplevel' is always false.
* When the operation "GET /admin/sem/<sem-name>" is implemented, 'toplevel' will
* be set to true for the rendering of the response to that request.
*/
static const std::string semRender(const char* name, bool toplevel, const char* state)
static const std::string semRender(const char* state)
{
std::string out;
JsonObjectHelper jh;

if (!toplevel)
{
out = JSON_STR(name) + ":";
}

out += "{";
out += JSON_STR("status") + ":" + JSON_STR(state);
jh.addString("status", state);

//
// FIXME P4 Fill in more fields here in the future (as part of issue #2145):
Expand All @@ -74,10 +66,7 @@ static const std::string semRender(const char* name, bool toplevel, const char*
// "taken": number of taken semaphores (for connectionEndpoints only)
//


out += "}";

return out;
return jh.str();
}


Expand All @@ -94,33 +83,19 @@ std::string semStateTreat
ParseData* parseDataP
)
{
const char* dbConnectionPoolState = mongoConnectionPoolSemGet();
const char* dbConnectionState = mongoConnectionSemGet();
const char* requestState = reqSemGet();
const char* subCacheState = cacheSemGet();
const char* transactionState = transSemGet();
const char* timeStatState = timeStatSemGet();
const char* logMsgState = lmSemGet();
const char* alarmMgrState = alarmMgr.semGet();
const char* connectionContextState = connectionContextSemGet();
const char* connectionSubContextState = connectionSubContextSemGet();
const char* metricsMgrState = metricsMgr.semStateGet();

std::string out = "{";

out += semRender("dbConnectionPool", false, dbConnectionPoolState) + ",";
out += semRender("dbConnection", false, dbConnectionState) + ",";
out += semRender("request", false, requestState) + ",";
out += semRender("subCache", false, subCacheState) + ",";
out += semRender("transaction", false, transactionState) + ",";
out += semRender("timeStat", false, timeStatState) + ",";
out += semRender("logMsg", false, logMsgState) + ",";
out += semRender("alarmMgr", false, alarmMgrState) + ",";
out += semRender("metricsMgr", false, metricsMgrState) + ",";
out += semRender("connectionContext", false, connectionContextState) + ",";
out += semRender("connectionEndpoints", false, connectionSubContextState);

out += "}";

return out;
JsonObjectHelper jh;

jh.addRaw("dbConnectionPool", semRender(mongoConnectionPoolSemGet()));
jh.addRaw("dbConnection", semRender(mongoConnectionSemGet()));
jh.addRaw("request", semRender(reqSemGet()));
jh.addRaw("subCache", semRender(cacheSemGet()));
jh.addRaw("transaction", semRender(transSemGet()));
jh.addRaw("timeStat", semRender(timeStatSemGet()));
jh.addRaw("logMsg", semRender(lmSemGet()));
jh.addRaw("alarmMgr", semRender(alarmMgr.semGet()));
jh.addRaw("metricsMgr", semRender(metricsMgr.semStateGet()));
jh.addRaw("connectionContext", semRender(connectionSubContextSemGet()));
jh.addRaw("connectionEndpoints", semRender(connectionSubContextSemGet()));

return jh.str();
}

0 comments on commit bd0108c

Please sign in to comment.