{
cout << "onFindResource" << endl;
- if (resource)
+ try
{
- OCResourceHandle resourceHandle;
- OCStackResult result = OCPlatform::registerResource(resourceHandle, resource);
- if (OC_STACK_OK == result)
- {
- cout << "onFindResource : Resource creation was successful\n";
- }
- else
+ if (resource)
{
- cout << "onFindResource : Resource creation was unsuccessful\n";
- return;
- }
+ OCResourceHandle resourceHandle;
+ OCStackResult result = OCPlatform::registerResource(resourceHandle, resource);
+ if (OC_STACK_OK == result)
+ {
+ cout << "onFindResource : Resource creation was successful\n";
+ }
+ else
+ {
+ cout << "onFindResource : Resource creation was unsuccessful\n";
+ return;
+ }
- result = gThingManager->joinGroup(collectionResourceType, resourceHandle);
- if (OC_STACK_OK == result)
- {
- cout << "onFindResource : Joining group was successful\n";
+ result = gThingManager->joinGroup(collectionResourceType, resourceHandle);
+ if (OC_STACK_OK == result)
+ {
+ cout << "onFindResource : Joining group was successful\n";
+ }
+ else
+ {
+ cout << "onFindResource : Joining group was unsuccessful\n";
+
+ OCPlatform::unregisterResource(resourceHandle);
+ return;
+ }
+
+ gResourceHandleList.push_back(resourceHandle);
}
else
{
- cout << "onFindResource : Joining group was unsuccessful\n";
-
- OCPlatform::unregisterResource(resourceHandle);
- return;
+ cout << "onFindResource : There is no found resource." << endl;
}
-
- gResourceHandleList.push_back(resourceHandle);
- }
- else
+ }catch (std::exception& e)
{
- cout << "onFindResource : There is no found resource." << endl;
+ std::cout << "Exception: " << e.what() << std::endl;
}
}
CT_DEFAULT,
onFindResource);
- result = OCPlatform::findResource("",
- "coap://224.0.1.187/oc/core?rt=core.musicplayer",
- CT_DEFAULT,
- onFindResource);
-
if (OC_STACK_OK == result)
{
cout << "Finding music player was successful\n";
static ActionSet* gPlayStop;
+void presenceCallback(std::string msg, OCStackResult res)
+{
+ std::cout << "Presence Callback: " << msg << "(" << res << ")" << std::endl;
+}
+
void onFindGroup(std::shared_ptr< OCResource > resource)
{
if (resource)
{
cout << "onFindGroup : Found group is saved now." << endl;
gFindGroup = resource;
+ {
+ OCStackResult res;
+ res = gThingManager->subscribeCollectionPresence( resource, &presenceCallback);
+
+ std::cout << "Return Value: " << res << std::endl;
+ }
}
gThingManager->joinGroup(gFindGroup, gPhoneResourceHandle);