emscripten Humble Cloud interface
Edward Rudd
2014-08-19 77b56602a23b778494ba7e67dc3e438bac21bdfa

use humble_cloud naming for C functions add header and export some "test" functions to be called from the JS

3 files modified
1 files added
58 ■■■■ changed files
CMakeLists.txt 3 ●●●●● patch | view | raw | blame | history
humble_cloud.h 14 ●●●●● patch | view | raw | blame | history
humble_cloud.js 5 ●●●●● patch | view | raw | blame | history
main.cpp 36 ●●●● patch | view | raw | blame | history
CMakeLists.txt
@@ -7,6 +7,9 @@
CreateProgram(TestApp
FILES
    main.cpp
ASM_FLAG
    NO_EXIT_RUNTIME=1
    EXPORTED_FUNCTIONS="['_main','_test_list_files']"
JS_LIBS
    ${CMAKE_CURRENT_SOURCE_DIR}/humble_cloud.js
)
humble_cloud.h
New file
@@ -0,0 +1,14 @@
#ifndef __HUMBLE_CLOUD_H__
#define __HUMBLE_CLOUD_H__
#ifdef __cplusplus
extern "C" {
#endif
    bool humble_cloud_init();
#ifdef __cplusplus
};
#endif
#endif // __HUMBLE_CLOUD_H__
humble_cloud.js
@@ -7,12 +7,13 @@
        staticInit: function() {
            console.log('Humble Cloud Init');
            addRunDependency('HUMBLE_CLOUD');
            FS.createFolder('/', 'user_data', true, true);
            console.log('Doing stuff to synchronize files');
            removeRunDependency('HUMBLE_CLOUD');
        }
    },
    humble_fs_sync: function() {
        console.log("Hello Syncing");
    humble_cloud_init: function() {
        // Dummy function to pull in the rest of the functions
    }
};
main.cpp
@@ -2,20 +2,36 @@
#include <emscripten/emscripten.h>
extern "C" {
    extern bool humble_fs_sync();
};
#include "humble_cloud.h"
#include <dirent.h>
extern "C" {
    void test_list_files();
}
std::string userPath = "/user_data";
void test_list_files()
{
    std::cout << "Listing Files\n";
    DIR *d = opendir(userPath.c_str());
    if (d)
    {
        struct dirent *entry = NULL;
        while((entry = readdir(d)))
        {
            std::cout << entry->d_name << "\n";
        }
        closedir(d);
    }
}
int main(int argc, char * argv[])
{
    std::cout << "External JS Test\n";
    std::cout << "Calling sync method\n";
    humble_fs_sync();
    std::cout << "Sync triggered\n";
    std::cout << "Welcome Main\n";
    // call dummy function to init cloud
    humble_cloud_init();
    return 0;
}