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_ 64 class __EXPORT StreamBuffer :
protected std::streambuf,
public std::iostream
67 __DELETE_COPY(StreamBuffer);
83 int uflow() __OVERRIDE;
87 void allocate(
size_t size);
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;}
114 class __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);
237 class __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) {
347 class __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 456 class __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;
492 class __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);
524 bool __EXPORT getline(std::istream& in,
char *buffer,
size_t size);
526 bool __EXPORT putline(std::ostream& out,
const char *buffer);
532 class __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);
553 inline std::ostream& operator<< (std::ostream& out,
const PrintProtocol& format) {
554 return _stream_operators::print(out, format);
557 inline std::istream& operator>> (std::istream& inp, InputProtocol& format) {
558 return _stream_operators::input(inp, format);
561 inline std::ostream& operator<< (std::ostream& out,
const string_t& str) {
562 return _stream_operators::print(out, str);
565 inline std::istream& operator>> (std::istream& inp,
string_t& str) {
566 return _stream_operators::input(inp, str);
569 inline std::ostream& operator<< (std::ostream& out,
const stringlist_t& list) {
570 return _stream_operators::print(out, list);
573 inline std::istream& operator>> (std::istream& in,
stringlist_t& list) {
574 return _stream_operators::input(in, list);
577 inline std::string& operator+(std::string& target, String& source) {
578 return _stream_operators::append(target, source);
581 inline std::string& operator+=(std::string& target, String& source) {
582 return _stream_operators::append(target, source);
585 inline 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;
Thread classes and sychronization objects.
Common socket class and address manipulation.
Various miscellaneous platform specific headers and defines.
Generic shell parsing and application services.
Abstract interfaces and support.
Common namespace for all ucommon objects.
T copy(const T &src)
Convenience function to copy objects.
const struct sockaddr * addr(Socket::address &address)
A convenience function to convert a socket address list into a socket address.
Thread-aware file system manipulation class.
StringPager stringlist_t
A convenience type for paged string lists.
class __attribute__((visibility("default"))) dir typedef fsys fsys_t
Convenience class for directories.
String string_t
A convenience type for string.