Update of /cvsroot/pclasses/pclasses2/plugins/IOHandler/file
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5478/plugins/IOHandler/file
Added Files:
Makefile.am IOHandler_file.cpp
Log Message:
- Added IOHandler plugin for file protocol
--- NEW FILE: Makefile.am ---
INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include $(all_includes)
METASOURCES = AUTO
pkglib_LTLIBRARIES = IOHandler_file.la
IOHandler_file_la_SOURCES = IOHandler_file.cpp
IOHandler_file_la_LDFLAGS = -module -avoid-version
IOHandler_file_la_LIBADD = $(top_builddir)/src/libpclasses.la \
$(top_builddir)/src/IO/libpclasses_io.la \
$(top_builddir)/src/System/libpclasses_system.la
--- NEW FILE: IOHandler_file.cpp ---
/***************************************************************************
* Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH *
* cp...@se... *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library 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 Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "pclasses/IO/IOHandler.h"
#include "pclasses/IO/IORequest.h"
#include "pclasses/System/Plugin.h"
#include "pclasses/System/File.h"
#include "pclasses/System/Directory.h"
using namespace P;
using namespace P::IO;
using namespace P::System;
class IORequest_file_Get: public IORequest_Get {
public:
IORequest_file_Get(const URL& url)
: IORequest_Get(url) { }
~IORequest_file_Get() { }
void open()
{
_file.open(url().path(), IODevice::Read, IODevice::OpenFail, IODevice::AllowWrite);
}
void close() { _file.close(); }
size_t read(char* buffer, size_t count)
{
return _file.read(buffer, count);
}
private:
File _file;
};
class IORequest_file_Put: public IORequest_Put {
public:
IORequest_file_Put(const URL& url)
: IORequest_Put(url) { }
~IORequest_file_Put() { }
void open()
{
_file.open(url().path(), IODevice::Write, IODevice::OpenCreate, IODevice::AllowRead);
}
void close() { _file.close(); }
size_t write(const char* buffer, size_t count)
{
return _file.write(buffer, count);
}
private:
File _file;
};
class IORequest_file_Unlink: public IORequest_Unlink {
public:
IORequest_file_Unlink(const URL& url)
: IORequest_Unlink(url) { }
~IORequest_file_Unlink() { }
void open() { }
void close() { }
void doit()
{ File::unlink(url().path()); }
};
class IORequest_file_MakeDir: public IORequest_MakeDir {
public:
IORequest_file_MakeDir(const URL& url)
: IORequest_MakeDir(url) { }
~IORequest_file_MakeDir() { }
void open() { }
void close() { }
void doit()
{ Directory::create(url().path()); }
};
class IORequest_file_RemoveDir: public IORequest_RemoveDir {
public:
IORequest_file_RemoveDir(const URL& url)
: IORequest_RemoveDir(url) { }
~IORequest_file_RemoveDir() { }
void open() { }
void close() { }
void doit()
{ Directory::remove(url().path()); }
};
class IOHandler_file: public IOHandler {
public:
IOHandler_file() { }
~IOHandler_file() { }
IORequest_Get* get(const URL& url)
{ return new IORequest_file_Get(url); }
IORequest_Put* put(const URL& url)
{ return new IORequest_file_Put(url); }
IORequest_Unlink* unlink(const URL& url)
{ return new IORequest_file_Unlink(url); }
IORequest_MakeDir* mkdir(const URL& url)
{ return new IORequest_file_MakeDir(url); }
IORequest_RemoveDir* rmdir(const URL& url)
{ return new IORequest_file_RemoveDir(url); }
IORequest_ListDir* lsdir(const URL& url)
{ return 0; }
void finish(IORequest* req)
{ delete req; }
};
P_PLUGIN_REGISTER_TYPE(IOHandler, IOHandler_file);
P_PLUGIN_REGISTER_ALIAS(IOHandler, file, IOHandler_file);
|