bool UpnpScheduledRecording::setAttributesRequest(const RCSResourceAttributes &value, UpnpRequest *request, const map< string, string > &queryParams) { bool status = false; for (auto it = value.begin(); it != value.end(); ++it) { const std::string attrName = it->key(); DEBUG_PRINT(" \"" << attrName << "\""); // Check the request if (!UpnpAttribute::isValidRequest(&m_attributeMap, attrName, UPNP_ACTION_POST)) { request->done++; continue; } RCSResourceAttributes::Value attrValue = it->value(); UpnpAttributeInfo *attrInfo = m_attributeMap[attrName].first; bool result = UpnpAttribute::set(m_proxy, request, attrInfo, &attrValue); status |= result; if (!result) { request->done++; } } return status; }
void SensorResource::onCacheUpdated(const RCSResourceAttributes &attrs) { cout << "----UPDATED---- State: " << attrs.at(SensorServer::IS_ON_ATTR).toString() << "-----------" << endl; isOn = attrs.at(SensorServer::IS_ON_ATTR).toString() == "true"; for(OnAttrChangeListener* listener : listeners){ listener->onAttrChanged(); } isWaitingForUpdate = false; }
JNIEXPORT jint JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSize (JNIEnv *env, jobject interfaceObject) { LOGD("RCSResourceAttributes_size"); RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); if (!rep) return -1; return static_cast<jint>(rep->size()); }
JNIEXPORT jboolean JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeIsEmpty (JNIEnv *env, jobject interfaceObject) { LOGD("RCSResourceAttributes_isEmpty"); RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); if (!rep) return false; return static_cast<jboolean>(rep->empty()); }
JNIEXPORT jobject JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeGetValueN (JNIEnv *env, jobject interfaceObject, jstring jKey) { LOGD("RCSResourceAttributes_getValueN"); if (!jKey) { throwRCSException(env, "attributeKey cannot be null"); return nullptr; } RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); if (!rep) return nullptr; std::string key = env->GetStringUTFChars(jKey, NULL); if (! rep->contains(key)) return nullptr; RCSResourceAttributes::Value attrValue = rep->at(key); RCSResourceAttributes::TypeId typeId = attrValue.getType().getId(); if (typeId == RCSResourceAttributes::TypeId::INT) { int val = attrValue.get<int>(); jobject jobj = env->NewObject( g_cls_Integer, g_mid_Integer_ctor, static_cast<jint>(val)); return jobj; } else if (typeId == RCSResourceAttributes::TypeId::DOUBLE) { double val = attrValue.get<double>(); jobject jobj = env->NewObject( g_cls_Double, g_mid_Double_ctor, static_cast<jdouble>(val)); return jobj; } else if (typeId == RCSResourceAttributes::TypeId::BOOL) { bool val = attrValue.get<bool>(); jobject jobj = env->NewObject( g_cls_Boolean, g_mid_Boolean_ctor, static_cast<jboolean>(val)); return jobj; } else if (typeId == RCSResourceAttributes::TypeId::STRING) { std::string val = attrValue.get<std::string>(); jstring jstr = env->NewStringUTF(val.c_str()); return static_cast<jobject>(jstr); } }
bool RCSResourceObject::applyAcceptanceMethod(const RCSSetResponse& response, const RCSResourceAttributes& requstAttrs) { auto requestHandler = response.getHandler(); assert(requestHandler != nullptr); auto replaced = requestHandler->applyAcceptanceMethod(response.getAcceptanceMethod(), *this, requstAttrs); OC_LOG_V(WARNING, LOG_TAG, "replaced num %zu", replaced.size()); for (const auto& attrKeyValPair : replaced) { std::shared_ptr< AttributeUpdatedListener > foundListener; { std::lock_guard< std::mutex > lock(m_mutexAttributeUpdatedListeners); auto it = m_attributeUpdatedListeners.find(attrKeyValPair.first); if (it != m_attributeUpdatedListeners.end()) { foundListener = it->second; } } if (foundListener) { (*foundListener)(attrKeyValPair.second, requstAttrs.at(attrKeyValPair.first)); } } return !replaced.empty(); }
void HostingObject::dataChangedCB(const RCSResourceAttributes & attributes) { if (attributes.empty()) { return; } std::unique_lock<std::mutex> lock(mutexForCB); if (mirroredServer == nullptr) { try { mirroredServer = createMirroredServer(this->remoteObject); } catch (const RCSException & e) { OIC_HOSTING_LOG(DEBUG, "[HostingObject::dataChangedCB]createMirroredServer Exception:%s", e.what()); return; } } lock.unlock(); RCSResourceObject::LockGuard guard(mirroredServer); mirroredServer->getAttributes() = std::move(attributes); }
void RemoteSceneCollection::initializeRemoteScenes( const std::vector< RCSResourceAttributes > &MemberReps, const std::string &host) { try { for (const auto &attrs : MemberReps) { for (const auto &mappingInfo : attrs.at(SCENE_KEY_SCENEMAPPINGS).get <std::vector< RCSResourceAttributes > >()) { std::string sceneName = mappingInfo.at(SCENE_KEY_SCENE).get< std::string >(); auto remoteScene = m_remoteScenes.find(sceneName); if (remoteScene == m_remoteScenes.end()) continue; RemoteScene::Ptr pRemoteScene = m_remoteScenes.at(sceneName); RCSResourceAttributes targetLinkAttrs = attrs.at(SCENE_KEY_PAYLOAD_LINK).get< RCSResourceAttributes >(); RCSRemoteResourceObject::Ptr targetResource = SceneUtils::createRCSResourceObject( targetLinkAttrs.at(SCENE_KEY_HREF).get< std::string >(), SCENE_CONNECTIVITY, targetLinkAttrs.at(SCENE_KEY_RT).get< std::vector< std::string > >(), targetLinkAttrs.at(SCENE_KEY_IF).get< std::vector< std::string > >()); std::string mappingInfoKey = mappingInfo.at(SCENE_KEY_MEMBERPROPERTY).get< std::string >(); RCSResourceAttributes::Value mappingInfoValue = mappingInfo.at(SCENE_KEY_MEMBERVALUE); pRemoteScene->addExistingRemoteSceneAction( host + attrs.at(SCENE_KEY_URI).get< std::string >(), attrs.at(SCENE_KEY_ID).get< std::string >(), targetResource, mappingInfoKey, mappingInfoValue); } } } catch (const std::exception &e) { SCENE_CLIENT_PRINT_LOG(e.what()); } }
bool acceptableAttributes(const RCSResourceAttributes& dest, const RCSResourceAttributes& attr) { for (const auto& kv : attr) { if (!dest.contains(kv.key())) { return false; } if (!acceptableAttributeValue(dest.at(kv.key()), kv.value())) { return false; } } return true; }
JNIEXPORT jboolean JNICALL Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeHasAttribute (JNIEnv *env, jobject interfaceObject, jstring jstr) { LOGD("RCSResourceAttributes_hasAttribute"); if (!jstr) { throwRCSException(env, "attributeKey cannot be null"); return false; } RCSResourceAttributes *rep = JniResourceAttributes::getResourceAttributePtr(env, interfaceObject); if (!rep) return false; std::string attributeKey = env->GetStringUTFChars(jstr, NULL); return static_cast<jboolean>(rep->contains(attributeKey)); }
void HostingObject::dataChangedCB(const RCSResourceAttributes & attributes, RemoteObjectPtr rObject) { if(attributes.empty()) { return; } if(mirroredServer == nullptr) { try { mirroredServer = createMirroredServer(rObject); }catch(PlatformException &e) { OIC_HOSTING_LOG(DEBUG, "[HostingObject::dataChangedCB]createMirroredServer PlatformException:%s", e.what()); mirroredServer = nullptr; return; } } RCSResourceAttributes rData; { RCSResourceObject::LockGuard guard(mirroredServer); rData = mirroredServer->getAttributes(); } if(rData.empty() || rData != attributes) { { RCSResourceObject::LockGuard guard(mirroredServer); for(auto it = rData.begin(); ; ++it) { if(it == rData.end()) { break; } mirroredServer->removeAttribute(it->key()); } for(auto it = attributes.begin();; ++it) { if(it == attributes.end()) { break; } mirroredServer->setAttribute(it->key(), it->value()); } } } }
void onCacheUpdated(const RCSResourceAttributes &attributes) { dlog_print(DLOG_INFO, LOG_TAG, "#### onCacheUpdated callback"); string logMessage = "Cache Updated : <br> "; if (attributes.empty()) { logMessage + logMessage + "Attribute is Empty <br>"; return; } for (const auto & attr : attributes) { logMessage = logMessage + "KEY:" + attr.key().c_str() + "<br>"; logMessage = logMessage + "VALUE:" + attr.value().toString().c_str() + "<br>"; } dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str()); ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage); }
void onRemoteAttributesReceived(const RCSResourceAttributes &attributes, int) { dlog_print(DLOG_INFO, LOG_TAG, "#### onRemoteAttributesReceived entry"); string logMessage = "Remote Attribute Updated : <br> "; if (attributes.empty()) { logMessage + logMessage + "Attribute is Empty <br>"; return; } for (const auto & attr : attributes) { logMessage = logMessage + "==========================<br>"; OIC::Service::RCSResourceAttributes::Value attrValue = attr.value(); std::vector< std::vector<RCSResourceAttributes >> attrVector = attrValue.get<std::vector< std::vector<RCSResourceAttributes >>>(); for (auto itr = attrVector.begin(); itr != attrVector.end(); ++itr) { std::vector<RCSResourceAttributes > attrKeyVector = *itr; for (auto itrKey = attrKeyVector.begin(); itrKey != attrKeyVector.end(); ++itrKey) { for (const auto & attribute : *itrKey) { logMessage = logMessage + attribute.key().c_str() + " : " + attribute.value().toString().c_str() + "<br>"; } } std::cout << std::endl; logMessage = logMessage + "<br>"; } logMessage = logMessage + "==========================<br>"; } dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str()); ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage); }
void SensorResource::onAttrGet(const RCSResourceAttributes &attrs, int eCode) { cout << "----GET---- State: " << attrs.at(SensorServer::IS_ON_ATTR).toString() << "-----------" << endl; }
void SensorResource::onAttrSet(const RCSResourceAttributes &attrs, int eCode) { cout << "----SET---- State: " << attrs.at(SensorServer::IS_ON_ATTR).toString() << "-----------" << endl; isWaitingForUpdate = false; }