}
else if (userInput == 8)
{
- ResourceAttributes atttribute = resource->getCachedAttributes();
- if (atttribute.empty())
- {
- cout << "Received cached attribute is empty" << std::endl;
- }
- else
+ try
{
- 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)
{
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;
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";
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();
+ cout << "\nSending response to Client : " << std::endl;
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);
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)
{
- 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);
m_watchingFlag = true;
m_brokerId = brokerId;
}
- catch (InvalidParameterException exception )
+ catch (std::exception &exception)
{
throw InvalidParameterException {exception.what()};
}
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::getState exit");
return getResourceStateFromBrokerState(brokerState);
}
- catch (InvalidParameterException exception)
+ catch (std::exception &exception)
{
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);
}
- catch (InvalidParameterException e)
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching InvalidParameterException");
}
{
try
{
- 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);
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;
}
- catch (InvalidParameterException exception)
+ catch (std::exception &exception)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopCaching InvalidParameterException");
}
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");
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 :: 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];
}
- 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");
}