/* ****************************************************************************
*
* addContextProviderAttribute -
*
* The limitReached parameter is to prevent the addition of new entities, which is needed in the case of the pagination
* limit has been reached with local entities.
*
*/
void addContextProviderAttribute
(
  ContextElementResponseVector&   cerV,
  EntityId*                       enP,
  ContextRegistrationAttribute*   craP,
  const ProvidingApplication&     pa,
  bool                            limitReached
)
{
  for (unsigned int ix = 0; ix < cerV.size(); ++ix)
  {
    if ((cerV.get(ix)->contextElement.entityId.id != enP->id) ||
        (cerV.get(ix)->contextElement.entityId.type != enP->type))
    {
     continue;
    }

    for (unsigned int jx = 0; jx < cerV.get(ix)->contextElement.contextAttributeVector.size(); ++jx)
    {
      std::string attrName = cerV.get(ix)->contextElement.contextAttributeVector.get(jx)->name;
      if (attrName == craP->name)
      {
        /* In this case, the attribute has been already found in local database. CPr is unnecessary */
        return;
      }
    }
    /* Reached this point, no attribute was found, so adding it with corresponding CPr info */
    ContextAttribute* caP = new ContextAttribute(craP->name, "", "");
    caP->providingApplication = pa;
    cerV.get(ix)->contextElement.contextAttributeVector.push_back(caP);
    return;

  }

  if (!limitReached)
  {
    /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */
    ContextElementResponse* cerP            = new ContextElementResponse();
    cerP->contextElement.entityId.id        = enP->id;
    cerP->contextElement.entityId.type      = enP->type;
    cerP->contextElement.entityId.isPattern = "false";

    cerP->statusCode.fill(SccOk);

    ContextAttribute* caP = new ContextAttribute(craP->name, "", "");
    caP->providingApplication = pa;
    cerP->contextElement.contextAttributeVector.push_back(caP);

    cerV.push_back(cerP);
  }
}
/* ****************************************************************************
*
* fillContextProviders -
*
* Looks in the elements of the CER vector passed as argument, searching for a suitable CPr in the CRR
* vector passed as argument. If a suitable CPr is found, it is added to the CER (and the 'found' field
* is changed to true)
*
*/
void fillContextProviders(ContextElementResponseVector& cerV, ContextRegistrationResponseVector& crrV)
{
  for (unsigned int ix = 0; ix < cerV.size(); ++ix)
  {
    fillContextProviders(cerV.get(ix), crrV);
  }
}
Пример #3
0
/* ****************************************************************************
*
* equalContextElementResponseVector -
*
*/
static bool equalContextElementResponseVector(ContextElementResponseVector cerExpectedV, ContextElementResponseVector cerArgV) {

    /* Check vector size */
    if (cerExpectedV.size() != cerArgV.size()) {
        LM_M(("different sizes: expected %d, actual %d", cerExpectedV.size(), cerArgV.size()));
        return false;
    }

    /* Check that every entity in 'cerArgV' is in 'cerExpectedV'. Order doesn't matter */
    for (unsigned int ix = 0; ix < cerArgV.size(); ++ix) {
        bool entityMatch = false;
        for (unsigned int jx = 0; jx < cerExpectedV.size(); ++jx) {
            ContextElementResponse* cerArg = cerArgV.get(ix);
            ContextElementResponse* cerExpected = cerExpectedV.get(jx);
            LM_M(("%d == %d?", ix, jx));
            if (!equalEntity(cerExpected->contextElement.entityId, cerArg->contextElement.entityId)) {
                LM_M(("entity doesn't match in ContextElementResponseVector comparison, continue..."));
                continue; /* loop in jx */
            }

            /* If there aren't attributes to check, then early exits the loop */
            if (cerExpected->contextElement.contextAttributeVector.size() == 0) {
                LM_M(("entity (without attributes) matches in ContextElementResponseVector comparison, check next one..."));
                entityMatch = true;
                break; /* loop in jx */
            }

            if (equalContextAttributeVector(cerExpected->contextElement.contextAttributeVector, cerArg->contextElement.contextAttributeVector)) {
                LM_M(("entity (with attributes) matches in ContextElementResponseVector comparison, check next one..."));
                entityMatch = true;
                break; /* loop in jx */
            }
        }

        if (!entityMatch) {
            LM_M(("after looking everyone, entity doesn't matches in ContextElementResponseVector comparison"));
            return false;
        }
    }

    LM_M(("ContextElementResponseVector comparison ok"));
    return true;

}
/* ****************************************************************************
*
* someContextElementNotFound -
*
* Returns true if some attribute with 'found' set to 'false' is found in the CER vector passed
* as argument
*
*/
bool someContextElementNotFound(ContextElementResponseVector& cerV)
{
  for (unsigned int ix = 0; ix < cerV.size(); ++ix)
  {
    if (someContextElementNotFound(*cerV.get(ix)))
    {
      return true;
    }
  }
  return false;
}
/* ****************************************************************************
*
* addContextProviderEntity -
*
*/
void addContextProviderEntity(ContextElementResponseVector& cerV, EntityId* enP, ProvidingApplication pa)
{
  for (unsigned int ix = 0; ix < cerV.size(); ++ix)
  {
    if (cerV.get(ix)->contextElement.entityId.id == enP->id && cerV.get(ix)->contextElement.entityId.type == enP->type)
    {
      cerV.get(ix)->contextElement.providingApplicationList.push_back(pa);
      return;    /* by construction, no more than one CER with the same entity information should exist in the CERV) */
    }
  }

  /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */
  ContextElementResponse* cerP            = new ContextElementResponse();
  cerP->contextElement.entityId.id        = enP->id;
  cerP->contextElement.entityId.type      = enP->type;
  cerP->contextElement.entityId.isPattern = "false";
  cerP->contextElement.providingApplicationList.push_back(pa);

  cerP->statusCode.fill(SccOk);
  cerV.push_back(cerP);

}