Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start rename and cleanup

  • Loading branch information...
commit f7ada296123eabfa57a823df6a7fbaae07cb3fc4 1 parent 783881f
@daleharvey daleharvey authored
View
49 src/com/couchbase/libcouch/CouchDB.java
@@ -1,49 +0,0 @@
-package com.couchbase.libcouch;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.IBinder;
-import android.os.RemoteException;
-
-public class CouchDB {
-
- private final static String defaultRelease = "couchbase-1.0-dp-be9fe2f";
- private static String releaseName;
-
- private static ICouchService couchService;
- private static ICouchClient couchClient;
-
- /*
- * This holds the connection to the CouchDB Service
- */
- private final static ServiceConnection mConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName className, final IBinder service) {
- try {
- couchService = ICouchService.Stub.asInterface(service);
- couchService.initCouchDB(couchClient, releaseName);
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public void onServiceDisconnected(ComponentName className) {
- couchService = null;
- }
- };
-
- public static ServiceConnection getService(Context ctx, ICouchClient client) {
- return getService(ctx, defaultRelease, client);
- }
-
- public static ServiceConnection getService(Context ctx, String release, ICouchClient client) {
- releaseName = release;
- couchClient = client;
- ctx.bindService(new Intent(ctx, CouchService.class), mConnection, Context.BIND_AUTO_CREATE);
- return mConnection;
- }
-}
View
47 src/com/couchbase/libcouch/CouchInstaller.java
@@ -15,25 +15,16 @@
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
-import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
public class CouchInstaller {
- public static String appNamespace;
-
final static String TAG = "CouchDB";
- public static String dataPath() {
- return "/data/data/" + appNamespace;
- }
- public static String externalPath() {
- return Environment.getExternalStorageDirectory() + "/Android/data/" + appNamespace;
- }
public static String indexFile() {
- return dataPath() + "/installedfiles.index";
+ return CouchbaseEmbeddedServer.dataPath() + "/installedfiles.index";
}
public static void doInstall(String pkg, Handler handler, CouchService service)
@@ -49,13 +40,13 @@ public static void doInstall(String pkg, Handler handler, CouchService service)
* of protecting ourselves from wiping the entire SD card with a typo.
*/
- File couchDir = new File(dataPath() + "/couchdb");
+ File couchDir = new File(CouchbaseEmbeddedServer.dataPath() + "/couchdb");
if (couchDir.exists()) {
deleteDirectory(couchDir);
}
- File erlangDir = new File(dataPath() + "/erlang");
+ File erlangDir = new File(CouchbaseEmbeddedServer.dataPath() + "/erlang");
if (erlangDir.exists()) {
deleteDirectory(erlangDir);
@@ -91,7 +82,7 @@ private static void installPackage(String pkg, Handler handler, CouchService ser
InputStream instream = service.getAssets().open(pkg + ".tgz" + ".jpg");
// Ensure /sdcard/Android/data/com.my.app/db exists
- File externalPath = new File(externalPath() + "/db/");
+ File externalPath = new File(CouchbaseEmbeddedServer.externalPath() + "/db/");
if (!externalPath.exists()) {
externalPath.mkdirs();
}
@@ -105,7 +96,7 @@ private static void installPackage(String pkg, Handler handler, CouchService ser
while ((e = tarstream.getNextTarEntry()) != null) {
- String fullName = dataPath() + "/" + e.getName();
+ String fullName = CouchbaseEmbeddedServer.dataPath() + "/" + e.getName();
// Obtain count of files in this archive so that we can indicate install progress
if (filesInArchive == 0 && e.getName().startsWith("filecount")) {
String[] count = e.getName().split("\\.");
@@ -163,7 +154,7 @@ private static void installPackage(String pkg, Handler handler, CouchService ser
tarstream.close();
instream.close();
- FileWriter iLOWriter = new FileWriter(dataPath() + "/" + pkg + ".installedfiles");
+ FileWriter iLOWriter = new FileWriter(CouchbaseEmbeddedServer.dataPath() + "/" + pkg + ".installedfiles");
for (String file : installedfiles) {
iLOWriter.write(file+"\n");
}
@@ -186,21 +177,21 @@ private static void installPackage(String pkg, Handler handler, CouchService ser
iLOWriter.close();
String[][] replacements = new String[][]{
- {"%app_name%", CouchInstaller.appNamespace},
+ {"%app_name%", CouchbaseEmbeddedServer.appNamespace},
{"%sdk_int%", Integer.toString(android.os.Build.VERSION.SDK_INT)}
};
- replace(CouchInstaller.dataPath() + "/erlang/erts-5.7.5/bin/start", replacements);
- replace(CouchInstaller.dataPath() + "/erlang/erts-5.7.5/bin/erl", replacements);
- replace(CouchInstaller.dataPath() + "/erlang/bin/start", replacements);
- replace(CouchInstaller.dataPath() + "/erlang/bin/erl", replacements);
- replace(CouchInstaller.dataPath() + "/couchdb/lib/couchdb/erlang/lib/couch/ebin/couch.app", replacements);
- replace(CouchInstaller.dataPath() + "/couchdb/lib/couchdb/erlang/lib/couch/priv/lib/couch_icu_driver.la", replacements);
- replace(CouchInstaller.dataPath() + "/couchdb/bin/couchdb", replacements);
- replace(CouchInstaller.dataPath() + "/couchdb/bin/couchjs", replacements);
- replace(CouchInstaller.dataPath() + "/couchdb/bin/couchjs_wrapper", replacements);
- replace(CouchInstaller.dataPath() + "/couchdb/etc/couchdb/default.ini", replacements);
- replace(CouchInstaller.dataPath() + "/couchdb/etc/couchdb/default.d/android.default.ini", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/erlang/erts-5.7.5/bin/start", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/erlang/erts-5.7.5/bin/erl", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/erlang/bin/start", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/erlang/bin/erl", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/couchdb/lib/couchdb/erlang/lib/couch/ebin/couch.app", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/couchdb/lib/couchdb/erlang/lib/couch/priv/lib/couch_icu_driver.la", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/couchdb/bin/couchdb", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/couchdb/bin/couchjs", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/couchdb/bin/couchjs_wrapper", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/couchdb/etc/couchdb/default.ini", replacements);
+ replace(CouchbaseEmbeddedServer.dataPath() + "/couchdb/etc/couchdb/default.d/android.default.ini", replacements);
}
/*
@@ -209,7 +200,7 @@ private static void installPackage(String pkg, Handler handler, CouchService ser
*/
public static boolean checkInstalled(String pkg) {
- File file = new File(dataPath() + "/" + pkg + ".installedfiles");
+ File file = new File(CouchbaseEmbeddedServer.dataPath() + "/" + pkg + ".installedfiles");
if (!file.exists()) {
return false;
}
View
3  src/com/couchbase/libcouch/CouchService.java
@@ -61,7 +61,6 @@ public void handleMessage(Message msg) {
*/
@Override
public void onCreate() {
- CouchInstaller.appNamespace = this.getApplication().getPackageName();
couch.service = this;
}
@@ -117,7 +116,7 @@ void couchStarted() throws RemoteException {
}
void startCouch() {
- couch.start("/system/bin/sh", CouchInstaller.dataPath() + "/couchdb/bin/couchdb", "", mHandler);
+ couch.start("/system/bin/sh", CouchbaseEmbeddedServer.dataPath() + "/couchdb/bin/couchdb", "", mHandler);
}
void installCouch(final String pkg) {
View
96 src/com/couchbase/libcouch/CouchbaseEmbeddedServer.java
@@ -0,0 +1,96 @@
+package com.couchbase.libcouch;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Environment;
+import android.os.IBinder;
+import android.os.RemoteException;
+
+/*
+ * This is the minimal API for building against Android-Couchbase, its
+ * main function is to allow developers to start Couchbase and contains
+ * some utility functions
+ */
+public class CouchbaseEmbeddedServer {
+
+ /* Tag used for log messages */
+ public final static String TAG = "Couchbase";
+
+ /* The application name (eg: com.dale.fubar) */
+ public static String appNamespace;
+
+ /* The name of the binary package of Couchbase stored in assets */
+ private static String releaseName;
+
+ /*
+ * The default package name of couchdb binaries, applications are
+ * recommended to use this default package name as it ensures this library
+ * was built to support these binaries
+ */
+ private final static String defaultRelease = "couchbase-1.0-dp-be9fe2f";
+
+ private static ICouchService couchService;
+ private static ICouchClient couchClient;
+ private static Context ctx;
+
+ /*
+ * A few of the utility functions require some of the same context
+ * that cannot be gotten automatically, so made this a class to
+ * store some context for later functions
+ */
+ public CouchbaseEmbeddedServer(Context appCtx, ICouchClient client) {
+ couchClient = client;
+ ctx = appCtx;
+ appNamespace = ctx.getPackageName();
+ }
+
+ /* The path to this apps internal memory */
+ public static String dataPath() {
+ return "/data/data/" + CouchbaseEmbeddedServer.appNamespace;
+ }
+
+ /* The path to this apps external (sdcard) memory */
+ public static String externalPath() {
+ return Environment.getExternalStorageDirectory() + "/Android/data/" + CouchbaseEmbeddedServer.appNamespace;
+ }
+
+ /* Start Couchbase with the default binaries */
+ public ServiceConnection startCouchbase() {
+ return startCouchbase(ctx, defaultRelease);
+ }
+
+ /*
+ * Start Couchbase, this starts Couchbase as an android service, the ServiceConnection
+ * returned allowed for futher communication (such as install progress / started
+ * callbacks), check the ICouchClient.aidl and ICouchServer.aidl for the definition
+ * of these callbacks
+ */
+ public ServiceConnection startCouchbase(Context ctx, String release) {
+ releaseName = release;
+ ctx.bindService(new Intent(ctx, CouchService.class), mConnection, Context.BIND_AUTO_CREATE);
+ return mConnection;
+ }
+
+ /*
+ * This holds the connection to the CouchDB Service
+ */
+ private final static ServiceConnection mConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName className, final IBinder service) {
+ try {
+ couchService = ICouchService.Stub.asInterface(service);
+ couchService.initCouchDB(couchClient, releaseName);
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName className) {
+ couchService = null;
+ }
+ };
+}
Please sign in to comment.
Something went wrong with that request. Please try again.