|
16 | 16 | import android.os.Message;
|
17 | 17 | import android.util.Log;
|
18 | 18 |
|
| 19 | +import com.couchbase.android.Intents.CouchbaseError; |
| 20 | +import com.couchbase.android.Intents.CouchbaseStarted; |
| 21 | + |
19 | 22 | /**
|
20 | 23 | * Implementation of the Couchbase service
|
21 | 24 | *
|
@@ -76,20 +79,8 @@ public void handleMessage(Message msg) {
|
76 | 79 |
|
77 | 80 | switch (msg.what) {
|
78 | 81 | case ERROR:
|
79 |
| - if(msg.obj instanceof Exception) { |
80 |
| - Exception e = (Exception) msg.obj; |
81 |
| - StringWriter sw = new StringWriter(); |
82 |
| - e.printStackTrace(new PrintWriter(sw)); |
83 |
| - String stacktrace = sw.toString(); |
84 |
| - if (couchbaseDelegate != null) { |
85 |
| - couchbaseDelegate.exit(stacktrace); |
86 |
| - } |
87 |
| - } |
88 |
| - else if(msg.obj instanceof String){ |
89 |
| - if (couchbaseDelegate != null) { |
90 |
| - couchbaseDelegate.exit((String)msg.obj); |
91 |
| - } |
92 |
| - } |
| 82 | + Exception e = (Exception) msg.obj; |
| 83 | + couchbaseError(e); |
93 | 84 | break;
|
94 | 85 | case COMPLETE:
|
95 | 86 | couchbaseInstallThread = null;
|
@@ -148,8 +139,37 @@ public void startCouchbase(ICouchbaseDelegate cb) {
|
148 | 139 | * Nofity the delegate that Couchbase has started
|
149 | 140 | */
|
150 | 141 | void couchbaseStarted() {
|
| 142 | + |
| 143 | + if(url != null) { |
| 144 | + //send broadcast intent |
| 145 | + Intent intent = new Intent(CouchbaseStarted.ACTION); |
| 146 | + intent.putExtra(CouchbaseStarted.HOST, url.getHost()); |
| 147 | + intent.putExtra(CouchbaseStarted.PORT, url.getPort()); |
| 148 | + getApplicationContext().sendBroadcast(intent); |
| 149 | + |
| 150 | + //notify delegate |
| 151 | + if (couchbaseDelegate != null) { |
| 152 | + couchbaseDelegate.couchbaseStarted(url.getHost(), url.getPort()); |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Notify the delegate that Couchbase has encountered an error |
| 159 | + */ |
| 160 | + void couchbaseError(Exception e) { |
| 161 | + StringWriter sw = new StringWriter(); |
| 162 | + e.printStackTrace(new PrintWriter(sw)); |
| 163 | + String stacktrace = sw.toString(); |
| 164 | + |
| 165 | + //send broadcast intent |
| 166 | + Intent intent = new Intent(CouchbaseError.ACTION); |
| 167 | + intent.putExtra(CouchbaseError.MESSAGE, stacktrace); |
| 168 | + getApplicationContext().sendBroadcast(intent); |
| 169 | + |
| 170 | + //notify delegate |
151 | 171 | if (couchbaseDelegate != null) {
|
152 |
| - couchbaseDelegate.couchbaseStarted(url.getHost(), url.getPort()); |
| 172 | + couchbaseDelegate.exit(stacktrace); |
153 | 173 | }
|
154 | 174 | }
|
155 | 175 |
|
|
0 commit comments