/*
Network File IO
Copyright (C) 2006 David Voswinkel

Homepage: http://optixx.org
E-mail:   david@optixx.org

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <sys/select.h>
#include <errno.h>
#include <curl/curl.h>

/* Server URI */
#define NET_IO_URI		"http://192.168.1.100:3333"
/* Remote Dir */
#define NET_IO_DIR		"/home/david/media/movies/psp/"
/* Index to WLAN Config */
#define NET_IO_CON		0
/* Enable net module */
#define NET_IO_ENABLED		1
/* alloc buffer for dirlist */
#define NET_IO_MAX_DIR_BUFFER   8192


//#define NET_IO_DEBUG		0
#define NET_IO_TEST_FILE "net://home/david/media/movies/psp/simpsons.avi"

#ifndef net_io_h
#define net_io_h

enum protocols  { FILE_IO = 0,NET_IO = 1};

typedef struct netfd {
    CURL	*curl;
    CURLcode	res;
    int		fd;	
    double	speed;
} netfd;

struct __netfd {
    int init; 
    int	fd;
    int	seek_offset;
    int err;
    int read_offset;
    void * read_buffer;
    int  dir_offset;
    void * dir_buffer;
    SceUID sema_open;
    SceUID sema_read;
    SceUID sema_lseek;
    SceUID sema_close;
    SceUID sema_listdir;
} __netfd;


int net_io_connect(int config);
int net_io_init();
void net_io_shutdown();
netfd *net_io_open(const char *filename);
int net_io_close( netfd *fd);
int net_io_read( netfd *fd,void *read_buffer, int size);
int net_io_lseek( netfd *fd,int offset, int whence);
int net_io_listdir(char * path, void *dir_buffer,int max_buffer_size);
enum protocols  net_io_isnet(char * filename);


#endif
