Giter Club home page Giter Club logo

psicash-lib-android's Introduction

Build Status

Android PsiCash Library

This is a C++ core library wrapped in Java/JNI glue for Android. Eventually the C++ will be split out into its own repository (and become a git subtree in this repo).

Usage

The main API entry point is psicashlib/.../PsiCashLib.java. An example usage of it can be found in the included sample app.

The trickiest part is the implementation of the HTTPRequester interface. The sample app has an implementation of it, but that should only be viewed as a rough guide -- it is not intended to be used as-is.

NOTE: If in-app PsiCash functionality is to coexist with browser-only mode, then the HTTPRequester implementation will need to support proxying when the tunnel is connected.

NOTE: The PsiCash rule about no automatic untunneled requests remains in effect.

Thread considerations

All library methods are synchronized. All methods are synchronous/blocking.

Network requests will be made on the same thread the method is called on.

Glue exchange formats

Consideration: Everything can be an error

Almost every JNI glue function has the potential to produce an error (JSON parsing or dumping, JNI string ops). So anything that isn't one of jint, jbyte, jshort, jlong, jfloat, jdouble, jchar, jboolean could produce an error while marshaling.

There are two categories of errors:

  • External to the library. Bad input, unreachable server, etc. These will typically be recoverable.
  • Internal to the library. Incorrect exchange format, JSON marshal failure, storage write error, etc. These will typically be unrecoverable.

Standard structure: JSON

{
    // If not null or absent, an error resulted and "result" should not
    // be considered valid.
    "error": {
        "message": string; nonempty (if error object present),

        // If true, the error probably resulted from programmer error.
        // Logging and reporting should be handled differently.
        "critical": boolean; true iff error is 'critical' and probably unrecoverable
    }

    "result": type varies; actual result of the call
}

The authoritative definition of the return format for each API call will above the call stub in PsiCashLib.java. Description of the arguments to the call will also be there.

Possibilities considered

JSON is kind of a clunky choice for exchanging data across the JNI boundary. It also doesn't give compile-time checks for type/structure-matching, and therefore errors can be introduced that aren't discovered until too late.

So here are some other things that were considered:

We could have written glue code to exchange objects. But in addition to that being a lot of painful code, it still doesn't provide compile-time assurances that the types match (because it relies on runtime lookup of thing -- check the sample code at that link).

SWIG seems like the "best" JNI glue generator. But the interface definition is also kind of... incomprehensible. If we used it, when someone comes along a year later to update it, they won't know what they're looking at.

So I decided that writing the glue in a language we can understand (and are already using, and using the support libraries for) was preferable. The runtime-error problem can be mitigated with a test suite.

psicash-lib-android's People

Contributors

adam-p avatar adamkruger avatar efryntov avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.