#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"
/**
* 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.
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;
{
currLightResource->state = prop->valueint;
}
-
cJSON_Delete(putJson);
}
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,
OCResourceInterface *interfacePtr = NULL;
cJSON *resObj = NULL;
cJSON *propObj = NULL;
+ cJSON *policyObj = NULL;
cJSON *rtArray = NULL;
char *jsonStr = NULL;
uint8_t encodeRes = 0;
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());
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);
class ListenResourceContainer
{
- class ListenResourcePropertiesContainer
+ class ListenResourcePolicyContainer
{
friend class cereal::access;
friend class ListenResourceContainer;
+ friend class ListenResourcePropertiesContainer;
template<class Archive>
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;
}
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<class Archive>
+ 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"<<std::flush;
ar.setNextName(nullptr);
}
}
}
- bool m_observable;
std::vector<std::string> m_resourceTypes;
std::vector<std::string> m_interfaces;
- bool m_secure;
- int m_port;
+ ListenResourcePolicyContainer m_policy;
};
public:
{
ar.setNextName(nullptr);
}
- }
+ }
std::string m_uri;
std::string m_serverId;
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<std::string> resourceTypes() const
{
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";
boost::get<std::vector<std::string>>(
parseAttributeValue(itr->value)));
}
- else if(keyName == OC::Key::PROPERTYKEY)
+ else if(keyName == OC::Key::INTERFACESKEY)
{
rep.setResourceInterfaces(
boost::get<std::vector<std::string>>(
//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;
TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
{
- std::string deviceDiscoveryURI = "/oic/res/d";
+ std::string deviceDiscoveryURI = "/oic/d";
PlatformConfig cfg;
OCPlatform::Configure(cfg);
std::ostringstream requestURI;
TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
{
- std::string deviceDiscoveryURI = "/oic/res/d";
+ std::string deviceDiscoveryURI = "/oic/d";
PlatformConfig cfg;
OCPlatform::Configure(cfg);
std::ostringstream requestURI;
TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
{
- std::string deviceDiscoveryURI = "/oic/res/d";
+ std::string deviceDiscoveryURI = "/oic/d";
PlatformConfig cfg;
OCPlatform::Configure(cfg);
std::ostringstream requestURI;
TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
{
- std::string deviceDiscoveryURI = "/oic/res/d";
+ std::string deviceDiscoveryURI = "/oic/d";
PlatformConfig cfg;
OCPlatform::Configure(cfg);
std::ostringstream requestURI;
TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
{
- std::string deviceDiscoveryURI = "/oic/res/d";
+ std::string deviceDiscoveryURI = "/oic/d";
PlatformConfig cfg;
OCPlatform::Configure(cfg);
std::ostringstream requestURI;