The Design of Kanbox SDK
I wrote an article Cross-platform development with Chromium to describe how to develop an application cross-platform with chromium simply. After a period of efforts, we applied it into Kanbox successfully. Now we can shared the design by this article.
As we saw, there are four layers in the architecture of Kanbox’s SDK:(From bottom to top)
- Chromium Framework: Foundation for “cross-platform”; Encapsulating basic modules such as base(json, serialization, encoding..), net(dns, proxy, http, https..), sql and so on.
- Kanbox Framework: Provides multi-threading, application initialization, global notification, and any other common needed by an application.
- Kanbox SDK: SDK layer of Kanbox implements binsiness relatived functions and exposes API of each module.
- API Layer: API layer of Kanbox supports the API in different platform(such as Objective-C in iOS, Java in Android).It encapsulates the Kanbox SDK’s API by different languages.
2, Thread Model
There will be serval threads while the Kanbox SDK is running:
- UI Thread: This is the UI control working thread, it will be created while application starts.
- API Thread: This is the SDK start up’s thread, which is called the RunKanbox method. It is also responsible for receiving all callback, as we saw above, each API callback will be called on this thread.
- SYNC Thread: There will be many tasks which need to work synchronized, here is the thread to execute tasks and do many calculations.
- IO Thread: It’s for networking such as DNS protocol resolving and HTTP protocol handling.
- FILE Blocking Thread Pool: There will be a thread pool for blocking operation such as file read/write.
The flowchart above shows how the application work with Kanbox SDK and how the Login API works. Btw, UI Response is called through Event BUS on API Thread, Kanbox SDK will be not callback on UI Thread automatically.
3, Physical Form
The graph shows the physical form of Kanbox’s SDK in iOS and Android. In iOS, it is a Fake Framework and supplying API written by Objective-C. In Android, there are jar and so files. The kanbox_sdk.jar exposes the API writtent by Java and called by the application layer.