From: Erich Keane Date: Fri, 5 Jun 2015 00:05:31 +0000 (-0700) Subject: Added Policy property to web type linking format X-Git-Tag: 0.9.2-beta~196 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9cf9d1e6d1ed4ef73c6078387278cb777c1db2d7;p=contrib%2Fiotivity.git Added Policy property to web type linking format This change set is based on OIC core framework standard specification draft A, Page#30,section 7.2.1.3 (Policy Property Definition).Added necessary changes to display policy property (Discoverable,Observable, Active, Slow etc) in JSON format. Modified core framework unit tests and samples to validate. Change-Id: I406889d21488e3c4d49b9e3fac5d223770d9420e Signed-off-by: Moumita Ray Signed-off-by: Erich Keane Reviewed-on: https://gerrit.iotivity.org/gerrit/1110 Tested-by: jenkins-iotivity --- diff --git a/resource/csdk/stack/include/octypes.h b/resource/csdk/stack/include/octypes.h index 76c4ccf..b14b1f2 100644 --- a/resource/csdk/stack/include/octypes.h +++ b/resource/csdk/stack/include/octypes.h @@ -83,7 +83,8 @@ extern "C" { #define OC_RSRVD_FW_VERSION "mnfv" #define OC_RSRVD_HOST_NAME "hn" #define OC_RSRVD_VERSION "icv" -#define OC_RSRVD_OBSERVABLE "obs" +#define OC_RSRVD_POLICY "p" +#define OC_RSRVD_BITMAP "bm" #define OC_RSRVD_SECURE "sec" #define OC_RSRVD_HOSTING_PORT "port" #define OC_RSRVD_SERVER_INSTANCE_ID "sid" @@ -201,14 +202,17 @@ typedef enum /** * Resource Properties. + * The value of a policy property is defined as bitmap. + * The LSB represents OC_DISCOVERABLE and Second LSB bit represents OC_OBSERVABLE and so on. + * Not including the policy property is equivalent to zero. * * ::OC_RES_PROP_NONE When none of the bits are set, the resource is non-discoverable & * non-observable by the client. + * ::OC_DISCOVERABLE When this bit is set, the resource is allowed to be discovered by clients. + * ::OC_OBSERVABLE When this bit is set, the resource is allowed to be observed by clients. * ::OC_ACTIVE When this bit is set, the resource is initialized, otherwise the resource * is 'inactive'. 'inactive' signifies that the resource has been marked for * deletion or is already deleted. - * ::OC_DISCOVERABLE When this bit is set, the resource is allowed to be discovered by clients. - * ::OC_OBSERVABLE When this bit is set, the resource is allowed to be observed by clients. * ::OC_SLOW When this bit is set, the resource has been marked as 'slow'. 'slow' * signifies that responses from this resource can expect delays in * processing its requests from clients. @@ -217,9 +221,9 @@ typedef enum typedef enum { OC_RES_PROP_NONE = (0), - OC_ACTIVE = (1 << 0), - OC_DISCOVERABLE = (1 << 1), - OC_OBSERVABLE = (1 << 2), + OC_DISCOVERABLE = (1 << 0), + OC_OBSERVABLE = (1 << 1), + OC_ACTIVE = (1 << 2), OC_SLOW = (1 << 3), OC_SECURE = (1 << 4) } OCResourceProperty; diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp index 7b2889b..b2c5ffd 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp @@ -137,7 +137,6 @@ char* constructJsonResponse (OCEntityHandlerRequest *ehRequest) { currLightResource->state = prop->valueint; } - cJSON_Delete(putJson); } @@ -757,6 +756,7 @@ void *ChangeLightRepresentation (void *param) cJSON_AddItemToObject(json, "rep", format=cJSON_CreateObject()); cJSON_AddBoolToObject(format, "state", Light.state); cJSON_AddNumberToObject(format, "power", Light.power); + char * obsResp = cJSON_Print(json); cJSON_Delete(json); result = OCNotifyListOfObservers (Light.handle, obsNotify, j, diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index 2b1b4e9..0374a6d 100644 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -308,6 +308,7 @@ BuildVirtualResourceResponse(const OCResource *resourcePtr, uint8_t filterOn, OCResourceInterface *interfacePtr = NULL; cJSON *resObj = NULL; cJSON *propObj = NULL; + cJSON *policyObj = NULL; cJSON *rtArray = NULL; char *jsonStr = NULL; uint8_t encodeRes = 0; @@ -366,6 +367,7 @@ BuildVirtualResourceResponse(const OCResource *resourcePtr, uint8_t filterOn, OC_RSRVD_SERVER_INSTANCE_ID, cJSON_CreateString(OCGetServerInstanceIDString())); + cJSON_AddItemToObject (resObj, OC_RSRVD_PROPERTY, propObj = cJSON_CreateObject()); // Add resource types cJSON_AddItemToObject (propObj, OC_RSRVD_RESOURCE_TYPE, rtArray = cJSON_CreateArray()); @@ -384,25 +386,35 @@ BuildVirtualResourceResponse(const OCResource *resourcePtr, uint8_t filterOn, cJSON_AddItemToArray (rtArray, cJSON_CreateString(interfacePtr->name)); interfacePtr = interfacePtr->next; } - // If resource is observable, set observability flag. - // Resources that are not observable will not have the flag. - if (resourcePtr->resourceProperties & OC_OBSERVABLE) - { - cJSON_AddItemToObject (propObj, OC_RSRVD_OBSERVABLE, - cJSON_CreateNumber(OC_RESOURCE_OBSERVABLE)); - } - // Set secure flag for secure resources - if (resourcePtr->resourceProperties & OC_SECURE) + + //Add Policy + cJSON_AddItemToObject (propObj, OC_RSRVD_POLICY, policyObj = cJSON_CreateObject()); + + if (policyObj) { - cJSON_AddNumberToObject (propObj, OC_RSRVD_SECURE, OC_RESOURCE_SECURE); - //Set the IP port also as secure resources are hosted on a different port - uint16_t port = 0; - if (GetSecurePortInfo (connType, &port) == OC_STACK_OK) + // Policy Property Bitmap + // If resource is discoverable, set discoverability flag. + // Resources that are not discoverable will not have the flag. + cJSON_AddNumberToObject (policyObj, OC_RSRVD_BITMAP, + resourcePtr->resourceProperties & (OC_OBSERVABLE|OC_DISCOVERABLE)); + + // Set secure flag for secure resources + if (resourcePtr->resourceProperties & OC_SECURE) { - cJSON_AddNumberToObject (propObj, OC_RSRVD_HOSTING_PORT, port); + cJSON_AddNumberToObject (policyObj, OC_RSRVD_SECURE, OC_RESOURCE_SECURE); + //Set the IP port also as secure resources are hosted on a different port + uint16_t port = 0; + if (GetSecurePortInfo (connType, &port) == OC_STACK_OK) + { + cJSON_AddNumberToObject (policyObj, OC_RSRVD_HOSTING_PORT, port); + } } } - + else + { + cJSON_Delete(resObj); + return OC_STACK_NO_MEMORY; + } } } jsonStr = cJSON_PrintUnformatted (resObj); diff --git a/resource/include/OCSerialization.h b/resource/include/OCSerialization.h index 898fde7..c9e0ce3 100644 --- a/resource/include/OCSerialization.h +++ b/resource/include/OCSerialization.h @@ -38,28 +38,29 @@ namespace OC class ListenResourceContainer { - class ListenResourcePropertiesContainer + class ListenResourcePolicyContainer { friend class cereal::access; friend class ListenResourceContainer; + friend class ListenResourcePropertiesContainer; template void serialize(Archive& ar) { try { - m_observable=false; - int obsTemp; - ar(cereal::make_nvp(OC::Key::OBSERVABLEKEY, obsTemp)); - m_observable = obsTemp != 0; + m_observable = false; + ar(cereal::make_nvp(OC::Key::BMKEY, m_bm)); + // In case of observable + if(m_bm & OC_OBSERVABLE) + { + m_observable = true; + } } catch(cereal::Exception&) { - // we swallow this exception, since it means the key - // doesn't exist, allowing these to be optional ar.setNextName(nullptr); } - try { m_secure = false; @@ -72,6 +73,35 @@ namespace OC } catch(cereal::Exception&) { + ar.setNextName(nullptr); + } + + } + + bool m_observable; + uint8_t m_bm; + bool m_secure; + int m_port; + }; + + class ListenResourcePropertiesContainer + { + friend class cereal::access; + friend class ListenResourceContainer; + + template + void serialize(Archive& ar) + { + try + { + ar(cereal::make_nvp(OC::Key::POLICYKEY, m_policy)); + + } + catch(cereal::Exception&) + { + // we swallow this exception, since it means the key + // doesn't exist, allowing these to be optional + oclog() << "Invalid POLICYKEY"< m_resourceTypes; std::vector m_interfaces; - bool m_secure; - int m_port; + ListenResourcePolicyContainer m_policy; }; public: @@ -138,8 +166,8 @@ namespace OC { ar.setNextName(nullptr); } - } + } std::string m_uri; std::string m_serverId; @@ -153,17 +181,17 @@ namespace OC bool observable() const { - return m_props.m_observable; + return m_props.m_policy.m_observable; } OCSecureType secureType() const { - return m_props.m_secure?OCSecureType::IPv4Secure :OCSecureType::IPv4; + return m_props.m_policy.m_secure?OCSecureType::IPv4Secure :OCSecureType::IPv4; } int port() const { - return m_props.m_port; + return m_props.m_policy.m_port; } std::vector resourceTypes() const diff --git a/resource/include/StringConstants.h b/resource/include/StringConstants.h index 7aea3ad..beb70b2 100644 --- a/resource/include/StringConstants.h +++ b/resource/include/StringConstants.h @@ -124,7 +124,8 @@ namespace OC { static const std::string OCKEY = "oic"; static const std::string URIKEY = "href"; - static const std::string OBSERVABLEKEY = "obs"; + static const std::string POLICYKEY = "p"; + static const std::string BMKEY = "bm"; static const std::string RESOURCETYPESKEY = "rt"; static const std::string INTERFACESKEY = "if"; static const std::string PROPERTYKEY = "prop"; diff --git a/resource/src/OCRepresentation.cpp b/resource/src/OCRepresentation.cpp index 6f73435..494f9aa 100644 --- a/resource/src/OCRepresentation.cpp +++ b/resource/src/OCRepresentation.cpp @@ -466,7 +466,7 @@ namespace OC boost::get>( parseAttributeValue(itr->value))); } - else if(keyName == OC::Key::PROPERTYKEY) + else if(keyName == OC::Key::INTERFACESKEY) { rep.setResourceInterfaces( boost::get>( diff --git a/resource/unittests/OCPlatformTest.cpp b/resource/unittests/OCPlatformTest.cpp index 89034d3..993b1d6 100644 --- a/resource/unittests/OCPlatformTest.cpp +++ b/resource/unittests/OCPlatformTest.cpp @@ -540,7 +540,7 @@ namespace OCPlatformTest //GetDeviceInfo Test TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters) { - std::string deviceDiscoveryURI = "/oic/res/d"; + std::string deviceDiscoveryURI = "/oic/d"; PlatformConfig cfg; OCPlatform::Configure(cfg); std::ostringstream requestURI; @@ -559,7 +559,7 @@ namespace OCPlatformTest TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler) { - std::string deviceDiscoveryURI = "/oic/res/d"; + std::string deviceDiscoveryURI = "/oic/d"; PlatformConfig cfg; OCPlatform::Configure(cfg); std::ostringstream requestURI; @@ -571,7 +571,7 @@ namespace OCPlatformTest TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos) { - std::string deviceDiscoveryURI = "/oic/res/d"; + std::string deviceDiscoveryURI = "/oic/d"; PlatformConfig cfg; OCPlatform::Configure(cfg); std::ostringstream requestURI; @@ -583,7 +583,7 @@ namespace OCPlatformTest TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos) { - std::string deviceDiscoveryURI = "/oic/res/d"; + std::string deviceDiscoveryURI = "/oic/d"; PlatformConfig cfg; OCPlatform::Configure(cfg); std::ostringstream requestURI; @@ -595,7 +595,7 @@ namespace OCPlatformTest TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos) { - std::string deviceDiscoveryURI = "/oic/res/d"; + std::string deviceDiscoveryURI = "/oic/d"; PlatformConfig cfg; OCPlatform::Configure(cfg); std::ostringstream requestURI; @@ -607,7 +607,7 @@ namespace OCPlatformTest TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos) { - std::string deviceDiscoveryURI = "/oic/res/d"; + std::string deviceDiscoveryURI = "/oic/d"; PlatformConfig cfg; OCPlatform::Configure(cfg); std::ostringstream requestURI;