int DSProImpl::updateLearning (const char *pszMessageId, uint8 ui8Usage) { const char *pszMethodName = "DSPro::updateLearning"; if (pszMessageId == NULL) { return -1; } _m.lock (2018); if (0 != _pInfoStore->updateUsage (pszMessageId, ui8Usage)) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "Unable to update 'usage' " "value for message with id = <%s> \n", pszMessageId); _m.unlock (2018); return -2; } MetadataList *pMetadataList = _pInfoStore->getMetadataForData (pszMessageId); if (pMetadataList != NULL) { MetadataInterface *pCurr, *pNext; pNext = pMetadataList->getFirst (); for (unsigned int i = 0; ((pCurr = pNext) != NULL); i++) { pNext = pMetadataList->getNext (); IHMC_C45::C45AVList *pDataset = _pMetadataConf->getMetadataAsDataset (pCurr); if (pDataset == NULL) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "Unable to convert the metadata " "from message with id = <%s> to C45AVList class.\n", pszMessageId); } else { int rc = _pNodeContextMgr->updateClassifier (pDataset); if (rc < 0) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "Unable to use the metadata " "from message with id = <%s> as input for the learning algorithm.\n", pszMessageId); } delete pDataset; } delete pMetadataList->remove (pCurr); } delete pMetadataList; } _m.unlock (2018); return 0; }
int DSProQueryController::doQueryWithPropertyListOnApplicationMetadata (const void *pQuery, unsigned int uiQueryLen, const char *pszQueryQualifiers, PtrLList<const char> *pResultsList) { const char *pszMethodName = "DSProQueryController::doQueryWithPropertyListOnApplicationMetadata"; MetadataList *pMetadataList = getAllMetadata (pszQueryQualifiers); if (pMetadataList == nullptr) { checkAndLogMsg (pszMethodName, Logger::L_Warning, "\n"); return -1; } PropertiesConditionsList *pPropertiesConditionsList = new PropertiesConditionsList(); String query ((char *) pQuery, uiQueryLen); checkAndLogMsg (pszMethodName, Logger::L_Info, "Property conditions list = %s\n", query.c_str()); char *pszTemp = nullptr; char *pszToken = nullptr; pszToken = strtok_mt (query.c_str(), ";", &pszTemp); while (pszToken) { int rc; if ((rc = pPropertiesConditionsList->addNewPropertyCondition (pszToken)) != 0) { checkAndLogMsg (pszMethodName, Logger::L_Warning, "Failed in adding the new property condition\n"); return -2; } pszToken = strtok_mt (nullptr, ";", &pszTemp); } MetadataInterface *pCurr, *pNext; pNext = pMetadataList->getFirst(); for (unsigned int i = 0; (pCurr = pNext) != nullptr; i++) { pNext = pMetadataList->getNext(); char *pszBuffer = nullptr; if (pCurr->getFieldValue (MetadataInterface::APPLICATION_METADATA, (char **) &pszBuffer) == 0 && pszBuffer != nullptr) { matchPropertyListToApplicationMetadata (pszBuffer, pPropertiesConditionsList, pCurr, pResultsList); free (pszBuffer); } delete pMetadataList->remove (pCurr); } delete pMetadataList; return 0; }
int DSProImpl::getData (const char *pszId, const char *pszCallbackParameter, void **ppData, uint32 &ui32DataLen, bool &bHasMoreChunks) { const char *pszMethodName = "DSProImpl::getData"; bHasMoreChunks = false; ui32DataLen = 0; if (pszId == NULL || ppData == NULL || strcmp (pszId, MetaData::NO_REFERRED_OBJECT) == 0) { return -1; } *ppData = NULL; const String grpName (extractGroupFromKey (pszId)); if (grpName.length() <= 0) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "Could not extract group from message id %s.\n", pszId); return -2; } const bool bIsDSProGrp = DisServiceAdaptor::checkGroupName (grpName, DisServiceAdaptor::DSPRO_GROUP_NAME); const bool bIsLargeObject = isOnDemandGroupName (grpName); if (!bIsDSProGrp) { } if (_pDataStore->getData (pszId, ppData, ui32DataLen) < 0) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "Could not read the data from the datacache.\n"); return -3; } _m.lock (2008); if ((*ppData == NULL) || (ui32DataLen == 0)) { // the data has not arrived yet, register the data request if (_userReqs.put (pszId, pszCallbackParameter) == 0) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "data message " "%s not found. Added it to _userReqs\n", pszId); } } MetadataList *pMetadataList = _pInfoStore->getMetadataForData (pszId); if (pMetadataList == NULL) { checkAndLogMsg ("DSPro::getData", Logger::L_Warning, "metadata not " "found for data message with id %s.\n", pszId); } else { for (MetadataInterface *pMetadata = pMetadataList->getFirst(); pMetadata != NULL; pMetadata = pMetadataList->getNext()) { char *pszMetadataId = NULL; if (0 == pMetadata->getFieldValue (pMetadata->MESSAGE_ID, &pszMetadataId) && pszMetadataId != NULL) { updateLearning (pszMetadataId, Classification::Useful); free (pszMetadataId); } delete (pMetadata); } delete pMetadataList; pMetadataList = NULL; } if (*ppData == NULL) { _m.unlock (2008); return 1; } // Copy the returned object void *pDataCpy = NULL; if (bIsLargeObject) { pDataCpy = *ppData; } else { uint32 ui32NewLen = 0; MessageHeaders::MsgType type; pDataCpy = MessageHeaders::removeDSProHeader (*ppData, ui32DataLen, ui32NewLen, type); if (pDataCpy == NULL) { checkAndLogMsg (pszMethodName, memoryExhausted); free (*ppData); _m.unlock (2008); return -5; } ui32DataLen = ui32NewLen; free (*ppData); } *ppData = pDataCpy; _m.unlock (2008); uint8 ui8NChunks, ui8TotChunks; ui8NChunks = ui8TotChunks = 0; if (_pDataStore->getNumberOfReceivedChunks (pszId, ui8NChunks, ui8TotChunks) < 0) { checkAndLogMsg (pszMethodName, Logger::L_Warning, "error when trying " "to check the number of received chunks for message %s\n", pszId); return -6; } checkAndLogMsg (pszMethodName, Logger::L_Info, "getNumberOfReceivedChunks() " "says that %d chunks out of %d have been received\n", ui8NChunks, ui8TotChunks); bHasMoreChunks = (ui8TotChunks > ui8NChunks); return 0; }