Fresco/Prague/include/Prague/Sys DLL.hh,1.9,1.10 DataTypeManager.hh,1.6,1.7 Directory.hh,1.7,1.8 Env.hh,1.2,1.3 FLock.hh,1.8,1.9 FdSet.hh,1.7,1.8 File.hh,1.9,1.10 Fork.hh,1.5,1.6 GetOpt.hh,1.11,1.12 MMap.hh,1.5,1.6 Memory.hh,1.6,1.7 Path.hh,1.9,1.10 Plugin.hh,1.16,1.17 Process.hh,1.5,1.6 Profiler.hh,1.18,1.19 SHM.hh,1.5,1.6 Signal.hh,1.8,1.9 Stopwatch.hh,1.4,1.5 Thread.hh,1.22,1.23 ThreadData.hh,1.3,1.4 ThreadPool.hh,1.9,1.10 ThreadQueue.hh,1.8,1.9 Time.hh,1.8,1.9 Timer.hh,1.9,1.10 Tracer.hh,1.9,1.10 User.hh,1.5,1.6 logbuf.hh,1.6,1.7 logstream.hh,1.3,1.4 ntree.hh,1.5,1.6 regex.hh,1.7,1.8
Tobias Hunger <[email protected]> Fri, 31 Oct 2003 22:33:47 +0000
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Prague/include/Prague/Sys In directory purcel:/tmp/cvs-serv28781/Prague/include/Prague/Sys Modified Files: DLL.hh DataTypeManager.hh Directory.hh Env.hh FLock.hh FdSet.hh File.hh Fork.hh GetOpt.hh MMap.hh Memory.hh Path.hh Plugin.hh Process.hh Profiler.hh SHM.hh Signal.hh Stopwatch.hh Thread.hh ThreadData.hh ThreadPool.hh ThreadQueue.hh Time.hh Timer.hh Tracer.hh User.hh logbuf.hh logstream.hh ntree.hh regex.hh Log Message: Fix up indention according to the coding style guide. Index: DLL.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/DLL.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- DLL.hh 8 May 2003 04:11:33 -0000 1.9 +++ DLL.hh 31 Oct 2003 22:33:10 -0000 1.10 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,22 +28,22 @@ namespace Prague { -//. DLL represents a dynamic library -class DLL -{ -public: - //. create a library handle for the named library - DLL(const std::string &name, bool now = true) throw(std::runtime_error, std::logic_error); - ~DLL() throw(); - //. resolve the given symbol - void *resolve(const std::string &) throw(std::runtime_error); - //. return the library's name - const std::string &name() const throw() { return my_name;} -private: - std::string my_name; - void *my_handle; -}; + //. DLL represents a dynamic library + class DLL + { + public: + //. create a library handle for the named library + DLL(const std::string &name, bool now = true) throw(std::runtime_error, std::logic_error); + ~DLL() throw(); + //. resolve the given symbol + void *resolve(const std::string &) throw(std::runtime_error); + //. return the library's name + const std::string &name() const throw() { return my_name; } + private: + std::string my_name; + void *my_handle; + }; -} +} // namespace #endif Index: DataTypeManager.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/DataTypeManager.hh,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- DataTypeManager.hh 2 Jun 2002 23:42:22 -0000 1.6 +++ DataTypeManager.hh 31 Oct 2003 22:33:10 -0000 1.7 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,57 +30,61 @@ namespace Prague { -//. a DataTypeManager maintains a data type repository to determine -//. the type of a given file, based on either a magic number or the file's extension -class DataTypeManager -{ - struct Type + //. a DataTypeManager maintains a data type repository to determine + //. the type of a given file, based on either a magic number or the file's extension + class DataTypeManager { - struct Name - { - std::string::const_iterator parse(std::string::const_iterator, std::string::const_iterator); - unsigned short match(const std::string &); - unsigned short score; - regex name; - }; - struct Magic - { - struct Part + struct Type { - std::string::const_iterator parse(std::string::const_iterator, std::string::const_iterator); - bool match(const unsigned char *, int); - unsigned short offset, length; - std::vector<unsigned char> data, mask; + struct Name + { + std::string::const_iterator parse(std::string::const_iterator, + std::string::const_iterator); + unsigned short match(const std::string &); + unsigned short score; + regex name; + }; + struct Magic + { + struct Part + { + std::string::const_iterator parse(std::string::const_iterator, + std::string::const_iterator); + bool match(const unsigned char *, int); + unsigned short offset, length; + std::vector<unsigned char> data, mask; + }; + std::string::const_iterator parse(std::string::const_iterator, + std::string::const_iterator); + unsigned short match(const unsigned char *, int); + unsigned short score; + std::vector<Part> parts; + }; + bool parse(const std::string &); + unsigned short match_name(const std::string &); + unsigned short match_magic(const unsigned char *, int); + std::string type; + std::string mime; + std::vector<Name> names; + std::vector<Magic> magics; }; - std::string::const_iterator parse(std::string::const_iterator, std::string::const_iterator); - unsigned short match(const unsigned char *, int); - unsigned short score; - std::vector<Part> parts; - }; - bool parse(const std::string &); - unsigned short match_name(const std::string &); - unsigned short match_magic(const unsigned char *, int); - std::string type; - std::string mime; - std::vector<Name> names; - std::vector<Magic> magics; + public: + DataTypeManager(const std::string &file) { merge(file); } + ~DataTypeManager() { } + //. merges in another type repository + void merge(const std::string &); + //. return the type, given the head of a file + std::string match(const std::string &); + //. return the type for a given file + std::string match(const std::string &, const unsigned char *, unsigned int); + std::string type_to_mime(const std::string &); + std::string mime_to_type(const std::string &); + private: + static short compare(unsigned short, unsigned short, + unsigned short, unsigned short); + std::vector<Type> _types; }; -public: - DataTypeManager(const std::string &file) { merge(file);} - ~DataTypeManager() {} - //. merges in another type repository - void merge(const std::string &); - //. return the type, given the head of a file - std::string match(const std::string &); - //. return the type for a given file - std::string match(const std::string &, const unsigned char *, unsigned int); - std::string type_to_mime(const std::string &); - std::string mime_to_type(const std::string &); -private: - static short compare(unsigned short, unsigned short, unsigned short, unsigned short); - std::vector<Type> _types; -}; -}; +} // namespace #endif Index: Directory.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Directory.hh,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Directory.hh 21 Mar 2001 06:28:22 -0000 1.7 +++ Directory.hh 31 Oct 2003 22:33:10 -0000 1.8 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,39 +30,40 @@ namespace Prague { -//. Directory contains a list of all files that live in this directory -class Directory : public File -{ -public: - typedef std::vector<File *>::iterator iterator; - typedef std::vector<File *>::const_iterator const_iterator; - enum { unsorted = 0x0, dirsfirst = 0x1, size = 0x2, modtime = 0x4, acctime = 0x8, alpha = 0x10}; - enum { unfiltered = 0x0, nohidden = 0x1, - readable = 0x2, writable = 0x4, executable = 0x8, - dirs = 0x10, nodirs = 0x20}; - Directory(const std::string &, int order, int filter = unfiltered); - //. list all files according to <i>filter</i> in the order given by @var{order} - Directory(const std::string &, int order, const std::string &); - //. list all files according to @var{filter} in the order given by @var{order} - Directory(const Directory &); - ~Directory(); - //. return file with index i - File *operator [] (unsigned int i) { return _children[i];} - //. return number of files - unsigned int children() const { return _children.size();} - //. return begin iterator - iterator begin() { return _children.begin();} - //. return begin iterator - const_iterator begin() const { return _children.begin();} - //. return end iterator - iterator end() { return _children.end();} - //. return end iterator - const_iterator end() const { return _children.end();} -protected: - std::vector<File *> _children; -private: -}; + //. Directory contains a list of all files that live in this directory + class Directory : public File + { + public: + typedef std::vector<File *>::iterator iterator; + typedef std::vector<File *>::const_iterator const_iterator; + enum { unsorted = 0x0, dirsfirst = 0x1, size = 0x2, + modtime = 0x4, acctime = 0x8, alpha = 0x10 }; + enum { unfiltered = 0x0, nohidden = 0x1, + readable = 0x2, writable = 0x4, executable = 0x8, + dirs = 0x10, nodirs = 0x20 }; + Directory(const std::string &, int order, int filter = unfiltered); + //. list all files according to <i>filter</i> in the order given by @var{order} + Directory(const std::string &, int order, const std::string &); + //. list all files according to @var{filter} in the order given by @var{order} + Directory(const Directory &); + ~Directory(); + //. return file with index i + File *operator [] (unsigned int i) { return _children[i]; } + //. return number of files + unsigned int children() const { return _children.size(); } + //. return begin iterator + iterator begin() { return _children.begin(); } + //. return begin iterator + const_iterator begin() const { return _children.begin(); } + //. return end iterator + iterator end() { return _children.end(); } + //. return end iterator + const_iterator end() const { return _children.end(); } + protected: + std::vector<File *> _children; + private: + }; -}; +} // namespace #endif Index: Env.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Env.hh,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Env.hh 6 Nov 2002 05:44:14 -0000 1.2 +++ Env.hh 31 Oct 2003 22:33:10 -0000 1.3 @@ -1,7 +1,7 @@ -/* +/* $Id: * - * This source file is a part of the Berlin Project. - * Copyright (C) 2002 Tobias Hunger <[email protected]> + * This source file is a part of the Fresco Project. + * Copyright (C) 2002 Tobias Hunger <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -25,8 +25,8 @@ #include <string> #include <stdlib.h> -namespace Prague { - +namespace Prague +{ //. Set the environment variable name to a value. //. (returns whether it was successful or not) bool putenv(const std::string &, const std::string &); @@ -35,6 +35,6 @@ //. get the value of the environment variable name. std::string getenv(const std::string &); -}; +} // namespace #endif Index: FLock.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/FLock.hh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- FLock.hh 2 Jun 2002 23:42:22 -0000 1.8 +++ FLock.hh 31 Oct 2003 22:33:10 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -34,93 +34,100 @@ namespace Prague { -//. provide locking based on fcntl. FLocks can be activated in read and in write mode. -class FLock -{ -public: - enum mode {read = F_RDLCK, write = F_WRLCK}; - //. create a FLock using a temporary file - FLock(); - //. create a FLock for a given file - FLock(int); - //. create a FLock using file @var{name}, create if @var{create} is true - FLock(const std::string &, bool = true); - //. Description{close the associated file, removes it if is a temporary one. - ~FLock(); - const std::string &name() { return _file;} - bool trylock(mode m = read) { return doit(m, false) == 0;} - bool trylock(off_t offset, off_t length, mode m = read) { return doit(offset, length, m, false) == 0;} - //. try to activate the lock for mode @var{m}, return @var{true} if it successful} - bool lock(mode m = read) { return doit(m, true) == 0;} - bool lock(off_t offset, off_t length, mode m = read) { return doit(offset, length, m, true) == 0;} - bool unlock() { return doit(F_UNLCK, false) == 0;} - pid_t locked(mode m) const; -private: - int doit(int, bool); - int doit(off_t, off_t, int, bool); - std::string _file; - bool _close : 1; - bool _remove: 1; - int _fd; -}; + //. provide locking based on fcntl. FLocks can be activated in read and in write mode. + class FLock + { + public: + enum mode {read = F_RDLCK, write = F_WRLCK }; + //. create a FLock using a temporary file + FLock(); + //. create a FLock for a given file + FLock(int); + //. create a FLock using file @var{name}, create if @var{create} is true + FLock(const std::string &, bool = true); + //. Description{close the associated file, removes it if is a temporary one. + ~FLock(); + const std::string &name() { return _file; } + bool trylock(mode m = read) { return doit(m, false) == 0; } + bool trylock(off_t offset, off_t length, mode m = read) + { return doit(offset, length, m, false) == 0; } + //. try to activate the lock for mode @var{m}, return @var{true} if it successful} + bool lock(mode m = read) { return doit(m, true) == 0; } + bool lock(off_t offset, off_t length, mode m = read) + { return doit(offset, length, m, true) == 0; } + bool unlock() { return doit(F_UNLCK, false) == 0; } + pid_t locked(mode m) const; + private: + int doit(int, bool); + int doit(off_t, off_t, int, bool); + std::string _file; + bool _close : 1; + bool _remove: 1; + int _fd; + }; -inline FLock::FLock() - : _file(File::tmp()), _close(true), _remove(true) -{ - _fd = open(_file.c_str(), O_RDWR|O_CREAT, 0600); - ::write(_fd, "l", 1); -}; + inline FLock::FLock() : + _file(File::tmp()), + _close(true), + _remove(true) + { + _fd = open(_file.c_str(), O_RDWR|O_CREAT, 0600); + ::write(_fd, "l", 1); + } -inline FLock::FLock(int f) - : _close(false), _remove(false), _fd(f) -{ -}; + inline FLock::FLock(int f) : + _close(false), + _remove(false), + _fd(f) + { } -inline FLock::FLock(const std::string &f, bool create) - : _file(f), _close(true), _remove(false) -{ - if (create) _fd = open(_file.c_str(), create ? O_RDWR|O_CREAT : O_RDWR, 0600); - if (create) ::write(_fd, "l", 1); -}; + inline FLock::FLock(const std::string &f, bool create) : + _file(f), + _close(true), + _remove(false) + { + if (create) _fd = open(_file.c_str(), create ? O_RDWR|O_CREAT : O_RDWR, 0600); + if (create) ::write(_fd, "l", 1); + } -inline FLock::~FLock() -{ - if (_close) ::close(_fd); - if (_remove) ::remove(_file.c_str()); -}; + inline FLock::~FLock() + { + if (_close) ::close(_fd); + if (_remove) ::remove(_file.c_str()); + } -inline int FLock::doit(int type, bool flag) -{ - struct flock lock; - lock.l_type = type; - lock.l_len = 1; - lock.l_start = 0; - lock.l_whence = SEEK_SET; - return fcntl(_fd, flag ? F_SETLKW : F_SETLK, &lock); -}; + inline int FLock::doit(int type, bool flag) + { + struct flock lock; + lock.l_type = type; + lock.l_len = 1; + lock.l_start = 0; + lock.l_whence = SEEK_SET; + return fcntl(_fd, flag ? F_SETLKW : F_SETLK, &lock); + } -inline int FLock::doit(off_t offset, off_t length, int type, bool flag) -{ - struct flock lock; - lock.l_type = type; - lock.l_len = length; - lock.l_start = offset; - lock.l_whence = SEEK_SET; - return fcntl(_fd, flag ? F_SETLKW : F_SETLK, &lock); -}; + inline int FLock::doit(off_t offset, off_t length, int type, bool flag) + { + struct flock lock; + lock.l_type = type; + lock.l_len = length; + lock.l_start = offset; + lock.l_whence = SEEK_SET; + return fcntl(_fd, flag ? F_SETLKW : F_SETLK, &lock); + } -inline pid_t FLock::locked(mode m) const -//. return the ID of the process currently holding the lock or 0. -{ - struct flock lock; - lock.l_type = m; - lock.l_len = 1; - lock.l_start = 0; - lock.l_whence = SEEK_SET; - if (fcntl(_fd, F_GETLK, &lock) < 0);// throw - return lock.l_type == F_UNLCK ? 0 : lock.l_pid; -}; + inline pid_t FLock::locked(mode m) const + //. return the ID of the process currently holding the lock or 0. + { + struct flock lock; + lock.l_type = m; + lock.l_len = 1; + lock.l_start = 0; + lock.l_whence = SEEK_SET; + if (fcntl(_fd, F_GETLK, &lock) < 0); // throw + return lock.l_type == F_UNLCK ? 0 : lock.l_pid; + } -}; +} // namespace #endif /* _FLock_hh */ Index: FdSet.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/FdSet.hh,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- FdSet.hh 9 Jan 2003 17:01:09 -0000 1.7 +++ FdSet.hh 31 Oct 2003 22:33:10 -0000 1.8 @@ -1,9 +1,7 @@ -/* -*- mode: c++; c-file-style: "fresco" -*- - * - * $Id$ +/* $Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -27,34 +25,35 @@ #include <sys/time.h> #include <sys/types.h> #include <cstring> // some platforms seem to need this (solaris, bsd) +#include <cassert> #undef isset // *sigh* -stefan namespace Prague { -//. FdSet is a helper class used when selecting available fds for non-blocking i/o -class FdSet -{ -public: - FdSet() : m(-1) { FD_ZERO(&fds);} - FdSet(const FdSet &F) : fds(F.fds), m(F.m) {} - ~FdSet() {} - FdSet &operator = (const FdSet &F) { fds = F.fds; m = F.m; return *this;} - //. add a fd to the set - void set(int fd) { FD_SET(fd, &fds); if (fd > m) m = fd;} - //. return whether the given fd is available for non-blocking i/o - bool isset(int fd) const { return FD_ISSET(fd, &fds);} - //. clear fd from the set - void clear(int fd) { FD_CLR(fd, &fds); if (fd == m) for (int i = 0; i < fd - 1; i++) if (isset(fd)) m = fd;} - //. return max fd - int max() const { return m;} - operator fd_set *() { return &fds;} -protected: - fd_set fds; - int m; -}; + //. FdSet is a helper class used when selecting available fds for non-blocking i/o + class FdSet + { + public: + FdSet() : my_m(-1) { FD_ZERO(&my_fds); } + FdSet(const FdSet &F) : my_fds(F.my_fds), my_m(F.my_m) { } + ~FdSet() { } + FdSet &operator = (const FdSet &F) { my_fds = F.my_fds; my_m = F.my_m; return *this; } + //. Add a fd to the set + void set(int fd) { FD_SET(fd, &my_fds); if (fd > my_m) my_m = fd; } + //. return whether the given fd is available for non-blocking i/o + bool isset(int fd) const { return FD_ISSET(fd, &my_fds); } + //. clear fd from the set + void clear(int fd) { FD_CLR(fd, &my_fds); if (fd == my_m) for (int i = 0; i < fd - 1; i++) if (isset(fd)) my_m = fd; } + //. return max fd + int max() const { return my_m; } + operator fd_set *() { return &my_fds; } + protected: + fd_set my_fds; + int my_m; + }; -}; +} // namespace #endif Index: File.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/File.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- File.hh 15 Nov 2001 02:01:23 -0000 1.9 +++ File.hh 31 Oct 2003 22:33:10 -0000 1.10 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.berlin-consortium.org * * This library is free software; you can redistribute it and/or @@ -32,97 +32,94 @@ namespace Prague { -//. a File encapsulates common file based operations, such as lookup for state information -class File -{ -public: - enum type_t { none = 0, - link = S_IFLNK, - reg = S_IFREG, - dir = S_IFDIR, - chr = S_IFCHR, - blk = S_IFBLK, - fifo = S_IFIFO, - sock = S_IFSOCK}; - enum access_t { ru = S_IRUSR, - wu = S_IWUSR, - xu = S_IXUSR, - rg = S_IRGRP, - wg = S_IWGRP, - xg = S_IXGRP, - ro = S_IROTH, - wo = S_IWOTH, - xo = S_IXOTH, - all= ru|wu|xu|rg|wg|xg|ro|wo|xo}; - File(const std::string &); - File(const File &); - virtual ~File(); - File &operator = (const File &); - File &operator = (const std::string &); - //. return the parent directory - File parent() const; - //. return the file's name - const std::string &name() const { return _shortname;} - //. return the file's long name - const std::string &long_name() const { return _longname;} - //. check whether the file is of the given type - bool is(type_t t) const { return (_status.st_mode & S_IFMT) == (mode_t) t;} - //. return the file's type - long type() const { return (_status.st_mode & S_IFMT);} - //. return the file's access permission flag - long access() const { return (_status.st_mode & (ru|wu|xu));} - //. return the file owner - uid_t uid() const { return _status.st_uid;} - //. return the owning group - gid_t gid() const { return _status.st_gid;} - //. return the file size - long size() const { return _status.st_size;} - //. return the access time - time_t acc_time() const { return _status.st_atime;} - //. return the modification time - time_t mod_time() const { return _status.st_mtime;} - //. return the change time - time_t ch_time() const { return _status.st_ctime;} + //. a File encapsulates common file based operations, such as lookup for state information + class File + { + public: + enum type_t + { + none = 0, link = S_IFLNK, reg = S_IFREG, dir = S_IFDIR, chr = S_IFCHR, + blk = S_IFBLK, fifo = S_IFIFO, sock = S_IFSOCK + }; + enum access_t + { + ru = S_IRUSR, wu = S_IWUSR, xu = S_IXUSR, + rg = S_IRGRP, wg = S_IWGRP, xg = S_IXGRP, + ro = S_IROTH, wo = S_IWOTH, xo = S_IXOTH, + all= ru|wu|xu|rg|wg|xg|ro|wo|xo + }; + File(const std::string &); + File(const File &); + virtual ~File(); + File &operator = (const File &); + File &operator = (const std::string &); + //. return the parent directory + File parent() const; + //. return the file's name + const std::string &name() const { return _shortname; } + //. return the file's long name + const std::string &long_name() const { return _longname; } + //. check whether the file is of the given type + bool is(type_t t) const { return (_status.st_mode & S_IFMT) == (mode_t) t; } + //. return the file's type + long type() const { return (_status.st_mode & S_IFMT); } + //. return the file's access permission flag + long access() const { return (_status.st_mode & (ru|wu|xu)); } + //. return the file owner + uid_t uid() const { return _status.st_uid; } + //. return the owning group + gid_t gid() const { return _status.st_gid; } + //. return the file size + long size() const { return _status.st_size; } + //. return the access time + time_t acc_time() const { return _status.st_atime; } + //. return the modification time + time_t mod_time() const { return _status.st_mtime; } + //. return the change time + time_t ch_time() const { return _status.st_ctime; } - //. change the access permission - bool chmod(access_t); - //. rename the file - bool mv(const std::string &); - //. remove the file - bool rm(); - //. static method to determine the base name for the given string - static std::string base(const std::string &); - //. static method to determine the directory name for the given string - static std::string directory(const std::string &); - //. generate a temporary file name - static std::string tmp() { return ::tmpnam(0);} -protected: - struct stat _status; - std::string _longname; - std::string _shortname; - bool get_status(); - const char *last_error() const; - int _error; -private: -}; + //. change the access permission + bool chmod(access_t); + //. rename the file + bool mv(const std::string &); + //. remove the file + bool rm(); + //. static method to determine the base name for the given string + static std::string base(const std::string &); + //. static method to determine the directory name for the given string + static std::string directory(const std::string &); + //. generate a temporary file name + static std::string tmp() { return ::tmpnam(0); } + protected: + struct stat _status; + std::string _longname; + std::string _shortname; + bool get_status(); + const char *last_error() const; + int _error; + }; -inline std::string File::base(const std::string &s) -{ - std::string::size_type p = s.rfind('/'); - return p == std::string::npos ? s : s.substr(p + 1); -} + inline std::string File::base(const std::string &s) + { + std::string::size_type p = s.rfind('/'); + return p == std::string::npos ? s : s.substr(p + 1); + } -inline std::string File::directory(const std::string &s) -{ - std::string::size_type p = s.rfind('/'); - return p == std::string::npos ? "" : s.substr(0, p); -} + inline std::string File::directory(const std::string &s) + { + std::string::size_type p = s.rfind('/'); + return p == std::string::npos ? "" : s.substr(0, p); + } -inline bool File::get_status() -{ - if (stat(_longname.c_str(), &_status) == -1) { _status.st_mode = 0; _error = errno; return false;} return true; -} + inline bool File::get_status() + { + if (stat(_longname.c_str(), &_status) == -1) + { + _status.st_mode = 0; _error = errno; return false; + } + return true; + } -}; +} // namespace #endif Index: Fork.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Fork.hh,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Fork.hh 15 Jan 2001 02:49:18 -0000 1.5 +++ Fork.hh 31 Oct 2003 22:33:10 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * this file is based on code from the socket++ library * Copyright (C) 1992-1996 Gnanasekaran Swaminathan <[email protected]> @@ -33,27 +33,27 @@ namespace Prague { -//. Fork encapsulates the housekeeping associated with the fork() system call -class Fork -{ - struct Process; - public: - Fork (bool = false, bool = false); - ~Fork(); - //. return whether this is the child process - bool child() const; - //. return whether this is the parent process - bool parent() const; - //. return the child process id - pid_t pid() const; - //. commit suicide at the signal signo - static void suicide_on_signal(int signo = Signal::terminate); - private: - Process *process; - Fork (const Fork &); - Fork &operator = (const Fork &); -}; + //. Fork encapsulates the housekeeping associated with the fork() system call + class Fork + { + struct Process; + public: + Fork (bool = false, bool = false); + ~Fork(); + //. return whether this is the child process + bool child() const; + //. return whether this is the parent process + bool parent() const; + //. return the child process id + pid_t pid() const; + //. commit suicide at the signal signo + static void suicide_on_signal(int signo = Signal::terminate); + private: + Process *process; + Fork (const Fork &); + Fork &operator = (const Fork &); + }; -}; +} // namespace #endif Index: GetOpt.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/GetOpt.hh,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- GetOpt.hh 31 Jan 2003 05:42:09 -0000 1.11 +++ GetOpt.hh 31 Oct 2003 22:33:10 -0000 1.12 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,109 +31,119 @@ namespace Prague { -//. GetOpt manages a command line option data base. It deals with short and long options, -//. and reorders the given option vector such that you can run different GetOpt instances over -//. the argv vector one after another. -class GetOpt -{ -public: - //. the option type, i.e. whether an argument is required or not. - enum type { novalue, optional, mandatory}; - enum order { inorder, require, permute}; - - class NoSuchOption : public std::exception - { - public: - NoSuchOption() throw() - : my_option("(unknown)") {} - NoSuchOption(const char o) throw() - : my_option(std::string("-") + o) {} - NoSuchOption(const std::string option) throw() - : my_option(std::string("--") + option) {} - virtual ~NoSuchOption() throw() {} - virtual const char* what() const throw() { return (std::string("no such option ") + my_option).c_str();} - const std::string my_option; - }; - class DuplicateOption : public std::exception - { - public: - DuplicateOption(const char o) throw() - : my_option(std::string("-") + o) {} - virtual ~DuplicateOption() throw() {} - virtual const char* what() const throw() { return (std::string("option already added: ") + my_option).c_str();} - private: - const std::string my_option; - }; -private: - struct cell - { - cell(char oo, const std::string &opt, type tt, const std::string &des) - : set(false), o(oo), option(opt), t(tt), description(des) {} - bool set; - char o; // option char - std::string option; // option name - type t; // option type - std::string description; // a description of option - std::string value; // value of option (string) - }; - typedef std::vector<cell> table_t; // option table -public: - GetOpt(const char *, const char * = 0); - ~GetOpt(); - //. print out usage information. This function uses help data provided with each - //. registered option, i.e. it is suitable to be used as a help message. - void usage() const; - //. parse the given argv - int parse(int argc, char **argv); - //. parse the given args - int parse(char *args); - //. register an option - void add(char o, const std::string &option, type, const std::string & = "no description available") throw (DuplicateOption); - //. return whether the option was issued - bool is_set(char o) const throw (NoSuchOption); - //. return whether the option was issued - bool is_set(const std::string &option) const throw (NoSuchOption); - //. return whether the option was issued and return a value (if any) in out parameter - bool get(char o, std::string *) const throw (NoSuchOption); - //. return whether the option was issued and return a value (if any) in out parameter - bool get(const std::string &option, std::string *) const throw (NoSuchOption); -private: - table_t table; - const char *p; // program basename - const char *u; // usage message - order ordering; - //. try to extract a long option, return number of tokens consumed - size_t getlongopt(int argc, char **argv); - //. try to extract a short option, return number of tokens consumed - size_t getopt(int argc, char **argv); - //. return the cell with the given option - table_t::iterator find(const std::string &option) - { return find_if(table.begin(), table.end(), comp_string(option));} - //. return the cell with the given option - table_t::const_iterator find(const std::string &option) const - { return find_if(table.begin(), table.end(), comp_string(option));} - //. return the cell with the given option - table_t::iterator find(char o) - { return find_if(table.begin(), table.end(), comp_char(o));} - //. return the cell with the given option - table_t::const_iterator find(char o) const - { return find_if(table.begin(), table.end(), comp_char(o));} - //. reorder the argument vector to move the consumed tokens to the front - void exchange(char **, size_t, char **); - struct comp_string - { - comp_string(const std::string &n) : name(n) {} - bool operator () (const cell &c) { return name == c.option;} - std::string name; - }; - struct comp_char + //. GetOpt manages a command line option data base. It deals with short and long options, + //. and reorders the given option vector such that you can run different GetOpt instances over + //. the argv vector one after another. + class GetOpt { - comp_char(char n) : name(n) {} - bool operator () (const cell &c) { return name == c.o;} - char name; + public: + //. the option type, i.e. whether an argument is required or not. + enum type { novalue, optional, mandatory }; + enum order { inorder, require, permute }; + + class NoSuchOption : public std::exception + { + public: + NoSuchOption() throw() : my_option("(unknown)") { } + NoSuchOption(const char o) throw() : + my_option(std::string("-") + o) + { } + NoSuchOption(const std::string option) throw() : + my_option(std::string("--") + option) + { } + virtual ~NoSuchOption() throw() { } + virtual const char* what() const throw() + { + return (std::string("no such option ") + my_option).c_str(); + } + const std::string my_option; + }; + class DuplicateOption : public std::exception + { + public: + DuplicateOption(const char o) throw() : + my_option(std::string("-") + o) + { } + virtual ~DuplicateOption() throw() { } + virtual const char* what() const throw() + { + return (std::string("option already added: ") + my_option).c_str(); + } + private: + const std::string my_option; + }; + private: + struct cell + { + cell(char oo, const std::string &opt, type tt, const std::string &des) : + set(false), o(oo), option(opt), t(tt), description(des) + { } + bool set; + char o; //.< option char + std::string option; //.< option name + type t; //.< option type + std::string description; //.< a description of option + std::string value; //.< value of option (string) + }; + typedef std::vector<cell> table_t; //.< option table + public: + GetOpt(const char *, const char * = 0); + ~GetOpt(); + //. print out usage information. This function uses help data provided with each + //. registered option, i.e. it is suitable to be used as a help message. + void usage() const; + //. parse the given argv + int parse(int argc, char **argv); + //. parse the given args + int parse(char *args); + //. register an option + void add(char o, const std::string &option, type, + const std::string & = "no description available") throw (DuplicateOption); + //. return whether the option was issued + bool is_set(char o) const throw (NoSuchOption); + //. return whether the option was issued + bool is_set(const std::string &option) const throw (NoSuchOption); + //. return whether the option was issued and return a value (if any) in out parameter + bool get(char o, std::string *) const throw (NoSuchOption); + //. return whether the option was issued and return a value (if any) in out parameter + bool get(const std::string &option, std::string *) const throw (NoSuchOption); + private: + table_t table; + const char *p; // program basename + const char *u; // usage message + order ordering; + //. try to extract a long option, return number of tokens consumed + size_t getlongopt(int argc, char **argv); + //. try to extract a short option, return number of tokens consumed + size_t getopt(int argc, char **argv); + //. return the cell with the given option + table_t::iterator find(const std::string &option) + { return find_if(table.begin(), table.end(), comp_string(option)); } + //. return the cell with the given option + table_t::const_iterator find(const std::string &option) const + { return find_if(table.begin(), table.end(), comp_string(option)); } + //. return the cell with the given option + table_t::iterator find(char o) + { return find_if(table.begin(), table.end(), comp_char(o)); } + //. return the cell with the given option + table_t::const_iterator find(char o) const + { return find_if(table.begin(), table.end(), comp_char(o)); } + //. reorder the argument vector to move the consumed tokens to the front + void exchange(char **, size_t, char **); + struct comp_string + { + comp_string(const std::string &n) : name(n) { } + bool operator () (const cell &c) { return name == c.option; } + std::string name; + }; + struct comp_char + { + comp_char(char n) : name(n) { } + bool operator () (const cell &c) { return name == c.o; } + char name; + }; }; -}; -}; +} // namespace #endif Index: MMap.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/MMap.hh,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- MMap.hh 19 Aug 2001 19:14:57 -0000 1.5 +++ MMap.hh 31 Oct 2003 22:33:10 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,33 +30,41 @@ namespace Prague { -//. a convenience wrapper around the mmap family of functions -class MMap -{ -public: - enum protection_t { none = PROT_NONE, read = PROT_READ, write = PROT_WRITE, exec = PROT_EXEC}; - enum map_t { fixed = MAP_FIXED, shared = MAP_SHARED, priv = MAP_PRIVATE}; - MMap(int, int = -1, int = read|write, int = priv, void * = 0, off_t = 0) throw(std::runtime_error); - MMap(const std::string &, int = -1, int = read|write, int = priv, void * = 0, off_t = 0) throw(std::runtime_error); - ~MMap(); - //. return the base address - void *addr() const { return _base;} - //. return the size - size_t size() const { return _length;} - //. synchronize the memory with the associated file - void sync(ssize_t = -1, bool = true); - //. synchronize the memory with the associated file - void sync(void *, size_t, bool = true); - //. protect the memory - void protect(ssize_t = -1, int = read|write); - //. protect the memory - void protect(void *, size_t, int = read|write); -private: - MMap(const MMap &); - void *_base; - size_t _length; -}; + //. a convenience wrapper around the mmap family of functions + class MMap + { + public: + enum protection_t + { + none = PROT_NONE, read = PROT_READ, write = PROT_WRITE, exec = PROT_EXEC + }; + enum map_t + { + fixed = MAP_FIXED, shared = MAP_SHARED, priv = MAP_PRIVATE + }; + MMap(int, int = -1, int = read|write, + int = priv, void * = 0, off_t = 0) throw(std::runtime_error); + MMap(const std::string &, int = -1, int = read|write, + int = priv, void * = 0, off_t = 0) throw(std::runtime_error); + ~MMap(); + //. return the base address + void *addr() const { return _base; } + //. return the size + size_t size() const { return _length; } + //. synchronize the memory with the associated file + void sync(ssize_t = -1, bool = true); + //. synchronize the memory with the associated file + void sync(void *, size_t, bool = true); + //. protect the memory + void protect(ssize_t = -1, int = read|write); + //. protect the memory + void protect(void *, size_t, int = read|write); + private: + MMap(const MMap &); + void *_base; + size_t _length; + }; -}; +} // namespace #endif Index: Memory.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Memory.hh,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Memory.hh 15 Jan 2001 02:49:18 -0000 1.6 +++ Memory.hh 31 Oct 2003 22:33:10 -0000 1.7 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,23 +27,32 @@ namespace Prague { -//. this is a portability wrapper, to hide platform differences, -//. as well as to hide some nasty casts -namespace Memory -{ -template <class T> -T *copy(const T *from, T *to, unsigned long n) { return n > 0 ? reinterpret_cast<T *>(memmove(to, from, size_t(n))) : to;} -template <class T> -T *move(const T *from, T *to, unsigned long n) { return n > 0 ? reinterpret_cast<T *>(memmove(to, from, size_t(n))) : to;} -template <class T> -T *set(T *b, unsigned long n, T c) { return reinterpret_cast<T *>(memset(b, c, size_t(n)));} -template <class T> -T *zero(T *m, unsigned long l) { return reinterpret_cast<T *>(memset(m, 0, size_t(l)));} -template <class T> -int compare(const T *p, const T *q, unsigned long n) { return memcmp(p, q, size_t(n));} + //. this is a portability wrapper, to hide platform differences, + //. as well as to hide some nasty casts + namespace Memory + { + template <class T> + T *copy(const T *from, T *to, unsigned long n) + { return n > 0 ? reinterpret_cast<T *>(memmove(to, from, size_t(n))) : to; } -}; + template <class T> + T *move(const T *from, T *to, unsigned long n) + { return n > 0 ? reinterpret_cast<T *>(memmove(to, from, size_t(n))) : to; } -}; + template <class T> + T *set(T *b, unsigned long n, T c) + { return reinterpret_cast<T *>(memset(b, c, size_t(n))); } + + template <class T> + T *zero(T *m, unsigned long l) + { return reinterpret_cast<T *>(memset(m, 0, size_t(l))); } + + template <class T> + int compare(const T *p, const T *q, unsigned long n) + { return memcmp(p, q, size_t(n)); } + + } // namespace + +} // namespace #endif Index: Path.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Path.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Path.hh 21 Sep 2002 12:21:30 -0000 1.9 +++ Path.hh 31 Oct 2003 22:33:10 -0000 1.10 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.berlin-consortium.org * * This library is free software; you can redistribute it and/or @@ -29,51 +29,60 @@ namespace Prague { -//. Path implements the Unix Path functionality, i.e. file lookup. -class Path -{ - typedef std::vector<std::string> rep_type; - struct Predicate { bool operator()(const std::string &name) { File file(name); return file.access() & File::ru;}}; -public: - typedef rep_type::iterator iterator; - typedef rep_type::const_iterator const_iterator; - //. construct an empty path - Path() {} - //. construct a list of directories, using the given separator to tokenize the string - Path(const std::string &path, char separator = ':'); - ~Path() {} - //. append a directory - void append(const std::string &directory) { _directories.push_back(directory);} - //. look up a file, using the predicate functor, if non-zero -// template <typename Predicate = dummy_predicate> - std::string lookup_file(const std::string &) const; - //. expand a directory, if it is provided as '~joe/foo' - static std::string expand_user(const std::string &); - //. return begin iterator - iterator begin() { return _directories.begin();} - //. return end iterator - iterator end() { return _directories.end();} - //. return the size, i.e. the number of directories contained in the path - size_t size() { return _directories.size();} - //. return ith directory - const std::string &operator [] (size_t i) { return _directories[i];} -private: - rep_type _directories; -}; + //. Path implements the Unix Path functionality, i.e. file lookup. + class Path + { + typedef std::vector<std::string> rep_type; + struct Predicate + { + bool operator()(const std::string &name) + { + File file(name); + return file.access() & File::ru; + } + }; + public: + typedef rep_type::iterator iterator; + typedef rep_type::const_iterator const_iterator; + //. construct an empty path + Path() { } + //. construct a list of directories, using the given separator to tokenize the string + Path(const std::string &path, char separator = ':'); + ~Path() { } + //. append a directory + void append(const std::string &directory) { _directories.push_back(directory); } + //. look up a file, using the predicate functor, if non-zero + // template <typename Predicate = dummy_predicate> + std::string lookup_file(const std::string &) const; + //. expand a directory, if it is provided as '~joe/foo' + static std::string expand_user(const std::string &); + //. return begin iterator + iterator begin() { return _directories.begin(); } + //. return end iterator + iterator end() { return _directories.end(); } + //. return the size, i.e. the number of directories contained in the path + size_t size() { return _directories.size(); } + //. return ith directory + const std::string &operator [] (size_t i) { return _directories[i]; } + private: + rep_type _directories; + }; -// template <typename Predicate> -inline std::string Path::lookup_file(const std::string &name) const -{ - if (name.empty() || name[0] == '/') return name; - Predicate predicate; - for (std::vector<std::string>::const_iterator i = _directories.begin(); i != _directories.end(); i++) - { - std::string result = *i + "/" + name; - if (predicate(result)) return result; - } - return std::string(); -}; + // template <typename Predicate> + inline std::string Path::lookup_file(const std::string &name) const + { + if (name.empty() || name[0] == '/') return name; + Predicate predicate; + for (std::vector<std::string>::const_iterator i = _directories.begin(); + i != _directories.end(); + ++i) + { + std::string result = *i + "/" + name; + if (predicate(result)) return result; + } + return std::string(); + } -}; +} // namespace #endif Index: Plugin.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Plugin.hh,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- Plugin.hh 23 Aug 2001 18:30:27 -0000 1.16 +++ Plugin.hh 31 Oct 2003 22:33:10 -0000 1.17 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,31 +27,32 @@ namespace Prague { -//. a special kind of a smart pointer which implements a plugin behavior. -//. It assumes a special layout of the library, with a special factory -//. that manufactures objects of type T. -template <class T> -class Plugin : public DLL -{ -public: - //. create a Plugin from the given file, using a factory with name loader - //. to create the actual object - Plugin(const std::string &file, const std::string &loader = "load") throw(std::runtime_error, std::logic_error) - : DLL(file) + //. a special kind of a smart pointer which implements a plugin behavior. + //. It assumes a special layout of the library, with a special factory + //. that manufactures objects of type T. + template <class T> + class Plugin : public DLL { - typedef T *(* DL) (); - DL dl = (DL) resolve(loader); - _t = dl ? (T *) dl() : 0; - } - ~Plugin() { delete _t;} - T &operator *() const { return *_t;} - T *operator->() const { return _t;} - T *get() const { return _t;} -private: - T *_t; -}; + public: + //. create a Plugin from the given file, using a factory with name loader + //. to create the actual object + Plugin(const std::string &file, const std::string &loader = "load") + throw(std::runtime_error, std::logic_error) : + DLL(file) + { + typedef T *(* DL) (); + DL dl = (DL) resolve(loader); + _t = dl ? (T *) dl() : 0; + } + ~Plugin() { delete _t; } + T &operator *() const { return *_t; } + T *operator->() const { return _t; } + T *get() const { return _t; } + private: + T *_t; + }; -} +} // namespace #define dload(T) extern "C" T *load() { return new T;} Index: Process.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Process.hh,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Process.hh 15 Jan 2001 02:49:18 -0000 1.5 +++ Process.hh 31 Oct 2003 22:33:10 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,22 +31,24 @@ namespace Prague { -//. provide process information -class Process -{ -public: - Process() { update();} - ~Process() {} - double cpu() const { return 0.;} - long memory() const { return _usage.ru_idrss;} - void update() { if (getrusage(RUSAGE_SELF, &_usage) == -1) perror("Process::update:");} - //. return the process' id - static pid_t id() { return getpid();} -protected: -private: - rusage _usage; -}; + //. provide process information + class Process + { + public: + Process() { update(); } + ~Process() { } + double cpu() const { return 0.; } + long memory() const { return _usage.ru_idrss; } + void update() + { + if (getrusage(RUSAGE_SELF, &_usage) == -1) perror("Process::update:"); + } + //. return the process' id + static pid_t id() { return getpid(); } + private: + rusage _usage; + }; -}; +} // namespace #endif Index: Profiler.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Profiler.hh,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- Profiler.hh 2 Jun 2002 23:42:22 -0000 1.18 +++ Profiler.hh 31 Oct 2003 22:33:10 -0000 1.19 @@ -1,9 +1,9 @@ /*$Id$ * - * This source file is a part of the Berlin Project. + * This source file is a part of the Fresco Project. * Copyright (C) 1999 Brent A. Fulgham <[email protected]> - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected] - * http://www.berlin-consortium.org + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected] + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -34,92 +34,91 @@ namespace Prague { -//. a poor man's profiler. The basic idea is to use a guard object which measures -//. the elapsed time between constructor and destructor and writes its findings into -//. a profiler data base (a scope tree). -class Profiler -{ -public: - struct CheckPoint - { - CheckPoint(const std::string &s) : name(s), count(0), start(0), stop(0), elapsed(0) {} - CheckPoint(CheckPoint *cp) - : name(cp->name), - count(cp->count), - start(cp->start), - stop(cp->stop), - elapsed(cp->elapsed) - {} - void indent(std::ostream &os, unsigned short ind) { while (ind--) os.put(' ');} - void output(std::ostream &os, unsigned short ind); - std::string name; - long count; - clock_t start; - clock_t stop; - double elapsed; - }; -private: - typedef ntree<CheckPoint *> table_t; - typedef ntree<CheckPoint *>::node item_t; - typedef ntree<CheckPoint *>::node::child_iterator child_iterator; - typedef ntree<CheckPoint *>::node::const_child_iterator const_child_iterator; - typedef ntree<CheckPoint *>::node::up_iterator up_iterator; - struct Guard + //. a poor man's profiler. The basic idea is to use a guard object which measures + //. the elapsed time between constructor and destructor and writes its findings into + //. a profiler data base (a scope tree). + class Profiler { - Guard() + public: + struct CheckPoint { - Profiler::table = new table_t(new CheckPoint("RootEntry")); - Profiler::current = &table->root(); - } - ~Guard() + CheckPoint(const std::string &s) : + name(s), count(0), start(0), stop(0), elapsed(0) + { } + CheckPoint(CheckPoint *cp) : + name(cp->name), count(cp->count), start(cp->start), stop(cp->stop), elapsed(cp->elapsed) + { } + void indent(std::ostream &os, unsigned short ind) + { while (ind--) os.put(' '); } + void output(std::ostream &os, unsigned short ind); + std::string name; + long count; + clock_t start; + clock_t stop; + double elapsed; + }; + private: + typedef ntree<CheckPoint *> table_t; + typedef ntree<CheckPoint *>::node item_t; + typedef ntree<CheckPoint *>::node::child_iterator child_iterator; + typedef ntree<CheckPoint *>::node::const_child_iterator const_child_iterator; + typedef ntree<CheckPoint *>::node::up_iterator up_iterator; + struct Guard + { + Guard() + { + Profiler::table = new table_t(new CheckPoint("RootEntry")); + Profiler::current = &table->root(); + } + ~Guard() + { + Profiler::clean(*Profiler::current); + delete Profiler::table; + } + }; + friend struct Guard; + public: + Profiler(const std::string &name) { - Profiler::clean(*Profiler::current); - delete Profiler::table; - } - }; - friend struct Guard; -public: - Profiler(const std::string &name) - { #ifdef profile - Prague::Guard<Mutex> guard(mutex); - child_iterator i = lookup(name); - current = &*i; - current->value->count++; - current->value->start = clock(); + Prague::Guard<Mutex> guard(mutex); + child_iterator i = lookup(name); + current = &*i; + current->value->count++; + current->value->start = clock(); #endif /* profile */ - } - ~Profiler() - { + } + ~Profiler() + { #ifdef profile - Prague::Guard<Mutex> guard(mutex); - current->value->stop = clock(); - current->value->elapsed += (current->value->stop - current->value->start); - up_iterator i = current->up_begin(); - current = &*++i; + Prague::Guard<Mutex> guard(mutex); + current->value->stop = clock(); + current->value->elapsed += (current->value->stop - current->value->start); + up_iterator i = current->up_begin(); + current = &*++i; #endif /* profile */ - } - static void dump(std::ostream &); -private: - static child_iterator lookup(const std::string &name) - { - for (child_iterator i = current->child_begin(); i != current->child_end(); i++) - if ((*i).value->name == name) return i; - return current->push_back(new CheckPoint(name)); - } - static void dump(std::ostream &, const item_t &, unsigned short); - static void clean(const item_t &root) - { - for (const_child_iterator i = root.child_begin(); i != root.child_end(); i++) - clean(*i); - delete root.value; - } - static Guard guard; - static table_t *table; - static item_t *current; - static Mutex mutex; -}; + } + static void dump(std::ostream &); + private: + static child_iterator lookup(const std::string &name) + { + for (child_iterator i = current->child_begin(); i != current->child_end(); i++) + if ((*i).value->name == name) return i; + return current->push_back(new CheckPoint(name)); + } + static void dump(std::ostream &, const item_t &, unsigned short); + static void clean(const item_t &root) + { + for (const_child_iterator i = root.child_begin(); i != root.child_end(); i++) + clean(*i); + delete root.value; + } + static Guard guard; + static table_t *table; + static item_t *current; + static Mutex mutex; + }; -}; +} // namespace #endif Index: SHM.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/SHM.hh,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SHM.hh 15 Jan 2001 02:49:18 -0000 1.5 +++ SHM.hh 31 Oct 2003 22:33:10 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,17 +28,17 @@ namespace Prague { -struct SHM -{ - static int allocate(key_t, size_t, int = IPC_CREAT | 0666); - static int allocate(size_t, int = IPC_CREAT | 0666); - static void deallocate(int); - static void *attach(int); - static void detach(void *); - int id; - unsigned int count; -}; + struct SHM + { + static int allocate(key_t, size_t, int = IPC_CREAT | 0666); + static int allocate(size_t, int = IPC_CREAT | 0666); + static void deallocate(int); + static void *attach(int); + static void detach(void *); + int id; + unsigned int count; + }; -}; +} // namespace #endif /* _SHM_hh */ Index: Signal.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Signal.hh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Signal.hh 21 Mar 2001 06:28:22 -0000 1.8 +++ Signal.hh 31 Oct 2003 22:33:10 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,67 +31,67 @@ namespace Prague { -class sigerr {}; + class sigerr{}; -//. a wrapper for the POSIX signal handling functions. -class Signal -{ -public: - class Notifier - { + //. a wrapper for the POSIX signal handling functions. + class Signal + { public: - virtual ~Notifier() {} - virtual void notify(int) = 0; - }; -private: - typedef std::vector<Notifier *> nlist_t; - typedef std::map<int, nlist_t> dict_t; -public: - enum type { hangup = SIGHUP, interrupt = SIGINT, quit = SIGQUIT, illegal = SIGILL, - trap = SIGTRAP, abort = SIGABRT, iotrap = SIGIOT, bus = SIGBUS, fpe = SIGFPE, - segv = SIGSEGV, - usr1 = SIGUSR1, usr2 = SIGUSR2, alarm = SIGALRM, terminate = SIGTERM, child = SIGCHLD, io = SIGIO, - pipe = SIGPIPE, kill = SIGKILL}; - //. add a notifier to be executed whenever the given signal is catched - static bool set(int, Notifier *); - //. removes a notifier from the list for signum - static bool unset(int, Notifier *); - //. remove all notifiers for the signal and reinstall the system's default handler - static void unset(int); - //. ignore the specified signal - static void mask(int); - //. block sigb while siga is handled - static void mask(int, int); - //. don't ignore the specified signal any more - static void unmask(int); - //. don't ignore the specified signal any more - static void unmask(int, int); - //. is there a pending signal of type signum (while being blocked) - static bool ispending(int signum); - //. is there any pending signal (while being blocked) - static sigset_t pending(); - static void sysresume(int, bool); - //. returns the signal name of signum if nonzero or of the last signal beeing catched - static const char *name(int); + class Notifier + { + public: + virtual ~Notifier() { } + virtual void notify(int) = 0; + }; + private: + typedef std::vector<Notifier *> nlist_t; + typedef std::map<int, nlist_t> dict_t; + public: + enum type { hangup = SIGHUP, interrupt = SIGINT, quit = SIGQUIT, illegal = SIGILL, + trap = SIGTRAP, abort = SIGABRT, iotrap = SIGIOT, bus = SIGBUS, fpe = SIGFPE, + segv = SIGSEGV, + usr1 = SIGUSR1, usr2 = SIGUSR2, alarm = SIGALRM, terminate = SIGTERM, child = SIGCHLD, io = SIGIO, + pipe = SIGPIPE, kill = SIGKILL}; + //. add a notifier to be executed whenever the given signal is catched + static bool set(int, Notifier *); + //. removes a notifier from the list for signum + static bool unset(int, Notifier *); + //. remove all notifiers for the signal and reinstall the system's default handler + static void unset(int); + //. ignore the specified signal + static void mask(int); + //. block sigb while siga is handled + static void mask(int, int); + //. don't ignore the specified signal any more + static void unmask(int); + //. don't ignore the specified signal any more + static void unmask(int, int); + //. is there a pending signal of type signum (while being blocked) + static bool ispending(int signum); + //. is there any pending signal (while being blocked) + static sigset_t pending(); + static void sysresume(int, bool); + //. returns the signal name of signum if nonzero or of the last signal beeing catched + static const char *name(int); - //. a Signal Guard, that masks a given signal over its lifetime. - class Guard - { - public: - Guard(int s) : signo(s) { mask(signo);} - ~Guard() { unmask(signo);} - private: - int signo; + //. a Signal Guard, that masks a given signal over its lifetime. + class Guard + { + public: + Guard(int s) : signo(s) { mask(signo); } + ~Guard() { unmask(signo); } + private: + int signo; + }; + private: + static void notify (int); + friend void sighandler (int signo); + static void *run(void *); + static dict_t notifiers; + static Thread::Queue<int> queue; + static Thread server; }; -private: - static void notify (int); - friend void sighandler (int signo); - static void *run(void *); - static dict_t notifiers; - static Thread::Queue<int> queue; - static Thread server; -}; -}; +} // namespace #endif Index: Stopwatch.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Stopwatch.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Stopwatch.hh 15 Jan 2001 02:49:18 -0000 1.4 +++ Stopwatch.hh 31 Oct 2003 22:33:10 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,36 +28,36 @@ namespace Prague { -//. measure the real/cpu/sys time spend between two given moments. -class Stopwatch -{ - enum state { undef, stopped, running}; - struct interval + //. measure the real/cpu/sys time spend between two given moments. + class Stopwatch { - clock_t begin; - clock_t end; + enum state { undef, stopped, running }; + struct interval + { + clock_t begin; + clock_t end; + }; + public: + Stopwatch(); + ~Stopwatch(){} + //. start the stopwatch + void start(); + //. stop the stopwatch + void stop(); + //. return real elapsed time + double real_time(); + //. return cpu elapsed time + double cpu_time(); + //. return sys elapsed time + double sys_time(); + private: + interval _real; + interval _cpu; + interval _sys; + static clock_t _ticks; + state _state; }; -public: - Stopwatch(); - ~Stopwatch(){} - //. start the stopwatch - void start(); - //. stop the stopwatch - void stop(); - //. return real elapsed time - double real_time(); - //. return cpu elapsed time - double cpu_time(); - //. return sys elapsed time - double sys_time(); -private: - interval _real; - interval _cpu; - interval _sys; - static clock_t _ticks; - state _state; -}; -}; +} // namespace #endif Index: Thread.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Thread.hh,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- Thread.hh 8 May 2003 03:21:11 -0000 1.22 +++ Thread.hh 31 Oct 2003 22:33:10 -0000 1.23 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999-2003 Stefan Seefeld <[email protected]> + * Copyright (C) 1999-2003 Stefan Seefeld <[email protected]> * Copyright (C) 2001 Tobias Hunger <[email protected]> * http://www.fresco.org * @@ -35,230 +35,230 @@ namespace Prague { -class Mutex -{ -public: - class Attribute + class Mutex { - public: - Attribute() { pthread_mutexattr_init (&impl);} - ~Attribute() { pthread_mutexattr_destroy(&impl);} - pthread_mutexattr_t impl; + public: + class Attribute + { + public: + Attribute() { pthread_mutexattr_init (&impl); } + ~Attribute() { pthread_mutexattr_destroy(&impl); } + pthread_mutexattr_t impl; + }; + // enum type { fast = PTHREAD_MUTEX_FAST_NP, + // recursive = PTHREAD_MUTEX_RECURSIVE_NP }; + Mutex() { pthread_mutex_init(&impl, 0); } + // Mutex(type t); + ~Mutex() { pthread_mutex_destroy(&impl); } + void lock() { pthread_mutex_lock(&impl); } + void unlock() { pthread_mutex_unlock(&impl); } + bool trylock() { return pthread_mutex_trylock(&impl); } + pthread_mutex_t impl; }; -// enum type { fast = PTHREAD_MUTEX_FAST_NP, -// recursive = PTHREAD_MUTEX_RECURSIVE_NP}; - Mutex() { pthread_mutex_init(&impl, 0);} -// Mutex(type t); - ~Mutex() { pthread_mutex_destroy(&impl);} - void lock() { pthread_mutex_lock(&impl);} - void unlock() { pthread_mutex_unlock(&impl);} - bool trylock() { return pthread_mutex_trylock(&impl);} - pthread_mutex_t impl; -}; -//. semaphores are used to limit the number of concurrent accesses to some resource. -class Semaphore -{ -public: - Semaphore(unsigned int v = 0) { sem_init(&impl, 0, v);} - ~Semaphore() { sem_destroy(&impl);} - void wait() { sem_wait(&impl);} - bool trywait() { return sem_trywait(&impl);} - void post() { sem_post(&impl);} - int value() { int v; sem_getvalue(&impl, &v); return v;} - sem_t impl; -private: - Semaphore(const Semaphore &); - Semaphore &operator = (const Semaphore &); -}; - -template<class T> -class Lock_Trait -{ -public: - void lock(T & t) { t.lock();} - void unlock(T & t) { t.unlock();} -}; - -template<> -class Lock_Trait<Semaphore> -{ -public: - void lock(Semaphore & t) { t.wait();} - void unlock(Semaphore & t) { t.post();} -}; - -template<class T> -class WLock_Trait -{ -public: - void lock(T & t) { t.wlock();} - void unlock(T & t) { t.unlock();} -}; + //. Semaphores are used to limit the number of concurrent accesses to some resource. + class Semaphore + { + public: + Semaphore(unsigned int v = 0) { sem_init(&impl, 0, v); } + ~Semaphore() { sem_destroy(&impl); } + void wait() { sem_wait(&impl); } + bool trywait() { return sem_trywait(&impl); } + void post() { sem_post(&impl); } + int value() { int v; sem_getvalue(&impl, &v); return v; } + sem_t impl; + private: + Semaphore(const Semaphore &); + Semaphore &operator = (const Semaphore &); + }; -// A helperclass -template <class T, class L_TRAIT = Lock_Trait<T> > -class Guard -{ -public: - Guard(T & t) : vip(t), trait() { trait.lock(vip);} - ~Guard() { trait.unlock(vip);} -private: - Guard(const Guard<T> &); - Guard & operator = (const Guard &); - T & vip; // Who else get's guarded? - L_TRAIT trait; -}; + template<class T> + class Lock_Trait + { + public: + void lock(T & t) { t.lock(); } + void unlock(T & t) { t.unlock(); } + }; -//. condition variables are used to commuicate changed conditions between threads. -class Condition -{ -public: - class Attribute + template<> + class Lock_Trait<Semaphore> { - public: - Attribute() { pthread_condattr_init(&impl);} - ~Attribute() { pthread_condattr_destroy(&impl);} - pthread_condattr_t impl; + public: + void lock(Semaphore & t) { t.wait(); } + void unlock(Semaphore & t) { t.post(); } }; - Condition(Mutex &m) : mutex(m) { pthread_cond_init(&impl, 0);} - ~Condition() { pthread_cond_destroy(&impl);} - void broadcast() { pthread_cond_broadcast(&impl);} - void signal() { pthread_cond_signal(&impl);} - void wait() { pthread_cond_wait(&impl, &mutex.impl);} - void wait(const Time &t) { timespec ts = t; pthread_cond_timedwait(&impl, &mutex.impl, &ts);} - pthread_cond_t impl; -private: - Mutex &mutex; -}; -class RWLock -{ -public: - class Attribute + template<class T> + class WLock_Trait { - public: - Attribute() { pthread_rwlockattr_init (&impl);} - ~Attribute() { pthread_rwlockattr_destroy(&impl);} - pthread_rwlockattr_t impl; + public: + void lock(T & t) { t.wlock(); } + void unlock(T & t) { t.unlock(); } }; - RWLock() { pthread_rwlock_init(&impl, 0);} - RWLock(const Attribute &a) { pthread_rwlock_init(&impl, &a.impl);} - ~RWLock() { pthread_rwlock_destroy(&impl);} - void rlock() { pthread_rwlock_rdlock(&impl);} - void wlock() { pthread_rwlock_wrlock(&impl);} - void unlock() { pthread_rwlock_unlock(&impl);} - bool tryrlock() { return pthread_rwlock_tryrdlock(&impl);} - bool trywlock() { return pthread_rwlock_trywrlock(&impl);} - pthread_rwlock_t impl; -}; -class RLockTrait -{ -public: - static void lock(RWLock &l) { l.rlock();} - static void unlock(RWLock &l) { l.unlock();} -}; + // A helperclass + template <class T, class L_TRAIT = Lock_Trait<T> > + class Guard + { + public: + Guard(T & t) : vip(t), trait() { trait.lock(vip); } + ~Guard() { trait.unlock(vip); } + private: + Guard(const Guard<T> &); + Guard & operator = (const Guard &); + T & vip; // Who else get's guarded? + L_TRAIT trait; + }; -class WLockTrait -{ -public: - static void lock(RWLock &l) { l.wlock();} - static void unlock(RWLock &l) { l.unlock();} -}; + //. condition variables are used to commuicate changed conditions between threads. + class Condition + { + public: + class Attribute + { + public: + Attribute() { pthread_condattr_init(&impl); } + ~Attribute() { pthread_condattr_destroy(&impl); } + pthread_condattr_t impl; + }; + Condition(Mutex &m) : mutex(m) { pthread_cond_init(&impl, 0); } + ~Condition() { pthread_cond_destroy(&impl); } + void broadcast() { pthread_cond_broadcast(&impl); } + void signal() { pthread_cond_signal(&impl); } + void wait() { pthread_cond_wait(&impl, &mutex.impl); } + void wait(const Time &t) { timespec ts = t; pthread_cond_timedwait(&impl, &mutex.impl, &ts); } + pthread_cond_t impl; + private: + Mutex &mutex; + }; -//. a thread housekeeping class. -class Thread -{ - struct Guard + class RWLock { - Guard(); - ~Guard(); + public: + class Attribute + { + public: + Attribute() { pthread_rwlockattr_init (&impl); } + ~Attribute() { pthread_rwlockattr_destroy(&impl); } + pthread_rwlockattr_t impl; + }; + RWLock() { pthread_rwlock_init(&impl, 0); } + RWLock(const Attribute &a) { pthread_rwlock_init(&impl, &a.impl); } + ~RWLock() { pthread_rwlock_destroy(&impl); } + void rlock() { pthread_rwlock_rdlock(&impl); } + void wlock() { pthread_rwlock_wrlock(&impl); } + void unlock() { pthread_rwlock_unlock(&impl); } + bool tryrlock() { return pthread_rwlock_tryrdlock(&impl); } + bool trywlock() { return pthread_rwlock_trywrlock(&impl); } + pthread_rwlock_t impl; }; - friend struct Guard; -public: - enum priority_t {LOW, NORMAL, HIGH}; - enum state_t {READY, RUNNING, TERMINATED}; - static const void *CANCELED; - template <class T> class Data; - template <class T> class Queue; - typedef void *(*proc)(void *); - class Attribute + + class RLockTrait { - public: - Attribute() { pthread_attr_init(&impl);} - ~Attribute() { pthread_attr_destroy(&impl);} - pthread_attr_t impl; + public: + static void lock(RWLock &l) { l.rlock(); } + static void unlock(RWLock &l) { l.unlock(); } }; - class Exception : public std::logic_error + + class WLockTrait { - public: - Exception(const std::string &m) : std::logic_error(m) {} + public: + static void lock(RWLock &l) { l.wlock(); } + static void unlock(RWLock &l) { l.unlock(); } }; - Thread(proc, void *, priority_t = NORMAL); - ~Thread(); - //. return the thread's priority - priority_t priority() { Prague::Guard<Mutex> g(my_mutex); return my_priority;} - //. return the thread's current state - state_t state() { Prague::Guard<Mutex> g(my_mutex); return my_state;} - //. start the thread - void start() throw (Exception); - //. wait for the thread to finish returning its return value - void join(void **) throw (Exception); - //. cancel the thread - void cancel(); - //. detach the thread - void detach(); - //. exit the calling thread with return value r - static void exit(void *r); - //. delay execution of the calling thread - static bool delay(const Time &); - //. cancellation point - static void testcancel() { pthread_testcancel();} - //. return a Thread pointer for the calling thread or 0 - //. if it wasn't created by this Thread class - static Thread *self(); - //. return a thread id. This gives a valid number even for third party threads - static unsigned long id(); -private: - Thread(pthread_t); - static void *start(void *); - static unsigned long counter; - static Thread *main; - static Guard guard; - static pthread_key_t self_key; - static pthread_key_t id_key; - static Mutex id_mutex; + //. a thread housekeeping class. + class Thread + { + struct Guard + { + Guard(); + ~Guard(); + }; + friend struct Guard; + public: + enum priority_t { LOW, NORMAL, HIGH }; + enum state_t { READY, RUNNING, TERMINATED }; + static const void *CANCELED; + template <class T> class Data; + template <class T> class Queue; + typedef void *(*proc)(void *); + class Attribute + { + public: + Attribute() { pthread_attr_init(&impl); } + ~Attribute() { pthread_attr_destroy(&impl); } + pthread_attr_t impl; + }; + class Exception : public std::logic_error + { + public: + Exception(const std::string &m) : std::logic_error(m) { } + }; + Thread(proc, void *, priority_t = NORMAL); + ~Thread(); + //. return the thread's priority + priority_t priority() { Prague::Guard<Mutex> g(my_mutex); return my_priority; } + //. return the thread's current state + state_t state() { Prague::Guard<Mutex> g(my_mutex); return my_state; } + //. start the thread + void start() throw (Exception); + //. wait for the thread to finish returning its return value + void join(void **) throw (Exception); + //. cancel the thread + void cancel(); + //. detach the thread + void detach(); + //. exit the calling thread with return value r + static void exit(void *r); + //. delay execution of the calling thread + static bool delay(const Time &); + //. cancellation point + static void testcancel() { pthread_testcancel();} + //. return a Thread pointer for the calling thread or 0 + //. if it wasn't created by this Thread class + static Thread *self(); + //. return a thread id. This gives a valid number even for third party threads + static unsigned long id(); + private: + Thread(pthread_t); + static void *start(void *); - proc my_proc; - void *my_arg; - pthread_t my_thread; - priority_t my_priority; - state_t my_state; - bool my_detached; - Mutex my_mutex; -}; + static unsigned long counter; + static Thread *main; + static Guard guard; + static pthread_key_t self_key; + static pthread_key_t id_key; + static Mutex id_mutex; -inline Thread *Thread::self() -{ - return reinterpret_cast<Thread *>(pthread_getspecific(self_key)); -} + proc my_proc; + void *my_arg; + pthread_t my_thread; + priority_t my_priority; + state_t my_state; + bool my_detached; + Mutex my_mutex; + }; -inline unsigned long Thread::id() -{ - unsigned long *_id = reinterpret_cast<unsigned long *>(pthread_getspecific(id_key)); - if (!_id) - { - Prague::Guard<Mutex> guard(id_mutex); + inline Thread *Thread::self() + { + return reinterpret_cast<Thread *>(pthread_getspecific(self_key)); + } + + inline unsigned long Thread::id() + { + unsigned long *_id = reinterpret_cast<unsigned long *>(pthread_getspecific(id_key)); if (!_id) - { - _id = new unsigned long (counter++); - pthread_setspecific(id_key, _id); - } - } - return *_id; -} + { + Prague::Guard<Mutex> guard(id_mutex); + if (!_id) + { + _id = new unsigned long (counter++); + pthread_setspecific(id_key, _id); + } + } + return *_id; + } } // namespace Prague Index: ThreadData.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/ThreadData.hh,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ThreadData.hh 22 Mar 2000 22:30:16 -0000 1.3 +++ ThreadData.hh 31 Oct 2003 22:33:10 -0000 1.4 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,91 +27,99 @@ namespace Prague { -template <class T> -class Thread::Data -{ -public: - class TooMuchTSDs : public Exception { public: TooMuchTSDs() : Exception("too much TSDs defined") {}}; - class InvalidKey : public Exception { public: InvalidKey() : Exception("illegal key") {}}; + template <class T> + class Thread::Data + { + public: + class TooMuchTSDs : public Exception + { + public: + TooMuchTSDs() : Exception("too much TSDs defined") { } + }; + class InvalidKey : public Exception + { + public: + InvalidKey() : Exception("illegal key") { } + }; - Data(T v) throw (TooMuchTSDs, InvalidKey) : initializer(v) - { - if(pthread_key_create(&key, destructor)) throw TooMuchTSDs(); - if(pthread_setspecific(key, new T(initializer))) throw InvalidKey(); - } - Data() throw (TooMuchTSDs, InvalidKey) - { - if(pthread_key_create(&key, destructor)) throw TooMuchTSDs(); - if(pthread_setspecific(key, new T)) throw InvalidKey(); - } - ~Data() - { - delete reinterpret_cast<T *>(pthread_getspecific(key)); - pthread_key_delete(key); - } - const T &var(void) const throw (InvalidKey) - { - T *data = reinterpret_cast<T *>(pthread_getspecific(key)); - if (!data) - { - if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); - data = reinterpret_cast<T *>(pthread_getspecific(key)); - } - return *data; - } - T &var(void) throw (InvalidKey) - { - T *data = reinterpret_cast<T *>(pthread_getspecific(key)); - if (!data) - { - if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); - data = reinterpret_cast<T *>(pthread_getspecific(key)); - } - return *data; - } - Data<T> &operator = (const T &t) throw (InvalidKey) - { - T *data = reinterpret_cast<T *>(pthread_getspecific(key)); - if (data) *data = t; - else if (pthread_setspecific(key, new T(t))) throw InvalidKey(); - return *this; - } - Data<T> &operator = (const Data<T> &t) throw (InvalidKey) - { - T *data = reinterpret_cast<T *>(pthread_getspecific(key)); - if (data) *data = *t; - else if (pthread_setspecific(key, new T(*t))) throw InvalidKey(); - return *this; - } - const T *operator->() const throw (InvalidKey) - { - T *data = reinterpret_cast<T *>(pthread_getspecific(key)); - if (!data) - { - if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); - data = reinterpret_cast<T *>(pthread_getspecific(key)); - } - return data; - } - T *operator->() throw (InvalidKey) - { - T *data = reinterpret_cast<T *>(pthread_getspecific(key)); - if (!data) - { - if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); - data = reinterpret_cast<T *>(pthread_getspecific(key)); - } - return data; - } - const T &operator *() const { return var();} - T &operator *() { return var();} -private: - static void destructor(void *data) { delete reinterpret_cast<T *>(data);} - Data(const Data<T> &); - pthread_key_t key; - T initializer; -}; + Data(T v) throw (TooMuchTSDs, InvalidKey) : initializer(v) + { + if(pthread_key_create(&key, destructor)) throw TooMuchTSDs(); + if(pthread_setspecific(key, new T(initializer))) throw InvalidKey(); + } + Data() throw (TooMuchTSDs, InvalidKey) + { + if(pthread_key_create(&key, destructor)) throw TooMuchTSDs(); + if(pthread_setspecific(key, new T)) throw InvalidKey(); + } + ~Data() + { + delete reinterpret_cast<T *>(pthread_getspecific(key)); + pthread_key_delete(key); + } + const T &var(void) const throw (InvalidKey) + { + T *data = reinterpret_cast<T *>(pthread_getspecific(key)); + if (!data) + { + if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); + data = reinterpret_cast<T *>(pthread_getspecific(key)); + } + return *data; + } + T &var(void) throw (InvalidKey) + { + T *data = reinterpret_cast<T *>(pthread_getspecific(key)); + if (!data) + { + if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); + data = reinterpret_cast<T *>(pthread_getspecific(key)); + } + return *data; + } + Data<T> &operator = (const T &t) throw (InvalidKey) + { + T *data = reinterpret_cast<T *>(pthread_getspecific(key)); + if (data) *data = t; + else if (pthread_setspecific(key, new T(t))) throw InvalidKey(); + return *this; + } + Data<T> &operator = (const Data<T> &t) throw (InvalidKey) + { + T *data = reinterpret_cast<T *>(pthread_getspecific(key)); + if (data) *data = *t; + else if (pthread_setspecific(key, new T(*t))) throw InvalidKey(); + return *this; + } + const T *operator->() const throw (InvalidKey) + { + T *data = reinterpret_cast<T *>(pthread_getspecific(key)); + if (!data) + { + if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); + data = reinterpret_cast<T *>(pthread_getspecific(key)); + } + return data; + } + T *operator->() throw (InvalidKey) + { + T *data = reinterpret_cast<T *>(pthread_getspecific(key)); + if (!data) + { + if (pthread_setspecific(key, new T(initializer))) throw InvalidKey(); + data = reinterpret_cast<T *>(pthread_getspecific(key)); + } + return data; + } + const T &operator *() const { return var(); } + T &operator *() { return var(); } + private: + static void destructor(void *data) { delete reinterpret_cast<T *>(data); } + Data(const Data<T> &); + pthread_key_t key; + T initializer; + }; -}; +} // namespace #endif /* _Prague_ThreadData_hh */ Index: ThreadPool.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/ThreadPool.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- ThreadPool.hh 26 Nov 2002 16:31:59 -0000 1.9 +++ ThreadPool.hh 31 Oct 2003 22:33:10 -0000 1.10 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,42 +33,43 @@ class ThreadPool { typedef std::vector<Thread *> tlist_t; - public: + public: ThreadPool(Thread::Queue<Task> &t, Acceptor &a, size_t s) : - _tasks(t), _acceptor(a), _threads(s, 0) + _tasks(t), _acceptor(a), _threads(s, 0) { - for (tlist_t::iterator i = _threads.begin(); - i != _threads.end(); - ++i) - (*i) = new Thread(run, this); + for (tlist_t::iterator i = _threads.begin(); + i != _threads.end(); + ++i) + (*i) = new Thread(run, this); } ~ThreadPool() { - for (tlist_t::iterator i = _threads.begin(); - i != _threads.end(); - i++) delete *i; + for (tlist_t::iterator i = _threads.begin(); + i != _threads.end(); + ++i) + delete *i; } void start() { - for (tlist_t::iterator i = _threads.begin(); - i != _threads.end(); - i++) - (*i)->start(); + for (tlist_t::iterator i = _threads.begin(); + i != _threads.end(); + ++i) + (*i)->start(); } - private: + private: static void *run(void *X) { - ThreadPool *_this = reinterpret_cast<ThreadPool *>(X); - while (1) - { - Task task = _this->_tasks.top(); - _this->_tasks.pop(); - Handler *handler = _this->_acceptor.consume(task); - handler->process(); - delete handler; - Thread::testcancel(); - } - return 0; + ThreadPool *_this = reinterpret_cast<ThreadPool *>(X); + while (1) + { + Task task = _this->_tasks.top(); + _this->_tasks.pop(); + Handler *handler = _this->_acceptor.consume(task); + handler->process(); + delete handler; + Thread::testcancel(); + } + return 0; } Thread::Queue<Task> &_tasks; @@ -76,6 +77,6 @@ tlist_t _threads; }; -}; +} // namespace #endif /* _ThreadPool_hh */ Index: ThreadQueue.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/ThreadQueue.hh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ThreadQueue.hh 3 Dec 2002 20:35:44 -0000 1.8 +++ ThreadQueue.hh 31 Oct 2003 22:33:10 -0000 1.9 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -29,39 +29,42 @@ namespace Prague { -template <class T> -class Thread::Queue : private std::queue<T> -{ - typedef std::queue<T> rep_type; -public: - Queue(size_t capacity) : my_free(capacity) {} - void push(const T &t) - { - my_free.wait(); - Prague::Guard<Mutex> guard(my_mutex); - rep_type::push(t); - my_tasks.post(); - } - T top() - { - my_tasks.wait(); - Prague::Guard<Mutex> guard(my_mutex); - return rep_type::front(); - } - void pop() - { - Prague::Guard<Mutex> guard(my_mutex); - rep_type::pop(); - my_free.post(); - } - size_t size() { Prague::Guard<Mutex> guard(my_mutex); return rep_type::size();} -protected: -private: - Semaphore my_tasks; - Semaphore my_free; - Mutex my_mutex; -}; + template <class T> + class Thread::Queue : private std::queue<T> + { + typedef std::queue<T> rep_type; + public: + Queue(size_t capacity) : my_free(capacity) { } + void push(const T &t) + { + my_free.wait(); + Prague::Guard<Mutex> guard(my_mutex); + rep_type::push(t); + my_tasks.post(); + } + T top() + { + my_tasks.wait(); + Prague::Guard<Mutex> guard(my_mutex); + return rep_type::front(); + } + void pop() + { + Prague::Guard<Mutex> guard(my_mutex); + rep_type::pop(); + my_free.post(); + } + size_t size() + { + Prague::Guard<Mutex> guard(my_mutex); + return rep_type::size(); + } + private: + Semaphore my_tasks; + Semaphore my_free; + Mutex my_mutex; + }; -}; +} // namespace #endif Index: Time.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Time.hh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Time.hh 29 Nov 2002 20:46:56 -0000 1.8 +++ Time.hh 31 Oct 2003 22:33:10 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,52 +29,72 @@ namespace Prague { -class Time : public timeval -{ -public: - static const Time zero; - Time() { tv_sec = tv_usec = 0;} - Time(const timeval &t) : timeval(t) { normalize();} - Time(const timespec &t) { tv_sec = t.tv_sec, tv_usec = t.tv_nsec/1000; normalize();} - Time(long l) { tv_sec = l/1000, tv_usec = (l - tv_sec*1000)*1000;} - Time(int, int, int, int, int, int, int); - Time(int, int, int, int); - ~Time() {} - bool operator == (const Time &T) const { return tv_sec == T.tv_sec && tv_usec == T.tv_usec;} - bool operator != (const Time &T) const { return tv_sec != T.tv_sec || tv_usec != T.tv_usec;} - bool operator > (const Time &T) const { return tv_sec > T.tv_sec || (tv_sec == T.tv_sec && tv_usec > T.tv_usec);} - bool operator < (const Time &T) const { return tv_sec < T.tv_sec || (tv_sec == T.tv_sec && tv_usec < T.tv_usec);} - bool operator >= (const Time &T) const { return operator > (T) || operator == (T);} - bool operator <= (const Time &T) const { return operator < (T) || operator == (T);} - Time &operator += (const Time &T) { tv_sec += T.tv_sec, tv_usec += T.tv_usec; normalize(); return *this;} - Time &operator -= (const Time &T) { tv_sec -= T.tv_sec, tv_usec -= T.tv_usec; normalize(); return *this;} - Time operator + (const Time &T) const { Time t = *this; t += T; return t;} - Time operator - (const Time &T) const { Time t = *this; t -= T; return t;} - operator bool () const { return tv_sec != 0 || tv_usec != 0;} - operator timespec () const { timespec t; t.tv_sec = tv_sec, t.tv_nsec = tv_usec * 1000; return t;} - operator double () const { return static_cast<double>(tv_sec) + static_cast<double>(tv_usec)/1000000.;} - // FIXME: timeval is defined differently in different systems - // on freebsd we can't use ctime(&tv_sec) because tv_sec is 'int32' - // while timeval contains 'time_t' members - // -stefan -// operator const char *() const { return ctime(&tv_sec);} - static Time currentTime(); - friend std::ostream &operator << (std::ostream &os, const Time &T) { return os << T.tv_sec << " s, " << T.tv_usec << " us";} -protected: - inline void normalize(); -private: -}; + class Time : public timeval + { + public: + static const Time zero; + Time() { tv_sec = tv_usec = 0; } + Time(const timeval &t) : timeval(t) { normalize(); } + Time(const timespec &t) + { tv_sec = t.tv_sec, tv_usec = t.tv_nsec/1000; normalize(); } + Time(long l) + { tv_sec = l/1000, tv_usec = (l - tv_sec*1000)*1000; } + Time(int, int, int, int, int, int, int); + Time(int, int, int, int); + ~Time() { } + bool operator == (const Time &T) const + { return tv_sec == T.tv_sec && tv_usec == T.tv_usec; } + bool operator != (const Time &T) const + { return tv_sec != T.tv_sec || tv_usec != T.tv_usec; } + bool operator > (const Time &T) const + { + return tv_sec > T.tv_sec || + (tv_sec == T.tv_sec && tv_usec > T.tv_usec); + } + bool operator < (const Time &T) const + { return tv_sec < T.tv_sec || (tv_sec == T.tv_sec && tv_usec < T.tv_usec); } + bool operator >= (const Time &T) const + { return operator > (T) || operator == (T); } + bool operator <= (const Time &T) const + { return operator < (T) || operator == (T); } + Time &operator += (const Time &T) + { tv_sec += T.tv_sec, tv_usec += T.tv_usec; normalize(); return *this; } + Time &operator -= (const Time &T) + { tv_sec -= T.tv_sec, tv_usec -= T.tv_usec; normalize(); return *this; } + Time operator + (const Time &T) const + { Time t = *this; t += T; return t; } + Time operator - (const Time &T) const + { Time t = *this; t -= T; return t; } + operator bool () const + { return tv_sec != 0 || tv_usec != 0; } + operator timespec () const + { timespec t; t.tv_sec = tv_sec, t.tv_nsec = tv_usec * 1000; return t; } + operator double () const + { return static_cast<double>(tv_sec) + static_cast<double>(tv_usec)/1000000.; } + // FIXME: timeval is defined differently in different systems + // on freebsd we can't use ctime(&tv_sec) because tv_sec is 'int32' + // while timeval contains 'time_t' members + // -stefan + // operator const char *() const { return ctime(&tv_sec); } + static Time currentTime(); + friend std::ostream &operator << (std::ostream &os, const Time &T) + { return os << T.tv_sec << " s, " << T.tv_usec << " us"; } + protected: + inline void normalize(); + private: + }; -inline void Time::normalize() -{ - while (tv_usec >= 1000000) tv_usec -= 1000000, tv_sec++; - while (tv_usec < 0) - { - if (tv_sec > 0) tv_usec += 1000000, tv_sec--; - else { tv_usec = 0; break;} - } -} + inline void Time::normalize() + { + while (tv_usec >= 1000000) + tv_usec -= 1000000, tv_sec++; + while (tv_usec < 0) + { + if (tv_sec > 0) tv_usec += 1000000, tv_sec--; + else { tv_usec = 0; break;} + } + } -} +} // namespace #endif /* _Prague_Time_hh */ Index: Timer.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Timer.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Timer.hh 21 Mar 2001 06:28:22 -0000 1.9 +++ Timer.hh 31 Oct 2003 22:33:10 -0000 1.10 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresci Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,31 +29,39 @@ namespace Prague { -class Timer -{ - struct comp; - friend class comp; - struct comp { bool operator () (const Timer *t1, const Timer *t2) { return t1->timeout > t2->timeout;}}; -public: - struct Notifier { virtual ~Notifier(){}; virtual void notify() = 0;}; - Timer(Notifier *n) : notifier(n) {} - virtual ~Timer() {} - void start(const Time &, const Time & = Time::zero); - void stop(); -private: - Notifier *notifier; - Time timeout; - Time interval; - static void *start(void *); - static void expire(); - static void schedule(Timer *); - static void cancel(Timer *); - static std::vector<Timer *> timers; - static Thread server; - static Mutex mutex; - static Condition condition; -}; + class Timer + { + struct comp; + friend class comp; + struct comp + { + bool operator () (const Timer *t1, const Timer *t2) + { return t1->timeout > t2->timeout; } + }; + public: + struct Notifier + { + virtual ~Notifier() { } + virtual void notify() = 0; + }; + Timer(Notifier *n) : notifier(n) { } + virtual ~Timer() { } + void start(const Time &, const Time & = Time::zero); + void stop(); + private: + Notifier *notifier; + Time timeout; + Time interval; + static void *start(void *); + static void expire(); + static void schedule(Timer *); + static void cancel(Timer *); + static std::vector<Timer *> timers; + static Thread server; + static Mutex mutex; + static Condition condition; + }; -}; +} // namespace #endif /* _Timer_hh */ Index: Tracer.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/Tracer.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Tracer.hh 15 Feb 2002 19:28:31 -0000 1.9 +++ Tracer.hh 31 Oct 2003 22:33:10 -0000 1.10 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Berlin Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> * http://www.berlin-consortium.org * * This library is free software; you can redistribute it and/or @@ -30,110 +30,110 @@ namespace Prague { -class Trace; + class Trace; -//. this class represents a lightweight circular tracing stream -//. similar to the one in GNU NANA except designed for use in -//. a multithreaded C++ environment with section guards. -class Tracer -{ - struct Event + //. this class represents a lightweight circular tracing stream + //. similar to the one in GNU NANA except designed for use in + //. a multithreaded C++ environment with section guards. + class Tracer { - double time, start; - unsigned long thread; - const char *type; - const char *object; - const char *section; + struct Event + { + double time, start; + unsigned long thread; + const char *type; + const char *object; + const char *section; + }; + friend std::ostream &Prague::operator << (std::ostream &os, const Event &e); + friend class Trace; + public: + static void resize(size_t s) + { + Prague::Guard<Mutex> guard(_mutex); + _events.resize(s); + if (_next >= s) _next = 0; + } + static void logging(bool l) { _log = l; } + static double add(const char *, const char *, const char *, double start = -1); + static void clear() { _next = 0; _wrapped = false; } + static void dump(std::ostream &); + static void reset_clock() { _start = Time::currentTime(); } + private: + static std::vector<Event> _events; + static Time _start; + static Thread::Data<unsigned short> _indent; + static Mutex _mutex; + static unsigned int _next; + static bool _wrapped; + static bool _log; }; - friend std::ostream &Prague::operator << (std::ostream &os, const Event &e); - friend class Trace; -public: - static void resize(size_t s) - { - Prague::Guard<Mutex> guard(_mutex); - _events.resize(s); - if (_next >= s) _next = 0; - } - static void logging(bool l) { _log = l;} - static double add(const char *, const char *, const char *, double start = -1); - static void clear() { _next = 0; _wrapped = false;} - static void dump(std::ostream &); - static void reset_clock() { _start = Time::currentTime();} -private: - static std::vector<Event> _events; - static Time _start; - static Thread::Data<unsigned short> _indent; - static Mutex _mutex; - static unsigned int _next; - static bool _wrapped; - static bool _log; -}; -//. An abstract class defining the NamedObject 'interface' providing a method -//. of retrieving the name of implementing objects. This will usually be used -//. for debugging purposes, eg: the Tracer -class NamedObject -{ -public: - //. Return a decriptive name for this object, used mainly for debugging - //. and introspection purposes. This should be short, only a couple of - //. words if that, and encapsulate the type and kit of the object. - virtual const char *object_name() = 0; -}; + //. An abstract class defining the NamedObject 'interface' providing a method + //. of retrieving the name of implementing objects. This will usually be used + //. for debugging purposes, eg: the Tracer + class NamedObject + { + public: + //. Return a decriptive name for this object, used mainly for debugging + //. and introspection purposes. This should be short, only a couple of + //. words if that, and encapsulate the type and kit of the object. + virtual const char *object_name() = 0; + }; #ifdef TRACER -//. The guard class which marks the start and end of a scope, typically used -//. to mark function calls in the trace dump. It will append an item to the -//. trace log upon construction, and another upon destruction. -//. -//. Usage: Trace(this, "MyObject::ThisFunc"); -class Trace -{ -public: - //. Constructor for classes that don't inherit NamedObject. Those that do - //. should use the other constructor. - Trace(const char *s) : _section(s), _obj_name(0) - { - _start = Tracer::add("enter", 0, _section); - ++*Tracer::_indent; - } - - //. Constructor for classes that do inherit NamedObject. The name of the - //. object is extracted using the 'object_name()' method, and stored in the - //. trace log. - Trace(NamedObject *obj, const char *section) : _section(section), _obj_name(0) + //. The guard class which marks the start and end of a scope, typically used + //. to mark function calls in the trace dump. It will append an item to the + //. trace log upon construction, and another upon destruction. + //. + //. Usage: Trace(this, "MyObject::ThisFunc"); + class Trace { - if (obj) _obj_name = obj->object_name(); - _start = Tracer::add("enter", _obj_name, _section); - ++*Tracer::_indent; - } + public: + //. Constructor for classes that don't inherit NamedObject. Those that do + //. should use the other constructor. + Trace(const char *s) : _section(s), _obj_name(0) + { + _start = Tracer::add("enter", 0, _section); + ++*Tracer::_indent; + } - //. Destructor, adds another trace log entry to signify the end of the - //. section this object was guarding - ~Trace() - { - --*Tracer::_indent; - Tracer::add("leave", _obj_name, _section, _start); - } -private: - //. The name of the section, or function - const char *_section; - //. The name of the object (which may contain more info than just the class - //. name) - const char *_obj_name; - //. The starting time of the guard section - double _start; -}; + //. Constructor for classes that do inherit NamedObject. The name of the + //. object is extracted using the 'object_name()' method, and stored in the + //. trace log. + Trace(NamedObject *obj, const char *section) : _section(section), _obj_name(0) + { + if (obj) _obj_name = obj->object_name(); + _start = Tracer::add("enter", _obj_name, _section); + ++*Tracer::_indent; + } + + //. Destructor, adds another trace log entry to signify the end of the + //. section this object was guarding + ~Trace() + { + --*Tracer::_indent; + Tracer::add("leave", _obj_name, _section, _start); + } + private: + //. The name of the section, or function + const char *_section; + //. The name of the object (which may contain more info than just the class + //. name) + const char *_obj_name; + //. The starting time of the guard section + double _start; + }; #else -class Trace -{ -public: - Trace(const char *) {} - Trace(NamedObject *, const char *) {} - ~Trace() {} -}; + class Trace + { + public: + Trace(const char *) { } + Trace(NamedObject *, const char *) { } + ~Trace() { } + }; #endif -}; +} // namespace #endif Index: User.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/User.hh,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- User.hh 21 Mar 2001 06:28:22 -0000 1.5 +++ User.hh 31 Oct 2003 22:33:10 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,22 +28,22 @@ namespace Prague { -class User -{ -public: - User(int id = -1); - User(const std::string &); - ~User() {} - uid_t uid() const { return pwd->pw_uid;} - gid_t gid() const { return pwd->pw_gid;} - const char *name() const { return pwd->pw_name;} - const char *realName() const { return pwd->pw_gecos;} - const char *home() const { return pwd->pw_dir;} -protected: - passwd *pwd; -private: -}; + class User + { + public: + User(int id = -1); + User(const std::string &); + ~User() { } + uid_t uid() const { return pwd->pw_uid; } + gid_t gid() const { return pwd->pw_gid; } + const char *name() const { return pwd->pw_name; } + const char *realName() const { return pwd->pw_gecos; } + const char *home() const { return pwd->pw_dir; } + protected: + passwd *pwd; + private: + }; -}; +} // namespace #endif /* _User_hh */ Index: logbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/logbuf.hh,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- logbuf.hh 5 Mar 2003 21:25:26 -0000 1.6 +++ logbuf.hh 31 Oct 2003 22:33:10 -0000 1.7 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,22 +28,23 @@ namespace Prague { -class logbuf : public std::streambuf -{ - typedef char char_type; - typedef int int_type; -public: - logbuf(size_t size) : wrapped(false) { char_type *p = new char_type[size]; setp(p, p + size);} - ~logbuf() { delete [] pbase();} - void clear() { setp(pbase(), epptr()); wrapped = false;} - void dump(std::ostream &); + class logbuf : public std::streambuf + { + typedef char char_type; + typedef int int_type; + public: + logbuf(size_t size) : wrapped(false) + { char_type *p = new char_type[size]; setp(p, p + size); } + ~logbuf() { delete [] pbase(); } + void clear() { setp(pbase(), epptr()); wrapped = false; } + void dump(std::ostream &); - int_type sputc(char_type c); - std::streamsize xsputn(const char_type *s, std::streamsize n); -private: - bool wrapped : 1; -}; + int_type sputc(char_type c); + std::streamsize xsputn(const char_type *s, std::streamsize n); + private: + bool wrapped : 1; + }; -}; +} // namespace #endif /* _logbuf_hh */ Index: logstream.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/logstream.hh,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- logstream.hh 18 Apr 2001 06:07:26 -0000 1.3 +++ logstream.hh 31 Oct 2003 22:33:10 -0000 1.4 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,16 +28,16 @@ namespace Prague { -class logstream : public std::ostream -{ -public: - logstream(logbuf *lb) : std::ostream(lb) {} - logbuf *rdbuf () { return static_cast<logbuf *> (std::ostream::rdbuf());} - logbuf *operator -> () { return rdbuf();} - void dump(std::ostream &os) { rdbuf()->dump(os);} -private: -}; + class logstream : public std::ostream + { + public: + logstream(logbuf *lb) : std::ostream(lb) { } + logbuf *rdbuf () { return static_cast<logbuf *> (std::ostream::rdbuf()); } + logbuf *operator -> () { return rdbuf(); } + void dump(std::ostream &os) { rdbuf()->dump(os); } + private: + }; -}; +} // namespace #endif /* _logstream_hh */ Index: ntree.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/ntree.hh,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ntree.hh 2 Jun 2002 23:42:22 -0000 1.5 +++ ntree.hh 31 Oct 2003 22:33:10 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * this code was originally written by * Author: Kevin S. Van Horn ([email protected]) [...1785 lines suppressed...] @@ -1680,13 +1688,17 @@ template <class T> bool _ntree_node<T>::has_ancestor(const self * p) -{ +{ const self * q = this; while (q) if (q == p) return true; else q = q->parent; return false; } +*/ #endif + +} // namespace + #endif /* _ntree_h */ Index: regex.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Sys/regex.hh,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- regex.hh 18 Nov 2002 14:42:50 -0000 1.7 +++ regex.hh 31 Oct 2003 22:33:11 -0000 1.8 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,69 +29,69 @@ namespace Prague { -//. rxmatch represents matches of a regular expression search -class rxmatch -{ -public: - typedef regmatch_t *iterator; - rxmatch() : _n(0), _r(0) {} - ~rxmatch() { delete [] _r;} - size_t size() const { return _n;} - iterator begin() const { return _r;} - iterator end() const { return _r + _n;} - std::string substr(iterator i) const { return _s.substr(i->rm_so, i->rm_eo - i->rm_so);} - operator bool () const { return _n;} - friend class regex; -private: - std::string _s; - size_t _n; - regmatch_t *_r; - rxmatch(const std::string &s, int p, size_t n, regmatch_t *r) : _s(s), _n(n), _r(r) + //. rxmatch represents matches of a regular expression search + class rxmatch { - if (p == -1) _n = 0; - for (size_t i = 0; i != n; ++i) - if (r[i].rm_so == -1) { _n = i; break;} - else r[i].rm_so += p, r[i].rm_eo += p; - } -}; + public: + typedef regmatch_t *iterator; + rxmatch() : _n(0), _r(0) { } + ~rxmatch() { delete [] _r; } + size_t size() const { return _n; } + iterator begin() const { return _r; } + iterator end() const { return _r + _n; } + std::string substr(iterator i) const { return _s.substr(i->rm_so, i->rm_eo - i->rm_so); } + operator bool () const { return _n; } + friend class regex; + private: + std::string _s; + size_t _n; + regmatch_t *_r; + rxmatch(const std::string &s, int p, size_t n, regmatch_t *r) : _s(s), _n(n), _r(r) + { + if (p == -1) _n = 0; + for (size_t i = 0; i != n; ++i) + if (r[i].rm_so == -1) { _n = i; break;} + else r[i].rm_so += p, r[i].rm_eo += p; + } + }; -class regex -{ - struct rx_t + class regex { - rx_t(bool e) : rx(0), count(1), extended(e) {} - ~rx_t() { if (rx) regfree(rx); delete rx;} - regex_t *rx; - short count; - bool extended; + struct rx_t + { + rx_t(bool e) : rx(0), count(1), extended(e) { } + ~rx_t() { if (rx) regfree(rx); delete rx; } + regex_t *rx; + short count; + bool extended; + }; + public: + enum syntax { extended = REG_EXTENDED, basic}; + regex(int e = extended) : _info(new rx_t(e & extended)) { } + regex(const std::string &, int = extended); + regex(const regex &); + regex &operator = (const regex &); + regex &operator = (const std::string &); + ~regex(); + std::string::size_type match(const std::string &, int = 0) const; + rxmatch search(const std::string &, int = 0) const; + bool OK() const { return _info && _info->rx; } + private: + std::string error(int); + rx_t *_info; }; -public: - enum syntax { extended = REG_EXTENDED, basic}; - regex(int e = extended) : _info(new rx_t(e & extended)) {} - regex(const std::string &, int = extended); - regex(const regex &); - regex &operator = (const regex &); - regex &operator = (const std::string &); - ~regex(); - std::string::size_type match(const std::string &, int = 0) const; - rxmatch search(const std::string &, int = 0) const; - bool OK() const { return _info && _info->rx;} -private: - std::string error(int); - rx_t *_info; -}; -extern const regex rxwhite; // = "[ \n\t\r\v\f]+" -extern const regex rxint; // = "-?[0-9]+" -extern const regex rxdouble; // = "-?(([0-9]+.[0-9]*)| - // ([0-9]+)|(.[0-9]+)) - // ([eE][---+]?[0-9]+)?" -extern const regex rxalpha; // = "[A-Za-z]+" -extern const regex rxlowercase; // = "[a-z]+" -extern const regex rxuppercase; // = "[A-Z]+" -extern const regex rxalphanum; // = "[0-9A-Za-z]+" -extern const regex rxidentifier; // = "[A-Za-z_][A-Za-z0-9_]*" + extern const regex rxwhite; // = "[ \n\t\r\v\f]+" + extern const regex rxint; // = "-?[0-9]+" + extern const regex rxdouble; // = "-?(([0-9]+.[0-9]*)| + // ([0-9]+)|(.[0-9]+)) + // ([eE][---+]?[0-9]+)?" + extern const regex rxalpha; // = "[A-Za-z]+" + extern const regex rxlowercase; // = "[a-z]+" + extern const regex rxuppercase; // = "[A-Z]+" + extern const regex rxalphanum; // = "[0-9A-Za-z]+" + extern const regex rxidentifier; // = "[A-Za-z_][A-Za-z0-9_]*" -}; +} // namespace #endif /* _regex_hh */