Sfoglia il codice sorgente

Remove NetworkFile*

Daniele Bartolini 10 anni fa
parent
commit
92ade5b392

+ 0 - 152
src/core/filesystem/network_file.cpp

@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#include "json_parser.h"
-#include "container_types.h"
-#include "log.h"
-#include "math_utils.h"
-#include "network_file.h"
-#include "network_filesystem.h"
-#include "string_stream.h"
-#include "string_utils.h"
-#include "temp_allocator.h"
-#include "types.h"
-#include "dynamic_string.h"
-
-namespace crown
-{
-
-NetworkFile::NetworkFile(const NetAddress& addr, uint16_t port, const char* filename)
-	: File(FOM_READ)
-	, _address(addr)
-	, _port(port)
-	, _position(0)
-{
-	strncpy(_filename, filename, 1024);
-	_socket.connect(addr, port);
-}
-
-NetworkFile::~NetworkFile()
-{
-	_socket.close();
-}
-
-void NetworkFile::seek(uint32_t position)
-{
-	_position = position;
-}
-
-void NetworkFile::seek_to_end()
-{
-	_position = size();
-}
-
-void NetworkFile::skip(uint32_t bytes)
-{
-	_position += bytes;
-}
-
-void NetworkFile::read(void* buffer, uint32_t size)
-{
-	using namespace string_stream;
-
-	TempAllocator1024 alloc;
-	StringStream command(alloc);
-
-	// Request the file
-	command << "{\"type\":\"filesystem\",\"filesystem\":\"read\",";
-	command << "\"file\":\"" << _filename << "\",";
-	command << "\"position\":" << _position << ",";
-	command << "\"size\":" << size << "}";
-
-	network_filesystem::send(_socket, c_str(command));
-
-	// Wait for response
-	Array<char> response(default_allocator());
-	network_filesystem::read_response(_socket, response);
-
-	// Parse the response
-	JSONParser json(array::begin(response));
-	JSONElement root = json.root();
-
-	// DynamicString data_base64;
-	// root.key("data").to_string(data_base64);
-
-	// uint32_t out_len = 0;
-	// unsigned char* data = base64_decode(data_base64.c_str(), data_base64.length(), &out_len);
-	// memcpy(buffer, data, sizeof(unsigned char) * out_len);
-	// default_allocator().deallocate(data);
-}
-
-void NetworkFile::write(const void* /*buffer*/, uint32_t /*size*/)
-{
-	CE_FATAL("Cannot write to a network file");
-}
-
-bool NetworkFile::copy_to(File& file, uint32_t size)
-{
-	return true;
-}
-
-bool NetworkFile::end_of_file()
-{
-	return position() == size();
-}
-
-bool NetworkFile::is_valid()
-{
-	return true;
-}
-
-void NetworkFile::flush()
-{
-	// Do nothing
-}
-
-uint32_t NetworkFile::position()
-{
-	return _position;
-}
-
-uint32_t NetworkFile::size()
-{
-	using namespace string_stream;
-
-	TempAllocator1024 alloc;
-	StringStream command(alloc);
-
-	// Request the file
-	command << "{\"type\":\"filesystem\",\"filesystem\":\"size\",";
-	command << "\"file\":\"" << _filename << "\"}";
-
-	network_filesystem::send(_socket, c_str(command));
-
-	// Wait for response
-	Array<char> response(default_allocator());
-	network_filesystem::read_response(_socket, response);
-
-	JSONParser parser(array::begin(response));
-	JSONElement root = parser.root();
-
-	return (uint32_t) root.key("size").to_int();
-}
-
-bool NetworkFile::can_read() const
-{
-	return true;
-}
-
-bool NetworkFile::can_write() const
-{
-	return false;
-}
-
-bool NetworkFile::can_seek() const
-{
-	return true;
-}
-
-} // namespace crown
-

+ 0 - 78
src/core/filesystem/network_file.h

@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "error.h"
-#include "socket.h"
-#include "os.h"
-#include "file.h"
-
-namespace crown
-{
-
-/// Access file on a remote file server.
-///
-/// @ingroup Filesystem
-class NetworkFile: public File
-{
-public:
-
-	/// Reads the file named @a filename from the given @a socket.
-	NetworkFile(const NetAddress& addr, uint16_t port, const char* filename);
-	virtual ~NetworkFile();
-
-	/// @copydoc File::seek()
-	void seek(uint32_t position);
-
-	/// @copydoc File::seek_to_end()
-	void seek_to_end();
-
-	/// @copydoc File::skip()
-	void skip(uint32_t bytes);
-
-	/// @copydoc File::read()
-	void read(void* buffer, uint32_t size);
-
-	/// @copydoc File::write()
-	void write(const void* buffer, uint32_t size);
-
-	/// @copydoc File::copy_to()
-	bool copy_to(File& file, uint32_t size = 0);
-
-	/// @copydoc File::flush()
-	void flush();
-
-	/// @copydoc File::end_of_file()
-	bool end_of_file();
-
-	/// @copydoc File::is_valid()
-	bool is_valid();
-
-	/// @copydoc File::size()
-	uint32_t size();
-
-	/// @copydoc File::position()
-	uint32_t position();
-
-	/// @copydoc File::can_read()
-	bool can_read() const;
-
-	/// @copydoc File::can_write()
-	bool can_write() const;
-
-	/// @copydoc File::can_seek()
-	bool can_seek() const;
-
-private:
-
-	char _filename[1024];
-	NetAddress _address;
-	uint16_t _port;
-	TCPSocket _socket;
-	uint32_t _position;
-};
-
-} // namespace crown

