Fix defects of IOT-534 in Things Manager
authorJihun Ha <jihun.ha@samsung.com>
Tue, 7 Jul 2015 00:40:56 +0000 (09:40 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 7 Jul 2015 09:54:59 +0000 (09:54 +0000)
Exception handling logic is added in group application.
startPresence for enabling presence check is added in speaker and musicplayer apps.

Change-Id: I12f6589154e27d288417d3fdd6413b867499a2bf
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1547
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/things-manager/sampleapp/linux/groupsyncaction/group.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/linux/groupsyncaction/musicplayer.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/linux/groupsyncaction/phone.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/linux/groupsyncaction/speaker.cpp [changed mode: 0644->0755]
service/things-manager/sdk/src/GroupManager.cpp

old mode 100644 (file)
new mode 100755 (executable)
index 7f72f19..c49d152
@@ -38,38 +38,44 @@ void onFindResource(std::shared_ptr< OCResource > resource)
 {
     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;
     }
 }
 
@@ -121,11 +127,6 @@ int main(int argc, char* argv[])
                             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";
old mode 100644 (file)
new mode 100755 (executable)
index fa148b2..64fa656
@@ -86,6 +86,8 @@ int main(int argc, char* argv[])
 
     OCPlatform::Configure(cfg);
 
+    OCPlatform::startPresence(30);
+
     int selectedMenu;
     OCStackResult result;
     OCResourceHandle mpResourceHandle = NULL;
old mode 100644 (file)
new mode 100755 (executable)
index 1e9ad79..4693637
@@ -40,6 +40,11 @@ static ActionSet* gPlayStart;
 
 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)
@@ -60,6 +65,12 @@ void onFindGroup(std::shared_ptr< OCResource > 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);
old mode 100644 (file)
new mode 100755 (executable)
index 4e90f3f..9f6d5a2
@@ -87,6 +87,8 @@ int main(int argc, char* argv[])
 
     OCPlatform::Configure(cfg);
 
+    OCPlatform::startPresence(30);
+
     int selectedMenu;
     OCStackResult result;
     OCResourceHandle speakerResourceHandle = NULL;
index 4844e8a..2f30d6e 100755 (executable)
  *
  */
 
-#include "GroupManager.h"
 #include <algorithm>
 #include <thread>
 #include <unistd.h>
-
 #include <string.h>
 
+#include "GroupManager.h"
+
 #define PLAIN_DELIMITER "\""
 #define ACTION_DELIMITER "*"
 #define DESC_DELIMITER "|"