<commit_before>#ifndef __IO_INTERFACE_H__
#define __IO_INTERFACE_H__

#include <stdlib.h>

#include <vector>

#include "exception.h"
#include "common.h"
#include "concurrency.h"

class io_request;

class callback
{
public:
	virtual int invoke(io_request *reqs[], int num) = 0;
};

class io_status
{
	long status: 8;
	long priv_data: 56;
public:
	io_status() {
		status = 0;
		priv_data = 0;
	}

	io_status(int status) {
		this->status = status;
		priv_data = 0;
	}

	void set_priv_data(long data) {
		priv_data = data;
	}

	long get_priv_data() const {
		return priv_data;
	}

	io_status &operator=(int status) {
		this->status = status;
		return *this;
	}

	bool operator==(int status) {
		return this->status == status;
	}
};

enum
{
	IO_OK,
	IO_PENDING = -1,
	IO_FAIL = -2,
	IO_UNSUPPORTED = -3,
};

/**
 * The interface for all IO classes.
 */
class io_interface
{
	int node_id;
	// This is an index for locating this IO object in a global table.
	int io_idx;
	static atomic_integer io_counter;
public:
	io_interface(int node_id) {
		this->node_id = node_id;
		this->io_idx = io_counter.inc(1) - 1;
	}

	virtual ~io_interface() { }

	/* When a thread begins, this method will be called. */
	virtual int init() {
		return 0;
	}

	int get_io_idx() const {
		return io_idx;
	}

	/**
	 * set the callback if the class supports the asynchronous fashion.
	 * If the class doesn't support async IO, return false.
	 */
	virtual bool set_callback(callback *cb) {
		return false;
	}

	virtual callback *get_callback() {
		return NULL;
	}

	virtual bool support_aio() {
		return false;
	}

	virtual int get_file_id() const = 0;

	virtual void cleanup() {
	}

	/**
	 * The asynchronous IO interface
	 */

	/**
	 * The main interface to send requests.
	 */
	virtual void access(io_request *requests, int num, io_status *status = NULL) {
		throw unsupported_exception();
	}
	/**
	 * When requests are passed to the access method, an IO layer may buffer
	 * the requests. This method guarantees that all requests are flushed to
	 * the underlying devices.
	 */
	virtual void flush_requests() {
	}
	/**
	 * This method waits for at least the specified number of requests currently
	 * being sent by the access method to complete.
	 */
	virtual void wait4complete() {
	}

	/**<commit_msg>The default behavior of io_interface is to show unsupported exception.<commit_after>#ifndef __IO_INTERFACE_H__
#define __IO_INTERFACE_H__

#include <stdlib.h>

#include <vector>

#include "exception.h"
#include "common.h"
#include "concurrency.h"

class io_request;

class callback
{
public:
	virtual int invoke(io_request *reqs[], int num) = 0;
};

class io_status
{
	long status: 8;
	long priv_data: 56;
public:
	io_status() {
		status = 0;
		priv_data = 0;
	}

	io_status(int status) {
		this->status = status;
		priv_data = 0;
	}

	void set_priv_data(long data) {
		priv_data = data;
	}

	long get_priv_data() const {
		return priv_data;
	}

	io_status &operator=(int status) {
		this->status = status;
		return *this;
	}

	bool operator==(int status) {
		return this->status == status;
	}
};

enum
{
	IO_OK,
	IO_PENDING = -1,
	IO_FAIL = -2,
	IO_UNSUPPORTED = -3,
};

/**
 * The interface for all IO classes.
 */
class io_interface
{
	int node_id;
	// This is an index for locating this IO object in a global table.
	int io_idx;
	static atomic_integer io_counter;
public:
	io_interface(int node_id) {
		this->node_id = node_id;
		this->io_idx = io_counter.inc(1) - 1;
	}

	virtual ~io_interface() { }

	/* When a thread begins, this method will be called. */
	virtual int init() {
		return 0;
	}

	int get_io_idx() const {
		return io_idx;
	}

	/**
	 * set the callback if the class supports the asynchronous fashion.
	 * If the class doesn't support async IO, return false.
	 */
	virtual bool set_callback(callback *cb) {
		return false;
	}

	virtual callback *get_callback() {
		return NULL;
	}

	virtual bool support_aio() {
		return false;
	}

	virtual int get_file_id() const = 0;

	virtual void cleanup() {
	}

	/**
	 * The asynchronous IO interface
	 */

	/**
	 * The main interface to send requests.
	 */
	virtual void access(io_request *requests, int num, io_status *status = NULL) {
		throw unsupported_exception();
	}
	/**
	 * When requests are passed to the access method, an IO layer may buffer
	 * the requests. This method guarantees that all requests are flushed to
	 * the underlying devices.
	 */
	virtual void flush_requests() {
		throw unsupported_exception();
	}
	/**
	 * This method waits for at least the specified number of requests currently
	 * being sent by the access method to complete.
	 */
	virtual void wait4complete() {
		throw unsupported_exception();
	}

	/**
{'fraction_non_alphanumeric': 0.10977958484913332, 'fraction_numerical': 0.006419858763107212, 'mean_word_length': 3.4727272727272727, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2188582', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1571, 'n_words': 515}