emscripten Humble Cloud interface
Edward Rudd
2014-08-21 374e4b0e261ccd2e22c19a9fb63e7cfecc4bfa92

refactor code out to make the HUMBLE CLOUD to simply be CLOUDFS and (eventually) more general

2 files renamed
3 files modified
1 files added
74 ■■■■■ changed files
client/CMakeLists.txt 3 ●●●● patch | view | raw | blame | history
client/library/humble_api.h 4 ●●●● patch | view | raw | blame | history
client/library/library_cloudfs.js 31 ●●●●● patch | view | raw | blame | history
client/library/library_humble.js 14 ●●●●● patch | view | raw | blame | history
client/test/main.cpp 4 ●●●● patch | view | raw | blame | history
client/test/shell.html 18 ●●●● patch | view | raw | blame | history
client/CMakeLists.txt
@@ -23,6 +23,7 @@
    NO_EXIT_RUNTIME=1
    EXPORTED_FUNCTIONS="['_main','_test_list_files']"
JS_LIBS
    ${CMAKE_CURRENT_SOURCE_DIR}/library/humble_cloud.js
    ${CMAKE_CURRENT_SOURCE_DIR}/library/library_cloudfs.js
    ${CMAKE_CURRENT_SOURCE_DIR}/library/library_humble.js
)
client/library/humble_api.h
File was renamed from client/library/humble_cloud.h
@@ -5,9 +5,9 @@
extern "C" {
#endif
    bool humble_cloud_init();
    bool humble_init();
    void humble_cloud_sync();
    void humble_sync();
#ifdef __cplusplus
};
client/library/library_cloudfs.js
File was renamed from client/library/humble_cloud.js
@@ -1,6 +1,6 @@
var LibraryHUMBLE_CLOUD = {
    $HUMBLE_CLOUD__deps: ['$FS', '$MEMFS', '$PATH'],
    $HUMBLE_CLOUD: {
var LibraryCLOUDFS = {
    $CLOUDFS__deps: ['$FS', '$MEMFS', '$PATH'],
    $CLOUDFS: {
        applicationToken: '__NOTOKEN__',
        remoteAPIEndpoint: 'http://asmjs.brigadoon.outoforder.cc/cloud',
@@ -12,10 +12,10 @@
            window.HB_mount = mount;
            console.log("Syncing", mount, populate);
            // re-use IDBFS.getLocalSet for now
            HUMBLE_CLOUD.getLocalSet(mount, function(err, local) {
            CLOUDFS.getLocalSet(mount, function(err, local) {
                if (err) return callback(err);
                HUMBLE_CLOUD.getRemoteSet(mount, function(err, remote) {
                CLOUDFS.getRemoteSet(mount, function(err, remote) {
                    if (err) return callback(err);
                    var src = populate ? remote : local;
@@ -23,6 +23,9 @@
                    console.log('source', src);
                    console.log('destination', dst);
                    // say we completed (for now)
                    callback(null);
                });
            });
        },
@@ -79,8 +82,8 @@
            return callback(null, { type: 'local', entries: entries });
        },
        getRemoteSet: function(mount, callback) {
          var url = HUMBLE_CLOUD.remoteAPIEndpoint + '/storage/files';
            HUMBLE_CLOUD.xhrLoad(url, function(data) {
          var url = CLOUDFS.remoteAPIEndpoint + '/storage/files';
            CLOUDFS.xhrLoad(url, function(data) {
            var entries = {},
                toAbsolute = function(p) { return PATH.join2(mount.mountpoint, p); };
                json = JSON.parse(data);
@@ -110,7 +113,7 @@
              }
              var p = toAbsolute(f.path);
              entries[p] = {
                url: (f.url.substr(0, 1) == '/') ? HUMBLE_CLOUD.remoteAPIEndpoint + f.url : f.url,
                url: (f.url.substr(0, 1) == '/') ? CLOUDFS.remoteAPIEndpoint + f.url : f.url,
                path: f.path.trim('/'),
                timestamp: timestamp,
                size: f.size
@@ -121,16 +124,8 @@
            callback(e || new Error('failed request'));
          });
        }
    },
    humble_cloud_init: function() {
        // Dummy function to pull in the rest of the functions
    },
    humble_cloud_sync: function() {
        FS.syncfs(function(err) {
            console.log('File Sync');
        });
    }
};
autoAddDeps(LibraryHUMBLE_CLOUD, '$HUMBLE_CLOUD');
mergeInto(LibraryManager.library, LibraryHUMBLE_CLOUD);
autoAddDeps(LibraryCLOUDFS, '$CLOUDFS');
mergeInto(LibraryManager.library, LibraryCLOUDFS);
client/library/library_humble.js
New file
@@ -0,0 +1,14 @@
var LibraryHUMBLE = {
    humble_init: function() {
        // Dummy function to pull in the rest of the functions
    },
    humble_sync__deps: ['$FS'],
    humble_sync: function() {
        FS.syncfs(function (err) {
            console.log('File Sync');
        });
    }
};
autoAddDeps(LibraryHUMBLE, '$CLOUDFS');
mergeInto(LibraryManager.library, LibraryHUMBLE);
client/test/main.cpp
@@ -2,7 +2,7 @@
#include <emscripten/emscripten.h>
#include "humble_cloud.h"
#include "humble_api.h"
#include <dirent.h>
@@ -50,7 +50,7 @@
{
    std::cout << "Welcome Main\n";
    // call dummy function to init cloud
    humble_cloud_init();
    humble_init();
    return 0;
}
client/test/shell.html
@@ -1218,6 +1218,7 @@
    </div>
    <textarea id="output" rows="8"></textarea>
    <script type='text/javascript' src="humble_cloud.js"></script>
    <script type='text/javascript'>
      var statusElement = document.getElementById('status');
      var progressElement = document.getElementById('progress');
@@ -1296,20 +1297,27 @@
        };
      };
      Module['preRun'].push(function() {
          addRunDependency('HUMBLE_CLOUD_setup');
          addRunDependency('CLOUDFS_setup');
          FS.createFolder('/', 'user_data', true, true);
          FS.mount(IDBFS, {}, '/user_data');
          FS.createFolder('/', 'user_cloud', true, true);
          FS.mount(HUMBLE_CLOUD, {
              endpoint: 'http://someawesomeserver/',
              applicationtoken: 'deadbeef'
          FS.mount(CLOUDFS, {
              // a list of regexes or string prefixes to synchronize
              sync: [
              ],
              // which provider engine to use.. (looks for an object of that name in the global window object)
              provider: 'HUMBLE_BUNDLE_PROVIDER',
              // configuration sent to the provider
              cloud: {
                  applicationtoken: 'deadbeef'
              }
          }, '/user_cloud');
          FS.syncfs(true, function(err) {
              if(err) console.log('ERROR!', err);
              console.log('finished syncing.. YEAH!!!');
              removeRunDependency('HUMBLE_CLOUD_setup');
              removeRunDependency('CLOUDFS_setup');
          });
      });
      var test_functions = {};