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

Bug/3162 registration destroys compound values #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/app/contextBroker/contextBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ int main(int argC, char* argV[])
paConfig("valid log level strings", validLogLevels);
paConfig("default value", "-logLevel", "WARN");

extern void compoundSaveInit(void);
compoundSaveInit();

//
// If option '-fg' is set, print traces to stdout as well, otherwise, only to file
Expand Down
86 changes: 84 additions & 2 deletions src/lib/ngsi/ContextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,79 @@ using namespace orion;



typedef struct CompoundSave
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If at the end we go with the workaround implemented by this PR, an explanation of the workaround should be included in a comment in the code in order to guide for a definitive solution. The text in the PR body is a good starting point for that.

Issue telefonicaid#3162 would remain open until the definitive solution comes.

{
std::string name;
ContextAttribute* aP;
orion::CompoundValueNode* compoundP;
ContextAttribute* aParentP;
std::string state;
} CompoundSave;

static CompoundSave compoundSaveV[100];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 should be unhardwired to a #define (maybe in this same file, no need to include it in global.h in the case of a workaround)

static int compoundSaveIx = 0;

void compoundSaveInit(void)
{
for (int ix = 0; ix < 100; ix++)
compoundSaveV[ix].state = "unused";
}

#if 0
void compoundSaveReport(void)
{
LM_TMP(("%-20s %-10s %-10s %-10s %s", "name", "attrP", "compoundP", "from Attr", "state"));
for (int ix = 0; ix < compoundSaveIx; ix++)
{
LM_TMP(("%-20s 0x%08x 0x%08x 0x%08x %s",
compoundSaveV[ix].name.c_str(),
compoundSaveV[ix].aP,
compoundSaveV[ix].compoundP,
compoundSaveV[ix].aParentP,
compoundSaveV[ix].state.c_str()));
// if (compoundSaveV[ix].compoundP != NULL)
// {
// delete compoundSaveV[ix].compoundP;
// compoundSaveV[ix].compoundP = NULL;
// }
}
}
#endif

static void compoundSave(ContextAttribute* aP, ContextAttribute* aParentP)
{
CompoundSave* csP = &compoundSaveV[compoundSaveIx];

csP->aP = aP;
csP->name = aP->name;
csP->compoundP = aP->compoundValueP;
csP->aParentP = aParentP;
csP->state = "used";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an enum (instead of plain strings) should be used for states.


++compoundSaveIx;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if this index overpass 100 ?

}

static void compoundUnsave(ContextAttribute* aP)
{
if (aP->compoundValueP != NULL)
{
for (int ix = 0; ix < compoundSaveIx; ix++)
{
if (aP->compoundValueP == compoundSaveV[ix].compoundP)
{
if (compoundSaveV[ix].state == "used")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style:

if ()
{
}

(Pls review the PR, I have seen more of this in other places)

compoundSaveV[ix].state = "usedAndFreed";
else if (compoundSaveV[ix].state == "unused")
compoundSaveV[ix].state = "freedWhenUnused";
else
compoundSaveV[ix].state = "freedWhen-" + compoundSaveV[ix].state;
}
}
}
}



/* ****************************************************************************
*
* ContextAttribute::bsonAppendAttrValue -
Expand Down Expand Up @@ -253,14 +326,22 @@ ContextAttribute::ContextAttribute(ContextAttribute* caP, bool useDefaultType)
stringValue = caP->stringValue;
numberValue = caP->numberValue;
boolValue = caP->boolValue;
compoundValueP = caP->compoundValueP;
caP->compoundValueP = NULL;
found = caP->found;
skip = false;
typeGiven = caP->typeGiven;
onlyValue = caP->onlyValue;
previousValue = NULL;

if (caP->compoundValueP != NULL)
{
compoundValueP = caP->compoundValueP->clone();
compoundSave(this, caP);
}
else
{
compoundValueP = NULL;
}

creDate = caP->creDate;
modDate = caP->modDate;

Expand Down Expand Up @@ -1189,6 +1270,7 @@ void ContextAttribute::present(const std::string& indent, int ix)
*/
void ContextAttribute::release(void)
{
compoundUnsave(this);
if (compoundValueP != NULL)
{
delete compoundValueP;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/rest/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ static void requestCompleted
std::string spath = (ciP->servicePathV.size() > 0)? ciP->servicePathV[0] : "";
struct timespec reqEndTime;

// compoundSaveReport();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this comment is preserved at the end (seems to be a good idea), a FIXME mark citing telefonicaid#3162 should be included in the line above it.


if ((ciP->payload != NULL) && (ciP->payload != static_buffer))
{
free(ciP->payload);
Expand Down
Loading