+ 0 - 85
src/core/filesystem/network_filesystem.cpp

@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#include "json_parser.h"
-#include "network_file.h"
-#include "network_filesystem.h"
-#include "os.h"
-#include "string_utils.h"
-#include "temp_allocator.h"
-#include "string_stream.h"
-
-namespace crown
-{
-
-NetworkFilesystem::NetworkFilesystem()
-{
-}
-
-NetworkFilesystem::NetworkFilesystem(const NetAddress& addr, uint16_t port)
-	: _address(addr)
-	, _port(port)
-{
-}
-
-File* NetworkFilesystem::open(const char* path, FileOpenMode mode)
-{
-	return CE_NEW(default_allocator(), NetworkFile)(_address, _port, path);
-}
-
-void NetworkFilesystem::close(File* file)
-{
-	CE_ASSERT_NOT_NULL(file);
-	CE_DELETE(default_allocator(), file);
-}
-
-bool NetworkFilesystem::exists(const char* path)
-{
-	return false;
-}
-
-bool NetworkFilesystem::is_directory(const char* path)
-{
-  return false;
-}
-
-bool NetworkFilesystem::is_file(const char* path)
-{
-  return false;
-}
-
-void NetworkFilesystem::create_directory(const char* /*path*/)
-{
-}
-
-void NetworkFilesystem::delete_directory(const char* /*path*/)
-{
-}
-
-void NetworkFilesystem::create_file(const char* /*path*/)
-{
-}
-
-void NetworkFilesystem::delete_file(const char* /*path*/)
-{
-}
-
-void NetworkFilesystem::list_files(const char* /*path*/, Vector<DynamicString>& /*files*/)
-{
-}
-
-void NetworkFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
-{
-
-}
-
-TCPSocket NetworkFilesystem::new_connection()
-{
-	TCPSocket socket;
-	socket.connect(_address, _port);
-	return socket;
-}
-
-} // namespace crown

+ 0 - 105
src/core/filesystem/network_filesystem.h

@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "filesystem.h"
-#include "socket.h"
-#include "os.h" // for max_path_length
-#include "log.h"
-
-namespace crown
-{
-namespace network_filesystem
-{
-	inline void read_response(TCPSocket socket, Array<char>& response)
-	{
-		// Read message length
-		uint32_t msg_len = 0;
-		socket.read(&msg_len, 4);
-
-		array::resize(response, msg_len);
-		socket.read(array::begin(response), msg_len);
-
-		// Ensure NUL-terminated
-		array::push_back(response, '\0');
-	}
-
-	inline void send(TCPSocket socket, const char* msg)
-	{
-		uint32_t msg_len = strlen(msg);
-		socket.write(&msg_len, 4);
-		socket.write(msg, msg_len);
-	}
-} // namespace network_filesystem
-
-/// Access files on a remote file server.
-/// All the file paths can be either relative or absolute.
-/// When a relative path is given, it is automatically translated
-/// to its absolute counterpart based on the file server's root path.
-/// Accessing files using absolute path directly is also possible,
-/// but platform-specific and thus generally not recommended.
-///
-/// @ingroup Filesystem
-class NetworkFilesystem : public Filesystem
-{
-public:
-
-	/// Sets the root path to the current working directory of
-	/// the engine executable.
-	NetworkFilesystem();
-
-	/// Sets the file server address and port.
-	/// @note
-	/// The @a root_path must be absolute.
-	NetworkFilesystem(const NetAddress& addr, uint16_t port);
-
-	/// Opens the file at the given @a path with the given @a mode.
-	File* open(const char* path, FileOpenMode mode);
-
-	/// Closes the given @a file.
-	void close(File* file);
-
-	/// Returns whether @a path exists.
-	bool exists(const char* path);
-
-	/// Returns true if @a path is a directory.
-	bool is_directory(const char* path);
-
-	/// Returns true if @a path is a regular file.
-	bool is_file(const char* path);
-
-	/// Creates the directory at the given @a path.
-	void create_directory(const char* path);
-
-	/// Deletes the directory at the given @a path.
-	void delete_directory(const char* path);
-
-	/// Creates the file at the given @a path.
-	void create_file(const char* path);
-
-	/// Deletes the file at the given @a path.
-	void delete_file(const char* path);
-
-	/// Returns the relative file names in the given @a path.
-	void list_files(const char* path, Vector<DynamicString>& files);
-
-	/// Returns the absolute path of the given @a path based on
-	/// the root path of the file source. If @a path is absolute,
-	/// the given path is returned.
-	void get_absolute_path(const char* path, DynamicString& os_path);
-
-private:
-
-	// Returns a new connection to the file server
-	TCPSocket new_connection();
-
-private:
-
-	NetAddress _address;
-	uint16_t _port;
-};
-
-} // namespace crown