Giter Club home page Giter Club logo

psicash-lib-core's Introduction

PsiCash Client Library

This is the C++ core of the library. It can be used directly or wrapped with native-language glue. For example, for Android there is a Java (JNI) glue wrapper.

Using the library

Supplying the HTTP Requester

This library relies on the native environment to provide an HTTP request callback. Notes about its signature, inputs and outputs can be found in psicash.hpp.

There is an example implementation in the Android wrapper project. But note that it does not support proxied requests, which may be necessary depending on the environment. (E.g., it probably doesn't matter on iOS, since our app only supported full-device VPN. But on Windows the app mostly uses a local proxy, so the HTTP Requester must support proxying.)

Note that the requester must do HTTPS certificate validation.

Thread Safety

All datastore reads and writes are mutexed. So, the only consistency guarantee is for individual data accesses. This means that multiple data accesses might get data from different states; for example, between getting the balance and getting the purchases list, there might have been a purchase, which would alter the balance. We will state this in positive terms as: "you will always get the very latest value". This is fine for our use cases at this time, but we might want to add "get a consistent set of data" in the future.

Platform-specific wrapper library implementations should not need additional synchronization. If more is needed, it should probably be added to the core library.

Code Style

C++

Mostly following Google's Style Guide. Major alteration: 4-space indent instead of 2. THe .clang-format file should be crafted as necessary to match what we want.

Review notes

  • I made no effort to be memory efficient (such as explicitly using move semantics, references, etc.). I tried to be clear and safe above efficiency. If there's a leak, that's a bug. If there's gross memory inefficiency, it can probably be improved. But we shouldn't bother with small efficiencies.

Troubleshooting

If Android Studio is saying that a new .cpp file is not part of the project, go to the "Build" menu and click "Refresh Linked C++ Projects". Then rebuild.

If you get a SIGABRT error in JNI code: You have probably triggered a JNI exception (that hasn't been cleared). It's possible that it's expected or acceptable and you just need to clear it, but it's more likely that it's a bug.

If you get a SIGSEGV error when hitting a breakpoint in JNI code: Yeah, beats me. I get it on MacOS but not Windows.

State diagram

   +-----------+
   |           |
   | no tokens +<----------------------------+
   |           |                             |
   +-----+-----+                             |
         |                                   |
         +                                   |
 RefreshState+NewTracker                     |
         +                                   |
         |                                   |
         v                                   |
+--------+--------+                          +
|                 |                      ResetUser()
| Tracker tokens  |                          +
|                 |                          |
+--------+--------+                          |
         |                                   |
         +                                   |
       Login                                 |
         +                                   |
         v                             +-----+------------------------+
+--------+--------+    token expiry    |                              |
|                 +------------------->+  IsAccount() && !HasTokens() |
|  Account tokens |                    |                              |
|                 +------------------->+        "logged out"          |
+--------------+--+   AccountLogout()  |                              |
               ^                       +--+---------------------------+
               |                          |
               +--------------------------+
                     AccountLogin()

psicash-lib-core's People

Contributors

adam-p avatar adotkhan avatar

Stargazers

 avatar  avatar

Watchers

 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.