emscripten Humble Cloud interface
Edward Rudd
2015-08-11 ba9e0fa6b07eb964d770793af3292bcb3078d62e
client/test/main.cpp
@@ -5,13 +5,15 @@
#include "humble_api.h"
#include <dirent.h>
#include <sys/stat.h>
extern "C" {
    void test_list_files();
    void test_async_fetch(const char* url);
    void test_demo_end();
}
std::string userDataPath = "/user_data";
std::string userCloudPath = "/user_cloud";
void list_subfolder(const std::string& folder, const std::string& short_folder, const std::string& prefix = "")
{
@@ -27,7 +29,9 @@
            if ((entry->d_type & DT_DIR)>0) {
                list_subfolder(folder + '/' + entry->d_name, entry->d_name, prefix + "  ");
            } else {
                std::cout << prefix << "  " << entry->d_name << "\n";
                struct stat st;
                stat((folder + '/' + entry->d_name).c_str(), &st);
                std::cout << prefix << "  " << entry->d_name << " S:" << st.st_size << "\n";
            }
        }
        closedir(d);
@@ -36,14 +40,38 @@
void list_folder(const std::string& folder)
{
    std::cout << "Listing files\n";
    list_subfolder(folder, folder);
}
void test_list_files()
void EMSCRIPTEN_KEEPALIVE test_list_files()
{
    std::cout << "Listing files\n" ;
    list_folder(userDataPath);
    list_folder(userCloudPath);
    list_folder("/data");
}
void on_get_file(void* arg, void* data, int data_size)
{
    std::cout << "File fetch succeeded: " << data_size << "\n";
    std::string tdata((char *)data, data_size);
    std::cout << "  " << tdata << "\n";
}
void on_fail_file(void *arg)
{
    std::cout << "File fetch failed\n";
}
void EMSCRIPTEN_KEEPALIVE test_async_fetch(const char* url)
{
    std::cout << "Fetch file: " << url << "\n";
    humble_fetch_asset_data(url, NULL, on_get_file, on_fail_file);
}
void EMSCRIPTEN_KEEPALIVE test_demo_end()
{
    std::cout << "Demo has ended\n";
    humble_demo_ended();
}
int main(int argc, char * argv[])
@@ -52,5 +80,10 @@
    // call dummy function to init cloud
    humble_init();
    int w, h;
    int ret = humble_get_player_size(&w, &h);
    std::cout << "HumblePlayerSize Enabled: " << ret << " @ ( " << w << ", " << h << " )\n";
    return 0;
}