mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
- IOChannel, IOChannelConfig, ActiveIOChannel
- ActiveMethod::operator () default argument value (convenient for arguments of Poco::Void type)
This commit is contained in:
93
Foundation/src/IOChannel.cpp
Normal file
93
Foundation/src/IOChannel.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// IOChannel.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/IOChannel.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: IO
|
||||
// Module: IOChannel
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/IOChannel.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
IOChannel::IOChannel(const std::string& name):
|
||||
_name(name),
|
||||
_pConfig(new IOChannelConfig)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IOChannel::IOChannel(IOChannelConfig* pConfig, const std::string& name):
|
||||
_name(name),
|
||||
_pConfig(pConfig)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IOChannel::~IOChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
char IOChannel::read()
|
||||
{
|
||||
char readBuf = 0;
|
||||
char* pReadBuf = &readBuf;
|
||||
readData(pReadBuf, 1);
|
||||
return readBuf;
|
||||
}
|
||||
|
||||
|
||||
std::string& IOChannel::read(std::string& buffer, int length)
|
||||
{
|
||||
buffer.clear();
|
||||
char* pBuf = 0;
|
||||
int len = 0;
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
pBuf = static_cast<char*>(std::calloc(length, sizeof(char)));
|
||||
len = readData(pBuf, length);
|
||||
}
|
||||
else
|
||||
len = readData(pBuf); // must allocate buffer as needed
|
||||
|
||||
if (len > 0) buffer.assign(pBuf, len);
|
||||
|
||||
std::free(pBuf);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
67
Foundation/src/IOChannelConfig.cpp
Normal file
67
Foundation/src/IOChannelConfig.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// SerialConfig.cpp
|
||||
//
|
||||
// $Id: //poco/Main/IO/src/IOChannelConfig.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: IO
|
||||
// Module: IOChannelConfig
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/IOChannelConfig.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
IOChannelConfig::IOChannelConfig(const std::string& name, ChannelType type, int timeoutMS):
|
||||
_name(name),
|
||||
_type(type),
|
||||
_timeoutMS(timeoutMS)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IOChannelConfig::~IOChannelConfig()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IOChannelConfig::setTimeout(int timeoutMS)
|
||||
{
|
||||
if (timeoutMS < 0 && INFINITE_TIMEOUT != timeoutMS)
|
||||
throw InvalidArgumentException("Invalid timeout value");
|
||||
|
||||
_timeoutMS = timeoutMS;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::IO
|
||||
111
Foundation/src/IOChannelStream.cpp
Normal file
111
Foundation/src/IOChannelStream.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// DigestStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.2/IO/src/IOChannelStream.cpp#1 $
|
||||
//
|
||||
// Library: IO
|
||||
// Package: IO
|
||||
// Module: IOChannelStream
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/IOChannelStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
IOChannelStreamBuf::IOChannelStreamBuf(IOChannel& channel): _channel(channel)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IOChannelStreamBuf::~IOChannelStreamBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void IOChannelStreamBuf::close()
|
||||
{
|
||||
_channel.close();
|
||||
}
|
||||
|
||||
|
||||
UnbufferedStreamBuf::int_type IOChannelStreamBuf::readFromDevice()
|
||||
{
|
||||
return charToInt(_channel.read());
|
||||
}
|
||||
|
||||
|
||||
UnbufferedStreamBuf::int_type IOChannelStreamBuf::writeToDevice(char c)
|
||||
{
|
||||
return _channel.write(c);
|
||||
}
|
||||
|
||||
|
||||
IOChannelIOS::IOChannelIOS(IOChannel& channel, openmode mode) :_buf(channel)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
IOChannelIOS::~IOChannelIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IOChannelStreamBuf* IOChannelIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
IOChannelOutputStream::IOChannelOutputStream(IOChannel& channel):
|
||||
IOChannelIOS(channel, std::ios::out),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IOChannelOutputStream::~IOChannelOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IOChannelInputStream::IOChannelInputStream(IOChannel& channel):
|
||||
IOChannelIOS(channel, std::ios::in),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
IOChannelInputStream::~IOChannelInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
Reference in New Issue
Block a user