Skip to content

Commit

Permalink
REMOVE toNgsiv2Subscription() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Aug 9, 2024
1 parent 33f4ba6 commit 55f97a0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 128 deletions.
89 changes: 1 addition & 88 deletions src/lib/ngsi10/SubscribeContextRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,10 @@ std::string SubscribeContextRequest::check(const std::string& predetectedError,
*
* SubscribeContextRequest::release -
*
* Old versions of this method also include a 'restriction.release()' call. However, now each time
* a SubscribeContextRequest is created, the method toNgsiv2Subscription() is used on it and the
* 'ownership' of the Restriction is transferred to the corresponding NGSIv2 class. Thus, leaving
* that 'restriction.release()' would cause double-free problems.
*
* What causes the problem is the following line in SubscribeContextRequest::toNgsiv2Subscription:
*
* sub->restriction = restriction;
*
* After doing this, we have TWO vectors pointing to the same scopes.
*
*/
void SubscribeContextRequest::release(void)
{
restriction.release();
entityIdVector.release();
attributeList.release();
notifyConditionVector.release();
Expand All @@ -109,80 +99,3 @@ void SubscribeContextRequest::fill(EntityTypeInfo typeInfo)
restriction.scopeVector.push_back(scopeP);
}
}


/* ****************************************************************************
*
* SubscribeContextRequest::toNgsiv2Subscription -
*/
void SubscribeContextRequest::toNgsiv2Subscription(Subscription* sub)
{
// Convert entityIdVector
for (unsigned int ix = 0; ix < entityIdVector.size(); ++ix)
{
EntityId* enP = entityIdVector[ix];
EntID en;

if (enP->isPatternIsTrue())
{
en.idPattern = enP->id;
}
else
{
en.id = enP->id;
}
en.type = enP->type;

sub->subject.entities.push_back(en);
}

// Convert attributeList
for (unsigned int ix = 0; ix < attributeList.size(); ++ix)
{
sub->notification.attributes.push_back(attributeList[ix]);
}

// Convert reference
sub->notification.httpInfo.url = reference.get();

// Convert duration
if (duration.isEmpty())
{
sub->expires = DEFAULT_DURATION_IN_SECONDS + getCurrentTime();
}
else
{
sub->expires = duration.parse() + getCurrentTime();
}

// Convert restriction
sub->restriction = restriction;

// Convert notifyConditionVector
for (unsigned int ix = 0; ix < notifyConditionVector.size(); ++ix)
{
NotifyCondition* ncP = notifyConditionVector[ix];
if (ncP->type == ON_CHANGE_CONDITION) // this is just a sanity measure: all types should be ONCHANGE
{
for (unsigned int jx = 0; jx < ncP->condValueList.size(); ++jx)
{
sub->subject.condition.attributes.push_back(ncP->condValueList[jx]);
}
}
}

// Convert throttling
sub->throttling = throttling.parse();

// Note that we don't do anything with 'restrictions': it is not needed by the NGSIv2 logic

// Fill NGSIv2 fields not used in NGSIv1 with default values
// description and expression are not touched, so default empty string provided by constructor will be used
sub->status = STATUS_ACTIVE;
sub->descriptionProvided = false;
sub->attrsFormat = NGSI_V2_NORMALIZED;
sub->notification.blacklist = false;
sub->notification.httpInfo.custom = false;

sub->notification.metadata.clear();
}
1 change: 0 additions & 1 deletion src/lib/ngsi10/SubscribeContextRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ typedef struct SubscribeContextRequest

std::string check(const std::string& predetectedError, int counter);
void release(void);
void toNgsiv2Subscription(ngsiv2::Subscription* sub);

void fill(EntityTypeInfo typeInfo);
} SubscribeContextRequest;
Expand Down
40 changes: 2 additions & 38 deletions src/lib/ngsi10/UpdateContextSubscriptionRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,42 +87,6 @@ std::string UpdateContextSubscriptionRequest::check(const std::string& predetect
*/
void UpdateContextSubscriptionRequest::release(void)
{
// Old versions of this method also include a 'restriction.release()' call. However, now each time
// a UpdateContextSubscriptionRequest is created, the method toNgsiv2Subscription() is used on it and the
// 'ownership' of the Restriction is transferred to the corresponding NGSIv2 class. Thus, leaving
// that 'restriction.release()' would cause double-free problems

restriction.release();
notifyConditionVector.release();
}



/* ****************************************************************************
*
* UpdateContextSubscriptionRequest::toNgsiv2Subscription -
*/
void UpdateContextSubscriptionRequest::toNgsiv2Subscription(SubscriptionUpdate* subUp)
{
// Parent method will do most of the work
SubscribeContextRequest::toNgsiv2Subscription(subUp);

// Fill remaining fields in SubscriptionUpdate
subUp->id = subscriptionId.get();
subUp->fromNgsiv1 = true;

// Fields that can be modified in a NGSIv1 subscription
// (See https://fiware-orion.readthedocs.io/en/master/user/updating_regs_and_subs/index.html)
//
// * notifyConditions (within subject in NGSIv2)
// * throttling (root field in NGSIv2)
// * duration (root field -as 'expires'- in NGSIv2)
// * restriction (already processed in the parent method)

subUp->subjectProvided = (notifyConditionVector.size() > 0);
subUp->expiresProvided = !duration.isEmpty();
subUp->statusProvided = false; // not supported in NGSIv1
subUp->notificationProvided = false; // NGSIv1 doesn's allow changes in that part
subUp->attrsFormatProvided = true; // updating in NGSIv1 involves and implicit change to NGSIv1 legacy format
subUp->throttlingProvided = !throttling.isEmpty();

}
}
1 change: 0 additions & 1 deletion src/lib/ngsi10/UpdateContextSubscriptionRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ struct UpdateContextSubscriptionRequest : public SubscribeContextRequest
UpdateContextSubscriptionRequest();
std::string check(const std::string& predetectedError, int counter);
void release(void);
void toNgsiv2Subscription(ngsiv2::SubscriptionUpdate* subUp);
};

#endif // SRC_LIB_NGSI10_UPDATECONTEXTSUBSCRIPTIONREQUEST_H_

0 comments on commit 55f97a0

Please sign in to comment.