update presence sample app for android. 99/13799/4
authorjihwan.seo <jihwan.seo@samsung.com>
Fri, 28 Oct 2016 04:13:03 +0000 (13:13 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 2 Nov 2016 11:17:37 +0000 (11:17 +0000)
- enable multicast presecne in client
- start presence can be triggered for several times
  after initialize step like createResource(..).
- this change is realted to IOT-1468.
  but it's not resolve patch for that.

Change-Id: Ia896b93eb0b10386cfe87969cebd8e2b18531f45
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13799
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
android/examples/presenceclient/src/main/java/org/iotivity/base/examples/PresenceClient.java
android/examples/presenceserver/src/main/java/org/iotivity/base/examples/PresenceServer.java

index 8d879e2..d2fad1e 100644 (file)
@@ -72,6 +72,15 @@ public class PresenceClient extends Activity implements
         msg("Configuring platform.");
         OcPlatform.Configure(platformConfig);
 
+        try {
+            msg("Subscribing to multicast presence");
+            OcPlatform.subscribePresence(OcPlatform.PRESENCE_URI,
+                    EnumSet.of(OcConnectivityType.CT_DEFAULT), this);
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to subscribe to multicast presence");
+        }
+
         try {
             msg("Finding Resource...");
             OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY,
index 6be053e..fefd053 100644 (file)
@@ -48,6 +48,8 @@ import java.util.EnumSet;
  */
 public class PresenceServer extends Activity {
     private OcResourceHandle mResourceHandle;
+    private int mPresenceCount = 0;
+    private final int mMaxCount = 10;
 
     private void startPresenceServer() {
         Context context = this;
@@ -80,6 +82,18 @@ public class PresenceServer extends Activity {
         enableStartStopButton();
     }
 
+    private void startPresence()
+    {
+        try {
+            msg("Starting presence notifications (" + mPresenceCount + " / " + mMaxCount + ")");
+            OcPlatform.startPresence(OcPlatform.DEFAULT_PRESENCE_TTL);
+            sleep(3);
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Error: " + e.toString());
+        }
+    }
+
     /**
      * This function internally calls registerResource API.
      */
@@ -145,11 +159,19 @@ public class PresenceServer extends Activity {
                         new Thread(new Runnable() {
                             public void run() {
                                 startPresenceServer();
+
+                                mPresenceCount = 0;
+                                while(mPresenceCount++ < mMaxCount)
+                                {
+                                    startPresence();
+                                }
+                                stopPresenceServer();
                             }
                         }).start();
                     } else {
                         new Thread(new Runnable() {
                             public void run() {
+                                mPresenceCount = 10;
                                 stopPresenceServer();
                             }
                         }).start();