25#ifndef UCOMMON_SYSRUNTIME
26#ifndef _UCOMMON_STREAM_H_
27#define _UCOMMON_STREAM_H_
29#ifndef _UCOMMON_CONFIG_H
33#ifndef _UCOMMON_PROTOCOLS_H_
37#ifndef _UCOMMON_THREAD_H_
41#ifndef _UCOMMON_SOCKET_H_
45#ifndef _UCOMMON_FSYS_H_
49#ifndef _UCOMMON_SHELL_H_
64class __EXPORT StreamBuffer :
protected std::streambuf,
public std::iostream
67 __DELETE_COPY(StreamBuffer);
83 int uflow() __OVERRIDE;
87 void allocate(
size_t size);
94 int sync(
void) __OVERRIDE;
96 inline
bool is_open(
void)
const
99 inline operator bool()
const
100 {
return bufsize > 0;}
102 inline bool operator!()
const
103 {
return bufsize == 0;}
114class __EXPORT tcpstream :
public StreamBuffer
117 __LOCAL
void allocate(
unsigned size);
118 __LOCAL
void reset(
void);
124 virtual ssize_t _read(
char *buffer,
size_t size);
126 virtual ssize_t _write(
const char *buffer,
size_t size);
128 virtual bool _wait(
void);
141 int underflow(
void) __OVERRIDE;
149 int overflow(
int ch) __OVERRIDE;
151 inline socket_t getsocket(
void)
const {
160 tcpstream(
const tcpstream& copy);
168 tcpstream(
const TCPServer *server,
unsigned segsize = 536, timeout_t timeout = 0);
175 tcpstream(
int family = PF_INET, timeout_t timeout = 0);
185 tcpstream(Socket::address& address,
unsigned segsize = 536, timeout_t timeout = 0);
190 virtual ~tcpstream();
196 inline operator bool()
const {
197 return so != INVALID_SOCKET && bufsize > 0;
204 inline bool operator!()
const {
205 return so == INVALID_SOCKET || bufsize == 0;
213 void open(Socket::address& address,
unsigned segment = 536);
221 void open(
const char *host,
const char *service,
unsigned segment = 536);
237class __EXPORT pipestream :
public StreamBuffer
247 __LOCAL
void allocate(
size_t size, access_t mode);
249 __DELETE_COPY(pipestream);
266 int underflow(
void) __OVERRIDE;
275 int overflow(
int ch) __OVERRIDE;
291 pipestream(
const char *command, access_t access,
char **args,
char **env = NULL,
size_t size = 512);
296 virtual ~pipestream();
302 inline operator bool()
const {
303 return (bufsize > 0);
310 inline bool operator!()
const {
322 void open(
const char *path, access_t access,
char **args,
char **env = NULL,
size_t buffering = 512);
333 void terminate(
void);
335 inline void cancel(
void) {
347class __EXPORT filestream :
public StreamBuffer
357 __LOCAL
void allocate(
size_t size, fsys::access_t mode);
369 int underflow(
void) __OVERRIDE;
378 int overflow(
int ch) __OVERRIDE;
389 filestream(
const filestream& copy);
394 filestream(
const char *path,
unsigned mode, fsys::access_t access,
size_t bufsize = 512);
399 filestream(
const char *path, fsys::access_t access,
size_t bufsize = 512);
404 virtual ~filestream();
410 inline operator bool()
const {
411 return (bufsize > 0);
418 inline bool operator!()
const {
425 void open(
const char *filename, fsys::access_t access,
size_t buffering = 512);
430 void open(
const char *filename,
unsigned mode, fsys::access_t access,
size_t buffering = 512);
440 void seek(fsys::offset_t offset);
448 inline int err(
void)
const
456class __EXPORT imemstream :
protected std::streambuf,
public std::istream
459 __DELETE_DEFAULTS(imemstream);
462 const uint8_t *pos, *bp;
465 imemstream(
const uint8_t *data,
size_t size);
466 imemstream(
const char *data);
468 int underflow() __OVERRIDE;
470 int uflow() __OVERRIDE;
472 inline
size_t remains()
const {
476 inline const uint8_t *mem()
const {
480 inline const char *chr()
const {
481 return (
const char *)bp;
484 inline size_t len()
const {
485 return (
size_t)(pos - bp) + count;
492class __EXPORT omemstream :
protected std::streambuf,
public std::ostream
495 __DELETE_DEFAULTS(omemstream);
502 explicit omemstream(uint8_t *data,
size_t size);
503 omemstream(
char *data,
size_t size);
505 int overflow(
int ch) __OVERRIDE;
507 inline size_t remains()
const {
511 inline uint8_t *mem()
const {
515 inline char *chr()
const {
519 inline size_t len()
const {
520 return (
size_t)(pos - bp);
524bool __EXPORT getline(std::istream& in,
char *buffer,
size_t size);
526bool __EXPORT putline(std::ostream& out,
const char *buffer);
532class __EXPORT _stream_operators
535 __DELETE_DEFAULTS(_stream_operators);
538 static std::ostream& print(std::ostream& out,
const PrintProtocol& format);
540 static std::istream& input(std::istream& inp, InputProtocol& format);
542 static std::ostream& print(std::ostream& out,
const string_t& str);
544 static std::istream& input(std::istream& inp, string_t& str);
546 static std::ostream& print(std::ostream& out,
const stringlist_t& list);
548 static std::istream& input(std::istream& in, stringlist_t& list);
550 static std::string& append(std::string& target, String& source);
553inline std::ostream& operator<< (std::ostream& out,
const PrintProtocol& format) {
554 return _stream_operators::print(out, format);
557inline std::istream& operator>> (std::istream& inp, InputProtocol& format) {
558 return _stream_operators::input(inp, format);
561inline std::ostream& operator<< (std::ostream& out,
const string_t& str) {
562 return _stream_operators::print(out, str);
565inline std::istream& operator>> (std::istream& inp,
string_t& str) {
566 return _stream_operators::input(inp, str);
569inline std::ostream& operator<< (std::ostream& out,
const stringlist_t& list) {
570 return _stream_operators::print(out, list);
573inline std::istream& operator>> (std::istream& in,
stringlist_t& list) {
574 return _stream_operators::input(in, list);
577inline std::string& operator+(std::string& target, String& source) {
578 return _stream_operators::append(target, source);
581inline std::string& operator+=(std::string& target, String& source) {
582 return _stream_operators::append(target, source);
585inline std::ostream& operator<<(std::ostream& os, Socket::address&
addr) {
587 char buf[INET6_ADDRSTRLEN];
589 char buf[INET_ADDRSTRLEN];
591 addr.print(buf,
sizeof(buf),
false,
true);
599 extern __EXPORT iostream& null;
Various miscellaneous platform specific headers and defines.
Generic shell parsing and application services.
Abstract interfaces and support.
Thread-aware file system manipulation class.
Common namespace for all ucommon objects.
String string_t
A convenience type for string.
class __attribute__((visibility("default"))) dir typedef fsys fsys_t
Convenience class for directories.
const struct sockaddr * addr(Socket::address &address)
A convenience function to convert a socket address list into a socket address.
StringPager stringlist_t
A convenience type for paged string lists.
Common socket class and address manipulation.
Thread classes and sychronization objects.