Permalink
Browse files

added PID to the broadcast intents

this allows receivers of the intents to see if the message is from
their own couchbase or possibly from another process

Change-Id: I573416c351e2753ebc5d488718e1599aafefc607
Reviewed-on: http://review.couchbase.org/10677
Tested-by: Marty Schoch <marty.schoch@gmail.com>
Reviewed-by: Marty Schoch <marty.schoch@gmail.com>
  • Loading branch information...
1 parent 6cbb2ef commit bcae8621ac9304f0c67b3aaf2fbf81384f448afa @mschoch mschoch committed Nov 8, 2011
Showing with 33 additions and 2 deletions.
  1. +2 −2 .classpath
  2. +3 −0 src/com/couchbase/android/CouchbaseService.java
  3. +28 −0 src/com/couchbase/android/Intents.java
View
@@ -3,6 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="libs/OtpErlang.jar"/>
- <classpathentry kind="output" path="bin"/>
+ <classpathentry kind="lib" path="../erlang/lib/jinterface/priv/OtpErlang.jar"/>
+ <classpathentry kind="output" path="bin/classes"/>
</classpath>
@@ -14,6 +14,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
+import android.os.Process;
import android.util.Log;
import com.couchbase.android.Intents.CouchbaseError;
@@ -145,6 +146,7 @@ void couchbaseStarted() {
Intent intent = new Intent(CouchbaseStarted.ACTION);
intent.putExtra(CouchbaseStarted.HOST, url.getHost());
intent.putExtra(CouchbaseStarted.PORT, url.getPort());
+ intent.putExtra(CouchbaseStarted.PID, Process.myPid());
getApplicationContext().sendBroadcast(intent);
//notify delegate
@@ -165,6 +167,7 @@ void couchbaseError(Exception e) {
//send broadcast intent
Intent intent = new Intent(CouchbaseError.ACTION);
intent.putExtra(CouchbaseError.MESSAGE, stacktrace);
+ intent.putExtra(CouchbaseError.PID, Process.myPid());
getApplicationContext().sendBroadcast(intent);
//notify delegate
@@ -35,6 +35,11 @@ private CouchbaseStarted() {}
public final static String PORT = "port";
/**
+ * Name used in Intext Extra for storing process id
+ */
+ public final static String PID = "pid";
+
+ /**
* Utility to get the host Couchbase is listening on
* @param intent the intent to parse
* @return the hostname
@@ -52,6 +57,15 @@ public static int getPort(Intent intent) {
return intent.getIntExtra(PORT, -1);
}
+ /**
+ * Utility to get the pid of the process for this Couchbase
+ * @param intent the intent to parse
+ * @return the pid
+ */
+ public static int getPid(Intent intent) {
+ return intent.getIntExtra(PID, -1);
+ }
+
}
/**
@@ -74,6 +88,11 @@ private CouchbaseError() {}
*/
public final static String MESSAGE = "message";
+ /**
+ * Name used in Intext Extra for storing process id
+ */
+ public final static String PID = "pid";
+
/**
* Utility to get the message from Couchbase
* @param intent the intent to parse
@@ -83,6 +102,15 @@ public static String getMessage(Intent intent) {
return intent.getStringExtra(MESSAGE);
}
+ /**
+ * Utility to get the pid of the process for this Couchbase
+ * @param intent the intent to parse
+ * @return the pid
+ */
+ public static int getPid(Intent intent) {
+ return intent.getIntExtra(PID, -1);
+ }
+
}
}

0 comments on commit bcae862

Please sign in to comment.