﻿/*
 *  TOPPERS/ECNL Prototyping tool
 *
 *  Copyright (C) 2017 Cores Co., Ltd. Japan
 *
 *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
 *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
 *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
 *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
 *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
 *      スコード中に含まれていること．
 *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
 *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
 *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
 *      の無保証規定を掲載すること．
 *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
 *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
 *      と．
 *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
 *        作権表示，この利用条件および下記の無保証規定を掲載すること．
 *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
 *        報告すること．
 *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
 *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
 *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
 *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
 *      免責すること．
 *
 *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
 *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
 *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
 *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
 *  の責任を負わない．
 *
 *  @(#) $Id$
 */
using System;
using Bridge;
using Bridge.Html5;

[External]
public class FileSystem
{
	/// <summary>
	/// Converts a major and minor number into a single unique integer.
	/// This is used as an id to represent the device.
	/// </summary>
	/// <param name="ma">Major number.</param>
	/// <param name="mi">Minor number.</param>
	internal int makedev(int ma, int mi)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Registers the specified device driver with a set of callbacks.
	/// </summary>
	/// <param name="dev">The specific device driver id, created using makedev().</param>
	/// <param name="ops">The set of callbacks required by the device.
	/// For an example, see the NODEFS default callbacks
	/// https://github.com/kripken/emscripten/blob/1.29.12/src/library_nodefs.js#L213</param>
	internal void registerDevice(int dev, object ops)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Sets up standard I/O devices for stdin, stdout, and stderr.
	/// The devices are set up using the following (optional) callbacks.
	/// If any of the callbacks throw an exception,
	/// it will be caught and handled as if the device malfunctioned.
	/// </summary>
	/// <param name="input">Input callback. This will be called with
	/// no parameters whenever the program attempts to read from stdin.
	/// It should return an ASCII character code when data is available,
	/// or null when it isn’t.</param>
	/// <param name="output">Output callback. This will be called with
	/// an ASCII character code whenever the program writes to stdout.
	/// It may also be called with null to flush the output.</param>
	/// <param name="error">Error callback. This is similar to output,
	/// except it is called when data is written to stderr.</param>
	/// <returns></returns>
	internal object init(Delegate input, Delegate output, Delegate error)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Mounts the FS object specified by type to the directory 
	/// specified by mountpoint. The opts object is specific
	/// to each file system type.
	/// </summary>
	/// <param name="type">The file system type: MEMFS, NODEFS, IDBFS or WORKERFS.</param>
	/// <param name="opts">A generic settings object used by the underlying file system.</param>
	/// <param name="mountpoint">A path to an existing local Emscripten directory
	/// where the file system is to be mounted. It can be either an absolute path,
	/// or something relative to the current directory.</param>
	internal void mount(object type, object opts, string mountpoint)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Unmounts the specified mountpoint.
	/// </summary>
	/// <param name="mountpoint">The directory to unmount.</param>
	internal void unmount(string mountpoint)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Responsible for iterating and synchronizing all mounted file systems
	/// in an asynchronous fashion.
	/// </summary>
	/// <param name="populate">true to initialize Emscripten’s file system data
	/// with the data from the file system’s persistent source,
	/// and false to save Emscripten`s file system data
	/// to the file system’s persistent source.</param>
	/// <param name="callback">A notification callback function
	/// that is invoked on completion of the synchronization.
	/// If an error occurred, it will be provided as a parameter to this function.</param>
	internal void syncfs(bool populate, Delegate callback)
	{

	}

	/// <summary>
	/// Creates a new directory node in the file system.
	/// </summary>
	/// <param name="path">The path name for the new directory node.</param>
	/// <param name="mode">File permissions for the new node.
	/// The default setting (in octal numeric notation) is 0777.</param>
	internal void mkdir(string path, int mode)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Creates a new device node in the file system referencing
	/// the registered device driver (FS.registerDevice()) for dev.
	/// </summary>
	/// <param name="path">The path name for the new device node.</param>
	/// <param name="mode">File permissions for the new node.
	/// The default setting (in octal numeric notation) is 0777.</param>
	/// <param name="dev">The registered device driver.</param>
	internal void mkdev(string path, int mode, int dev)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Creates a symlink node at newpath linking to oldpath.
	/// </summary>
	/// <param name="oldpath">The path name of the file to link to.</param>
	/// <param name="newpath">The path to the new symlink node, that points to oldpath.</param>
	internal void symlink(string oldpath, string newpath)
	{
		throw new NotImplementedException();
	}

	internal Stat stat(string path)
	{
		return new Stat();
	}

	internal File open(string path, string flag)
	{
		return new File();
	}

	internal void close(File stream)
	{
	}

	internal void read(File stream, Uint8Array buffer, int offset, int length, int position)
	{
	}

	/// <summary>
	/// Writes the entire contents of data to the file at path.
	/// The value of opts determines whether data is treated
	/// either as a string (encoding = utf8), or as an ArrayBufferView(encoding = binary).
	/// </summary>
	/// <param name="path">The file to which to write data.</param>
	/// <param name="data">The data to write.</param>
	/// <param name="opts">
	/// encoding(string)
	/// 	binary | utf8.The default is utf8
	/// flags(string)
	/// 	Write flags, as defined in FS.open(). The default is ‘w’.
	/// </param>
	internal void writeFile(string path, object data, object opts = null)
	{
		throw new NotImplementedException();
	}

	/// <summary>
	/// Preloads a file asynchronously, and uses preload plugins to prepare its content.
	/// You should call this in preRun, run() will be delayed until all preloaded files are ready.
	/// This is how the preload-file option works in emcc
	/// when --use-preload-plugins has been specified (if you use this method by itself,
	/// you will need to build the program with that option).
	/// </summary>
	/// <param name="parent">The parent folder, either as a path (e.g. ‘/usr/lib’) or
	/// an object previously returned from a FS.createFolder() or FS.createPath() call.</param>
	/// <param name="name">The name of the new file.</param>
	/// <param name="url">In the browser, this is the URL whose contents will be returned
	/// when the file is accessed. In a command line engine,
	/// this will be the local (real) file system path the contents
	/// will be loaded from. Note that writes to this file are virtual.</param>
	/// <param name="canRead">Whether the file should have read permissions set
	/// from the program’s point of view.</param>
	/// <param name="canWrite">Whether the file should have write permissions set
	/// from the program’s point of view.</param>
	internal void createPreloadedFile(string parent, string name, string url, bool canRead, bool canWrite)
	{
		throw new NotImplementedException();
	}

	internal void createFolder(string parent, string name, bool canRead, bool canWrite)
	{
		throw new NotImplementedException();
	}
}

[External]
class Stat
{
	internal int size = 0;
}

[External]
class File
{

}
