- Added exception for the missed api.
- Updated exception handling in Resource Client
- Added more logs in the Sample Applications
Change-Id: I7a212e05856f37628f2e744d83d4f1619f6a1e06
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1663
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
}
else if (userInput == 8)
{
}
else if (userInput == 8)
{
- ResourceAttributes atttribute = resource->getCachedAttributes();
- if (atttribute.empty())
- {
- cout << "Received cached attribute is empty" << std::endl;
- }
- else
- ResourceAttributes::const_iterator iter = atttribute.begin();
- for (unsigned int i = 0; i < atttribute.size(); ++i)
+ ResourceAttributes atttribute = resource->getCachedAttributes();
+ if (atttribute.empty())
- std::cout << "\nkey : " << iter->key() << "\nvalue : " << iter->value().toString() << std::endl;
- ++iter;
+ cout << "Received cached attribute is empty" << std::endl;
+ }
+ else
+ {
+ ResourceAttributes::const_iterator iter = atttribute.begin();
+ for (unsigned int i = 0; i < atttribute.size(); ++i)
+ {
+ std::cout << "\nkey : " << iter->key() << "\nvalue : " << iter->value().toString() << std::endl;
+ ++iter;
+ }
+ catch (BadRequestException e)
+ {
+ cout << "getCachedAttributes exception : " << e.what() << std::endl;
+ }
}
else if (userInput == 9)
{
}
else if (userInput == 9)
{
int value = valueObj.get< int >();
cout << "\nkey : " << key << "\nValue : " << value << std::endl;
}
int value = valueObj.get< int >();
cout << "\nkey : " << key << "\nValue : " << value << std::endl;
}
+ catch (BadRequestException e)
+ {
+ cout << "getCachedAttribute exception : " << e.what() << std::endl;
+ }
catch (BadGetException e)
{
cout << "Exeception in getCachedAttribute BadGetException:: " << e.what() << std::endl;
catch (BadGetException e)
{
cout << "Exeception in getCachedAttribute BadGetException:: " << e.what() << std::endl;
using namespace OC::OCPlatform;
using namespace OIC::Service;
using namespace OC::OCPlatform;
using namespace OIC::Service;
-std::string resourceUri = "/a/TempHumSensor";
+std::string resourceUri = "/a/TempSensor";
std::string resourceType = "core.TemperatureSensor";
std::string resourceInterface = "oic.if.";
std::string attributeKey = "Temperature";
std::string resourceType = "core.TemperatureSensor";
std::string resourceInterface = "oic.if.";
std::string attributeKey = "Temperature";
PrimitiveGetResponse RequestHandlerForGet(const PrimitiveRequest &request,
ResourceAttributes &attrs)
{
PrimitiveGetResponse RequestHandlerForGet(const PrimitiveRequest &request,
ResourceAttributes &attrs)
{
- cout << "\nRecieved a Get request from Client" << std::endl;
+ cout << "Recieved a Get request from Client" << std::endl;
ResourceObject::LockGuard lock(*server);
ResourceAttributes attr = server->getAttributes();
ResourceAttributes::const_iterator iter = attr.begin();
ResourceObject::LockGuard lock(*server);
ResourceAttributes attr = server->getAttributes();
ResourceAttributes::const_iterator iter = attr.begin();
+ cout << "\nSending response to Client : " << std::endl;
for (unsigned int i = 0; i < attr.size(); ++i)
{
for (unsigned int i = 0; i < attr.size(); ++i)
{
- std::cout << "\nkey : " << iter->key() << "\nvalue : " << iter->value().toString() << std::endl;
+ std::cout << "\tkey : " << iter->key() << "\n\tvalue : " << iter->value().toString() << std::endl;
++iter;
}
return PrimitiveGetResponse::create(attr);
++iter;
}
return PrimitiveGetResponse::create(attr);
PrimitiveSetResponse RequestHandlerForSet(const PrimitiveRequest &request,
ResourceAttributes &attrs)
{
PrimitiveSetResponse RequestHandlerForSet(const PrimitiveRequest &request,
ResourceAttributes &attrs)
{
- cout << "\nRecieved a Set request from Client" << std::endl;
+ cout << "Recieved a Set request from Client" << std::endl;
ResourceAttributes::const_iterator iter = attrs.begin();
for (unsigned int i = 0; i < attrs.size(); ++i)
{
ResourceAttributes::const_iterator iter = attrs.begin();
for (unsigned int i = 0; i < attrs.size(); ++i)
{
- std::cout << "\nkey : " << iter->key() << "\nvalue : " << iter->value().toString() << std::endl;
+ std::cout << "\tkey : " << iter->key() << "\n\tvalue : " << iter->value().toString() << std::endl;
+ ++iter;
+ }
+ iter = attrs.begin();
+ cout << "\n\nSending response to Client : " << std::endl;
+ for (unsigned int i = 0; i < attrs.size(); ++i)
+ {
+ std::cout << "\tkey : " << iter->key() << "\n\tvalue : " << iter->value().toString() << std::endl;
++iter;
}
return PrimitiveSetResponse::create(attrs);
++iter;
}
return PrimitiveSetResponse::create(attrs);
* API to get cached ResourceAttributes data.
*
* @return ResourceAttributes - cached ResourceAttributes data
* API to get cached ResourceAttributes data.
*
* @return ResourceAttributes - cached ResourceAttributes data
+ *
+ * @throw BadRequestException
+ *
*/
ResourceAttributes getCachedAttributes() const;
*/
ResourceAttributes getCachedAttributes() const;
* API to get particular cached ResourceAttribute value
*
* @return Value - ResourceAttributes::Value class object
* API to get particular cached ResourceAttribute value
*
* @return Value - ResourceAttributes::Value class object
+ *
+ * @throw BadRequestException
+ *
*/
ResourceAttributes::Value getCachedAttribute( const std::string &) ;
*/
ResourceAttributes::Value getCachedAttribute( const std::string &) ;
m_watchingFlag = true;
m_brokerId = brokerId;
}
m_watchingFlag = true;
m_brokerId = brokerId;
}
- catch (InvalidParameterException exception )
+ catch (std::exception &exception)
{
throw InvalidParameterException {exception.what()};
}
{
throw InvalidParameterException {exception.what()};
}
ResourceBroker::getInstance()->cancelHostResource(m_brokerId);
m_watchingFlag = false;
}
ResourceBroker::getInstance()->cancelHostResource(m_brokerId);
m_watchingFlag = false;
}
- catch (InvalidParameterException exception )
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopWatching InvalidParameterException");
}
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopWatching InvalidParameterException");
}
OC_LOG(DEBUG, CLIENT_W_TAG, " RemoteResourceObject::getState exit");
return getResourceStateFromBrokerState(brokerState);
}
OC_LOG(DEBUG, CLIENT_W_TAG, " RemoteResourceObject::getState exit");
return getResourceStateFromBrokerState(brokerState);
}
- catch (InvalidParameterException exception)
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG, " RemoteResourceObject::getState InvalidParameterException");
}
{
OC_LOG(DEBUG, CLIENT_W_TAG, " RemoteResourceObject::getState InvalidParameterException");
}
m_cachingFlag = true;
OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
}
m_cachingFlag = true;
OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
}
- catch (InvalidParameterException e)
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching InvalidParameterException");
}
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching InvalidParameterException");
}
- CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
+ CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
std::bind(cachingCallback, std::placeholders::_1, std::placeholders::_2, cb),
REPORT_FREQUENCY::UPTODATE, 0);
std::bind(cachingCallback, std::placeholders::_1, std::placeholders::_2, cb),
REPORT_FREQUENCY::UPTODATE, 0);
m_cachingFlag = true;
OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
}
m_cachingFlag = true;
OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
}
- catch (InvalidParameterException e)
+ catch (std::exception &exception)
- throw InvalidParameterException { e.what() };
+ throw InvalidParameterException {"startCaching : Callback is NULL" };
ResourceCacheManager::getInstance()->cancelResourceCache(m_cacheId);
m_cachingFlag = false;
}
ResourceCacheManager::getInstance()->cancelResourceCache(m_cacheId);
m_cachingFlag = false;
}
- catch (InvalidParameterException exception)
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopCaching InvalidParameterException");
}
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopCaching InvalidParameterException");
}
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getResourceCacheState exit");
return getCacheState(cacheState);
}
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getResourceCacheState exit");
return getCacheState(cacheState);
}
- catch (InvalidParameterException exception)
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG,
"RemoteResourceObject::getResourceCacheState InvalidParameterException");
{
OC_LOG(DEBUG, CLIENT_W_TAG,
"RemoteResourceObject::getResourceCacheState InvalidParameterException");
ResourceCacheManager::getInstance()->updateResourceCache(
m_primitiveResource);
}
ResourceCacheManager::getInstance()->updateResourceCache(
m_primitiveResource);
}
- catch (InvalidParameterException exception)
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::refreshCache InvalidParameterException");
}
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::refreshCache InvalidParameterException");
}
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject :: getCachedAttributes ");
try
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject :: getCachedAttributes ");
try
{
- return ResourceCacheManager::getInstance()->getCachedData(m_primitiveResource);
+ return ResourceCacheManager::getInstance()->getCachedData(m_primitiveResource);
- catch (InvalidParameterException e)
+ catch (std::exception &exception)
- OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getCachedAttributes InvalidParameterException");
+ throw BadRequestException { "[getCachedAttributes] Caching not started" };
m_primitiveResource);
return Cachedattributes[key];
}
m_primitiveResource);
return Cachedattributes[key];
}
- catch (InvalidParameterException e)
+ catch (std::exception &exception)
- OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getCachedAttribute InvalidParameterException");
+ throw BadRequestException { "[getCachedAttribute] Caching not started" };
}
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject :: getCachedAttribute exit");
}
}
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject :: getCachedAttribute exit");
}