[Filesystem] Initial implmentation
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Wed, 11 Feb 2015 09:52:03 +0000 (10:52 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Thu, 12 Feb 2015 10:49:17 +0000 (19:49 +0900)
Change-Id: I2afa0803897becb62220b87e23bbd1114fc635cf
Signed-off-by: Pawel Kaczmarek <p.kaczmarek3@samsung.com>
src/filesystem/filesystem_api.js [new file with mode: 0644]
src/filesystem/filesystem_extension.cc [new file with mode: 0644]
src/filesystem/filesystem_extension.h [new file with mode: 0644]
src/filesystem/filesystem_instance.cc [new file with mode: 0644]
src/filesystem/filesystem_instance.h [new file with mode: 0644]

diff --git a/src/filesystem/filesystem_api.js b/src/filesystem/filesystem_api.js
new file mode 100644 (file)
index 0000000..b27ab12
--- /dev/null
@@ -0,0 +1,576 @@
+/* global tizen, xwalk, extension */
+
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+var utils_ = xwalk.utils;
+var type_ = utils_.type;
+var converter_ = utils_.converter;
+var validator_ = utils_.validator;
+var types_ = validator_.Types;
+var native_ = new xwalk.utils.NativeManager(extension);
+
+var callbackId = 0;
+var callbacks = {};
+
+function nextCallbackId() {
+  return callbackId++;
+}
+
+
+function SetReadOnlyProperty(obj, n, v) {
+  Object.defineProperty(obj, n, {value: v, writable: false});
+}
+
+var FileMode = {
+  r: 'r',
+  rw: 'rw',
+  w: 'w',
+  a: 'a'
+};
+var FileSystemStorageType = {
+  INTERNAL: 'INTERNAL',
+  EXTERNAL: 'EXTERNAL'
+};
+var FileSystemStorageState = {
+  MOUNTED: 'MOUNTED',
+  REMOVED: 'REMOVED',
+  UNMOUNTABLE: 'UNMOUNTABLE'
+};
+
+
+function FileSystemManager() {
+  SetReadOnlyProperty(this, 'maxPathLength', null);
+}
+
+
+FileSystemManager.prototype.resolve = function(location, onsuccess, onerror, mode) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'location', type: types_.STRING},
+    {name: 'onsuccess', type: types_.FUNCTION},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'mode', type: types_.ENUM, values: ['r', 'rw', 'w', 'a'], optional: true, nullable: true}
+  ]);
+
+  var data = {
+    location: args.location,
+    mode: args.mode
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('FileSystemManager_resolve', data, callback);
+};
+
+FileSystemManager.prototype.getStorage = function(label, onsuccess, onerror) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'label', type: types_.STRING},
+    {name: 'onsuccess', type: types_.FUNCTION},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    label: args.label
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('FileSystemManager_getStorage', data, callback);
+};
+
+FileSystemManager.prototype.listStorages = function(onsuccess, onerror) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'onsuccess', type: types_.FUNCTION},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
+  ]);
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('FileSystemManager_listStorages', {}, callback);
+};
+
+FileSystemManager.prototype.addStorageStateChangeListener = function(onsuccess, onerror) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'onsuccess', type: types_.FUNCTION},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
+  ]);
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('FileSystemManager_addStorageStateChangeListener', {}, callback);
+};
+
+FileSystemManager.prototype.removeStorageStateChangeListener = function(watchId) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'watchId', type: types_.LONG}
+  ]);
+
+  var data = {
+    watchId: args.watchId
+  };
+
+  var result = native_.callSync('FileSystemManager_removeStorageStateChangeListener', data);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+
+
+function File() {
+  Object.defineProperties(this, {
+    position: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    readOnly: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    isFile: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    isDirectory: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    created: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    modified: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    path: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    name: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    fullPath: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    length: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    }
+  });
+}
+
+
+File.prototype.toURI = function() {
+  var result = native_.callSync('File_toURI', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return native_.getResultObject(result);
+};
+
+File.prototype.listFiles = function(onsuccess, onerror, filter) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'onsuccess', type: types_.FUNCTION},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'filter', type: types_.DICTIONARY, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    filter: args.filter
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('File_listFiles', data, callback);
+};
+
+File.prototype.openStream = function(mode, onsuccess, onerror, encoding) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'mode', type: types_.ENUM, values: ['r', 'rw', 'w', 'a']},
+    {name: 'onsuccess', type: types_.FUNCTION},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'encoding', type: types_.STRING, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    mode: args.mode,
+    encoding: args.encoding
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess, new FileStream(native_.getResultObject(result)));
+  };
+
+  native_.call('File_openStream', data, callback);
+};
+
+File.prototype.readAsText = function(onsuccess, onerror, encoding) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'onsuccess', type: types_.FUNCTION},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'encoding', type: types_.STRING, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    encoding: args.encoding
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('File_readAsText', data, callback);
+};
+
+File.prototype.copyTo = function(originFilePath, destinationFilePath, overwrite, onsuccess, onerror) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'originFilePath', type: types_.STRING},
+    {name: 'destinationFilePath', type: types_.STRING},
+    {name: 'overwrite', type: types_.BOOLEAN},
+    {name: 'onsuccess', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    originFilePath: args.originFilePath,
+    destinationFilePath: args.destinationFilePath,
+    overwrite: args.overwrite
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('File_copyTo', data, callback);
+};
+
+File.prototype.moveTo = function(originFilePath, destinationFilePath, overwrite, onsuccess, onerror) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'originFilePath', type: types_.STRING},
+    {name: 'destinationFilePath', type: types_.STRING},
+    {name: 'overwrite', type: types_.BOOLEAN},
+    {name: 'onsuccess', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    originFilePath: args.originFilePath,
+    destinationFilePath: args.destinationFilePath,
+    overwrite: args.overwrite
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('File_moveTo', data, callback);
+};
+
+File.prototype.createDirectory = function(dirPath) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'dirPath', type: types_.STRING}
+  ]);
+
+  var data = {
+    dirPath: args.dirPath
+  };
+
+  var result = native_.callSync('File_createDirectory', data);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  var returnObject = new File(native_.getResultObject(result));
+  return returnObject;
+
+};
+
+File.prototype.createFile = function(relativeFilePath) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'relativeFilePath', type: types_.STRING}
+  ]);
+
+  var data = {
+    relativeFilePath: args.relativeFilePath
+  };
+
+  var result = native_.callSync('File_createFile', data);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  var returnObject = new File(native_.getResultObject(result));
+  return returnObject;
+
+};
+
+File.prototype.resolve = function(filePath) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'filePath', type: types_.STRING}
+  ]);
+
+  var data = {
+    filePath: args.filePath
+  };
+
+  var result = native_.callSync('File_resolve', data);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  var returnObject = new File(native_.getResultObject(result));
+  return returnObject;
+
+};
+
+File.prototype.deleteDirectory = function(directoryPath, recursive, onsuccess, onerror) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'directoryPath', type: types_.STRING},
+    {name: 'recursive', type: types_.BOOLEAN},
+    {name: 'onsuccess', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    directoryPath: args.directoryPath,
+    recursive: args.recursive
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('File_deleteDirectory', data, callback);
+
+};
+
+File.prototype.deleteFile = function(filePath, onsuccess, onerror) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'filePath', type: types_.STRING},
+    {name: 'onsuccess', type: types_.FUNCTION, optional: true, nullable: true},
+    {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
+  ]);
+
+  var data = {
+    filePath: args.filePath
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+      return;
+    }
+    native_.callIfPossible(args.onsuccess);
+  };
+
+  native_.call('File_deleteFile', data, callback);
+};
+
+
+function FileStream(fileDescriptor, nodeMode, nodeEncoding) {
+  Object.defineProperties(this, {
+    position: {
+      get: function() {},
+      enumerable: true,
+      writable: false
+    },
+    eof: {
+      get: function() {},
+      set: function() {},
+      enumerable: true
+    },
+    bytesAvailable: {
+      get: function() {},
+      enumerable: true,
+      writable: false
+    }
+  });
+}
+
+FileStream.prototype.close = function() {
+  var result = native_.callSync('FileStream_close', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+FileStream.prototype.read = function() {
+  var args = validator_.validateArgs(arguments, [
+    {
+      name: 'charCount',
+      type: types_.LONG
+    }
+  ]);
+
+  if (args.charCount <= 0) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+        'Argument "charCount" must be greater than 0');
+  }
+
+  var result = native_.callSync('FileStream_read', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+FileStream.prototype.readBytes = function() {
+  var args = validator_.validateArgs(arguments, [
+    {
+      name: 'byteCount',
+      type: types_.LONG
+    }
+  ]);
+
+  if (args.byteCount <= 0) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+        'Argument "byteCount" must be greater than 0');
+  }
+
+  var result = native_.callSync('FileStream_readBytes', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+FileStream.prototype.readBase64 = function() {
+  var args = validator_.validateArgs(arguments, [
+    {
+      name: 'byteCount',
+      type: types_.LONG
+    }
+  ]);
+
+  if (args.byteCount <= 0) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+        'Argument "byteCount" must be greater than 0');
+  }
+
+  var result = native_.callSync('FileStream_readBase64', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+FileStream.prototype.write = function() {
+  var args = validator_.validateArgs(arguments, [
+    {
+      name: 'stringData',
+      type: types_.STRING
+    }
+  ]);
+
+  var result = native_.callSync('FileStream_write', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+FileStream.prototype.writeBytes = function() {
+  var args = validator_.validateArgs(arguments, [
+    {
+      name: 'byteData',
+      type: types_.ARRAY,
+      values: types_.OCTET
+    }
+  ]);
+
+  var result = native_.callSync('FileStream_writeBytes', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+FileStream.prototype.writeBase64 = function() {
+  var args = validator_.validateArgs(arguments, [
+    {
+      name: 'base64Data',
+      type: types_.STRING
+    }
+  ]);
+
+  var result = native_.callSync('FileStream_writeBase64', {});
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+
+exports = new FileSystemManager();
diff --git a/src/filesystem/filesystem_extension.cc b/src/filesystem/filesystem_extension.cc
new file mode 100644 (file)
index 0000000..aa9cc82
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "filesystem/filesystem_extension.h"
+
+#include "filesystem/filesystem_instance.h"
+
+// This will be generated from filesystem_api.js
+extern const char kSource_filesystem_api[];
+
+common::Extension* CreateExtension() {
+  return new FilesystemExtension;
+}
+
+FilesystemExtension::FilesystemExtension() {
+  SetExtensionName("tizen.filesystem");
+  SetJavaScriptAPI(kSource_filesystem_api);
+}
+
+FilesystemExtension::~FilesystemExtension() {}
+
+common::Instance* FilesystemExtension::CreateInstance() {
+  return new extension::filesystem::FilesystemInstance;
+}
diff --git a/src/filesystem/filesystem_extension.h b/src/filesystem/filesystem_extension.h
new file mode 100644 (file)
index 0000000..5451d7c
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef FILESYSTEM_FILESYSTEM_EXTENSION_H_
+#define FILESYSTEM_FILESYSTEM_EXTENSION_H_
+
+#include "common/extension.h"
+
+class FilesystemExtension : public common::Extension {
+ public:
+  FilesystemExtension();
+  virtual ~FilesystemExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+#endif // FILESYSTEM_FILESYSTEM_EXTENSION_H_
diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc
new file mode 100644 (file)
index 0000000..51745d9
--- /dev/null
@@ -0,0 +1,336 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "filesystem/filesystem_instance.h"
+
+#include <functional>
+
+#include "common/picojson.h"
+#include "common/logger.h"
+#include "common/platform_exception.h"
+
+namespace extension {
+namespace filesystem {
+
+namespace {
+// The privileges that required in Filesystem API
+const std::string kPrivilegeFilesystem = "";
+
+} // namespace
+
+using namespace common;
+using namespace extension::filesystem;
+
+FilesystemInstance::FilesystemInstance() {
+  using namespace std::placeholders;
+  #define REGISTER_SYNC(c,x) \
+    RegisterSyncHandler(c, std::bind(&FilesystemInstance::x, this, _1, _2));
+  REGISTER_SYNC("File_moveTo", FileMoveTo);
+  REGISTER_SYNC("FileSystemManager_listStorages", FileSystemManagerListStorages);
+  REGISTER_SYNC("FileSystemManager_resolve", FileSystemManagerResolve);
+  REGISTER_SYNC("FileSystemManager_addStorageStateChangeListener", FileSystemManagerAddStorageStateChangeListener);
+  REGISTER_SYNC("FileSystemManager_removeStorageStateChangeListener", FileSystemManagerRemoveStorageStateChangeListener);
+  REGISTER_SYNC("File_toURI", FileToURI);
+  REGISTER_SYNC("File_resolve", FileResolve);
+  REGISTER_SYNC("File_listFiles", FileListFiles);
+  REGISTER_SYNC("File_deleteDirectory", FileDeleteDirectory);
+  REGISTER_SYNC("File_openStream", FileOpenStream);
+  REGISTER_SYNC("File_createDirectory", FileCreateDirectory);
+  REGISTER_SYNC("File_createFile", FileCreateFile);
+  REGISTER_SYNC("File_deleteFile", FileDeleteFile);
+  REGISTER_SYNC("File_readAsText", FileReadAsText);
+  REGISTER_SYNC("File_copyTo", FileCopyTo);
+  REGISTER_SYNC("FileSystemManager_getStorage", FileSystemManagerGetStorage);
+  #undef REGISTER_SYNC
+}
+
+FilesystemInstance::~FilesystemInstance() {
+}
+
+
+enum FilesystemCallbacks {
+  FileMoveToCallback,
+  FileSystemManagerListStoragesCallback,
+  FileSystemManagerResolveCallback,
+  FileSystemManagerAddStorageStateChangeListenerCallback,
+  FileSystemManagerRemoveStorageStateChangeListenerCallback,
+  FileToURICallback,
+  FileResolveCallback,
+  FileListFilesCallback,
+  FileDeleteDirectoryCallback,
+  FileOpenStreamCallback,
+  FileCreateDirectoryCallback,
+  FileCreateFileCallback,
+  FileDeleteFileCallback,
+  FileReadAsTextCallback,
+  FileCopyToCallback,
+  FileSystemManagerGetStorageCallback
+};
+
+static void ReplyAsync(FilesystemInstance* instance, FilesystemCallbacks cbfunc,
+                       int callbackId, bool isSuccess, picojson::object& param) {
+  param["callbackId"] = picojson::value(static_cast<double>(callbackId));
+  param["status"] = picojson::value(isSuccess ? "success" : "error");
+
+  // insert result for async callback to param
+
+  picojson::value result = picojson::value(param);
+
+  instance->PostMessage(result.serialize().c_str());
+}
+
+#define CHECK_EXIST(args, name, out) \
+    if (!args.contains(name)) {\
+      ReportError(TypeMismatchException(name" is required argument"), out);\
+      return;\
+    }
+
+
+void FilesystemInstance::FileSystemManagerResolve(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "location", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& location = args.get("location").get<std::string>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileSystemManagerGetStorage(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "label", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& label = args.get("label").get<std::string>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileSystemManagerListStorages(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileSystemManagerAddStorageStateChangeListener(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileSystemManagerRemoveStorageStateChangeListener(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "watchId", out)
+
+  double watchId = args.get("watchId").get<double>();
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileToURI(const picojson::value& args, picojson::object& out) {
+
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileListFiles(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileOpenStream(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& encoding = args.get("encoding").get<std::string>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileReadAsText(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& encoding = args.get("encoding").get<std::string>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileCopyTo(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "originFilePath", out)
+  CHECK_EXIST(args, "destinationFilePath", out)
+  CHECK_EXIST(args, "overwrite", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& originFilePath = args.get("originFilePath").get<std::string>();
+  const std::string& destinationFilePath = args.get("destinationFilePath").get<std::string>();
+  bool overwrite = args.get("overwrite").get<bool>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileMoveTo(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "originFilePath", out)
+  CHECK_EXIST(args, "destinationFilePath", out)
+  CHECK_EXIST(args, "overwrite", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& originFilePath = args.get("originFilePath").get<std::string>();
+  const std::string& destinationFilePath = args.get("destinationFilePath").get<std::string>();
+  bool overwrite = args.get("overwrite").get<bool>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileCreateDirectory(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "dirPath", out)
+
+  const std::string& dirPath = args.get("dirPath").get<std::string>();
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileCreateFile(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "relativeFilePath", out)
+
+  const std::string& relativeFilePath = args.get("relativeFilePath").get<std::string>();
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileResolve(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "filePath", out)
+
+  const std::string& filePath = args.get("filePath").get<std::string>();
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileDeleteDirectory(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "directoryPath", out)
+  CHECK_EXIST(args, "recursive", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& directoryPath = args.get("directoryPath").get<std::string>();
+  bool recursive = args.get("recursive").get<bool>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void FilesystemInstance::FileDeleteFile(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "filePath", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+  const std::string& filePath = args.get("filePath").get<std::string>();
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+
+
+#undef CHECK_EXIST
+
+} // namespace filesystem
+} // namespace extension
diff --git a/src/filesystem/filesystem_instance.h b/src/filesystem/filesystem_instance.h
new file mode 100644 (file)
index 0000000..4308a3b
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef FILESYSTEM_FILESYSTEM_INSTANCE_H_
+#define FILESYSTEM_FILESYSTEM_INSTANCE_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace filesystem {
+
+class FilesystemInstance : public common::ParsedInstance {
+ public:
+  FilesystemInstance();
+  virtual ~FilesystemInstance();
+
+ private:
+  void FileMoveTo(const picojson::value& args, picojson::object& out);
+  void FileSystemManagerListStorages(const picojson::value& args, picojson::object& out);
+  void FileSystemManagerResolve(const picojson::value& args, picojson::object& out);
+  void FileSystemManagerAddStorageStateChangeListener(const picojson::value& args, picojson::object& out);
+  void FileSystemManagerRemoveStorageStateChangeListener(const picojson::value& args, picojson::object& out);
+  void FileToURI(const picojson::value& args, picojson::object& out);
+  void FileResolve(const picojson::value& args, picojson::object& out);
+  void FileListFiles(const picojson::value& args, picojson::object& out);
+  void FileDeleteDirectory(const picojson::value& args, picojson::object& out);
+  void FileOpenStream(const picojson::value& args, picojson::object& out);
+  void FileCreateDirectory(const picojson::value& args, picojson::object& out);
+  void FileCreateFile(const picojson::value& args, picojson::object& out);
+  void FileDeleteFile(const picojson::value& args, picojson::object& out);
+  void FileReadAsText(const picojson::value& args, picojson::object& out);
+  void FileCopyTo(const picojson::value& args, picojson::object& out);
+  void FileSystemManagerGetStorage(const picojson::value& args, picojson::object& out);
+};
+
+} // namespace filesystem
+} // namespace extension
+
+#endif // FILESYSTEM_FILESYSTEM_INSTANCE_H_