Thread: [complement-svn] SF.net SVN: complement: [1882] trunk/complement/explore (Page 6)
Status: Pre-Alpha
Brought to you by:
complement
From: <dmi...@us...> - 2008-05-25 12:14:47
|
Revision: 1882 http://complement.svn.sourceforge.net/complement/?rev=1882&view=rev Author: dmitryosmakov Date: 2008-05-25 05:14:17 -0700 (Sun, 25 May 2008) Log Message: ----------- fixed lib Opts : loops in get functions are replaced by find and copy algorithms , help function is rewriten (using overloaded << operator for class Opt) Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-05-24 10:09:48 UTC (rev 1881) +++ trunk/complement/explore/include/misc/opts.h 2008-05-25 12:14:17 UTC (rev 1882) @@ -12,28 +12,27 @@ #include <exception> #include <stdexcept> -const char* OPT_DEFAULT_DESCRIPTION = "(no description)"; -const char* OPT_DEFAULT_LONGNAME = "(no longname)"; +#define all(c) (c).begin() , (c).end() class Opt { public: - Opt() { cnt = 0 , shortname = ' '; } + Opt() : shortname(' ') + { } char shortname; std::string longname; std::string desc; std::string default_v; int token; - + std::vector< std::string > args; std::vector< int > pos; bool has_arg; - bool is_set; - int cnt; // number of times this option was encounterd in command line bool operator==( const std::string& _longname ) const { return longname == _longname; } bool operator==( char _shortname ) const { return shortname == _shortname; } bool operator==( int _token ) const { return token == _token; } + friend std::ostream& operator<<(std::ostream& t,const Opt& opt); }; class Opts @@ -50,14 +49,14 @@ // adding option / flag (option that doesn't need arguments) template <class T> - int add( const std::string& _longname,T _default_value,const std::string& _desc = OPT_DEFAULT_DESCRIPTION ); + int add( const std::string& _longname,T _default_value,const std::string& _desc = "(no decription)" ); template <class T> - int add( char _shortname,T _default_value,const std::string& _longname = OPT_DEFAULT_LONGNAME, const std::string& _desc = OPT_DEFAULT_DESCRIPTION ); + int add( char _shortname,T _default_value,const std::string& _longname = "(no longname)", const std::string& _desc = "(no decription)" ); - int addflag( const std::string& _longname,const std::string& desc = OPT_DEFAULT_DESCRIPTION); + int addflag( const std::string& _longname = "(no longname)",const std::string& desc = "(no decription)"); - int addflag( char _shortname,const std::string& _longname = OPT_DEFAULT_LONGNAME,const std::string& _desc = OPT_DEFAULT_DESCRIPTION ); + int addflag( char _shortname,const std::string& _longname = "(no longname)",const std::string& _desc = "(no decription)" ); // getting option @@ -151,54 +150,42 @@ template <class T> bool Opts::is_set(T field) const { - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (*i == field) - return i->is_set; - return false; + options_container_type::const_iterator i = find(all(storage),field); + return ( (i == storage.end()) ? false : !i->pos.empty()); } template <class T> int Opts::get_cnt(T field) const { - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (*i == field) - return i->cnt; - return 0; + options_container_type::const_iterator i = find(all(storage),field); + return ( (i == storage.end()) ? 0 : i->pos.size()); } template < class T , class V > T Opts::get( V field ) { - options_container_type::const_iterator i; + options_container_type::const_iterator i = find(all(storage),field); T res; - for ( i = storage.begin(); i != storage.end(); ++i ) + + if (i != storage.end()) { - if ( *i == field ) + if ( !i->has_arg ) { - if ( !i->has_arg ) - { - throw std::logic_error("using Opts::get for option without arguments"); - } - - std::stringstream ss; - ss << (i->args.empty() ? i->default_v : i->args[0]); - ss >> res; + throw std::logic_error("using Opts::get for option without arguments"); + } - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args[0]); - } - - break; + std::stringstream ss(i->args.empty() ? i->default_v : i->args[0]); + ss >> res; + + if (ss.fail()) + { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->args.empty() ? i->default_v : i->args[0]); } } - - if ( i == storage.end() ) - { + else + { std::stringstream ss1; ss1 << field; throw unknown_option( ss1.str() ); @@ -211,67 +198,60 @@ template <class T , class V> T Opts::get_default( V field ) { - options_container_type::const_iterator i; + options_container_type::const_iterator i = find(all(storage),field); T res; - for (i = storage.begin();i != storage.end();++i) - if (*i == field) - { - if (!i->has_arg) - throw std::logic_error("using Opts::get for option without arguments"); + + if (i != storage.end()) + { + if (!i->has_arg) + throw std::logic_error("using Opts::get for option without arguments"); - std::stringstream ss; - ss << i->default_v; + std::stringstream ss(i->default_v); + ss >> res; - ss >> res; - - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->default_v); - } - - break; - } - - if (i == storage.end()) + if (ss.fail()) + { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->default_v); + } + } + else { std::stringstream ss1; ss1 << field; throw unknown_option( ss1.str() ); } + return res; } template <class V , class BackInsertIterator> void Opts::getemall( V field , BackInsertIterator bi) { - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (*i == field) - { - if (!i->has_arg) - throw std::logic_error("using Opts::getemall for option without arguments"); + options_container_type::const_iterator i = find(all(storage),field); + if (i != storage.end()) + { + if (!i->has_arg) + throw std::logic_error("using Opts::getemall for option without arguments"); - if (!i->args.empty()) - for (int j = 0;j < i->args.size();j++) - { + if (!i->args.empty()) + { + for (int j = 0;j < i->args.size();++j) + { + std::stringstream ss(i->args[j]); + ss >> *bi++; - std::stringstream ss(i->args[j]); - ss >> *bi++; - - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args[j]); - } + if (ss.fail()) + { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->args[j]); } - - break; + } } - - if (i == storage.end()) + } + else { std::stringstream ss1; ss1 << field; @@ -282,27 +262,18 @@ template <class V , class BackInsertIterator> void Opts::get_pos( V field , BackInsertIterator bi) { - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - if (*i == field) - { - if (i->is_set) - for (int j = 0;j < i->pos.size();j++) - { - *bi++ = i->pos[j]; - } - - break; - } + options_container_type::const_iterator i = find(all(storage),field); - if (i == storage.end()) + if (i != storage.end()) { + copy(all(i->pos),bi); + } + else + { std::stringstream ss1; ss1 << field; throw unknown_option(ss1.str()); } } - - #endif Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-05-24 10:09:48 UTC (rev 1881) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-05-25 12:14:17 UTC (rev 1882) @@ -10,10 +10,6 @@ string Opts::get_pname() const { return pname; } -bool Opts::isterm(const string& s) -{ - return (s == "--"); -} bool Opts::is_opt_name(const string& s) { @@ -81,6 +77,20 @@ return storage.end(); } +ostream& operator<<(ostream& out,const Opt& opt) +{ + if (opt.shortname == ' ') + { + out << "--" << opt.longname << '\t' << (opt.has_arg ? (string("[") + opt.default_v + "]\t") : "" ) << opt.desc; + } + else + { + out << '-' << opt.shortname << '\t' << (!opt.longname.empty() ? (string("[--") + opt.longname +"]\t") : "") << (opt.has_arg ? string("[") + opt.default_v + ("]\t") : "") << opt.desc; + } + + return out; +} + void Opts::help(ostream& out) { if (!brief.empty()) @@ -90,13 +100,11 @@ if (!copyright.empty()) out << copyright << endl; - out << "usage: " << endl; - out << pname << " [option ...] [optiongoup ...] [end operands ...]" << endl; - out << "available options:" << endl << "shortname:" << '\t' << "longname:" << '\t' << "default value" << '\t' << "description" << endl; + out << "Valid options:" << endl; options_container_type::const_iterator i; for (i = storage.begin();i != storage.end();++i) { - out << i->shortname << "\t[--" << i->longname << "] [" << i->default_v << "]\t-\t" << i->desc << endl; + out << *i << endl; } } @@ -107,7 +115,6 @@ opt.longname = _longname; opt.desc = _desc; opt.has_arg = false; - opt.is_set = false; opt.token = ++free_token; storage.push_back(opt); return opt.token; @@ -119,7 +126,6 @@ opt.longname = _longname; opt.desc = _desc; opt.has_arg = false; - opt.is_set = false; opt.token = ++free_token; storage.push_back(opt); return opt.token; @@ -132,7 +138,7 @@ int i = 1; int j = 1; int q = 0; - while (i < ac && !isterm(av[i])) + while ( (i < ac) && (string(av[i]) != "--") ) { if (is_opt_name(av[i])) { @@ -154,8 +160,6 @@ else { p->pos.push_back(++q); - p->is_set = true; - p->cnt++; if (p->has_arg) { if (!arg.empty()) @@ -184,8 +188,6 @@ } else { - p->is_set = true; - p->cnt++; p->pos.push_back(++q); if (p->has_arg) throw missing_arg( "-" + string(1,optgroup[j]) ); @@ -197,7 +199,7 @@ i++; } - i += (i < ac && isterm(av[i])); + i += ( i < ac ); while (i < ac) av[j++] = av[i++]; Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-24 10:09:48 UTC (rev 1881) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-25 12:14:17 UTC (rev 1882) @@ -15,12 +15,10 @@ #include <vector> #include <list> #include <fstream> + #include <iostream> -// #include <iostream> - using namespace std; - int EXAM_IMPL(opts_test::bool_option) { const char* argv[] = { "name", "-h" }; @@ -711,11 +709,11 @@ opts.addflag('h',"help","print this help message"); - opts.addflag('v',"verbose"); opts.addflag("flag","some program flag"); + opts.addflag('v',"version","view program version"); opts.add('I',"/usr/include","include","include paths" ); opts.add('p',80,"port","listen to tcp port"); - opts.add('t',"standart");; + opts.add("mode","standart","program mode"); opts.parse(argc,argv); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-06 14:41:48
|
Revision: 1888 http://complement.svn.sourceforge.net/complement/?rev=1888&view=rev Author: complement Date: 2008-06-06 07:41:32 -0700 (Fri, 06 Jun 2008) Log Message: ----------- take into account extra CFLAGS and LDFLAGS; configurable via 'configure'; don't assume presence of STLport. Modified Paths: -------------- trunk/complement/explore/Makefiles/ChangeLog trunk/complement/explore/Makefiles/gmake/extern.mak trunk/complement/explore/Makefiles/gmake/gcc.mak trunk/complement/explore/Makefiles/gmake/top.mak trunk/complement/explore/configure Modified: trunk/complement/explore/Makefiles/ChangeLog =================================================================== --- trunk/complement/explore/Makefiles/ChangeLog 2008-06-06 12:29:52 UTC (rev 1887) +++ trunk/complement/explore/Makefiles/ChangeLog 2008-06-06 14:41:32 UTC (rev 1888) @@ -3,8 +3,13 @@ * gmake/targetdirs.mak: use $(DESTDIR) as in common practice (change root of installation, but don't change run paths); - * gmake/depend.mak: fix options for ctags/etags. + * gmake/depend.mak: fix options for ctags/etags; + * gmake/gcc.mak, gmake/top.mak, configure: take into account + extra CFLAGS and LDFLAGS; configurable via 'configure'; + + * gmake/extern.mak: don't assume presence of STLport. + 2008-02-27 Petr Ovtchenkov <pt...@is...> * gmake/lib/gcc.mak: 3.3 is normal compiler, just some Modified: trunk/complement/explore/Makefiles/gmake/extern.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/extern.mak 2008-06-06 12:29:52 UTC (rev 1887) +++ trunk/complement/explore/Makefiles/gmake/extern.mak 2008-06-06 14:41:32 UTC (rev 1888) @@ -1,6 +1,6 @@ -# Time-stamp: <07/03/08 22:41:26 ptr> +# Time-stamp: <08/06/06 17:06:16 yeti> # -# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 +# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006, 2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -30,9 +30,11 @@ # STLport library +ifndef STLPORT_DIR ifndef WITHOUT_STLPORT -STLPORT_DIR ?= ${HOME}/STLport.lab/STLport +WITHOUT_STLPORT = 1 endif +endif ifdef STLPORT_DIR STLPORT_LIB_DIR ?= $(STLPORT_DIR)/${TARGET_NAME}lib Modified: trunk/complement/explore/Makefiles/gmake/gcc.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/gcc.mak 2008-06-06 12:29:52 UTC (rev 1887) +++ trunk/complement/explore/Makefiles/gmake/gcc.mak 2008-06-06 14:41:32 UTC (rev 1888) @@ -1,4 +1,4 @@ -# Time-stamp: <08/02/26 13:46:36 ptr> +# Time-stamp: <08/06/06 17:38:26 yeti> # # Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov @@ -179,6 +179,10 @@ CXXFLAGS += ${EXTRA_CXXFLAGS} endif +ifdef EXTRA_CFLAGS +CFLAGS += ${EXTRA_CFLAGS} +endif + CDEPFLAGS = -E -M CCDEPFLAGS = -E -M Modified: trunk/complement/explore/Makefiles/gmake/top.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/top.mak 2008-06-06 12:29:52 UTC (rev 1887) +++ trunk/complement/explore/Makefiles/gmake/top.mak 2008-06-06 14:41:32 UTC (rev 1888) @@ -1,4 +1,4 @@ -# Time-stamp: <07/07/12 10:55:41 ptr> +# Time-stamp: <08/06/06 17:28:38 yeti> # # Copyright (c) 1997-1999, 2002, 2003, 2005-2007 # Petr Ovtchenkov @@ -25,6 +25,10 @@ COMPILER_NAME := gcc endif +ifndef LDFLAGS +LDFLAGS := +endif + ifndef ALL_TAGS ifndef _NO_SHARED_BUILD @@ -91,6 +95,8 @@ # os-specific local rules (or other project-specific definitions) -include specific.mak +LDFLAGS += ${EXTRA_LDFLAGS} + # derive common targets (*.o, *.d), # build rules (including output catalogs) include ${RULESBASE}/gmake/targets.mak Modified: trunk/complement/explore/configure =================================================================== --- trunk/complement/explore/configure 2008-06-06 12:29:52 UTC (rev 1887) +++ trunk/complement/explore/configure 2008-06-06 14:41:32 UTC (rev 1888) @@ -1,6 +1,6 @@ #!/bin/sh -# Time-stamp: <08/02/26 16:02:32 yeti> +# Time-stamp: <08/06/06 17:44:52 yeti> base=`cd \`dirname $0\`; echo $PWD` @@ -47,6 +47,10 @@ --with-mssdk=<dir> use MS SDK from this catalog --with-extra-cxxflags=<options> pass extra options to C++ compiler + --with-extra-cflags=<options> + pass extra options to C compiler + --with-extra-ldflags=<options> + pass extra options to linker (via C/C++) --use-static-gcc use static gcc libs instead of shared libgcc_s (useful for gcc compiler, that was builded with --enable-shared [default]; if compiler was builded with --disable-shared, static libraries will be used in any case) @@ -69,6 +73,8 @@ \$CXX C++ compiler name (use --target= for cross-compilation) \$CC C compiler name (use --target= for cross-compilation) \$CXXFLAGS pass extra options to C++ compiler + \$CFLAGS pass extra options to C compiler + \$LDFLAGS pass extra options to linker (via C/C++) Options has preference over environment variables. @@ -156,6 +162,14 @@ write_option "$option" EXTRA_CXXFLAGS cxxflags_set=y ;; + --with-extra-cflags=*) + write_option "$option" EXTRA_CFLAGS + cflags_set=y + ;; + --with-extra-ldflags=*) + write_option "$option" EXTRA_LDFLAGS + ldflags_set=y + ;; --use-static-gcc) write_option "1" USE_STATIC_LIBGCC ;; @@ -236,6 +250,22 @@ fi fi +if [ "$CFLAGS" != "" ]; then + if [ "$cflags_set" = "" ]; then + write_option "$CFLAGS" EXTRA_CFLAGS + else + echo "Both --with-extra-cflags and \$CFLAGS set, using the first" + fi +fi + +if [ "$LDFLAGS" != "" ]; then + if [ "$ldflags_set" = "" ]; then + write_option "$LDFLAGS" EXTRA_LDFLAGS + else + echo "Both --with-extra-ldflags and \$LDFLAGS set, using the first" + fi +fi + # default settings default_settings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-06 17:27:26
|
Revision: 1889 http://complement.svn.sourceforge.net/complement/?rev=1889&view=rev Author: complement Date: 2008-06-06 10:27:03 -0700 (Fri, 06 Jun 2008) Log Message: ----------- functions for generating UIDs; libxmt revision to 2.0.3 Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/include/mt/uid.h 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 13:38:05 ptr> +// -*- C++ -*- Time-stamp: <08/06/06 21:21:30 yeti> /* * Copyright (c) 2006 @@ -65,6 +65,9 @@ const char *hostid_str(); const xmt::uuid_type& hostid(); +std::string uid_str(); +xmt::uuid_type uid(); + } // namespace xmt #endif // __mt_uid_h Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,3 +1,9 @@ +2008-06-06 Petr Ovtchenkov <pt...@is...> + + * uid.h, uid.cc: functions for generating UIDs; + + * libxmt: bump revision to 2.0.3. + 2008-04-23 Petr Ovtchenkov <pt...@is...> * mutex: remove STLport-specific macro STATIC_CAST; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/04/23 23:15:02 ptr> +# -*- Makefile -*- Time-stamp: <08/06/06 21:25:42 yeti> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 2 +PATCH = 3 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/lib/mt/uid.cc 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 13:38:19 ptr> +// -*- C++ -*- Time-stamp: <08/06/06 21:23:34 yeti> /* * Copyright (c) 2006 @@ -34,6 +34,16 @@ uuid_type __uid_init::_host_id; char __uid_init::_host_id_str[48]; +class __uuid_init +{ + public: + __uuid_init(); + + static ifstream _uuid; +}; + +ifstream __uuid_init::_uuid; + __uid_init::__uid_init() { static mutex _lk; @@ -83,8 +93,21 @@ >> reinterpret_cast<unsigned&>(_host_id.u.b[15]); } +__uuid_init::__uuid_init() +{ + static mutex _lk; + + scoped_lock lock( _lk ); + + if ( !_uuid.is_open() ) { + _uuid.open( "/proc/sys/kernel/random/uuid" ); + } +} + } // namespace detail +using namespace std; + const char *hostid_str() { static detail::__uid_init _uid; @@ -97,4 +120,63 @@ return detail::__uid_init::_host_id; } +std::string uid_str() +{ + static detail::__uuid_init _uid; + + static mutex _lk; + + scoped_lock lock( _lk ); + + std::string tmp; + + getline( _uid._uuid, tmp ); + + return tmp; +} + +xmt::uuid_type uid() +{ + string tmp = uid_str(); + uuid_type id; + + stringstream s; + s << tmp[0] << tmp[1] << ' ' + << tmp[2] << tmp[3] << ' ' + << tmp[4] << tmp[5] << ' ' + << tmp[6] << tmp[7] << ' ' // - + << tmp[9] << tmp[10] << ' ' + << tmp[11] << tmp[12] << ' ' // - + << tmp[14] << tmp[15] << ' ' + << tmp[16] << tmp[17] << ' ' // - + << tmp[19] << tmp[20] << ' ' + << tmp[21] << tmp[22] << ' ' // - + << tmp[24] << tmp[25] << ' ' + << tmp[26] << tmp[27] << ' ' + << tmp[28] << tmp[29] << ' ' + << tmp[30] << tmp[31] << ' ' + << tmp[32] << tmp[33] << ' ' + << tmp[34] << tmp[35]; + + s >> hex + >> reinterpret_cast<unsigned&>(id.u.b[0]) + >> reinterpret_cast<unsigned&>(id.u.b[1]) + >> reinterpret_cast<unsigned&>(id.u.b[2]) + >> reinterpret_cast<unsigned&>(id.u.b[3]) + >> reinterpret_cast<unsigned&>(id.u.b[4]) + >> reinterpret_cast<unsigned&>(id.u.b[5]) + >> reinterpret_cast<unsigned&>(id.u.b[6]) + >> reinterpret_cast<unsigned&>(id.u.b[7]) + >> reinterpret_cast<unsigned&>(id.u.b[8]) + >> reinterpret_cast<unsigned&>(id.u.b[9]) + >> reinterpret_cast<unsigned&>(id.u.b[10]) + >> reinterpret_cast<unsigned&>(id.u.b[11]) + >> reinterpret_cast<unsigned&>(id.u.b[12]) + >> reinterpret_cast<unsigned&>(id.u.b[13]) + >> reinterpret_cast<unsigned&>(id.u.b[14]) + >> reinterpret_cast<unsigned&>(id.u.b[15]); + + return id; +} + } // namespace xmt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-07 11:28:22
|
Revision: 1890 http://complement.svn.sourceforge.net/complement/?rev=1890&view=rev Author: complement Date: 2008-06-07 04:28:16 -0700 (Sat, 07 Jun 2008) Log Message: ----------- don't duplicate options in config.mak, that has default values in makefiles Modified Paths: -------------- trunk/complement/explore/Makefiles/ChangeLog trunk/complement/explore/configure Modified: trunk/complement/explore/Makefiles/ChangeLog =================================================================== --- trunk/complement/explore/Makefiles/ChangeLog 2008-06-06 17:27:03 UTC (rev 1889) +++ trunk/complement/explore/Makefiles/ChangeLog 2008-06-07 11:28:16 UTC (rev 1890) @@ -1,3 +1,8 @@ +2008-06-07 Petr Ovtchenkov <pt...@is...> + + * configure: don't duplicate options in config.mak, that + has default values in makefiles. + 2008-06-06 Petr Ovtchenkov <pt...@is...> * gmake/targetdirs.mak: use $(DESTDIR) as in common practice Modified: trunk/complement/explore/configure =================================================================== --- trunk/complement/explore/configure 2008-06-06 17:27:03 UTC (rev 1889) +++ trunk/complement/explore/configure 2008-06-07 11:28:16 UTC (rev 1890) @@ -1,6 +1,6 @@ #!/bin/sh -# Time-stamp: <08/06/06 17:44:52 yeti> +# Time-stamp: <08/06/07 15:22:06 yeti> base=`cd \`dirname $0\`; echo $PWD` @@ -86,27 +86,26 @@ # write_option "${PWD}/external/boost" BOOST_DIR # fi - if [ "$stlport_set" = "" ]; then - # write_option "${PWD}/external/STLport" STLPORT_DIR - write_option "1" WITHOUT_STLPORT - fi + # Set in Makefiles/gmake/extern.mak + # if [ -z "${stlport_set}" ]; then + # # write_option "${PWD}/external/STLport" STLPORT_DIR + # write_option "1" WITHOUT_STLPORT + # fi + # write_option "${PWD}/build/" BASE_INSTALL_DIR '${DESTDIR}' - if [ "$compiler_family_set" = "" ]; then - write_option gcc COMPILER_NAME - fi - # if [ "$prefix_set" = "" ]; then + + # Set in Makefiles/gmake/top.mak + # if [ -z "${compiler_family_set}" ]; then + # write_option gcc COMPILER_NAME + # fi + + # Set in Makefiles/gmake/targetdirs.mak + # if [ -z "${prefix_set}" ]; then # write_option "/usr/local" BASE_INSTALL_DIR '${DESTDIR}' # fi } -case $# in - 0) - if [ ! -f ${configmak} ]; then - default_settings - fi - exit 0 - ;; -esac +[ $# -eq 0 ] && { >${configmak}; default_settings; exit 0; } for a in $@ ; do case $a in @@ -121,8 +120,7 @@ esac done -rm -f ${configmak} -touch ${configmak} +>${configmak} while : do @@ -207,7 +205,7 @@ ;; --prefix=*) write_option "$option" BASE_INSTALL_DIR '${DESTDIR}' - # prefix_set=y + prefix_set=y ;; --bindir=*) write_option "$option" INSTALL_BIN_DIR '${DESTDIR}' @@ -221,46 +219,46 @@ esac done -if [ "$CXX" != "" ]; then - if [ "$cxx_set" != "" ]; then +if [ -n "${CXX}" ]; then + if [ -n "${cxx_set}" ]; then echo "Both --with-cxx and \$CXX set, using the first" - elif [ "$target_set" = "" ]; then - write_option "$CXX" _FORCE_CXX + elif [ -z "${target_set}" ]; then + write_option "${CXX}" _FORCE_CXX else echo "For cross-compilation with gcc use --target option only" fi - if [ "$CC" = "" ] && [ "$cc_set" = "" ]; then + if [ -z "${CC}" -a -z "${cc_set}" ]; then echo "\$CXX set, but I don't see \$CC!" fi fi -if [ "$CC" != "" ]; then - if [ "$cxx_set" != "" ]; then +if [ -n "${CC}" ]; then + if [ -n "${cxx_set}" ]; then echo "Both --with-cc and \$CC set, using the first" else - write_option "$CC" _FORCE_CC + write_option "${CC}" _FORCE_CC fi fi -if [ "$CXXFLAGS" != "" ]; then - if [ "$cxxflags_set" = "" ]; then - write_option "$CXXFLAGS" EXTRA_CXXFLAGS +if [ -n "${CXXFLAGS}" ]; then + if [ -z "${cxxflags_set}" ]; then + write_option "${CXXFLAGS}" EXTRA_CXXFLAGS else echo "Both --with-extra-cxxflags and \$CXXFLAGS set, using the first" fi fi -if [ "$CFLAGS" != "" ]; then - if [ "$cflags_set" = "" ]; then - write_option "$CFLAGS" EXTRA_CFLAGS +if [ -n "${CFLAGS}" ]; then + if [ -z "${cflags_set}" ]; then + write_option "${CFLAGS}" EXTRA_CFLAGS else echo "Both --with-extra-cflags and \$CFLAGS set, using the first" fi fi -if [ "$LDFLAGS" != "" ]; then - if [ "$ldflags_set" = "" ]; then - write_option "$LDFLAGS" EXTRA_LDFLAGS +if [ -n "${LDFLAGS}" ]; then + if [ -z "${ldflags_set}" ]; then + write_option "${LDFLAGS}" EXTRA_LDFLAGS else echo "Both --with-extra-ldflags and \$LDFLAGS set, using the first" fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-12 12:57:06
|
Revision: 1894 http://complement.svn.sourceforge.net/complement/?rev=1894&view=rev Author: complement Date: 2008-06-12 05:55:26 -0700 (Thu, 12 Jun 2008) Log Message: ----------- Remove LDSEARCH macro; add option for STLport includes in configure Modified Paths: -------------- trunk/complement/explore/Makefiles/gmake/app/gcc.mak trunk/complement/explore/Makefiles/gmake/app/top.mak trunk/complement/explore/Makefiles/gmake/extern.mak trunk/complement/explore/Makefiles/gmake/icc.mak trunk/complement/explore/Makefiles/gmake/lib/CC.mak trunk/complement/explore/Makefiles/gmake/lib/aCC.mak trunk/complement/explore/Makefiles/gmake/lib/gcc.mak trunk/complement/explore/Makefiles/gmake/lib/icc.mak trunk/complement/explore/Makefiles/gmake/lib/vc6.mak trunk/complement/explore/configure trunk/complement/explore/lib/DB/PgSQL/Makefile trunk/complement/explore/lib/exam/ut/Makefile trunk/complement/explore/lib/janus/Makefile trunk/complement/explore/lib/janus/ut/Makefile trunk/complement/explore/lib/misc/ut/Makefile trunk/complement/explore/lib/mt/ut/Makefile trunk/complement/explore/lib/net/samples/httpclient/Makefile trunk/complement/explore/lib/net/ut/Makefile trunk/complement/explore/lib/sockios/perf/Makefile trunk/complement/explore/lib/sockios/ut/Makefile trunk/complement/explore/lib/stem/ut/Makefile trunk/complement/explore/lib/stem/ut/dl/Makefile Removed Paths: ------------- trunk/complement/explore/lib/mt/Makefile.mwccnlm trunk/complement/explore/lib/mt/gcc-libstd.mak trunk/complement/explore/lib/mt/mwccnlm.mak trunk/complement/explore/lib/mt/ut/gcc-libstd.mak Modified: trunk/complement/explore/Makefiles/gmake/app/gcc.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/app/gcc.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/app/gcc.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/05/30 23:54:39 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 13:54:55 ptr> # # Copyright (c) 1997-1999, 2002, 2003, 2005-2007 # Petr Ovtchenkov @@ -62,14 +62,21 @@ endif ifndef WITHOUT_STLPORT -LDSEARCH += -L${STLPORT_LIB_DIR} - +ifeq (${STLPORT_LIB_DIR},) release-shared: STLPORT_LIB = -lstlport release-static: STLPORT_LIB = -Wl,-Bstatic -lstlport -Wl,-Bdynamic dbg-shared: STLPORT_LIB = -lstlportg dbg-static: STLPORT_LIB = -Wl,-Bstatic -lstlportg -Wl,-Bdynamic stldbg-shared: STLPORT_LIB = -lstlportstlg stldbg-static: STLPORT_LIB = -Wl,-Bstatic -lstlportstlg -Wl,-Bdynamic +else +release-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport +release-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlport -Wl,-Bdynamic +dbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg +dbg-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlportg -Wl,-Bdynamic +stldbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg +stldbg-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlportstlg -Wl,-Bdynamic +endif ifeq ($(OSNAME),windows) LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} Modified: trunk/complement/explore/Makefiles/gmake/app/top.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/app/top.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/app/top.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/06/08 23:35:09 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 13:55:47 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -31,8 +31,6 @@ $(foreach prg,$(PRGNAMES),$(eval $(call prog_prog,$(prg)))) -LDFLAGS += ${LDSEARCH} - include ${RULESBASE}/gmake/app/${COMPILER_NAME}.mak include ${RULESBASE}/gmake/app/rules.mak include ${RULESBASE}/gmake/app/rules-install.mak Modified: trunk/complement/explore/Makefiles/gmake/extern.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/extern.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/extern.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -31,10 +31,12 @@ # STLport library ifndef STLPORT_DIR +ifndef STLPORT_INCLUDE_DIR ifndef WITHOUT_STLPORT WITHOUT_STLPORT = 1 endif endif +endif ifdef STLPORT_DIR STLPORT_LIB_DIR ?= $(STLPORT_DIR)/${TARGET_NAME}lib Modified: trunk/complement/explore/Makefiles/gmake/icc.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/icc.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/icc.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,6 +1,6 @@ -# Time-stamp: <07/03/08 21:41:21 ptr> +# Time-stamp: <08/06/12 14:57:58 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 Modified: trunk/complement/explore/Makefiles/gmake/lib/CC.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/lib/CC.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/lib/CC.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/03/08 21:39:22 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 14:58:49 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -11,12 +11,9 @@ OPT += -xcode=pic32 -dbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_DBGxx) ${LDSEARCH} ${NOSTDLIB} -stldbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_STLDBGxx) ${LDSEARCH} ${NOSTDLIB} -release-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAMExx) ${LDSEARCH} ${NOSTDLIB} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAMExx) ${NOSTDLIB} DEPENDS_COLLECTION_SUNPRO := $(DEPENDS_COLLECTION).sunpro Modified: trunk/complement/explore/Makefiles/gmake/lib/aCC.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/lib/aCC.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/lib/aCC.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/05/31 00:50:40 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 14:59:23 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -9,6 +9,6 @@ # Licensed under the Academic Free License version 3.0 # -dbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_DBGxx) ${LDSEARCH} -stldbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_STLDBGxx) ${LDSEARCH} -release-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAMExx) ${LDSEARCH} +dbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_DBGxx) +stldbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_STLDBGxx) +release-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAMExx) Modified: trunk/complement/explore/Makefiles/gmake/lib/gcc.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/lib/gcc.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/lib/gcc.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/05/31 00:55:13 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 14:08:48 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -71,11 +71,16 @@ endif ifndef WITHOUT_STLPORT -LDSEARCH += -L${STLPORT_LIB_DIR} +ifeq (${STLPORT_LIB_DIR},) release-shared: STLPORT_LIB = -lstlport dbg-shared: STLPORT_LIB = -lstlportg stldbg-shared: STLPORT_LIB = -lstlportstlg +else +release-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport +dbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg +stldbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg +endif ifeq ($(OSNAME),windows) LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} @@ -196,64 +201,52 @@ endif ifeq ($(OSNAME),hp-ux) -dbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_DBGxx) ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_STLDBGxx) ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAMExx) ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_DBGxx) +stldbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_STLDBGxx) +release-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAMExx) endif ifeq ($(OSNAME),sunos) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} endif ifeq ($(OSNAME),linux) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} endif ifeq ($(OSNAME),windows) dbg-shared: LDFLAGS += -shared -Wl,--out-implib=${LIB_NAME_OUT_DBG},--enable-auto-image-base stldbg-shared: LDFLAGS += -shared -Wl,--out-implib=${LIB_NAME_OUT_STLDBG},--enable-auto-image-base release-shared: LDFLAGS += -shared -Wl,--out-implib=${LIB_NAME_OUT},--enable-auto-image-base -dbg-static: LDFLAGS += -static ${LDSEARCH} -stldbg-static: LDFLAGS += -static ${LDSEARCH} -release-static: LDFLAGS += -static ${LDSEARCH} +dbg-static: LDFLAGS += -static +stldbg-static: LDFLAGS += -static +release-static: LDFLAGS += -static endif ifeq ($(OSNAME),freebsd) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} endif ifeq ($(OSNAME),darwin) CURRENT_VERSION := ${MAJOR}.${MINOR}.${PATCH} COMPATIBILITY_VERSION := $(CURRENT_VERSION) -dbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_DBGxx) ${LDSEARCH} ${NOSTDLIB} -stldbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_STLDBGxx) ${LDSEARCH} ${NOSTDLIB} -release-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAMExx) ${LDSEARCH} ${NOSTDLIB} -dbg-static: LDFLAGS += -staticlib ${LDSEARCH} -stldbg-static: LDFLAGS += -staticlib ${LDSEARCH} -release-static: LDFLAGS += -staticlib ${LDSEARCH} +dbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAMExx) ${NOSTDLIB} +dbg-static: LDFLAGS += -staticlib +stldbg-static: LDFLAGS += -staticlib +release-static: LDFLAGS += -staticlib endif ifeq ($(OSNAME),openbsd) -dbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAMExx) ${NOSTDLIB} endif Modified: trunk/complement/explore/Makefiles/gmake/lib/icc.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/lib/icc.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/lib/icc.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/03/08 21:37:08 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 15:00:07 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -9,19 +9,11 @@ # Licensed under the Academic Free License version 3.0 # -# Oh, the commented below work for gmake 3.78.1 and above, -# but phrase without tag not work for it. Since gmake 3.79 -# tag with assignment fail, but work assignment for all tags -# (really that more correct). - OPT += -KPIC ifeq ($(OSNAME),linux) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) endif Modified: trunk/complement/explore/Makefiles/gmake/lib/vc6.mak =================================================================== --- trunk/complement/explore/Makefiles/gmake/lib/vc6.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/Makefiles/gmake/lib/vc6.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/03/08 21:35:57 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 15:03:15 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -9,13 +9,7 @@ # Licensed under the Academic Free License version 3.0 # -# Oh, the commented below work for gmake 3.78.1 and above, -# but phrase without tag not work for it. Since gmake 3.79 -# tag with assignment fail, but work assignment for all tags -# (really that more correct). - LDLIBS ?= -LDSEARCH += /LIBPATH:"$(MSVC_LIB_DIR)" dbg-shared: OPT += /MDd stldbg-shared: OPT += /MDd @@ -30,11 +24,8 @@ stldbg-static: DEFS += /D_LIB -dbg-shared: LDFLAGS += /DLL ${LDSEARCH} -stldbg-shared: LDFLAGS += /DLL ${LDSEARCH} -release-shared: LDFLAGS += /DLL ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += /DLL +stldbg-shared: LDFLAGS += /DLL +release-shared: LDFLAGS += /DLL -LDFLAGS += /VERSION:$(MAJOR).$(MINOR) +LDFLAGS += /LIBPATH:"$(MSVC_LIB_DIR)" /VERSION:$(MAJOR).$(MINOR) Modified: trunk/complement/explore/configure =================================================================== --- trunk/complement/explore/configure 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/configure 2008-06-12 12:55:26 UTC (rev 1894) @@ -40,6 +40,7 @@ --help print this help message and exit --with-stlport=<dir> use STLport in catalog <dir> + --with-stlport-headers=<dir> use STLport headers in catalog <dir> --without-stlport compile without STLport (default) --with-boost=<dir> use boost headers in catalog <dir> --with-system-boost use boost installed on this system @@ -82,6 +83,7 @@ } default_settings () { + : # if [ "$boost_set" = "" ]; then # write_option "${PWD}/external/boost" BOOST_DIR # fi @@ -140,6 +142,10 @@ write_option "$option" STLPORT_DIR stlport_set=y ;; + --with-stlport-headers=*) + write_option "$option" STLPORT_INCLUDE_DIR + stlport_set=y + ;; --without-stlport) write_option "1" WITHOUT_STLPORT stlport_set=y Modified: trunk/complement/explore/lib/DB/PgSQL/Makefile =================================================================== --- trunk/complement/explore/lib/DB/PgSQL/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/DB/PgSQL/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,14 +1,21 @@ -# -*- Makefile -*- Time-stamp: <03/09/25 12:02:31 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:09:05 ptr> SRCROOT := ../../.. -PG_INCLUDE := /opt/pgsql/include -PG_LIB := /opt/pgsql/lib +# PG_INCLUDE := /opt/pgsql/include +# PG_LIB_DIR := /opt/pgsql/lib include Makefile.inc include ${SRCROOT}/Makefiles/gmake/top.mak -INCLUDES += -I$(SRCROOT)/include -I${PG_INCLUDE} +INCLUDES += -I$(SRCROOT)/include -LDSEARCH += -L${PG_LIB} +ifneq (${PG_INCLUDE},) +INCLUDES += -I${PG_INCLUDE} +endif + +ifneq (${PG_LIB_DIR},) +LDFLAGS += -L${PG_LIB_DIR} +endif + LDLIBS = -lpq Modified: trunk/complement/explore/lib/exam/ut/Makefile =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/exam/ut/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/09/03 22:27:45 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 14:00:05 ptr> SRCROOT := ../../.. @@ -15,12 +15,12 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif Modified: trunk/complement/explore/lib/janus/Makefile =================================================================== --- trunk/complement/explore/lib/janus/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/janus/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/02/07 12:28:46 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:26:16 ptr> SRCROOT := ../.. COMPILER_NAME := gcc @@ -12,7 +12,7 @@ LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBSTEM_DIR = ${CoMT_DIR}/lib/stem -LDSEARCH += -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR} +LDFLAGS += -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR} release-shared : LDLIBS = -lxmt -lsockios -lstem ifndef WITHOUT_STLPORT Modified: trunk/complement/explore/lib/janus/ut/Makefile =================================================================== --- trunk/complement/explore/lib/janus/ut/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/janus/ut/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/02/25 19:21:09 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:26:38 ptr> SRCROOT := ../../.. COMPILER_NAME := gcc @@ -20,12 +20,12 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR} -L$(LIBSTEM_DIR)/${OUTPUT_DIR} -L$(LIBJANUS_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBJANUS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR} -L$(LIBSTEM_DIR)/${OUTPUT_DIR} -L$(LIBJANUS_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBJANUS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_DBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_DBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif Modified: trunk/complement/explore/lib/misc/ut/Makefile =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/misc/ut/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/11/23 23:30:57 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:20:10 ptr> SRCROOT := ../../.. @@ -14,24 +14,22 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif ifeq ($(OSNAME),openbsd) -release-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} - -dbg-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} - ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -Wl,-R:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -Wl,-R:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -Wl,-R:${STLPORT_LIB_DIR} endif endif Deleted: trunk/complement/explore/lib/mt/Makefile.mwccnlm =================================================================== --- trunk/complement/explore/lib/mt/Makefile.mwccnlm 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/mt/Makefile.mwccnlm 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,32 +0,0 @@ -# -*- Makefile -*- Time-stamp: <03/06/13 16:51:25 ptr> -# $Id$ - -BASEDIR := $(shell xtmp=`pwd`; xtmp=`dirname $$xtmp`; dirname $$xtmp) -LIBDIR := $(shell xtmp=`pwd`; dirname $$xtmp) - -COMPILER_NAME = mwccnlm -include $(BASEDIR)/lib/mt/Makefile.inc - -all: all-release all-debug - -install: install-dbg-shared install-stldbg-shared install-release-shared - -all-shared: release-shared dbg-shared stldbg-shared - -all-debug: dbg-shared stldbg-shared - -all-release: release-shared - -include ${BASEDIR}/Makefiles/lib/Makefile.inc - -INCLUDES += -I$(STLPORT_INCLUDE_DIR) -I../../include - -release-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} - -release-shared : LDLIBS = -lstlport_gcc -stldbg-shared : LDLIBS = -lstlport_gcc_stldebug -dbg-shared : LDLIBS = -lstlport_gcc - - Deleted: trunk/complement/explore/lib/mt/gcc-libstd.mak =================================================================== --- trunk/complement/explore/lib/mt/gcc-libstd.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/mt/gcc-libstd.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,13 +0,0 @@ -# -*- Makefile -*- Time-stamp: <03/09/25 12:02:31 ptr> -# $Id$ - -SRCROOT := ../.. -COMPILER_NAME := gcc - -ALL_TAGS = release-shared dbg-shared - -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - -INCLUDES += -I$(SRCROOT)/include - Deleted: trunk/complement/explore/lib/mt/mwccnlm.mak =================================================================== --- trunk/complement/explore/lib/mt/mwccnlm.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/mt/mwccnlm.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,11 +0,0 @@ -# -*- Makefile -*- Time-stamp: <05/06/03 21:45:55 ptr> -# $Id$ - -SRCROOT := ../.. -COMPILER_NAME := mwccnlm - -STLPORT_DIR := ../../../Novell-STLP/STLport -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - -INCLUDES += -I$(SRCROOT)/include -I$(STLPORT_INCLUDE_DIR) Modified: trunk/complement/explore/lib/mt/ut/Makefile =================================================================== --- trunk/complement/explore/lib/mt/ut/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/mt/ut/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 22:38:12 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:11:40 ptr> SRCROOT := ../../.. @@ -27,24 +27,24 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif ifeq ($(OSNAME),openbsd) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif Deleted: trunk/complement/explore/lib/mt/ut/gcc-libstd.mak =================================================================== --- trunk/complement/explore/lib/mt/ut/gcc-libstd.mak 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/mt/ut/gcc-libstd.mak 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,48 +0,0 @@ -# -*- Makefile -*- Time-stamp: <03/11/21 08:02:55 ptr> -# $Id$ - -SRCROOT := ../../.. -COMPILER_NAME := gcc -ALL_TAGS = release-shared dbg-shared - -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - - -INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) - -# temporary, before dums fix strings: -# DEFS += -D_STLP_DONT_USE_TEMPLATE_EXPRESSION - -ifeq ($(OSNAME),linux) -release-shared: LDSEARCH = -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_STLDBG} -Wl,--rpath=${CoMT_LIB_DIR_STLDBG} -dbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_DBG} -Wl,--rpath=${CoMT_LIB_DIR_DBG} -endif - -ifeq ($(OSNAME),openbsd) -release-shared: LDSEARCH = -L${CoMT_LIB_DIR} -Wl,-R${CoMT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_STLDBG} -Wl,-R${CoMT_LIB_DIR_STLDBG} -dbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_DBG} -Wl,-R${CoMT_LIB_DIR_DBG} -endif - -release-shared : LDLIBS = -lxmt_gcc -lboost_test_utf_gcc -stldbg-shared : LDLIBS = -lxmt_gcc_stl-g -lboost_test_utf_gcc_stl-g -dbg-shared : LDLIBS = -lxmt_gcc-g -lboost_test_utf_gcc-g - -ifeq ($(OSNAME),freebsd) -release-shared : LDLIBS += -lthr -stldbg-shared : LDLIBS += -lthr -dbg-shared : LDLIBS += -lthr -endif - -ifeq ($(OSNAME),sunos) -release-shared : LDLIBS += -lrt -stldbg-shared : LDLIBS += -lrt -dbg-shared : LDLIBS += -lrt -endif - -ifeq ($(OSNAME),openbsd) -release-shared: LDLIBS = -lxmt_gcc -lboost_test_utf_gcc -endif - Modified: trunk/complement/explore/lib/net/samples/httpclient/Makefile =================================================================== --- trunk/complement/explore/lib/net/samples/httpclient/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/net/samples/httpclient/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/02/21 15:30:59 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:27:19 ptr> SRCROOT := ../../../.. # CoMT_DIR := ../../external/complement/explore @@ -18,15 +18,15 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif Modified: trunk/complement/explore/lib/net/ut/Makefile =================================================================== --- trunk/complement/explore/lib/net/ut/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/net/ut/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/02/21 15:30:59 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:17:05 ptr> SRCROOT := ../../.. # CoMT_DIR := ../../external/complement/explore @@ -18,15 +18,15 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif Modified: trunk/complement/explore/lib/sockios/perf/Makefile =================================================================== --- trunk/complement/explore/lib/sockios/perf/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/sockios/perf/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/09/05 22:48:46 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:23:48 ptr> SRCROOT := ../../.. @@ -18,11 +18,11 @@ # LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif release-shared : LDLIBS = -lxmt -lsockios -lexam Modified: trunk/complement/explore/lib/sockios/ut/Makefile =================================================================== --- trunk/complement/explore/lib/sockios/ut/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/sockios/ut/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 23:06:43 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:24:26 ptr> SRCROOT := ../../.. @@ -18,11 +18,11 @@ # LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif release-shared : LDLIBS = -lxmt -lsockios -lexam Modified: trunk/complement/explore/lib/stem/ut/Makefile =================================================================== --- trunk/complement/explore/lib/stem/ut/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/stem/ut/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 23:55:05 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:25:10 ptr> SRCROOT := ../../.. @@ -19,15 +19,15 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif Modified: trunk/complement/explore/lib/stem/ut/dl/Makefile =================================================================== --- trunk/complement/explore/lib/stem/ut/dl/Makefile 2008-06-10 05:12:41 UTC (rev 1893) +++ trunk/complement/explore/lib/stem/ut/dl/Makefile 2008-06-12 12:55:26 UTC (rev 1894) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 23:59:51 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:25:51 ptr> SRCROOT := ../../../.. @@ -12,11 +12,11 @@ INCLUDES += -I$(SRCROOT)/include -#LDSEARCH = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR} -release-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR} -dbg-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} +#LDFLAGS = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBSTEM_DIR}/${OUTPUT_DIR} +dbg-shared: LDFLAGS += -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} +stldbg-shared: LDFLAGS += -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} endif #release-shared : LDLIBS = -lxmt -lsockios -lstem -lboost_test_utf This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dmi...@us...> - 2008-06-14 21:50:44
|
Revision: 1896 http://complement.svn.sourceforge.net/complement/?rev=1896&view=rev Author: dmitryosmakov Date: 2008-06-14 14:50:39 -0700 (Sat, 14 Jun 2008) Log Message: ----------- Added basic options support to exam Modified Paths: -------------- trunk/complement/explore/include/exam/suite.h trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/Makefile.inc trunk/complement/explore/lib/exam/ut/exam_self_test.cc trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/misc/ut/opts_test.h Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/include/exam/suite.h 2008-06-14 21:50:39 UTC (rev 1896) @@ -212,6 +212,7 @@ base_logger *set_logger( base_logger * ); test_case_type test_by_name( const std::string& ); + void print_graph( std::ostream& ); private: enum { Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/include/misc/opts.h 2008-06-14 21:50:39 UTC (rev 1896) @@ -62,10 +62,18 @@ template < class T ,class V > T get( V field ); + + + template < class V > + std::string get( V field ); + template <class T , class V> T get_default( V field ); + template < class V > + std::string get_default( V field ); + template < class V , class BackInsertIterator> void getemall( V field , BackInsertIterator bi); @@ -161,6 +169,31 @@ return ( (i == storage.end()) ? 0 : i->pos.size()); } +template <class V> +std::string Opts::get( V field ) +{ + options_container_type::const_iterator i = find(all(storage),field); + std::string res; + + if (i != storage.end()) + { + if ( !i->has_arg ) + { + throw std::logic_error("using Opts::get for option without arguments"); + } + + res = i->args.empty() ? i->default_v : i->args[0]; + } + else + { + std::stringstream ss1; + ss1 << field; + throw unknown_option( ss1.str() ); + } + + return res; +} + template < class T , class V > T Opts::get( V field ) { @@ -195,6 +228,29 @@ } +template < class V> +std::string Opts::get_default( V field ) +{ + options_container_type::const_iterator i = find(all(storage),field); + std::string res; + + if (i != storage.end()) + { + if (!i->has_arg) + throw std::logic_error("using Opts::get for option without arguments"); + + res = i->default_v; + } + else + { + std::stringstream ss1; + ss1 << field; + throw unknown_option( ss1.str() ); + } + + return res; +} + template <class T , class V> T Opts::get_default( V field ) { Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/lib/exam/suite.cc 2008-06-14 21:50:39 UTC (rev 1896) @@ -389,4 +389,19 @@ return dry_girdle( 0 ); } +void test_suite::print_graph(ostream& out) +{ + out << _suite_name << endl; + for (test_case_type i = 1;i <= _count;i++) + { + out << i << " ( "; + for (list<edge_t>::const_iterator j = _edges.begin();j != _edges.end();++j) + { + if (j->second == i && j->first != 0) + out << j->first << ' '; + } + out << ") " << _test[i].name << endl; + } +} + } // namespace exam Modified: trunk/complement/explore/lib/exam/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile.inc 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/lib/exam/ut/Makefile.inc 2008-06-14 21:50:39 UTC (rev 1896) @@ -3,3 +3,4 @@ PRGNAME = exam_self_test SRC_CC = exam_self_test.cc \ exam_test_suite.cc +SRC_CPP = ./../../misc/opts.cpp Modified: trunk/complement/explore/lib/exam/ut/exam_self_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2008-06-14 21:50:39 UTC (rev 1896) @@ -8,14 +8,69 @@ */ #include "exam_test_suite.h" +#include "misc/opts.h" +#include <vector> +#include <string> -int main( int, char ** ) +using namespace std; + +int main( int argc,const char** argv) { // exam::test_suite t( "exam self test" ); // t.add( exam_self_test, "exam self test suite" ); // // return t.girdle(); - return exam_self_test(0); + // return exam_self_test(0); + + exam::test_suite t( "exam self test" ); + exam_basic_test exam_basic; + + exam::test_suite::test_case_type d0 = t.add( &exam_basic_test::function_good, exam_basic, "call test, good calls" ); + t.add( &exam_basic_test::function, exam_basic, "call test, fail calls", d0 ); + exam::test_suite::test_case_type d = t.add( &exam_basic_test::dep, exam_basic, "call test, tests dependency", d0 ); + t.add( &exam_basic_test::trace, exam_basic, "trace flags test", d ); + t.add( &exam_basic_test::dep_test_suite, exam_basic, "test suites grouping", d ); + exam::test_suite::test_case_type d2 = t.add( &exam_basic_test::multiple_dep, exam_basic, "multiple dependencies", d ); + t.add( &exam_basic_test::multiple_dep_complex, exam_basic, "complex multiple dependencies", d2 ); + + t.add( &exam_basic_test::perf, exam_basic, "performance timer test", d0 ); + t.add( &exam_basic_test::dry, exam_basic, "complex multiple dependencies, dry run", d2 ); + t.add( &exam_basic_test::single, exam_basic, "complex multiple dependencies, single test", d2 ); + + Opts opts; + + opts.addflag('h',"help","print this help message"); + opts.addflag('l',"list","list all test cases"); + opts.add('n',0,"num","run tests by number"); + + try + { + opts.parse(argc,argv); + } + catch(...) + { + cout << "there were errors" << endl; + } + + if (opts.is_set('h')) + opts.help(cout); + + if (opts.is_set('l')) + t.print_graph(cout); + + if (opts.is_set('n')) + { + stringstream ss(opts.get('n')); + int n; + while (ss >> n) + { + t.single(n); + } + + return 0; + } + + return t.girdle(); } Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-06-14 21:50:39 UTC (rev 1896) @@ -10,7 +10,6 @@ string Opts::get_pname() const { return pname; } - bool Opts::is_opt_name(const string& s) { return (s.size() > 1) && (s[0] == '-') && !is_flag_group(s); Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-14 21:50:39 UTC (rev 1896) @@ -103,5 +103,7 @@ t.add( &opts_test::help, opts, "help"); + t.add( &opts_test::long_string, opts, "long string"); + return t.girdle(); } Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-14 21:50:39 UTC (rev 1896) @@ -15,7 +15,7 @@ #include <vector> #include <list> #include <fstream> - #include <iostream> +#include <iostream> using namespace std; @@ -209,13 +209,13 @@ EXAM_CHECK( opts.is_set('t') ); EXAM_CHECK( opts.get_cnt(t_token) == 1 ); EXAM_CHECK( opts.get<int>('t') == 20); - EXAM_CHECK( opts.get_default<int>(t_token) == 10 ); + //EXAM_CHECK( opts.get_default<int>(t_token) == 10 ); EXAM_CHECK( opts.is_set(name_token) ); EXAM_CHECK( opts.get_cnt("name") == 1 ); EXAM_CHECK( opts.get<string>(name_token) == "torwalds"); EXAM_CHECK( opts.get_default<string>("name") == "linus"); EXAM_CHECK( !opts.is_set('p') ); - EXAM_CHECK( !opts.is_set("num") && opts.get<int>(num_token) == opts.get_default<int>("num") ) ; + //EXAM_CHECK( !opts.is_set("num") && opts.get<int>(num_token) == opts.get_default<int>("num") ) ; return EXAM_RESULT; } @@ -690,7 +690,7 @@ opts.getemall('I',vs.begin()); EXAM_CHECK( opts.get_default<string>("include") == "/usr/include"); - + EXAM_CHECK( vs[0] == "first" ); EXAM_CHECK( vs[1] == "second" ); EXAM_CHECK( vs[2] == "third" ); @@ -728,3 +728,25 @@ return EXAM_RESULT; } + +int EXAM_IMPL(opts_test::long_string) +{ + { + const char* argv[] = { "name" , "--string" , "long string"}; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add('s',string("default value"),"string","some string param"); + + EXAM_CHECK( opts.get('s') == "default value"); + + opts.parse(argc,argv); + + EXAM_CHECK( opts.get('s') == "long string"); + + } + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/lib/misc/ut/opts_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.h 2008-06-12 12:57:36 UTC (rev 1895) +++ trunk/complement/explore/lib/misc/ut/opts_test.h 2008-06-14 21:50:39 UTC (rev 1896) @@ -41,6 +41,7 @@ int EXAM_DECL(autocomplement_failure); int EXAM_DECL(multiple_args); int EXAM_DECL(help); + int EXAM_DECL(long_string); }; #endif // __MISC_TEST_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-27 11:20:51
|
Revision: 1924 http://complement.svn.sourceforge.net/complement/?rev=1924&view=rev Author: complement Date: 2008-06-27 04:20:41 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/sockios/sockstream.cc trunk/complement/explore/include/stem/Cron.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/lib/sockios/_sockmgr.cc trunk/complement/explore/lib/sockios/ut/Makefile.inc trunk/complement/explore/lib/sockios/ut/names.cc trunk/complement/explore/lib/sockios/ut/sockios_test.cc trunk/complement/explore/lib/sockios/ut/sockios_test.h trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/Cron.cc trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/lib/stem/ut/unit_test.cc Added Paths: ----------- trunk/complement/explore/include/sockios/socksrv.cc trunk/complement/explore/include/sockios/socksrv.h trunk/complement/explore/lib/sockios/ut/sockios2_test.cc trunk/complement/explore/lib/sockios/ut/sockios2_test.h Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2008-06-27 10:28:54 UTC (rev 1923) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2008-06-27 11:20:41 UTC (rev 1924) @@ -1,595 +1,515 @@ -// -*- C++ -*- Time-stamp: <07/09/19 11:43:21 ptr> +// -*- C++ -*- Time-stamp: <08/06/26 09:10:47 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 + * Copyright (c) 2008 * Petr Ovtchenkov * - * Portion Copyright (c) 1999-2001 - * Parallel Graphics Ltd. - * * Licensed under the Academic Free License Version 3.0 * */ -#include <algorithm> -#include <functional> - -// #ifdef __unix -// extern "C" int nanosleep(const struct timespec *, struct timespec *); -// #endif - -#ifdef STLPORT -_STLP_BEGIN_NAMESPACE -#else namespace std { -#endif -#ifndef __FIT_NO_POLL +namespace detail { -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::_open( sock_base::stype t ) +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::io_worker() { - xmt::scoped_lock lk(_fd_lck); - if ( is_open_unsafe() ) { - if ( t == sock_base::sock_stream ) { - _accept = &_Self_type::accept_tcp; - _pfd.reserve( 32 ); - if ( _pfd.size() == 0 ) { - int pipefd[2]; - pipe( pipefd ); // check err - _cfd = pipefd[1]; + epoll_event ev[/*n_ret*/ 512 ]; - _pfd.resize( 2 ); - _pfd[0].fd = fd_unsafe(); - _pfd[0].events = POLLIN; - _pfd[1].fd = pipefd[0]; - _pfd[1].events = POLLIN; - } - } else if ( t == sock_base::sock_dgram ) { - _accept = &_Self_type::accept_udp; - if ( _pfd.size() == 0 ) { - int pipefd[2]; - pipe( pipefd ); // check err - _cfd = pipefd[1]; +/* + ctl _xctl; + int r = read( pipefd[0], &_xctl, sizeof(ctl) ); - _pfd.resize( 2 ); - _pfd[0].fd = fd_unsafe(); - _pfd[0].events = POLLIN; - _pfd[1].fd = pipefd[0]; - _pfd[1].events = POLLIN; - } - } else { - throw invalid_argument( "sockmgr_stream_MP" ); - } - - _loop_cnd.set( false ); - loop_thr.launch( loop, this /* , 0, PTHREAD_STACK_MIN * 2 */ ); - _loop_cnd.try_wait(); + if ( _xctl.cmd == rqstart ) { + std::cerr << "io_worker fine" << std::endl; + } else { + std::cerr << "io_worker not fine, " << r << ", " << errno << std::endl; } -} +*/ -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::open( const in_addr& addr, int port, sock_base::stype t ) -{ - basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP<Connect,C,T>::_open( t ); -} + try { + for ( ; ; ) { + int n = epoll_wait( efd, &ev[0], /* n_ret */ 512, -1 ); -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::open( unsigned long addr, int port, sock_base::stype t ) -{ - basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP<Connect,C,T>::_open( t ); -} + if ( n < 0 ) { + if ( errno == EINTR ) { + errno = 0; + continue; + } + // throw system_error + } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::open( int port, sock_base::stype t ) -{ - basic_sockmgr::open( port, t, sock_base::inet ); - sockmgr_stream_MP<Connect,C,T>::_open( t ); -} + std::tr2::lock_guard<std::tr2::mutex> lk( dll ); -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -bool sockmgr_stream_MP<Connect,C,T>::_shift_fd() -{ - bool ret = false; - typename iterator_traits<typename _fd_sequence::iterator>::difference_type d; + for ( int i = 0; i < n; ++i ) { + if ( ev[i].data.fd == pipefd[0] ) { + cmd_from_pipe(); + } else { + typename fd_container_type::iterator ifd = descr.find( ev[i].data.fd ); + if ( ifd == descr.end() ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev[i].data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ev[i].data.fd, 0 ) < 0 ) { + // throw system_error + } + continue; + // throw std::logic_error( "file descriptor in epoll, but not in descr[]" ); + } - for ( _fd_sequence::iterator j = _pfd.begin() + 2; j != _pfd.end(); ++j ) { // _pfd at least 2 in size - // if ( j->fd == -1 ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; - // } - if ( j->revents != 0 ) { - xmt::scoped_lock _l( _c_lock ); - // We should distinguish closed socket from income message - typename container_type::iterator i = - find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp, j->fd ) ); - // Solaris return ERROR on poll, before close socket - if ( i == _M_c.end() ) { - // Socket already closed (may be after read/write failure) - // this way may not notify poll (like in HP-UX 11.00) via POLLERR flag - // as made in Solaris - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - i = _M_c.begin(); - while ( (i = find_if( i, _M_c.end(), bind2nd( _M_comp, -1 ) )) != _M_c.end() ) { - _dlock.lock(); - _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); - _dlock.unlock(); - _M_c.erase( i++ ); + fd_info& info = ifd->second; + if ( info.flags & fd_info::listener ) { + process_listener( ev[i], ifd ); + } else { + process_regular( ev[i], ifd ); + } } - } else if ( j->revents & POLLERR /* | POLLHUP | POLLNVAL */ ) { - // poll first see closed socket - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - _dlock.lock(); - _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); - _dlock.unlock(); - _M_c.erase( i ); - } else { - // Check that other side close socket: - // on Linux and (?) Solaris I see normal POLLIN event, and see error - // only after attempt to read something. - // Due to this fd isn't stream (it's upper than stream), - // I can't use ioctl with I_PEEK command here. - char x; - int nr = recv( j->fd, reinterpret_cast<void *>(&x), 1, MSG_PEEK ); - if ( nr <= 0 ) { // I can't read even one byte: this designate closed - // socket operation - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - _dlock.lock(); - _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); - _dlock.unlock(); - _M_c.erase( i ); - } else { // normal data available for reading - _dlock.lock(); - _conn_pool.push_back( i ); - // xmt::Thread::gettime( &_tpush ); - _pool_cnd.set( true ); - _observer_cnd.set( true ); - _dlock.unlock(); - - /* erase: I don't want to listen this socket - * (it may be polled elsewhere, during connection - * processing). - * This help to avoid unwanted processing of the same socket - * in different threads: the socket in process can't - * come here before it will be re-added after processing - */ - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - - ret = true; // mark that I add somthing in connection queue - } } } } - - return ret; + catch ( std::detail::stop_request& ) { + // this is possible, normal flow of operation + } + catch ( std::exception& e ) { + std::cerr << e.what() << std::endl; + } } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -bool sockmgr_stream_MP<Connect,C,T>::accept_tcp() +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::cmd_from_pipe() { - if ( !is_open() ) { - return false; + epoll_event ev_add; + ctl _ctl; + + int r = read( pipefd[0], &_ctl, sizeof(ctl) ); + if ( r < 0 ) { + // throw system_error + throw std::detail::stop_request(); // runtime_error( "Stop request (normal flow)" ); + } else if ( r == 0 ) { + throw runtime_error( "Read pipe return 0" ); } - _xsockaddr addr; - socklen_t sz = sizeof( sockaddr_in ); - bool _in_buf; - - do { - _in_buf = false; - _pfd[0].revents = 0; - _pfd[1].revents = 0; - while ( poll( &_pfd[0], _pfd.size(), -1 ) < 0 ) { // wait infinite - if ( errno == EINTR ) { // may be interrupted, check and ignore - errno = 0; - continue; + switch ( _ctl.cmd ) { + case listener: + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + ev_add.data.fd = static_cast<socks_processor_t*>(_ctl.data.ptr)->fd(); + if ( ev_add.data.fd >= 0 ) { + if ( fcntl( ev_add.data.fd, F_SETFL, fcntl( ev_add.data.fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + // std::cerr << "xxx " << errno << " " << std::tr2::getpid() << std::endl; + throw std::runtime_error( "can't establish nonblock mode on listener" ); + } + if ( descr.find( ev_add.data.fd ) != descr.end() ) { // reuse? + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // descr.erase( ev_add.data.fd ); + // throw system_error + return; + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // throw system_error + return; + } + } + descr[ev_add.data.fd] = fd_info( static_cast<socks_processor_t*>(_ctl.data.ptr) ); } - return false; // poll wait infinite, so it can't return 0 (timeout), so it return -1. - } + break; + case tcp_buffer: + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + ev_add.data.fd = static_cast<sockbuf_t*>(_ctl.data.ptr)->fd(); + if ( ev_add.data.fd >= 0 ) { + if ( descr.find( ev_add.data.fd ) != descr.end() ) { // reuse? + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // descr.erase( ev_add.data.fd ); + // throw system_error + return; + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // throw system_error + return; + } + } + descr[ev_add.data.fd] = fd_info( static_cast<sockbuf_t*>(_ctl.data.ptr) ); + } + break; + case listener_on_exit: + listeners_final.insert( _ctl.data.ptr ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + { + int lfd = check_closed_listener( reinterpret_cast<socks_processor_t*>(_ctl.data.ptr) ); + if ( lfd != -1 ) { + descr.erase( lfd ); + } + // dump_descr(); + } + break; + case rqstop: + // std::cerr << "Stop request\n"; + throw std::detail::stop_request(); // runtime_error( "Stop request (normal flow)" ); + // break; + } +} - // New connction open before data read from opened sockets. - // This policy may be worth to revise. - - if ( (_pfd[0].revents & POLLERR) != 0 || (_pfd[1].revents & POLLERR) != 0 ) { - return false; // return 0 only for binded socket, or control socket +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::process_listener( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) +{ + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; } - if ( _pfd[0].revents != 0 ) { - xmt::scoped_lock lk(_fd_lck); - if ( !is_open_unsafe() ) { // may be already closed - return false; + if ( ifd->second.p != 0 ) { + ifd->second.p->close(); + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( (i->second.p == ifd->second.p) && (i->second.b != 0) ) { + i->second.b->shutdown( sock_base::stop_in | sock_base::stop_out ); + } } - // poll found event on binded socket - sock_base::socket_type _sd = ::accept( fd_unsafe(), &addr.any, &sz ); - if ( _sd == -1 ) { - // check and set errno - // _STLP_ASSERT( _sd == -1 ); - return false; - } + } - try { - xmt::scoped_lock _l( _c_lock ); - _M_c.push_back( _Connect() ); - _M_c.back().open( _sd, addr.any ); - _Connect *cl_new = &_M_c.back(); - if ( cl_new->s.rdbuf()->in_avail() > 0 ) { - // this is the case when user read from sockstream - // in ctor above; push processing of this stream - xmt::scoped_lock lk(_dlock); - _conn_pool.push_back( --_M_c.end() ); - _pool_cnd.set( true ); - _observer_cnd.set( true ); - _in_buf = true; - } + listeners_final.insert(static_cast<void *>(ifd->second.p)); - pollfd newfd; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - newfd.fd = _sd; - newfd.events = POLLIN; - newfd.revents = 0; + socks_processor_t* p = ifd->second.p; - _pfd.push_back( newfd ); - } - catch ( ... ) { - } - } - if ( _pfd[1].revents != 0 ) { // fd come back for poll - pollfd rfd; - ::read( _pfd[1].fd, reinterpret_cast<char *>(&rfd.fd), sizeof(sock_base::socket_type) ); - rfd.events = POLLIN; - rfd.revents = 0; + descr.erase( ifd ); - _pfd.push_back( rfd ); + int lfd = check_closed_listener( p ); + + if ( lfd != -1 ) { + descr.erase( lfd ); } - } while ( !_shift_fd() && !_in_buf ); - - return true; // something was pushed in connection queue (by _shift_fd) -} -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -bool sockmgr_stream_MP<Connect,C,T>::accept_udp() -{ - if ( !is_open() ) { - return false; + // dump_descr(); + + return; } - _xsockaddr addr; + if ( (ev.events & EPOLLIN) == 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << std::hex << ev.events << std::dec << std::endl; + return; // I don't know what to do this case... + } + + sockaddr addr; socklen_t sz = sizeof( sockaddr_in ); - bool _in_buf; - // Problem here: - // if I see event on pfd[1], I should set fd_in_work = 1 and process it below in loop; - // but if no event on pfd[1], I don't really know wether pfd[1] polling in - // connect_processor or not; size of _conn_pool don't help here too ... + fd_info info = ifd->second; - // Hmm, but not all so bad: if I will see event on pfd[0] here, I just - // add SAME iterator to _conn_pool, and hope that observer process it accurate... - - int pret = poll( &_pfd[1], 1, 1 ); // timeout as short as possible - int fd_in_work = pret == 0 ? 0 : 1; - // int fd_in_work = 0; - - do { - _in_buf = false; - _pfd[0].revents = 0; - _pfd[1].revents = 0; - while ( poll( &_pfd[0 + fd_in_work], /* _pfd.size() */ 2 - fd_in_work, -1 ) < 0 ) { // wait infinite - if ( errno == EINTR ) { // may be interrupted, check and ignore + for ( ; ; ) { + int fd = accept( ev.data.fd, &addr, &sz ); + if ( fd < 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ /* << " " << std::tr2::getpid() */ << std::endl; + if ( (errno == EINTR) || (errno == ECONNABORTED) /* || (errno == ERESTARTSYS) */ ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; errno = 0; continue; } - return false; // poll wait infinite, so it can't return 0 (timeout), so it return -1. - } + if ( !(errno == EAGAIN /* || errno == EWOULDBLOCK */ ) ) { // EWOULDBLOCK == EAGAIN + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " + << errno << std::endl; + // throw system_error + } - // New connction open before data read from opened sockets. - // This policy may be worth to revise. - - if ( (_pfd[0].revents & POLLERR) != 0 /* || (_pfd[1].revents & POLLERR) != 0 */ ) { - return false; // return 0 only for binded socket, or control socket - } - - if ( _pfd[0].revents != 0 ) { - xmt::scoped_lock lk(_fd_lck); - if ( !is_open_unsafe() ) { // may be already closed - return false; - } - try { - xmt::scoped_lock _l( _c_lock ); - // - if ( _M_c.empty() ) { - _M_c.push_back( _Connect() ); - // poll found event on binded socket - // to fill addr.any only, for _M_c.back().open() call - char buff[1]; - ::recvfrom( fd_unsafe(), buff, 1, MSG_PEEK, &addr.any, &sz ); - _M_c.back().open( fd_unsafe(), addr.any, sock_base::sock_dgram ); - _Connect *cl_new = &_M_c.back(); - if ( cl_new->s.rdbuf()->in_avail() > 0 ) { - // this is the case when user read from sockstream - // in ctor above; push processing of this stream - xmt::scoped_lock lk(_dlock); - _conn_pool.push_back( _M_c.begin() ); - _pool_cnd.set( true ); - _observer_cnd.set( true ); - _in_buf = true; - fd_in_work = 1; + if ( ifd->second.p != 0 ) { + ifd->second.p->close(); + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( (i->second.p == ifd->second.p) && (i->second.b != 0) ) { + i->second.b->shutdown( sock_base::stop_in | sock_base::stop_out ); + } } - } else { // normal data available for reading - xmt::scoped_lock lk(_dlock); - _conn_pool.push_back( _M_c.begin() ); - // xmt::Thread::gettime( &_tpush ); - _pool_cnd.set( true ); - _observer_cnd.set( true ); - _in_buf = true; - fd_in_work = 1; } - // if addr.any pesent in _M_c - // typename container_type::iterator i = - // find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp_inet, addr.any ) ); - // if ( i == _M_c.end() ) { - // _M_c.push_back( _Connect() ); - // _M_c.back().open( fd(), addr.any, sock_base::sock_dgram ); - // _Connect *cl_new = &_M_c.back(); - // } - // - // ... - // - } - catch ( ... ) { - } - } - if ( _pfd[1].revents != 0 ) { // fd come back for poll - // really not used (i.e. this is fd()), but we need to read it from pipe - sock_base::socket_type _xfd; - ::read( _pfd[1].fd, reinterpret_cast<char *>(&_xfd), sizeof(sock_base::socket_type) ); - fd_in_work = 0; - } - } while ( /* !_shift_fd() && */ !_in_buf ); - return true; -} + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::_close_by_signal( int ) -{ -#ifdef _PTHREADS - void *_uw_save = *((void **)pthread_getspecific( xmt::Thread::mtkey() ) + _idx ); - _Self_type *me = static_cast<_Self_type *>( _uw_save ); + socks_processor_t* p = ifd->second.p; + listeners_final.insert( static_cast<void *>(p) ); - me->close(); -#else -#error "Fix me!" -#endif -} + descr.erase( ifd ); -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::loop( void *p ) -{ - _Self_type *me = static_cast<_Self_type *>(p); - me->loop_thr.pword( _idx ) = me; // push pointer to self for signal processing - xmt::Thread::ret_t rtc = 0; - xmt::Thread::ret_t rtc_observer = 0; + check_closed_listener( p ); - xmt::Thread thr_observer; - - try { - me->_loop_cnd.set( true ); - - me->_follow = true; - - while ( (me->*me->_accept)() /* && me->_is_follow() */ ) { - if ( thr_observer.bad() ) { - if ( thr_observer.is_join_req() ) { - rtc_observer = thr_observer.join(); - if ( rtc_observer != 0 ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-2); // there was connect_processor that was killed - } + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // dump_descr(); + } else { // back to listen + errno = 0; + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + xev.data.fd = ev.data.fd; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " + << errno << std::endl; } - thr_observer.launch( observer, me, 0, PTHREAD_STACK_MIN * 2 ); } + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + return; } - } - catch ( ... ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); - } + if ( fcntl( fd, F_SETFL, fcntl( fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + throw std::runtime_error( "can't establish nonblock mode" ); + } + + try { + epoll_event ev_add; + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + ev_add.data.fd = fd; - xmt::block_signal( SIGINT ); - xmt::block_signal( SIGPIPE ); - xmt::block_signal( SIGCHLD ); - xmt::block_signal( SIGPOLL ); + if ( descr.find( fd ) != descr.end() ) { // reuse? + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << " " << errno << std::endl; + descr.erase( fd ); + // throw system_error + return; // throw + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << " " << errno << std::endl; + return; // throw + } + } - me->_dlock.lock(); - me->_follow = false; - me->_pool_cnd.set( true, true ); - me->_observer_cnd.set( true ); - me->_dlock.unlock(); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + sockbuf_t* b = (*info.p)( fd, addr ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - // me->_c_lock.lock(); - ::close( me->_cfd ); - ::close( me->_pfd[1].fd ); - me->close(); - // me->_c_lock.unlock(); - rtc_observer = thr_observer.join(); - - xmt::scoped_lock _l( me->_c_lock ); - me->_M_c.clear(); // FIN still may not come yet; force close - if ( rtc_observer != 0 && rtc == 0 ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-2); // there was connect_processor that was killed + descr[fd] = fd_info( b, info.p ); + } + catch ( const std::bad_alloc& ) { + // nothing + descr.erase( fd ); + } + catch ( ... ) { + descr.erase( fd ); + } } - - return rtc; } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::connect_processor( void *p ) +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::process_regular( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) { - _Self_type *me = static_cast<_Self_type *>(p); + fd_info& info = ifd->second; - try { - timespec idle( me->_idle ); - typename _Sequence::iterator c; + sockbuf_t* b = info.b; + if ( b == 0 ) { // marginal case: sockbuf wasn't created by processor... + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; + // throw system_error + } + if ( info.p != 0 ) { // ... but controlled by processor + (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); - { - xmt::scoped_lock lk(me->_dlock); - if ( me->_conn_pool.empty() ) { - me->_pool_cnd.set( false ); - me->_observer_cnd.set( false ); - return 0; + socks_processor_t* p = info.p; + descr.erase( ifd ); + int lfd = check_closed_listener( p ); + if ( lfd != -1 ) { + descr.erase( lfd ); } - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - xmt::gettime( &me->_tpop ); + } else { + descr.erase( ifd ); } + return; + } - do { - sockstream& stream = c->s; - if ( stream.is_open() ) { - (c->_proc->*C)( stream ); - if ( stream.is_open() && stream.good() ) { - if ( stream.rdbuf()->in_avail() > 0 ) { - // socket has buffered data, push it back to queue - xmt::scoped_lock lk(me->_dlock); - me->_conn_pool.push_back( c ); - me->_observer_cnd.set( true ); - me->_pool_cnd.set( true ); - if ( !me->_follow ) { - break; - } - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - xmt::gettime( &me->_tpop ); - // xmt::Thread::gettime( &me->_tpush ); - continue; - } else { // no buffered data, return socket to poll - sock_base::socket_type rfd = stream.rdbuf()->fd(); - ::write( me->_cfd, reinterpret_cast<const char *>(&rfd), sizeof(sock_base::socket_type) ); - } - } else { - me->_dlock.lock(); - me->_conn_pool.erase( std::remove( me->_conn_pool.begin(), me->_conn_pool.end(), c ), me->_conn_pool.end() ); - me->_dlock.unlock(); + errno = 0; - xmt::scoped_lock _l( me->_c_lock ); - me->_M_c.erase( c ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( ev.events & EPOLLIN ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + for ( ; ; ) { + if ( b->_ebuf == b->egptr() ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // process extract data from buffer too slow for us! + if ( (info.flags & fd_info::level_triggered) == 0 ) { + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP; + xev.data.fd = ev.data.fd; + info.flags |= fd_info::level_triggered; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; + } } + if ( info.p != 0 ) { + (*info.p)( ev.data.fd ); + } + break; } - { - xmt::scoped_lock lk(me->_dlock); - if ( me->_conn_pool.empty() ) { - lk.unlock(); - if ( me->_pool_cnd.try_wait_delay( &idle ) != 0 ) { - lk.lock(); - me->_pool_cnd.set( false ); - me->_observer_cnd.set( false ); - return 0; + long offset = read( ev.data.fd, b->egptr(), sizeof(charT) * (b->_ebuf - b->egptr()) ); + + if ( offset < 0 ) { + switch ( errno ) { + case EINTR: // read was interrupted + errno = 0; + continue; + break; + case EFAULT: // Bad address + case ECONNRESET: // Connection reset by peer + errno = 0; + ev.events |= EPOLLRDHUP; // will be processed below + break; + case EAGAIN: + // case EWOULDBLOCK: + errno = 0; + { + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + xev.data.fd = ev.data.fd; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; + } + } + break; + default: + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + break; + } + break; + } else if ( offset > 0 ) { + offset /= sizeof(charT); // if offset % sizeof(charT) != 0, rest will be lost! + + if ( info.flags & fd_info::level_triggered ) { + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + xev.data.fd = ev.data.fd; + info.flags &= ~static_cast<unsigned>(fd_info::level_triggered); + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; } - if ( !me->_is_follow() ) { // before _conn_pool.front() - return 0; - } - lk.lock(); - if ( me->_conn_pool.empty() ) { - return 0; - } } - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - xmt::gettime( &me->_tpop ); + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); + b->setg( b->eback(), b->gptr(), b->egptr() + offset ); + b->ucnd.notify_one(); + if ( info.p != 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; + (*info.p)( ev.data.fd ); + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; + // EPOLLRDHUP may be missed in kernel, but offset 0 is the same + ev.events |= EPOLLRDHUP; // will be processed below + break; } - } while ( me->_is_follow() ); + } } - catch ( ... ) { - return reinterpret_cast<xmt::Thread::ret_t>(-1); - } - return 0; -} + if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; + } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::observer( void *p ) -{ - _Self_type *me = static_cast<_Self_type *>(p); - xmt::Thread::ret_t rtc = 0; - int pool_size[3]; - // size_t thr_pool_size[3]; - timespec tpop; - timespec delta( me->_busylimit ); - timespec alarm( me->_alarm ); + if ( info.p != 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - timespec idle( me->_idle ); + socks_processor_t* p = info.p; - timespec now; - std::fill( pool_size, pool_size + 3, 0 ); + descr.erase( ifd ); - try { - xmt::ThreadMgr mgr; + int lfd = check_closed_listener( p ); + if ( lfd != -1 ) { + descr.erase( lfd ); + } + } else { + b->_notify_close = false; // avoid deadlock + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; + } + descr.erase( ifd ); + b->close(); + } + // dump_descr(); + } + // if ( ev.events & EPOLLHUP ) { + // std::cerr << "Poll HUP" << std::endl; + // } + // if ( ev.events & EPOLLERR ) { + // std::cerr << "Poll ERR" << std::endl; + // } + if ( ev.events & EPOLLPRI ) { + std::cerr << "Poll PRI" << std::endl; + } + if ( ev.events & EPOLLRDNORM ) { + std::cerr << "Poll RDNORM" << std::endl; + } + if ( ev.events & EPOLLRDBAND ) { + std::cerr << "Poll RDBAND" << std::endl; + } + if ( ev.events & EPOLLMSG ) { + std::cerr << "Poll MSG" << std::endl; + } +} - mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); +template<class charT, class traits, class _Alloc> +int sockmgr<charT,traits,_Alloc>::check_closed_listener( socks_processor_t* p ) +{ + int myfd = -1; - do { - // std::swap( pool_size[0], pool_size[1] ); - std::rotate( pool_size, pool_size, pool_size + 3 ); - { - xmt::scoped_lock lk(me->_dlock); - pool_size[2] = static_cast<int>(me->_conn_pool.size()); - tpop = me->_tpop; - } - if ( pool_size[2] != 0 ) { - if ( me->_thr_limit > mgr.size() ) { - if ( (pool_size[0] - 2 * pool_size[1] + pool_size[2]) > 0 || - pool_size[2] > me->_thr_limit - /* pool_size[1] > 3 && pool_size[0] <= pool_size[1] */ ) { - // queue not empty and not decrease - mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); - } else { - xmt::gettime( &now ); - if ( (tpop + delta) < now ) { - // a long time was since last pop from queue - mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); - } + if ( !listeners_final.empty() ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( listeners_final.find( static_cast<void*>(p) ) != listeners_final.end() ) { + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( i->second.p == p ) { + if ( (i->second.flags & fd_info::listener) == 0 ) { // it's not me! + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + return -1; } + myfd = i->first; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } - mgr.garbage_collector(); - xmt::delay( &alarm ); - } else { - if ( /* me->_is_follow() && */ me->_observer_cnd.try_wait_delay( &idle ) != 0 && mgr.size() == 0 ) { - return rtc; - } } - } while ( me->_is_follow() ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - int count = 24; - while ( mgr.size() > 0 && count > 0 ) { - me->_pool_cnd.set( true, true ); - xmt::delay( &alarm ); - alarm *= 1.2; - --count; + // no more connection with this listener + listeners_final.erase( static_cast<void*>(p) ); + + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + + // if ( myfd != -1 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + p->stop(); + // } } - if ( mgr.size() > 0 ) { - mgr.signal( SIGTERM ); - rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); - } } - catch ( ... ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); - } - return rtc; + return myfd; } -#endif // !__FIT_NO_POLL +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::dump_descr() +{ + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + std::cerr << i->first << " " + << std::hex + << i->second.flags + << " " + << (void*)i->second.b + << " " + << (void*)i->second.p + << std::dec + << endl; + } +} -#ifdef STLPORT -_STLP_END_NAMESPACE -#else + +} // namespace detail + } // namespace std -#endif Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2008-06-27 10:28:54 UTC (rev 1923) +++ trunk/complement/explore/include/sockios/sockmgr.h 2008-06-27 11:20:41 UTC (rev 1924) @@ -1,351 +1,350 @@ -// -*- C++ -*- Time-stamp: <07/09/06 21:23:52 ptr> +// -*- C++ -*- Time-stamp: <08/06/27 00:50:33 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 + * Copyright (c) 2008 * Petr Ovtchenkov * - * Portion Copyright (c) 1999-2001 - * Parallel Graphics Ltd. - * * Licensed under the Academic Free License Version 3.0 * */ -#ifndef __SOCKMGR_H -#define __SOCKMGR_H +#ifndef __SOCKIOS_SOCKMGR_H +#define __SOCKIOS_SOCKMGR_H -#ifndef __config_feature_h -#include <config/feature.h> -#endif +#include <sys/epoll.h> -#ifndef __SOCKSTREAM__ -#include <sockios/sockstream> +#ifndef EPOLLRDHUP +# define EPOLLRDHUP 0x2000 #endif -#include <vector> -#include <deque> +#include <fcntl.h> + #include <cerrno> +#include <mt/thread> +#include <mt/mutex> +#include <mt/condition_variable> -#ifndef __XMT_H -#include <mt/xmt.h> -#endif +#include <sockios/socksrv.h> -#ifndef __THR_MGR_H -#include <mt/thr_mgr.h> +#ifdef STLPORT +# include <unordered_map> +# include <unordered_set> +// # include <hash_map> +// # include <hash_set> +// # define __USE_STLPORT_HASH +# define __USE_STLPORT_TR1 +#else +# if defined(__GNUC__) && (__GNUC__ < 4) +# include <ext/hash_map> +# include <ext/hash_set> +# define __USE_STD_HASH +# else +# include <tr1/unordered_map> +# include <tr1/unordered_set> +# define __USE_STD_TR1 +# endif #endif -#ifdef __unix -#include <poll.h> -#endif +#include <sockios/sockstream> +#include <deque> +#include <functional> -#ifdef STLPORT -_STLP_BEGIN_NAMESPACE -#else namespace std { -#endif -union _xsockaddr { - sockaddr_in inet; - sockaddr any; +template <class charT, class traits, class _Alloc> class basic_sockbuf; +template <class charT, class traits, class _Alloc> class basic_sockstream; +template <class charT, class traits, class _Alloc> class sock_processor_base; + + +template <class charT, class traits, class _Alloc> class basic_sockbuf; + +namespace detail { + +class stop_request : + public std::exception +{ + public: + virtual const char* what() throw() + { return "sockmgr receive stop reqest"; } }; -class basic_sockmgr : - public sock_base +template<class charT, class traits, class _Alloc> +class sockmgr { private: - class Init - { - public: - Init(); - ~Init(); - private: - static void _guard( int ); - static void __at_fork_prepare(); - static void __at_fork_child(); - static void __at_fork_parent(); + typedef basic_sockstream<charT,traits,_Alloc> sockstream_t; + typedef basic_sockbuf<charT,traits,_Alloc> sockbuf_t; + typedef sock_processor_base<charT,traits,_Alloc> socks_processor_t; + + enum { + listener, + tcp_buffer, + rqstop, + rqstart, + listener_on_exit }; - public: - basic_sockmgr(); - virtual ~basic_sockmgr(); + struct fd_info + { + enum { + listener = 0x1, + level_triggered = 0x2 + }; - protected: - __FIT_DECLSPEC void open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ); - __FIT_DECLSPEC void open( unsigned long addr, int port, sock_base::stype type, sock_base::protocol prot ); - __FIT_DECLSPEC void open( int port, sock_base::stype type, sock_base::protocol prot ); + fd_info() : + flags(0U), + b(0), + p(0) + { } - virtual __FIT_DECLSPEC void close(); - bool is_open_unsafe() const - { return _fd != -1; } - sock_base::socket_type fd_unsafe() const - { return _fd; } - __FIT_DECLSPEC - void setoptions_unsafe( sock_base::so_t optname, bool on_off = true, - int __v = 0 ); + fd_info( unsigned f, sockbuf_t* buf, socks_processor_t* proc ) : + flags(f), + b(buf), + p(proc) + { } - public: - bool is_open() const - { xmt::scoped_lock lk(_fd_lck); return is_open_unsafe(); } - bool good() const - { return _state == ios_base::goodbit; } + fd_info( sockbuf_t* buf, socks_processor_t* proc ) : + flags(0U), + b(buf), + p(proc) + { } - sock_base::socket_type fd() const - { xmt::scoped_lock lk(_fd_lck); sock_base::socket_type tmp = fd_unsafe(); return tmp; } + fd_info( sockbuf_t* buf ) : + flags(0U), + b(buf), + p(0) + { } - __FIT_DECLSPEC - void shutdown( sock_base::shutdownflg dir ); - void setoptions( sock_base::so_t optname, bool on_off = true, - int __v = 0 ) - { - xmt::scoped_lock lk(_fd_lck); - setoptions_unsafe( optname, on_off, __v ); - } + fd_info( socks_processor_t* proc ) : + flags(listener), + b(0), + p(proc) + { } - private: - basic_sockmgr( const basic_sockmgr& ); - basic_sockmgr& operator =( const basic_sockmgr& ); + fd_info( const fd_info& info ) : + flags( info.flags ), + b( info.b ), + p( info.p ) + { } - private: - sock_base::socket_type _fd; // master socket - unsigned long _mode; // open mode - unsigned long _state; // state flags - int _errno; // error state - _xsockaddr _address; + unsigned flags; + sockbuf_t* b; + socks_processor_t* p; + }; - protected: - static int _idx; - friend class Init; + struct ctl + { + int cmd; + union { + sock_base::socket_type fd; + void *ptr; + } data; + }; - protected: - xmt::mutex _fd_lck; - xmt::condition _loop_cnd; -}; + static void _loop( sockmgr *me ) + { me->io_worker(); } -class ConnectionProcessorTemplate_MP // As reference -{ public: - ConnectionProcessorTemplate_MP( std::sockstream& ) - { } + sockmgr( int hint = 1024, int ret = 512 ) : + n_ret( ret ) + { + efd = epoll_create( hint ); + if ( efd < 0 ) { + // throw system_error( errno ) + throw std::runtime_error( "epoll_create" ); + } + if ( pipe( pipefd ) < 0 ) { // check err + ::close( efd ); + // throw system_error; + throw std::runtime_error( "pipe" ); + } + // cfd = pipefd[1]; - void connect( std::sockstream& ) - { } - void close() - { } -}; + epoll_event ev_add; + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP; + ev_add.data.fd = pipefd[0]; + epoll_ctl( efd, EPOLL_CTL_ADD, pipefd[0], &ev_add ); -#ifndef __FIT_NO_POLL + _worker = new std::tr2::thread( _loop, this ); -template <class Connect, void (Connect::*C)( std::sockstream& ) = &Connect::connect, void (Connect::*T)() = &Connect::close > -class sockmgr_stream_MP : - public basic_sockmgr -{ - public: - sockmgr_stream_MP() : - basic_sockmgr(), - _thr_limit( 31 ) - { - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 90000000; // i.e 0.09 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + // ctl _ctl; + // _ctl.cmd = rqstart; + + // write( pipefd[1], &_ctl, sizeof(ctl) ); } - explicit sockmgr_stream_MP( const in_addr& addr, int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _thr_limit( 31 ) + ~sockmgr() { - open( addr, port, t ); - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 90000000; // i.e 0.09 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + if ( _worker->joinable() ) { + ctl _ctl; + _ctl.cmd = rqstop; + _ctl.data.ptr = 0; + + ::write( pipefd[1], &_ctl, sizeof(ctl) ); + + _worker->join(); + } + ::close( pipefd[1] ); + ::close( pipefd[0] ); + ::close( efd ); + delete _worker; } - explicit sockmgr_stream_MP( unsigned long addr, int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _thr_limit( 31 ) + void push( socks_processor_t& p ) { - open( addr, port, t ); - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 90000000; // i.e 0.09 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + ctl _ctl; + _ctl.cmd = listener; + _ctl.data.ptr = static_cast<void *>(&p); + + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } } - explicit sockmgr_stream_MP( int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _thr_limit( 31 ) + void push( sockbuf_t& s ) { - open( port, t ); - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 50000000; // i.e 0.05 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + ctl _ctl; + _ctl.cmd = tcp_buffer; + _ctl.data.ptr = static_cast<void *>(&s); + + errno = 0; + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } } - ~sockmgr_stream_MP() - { loop_thr.join(); } + void pop( socks_processor_t& p, sock_base::socket_type _fd ) + { + ctl _ctl; + _ctl.cmd = listener_on_exit; + _ctl.data.ptr = reinterpret_cast<void *>(&p); - private: - sockmgr_stream_MP( const sockmgr_stream_MP<Connect,C,T>& ); - sockmgr_stream_MP<Connect,C,T>& operator =( const sockmgr_stream_MP<Connect,C,T>& ); + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } + } - public: - void open( const in_addr& addr, int port, sock_base::stype t = sock_base::sock_stream ); - void open( unsigned long addr, int port, sock_base::stype t = sock_base::sock_stream ); - void open( int port, sock_base::stype t = sock_base::sock_stream ); + void exit_notify( sockbuf_t* b, sock_base::socket_type fd ) + { + try { + std::tr2::unique_lock<std::tr2::mutex> lk( dll, std::tr2::defer_lock ); - virtual void close() - { basic_sockmgr::close(); } + if ( lk.try_lock() ) { + if ( b->_notify_close ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + typename fd_container_type::iterator i = descr.find( fd ); + if ( (i != descr.end()) && (i->second.b == b) && (i->second.p == 0) ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, fd, 0 ) < 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // throw system_error + } + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + descr.erase( i ); + } + b->_notify_close = false; + } + } + } + catch ( const std::tr2::lock_error& ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + } + } - void wait() - { loop_thr.join(); } - - void detach( sockstream& ) // remove sockstream from polling in manager + private: + sockmgr( const sockmgr& ) { } + sockmgr& operator =( const sockmgr& ) + { return *this; } - void setbusytime( const timespec& t ) - { _busylimit = t; } + int check_closed_listener( socks_processor_t* p ); + void dump_descr(); - void setobservertime( const timespec& t ) - { _alarm = t; } +#ifdef __USE_STLPORT_HASH + typedef std::hash_map<sock_base::socket_type,fd_info> fd_container_type; + typedef std::hash_set<void *> listener_container_type; +#endif +#ifdef __USE_STD_HASH + typedef __gnu_cxx::hash_map<sock_base::socket_type, fd_info> fd_container_type; + typedef __gnu_cxx::hash_set<void *> listener_container_type; +#endif +#if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) + typedef std::tr1::unordered_map<sock_base::socket_type, fd_info> fd_container_type; + typedef std::tr1::unordered_set<void *> listener_container_type; +#endif - void setidletime( const timespec& t ) - { _idle = t; } + void io_worker(); + void cmd_from_pipe(); + void process_listener( epoll_event&, typename fd_container_type::iterator ); + void process_regular( epoll_event&, typename fd_container_type::iterator ); - void setthreadlimit( unsigned lim ) - { _thr_limit = std::max( 3U, lim ) - 1; } + int efd; + int pipefd[2]; + std::tr2::thread *_worker; + const int n_ret; - protected: + fd_container_type descr; + listener_container_type listeners_final; + std::tr2::mutex dll; +}; - struct _Connect - { - _Connect() : - _proc( 0 ) - { } +} //detail - _Connect( const _Connect& ) : - _proc( 0 ) - { } +} // namesapce std - ~_Connect() - { if ( _proc ) { s.close(); (_proc->*T)(); delete _proc; _proc = 0; } } +#if defined(__USE_STLPORT_HASH) || defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) +# define __HASH_NAMESPACE std +#endif +#if defined(__USE_STD_HASH) +# define __HASH_NAMESPACE __gnu_cxx +#endif - void open( sock_base::socket_type st, const sockaddr& addr, sock_base::stype t = sock_base::sock_stream ) - { s.open( st, addr, t ); _proc = new Connect( s ); } +namespace __HASH_NAMESPACE { - sockstream s; - Connect *_proc; - }; +#ifdef __USE_STD_TR1 +namespace tr1 { +#endif - typedef std::vector<pollfd> _fd_sequence; - typedef std::list<_Connect> _Sequence; - typedef std::deque<typename _Sequence::iterator> _connect_pool_sequence; +template <class charT, class traits, class _Alloc> +struct hash<std::basic_sockstream<charT, traits, _Alloc>* > +{ + size_t operator()(const std::basic_sockstream<charT, traits, _Alloc>* __x) const + { return reinterpret_cast<size_t>(__x); } +}; - void _open( sock_base::stype t = sock_base::sock_stream ); - static xmt::Thread::ret_t loop( void * ); - static xmt::Thread::ret_t connect_processor( void * ); - static xmt::Thread::ret_t observer( void * ); - - struct fd_equal : - public std::binary_function<_Connect,int,bool> - { - bool operator()(const _Connect& __x, int __y) const - { return __x.s.rdbuf()->fd() == __y; } - }; - - struct iaddr_equal : - public std::binary_function<_Connect,sockaddr,bool> - { - bool operator()(const _Connect& __x, const sockaddr& __y) const - { return memcmp( &(__x.s.rdbuf()->inet_sockaddr()), reinterpret_cast<const sockaddr_in *>(&__y), sizeof(sockaddr_in) ) == 0; } - }; - - struct pfd_equal : - public std::binary_function<typename _fd_sequence::value_type,int,bool> - { - bool operator()(const typename _fd_sequence::value_type& __x, int __y) const - { return __x.fd == __y; } - }; - - typedef bool (sockmgr_stream_MP<Connect,C,T>::*accept_type)(); - -#if 0 - accept_type _accept; - _Connect *accept() // workaround for CC - { return (this->*_accept)(); } -#else - accept_type _accept; +#ifdef __USE_STD_TR1 +} #endif - bool accept_tcp(); - bool accept_udp(); - private: - xmt::Thread loop_thr; - - protected: - typedef sockmgr_stream_MP<Connect,C,T> _Self_type; - typedef fd_equal _Compare; - typedef iaddr_equal _Compare_inet; - typedef typename _Sequence::value_type value_type; - typedef typename _Sequence::size_type size_type; - typedef _Sequence container_type; - - typedef typename _Sequence::reference reference; - typedef typename _Sequence::const_reference const_reference; - - _Sequence _M_c; - _Compare _M_comp; - _Compare_inet _M_comp_inet; - pfd_equal _pfdcomp; - xmt::mutex _c_lock; - - _fd_sequence _pfd; - int _cfd; // sock_base::socket_type - _connect_pool_sequence _conn_pool; - xmt::condition _pool_cnd; - xmt::mutex _dlock; - timespec _tpop; - - xmt::mutex _flock; - bool _follow; - - xmt::condition _observer_cnd; - timespec _busylimit; // start new thread to process incoming - // requests, if processing thread busy - // more then _busylimit - timespec _alarm; // check and make decision about start - // new thread with _alarm interval - timespec _idle; // do nothing _idle time before thread - // terminate - - unsigned _thr_limit; - - private: - bool _shift_fd(); - static void _close_by_signal( int ); - bool _is_follow() const - { xmt::scoped_lock lk( _flock ); bool tmp = _follow; return tmp; } +#if defined(__GNUC__) && (__GNUC__ < 4) +template<> +struct hash<void *> +{ + size_t operator()(const void *__x) const + { return reinterpret_cast<size_t>(__x); } }; +#endif // __GNUC__ < 4 -#endif // !__FIT_NO_POLL +} // namespace __HASH_NAMESPACE -#ifdef STLPORT -_STLP_END_NAMESPACE -#else -} // namespace std +#undef __HASH_NAMESPACE + +#ifdef __USE_STLPORT_HASH +# undef __USE_STLPORT_HASH #endif +#ifdef __USE_STD_HASH +# undef __USE_STD_HASH +#endif +#ifdef __USE_STLPORT_TR1 +# undef __USE_STLPORT_TR1 +#endif +#ifdef __USE_STD_TR1 +# undef __USE_STD_TR1 +#endif -#ifndef __STL_LINK_TIME_INSTANTIATION #include <sockios/sockmgr.cc> -#endif -#endif // __SOCKMGR_H +#endif /* __SOCKIOS_SOCKMGR_H */ Added: trunk/complement/explore/include/sockios/socksrv.cc =================================================================== --- trunk/complement/explore/include/sockios/socksrv.cc (rev 0) +++ trunk/complement/explore/include/sockios/socksrv.cc 2008-06-27 11:20:41 UTC (rev 1924) @@ -0,0 +1,341 @@ +// -*- C++ -*- Time-stamp: <08/06/26 09:00:54 ptr> + +/* + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +namespace std { + +template<class charT, class traits, class _Alloc> +void sock_processor_base<charT,traits,_Alloc>::open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ) +{ + std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); + if ( basic_socket_t::is_open_unsafe() ) { + return; + } + _mode = ios_base::in | ios_base::out; + _state = ios_base::goodbit; +#ifdef WIN32 + ::WSASetLastError( 0 ); +#endif + if ( prot == sock_base::inet ) { + basic_socket_t::_fd = socket( PF_INET, type, 0 ); + if ( basic_socket_t::_fd == -1 ) { + _state |= ios_base::failbit | ios_base::badbit; + return; + } + // _open = true; + basic_socket_t::_address.inet.sin_family = AF_INET; + basic_socket_t::_address.inet.sin_port = htons( port ); + basic_socket_t::_address.inet.sin_addr.s_addr = addr.s_addr; + + if ( type == sock_base::sock_stream || type == sock_base::sock_seqpacket ) { + // let's try reuse local address + setoptions_unsafe( sock_base::so_reuseaddr, true ); + } + + if ( ::bind( basic_socket_t::_fd, &basic_socket_t::_address.any, sizeof(basic_socket_t::_address) ) == -1 ) { + _state |= ios_base::failbit; +#ifdef WIN32 + ::closesocket( basic_socket_t::_fd ); +#else + ::close( basic_socket_t::_fd ); +#endif + basic_socket_t::_fd = -1; + return; + } + + if ( type == sock_base::sock_stream || type == sock_base::sock_seqpacket ) { + // I am shure, this is socket of type SOCK_STREAM | SOCK_SEQPACKET, + // so don't check return code from listen + ::listen( basic_socket_t::_fd, SOMAXCONN ); + basic_socket_t::mgr->push( *this ); + } + } else if ( prot == sock_base::local ) { + return; + } else { + return; + } + _state = ios_base::goodbit; + + return; +} + +template<class charT, class traits, class _Alloc> +void sock_processor_base<charT,traits,_Alloc>::_close() +{ + std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); + if ( !basic_socket_t::is_open_unsafe() ) { + return; + } + // std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; + +#ifdef WIN32 + ::closesocket( basic_socket_t::_fd ); +#else + ::shutdown( basic_socket_t::_fd, 2 ); + ::close( basic_socket_t::_fd ); +#endif + basic_socket<charT,traits,_Alloc>::mgr->pop( *this, basic_socket_t::_fd ); + basic_socket_t::_fd = -1; +} + +template<class charT, class traits, class _Alloc> +void sock_processor_base<charT,traits,_Alloc>::shutdown( sock_base::shutdownflg dir ) +{ + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + + std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); + if ( basic_socket_t::is_open_unsafe() ) { + if ( (dir & ... [truncated message content] |
From: <com...@us...> - 2008-06-29 21:47:49
|
Revision: 1926 http://complement.svn.sourceforge.net/complement/?rev=1926&view=rev Author: complement Date: 2008-06-29 14:47:47 -0700 (Sun, 29 Jun 2008) Log Message: ----------- Rename Opt -> option; set proper ctors; hide implementation. Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-27 17:42:24 UTC (rev 1925) +++ trunk/complement/explore/include/misc/opts.h 2008-06-29 21:47:47 UTC (rev 1926) @@ -1,5 +1,16 @@ -// -*- C++ -*- Time-stamp: <08/05/21 12:17:39 yeti> +// -*- C++ -*- Time-stamp: <08/06/28 10:26:23 ptr> +/* + * Copyright (c) 2008 + * Dmitry Osmakov + * + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + #ifndef __OPTS_H__ #define __OPTS_H__ @@ -14,11 +25,36 @@ #define all(c) (c).begin() , (c).end() -class Opt +class option { public: - Opt() : shortname(' ') + + option( const char* _description, char _short_var, const char* _long_var ) : + shortname( _short_var ), + longname( _long_var ), + desc( _description ) { } + + option( const char* _description, char _short_var ) : + shortname( _short_var ), + longname(), + desc( _description ) + { } + + option( const char* _description, const char* _long_var ) : + shortname( 0 ), + longname( _long_var ), + desc( _description ) + { } + + bool operator ==( const std::string& _longname ) const + { return longname == _longname; } + bool operator ==( char _shortname ) const + { return shortname == _shortname; } + bool operator ==( int _token ) const + { return token == _token; } + + private: char shortname; std::string longname; std::string desc; @@ -29,24 +65,31 @@ std::vector< int > pos; bool has_arg; - bool operator==( const std::string& _longname ) const { return longname == _longname; } - bool operator==( char _shortname ) const { return shortname == _shortname; } - bool operator==( int _token ) const { return token == _token; } - friend std::ostream& operator<<(std::ostream& t,const Opt& opt); + + friend std::ostream& operator <<( std::ostream& t, const option& opt ); + friend class Opts; }; class Opts { private: - typedef std::vector< Opt > options_container_type; + typedef std::vector< option > options_container_type; options_container_type storage; + public: - Opts( const std::string& _brief = "", const std::string& _author = "", const std::string& _copyright = "") : - brief(_brief), - author(_author), - copyright(_copyright) - { free_token = 0; } + Opts() : + free_token(0) + { } + void description( const char* text ) + { _brief = text; } + + void author( const char* text ) + { _author = text; } + + void copyright( const char* text ) + { _copyright = text; } + // adding option / flag (option that doesn't need arguments) template <class T> int add( const std::string& _longname,T _default_value,const std::string& _desc = "(no decription)" ); @@ -118,13 +161,14 @@ std::invalid_argument(std::string("argument [").append(_argname).append("] doesn't match by type for option ").append(_optname)) { } }; - + + private: int free_token; - private: + std::string pname; - std::string brief; - std::string author; - std::string copyright; + std::string _brief; + std::string _author; + std::string _copyright; bool isterm( const std::string& s ); bool is_opt_name( const std::string& s ); @@ -332,4 +376,4 @@ } } -#endif +#endif // __OPTS_H__ Modified: trunk/complement/explore/lib/misc/opts.cc =================================================================== --- trunk/complement/explore/lib/misc/opts.cc 2008-06-27 17:42:24 UTC (rev 1925) +++ trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:47:47 UTC (rev 1926) @@ -1,3 +1,16 @@ +// -*- C++ -*- Time-stamp: <08/06/28 10:25:43 ptr> + +/* + * Copyright (c) 2008 + * Dmitry Osmakov + * + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + #include <vector> #include <string> #include <sstream> @@ -76,14 +89,11 @@ return storage.end(); } -ostream& operator<<(ostream& out,const Opt& opt) +ostream& operator <<( ostream& out, const option& opt ) { - if (opt.shortname == ' ') - { + if ( opt.shortname == 0 ) { out << "--" << opt.longname << '\t' << (opt.has_arg ? (string("[") + opt.default_v + "]\t") : "" ) << opt.desc; - } - else - { + } else { out << '-' << opt.shortname << '\t' << (!opt.longname.empty() ? (string("[--") + opt.longname +"]\t") : "") << (opt.has_arg ? string("[") + opt.default_v + ("]\t") : "") << opt.desc; } @@ -92,12 +102,12 @@ void Opts::help(ostream& out) { - if (!brief.empty()) - out << brief << endl; - if (!author.empty()) - out << author << endl; - if (!copyright.empty()) - out << copyright << endl; + if (!_brief.empty()) + out << _brief << endl; + if (!_author.empty()) + out << _author << endl; + if (!_copyright.empty()) + out << _copyright << endl; out << "Valid options:" << endl; options_container_type::const_iterator i; @@ -107,23 +117,20 @@ } } -int Opts::addflag(char _shortname,const string& _longname,const string& _desc) +int Opts::addflag( char _shortname, const string& _longname, const string& _desc ) { - Opt opt; - opt.shortname = _shortname; - opt.longname = _longname; - opt.desc = _desc; + option opt( _desc.c_str(), _shortname, _longname.c_str() ); + opt.has_arg = false; opt.token = ++free_token; storage.push_back(opt); return opt.token; } -int Opts::addflag(const string& _longname,const string& _desc) +int Opts::addflag( const string& _longname, const string& _desc ) { - Opt opt; - opt.longname = _longname; - opt.desc = _desc; + option opt( _desc.c_str(), _longname.c_str() ); + opt.has_arg = false; opt.token = ++free_token; storage.push_back(opt); Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-27 17:42:24 UTC (rev 1925) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:47:47 UTC (rev 1926) @@ -1,9 +1,12 @@ -// -*- C++ -*- Time-stamp: <08/05/21 12:20:14 yeti> +// -*- C++ -*- Time-stamp: <08/06/28 10:25:10 ptr> /* * Copyright (c) 2008 * Petr Ovtchenkov * + * Copyright (c) 2008 + * Dmitry Osmakov + * * Licensed under the Academic Free License Version 3.0 * */ @@ -705,8 +708,11 @@ const char* argv[] = { "name" , "--help" }; int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts("what utility do","author","copyright"); + Opts opts; + opts.description( "what utility do" ); + opts.author( "author" ); + opts.copyright( "copyright" ); opts.addflag('h',"help","print this help message"); opts.addflag("flag","some program flag"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-29 21:48:13
|
Revision: 1927 http://complement.svn.sourceforge.net/complement/?rev=1927&view=rev Author: complement Date: 2008-06-29 14:48:10 -0700 (Sun, 29 Jun 2008) Log Message: ----------- Clean code; enhance help message; pass default value via operator [] Also rename option to option_base (keep in mind future changes). Test for print help really check printed message. Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-29 21:47:47 UTC (rev 1926) +++ trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:10 UTC (rev 1927) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/28 10:26:23 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 13:52:41 ptr> /* * Copyright (c) 2008 @@ -23,30 +23,34 @@ #include <exception> #include <stdexcept> -#define all(c) (c).begin() , (c).end() - -class option +class option_base { public: - option( const char* _description, char _short_var, const char* _long_var ) : + option_base( const char* _description, char _short_var, const char* _long_var ) : shortname( _short_var ), longname( _long_var ), - desc( _description ) + desc( _description ), + has_arg( false ) { } - option( const char* _description, char _short_var ) : + option_base( const char* _description, char _short_var ) : shortname( _short_var ), longname(), - desc( _description ) + desc( _description ), + has_arg( false ) { } - option( const char* _description, const char* _long_var ) : + option_base( const char* _description, const char* _long_var ) : shortname( 0 ), longname( _long_var ), - desc( _description ) + desc( _description ), + has_arg( false ) { } + option_base& operator []( const std::string& d ) + { default_v = d; has_arg = true; } + bool operator ==( const std::string& _longname ) const { return longname == _longname; } bool operator ==( char _shortname ) const @@ -66,14 +70,14 @@ bool has_arg; - friend std::ostream& operator <<( std::ostream& t, const option& opt ); + friend std::ostream& operator <<( std::ostream& t, const option_base& opt ); friend class Opts; }; class Opts { private: - typedef std::vector< option > options_container_type; + typedef std::vector< option_base > options_container_type; options_container_type storage; public: @@ -84,6 +88,9 @@ void description( const char* text ) { _brief = text; } + void usage( const char* text ) + { _usage = text; } + void author( const char* text ) { _author = text; } @@ -167,6 +174,7 @@ std::string pname; std::string _brief; + std::string _usage; std::string _author; std::string _copyright; @@ -183,8 +191,7 @@ addflag(_shortname,_longname,_desc); std::stringstream ss; ss << _default_value; - storage[storage.size() - 1].default_v = ss.str(); - storage[storage.size() - 1].has_arg = true; + storage[storage.size() - 1][ss.str()]; return storage[storage.size() - 1].token; } @@ -194,186 +201,157 @@ addflag(_longname,_desc); std::stringstream ss; ss << _default_value; - storage[storage.size() - 1].default_v = ss.str(); - storage[storage.size() - 1].has_arg = true; + storage[storage.size() - 1][ss.str()]; return storage[storage.size() - 1].token; } template <class T> bool Opts::is_set(T field) const { - options_container_type::const_iterator i = find(all(storage),field); + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); return ( (i == storage.end()) ? false : !i->pos.empty()); } template <class T> int Opts::get_cnt(T field) const { - options_container_type::const_iterator i = find(all(storage),field); + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); return ( (i == storage.end()) ? 0 : i->pos.size()); } template <class V> std::string Opts::get( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - std::string res; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - if ( !i->has_arg ) - { - throw std::logic_error("using Opts::get for option without arguments"); - } - - res = i->args.empty() ? i->default_v : i->args[0]; - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option( ss1.str() ); } - return res; + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); + } + + return i->args.empty() ? i->default_v : i->args[0]; } template < class T , class V > T Opts::get( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - T res; + options_container_type::const_iterator i = std::find(storage.begin(), storage.end() ,field); - if (i != storage.end()) - { - if ( !i->has_arg ) - { - throw std::logic_error("using Opts::get for option without arguments"); - } + if ( i == storage.end() ) { + std::stringstream ss1; + ss1 << field; + throw unknown_option( ss1.str() ); + } - std::stringstream ss(i->args.empty() ? i->default_v : i->args[0]); - ss >> res; - - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args.empty() ? i->default_v : i->args[0]); - } + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); } - else - { + + T res; + std::stringstream ss(i->args.empty() ? i->default_v : i->args[0]); + ss >> res; + + if ( ss.fail() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw arg_typemismatch(ss1.str(),i->args.empty() ? i->default_v : i->args[0]); } return res; } - template < class V> std::string Opts::get_default( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - std::string res; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - if (!i->has_arg) - throw std::logic_error("using Opts::get for option without arguments"); - - res = i->default_v; - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option( ss1.str() ); } - return res; + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); + } + + return i->default_v; } template <class T , class V> T Opts::get_default( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - T res; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - if (!i->has_arg) - throw std::logic_error("using Opts::get for option without arguments"); - - std::stringstream ss(i->default_v); - ss >> res; - - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->default_v); - } - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option( ss1.str() ); } + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); + } + + T res; + std::stringstream ss(i->default_v); + ss >> res; + + if ( ss.fail() ) { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->default_v); + } + return res; } template <class V , class BackInsertIterator> void Opts::getemall( V field , BackInsertIterator bi) { - options_container_type::const_iterator i = find(all(storage),field); - if (i != storage.end()) - { - if (!i->has_arg) - throw std::logic_error("using Opts::getemall for option without arguments"); - - if (!i->args.empty()) - { - for (int j = 0;j < i->args.size();++j) - { - std::stringstream ss(i->args[j]); - ss >> *bi++; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args[j]); - } - } - } - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option(ss1.str()); } + + if ( !i->has_arg ) { + throw std::logic_error("using Opts::getemall for option without arguments"); + } + + if ( !i->args.empty() ) { + for ( int j = 0; j < i->args.size(); ++j) { + std::stringstream ss(i->args[j]); + ss >> *bi++; + + if ( ss.fail() ) { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->args[j]); + } + } + } } template <class V , class BackInsertIterator> void Opts::get_pos( V field , BackInsertIterator bi) { - options_container_type::const_iterator i = find(all(storage),field); + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - copy(all(i->pos),bi); - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option(ss1.str()); } + + std::copy( i->pos.begin(), i->pos.end(), bi ); } #endif // __OPTS_H__ Modified: trunk/complement/explore/lib/misc/opts.cc =================================================================== --- trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:47:47 UTC (rev 1926) +++ trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:48:10 UTC (rev 1927) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/28 10:25:43 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 13:05:13 ptr> /* * Copyright (c) 2008 @@ -21,6 +21,22 @@ using namespace std; +ostream& operator <<( ostream& out, const option_base& opt ) +{ + if ( opt.shortname != 0 ) { + out << '-' << opt.shortname << (opt.has_arg ? " <val>" : "" ); + if ( !opt.longname.empty() ) { + out << ", "; + } + } + + if ( !opt.longname.empty() ) { + out << "--" << opt.longname << (opt.has_arg ? "=<val>" : "" ); + } + + return out << (opt.has_arg ? (string(" [") + opt.default_v + "]\t") : "\t" ) << opt.desc; +} + string Opts::get_pname() const { return pname; } bool Opts::is_opt_name(const string& s) @@ -39,17 +55,19 @@ return true; } -bool Opts::is_flag_group(const string& s) +bool Opts::is_flag_group( const string& s ) { - if (s.size() > 2 && s[0] == '-') - { - for (int i = 1;i < s.size();i++) - if (!isalnum(s[i])) + string::const_iterator i = s.begin(); + + if ( s.size() > 2 && *i == '-' ) { + while ( ++i != s.end() ) { + if ( !isalnum( *i ) ) { return false; + } + } return true; } - else - return false; + return false; } // this function assumes that is_opt_name(s) = true; @@ -89,37 +107,37 @@ return storage.end(); } -ostream& operator <<( ostream& out, const option& opt ) +void Opts::help( ostream& out ) { - if ( opt.shortname == 0 ) { - out << "--" << opt.longname << '\t' << (opt.has_arg ? (string("[") + opt.default_v + "]\t") : "" ) << opt.desc; - } else { - out << '-' << opt.shortname << '\t' << (!opt.longname.empty() ? (string("[--") + opt.longname +"]\t") : "") << (opt.has_arg ? string("[") + opt.default_v + ("]\t") : "") << opt.desc; + out << "This is " << pname; + if ( !_brief.empty() ) { + out << ", " << _brief; } - - return out; -} + out << "\n\n"; -void Opts::help(ostream& out) -{ - if (!_brief.empty()) - out << _brief << endl; - if (!_author.empty()) - out << _author << endl; - if (!_copyright.empty()) - out << _copyright << endl; - - out << "Valid options:" << endl; - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - { - out << *i << endl; + if ( !_author.empty() ) { + out << _author << "\n\n"; } + + if ( !_copyright.empty() ) { + out << _copyright << "\n\n"; + } + + out << "Usage:\n\n" << pname << " " << _usage << "\n"; // " [options] etc. etc." + + if ( !storage.empty() ) { + out << "\nOptions:\n\n"; + + for ( options_container_type::const_iterator i = storage.begin(); i != storage.end(); ++i) { + out << *i << "\n"; + } + } + out << endl; } int Opts::addflag( char _shortname, const string& _longname, const string& _desc ) { - option opt( _desc.c_str(), _shortname, _longname.c_str() ); + option_base opt( _desc.c_str(), _shortname, _longname.c_str() ); opt.has_arg = false; opt.token = ++free_token; @@ -129,7 +147,7 @@ int Opts::addflag( const string& _longname, const string& _desc ) { - option opt( _desc.c_str(), _longname.c_str() ); + option_base opt( _desc.c_str(), _longname.c_str() ); opt.has_arg = false; opt.token = ++free_token; @@ -137,77 +155,67 @@ return opt.token; } -void Opts::parse(int& ac,const char** av) +void Opts::parse( int& ac, const char** av ) { pname = av[0]; int i = 1; int j = 1; int q = 0; - while ( (i < ac) && (string(av[i]) != "--") ) - { - if (is_opt_name(av[i])) - { + + while ( (i < ac) && (string(av[i]) != "--") ) { + if ( is_opt_name(av[i]) ) { string opt = av[i]; string arg; - int k = opt.find("="); + int k = opt.find( "=" ); - if (k != string::npos) - { - arg = opt.substr(k + 1); - opt = opt.substr(0,k); + if ( k != string::npos ) { + arg = opt.substr( k + 1 ); + opt = opt.substr( 0, k ); } - options_container_type::iterator p = get_opt_index(opt); + options_container_type::iterator p = get_opt_index(opt); - if (p == storage.end()) + if ( p == storage.end() ) { throw unknown_option(opt); - else - { - p->pos.push_back(++q); - if (p->has_arg) - { - if (!arg.empty()) - p->args.push_back(arg); - else - if (i + 1 < ac) - p->args.push_back(av[++i]); - else - throw missing_arg(opt); + } + + p->pos.push_back(++q); + if ( p->has_arg ) { + if ( !arg.empty() ) { + p->args.push_back(arg); + } else { + if ( (i + 1) >= ac ) { + throw missing_arg(opt); + } + p->args.push_back(av[++i]); } - else - if (!arg.empty()) //unexpected arg (not exactly mismatch) - throw arg_typemismatch(opt,arg); - } - } - else - if (is_flag_group(av[i])) - { + } else if ( !arg.empty() ) { //unexpected arg (not exactly mismatch) + throw arg_typemismatch(opt,arg); + } + } else if ( is_flag_group(av[i]) ) { string optgroup = av[i]; - for (int j = 1;j < optgroup.size();j++) - { + for ( int j = 1; j < optgroup.size(); j++ ) { options_container_type::iterator p = get_opt_index(string("-") + optgroup[j]); - if (p == storage.end()) - { + if ( p == storage.end() ) { throw unknown_option( "-" + string(1,optgroup[j]) ); } - else - { - p->pos.push_back(++q); - if (p->has_arg) - throw missing_arg( "-" + string(1,optgroup[j]) ); + p->pos.push_back(++q); + if ( p->has_arg ) { + throw missing_arg( "-" + string(1,optgroup[j]) ); } } + } else { + av[j++] = av[i]; } - else - av[j++] = av[i]; i++; } i += ( i < ac ); - while (i < ac) - av[j++] = av[i++]; + while (i < ac) { + av[j++] = av[i++]; + } ac = j; } Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:47:47 UTC (rev 1926) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:10 UTC (rev 1927) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/28 10:25:10 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 13:18:16 ptr> /* * Copyright (c) 2008 @@ -704,34 +704,55 @@ int EXAM_IMPL(opts_test::help) { - { - const char* argv[] = { "name" , "--help" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "programname" , "--help" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.description( "what utility do" ); - opts.author( "author" ); - opts.copyright( "copyright" ); + opts.description( "test for printing help message" ); + opts.usage( "[options] file-from file-to" ); + opts.author( "B. L. User" ); + opts.copyright( "Copyright (C) Youyoudine, 2008" ); - opts.addflag('h',"help","print this help message"); - opts.addflag("flag","some program flag"); - opts.addflag('v',"version","view program version"); - opts.add('I',"/usr/include","include","include paths" ); - opts.add('p',80,"port","listen to tcp port"); - opts.add("mode","standart","program mode"); + opts.addflag( 'h', "help", "print this help message" ); + opts.addflag( "flag", "some program flag" ); + opts.addflag( 'v', "version", "print version"); + opts.add( 'I', "/usr/include", "include", "include paths" ); + opts.add( 'p', 80, "port", "listen to tcp port" ); + opts.add( "mode", "standard", "program mode"); - opts.parse(argc,argv); + opts.parse( argc,argv ); - EXAM_CHECK(opts.is_set('h')); - EXAM_CHECK( opts.get_pname() == "name" ); + EXAM_CHECK( opts.is_set('h') ); + EXAM_CHECK( opts.get_pname() == "programname" ); - ofstream out("help.out"); - opts.help(out); - cout << "check file help.out" << endl; - out.close(); - } + stringstream s; + opts.help( s ); + + const char sample[] = +"This is programname, test for printing help message\n\ +\n\ +B. L. User\n\ +\n\ +Copyright (C) Youyoudine, 2008\n\ +\n\ +Usage:\n\ +\n\ +programname [options] file-from file-to\n\ +\n\ +Options:\n\ +\n\ +-h, --help\tprint this help message\n\ +--flag\tsome program flag\n\ +-v, --version\tprint version\n\ +-I <val>, --include=<val> [/usr/include]\tinclude paths\n\ +-p <val>, --port=<val> [80]\tlisten to tcp port\n\ +--mode=<val> [standard]\tprogram mode\n\ +\n"; + + EXAM_CHECK( s.str() == sample ); + return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-29 21:48:36
|
Revision: 1928 http://complement.svn.sourceforge.net/complement/?rev=1928&view=rev Author: complement Date: 2008-06-29 14:48:33 -0700 (Sun, 29 Jun 2008) Log Message: ----------- revision of options framework. insert object with type and type check into option; default value passed via [] operator; option registration done via << oprator. Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/exam/ut/exam_self_test.cc trunk/complement/explore/lib/misc/ChangeLog trunk/complement/explore/lib/misc/Makefile.inc trunk/complement/explore/lib/misc/opts.cc trunk/complement/explore/lib/misc/ut/Makefile trunk/complement/explore/lib/misc/ut/Makefile.inc trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,10 +1,10 @@ -// -*- C++ -*- Time-stamp: <08/06/29 13:52:41 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 22:16:12 ptr> /* * Copyright (c) 2008 * Dmitry Osmakov * - * Copyright (c) 2008 + * Copyright (c) 1997-1998, 2001, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -17,11 +17,15 @@ #include <iostream> #include <string> #include <vector> +#include <list> #include <sstream> #include <typeinfo> #include <cctype> #include <exception> #include <stdexcept> +#include <algorithm> +#include <functional> +#include <iterator> class option_base { @@ -31,6 +35,7 @@ shortname( _short_var ), longname( _long_var ), desc( _description ), + token( _count++ ), has_arg( false ) { } @@ -38,6 +43,7 @@ shortname( _short_var ), longname(), desc( _description ), + token( _count++ ), has_arg( false ) { } @@ -45,11 +51,12 @@ shortname( 0 ), longname( _long_var ), desc( _description ), + token( _count++ ), has_arg( false ) { } - option_base& operator []( const std::string& d ) - { default_v = d; has_arg = true; } + virtual ~option_base() + { } bool operator ==( const std::string& _longname ) const { return longname == _longname; } @@ -58,31 +65,300 @@ bool operator ==( int _token ) const { return token == _token; } - private: + virtual const std::type_info& type() const = 0; + + template <class T> + bool assign( T& v ) const + { + if ( this->type() != typeid(T) ) { + throw std::invalid_argument( "types mismatch" ); + } + return _assign( static_cast<void*>(&v) ); + } + + protected: + virtual void read( const char* str ) = 0; + virtual void read( const std::string& str ) = 0; + virtual bool _assign( void* ) const = 0; + virtual std::ostream& _describe( std::ostream& ) const = 0; + char shortname; std::string longname; std::string desc; - std::string default_v; int token; - - std::vector< std::string > args; - std::vector< int > pos; + protected: + std::vector<int> pos; + bool has_arg; - friend std::ostream& operator <<( std::ostream& t, const option_base& opt ); + // friend std::ostream& operator <<( std::ostream& t, const option_base& opt ); friend class Opts; + + private: + static int _count; }; +namespace detail { + +template <class P, class V> +class deref_equal : + public std::binary_function<P,V,bool> +{ + public: + bool operator()(const P& __x, const V& __y) const + { return *__x == __y; } +}; + +} // namespace detail + +template <class T> +class option : + public option_base +{ + public: + option( const char* _description, char _short_var, const char* _long_var ) : + option_base( _description, _short_var, _long_var ) + { } + + option( const char* _description, char _short_var ) : + option_base( _description, _short_var ) + { } + + option( const char* _description, const char* _long_var ) : + option_base( _description, _long_var ) + { } + + virtual const std::type_info& type() const + { return typeid( T ); } + + option<T>& operator []( const T& val ) + { args.push_back( val ); has_arg = true; return *this; } + + template <class BackInstertIterator> + void get( BackInstertIterator bi ) const + { std::copy( args.begin(), args.end(), bi ); } + + protected: + virtual std::ostream& _describe( std::ostream& o ) const; + + virtual bool _assign( void* v ) const + { + if ( args.empty() ) { + // throw + } + *reinterpret_cast<T*>(v) = args.front(); + + return !pos.empty(); + } + + private: + std::list<T> args; + + void read( const char *str ) throw (std::invalid_argument) + { + std::istringstream s( str ); + T _v; + if ( !(s >> _v).fail() ) { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = _v; + } else { + args.push_back( _v ); + } + } else { + throw std::invalid_argument( str ); + } + } + + void read( const std::string& str ) throw (std::invalid_argument) + { + std::istringstream s( str ); + T _v; + if ( !(s >> _v).fail() ) { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = _v; + } else { + args.push_back( _v ); + } + } else { + throw std::invalid_argument( str ); + } + } + + friend class Opts; +}; + +template <class T> +std::ostream& option<T>::_describe( std::ostream& out ) const +{ + if ( option_base::shortname != 0 ) { + out << '-' << option_base::shortname; + if ( option_base::has_arg ) { + out << " <" << typeid(T).name() << ">"; + } + if ( !option_base::longname.empty() ) { + out << ", "; + } + } + + if ( !option_base::longname.empty() ) { + out << "--" << option_base::longname; + if ( option_base::has_arg ) { + out << "=<" << typeid(T).name() << ">"; + } + } + + if ( option_base::has_arg ) { + out << " [" << args.front() << "]\t"; + } else { + out << '\t'; + } + + return out << option_base::desc; +} + +template <> +class option<std::string> : + public option_base +{ + public: + option( const char* _description, char _short_var, const char* _long_var ) : + option_base( _description, _short_var, _long_var ) + { } + + option( const char* _description, char _short_var ) : + option_base( _description, _short_var ) + { } + + option( const char* _description, const char* _long_var ) : + option_base( _description, _long_var ) + { } + + virtual const std::type_info& type() const + { return typeid( std::string ); } + + option<std::string>& operator []( const char* val ) + { args.push_back( std::string(val) ); has_arg = true; return *this; } + + option<std::string>& operator []( const std::string& val ) + { args.push_back( val ); has_arg = true; return *this; } + + template <class BackInstertIterator> + void get( BackInstertIterator bi ) const + { std::copy( args.begin(), args.end(), bi ); } + + protected: + virtual std::ostream& _describe( std::ostream& o ) const; + + virtual bool _assign( void* v ) const + { + if ( args.empty() ) { + // throw + } + *reinterpret_cast<std::string*>(v) = args.front(); + + return !pos.empty(); + } + + private: + std::list<std::string> args; + + void read( const char *str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( std::string( str ) ); + } + } + + void read( const std::string& str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( str ); + } + } + + friend class Opts; +}; + +template <> +class option<char*> : + public option_base +{ + public: + option( const char* _description, char _short_var, const char* _long_var ) : + option_base( _description, _short_var, _long_var ) + { } + + option( const char* _description, char _short_var ) : + option_base( _description, _short_var ) + { } + + option( const char* _description, const char* _long_var ) : + option_base( _description, _long_var ) + { } + + virtual const std::type_info& type() const + { return typeid( std::string ); } + + option<char*>& operator []( const char* val ) + { args.push_back( std::string(val) ); has_arg = true; return *this; } + + option<char*>& operator []( const std::string& val ) + { args.push_back( val ); has_arg = true; return *this; } + + template <class BackInstertIterator> + void get( BackInstertIterator bi ) const + { std::copy( args.begin(), args.end(), bi ); } + + protected: + virtual std::ostream& _describe( std::ostream& o ) const; + + virtual bool _assign( void* v ) const + { + if ( args.empty() ) { + // throw + } + *reinterpret_cast<std::string*>(v) = args.front(); + + return !pos.empty(); + } + + private: + std::list<std::string> args; + + void read( const char *str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( std::string( str ) ); + } + } + + void read( const std::string& str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( str ); + } + } + + friend class Opts; +}; + class Opts { private: - typedef std::vector< option_base > options_container_type; - options_container_type storage; + typedef std::vector< option_base* > options_container_type; + options_container_type storage; public: - Opts() : - free_token(0) + Opts() { } void description( const char* text ) @@ -97,46 +373,51 @@ void copyright( const char* text ) { _copyright = text; } - // adding option / flag (option that doesn't need arguments) - template <class T> - int add( const std::string& _longname,T _default_value,const std::string& _desc = "(no decription)" ); template <class T> - int add( char _shortname,T _default_value,const std::string& _longname = "(no longname)", const std::string& _desc = "(no decription)" ); + Opts& operator << ( const option<T>& o ) + { + storage.push_back( new option<T>( o ) ); + return *this; + } - int addflag( const std::string& _longname = "(no longname)",const std::string& desc = "(no decription)"); - - int addflag( char _shortname,const std::string& _longname = "(no longname)",const std::string& _desc = "(no decription)" ); - // getting option - template < class T ,class V > - T get( V field ); - - - template < class V > - std::string get( V field ); - + template <class T ,class V> + T get( const V& field, const T& ); - template <class T , class V> - T get_default( V field ); + template <class T, class V> + T get( const V& field ); - template < class V > - std::string get_default( V field ); + template <class BackInsertIterator> + void getemall( char field , BackInsertIterator bi ); + template <class BackInsertIterator> + void getemall( const std::string& field , BackInsertIterator bi ); + template <class BackInsertIterator> + void getemall( int field , BackInsertIterator bi ); - template < class V , class BackInsertIterator> - void getemall( V field , BackInsertIterator bi); + bool is_set( char field ) const; + bool is_set( const char* field ) const + { return is_set( std::string(field) ); } + bool is_set( const std::string& field ) const; + bool is_set( int field ) const; + int get_cnt( char field ) const; + int get_cnt( const char* field ) const + { return get_cnt( std::string(field) ); } + int get_cnt( const std::string& field ) const; + int get_cnt( int field ) const; - template < class T > - bool is_set( T field ) const; + template <class BackInsertIterator> + void get_pos( char, BackInsertIterator bi); + template <class BackInsertIterator> + void get_pos( const char* f, BackInsertIterator bi) + { get_pos( std::string(f), bi ); } + template <class BackInsertIterator> + void get_pos( const std::string&, BackInsertIterator bi); + template <class BackInsertIterator> + void get_pos( int, BackInsertIterator bi); - template < class T > - int get_cnt( T field ) const; - - template < class V , class BackInsertIterator > - void get_pos( V field , BackInsertIterator bi); - // parse void parse(int& ac, const char** av); @@ -169,9 +450,10 @@ { } }; + int last_token() const + { return storage.empty() ? -1 : storage.back()->token; } + private: - int free_token; - std::string pname; std::string _brief; std::string _usage; @@ -182,65 +464,39 @@ bool is_opt_name( const std::string& s ); bool is_flag_group( const std::string& s ); bool is_substr(const std::string& small, const std::string& big ); - options_container_type::iterator get_opt_index( std::string s ); + options_container_type::const_iterator get_opt_index( const std::string& s ); }; -template <class T> -int Opts::add(char _shortname,T _default_value,const std::string& _longname,const std::string& _desc) +template < class T , class V > +T Opts::get( const V& field, const T& ) { - addflag(_shortname,_longname,_desc); - std::stringstream ss; - ss << _default_value; - storage[storage.size() - 1][ss.str()]; - return storage[storage.size() - 1].token; -} + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,V>(), field ) ); -template <class T> -int Opts::add(const std::string& _longname,T _default_value,const std::string& _desc) -{ - addflag(_longname,_desc); - std::stringstream ss; - ss << _default_value; - storage[storage.size() - 1][ss.str()]; - return storage[storage.size() - 1].token; -} - -template <class T> -bool Opts::is_set(T field) const -{ - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - return ( (i == storage.end()) ? false : !i->pos.empty()); -} - -template <class T> -int Opts::get_cnt(T field) const -{ - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - return ( (i == storage.end()) ? 0 : i->pos.size()); -} - -template <class V> -std::string Opts::get( V field ) -{ - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option( ss1.str() ); } - if ( !i->has_arg ) { + if ( !(*i)->has_arg ) { throw std::logic_error("using Opts::get for option without arguments"); } - return i->args.empty() ? i->default_v : i->args[0]; + T res; + + (*i)->assign( res ); + + return res; } template < class T , class V > -T Opts::get( V field ) +T Opts::get( const V& field ) { - options_container_type::const_iterator i = std::find(storage.begin(), storage.end() ,field); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,V>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; @@ -248,73 +504,71 @@ throw unknown_option( ss1.str() ); } - if ( !i->has_arg ) { + if ( !(*i)->has_arg ) { throw std::logic_error("using Opts::get for option without arguments"); } T res; - std::stringstream ss(i->args.empty() ? i->default_v : i->args[0]); - ss >> res; - if ( ss.fail() ) { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args.empty() ? i->default_v : i->args[0]); - } + (*i)->assign( res ); return res; } -template < class V> -std::string Opts::get_default( V field ) +template <class BackInsertIterator> +void Opts::getemall( char field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option(ss1.str()); } - if ( !i->has_arg ) { - throw std::logic_error("using Opts::get for option without arguments"); + if ( !(*i)->has_arg ) { + throw std::logic_error("using Opts::getemall for option without arguments"); } - - return i->default_v; + + typedef typename BackInsertIterator::container_type::value_type real_type; + + option<real_type>* opt = dynamic_cast< option<real_type> * >( *i ); + + opt->get( bi ); } -template <class T , class V> -T Opts::get_default( V field ) +template <class BackInsertIterator> +void Opts::getemall( const std::string& field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option(ss1.str()); } - if ( !i->has_arg ) { - throw std::logic_error("using Opts::get for option without arguments"); + if ( !(*i)->has_arg ) { + throw std::logic_error("using Opts::getemall for option without arguments"); } - - T res; - std::stringstream ss(i->default_v); - ss >> res; - if ( ss.fail() ) { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->default_v); - } + typedef typename BackInsertIterator::container_type::value_type real_type; - return res; + option<real_type>* opt = dynamic_cast< option<real_type> * >( *i ); + + opt->get( bi ); } -template <class V , class BackInsertIterator> -void Opts::getemall( V field , BackInsertIterator bi) +template <class BackInsertIterator> +void Opts::getemall( int field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; @@ -322,28 +576,39 @@ throw unknown_option(ss1.str()); } - if ( !i->has_arg ) { + if ( !(*i)->has_arg ) { throw std::logic_error("using Opts::getemall for option without arguments"); } - - if ( !i->args.empty() ) { - for ( int j = 0; j < i->args.size(); ++j) { - std::stringstream ss(i->args[j]); - ss >> *bi++; - if ( ss.fail() ) { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args[j]); - } - } + typedef typename BackInsertIterator::container_type::value_type real_type; + + option<real_type>* opt = dynamic_cast< option<real_type> * >( *i ); + + opt->get( bi ); +} + +template <class BackInsertIterator> +void Opts::get_pos( char field , BackInsertIterator bi ) +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); + + if ( i == storage.end() ) { + std::stringstream ss1; + ss1 << field; + throw unknown_option(ss1.str()); } + + std::copy( (*i)->pos.begin(), (*i)->pos.end(), bi ); } -template <class V , class BackInsertIterator> -void Opts::get_pos( V field , BackInsertIterator bi) +template <class BackInsertIterator> +void Opts::get_pos( const std::string& field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; @@ -351,7 +616,23 @@ throw unknown_option(ss1.str()); } - std::copy( i->pos.begin(), i->pos.end(), bi ); + std::copy( (*i)->pos.begin(), (*i)->pos.end(), bi ); } +template <class BackInsertIterator> +void Opts::get_pos( int field, BackInsertIterator bi ) +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); + + if ( i == storage.end() ) { + std::stringstream ss1; + ss1 << field; + throw unknown_option(ss1.str()); + } + + std::copy( (*i)->pos.begin(), (*i)->pos.end(), bi ); +} + #endif // __OPTS_H__ Modified: trunk/complement/explore/lib/exam/ut/exam_self_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:10:26 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 01:27:58 ptr> /* - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -14,15 +14,8 @@ using namespace std; -int main( int argc,const char** argv) +int main( int argc, const char** argv ) { - // exam::test_suite t( "exam self test" ); - // t.add( exam_self_test, "exam self test suite" ); - // - // return t.girdle(); - - // return exam_self_test(0); - exam::test_suite t( "exam self test" ); exam_basic_test exam_basic; @@ -40,12 +33,15 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); - opts.addflag( 'l', "list", "list all test cases" ); - opts.add( 'r', 0, "run", "run tests by number" ); - opts.addflag( 'v', "verbose", "print status of tests within test suite" ); - opts.addflag( 't', "trace", "trace checks" ); + opts.description( "test suite for 'exam' framework" ); + opts.usage( "[options]" ); + opts << option<bool>( "print this help message", 'h', "help" ) + << option<bool>( "list all test cases", 'l', "list" ) + << option<string>( "run tests by number", 'r', "run" )["0"] + << option<bool>( "print status of tests within test suite", 'v', "verbose" ) + << option<bool>( "trace checks", 't', "trace" ); + try { opts.parse( argc, argv ); } @@ -73,7 +69,7 @@ } if ( opts.is_set( 'r' ) ) { - stringstream ss( opts.get( 'r' ) ); + stringstream ss( opts.get<string>( 'r' ) ); int n; while ( ss >> n ) { t.single( n ); @@ -84,4 +80,3 @@ return t.girdle(); } - Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ChangeLog 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,3 +1,11 @@ +2008-06-30 Petr Ovtchenkov <pt...@is...> + + * opts.h, opts.cc: revision of options framework; + insert object with type and type check into option; + default value passed via [] operator; + + * libmisc: version 1.10.0. + 2008-06-16 Petr Ovtchenkov <ye...@ya...> * opts.cc, opts.h: options parser, by Dmitry Osmakov. Modified: trunk/complement/explore/lib/misc/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/Makefile.inc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/Makefile.inc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <02/08/01 09:27:30 ptr> +# -*- Makefile -*- Time-stamp: <08/06/30 01:39:17 ptr> # I have only one reason while I should use "C++" variant of MD5 instead of "C": # names like MD5Init is wide distributed, but some cool programmers use this @@ -9,7 +9,7 @@ LIBNAME = misc MAJOR = 1 -MINOR = 9 -PATCH = 1 +MINOR = 10 +PATCH = 0 SRC_CC = CyrMoney.cc args.cc arguments.cc opts.cc SRC_C = md5.c Modified: trunk/complement/explore/lib/misc/opts.cc =================================================================== --- trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,10 +1,10 @@ -// -*- C++ -*- Time-stamp: <08/06/29 13:05:13 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 22:38:24 ptr> /* * Copyright (c) 2008 * Dmitry Osmakov * - * Copyright (c) 2008 + * Copyright (c) 1997-1998, 2001, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -21,22 +21,106 @@ using namespace std; -ostream& operator <<( ostream& out, const option_base& opt ) +int option_base::_count = 0; + +std::ostream& option<string>::_describe( std::ostream& out ) const { - if ( opt.shortname != 0 ) { - out << '-' << opt.shortname << (opt.has_arg ? " <val>" : "" ); - if ( !opt.longname.empty() ) { + if ( option_base::shortname != 0 ) { + out << '-' << option_base::shortname << " <string>"; + if ( !option_base::longname.empty() ) { out << ", "; } } + + if ( !option_base::longname.empty() ) { + out << "--" << option_base::longname << "=<string>"; + } - if ( !opt.longname.empty() ) { - out << "--" << opt.longname << (opt.has_arg ? "=<val>" : "" ); + if ( option_base::has_arg ) { + out << " [" << args.front() << "]\t"; + } else { + out << '\t'; } - return out << (opt.has_arg ? (string(" [") + opt.default_v + "]\t") : "\t" ) << opt.desc; + return out << option_base::desc; } +std::ostream& option<char*>::_describe( std::ostream& out ) const +{ + if ( option_base::shortname != 0 ) { + out << '-' << option_base::shortname << " <string>"; + if ( !option_base::longname.empty() ) { + out << ", "; + } + } + + if ( !option_base::longname.empty() ) { + out << "--" << option_base::longname << "=<string>"; + } + + if ( option_base::has_arg ) { + out << " [" << args.front() << "]\t"; + } else { + out << '\t'; + } + + return out << option_base::desc; +} + +bool Opts::is_set( char field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); + + return ( (i == storage.end()) ? false : !(*i)->pos.empty()); +} + +bool Opts::is_set( const std::string& field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); + + return ( (i == storage.end()) ? false : !(*i)->pos.empty()); +} + +bool Opts::is_set( int field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); + + return ( (i == storage.end()) ? false : !(*i)->pos.empty()); +} + +int Opts::get_cnt( char field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); + + return ( (i == storage.end()) ? 0 : (*i)->pos.size()); +} + +int Opts::get_cnt( const std::string& field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); + + return ( (i == storage.end()) ? 0 : (*i)->pos.size()); +} + +int Opts::get_cnt( int field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); + + return ( (i == storage.end()) ? 0 : (*i)->pos.size()); +} + string Opts::get_pname() const { return pname; } bool Opts::is_opt_name(const string& s) @@ -71,37 +155,38 @@ } // this function assumes that is_opt_name(s) = true; -Opts::options_container_type::iterator Opts::get_opt_index(string s) +Opts::options_container_type::const_iterator Opts::get_opt_index( const string& s) { assert(is_opt_name(s)); - if (s.size() == 2 && isalnum(s[1]) ) // is short name - { - options_container_type::iterator i; - for (i = storage.begin();i != storage.end();++i) - if (i->shortname == s[1]) + if (s.size() == 2 && isalnum(s[1]) ) { // is short name + options_container_type::const_iterator i = storage.begin(); + for ( ; i != storage.end(); ++i ) { + if ( (*i)->shortname == s[1]) { break; + } + } return i; } - if (s.size() > 2 && s[1] == '-') - { - options_container_type::iterator i; - s = s.substr(2); + if (s.size() > 2 && s[1] == '-') { + options_container_type::const_iterator i; + string tmp = s.substr(2); // exact match - for (i = storage.begin();i != storage.end();++i) - if (i->longname == s) + for ( i = storage.begin(); i != storage.end(); ++i ) { + if ( (*i)->longname == tmp ) { return i; + } + } - vector< options_container_type::iterator > matches; - for (i = storage.begin();i != storage.end();++i) - if (is_substr(s,i->longname)) + vector< options_container_type::const_iterator > matches; + for ( i = storage.begin();i != storage.end();++i ) { + if ( is_substr( tmp, (*i)->longname ) ) { matches.push_back(i); + } + } - if (matches.size() == 1) - return matches[0]; - else - return storage.end(); + return matches.size() == 1 ? matches[0] : storage.end(); } return storage.end(); @@ -129,32 +214,12 @@ out << "\nOptions:\n\n"; for ( options_container_type::const_iterator i = storage.begin(); i != storage.end(); ++i) { - out << *i << "\n"; + (*i)->_describe( out ) << '\n'; } } out << endl; } -int Opts::addflag( char _shortname, const string& _longname, const string& _desc ) -{ - option_base opt( _desc.c_str(), _shortname, _longname.c_str() ); - - opt.has_arg = false; - opt.token = ++free_token; - storage.push_back(opt); - return opt.token; -} - -int Opts::addflag( const string& _longname, const string& _desc ) -{ - option_base opt( _desc.c_str(), _longname.c_str() ); - - opt.has_arg = false; - opt.token = ++free_token; - storage.push_back(opt); - return opt.token; -} - void Opts::parse( int& ac, const char** av ) { pname = av[0]; @@ -168,41 +233,41 @@ string opt = av[i]; string arg; - int k = opt.find( "=" ); + string::size_type k = opt.find( "=" ); if ( k != string::npos ) { arg = opt.substr( k + 1 ); opt = opt.substr( 0, k ); } - options_container_type::iterator p = get_opt_index(opt); + options_container_type::const_iterator p = get_opt_index(opt); if ( p == storage.end() ) { throw unknown_option(opt); } - p->pos.push_back(++q); - if ( p->has_arg ) { + if ( (*p)->has_arg ) { if ( !arg.empty() ) { - p->args.push_back(arg); + (*p)->read(arg); } else { if ( (i + 1) >= ac ) { throw missing_arg(opt); } - p->args.push_back(av[++i]); + (*p)->read( av[++i] ); } } else if ( !arg.empty() ) { //unexpected arg (not exactly mismatch) throw arg_typemismatch(opt,arg); } + (*p)->pos.push_back(++q); } else if ( is_flag_group(av[i]) ) { string optgroup = av[i]; for ( int j = 1; j < optgroup.size(); j++ ) { - options_container_type::iterator p = get_opt_index(string("-") + optgroup[j]); + options_container_type::const_iterator p = get_opt_index(string("-") + optgroup[j]); if ( p == storage.end() ) { throw unknown_option( "-" + string(1,optgroup[j]) ); } - p->pos.push_back(++q); - if ( p->has_arg ) { + (*p)->pos.push_back(++q); + if ( (*p)->has_arg ) { throw missing_arg( "-" + string(1,optgroup[j]) ); } } Modified: trunk/complement/explore/lib/misc/ut/Makefile =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/Makefile 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:20:10 ptr> +# -*- Makefile -*- Time-stamp: <08/06/29 19:26:11 ptr> SRCROOT := ../../.. @@ -11,15 +11,16 @@ LIBEXAM_DIR = ${CoMT_DIR}/lib/exam LIBXMT_DIR = ${CoMT_DIR}/lib/mt +LIBMISC_DIR = ${CoMT_DIR}/lib/misc ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif @@ -34,10 +35,10 @@ endif -release-shared : LDLIBS = -lexam -lxmt -dbg-shared : LDLIBS = -lexamg -lxmtg +release-shared : LDLIBS = -lexam -lxmt -lmisc +dbg-shared : LDLIBS = -lexamg -lxmtg -lmiscg ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lexamstlg -lxmtstlg +stldbg-shared : LDLIBS = -lexamstlg -lxmtstlg -lmiscstlg endif ifeq ($(OSNAME),freebsd) Modified: trunk/complement/explore/lib/misc/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile.inc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/Makefile.inc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,7 +1,6 @@ -# -*- makefile -*- Time-stamp: <08/05/01 12:00:01 ptr> +# -*- makefile -*- Time-stamp: <08/06/29 19:23:01 ptr> PRGNAME = misc_ut SRC_CC = unit_test.cc \ misc_test.cc misc_test_suite.cc opts_test.cc -SRC_CPP = ../opts.cpp Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/05/21 12:30:07 yeti> +// -*- C++ -*- Time-stamp: <08/06/30 01:37:00 ptr> /* * Copyright (c) 2007, 2008 @@ -65,45 +65,49 @@ opts_test opts; - t.add( &opts_test::bool_option_long, opts, "simple boolean option, long" , + exam::test_suite::test_case_type tc[10]; + + tc[0] = + t.add( &opts_test::bool_option_long, opts, "simple boolean option, long" , t.add( &opts_test::bool_option, opts, "simple boolean option" ) ); - t.add( &opts_test::int_option_long, opts, "option with int parameter, long", + tc[1] = + t.add( &opts_test::int_option_long, opts, "option with int parameter, long", t.add( &opts_test::int_option, opts, "option with int parameter" ) ); - t.add( &opts_test::add_check_flag , opts , "add_check_flag"); - t.add( &opts_test::add_get_opt , opts , "add_get_opts"); - t.add( &opts_test::option_position,opts,"option position"); + t.add( &opts_test::add_check_flag, opts, "add_check_flag", tc[0] ); + t.add( &opts_test::add_get_opt, opts, "add_get_opts", tc[1] ); + t.add( &opts_test::option_position, opts, "option position", tc[0] ); - t.add( &opts_test::defaults, opts, "defaults" ); + t.add( &opts_test::defaults, opts, "defaults", tc[1] ); - t.add( &opts_test::bad_option, opts, "bad option" ); - t.add( &opts_test::bad_argument, opts, "bad argument" ); - t.add( &opts_test::unexpected_argument, opts, "unexpected_argument" ); - t.add( &opts_test::missing_argument, opts, "missing argument" ); + t.add( &opts_test::bad_option, opts, "bad option", tc[0] ); + t.add( &opts_test::bad_argument, opts, "bad argument", tc[1] ); + t.add( &opts_test::unexpected_argument, opts, "unexpected_argument", tc[0] ); + t.add( &opts_test::missing_argument, opts, "missing argument", tc[1] ); t.add( &opts_test::user_defined, opts, "user-defined type" ); - t.add( &opts_test::compound, opts, "compound" ); + tc[2] = t.add( &opts_test::compound, opts, "compound", tc[0] ); - t.add( &opts_test::multiple, opts,"multiple"); + tc[3] = t.add( &opts_test::multiple, opts, "multiple", tc[0] ); - t.add( &opts_test::multiple_compound, opts,"multiple_compound"); + t.add( &opts_test::multiple_compound, opts, "multiple_compound", tc + 2, tc + 4 ); - t.add( &opts_test::args, opts,"args"); + t.add( &opts_test::args, opts, "args" ); - t.add( &opts_test::stop, opts,"stop"); + t.add( &opts_test::stop, opts, "stop", tc, tc + 2 ); // check whether autocomplement works - t.add( &opts_test::autocomplement, opts,"autocomplement"); - t.add( &opts_test::autocomplement_failure, opts,"autocomplement_failure"); + tc[4] = t.add( &opts_test::autocomplement, opts, "autocomplement", tc[1] ); + t.add( &opts_test::autocomplement_failure, opts, "autocomplement_failure", tc[4] ); - t.add( &opts_test::multiple_args, opts,"multiple_args"); + t.add( &opts_test::multiple_args, opts, "multiple_args", tc[3] ); - t.add( &opts_test::help, opts, "help"); + t.add( &opts_test::help, opts, "help", tc, tc + 2 ); - t.add( &opts_test::long_string, opts, "long string"); + t.add( &opts_test::long_string, opts, "long string" ); return t.girdle(); } Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/29 13:18:16 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 01:10:34 ptr> /* * Copyright (c) 2008 @@ -17,7 +17,6 @@ #include <set> #include <vector> #include <list> -#include <fstream> #include <iostream> using namespace std; @@ -29,7 +28,7 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); + opts << option<bool>( "print this help message", 'h', "help" ); try { opts.parse( argc, argv ); @@ -40,6 +39,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } return EXAM_RESULT; } @@ -51,7 +52,7 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); + opts << option<bool>( "print this help message", 'h', "help" ); try { opts.parse( argc, argv ); @@ -62,6 +63,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } return EXAM_RESULT; } @@ -74,7 +77,7 @@ Opts opts; - opts.add( 'p', 0,"port", "listen tcp port"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; try { opts.parse( argc, argv ); @@ -97,7 +100,7 @@ Opts opts; - opts.add( 'p', 0, "port", "listen tcp port"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; try { opts.parse( argc, argv ); @@ -110,6 +113,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } return EXAM_RESULT; } @@ -121,11 +126,15 @@ Opts opts; - int f_token = opts.addflag('f'); - opts.addflag('t',"tag"); - int foo_token = opts.addflag("foo"); - opts.addflag("temp","temp desc"); - int h_token = opts.addflag( 'h', "help", "print this help message" ); + int f_token = (opts << option<bool>( "", 'f' )).last_token(); + + opts << option<bool>( "", 't', "tag" ); + + int foo_token = (opts << option<bool>( "", "foo" ) ).last_token(); + + opts << option<bool>( "temp desc", "temp" ); + + int h_token = ( opts << option<bool>( "print this help message", 'h', "help" ) ).last_token(); bool exception_happens = false; try { @@ -137,6 +146,10 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } + catch ( ... ) { + } EXAM_CHECK( !opts.is_set("foo") ); EXAM_CHECK( !opts.is_set(foo_token) ); @@ -146,40 +159,36 @@ EXAM_CHECK( opts.is_set('t')); EXAM_CHECK( opts.is_set("temp") ); EXAM_CHECK( !opts.is_set("unknow option") ); - EXAM_CHECK( !opts.is_set(42) ); + EXAM_CHECK( !opts.is_set(h_token+1) ); - try - { + try { opts.get<int>('f'); } - catch(const logic_error& e) - { + catch(const logic_error& e) { exception_happens = true; } EXAM_CHECK( exception_happens ); - exception_happens = false; - try - { - opts.get_default<int>("tag"); - } - catch(const logic_error& e) - { - exception_happens = true; - } +// exception_happens = false; +// try +// { +// opts.get_default<int>("tag"); +// } +// catch(const logic_error& e) +// { +// exception_happens = true; +// } - EXAM_CHECK( exception_happens ); +// EXAM_CHECK( exception_happens ); exception_happens = false; - try - { + try { vector< string > vs; - opts.getemall(h_token,vs.begin()); + opts.getemall( h_token, back_inserter( vs ) ); } - catch( const logic_error& e) - { + catch ( const logic_error& e) { exception_happens = true; } @@ -195,11 +204,10 @@ Opts opts; - int t_token = opts.add('t',10); - int name_token = opts.add("name","linus"); - int port_token = opts.add('p',80,"port"); - int num_token = opts.add("num",100,"number of elements"); - + int t_token = (opts << option<int>( "", 't' )[10]).last_token(); + int name_token = (opts << option<string>( "", "name" )["linus"]).last_token(); + int port_token = (opts << option<int>( "", 'p', "port" )[80]).last_token(); + int num_token = (opts << option<int>( "number of elements", "num")[100]).last_token(); try { opts.parse( argc, argv ); @@ -216,7 +224,7 @@ EXAM_CHECK( opts.is_set(name_token) ); EXAM_CHECK( opts.get_cnt("name") == 1 ); EXAM_CHECK( opts.get<string>(name_token) == "torwalds"); - EXAM_CHECK( opts.get_default<string>("name") == "linus"); + // EXAM_CHECK( opts.get_default<string>("name") == "linus"); EXAM_CHECK( !opts.is_set('p') ); //EXAM_CHECK( !opts.is_set("num") && opts.get<int>(num_token) == opts.get_default<int>("num") ) ; @@ -230,11 +238,11 @@ Opts opts; - opts.add( 'p', 0, "port", "listen tcp port"); - opts.addflag("begin"); - int f1_token = opts.addflag("f1"); - int f2_token = opts.addflag("f2"); - opts.addflag("end"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; + opts << option<bool>( "", "begin" ); + int f1_token = (opts << option<bool>( "", "f1") ).last_token(); + int f2_token = (opts << option<bool>( "", "f2") ).last_token(); + opts << option<bool>( "", "end" ); try { opts.parse( argc, argv ); @@ -262,8 +270,7 @@ opts.get_pos(f2_token,f2_v.begin()); opts.get_pos("end",e_v.begin()); - try - { + try { opts.get_pos("unknown",u_l.begin()); } catch(const Opts::unknown_option& e) @@ -292,7 +299,7 @@ Opts opts; - opts.add( 'p', 0, "port", "listen tcp port"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; try { opts.parse( argc, argv ); @@ -305,6 +312,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( ... ) { + } return EXAM_RESULT; } @@ -316,7 +325,7 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); + opts << option<bool>( "print this help message", 'h', "help" ); bool exception_happens = false; @@ -330,6 +339,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( ... ) { + } EXAM_CHECK( exception_happens ); @@ -343,23 +354,26 @@ Opts opts; - opts.add( 'p', 10, "port", "listen tcp port" ); + opts << option<int>( "listen tcp port", 'p', "port" )[10]; bool exception_happens = false; - - opts.parse( argc, argv ); - try - { + try { + opts.parse( argc, argv ); // <- exception here + int t = opts.get<int>('p'); } - catch(const Opts::arg_typemismatch& e) - { + catch ( const Opts::arg_typemismatch& e ) { exception_happens = true; } + catch ( const std::invalid_argument& e ) { + exception_happens = true; + } + catch ( ... ) { + } EXAM_CHECK( exception_happens ); - EXAM_CHECK ( opts.get_default<int>('p') == 10 ); + // EXAM_CHECK ( opts.get_default<int>('p') == 10 ); return EXAM_RESULT; } @@ -371,16 +385,14 @@ Opts opts; - opts.addflag('h',"help"); + opts << option<bool>( "", 'h', "help" ); bool exception_happens = false; - try - { + try { opts.parse( argc, argv ); } - catch(const Opts::arg_typemismatch& e) - { + catch(const Opts::arg_typemismatch& e) { exception_happens = true; } @@ -396,18 +408,18 @@ Opts opts; - opts.add('n',10,"num"); + opts << option<int>( "", 'n', "num" )[10]; bool exception_happens = false; - try - { + try { opts.parse( argc, argv ); } - catch(const Opts::missing_arg& e) - { + catch(const Opts::missing_arg& e) { exception_happens = true; } + catch ( ... ) { + } EXAM_CHECK( exception_happens ); @@ -422,7 +434,7 @@ Opts opts; - opts.addflag( 'v', "verbose", "more trace messages" ); + opts << option<bool>( "more trace messages", 'v', "verbose" ); opts.parse( argc, argv ); @@ -435,7 +447,7 @@ Opts opts; - opts.addflag( 'v', "verbose", "more trace messages" ); + opts << option<bool>( "more trace messages", 'v', "verbose" ); opts.parse( argc, argv ); @@ -448,7 +460,7 @@ Opts opts; - opts.addflag( 'v', "verbose", "more trace messages" ); + opts << option<bool>( "more trace messages", 'v', "verbose" ); opts.parse( argc, argv ); @@ -458,7 +470,6 @@ return EXAM_RESULT; } - int EXAM_IMPL(opts_test::compound) { { @@ -467,9 +478,9 @@ Opts opts; - opts.addflag( 'a', "a-option", "option a" ); - opts.addflag( 'b', "b-option", "option b" ); - opts.addflag( 'c', "c-option", "option c" ); + opts << option<bool>( "option a", 'a', "a-option" ); + opts << option<bool>( "option b", 'b', "b-option" ); + opts << option<bool>( "option c", 'c', "c-option" ); opts.parse( argc, argv ); @@ -482,36 +493,40 @@ int EXAM_IMPL(opts_test::multiple_compound) { - { - const char* argv[] = { "name", "-xf","--flag", "-f", "-p=first" ,"--pa","second" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name", "-xf", "--flag", "-f", "-p=first", "--pa", "second" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.addflag( 'x', "x-option", "option x" ); - opts.addflag( 'f', "flag", "option f" ); + opts << option<bool>( "option x", 'x', "x-option" ); + opts << option<bool>( "option f", 'f', "flag" ); - opts.add('p',"defaultpath","path","some path"); + opts << option<string>( "some path", 'p', "path" )["defaultpath"]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - EXAM_CHECK(opts.is_set('x')); - EXAM_CHECK(opts.is_set("flag")); - EXAM_CHECK(opts.is_set('p')); - EXAM_CHECK(opts.get_cnt("flag") == 3 && opts.get_cnt('f') == 3); - vector<string> vs(2); + EXAM_CHECK(opts.is_set('x')); + EXAM_CHECK(opts.is_set("flag")); + EXAM_CHECK(opts.is_set('p')); + EXAM_CHECK(opts.get_cnt("flag") == 3 && opts.get_cnt('f') == 3); - opts.getemall("path",vs.begin()); - EXAM_CHECK( vs[0] == "first" ); - EXAM_CHECK( vs[1] == "second" ); - } + vector<string> vs; + opts.getemall( "path", back_inserter( vs ) ); + vector<string>::iterator j = vs.begin(); + + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "first" ); + ++j; + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "second" ); + ++j; + EXAM_CHECK( j == vs.end() ); + return EXAM_RESULT; } - - int EXAM_IMPL(opts_test::args) { { @@ -520,7 +535,7 @@ Opts opts; - opts.add( 'f',string("default.conf"), "config", "configuration file"); + opts << option<string>( "configuration file", 'f', "config" )["default.conf"]; opts.parse( argc, argv ); @@ -536,7 +551,7 @@ Opts opts; - opts.add( 'f', string("default.conf"), "config", "configuration file" ); + opts << option<string>( "configuration file", 'f', "config" )["default.conf"]; opts.parse( argc, argv ); @@ -552,7 +567,7 @@ Opts opts; - opts.add( 'f', string("default.conf"), "config", "configuration file" ); + opts << option<string>( "configuration file", 'f', "config" )["default.conf"]; opts.parse( argc, argv ); @@ -573,7 +588,7 @@ Opts opts; - opts.addflag( 'a', "a-option", "option a" ); + opts << option<bool>( "option a", 'a', "a-option" ); opts.parse( argc, argv ); @@ -611,20 +626,18 @@ int EXAM_IMPL(opts_test::user_defined) { - { - const char* argv[] = { "name", "-s", "1 2" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name", "-s", "1 2" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add( 's', point(1,1) ,"start-point", "start point"); + opts << option<point>( "start point", 's', "start-point" )[point(1,1)]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - point p = opts.get<point>( 's' ); + point p = opts.get<point>( 's' ); - EXAM_CHECK( (p.x == 1) && (p.y == 2) ); - } + EXAM_CHECK( (p.x == 1) && (p.y == 2) ); return EXAM_RESULT; } @@ -632,73 +645,79 @@ // check whether autocomplement works int EXAM_IMPL(opts_test::autocomplement) { - { - const char* argv[] = { "name" , "--num" , "4"}; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name" , "--num", "4" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add('n',1,"number_of_processors","number of processors" ); + opts << option<int>( "number of processors", 'n', "number_of_processors" )[1]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - EXAM_CHECK( opts.get<int>('n') == 4 ); - } + EXAM_CHECK( opts.get<int>('n') == 4 ); return EXAM_RESULT; } int EXAM_IMPL(opts_test::autocomplement_failure) { - { - const char* argv[] = { "name" , "--proc" , "4"}; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name" , "--proc" , "4" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add('p',1,"proc_num","process number" ); - opts.add('t',string("standart"),"proc_type","process type"); + opts << option<int>( "process number", 'p', "proc_num" )[1]; + opts << option<string>( "process type", 't', "proc_type" )["standard"]; - bool exception_happens = false; + bool exception_happens = false; - try - { - opts.parse( argc, argv ); - } - catch(const Opts::unknown_option& e) - { - exception_happens = true; - } - - EXAM_CHECK( exception_happens ); + try { + opts.parse( argc, argv ); } + catch (const Opts::unknown_option& e) { + exception_happens = true; + } + catch ( ... ) { + } + EXAM_CHECK( exception_happens ); + return EXAM_RESULT; } int EXAM_IMPL(opts_test::multiple_args) { - { - const char* argv[] = { "name" , "-I" , "first","-I","second","-I","third"}; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name" , "-I", "first", "-I", "second", "-I", "third" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add('I',"/usr/include","include","include paths" ); + opts << option<string>( "include paths", 'I', "include" )[ "/usr/include" ]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - vector<string> vs(10); + vector<string> vs; - opts.getemall('I',vs.begin()); + opts.getemall( 'I', back_inserter(vs) ); - EXAM_CHECK( opts.get_default<string>("include") == "/usr/include"); + // EXAM_CHECK( opts.get_default<string>("include") == "/usr/include"); + + vector<string>::iterator j = vs.begin(); + + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "first" ); + + ++j; + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "second" ); - EXAM_CHECK( vs[0] == "first" ); - EXAM_CHECK( vs[1] == "second" ); - EXAM_CHECK( vs[2] == "third" ); - } + ++j; + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "third" ); + ++j; + EXAM_CHECK( j == vs.end() ); + return EXAM_RESULT; } @@ -714,12 +733,12 @@ opts.author( "B. L. User" ); opts.copyright( "Copyright (C) Youyoudine, 2008" ); - opts.addflag( 'h', "help", "print this help message" ); - opts.addflag( "flag", "some program flag" ); - opts.addflag( 'v', "version", "print version"); - opts.add( 'I', "/usr/include", "include", "include paths" ); - opts.add( 'p', 80, "port", "listen to tcp port" ); - opts.add( "mode", "standard", "program mode"); + opts << option<bool>( "print this help message", 'h', "help" ); + opts << option<bool>( "some program flag", "flag" ); + opts << option<bool>( "print version", 'v', "version" ); + opts << option<string>( "include paths", 'I', "include" )["/usr/include"]; + opts << option<int>( "listen to tcp port", 'p', "port" )[80]; + opts << option<string>( "program mode", "mode" )["standard"]; opts.parse( argc,argv ); @@ -746,9 +765,9 @@ -h, --help\tprint this help message\n\ --flag\tsome program flag\n\ -v, --version\tprint version\n\ --I <val>, --include=<val> [/usr/include]\tinclude paths\n\ --p <val>, --port=<val> [80]\tlisten to tcp port\n\ ---mode=<val> [standard]\tprogram mode\n\ +-I <string>, --include=<string> [/usr/include]\tinclude paths\n\ +-p <i>, --port=<i> [80]\tlisten to tcp port\n\ +--mode=<string> [standard]\tprogram mode\n\ \n"; EXAM_CHECK( s.str() == sample ); @@ -759,19 +778,29 @@ int EXAM_IMPL(opts_test::long_string) { { - const char* argv[] = { "name" , "--string" , "long string"}; + const char* argv[] = { "name", "--string", "long string" }; int argc = sizeof( argv ) / sizeof(argv[0]); Opts opts; - opts.add('s',string("default value"),"string","some string param"); + opts << option<string>( "some string param", 's', "string" )["default value"]; - EXAM_CHECK( opts.get('s') == "default value"); + opts.parse( argc, argv ); - opts.parse(argc,argv); + EXAM_CHECK( opts.get<string>( 's' ) == "long string" ); + } - EXAM_CHECK( opts.get('s') == "long string"); + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "some string param", 's', "string" )["default value"]; + opts.parse( argc, argv ); + + EXAM_CHECK( opts.get<string>( 's' ) == "default value" ); } return EXAM_RESULT; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-30 06:28:37
|
Revision: 1929 http://complement.svn.sourceforge.net/complement/?rev=1929&view=rev Author: complement Date: 2008-06-29 23:28:32 -0700 (Sun, 29 Jun 2008) Log Message: ----------- libmisc 1.10.1; free allocated objects. add tests for is_set with/without default value, that not pass (unexpected behaviour) Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/ChangeLog trunk/complement/explore/lib/misc/Makefile.inc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/include/misc/opts.h 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/29 22:16:12 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 10:00:22 ptr> /* * Copyright (c) 2008 @@ -110,6 +110,9 @@ { return *__x == __y; } }; +inline void option_base_destroyer( option_base* p ) +{ delete p; } + } // namespace detail template <class T> @@ -361,6 +364,9 @@ Opts() { } + ~Opts() + { std::for_each( storage.begin(), storage.end(), detail::option_base_destroyer ); } + void description( const char* text ) { _brief = text; } Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/ChangeLog 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,5 +1,9 @@ 2008-06-30 Petr Ovtchenkov <pt...@is...> + * opts.h: free allocated objects; + + * libmisc: version 1.10.1. + * opts.h, opts.cc: revision of options framework; insert object with type and type check into option; default value passed via [] operator; Modified: trunk/complement/explore/lib/misc/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/Makefile.inc 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/Makefile.inc 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/30 01:39:17 ptr> +# -*- Makefile -*- Time-stamp: <08/06/30 10:25:33 ptr> # I have only one reason while I should use "C++" variant of MD5 instead of "C": # names like MD5Init is wide distributed, but some cool programmers use this @@ -10,6 +10,6 @@ LIBNAME = misc MAJOR = 1 MINOR = 10 -PATCH = 0 +PATCH = 1 SRC_CC = CyrMoney.cc args.cc arguments.cc opts.cc SRC_C = md5.c Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 01:10:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 10:08:01 ptr> /* * Copyright (c) 2008 @@ -294,26 +294,63 @@ int EXAM_IMPL(opts_test::defaults) { - const char* argv[] = { "name" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts << option<int>( "listen tcp port", 'p', "port" )[0]; + opts << option<int>( "listen tcp port", 'p', "port" )[0]; - try { - opts.parse( argc, argv ); + try { + opts.parse( argc, argv ); + EXAM_CHECK( !opts.is_set( 'p' ) ); + EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); + } + catch ( const Opts::unknown_option& e ) { + } + catch ( const Opts::arg_typemismatch& e ) { + } + catch ( ... ) { + } + } - EXAM_CHECK( !opts.is_set( 'p' ) ); - EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); + { + const char* argv[] = { "name", "-r", "10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" )["0"]; + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } - catch ( const Opts::unknown_option& e ) { + + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" )["20"]; + + EXAM_CHECK( opts.is_set( 'r' ) == false ); // not set + EXAM_CHECK( opts.get<string>( 'r' ) == "20" ); // but has default value } - catch ( const Opts::arg_typemismatch& e ) { + + { + const char* argv[] = { "name", "-r", "10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" ); + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } - catch ( ... ) { - } return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-30 12:51:08
|
Revision: 1933 http://complement.svn.sourceforge.net/complement/?rev=1933&view=rev Author: complement Date: 2008-06-30 05:51:01 -0700 (Mon, 30 Jun 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Modified Paths: -------------- trunk/complement/explore/include/mt/shm.h trunk/complement/explore/lib/misc/ut/misc_test.cc trunk/complement/explore/lib/misc/ut/misc_test.h trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc Modified: trunk/complement/explore/include/mt/shm.h =================================================================== --- trunk/complement/explore/include/mt/shm.h 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/include/mt/shm.h 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:37:01 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 13:48:26 yeti> /* * Copyright (c) 2006-2008 @@ -106,6 +106,7 @@ __SPEC_FULL(is_ipc_sharable,std::tr2::condition_variable_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::condition_variable_any_ip,true); +__SPEC_FULL(is_ipc_sharable,std::tr2::condition_event_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::semaphore_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::barrier_ip,true); __SPEC_FULL(is_ipc_sharable,std::tr2::mutex_ip,true); Modified: trunk/complement/explore/lib/misc/ut/misc_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test.cc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/misc_test.cc 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/12/02 20:37:29 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 12:39:37 yeti> /* * Copyright (c) 2007 @@ -512,8 +512,6 @@ { EXAM_CHECK( std::tr1::is_pod<const int>::value == true ); EXAM_CHECK( std::tr1::is_pod<int *>::value == true ); - EXAM_CHECK( std::tr1::is_pod<NT>::value == true ); - EXAM_CHECK( std::tr1::is_pod<POD>::value == true ); EXAM_CHECK( std::tr1::is_pod<SL>::value == false ); EXAM_CHECK( std::tr1::is_pod<N>::value == false ); @@ -522,6 +520,18 @@ return EXAM_RESULT; } +int EXAM_IMPL(misc_test::type_traits_is_pod_compiler_supp) +{ +#if defined(__GNUC__) && ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) ) + throw exam::skip_exception(); +#endif + + EXAM_CHECK( std::tr1::is_pod<NT>::value == true ); + EXAM_CHECK( std::tr1::is_pod<POD>::value == true ); + + return EXAM_RESULT; +} + class empty { }; Modified: trunk/complement/explore/lib/misc/ut/misc_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test.h 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/misc_test.h 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/12/02 18:50:20 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 12:40:05 yeti> /* * Copyright (c) 2007 @@ -50,6 +50,7 @@ int EXAM_DECL(type_traits_is_trivial); int EXAM_DECL(type_traits_is_standard_layout); int EXAM_DECL(type_traits_is_pod); + int EXAM_DECL(type_traits_is_pod_compiler_supp); int EXAM_DECL(type_traits_is_empty); }; Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 01:37:00 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 12:42:03 yeti> /* * Copyright (c) 2007, 2008 @@ -52,7 +52,8 @@ t.add( &misc_test::type_traits_is_volatile, test, "is_volatile", tc[0] ); // t.add( &misc_test::type_traits_is_trivial, test, "is_trivial", tc[0] ); // t.add( &misc_test::type_traits_is_standard_layout, test, "is_standard_layout", tc[0] ); - t.add( &misc_test::type_traits_is_pod, test, "is_pod", tc[0] ); + tc[4] = t.add( &misc_test::type_traits_is_pod, test, "is_pod", tc[0] ); + t.add( &misc_test::type_traits_is_pod_compiler_supp, test, "is_pod_compiler_supp", tc[4] ); t.add( &misc_test::type_traits_is_empty, test, "is_empty", tc[0] ); return t.girdle(); Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 12:51:01 UTC (rev 1933) @@ -324,6 +324,8 @@ opts << option<string>( "run tests by number", 'r', "run" )["0"]; + opts.parse( argc, argv ); + EXAM_CHECK( opts.is_set( 'r' ) ); EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } @@ -336,6 +338,8 @@ opts << option<string>( "run tests by number", 'r', "run" )["20"]; + opts.parse( argc, argv ); + EXAM_CHECK( opts.is_set( 'r' ) == false ); // not set EXAM_CHECK( opts.get<string>( 'r' ) == "20" ); // but has default value } @@ -348,6 +352,8 @@ opts << option<string>( "run tests by number", 'r', "run" ); + opts.parse( argc, argv ); + EXAM_CHECK( opts.is_set( 'r' ) ); EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,3 +1,9 @@ +2008-06-30 Petr Ovtchenkov <ye...@ya...> + + * shm.h: condition_event_ip may be used in shared memory; + + * libxmt: bump revision to 2.0.4. + 2008-06-06 Petr Ovtchenkov <pt...@is...> * uid.h, uid.cc: functions for generating UIDs; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-06-30 12:50:41 UTC (rev 1932) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-06-30 12:51:01 UTC (rev 1933) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/06/06 21:25:42 yeti> +# -*- Makefile -*- Time-stamp: <08/06/30 13:51:45 yeti> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 3 +PATCH = 4 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-01 14:41:39
|
Revision: 1935 http://complement.svn.sourceforge.net/complement/?rev=1935&view=rev Author: complement Date: 2008-07-01 07:41:36 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Replace old xmt-style mutexes/conds by new wg21 implementation. Modified Paths: -------------- trunk/complement/explore/include/stem/Event.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/lib/stem/ut/Convert.cc trunk/complement/explore/lib/stem/ut/Convert.h trunk/complement/explore/lib/stem/ut/Echo.cc trunk/complement/explore/lib/stem/ut/Echo.h trunk/complement/explore/lib/stem/ut/Makefile trunk/complement/explore/lib/stem/ut/NameService.cc trunk/complement/explore/lib/stem/ut/NameService.h trunk/complement/explore/lib/stem/ut/Node.cc trunk/complement/explore/lib/stem/ut/Node.h trunk/complement/explore/lib/stem/ut/NodeDL.h trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc trunk/complement/explore/lib/stem/ut/unit_test.cc Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/include/stem/Event.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/10/15 22:41:17 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:14:16 yeti> /* * - * Copyright (c) 1995-1999, 2002, 2003, 2005-2007 + * Copyright (c) 1995-1999, 2002, 2003, 2005-2008 * Petr Ovtchenkov * * Copyright (c) 1999-2001 @@ -29,7 +29,7 @@ #include <misc/type_traits.h> #include <stem/EvPack.h> #include <mt/uid.h> -#include <mt/xmt.h> +#include <mt/thread> #ifdef STLPORT # include <unordered_map> @@ -85,7 +85,7 @@ explicit gaddr_type( stem::addr_type _addr ) : hid( xmt::hostid() ), - pid( xmt::getpid() ), + pid( std::tr2::getpid() ), addr( _addr ) { } Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/include/stem/NetTransport.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:34:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 15:29:44 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006, 2008 @@ -81,6 +81,10 @@ __FIT_DECLSPEC void connect( std::sockstream& ); + + private: + void _do_handshake(); + bool _handshake; }; class NetTransportMgr : Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/EvManager.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:36:14 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:18:21 yeti> /* * @@ -20,7 +20,7 @@ #include "stem/EvManager.h" #include "stem/NetTransport.h" #include <iomanip> -#include <mt/xmt.h> +#include <mt/mutex> // #include <typeinfo> @@ -114,7 +114,7 @@ lock_guard<mutex> lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = xmt::getpid(); + gaddr.pid = std::tr2::getpid(); gaddr.addr = id; } @@ -147,7 +147,7 @@ lock_guard<mutex> lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = xmt::getpid(); + gaddr.pid = std::tr2::getpid(); gaddr.addr = id; } @@ -198,7 +198,7 @@ const std::string& info ) { addr_type id; - if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // local + if ( addr.hid == xmt::hostid() && addr.pid == std::tr2::getpid() ) { // local if ( addr.addr & extbit ) { // may be transit object lock_guard<mutex> lk( _lock_xheap ); pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( addr ); @@ -286,7 +286,7 @@ __FIT_DECLSPEC addr_type EvManager::reflect( const gaddr_type& addr ) const { - if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { + if ( addr.hid == xmt::hostid() && addr.pid == std::tr2::getpid() ) { // this host, this process if ( (addr.addr & extbit) == 0 ) { // looks like local object lock_guard<mutex> _x1( _lock_heap ); @@ -432,7 +432,7 @@ if ( i == _ex_heap.end() ) { // destination not found ostringstream s; s << "external address unknown: " << hex << e.dest() << " from " - << e.src() << ", pid " << xmt::getpid() << dec; + << e.src() << ", pid " << std::tr2::getpid() << dec; throw invalid_argument( s.str() ); } @@ -450,7 +450,7 @@ if ( j == _ex_heap.end() ) { gaddr_type& _gaddr_src = _ex_heap[e.src()]; _gaddr_src.hid = xmt::hostid(); - _gaddr_src.pid = xmt::getpid(); + _gaddr_src.pid = std::tr2::getpid(); _gaddr_src.addr = e.src(); // it may be as local as foreign; if e.src() // is foreign, the object is 'transit object' gaddr_src = _gaddr_src; Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/Names.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/04 18:43:56 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:11:16 yeti> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 + * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006, 2008 * Petr Ovtchenkov * * Copyright (c) 1999-2001 @@ -26,12 +26,9 @@ #include <list> #include <iostream> -#include <mt/xmt.h> - namespace stem { using namespace std; -using namespace xmt; __FIT_DECLSPEC Names::Names() : EventHandler() Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 01:28:00 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:07:37 yeti> /* * @@ -264,10 +264,15 @@ __FIT_DECLSPEC NetTransport::NetTransport( std::sockstream& s ) : - NetTransport_base( "stem::NetTransport" ) + NetTransport_base( "stem::NetTransport" ), + _handshake( false ) { net = &s; +} +__FIT_DECLSPEC +void NetTransport::_do_handshake() +{ try { Event ev; gaddr_type dst; @@ -295,40 +300,46 @@ } else { throw runtime_error( "net error or net handshake error" ); } + _handshake = true; } catch ( runtime_error& err ) { try { lock_guard<mutex> lk(manager()->_lock_tr); if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " " << err.what() - << " (" << s.rdbuf()->inet_addr() << ":" << s.rdbuf()->port() + << " (" << net->rdbuf()->inet_addr() << ":" << net->rdbuf()->port() << ")" << endl; } } catch ( ... ) { } - s.close(); + net->close(); } catch ( ... ) { try { lock_guard<mutex> lk(manager()->_lock_tr); if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracefault) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " unknown exception" - << " (" << s.rdbuf()->inet_addr() << ":" << s.rdbuf()->port() + << " (" << net->rdbuf()->inet_addr() << ":" << net->rdbuf()->port() << ")" << endl; } } catch ( ... ) { } - s.close(); + net->close(); } } __FIT_DECLSPEC void NetTransport::connect( sockstream& s ) { + if ( !_handshake ) { + _do_handshake(); + return; + } + try { Event ev; gaddr_type dst; @@ -339,7 +350,7 @@ try { lock_guard<mutex> lk(manager()->_lock_tr); if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracenet) ) { - *manager()->_trs << "Pid/ppid: " << xmt::getpid() << "/" << xmt::getppid() << "\n"; + *manager()->_trs << "Pid/ppid: " << std::tr2::getpid() << "/" << std::tr2::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } } @@ -354,7 +365,7 @@ if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" - << xmt::getpid() << "/" << xmt::getppid() << ") " + << std::tr2::getpid() << "/" << std::tr2::getppid() << ") " << "Unknown destination\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -511,7 +522,7 @@ try { lock_guard<mutex> lk(manager()->_lock_tr); if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & EvManager::tracenet) ) { - *manager()->_trs << "Pid/ppid: " << xmt::getpid() << "/" << xmt::getppid() << "\n"; + *manager()->_trs << "Pid/ppid: " << std::tr2::getpid() << "/" << std::tr2::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } } @@ -526,7 +537,7 @@ if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" - << xmt::getpid() << "/" << xmt::getppid() << ") " + << std::tr2::getpid() << "/" << std::tr2::getppid() << ") " << "Unknown destination\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -578,7 +589,7 @@ lock_guard<mutex> lk(manager()->_lock_tr); if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & E vManager::tracenet) ) { - *manager()->_trs << "Pid/ppid: " << xmt::getpid() << "/" << xmt::getppid() << + *manager()->_trs << "Pid/ppid: " << std::tr2::getpid() << "/" << std::tr2::getppid() << "\n"; manager()->dump( *manager()->_trs ) << endl; } @@ -594,7 +605,7 @@ if ( manager()->_trs != 0 && manager()->_trs->good() && (manager()->_trflags & (EvManager::tracefault)) ) { *manager()->_trs << __FILE__ << ":" << __LINE__ << " (" - << xmt::getpid() << "/" << xmt::getppid() << ") " + << std::tr2::getpid() << "/" << std::tr2::getppid() << ") " << "Unknown destination\n"; manager()->dump( *manager()->_trs ) << endl; } Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:32:30 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:16:58 yeti> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006, 2008 @@ -19,7 +19,9 @@ #include "stem/EventHandler.h" #include "stem/EvManager.h" #include "stem/Names.h" -#include "mt/mutex" +#include <mt/mutex> +#include <mt/thread> +#include <mt/uid.h> #include <unistd.h> @@ -265,7 +267,7 @@ __FIT_DECLSPEC gaddr_type EventHandler::self_glid() const { - return gaddr_type(xmt::hostid(), xmt::getpid(), _id ); + return gaddr_type(xmt::hostid(), std::tr2::getpid(), _id ); } } // namespace stem Modified: trunk/complement/explore/lib/stem/ut/Convert.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/Convert.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Convert.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/20 00:05:52 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 19:08:00 yeti> /* * - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -10,7 +10,10 @@ */ #include "Convert.h" +#include <mt/date_time> +using namespace std::tr2; + void mess::pack( std::ostream& s ) const { __pack( s, super_id ); @@ -35,65 +38,64 @@ __net_unpack( s, message ); } +int Convert::v = 0; + + Convert::Convert() : - EventHandler(), - v( 0 ) + EventHandler() { - cnd.set( false ); } Convert::Convert( stem::addr_type id ) : - EventHandler( id ), - v( 0 ) + EventHandler( id ) { - cnd.set( false ); } Convert::Convert( stem::addr_type id, const char *info ) : - EventHandler( id, info ), - v( 0 ) + EventHandler( id, info ) { - cnd.set( false ); } Convert::~Convert() { - // cnd.wait(); } void Convert::handler0() { + lock_guard<mutex> lk( mtx ); v = -1; - cnd.set(true); + cnd.notify_one(); } void Convert::handler1( const stem::Event& ) { + lock_guard<mutex> lk( mtx ); v = 1; - cnd.set(true); + cnd.notify_one(); } void Convert::handler2( const stem::Event_base<mess>& ev ) { + lock_guard<mutex> lk( mtx ); v = ev.value().super_id; m2 = ev.value().message; - cnd.set(true); + cnd.notify_one(); } void Convert::handler3( const mess& m ) { + lock_guard<mutex> lk( mtx ); v = m.super_id; m3 = m.message; - cnd.set(true); + cnd.notify_one(); } -void Convert::wait() +bool Convert::wait() { - cnd.try_wait(); - - cnd.set( false ); + unique_lock<mutex> lk( mtx ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ), v_nz_check ); } DEFINE_RESPONSE_TABLE( Convert ) Modified: trunk/complement/explore/lib/stem/ut/Convert.h =================================================================== --- trunk/complement/explore/lib/stem/ut/Convert.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Convert.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/20 00:03:52 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 19:07:02 yeti> /* * - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,8 @@ #ifndef __Convert_h #define __Convert_h -#include <mt/xmt.h> +#include <mt/mutex> +#include <mt/condition_variable> #include <stem/Event.h> #include <stem/EventHandler.h> @@ -53,16 +54,20 @@ void handler2( const stem::Event_base<mess>& ); void handler3( const mess& ); - void wait(); + bool wait(); - int v; + static int v; std::string m2; std::string m3; private: - xmt::condition cnd; + static bool v_nz_check() + { return v != 0; } + std::tr2::mutex mtx; + std::tr2::condition_variable cnd; + DECLARE_RESPONSE_TABLE( Convert, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/Echo.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/Echo.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Echo.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 13:02:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 13:16:04 yeti> /* * Copyright (c) 2006, 2007 @@ -14,6 +14,7 @@ #include <stem/EvManager.h> #include <exam/suite.h> +#include <mt/date_time> using namespace stem; @@ -45,7 +46,8 @@ { // cerr << "Echo\n"; manager()->change_announce( ev.src(), ev.value() ); - cnd.set( true ); + + cnd.notify_one(); } DEFINE_RESPONSE_TABLE( StEMecho ) @@ -57,21 +59,18 @@ EventHandler(), mess( "echo string" ) { - cnd.set( false ); } EchoClient::EchoClient( stem::addr_type id ) : EventHandler( id ), mess( "echo string" ) { - cnd.set( false ); } EchoClient::EchoClient( stem::addr_type id, const char *info ) : EventHandler( id, info ), mess( "echo string" ) { - cnd.set( false ); } EchoClient::~EchoClient() @@ -82,12 +81,13 @@ void EchoClient::handler1( const stem::Event& ev ) { EXAM_CHECK_ASYNC( ev.value() == mess ); - cnd.set(true); + + cnd.notify_one(); } -void EchoClient::wait() +bool EchoClient::wait() { - cnd.try_wait(); + return cnd.timed_wait( std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( EchoClient ) @@ -98,28 +98,24 @@ EventHandler(), mess( "peer client" ) { - cnd.set( false ); } PeerClient::PeerClient( stem::addr_type id ) : EventHandler( id ), mess( "peer client" ) { - cnd.set( false ); } PeerClient::PeerClient( const char *info ) : EventHandler( info ), mess( info ) { - cnd.set( false ); } PeerClient::PeerClient( stem::addr_type id, const char *info ) : EventHandler( id, info ), mess( info ) { - cnd.set( false ); } PeerClient::~PeerClient() @@ -131,12 +127,12 @@ { EXAM_CHECK_ASYNC( ev.value() == mess ); - cnd.set(true); + cnd.notify_one(); } -void PeerClient::wait() +bool PeerClient::wait() { - cnd.try_wait(); + return cnd.timed_wait( std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( PeerClient ) Modified: trunk/complement/explore/lib/stem/ut/Echo.h =================================================================== --- trunk/complement/explore/lib/stem/ut/Echo.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Echo.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:45:09 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 13:15:07 yeti> /* - * Copyright (c) 2006, 2007 + * Copyright (c) 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,7 @@ #define __Echo_h #include <string> -#include <mt/xmt.h> +#include <mt/condition_variable> #include <stem/EventHandler.h> // #include <stem/Names.h> // #include <list> @@ -28,7 +28,7 @@ void echo( const stem::Event& ); void regme( const stem::Event& ); - xmt::condition cnd; + std::tr2::condition_event cnd; private: DECLARE_RESPONSE_TABLE( StEMecho, stem::EventHandler ); @@ -45,12 +45,12 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); const std::string mess; private: - xmt::condition cnd; + std::tr2::condition_event cnd; DECLARE_RESPONSE_TABLE( EchoClient, stem::EventHandler ); }; @@ -67,12 +67,12 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); const std::string mess; private: - xmt::condition cnd; + std::tr2::condition_event cnd; DECLARE_RESPONSE_TABLE( PeerClient, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/Makefile =================================================================== --- trunk/complement/explore/lib/stem/ut/Makefile 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Makefile 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:25:10 ptr> +# -*- Makefile -*- Time-stamp: <08/06/30 11:54:35 yeti> SRCROOT := ../../.. @@ -16,25 +16,26 @@ LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBSTEM_DIR = ${CoMT_DIR}/lib/stem LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBMISC_DIR = ${CoMT_DIR}/lib/misc ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} - endif -release-shared : LDLIBS = -lxmt -lsockios -lstem -lexam -ldl -dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg -lexamg -ldl +release-shared : LDLIBS = -lxmt -lsockios -lstem -lexam -lmisc -ldl +dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg -lexamg -lmiscg -ldl ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lexamstlg -ldl +stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lexamstlg -lmiscstlg -ldl endif # dbg-shared: DEFS += -DDEBUG Modified: trunk/complement/explore/lib/stem/ut/NameService.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/NameService.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/NameService.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/11/29 10:50:21 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:47:39 yeti> /* - * Copyright (c) 2006, 2007 + * Copyright (c) 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -15,44 +15,43 @@ #include <stem/EDSEv.h> #include "NameService.h" +#include <mt/date_time> + using namespace std; using namespace stem; -using namespace xmt; +using namespace std::tr2; Naming::Naming() : EventHandler() { - cnd.set( false ); } Naming::Naming( stem::addr_type id ) : EventHandler( id ) { - cnd.set( false ); } Naming::~Naming() { - // cnd.wait(); } void Naming::names_list( const nsrecords_type& nr ) { copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); - cnd.set(true); + cnd.notify_one(); } void Naming::names_name( const nsrecords_type& nr ) { copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); - cnd.set(true); + cnd.notify_one(); } -void Naming::wait() +bool Naming::wait() { - cnd.try_wait(); + return cnd.timed_wait( std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( Naming ) Modified: trunk/complement/explore/lib/stem/ut/NameService.h =================================================================== --- trunk/complement/explore/lib/stem/ut/NameService.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/NameService.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:47:37 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:45:50 yeti> /* - * Copyright (c) 2006, 2007 + * Copyright (c) 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -11,7 +11,7 @@ #ifndef __NameService_h #define __NameService_h -#include <mt/xmt.h> +#include <mt/condition_variable> #include <stem/EventHandler.h> #include <stem/Names.h> #include <list> @@ -29,14 +29,14 @@ void names_list( const nsrecords_type& ); void names_name( const nsrecords_type& ); - void wait(); + bool wait(); void reset() - { cnd.set( false ); } + { cnd.reset(); } nsrecords_type::container_type lst; private: - xmt::condition cnd; + std::tr2::condition_event cnd; DECLARE_RESPONSE_TABLE( Naming, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/Node.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/Node.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Node.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <06/09/29 23:23:57 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:41:59 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -11,47 +11,47 @@ #include "Node.h" +#include <mt/date_time> + using namespace std; using namespace stem; -using namespace xmt; +using namespace std::tr2; Node::Node() : EventHandler(), v( 0 ) { - cnd.set( false ); } Node::Node( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } Node::Node( stem::addr_type id, const char *info ) : EventHandler( id, info ), v( 0 ) { - cnd.set( false ); } Node::~Node() { - // cnd.wait(); } void Node::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); // std::cerr << "I am here 1\n"; v = 1; - cnd.set(true); + cnd.notify_one(); // std::cerr << "I am here 2\n"; } -void Node::wait() +bool Node::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( Node ) @@ -64,32 +64,31 @@ EventHandler(), v( 0 ) { - cnd.set( false ); } NewNode::NewNode( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } NewNode::~NewNode() { - // cnd.wait(); } void NewNode::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); // std::cerr << "I am here 1\n"; v = 1; - cnd.set(true); + cnd.notify_one(); // std::cerr << "I am here 2\n"; } -void NewNode::wait() +bool NewNode::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( NewNode ) Modified: trunk/complement/explore/lib/stem/ut/Node.h =================================================================== --- trunk/complement/explore/lib/stem/ut/Node.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/Node.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:47:25 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:54:21 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,8 @@ #ifndef __Node_h #define __Node_h -#include <mt/xmt.h> +#include <mt/mutex> +#include <mt/condition_variable> #include <stem/EventHandler.h> class Node : @@ -26,12 +27,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( Node, stem::EventHandler ); }; @@ -47,12 +49,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( NewNode, stem::EventHandler ); }; Modified: trunk/complement/explore/lib/stem/ut/NodeDL.h =================================================================== --- trunk/complement/explore/lib/stem/ut/NodeDL.h 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/NodeDL.h 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <07/07/11 21:47:58 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:35:02 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,7 +12,8 @@ #ifndef __NodeDL_h #define __NodeDL_h -#include <mt/xmt.h> +#include <mt/mutex> +#include <mt/condition_variable> #include <stem/EventHandler.h> class NodeDL : @@ -25,12 +26,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( NodeDL, stem::EventHandler ); }; @@ -46,12 +48,13 @@ void handler1( const stem::Event& ); - void wait(); + bool wait(); int v; private: - xmt::condition cnd; + std::tr2::mutex m; + std::tr2::condition_variable cnd; DECLARE_RESPONSE_TABLE( NewNodeDL, stem::EventHandler ); }; @@ -59,7 +62,7 @@ #define NODE_EV2 0x901 extern "C" void *create_NewNodeDL( unsigned ); -extern "C" void wait_NewNodeDL( void * ); +extern "C" int wait_NewNodeDL( void * ); extern "C" int v_NewNodeDL( void * ); extern "C" void destroy_NewNodeDL( void * ); Modified: trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/dl/loadable_stem.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <06/09/29 22:53:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 18:36:09 yeti> /* * - * Copyright (c) 2002, 2003, 2006, 2007 + * Copyright (c) 2002, 2003, 2006-2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -12,19 +12,18 @@ #include "../NodeDL.h" using namespace stem; +using namespace std::tr2; NodeDL::NodeDL() : EventHandler(), v( 0 ) { - cnd.set( false ); } NodeDL::NodeDL( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } NodeDL::~NodeDL() @@ -33,13 +32,15 @@ void NodeDL::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); v = 1; - cnd.set(true); + cnd.notify_one(); } -void NodeDL::wait() +bool NodeDL::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( NodeDL ) @@ -52,14 +53,12 @@ EventHandler(), v( 0 ) { - cnd.set( false ); } NewNodeDL::NewNodeDL( stem::addr_type id ) : EventHandler( id ), v( 0 ) { - cnd.set( false ); } NewNodeDL::~NewNodeDL() @@ -68,13 +67,15 @@ void NewNodeDL::handler1( const stem::Event& ) { + lock_guard<mutex> lk( m ); v = 1; - cnd.set(true); + cnd.notify_one(); } -void NewNodeDL::wait() +bool NewNodeDL::wait() { - cnd.try_wait(); + unique_lock<mutex> lk( m ); + return cnd.timed_wait( lk, std::tr2::milliseconds( 500 ) ); } DEFINE_RESPONSE_TABLE( NewNodeDL ) @@ -86,9 +87,9 @@ return (void *)new NewNodeDL( a ); } -void wait_NewNodeDL( void *p ) +int wait_NewNodeDL( void *p ) { - reinterpret_cast<NewNodeDL *>( p )->wait(); + return reinterpret_cast<NewNodeDL *>( p )->wait() ? 1 : 0; } int v_NewNodeDL( void *p ) Modified: trunk/complement/explore/lib/stem/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/stem/ut/unit_test.cc 2008-07-01 14:41:10 UTC (rev 1934) +++ trunk/complement/explore/lib/stem/ut/unit_test.cc 2008-07-01 14:41:36 UTC (rev 1935) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 13:14:16 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 19:19:39 yeti> /* * Copyright (c) 2002, 2003, 2006-2008 @@ -41,6 +41,8 @@ #include <signal.h> +#include <misc/opts.h> + using namespace std; using namespace std::tr2; @@ -161,7 +163,7 @@ EXAM_REQUIRE( lh != NULL ); void *(*f)(unsigned); void (*g)(void *); - void (*w)(void *); + int (*w)(void *); int (*v)(void *); *(void **)(&f) = dlsym( lh, "create_NewNodeDL" ); @@ -178,7 +180,7 @@ ev.dest( 2002 ); node->Send( ev ); - w( reinterpret_cast<void *>(node) ); + EXAM_CHECK( w( reinterpret_cast<void *>(node) ) == 1 ); EXAM_CHECK( v(reinterpret_cast<void *>(node)) == 1 ); g( reinterpret_cast<void *>(node) ); @@ -289,7 +291,7 @@ node.Send( ev ); - node.wait(); + EXAM_CHECK( node.wait() ); mgr.close(); mgr.join(); @@ -305,8 +307,8 @@ const char fname[] = "/tmp/stem_test.shm"; xmt::shm_alloc<0> seg; -xmt::allocator_shm<xmt::__condition<true>,0> shm_cnd; -xmt::allocator_shm<xmt::__barrier<true>,0> shm_b; +xmt::allocator_shm<condition_event_ip,0> shm_cnd; +xmt::allocator_shm<barrier_ip,0> shm_b; stem_test::stem_test() { @@ -314,7 +316,16 @@ seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); } catch ( const xmt::shm_bad_alloc& err ) { - EXAM_ERROR_ASYNC( err.what() ); + try { + seg.allocate( fname, 4*4096, 0, 0600 ); + } + catch ( const xmt::shm_bad_alloc& err2 ) { + string s = err.what(); + s += "; "; + s += err2.what(); + EXAM_ERROR_ASYNC( s.c_str() ); + } + // EXAM_ERROR_ASYNC( err.what() ); } } @@ -326,18 +337,17 @@ int EXAM_IMPL(stem_test::echo_net) { - xmt::__condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - fcnd.set( false ); + condition_event_ip& fcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); try { - xmt::fork(); + std::tr2::this_thread::fork(); int eflag = 0; try { stem::NetTransportMgr mgr; - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); stem::addr_type zero = mgr.open( "localhost", 6995 ); @@ -353,7 +363,7 @@ node.Send( ev ); - node.wait(); + EXAM_CHECK_ASYNC_F( node.wait(), eflag ); mgr.close(); mgr.join(); @@ -363,13 +373,13 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { try { connect_processor<stem::NetTransport> srv( 6995 ); StEMecho echo( 0, "echo service"); // <= zero! - fcnd.set( true ); + fcnd.notify_one(); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -386,7 +396,7 @@ } } - (&fcnd)->~__condition<true>(); + (&fcnd)->~condition_event_ip(); shm_cnd.deallocate( &fcnd, 1 ); // cerr << "Fine\n"; @@ -399,13 +409,11 @@ int EXAM_IMPL(stem_test::net_echo) { try { - xmt::__barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__barrier<true>(); - xmt::__condition<true>& c = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); + barrier_ip& b = *new ( shm_b.allocate( 1 ) ) barrier_ip(); + condition_event_ip& c = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); - c.set( false ); - try { - xmt::fork(); + std::tr2::this_thread::fork(); int eflag = 0; // server part @@ -417,7 +425,7 @@ // echo.manager()->settrs( &std::cerr ); EXAM_CHECK_ASYNC_F( srv.good(), eflag ); - c.set( true ); // ok, server listen + c.notify_one(); // ok, server listen b.wait(); // server may go away @@ -427,14 +435,14 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { // client part stem::NetTransportMgr mgr; // mgr.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch | stem::EvManager::tracefault ); // mgr.manager()->settrs( &std::cerr ); - c.try_wait(); // wait server start + EXAM_CHECK( c.timed_wait( std::tr2::milliseconds( 800 ) ) ); // wait server start stem::addr_type zero = mgr.open( "localhost", 6995 ); @@ -448,7 +456,7 @@ ev.value() = node.mess; node.Send( ev ); - node.wait(); + EXAM_CHECK( node.wait() ); mgr.close(); mgr.join(); @@ -464,9 +472,9 @@ } } - (&c)->~__condition<true>(); + (&c)->~condition_event_ip(); shm_cnd.deallocate( &c, 1 ); - (&b)->~__barrier<true>(); + (&b)->~barrier_ip(); shm_b.deallocate( &b, 1 ); } catch ( xmt::shm_bad_alloc& err ) { @@ -504,18 +512,13 @@ pid_t fpid; - xmt::__condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - fcnd.set( false ); + condition_event_ip& fcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); + condition_event_ip& pcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); + condition_event_ip& scnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); - xmt::__condition<true>& pcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - pcnd.set( false ); - - xmt::__condition<true>& scnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - scnd.set( false ); - try { // Client 1 - xmt::fork(); + std::tr2::this_thread::fork(); #if 0 struct sigaction action; struct sigaction old_action; @@ -539,7 +542,7 @@ PeerClient c1( "c1 local" ); // c1 client Naming nm; - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server // It done like it should on client side @@ -568,7 +571,7 @@ evname.dest( c1.manager()->reflect( ga ) ); evname.value() = "c2@here"; - pcnd.try_wait(); + EXAM_CHECK_ASYNC_F( pcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); Naming::nsrecords_type::const_iterator i; @@ -602,7 +605,7 @@ c1.Send( pe ); } - scnd.try_wait(); + EXAM_CHECK_ASYNC_F( scnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); mgr.close(); mgr.join(); @@ -613,13 +616,13 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { fpid = child.pid(); } try { // Client 2 - xmt::fork(); + std::tr2::this_thread::fork(); #if 0 struct sigaction action; @@ -643,7 +646,7 @@ // ^ PeerClient c2( "c2 local" ); // <<--- name the same as mess expected ... | - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server // It done like it should on client side @@ -657,11 +660,11 @@ ev.value() = "c2@here"; c2.Send( ev ); // 'register' c2 client on 'echo' server - pcnd.set( true ); + pcnd.notify_one(); c2.wait(); // cerr << "Fine!" << endl; - scnd.set( true ); + scnd.notify_one(); mgr.close(); mgr.join(); @@ -672,11 +675,11 @@ exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { connect_processor<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) - fcnd.set( true, true ); + fcnd.notify_all(); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -697,11 +700,11 @@ srv.wait(); } - (&fcnd)->~__condition<true>(); + (&fcnd)->~condition_event_ip(); shm_cnd.deallocate( &fcnd, 1 ); - (&pcnd)->~__condition<true>(); + (&pcnd)->~condition_event_ip(); shm_cnd.deallocate( &pcnd, 1 ); - (&scnd)->~__condition<true>(); + (&scnd)->~condition_event_ip(); shm_cnd.deallocate( &scnd, 1 ); return EXAM_RESULT; @@ -709,17 +712,16 @@ int EXAM_IMPL(stem_test::boring_manager) { - xmt::__condition<true>& fcnd = *new ( shm_cnd.allocate( 1 ) ) xmt::__condition<true>(); - fcnd.set( false ); + condition_event_ip& fcnd = *new ( shm_cnd.allocate( 1 ) ) condition_event_ip(); try { // Client - xmt::fork(); + std::tr2::this_thread::fork(); int eflag = 0; try { - fcnd.try_wait(); + EXAM_CHECK_ASYNC_F( fcnd.timed_wait( std::tr2::milliseconds( 800 ) ), eflag ); for ( int i = 0; i < 10; ++i ) { const int n = 10; @@ -745,11 +747,11 @@ } exit( eflag ); } - catch ( xmt::fork_in_parent& child ) { + catch ( std::tr2::fork_in_parent& child ) { connect_processor<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) - fcnd.set( true, true ); + fcnd.notify_all(); int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -763,7 +765,7 @@ srv.wait(); } - (&fcnd)->~__condition<true>(); + (&fcnd)->~condition_event_ip(); shm_cnd.deallocate( &fcnd, 1 ); return EXAM_RESULT; @@ -784,10 +786,11 @@ conv.Send( ev ); - conv.wait(); - + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == -1 ); + conv.v = 0; + stem::Event_base<mess> ev1( CONV_EV1 ); ev1.dest( conv.self_id() ); @@ -795,10 +798,11 @@ conv.Send( ev1 ); - conv.wait(); - + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == 1 ); + conv.v = 0; + stem::Event_base<mess> ev2( CONV_EV2 ); ev2.dest( conv.self_id() ); @@ -806,11 +810,13 @@ conv.Send( ev2 ); - conv.wait(); + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == 2 ); EXAM_CHECK( conv.m2 == "hello" ); + conv.v = 0; + stem::Event_base<mess> ev3( CONV_EV3 ); ev3.dest( conv.self_id() ); @@ -819,21 +825,17 @@ conv.Send( ev3 ); - conv.wait(); + EXAM_CHECK( conv.wait() ); EXAM_CHECK( conv.v == 3 ); EXAM_CHECK( conv.m3 == ", wold!" ); + conv.v = 0; + return EXAM_RESULT; } -// ----------------- - -// ----------------- - -int EXAM_DECL(stem_test_suite); - -int EXAM_IMPL(stem_test_suite) +int main( int argc, const char** argv ) { exam::test_suite::test_case_type tc[4]; @@ -858,10 +860,52 @@ t.add( &stem_test::convert, test, "convert", tc[0] ); + Opts opts; + + opts.description( "test suite for 'StEM' framework" ); + opts.usage( "[options]" ); + + opts << option<bool>( "print this help message", 'h', "help" ) + << option<bool>( "list all test cases", 'l', "list" ) + << option<string>( "run tests by number", 'r', "run" )["0"] + << option<bool>( "print status of tests within test suite", 'v', "verbose" ) + << option<bool>( "trace checks", 't', "trace" ); + + try { + opts.parse( argc, argv ); + } + catch (...) { + opts.help( cerr ); + return 1; + } + + if ( opts.is_set( 'h' ) ) { + opts.help( cerr ); + return 0; + } + + if ( opts.is_set( 'l' ) ) { + t.print_graph( cerr ); + return 0; + } + + if ( opts.is_set( 'v' ) ) { + t.flags( t.flags() | exam::base_logger::verbose ); + } + + if ( opts.is_set( 't' ) ) { + t.flags( t.flags() | exam::base_logger::trace ); + } + + if ( opts.is_set( 'r' ) ) { + stringstream ss( opts.get<string>( 'r' ) ); + int n; + while ( ss >> n ) { + t.single( n ); + } + + return 0; + } + return t.girdle(); } - -int main( int, char ** ) -{ - return stem_test_suite(0); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-02 05:36:23
|
Revision: 1938 http://complement.svn.sourceforge.net/complement/?rev=1938&view=rev Author: complement Date: 2008-07-01 22:36:21 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Conflicts: complement/explore/include/sockios/sockmgr.cc complement/explore/lib/stem/NetTransport.cc Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/sockios/sockstream.cc trunk/complement/explore/lib/sockios/ut/Makefile trunk/complement/explore/lib/sockios/ut/Makefile.inc trunk/complement/explore/lib/sockios/ut/sockios2_test.cc trunk/complement/explore/lib/sockios/ut/sockios2_test.h trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/01 10:16:39 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 14:40:03 yeti> /* * Copyright (c) 2008 @@ -407,13 +407,19 @@ } if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; - if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { - // throw system_error - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; - } if ( info.p != 0 ) { + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; + } + { + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); + b->close(); + b->ucnd.notify_all(); + } // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; @@ -434,7 +440,9 @@ std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; } descr.erase( ifd ); + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); b->close(); + b->ucnd.notify_all(); } // dump_descr(); } Modified: trunk/complement/explore/include/sockios/sockstream =================================================================== --- trunk/complement/explore/include/sockios/sockstream 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockstream 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 00:51:30 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 14:46:29 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -480,7 +480,7 @@ protected: virtual streamsize showmanyc() - { return this->egptr() - this->gptr(); } + { return basic_socket_t::_fd != -1 ? this->egptr() - this->gptr() : -1; } virtual int_type underflow(); virtual int_type overflow( int_type c = traits::eof() ); @@ -568,7 +568,7 @@ b( self ) { } bool operator ()() const - { return b.showmanyc() != 0; } + { return b.showmanyc() > 0; } private: sockbuf_type& b; } rdready; Modified: trunk/complement/explore/include/sockios/sockstream.cc =================================================================== --- trunk/complement/explore/include/sockios/sockstream.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockstream.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 08:40:03 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 13:30:58 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -307,8 +307,9 @@ std::tr2::unique_lock<std::tr2::mutex> lk( ulck ); - if ( this->gptr() < this->egptr() ) + if ( this->gptr() < this->egptr() ) { return traits::to_int_type(*this->gptr()); + } if ( this->egptr() == this->gptr() ) { // fullfilled: _ebuf == gptr() setg( this->eback(), this->eback(), this->eback() ); @@ -317,12 +318,14 @@ // setg( this->eback(), this->eback(), this->eback() + offset ); // wait on condition if ( basic_socket_t::_use_rdtimeout ) { - ucnd.timed_wait( lk, basic_socket_t::_rdtimeout, rdready ); + if ( !ucnd.timed_wait( lk, basic_socket_t::_rdtimeout, rdready ) ) { + return traits::eof(); + } } else { ucnd.wait( lk, rdready ); } - - return traits::to_int_type(*this->gptr()); + + return this->gptr() < this->egptr() ? traits::to_int_type(*this->gptr()) : traits::eof(); } template<class charT, class traits, class _Alloc> Modified: trunk/complement/explore/lib/sockios/ut/Makefile =================================================================== --- trunk/complement/explore/lib/sockios/ut/Makefile 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/Makefile 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:24:26 ptr> +# -*- Makefile -*- Time-stamp: <08/07/01 12:27:54 yeti> SRCROOT := ../../.. @@ -15,18 +15,24 @@ LIBMT_DIR = ${CoMT_DIR}/lib/mt LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBEXAM_DIR = ${CoMT_DIR}/lib/exam -# LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +LIBMISC_DIR = ${CoMT_DIR}/lib/misc ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + endif -release-shared : LDLIBS = -lxmt -lsockios -lexam +release-shared : LDLIBS = -lxmt -lsockios -lexam -lmisc + +dbg-shared : LDLIBS = -lxmtg -lsockiosg -lexamg -lmiscg + ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lexamstlg +stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lexamstlg -lmiscstlg endif -dbg-shared : LDLIBS = -lxmtg -lsockiosg -lexamg Modified: trunk/complement/explore/lib/sockios/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/ut/Makefile.inc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/Makefile.inc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,5 +1,5 @@ -# -*- makefile -*- Time-stamp: <08/06/09 20:31:17 yeti> +# -*- makefile -*- Time-stamp: <08/07/01 12:22:34 yeti> PRGNAME = sockios_ut SRC_CC = message.cc \ - names.cc sockios_test.cc sockios2_test.cc sockios_test_suite.cc unit_test.cc + names.cc sockios_test.cc sockios2_test.cc sockios_test_suite.cc Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 21:29:52 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 15:28:50 yeti> /* * @@ -464,6 +464,96 @@ return EXAM_RESULT; } +class srv_reader +{ + public: + srv_reader( sockstream& ) + { } + ~srv_reader() + { } + void connect( sockstream& s ) + { + char buf[64]; + + while ( s.read( buf, 4 ).good() ) { + continue; + } + + cnd.notify_one(); + } + + static std::tr2::condition_event cnd; +}; + +std::tr2::condition_event srv_reader::cnd; + +int EXAM_IMPL(sockios2_test::disconnect) +{ + const char fname[] = "/tmp/sockios2_test.shm"; + xmt::shm_alloc<0> seg; + + try { + seg.allocate( fname, 4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + } + catch ( xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + try { + seg.allocate( fname, 4096, 0, 0660 ); + } + catch ( xmt::shm_bad_alloc& err2 ) { + EXAM_ERROR( err.what() ); + return EXAM_RESULT; + } + } + + xmt::allocator_shm<barrier_ip,0> shm; + barrier_ip& b = *new ( shm.allocate( 1 ) ) barrier_ip(); + + try { + this_thread::fork(); + + connect_processor<srv_reader> prss( 2008 ); + + EXAM_CHECK_ASYNC( prss.good() ); + + b.wait(); + + if ( srv_reader::cnd.timed_wait( milliseconds( 800 ) ) ) { + exit( 0 ); + } + // srv_reader::cnd.wait(); + + exit( 1 ); + } + catch ( std::tr2::fork_in_parent& child ) { + b.wait(); + + sockstream s( "localhost", 2008 ); + + char buf[] = "1234"; + + EXAM_CHECK( s.write( buf, 4 ).flush().good() ); + + s.rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); + + // s.close(); + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child fail" ); + } + } + + shm.deallocate( &b ); + seg.deallocate(); + unlink( fname ); + + return EXAM_RESULT; +} + int EXAM_IMPL(sockios2_test::fork) { const char fname[] = "/tmp/sockios2_test.shm"; Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.h =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 00:55:32 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 12:21:46 yeti> /* * @@ -22,6 +22,7 @@ int EXAM_DECL(srv_core); int EXAM_DECL(connect_disconnect); + int EXAM_DECL(disconnect); int EXAM_DECL(processor_core); int EXAM_DECL(fork); int EXAM_DECL(srv_sigpipe); Modified: trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:55:26 yeti> +// -*- C++ -*- Time-stamp: <08/07/01 12:57:40 yeti> /* * @@ -9,7 +9,6 @@ * */ -#include "sockios_test_suite.h" #include "sockios_test.h" #include "sockios2_test.h" @@ -17,7 +16,7 @@ #include <iostream> #include <list> -#include <mt/xmt.h> +#include <misc/opts.h> // #include <sockios/sockstream> // #include <sockios/sockmgr.h> @@ -31,14 +30,12 @@ int EXAM_DECL(test_more_bytes_in_socket); int EXAM_DECL(test_more_bytes_in_socket2); -int EXAM_IMPL(sockios_test_suite) +int main( int argc, const char** argv ) { - exam::test_suite::test_case_type tc[3]; + exam::test_suite::test_case_type tc[4]; exam::test_suite t( "libsockios test" ); - t.flags( t.flags() | exam::base_logger::trace | exam::base_logger::verbose ); - #if 0 trivial_sockios_test trivial_test; @@ -83,10 +80,59 @@ t.add( &sockios2_test::read0, test2, "sockios2_test::read0", t.add( &sockios2_test::srv_sigpipe, test2, "sockios2_test::srv_sigpipe", t.add( &sockios2_test::fork, test2, "sockios2_test::fork", - t.add( &sockios2_test::processor_core, test2, "sockios2_test::processor_core", + tc[3] = t.add( &sockios2_test::processor_core, test2, "sockios2_test::processor_core", t.add( &sockios2_test::connect_disconnect, test2, "sockios2_test::connect_disconnect", t.add( &sockios2_test::srv_core, test2, "sockios2_test::srv_core" ) ) ) ) ) ); + t.add( &sockios2_test::disconnect, test2, "sockios2_test::disconnect", tc[3] ); + + Opts opts; + + opts.description( "test suite for 'sockios' framework" ); + opts.usage( "[options]" ); + + opts << option<bool>( "print this help message", 'h', "help" ) + << option<bool>( "list all test cases", 'l', "list" ) + << option<string>( "run tests by number", 'r', "run" )["0"] + << option<bool>( "print status of tests within test suite", 'v', "verbose" ) + << option<bool>( "trace checks", 't', "trace" ); + + try { + opts.parse( argc, argv ); + } + catch (...) { + opts.help( cerr ); + return 1; + } + + if ( opts.is_set( 'h' ) ) { + opts.help( cerr ); + return 0; + } + + if ( opts.is_set( 'l' ) ) { + t.print_graph( cerr ); + return 0; + } + + if ( opts.is_set( 'v' ) ) { + t.flags( t.flags() | exam::base_logger::verbose ); + } + + if ( opts.is_set( 't' ) ) { + t.flags( t.flags() | exam::base_logger::trace ); + } + + if ( opts.is_set( 'r' ) ) { + stringstream ss( opts.get<string>( 'r' ) ); + int n; + while ( ss >> n ) { + t.single( n ); + } + + return 0; + } + return t.girdle(); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -105,8 +105,6 @@ uint32_t buf[bsz]; using namespace std; - MT_IO_REENTRANT( *net ) - if ( !net->read( (char *)buf, sizeof(uint32_t) ).good() ) { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-02 11:01:21
|
Revision: 1942 http://complement.svn.sourceforge.net/complement/?rev=1942&view=rev Author: complement Date: 2008-07-02 04:01:18 -0700 (Wed, 02 Jul 2008) Log Message: ----------- fix uuid generation /proc/sys/kernel/random/uuid should be reopen for next read; if not, next read will return 0 (not eveident!). All uid-generated functions throw runtime_exception if detect problem. Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/uid.cc trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2008-07-02 09:39:31 UTC (rev 1941) +++ trunk/complement/explore/include/mt/uid.h 2008-07-02 11:01:18 UTC (rev 1942) @@ -1,7 +1,7 @@ // -*- C++ -*- Time-stamp: <08/06/06 21:21:30 yeti> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -18,6 +18,7 @@ #include <string> // #include <algorithm> #include <stdint.h> +#include <stdexcept> namespace xmt { @@ -62,11 +63,11 @@ } }; -const char *hostid_str(); -const xmt::uuid_type& hostid(); +const char *hostid_str() throw (std::runtime_error); +const xmt::uuid_type& hostid() throw (std::runtime_error); -std::string uid_str(); -xmt::uuid_type uid(); +std::string uid_str() throw (std::runtime_error); +xmt::uuid_type uid() throw (std::runtime_error); } // namespace xmt Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-02 09:39:31 UTC (rev 1941) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-02 11:01:18 UTC (rev 1942) @@ -15,7 +15,10 @@ #include <cstring> #include <unistd.h> #include <fcntl.h> +#include <stdexcept> +#include <iostream> + namespace xmt { namespace detail { @@ -24,98 +27,95 @@ using namespace xmt; using namespace std::tr2; -class __uid_init +struct __uid_init { - public: __uid_init(); static uuid_type _host_id; char _host_id_str[48]; // 37 really + bool fail; }; uuid_type __uid_init::_host_id; -struct __uuid_init +__uid_init::__uid_init() : + fail( false ) { - public: - __uuid_init(); - ~__uuid_init(); - - int fd; -}; - -__uid_init::__uid_init() -{ int fd = ::open( "/proc/sys/kernel/random/boot_id", O_RDONLY ); - ::read( fd, _host_id_str, 36 ); - _host_id_str[36] = '\0'; - ::close( fd ); + if ( (fd < 0) || (::read( fd, _host_id_str, 36 ) != 36 )) { + if ( fd >= 0 ) { + ::close( fd ); + } + fail = true; + } else { + _host_id_str[36] = '\0'; + ::close( fd ); - stringstream s; - s << _host_id_str[0] << _host_id_str[1] << ' ' - << _host_id_str[2] << _host_id_str[3] << ' ' - << _host_id_str[4] << _host_id_str[5] << ' ' - << _host_id_str[6] << _host_id_str[7] << ' ' // - - << _host_id_str[9] << _host_id_str[10] << ' ' - << _host_id_str[11] << _host_id_str[12] << ' ' // - - << _host_id_str[14] << _host_id_str[15] << ' ' - << _host_id_str[16] << _host_id_str[17] << ' ' // - - << _host_id_str[19] << _host_id_str[20] << ' ' - << _host_id_str[21] << _host_id_str[22] << ' ' // - - << _host_id_str[24] << _host_id_str[25] << ' ' - << _host_id_str[26] << _host_id_str[27] << ' ' - << _host_id_str[28] << _host_id_str[29] << ' ' - << _host_id_str[30] << _host_id_str[31] << ' ' - << _host_id_str[32] << _host_id_str[33] << ' ' - << _host_id_str[34] << _host_id_str[35]; + stringstream s; + s << _host_id_str[0] << _host_id_str[1] << ' ' + << _host_id_str[2] << _host_id_str[3] << ' ' + << _host_id_str[4] << _host_id_str[5] << ' ' + << _host_id_str[6] << _host_id_str[7] << ' ' // - + << _host_id_str[9] << _host_id_str[10] << ' ' + << _host_id_str[11] << _host_id_str[12] << ' ' // - + << _host_id_str[14] << _host_id_str[15] << ' ' + << _host_id_str[16] << _host_id_str[17] << ' ' // - + << _host_id_str[19] << _host_id_str[20] << ' ' + << _host_id_str[21] << _host_id_str[22] << ' ' // - + << _host_id_str[24] << _host_id_str[25] << ' ' + << _host_id_str[26] << _host_id_str[27] << ' ' + << _host_id_str[28] << _host_id_str[29] << ' ' + << _host_id_str[30] << _host_id_str[31] << ' ' + << _host_id_str[32] << _host_id_str[33] << ' ' + << _host_id_str[34] << _host_id_str[35]; - s >> hex - >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] - >> _host_id.u.b[4] >> _host_id.u.b[5] >> _host_id.u.b[6] >> _host_id.u.b[7] - >> _host_id.u.b[8] >> _host_id.u.b[9] >> _host_id.u.b[10] >> _host_id.u.b[11] - >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; + s >> hex + >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] + >> _host_id.u.b[4] >> _host_id.u.b[5] >> _host_id.u.b[6] >> _host_id.u.b[7] + >> _host_id.u.b[8] >> _host_id.u.b[9] >> _host_id.u.b[10] >> _host_id.u.b[11] + >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; + } } -__uuid_init::__uuid_init() -{ - fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); -} - -__uuid_init::~__uuid_init() -{ - ::close( fd ); -} - } // namespace detail using namespace std; using namespace std::tr2; -const char *hostid_str() +const char *hostid_str() throw (runtime_error) { static detail::__uid_init _uid; + if ( _uid.fail ) { + throw runtime_error( "can't read hostid" ); + } return _uid._host_id_str; } -const xmt::uuid_type& hostid() +const xmt::uuid_type& hostid() throw (runtime_error) { hostid_str(); return detail::__uid_init::_host_id; } -std::string uid_str() +std::string uid_str() throw (runtime_error) { - static detail::__uuid_init __uuid; + char buf[37]; - char buf[36]; + int fd = ::open( "/proc/sys/kernel/random/uuid", O_RDONLY ); + if ( (fd < 0) || (::read( fd, buf, 37 ) != 37) ) { + if ( fd >= 0 ) { + ::close( fd ); + } + throw runtime_error( "Can't generate UID" ); + // return std::string(); + } + ::close( fd ); - ::read( __uuid.fd, buf, 36 ); - return std::string( buf, 36 ); } -xmt::uuid_type uid() +xmt::uuid_type uid() throw (runtime_error) { string tmp = uid_str(); uuid_type id; Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 09:39:31 UTC (rev 1941) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-02 11:01:18 UTC (rev 1942) @@ -334,6 +334,18 @@ EXAM_CHECK( u1 != u2 ); + for ( int i = 0; i < 100; ++i ) { + std::string s = xmt::uid_str(); + + EXAM_REQUIRE( s.length() == 36 ); + EXAM_REQUIRE( s[8] == '-' ); + EXAM_REQUIRE( s[13] == '-' ); + EXAM_REQUIRE( s[18] == '-' ); + EXAM_REQUIRE( s[23] == '-' ); + + EXAM_REQUIRE( s.find_first_not_of( "0123456789abcdef-" ) == std::string::npos ); + } + return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-07 06:39:36
|
Revision: 1943 http://complement.svn.sourceforge.net/complement/?rev=1943&view=rev Author: complement Date: 2008-07-06 23:39:32 -0700 (Sun, 06 Jul 2008) Log Message: ----------- convert uid to string; output uid to ostream; libxmt 2.0.6 Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/include/mt/uid.h 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/06 21:21:30 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 01:13:55 ptr> /* * Copyright (c) 2006, 2008 @@ -19,6 +19,7 @@ // #include <algorithm> #include <stdint.h> #include <stdexcept> +#include <ostream> namespace xmt { @@ -61,6 +62,8 @@ // return std::lexicographical_compare( u.i, u.i + 4, uid.u.i, uid.u.i + 4 ); return u.l[0] < uid.u.l[0] ? true : u.l[0] > uid.u.l[0] ? false : (u.l[1] < uid.u.l[1]); } + + operator std::string() const; }; const char *hostid_str() throw (std::runtime_error); @@ -71,4 +74,10 @@ } // namespace xmt +namespace std { + +std::ostream& operator <<( std::ostream&, const xmt::uuid_type& ); + +} // namespace std + #endif // __mt_uid_h Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,3 +1,10 @@ +2008-07-07 Petr Ovtchenkov <pt...@is...> + + * uid.cc, uid.h: convert uid to string; output uid + to ostream; + + * libxmt: bump revision to 2.0.6. + 2008-07-02 Petr Ovtchenkov <pt...@is...> * uid.cc: fix wrong type cast; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/07/02 09:28:02 ptr> +# -*- Makefile -*- Time-stamp: <08/07/07 10:35:20 ptr> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 5 +PATCH = 6 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-07-02 11:01:18 UTC (rev 1942) +++ trunk/complement/explore/lib/mt/uid.cc 2008-07-07 06:39:32 UTC (rev 1943) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/02 13:15:01 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 04:14:12 ptr> /* * Copyright (c) 2006, 2008 @@ -19,6 +19,26 @@ #include <iostream> +namespace std { + +std::ostream& operator <<( std::ostream& s, const xmt::uuid_type& uid ) +{ + std::ios_base::fmtflags f = s.flags( 0 ); + s << hex << setfill('0') + << setw(2) << uid.u.b[0] << setw(2) << uid.u.b[1] << setw(2) << uid.u.b[2] << setw(2) << uid.u.b[3] << '-' + << setw(2) << uid.u.b[4] << setw(2) << uid.u.b[5] << '-' + << setw(2) << uid.u.b[6] << setw(2) << uid.u.b[7] << '-' + << setw(2) << uid.u.b[8] << setw(2) << uid.u.b[9] << '-' + << setw(2) << uid.u.b[10] << setw(2) << uid.u.b[11] + << setw(2) << uid.u.b[12] << setw(2) << uid.u.b[13] + << setw(2) << uid.u.b[14] << setw(2) << uid.u.b[15]; + s.flags( f ); + + return s; +} + +} // namespace std + namespace xmt { namespace detail { @@ -83,6 +103,15 @@ using namespace std; using namespace std::tr2; +uuid_type::operator string() const +{ + ostringstream s; + + s << *this; + + return s.str(); +} + const char *hostid_str() throw (runtime_error) { static detail::__uid_init _uid; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-07-07 17:27:26
|
Revision: 1945 http://complement.svn.sourceforge.net/complement/?rev=1945&view=rev Author: complement Date: 2008-07-07 10:26:37 -0700 (Mon, 07 Jul 2008) Log Message: ----------- fix dispatch loop finish condition; libstem 4.8.1 (for git-svn) pass predicate to wait condition in dispatch loop; predicate check as non-empty income events queue, as flag for _dispatch_stop flag; spinlock, that cover only _dispatch_stop removed. Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/include/stem/EvManager.h 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 12:35:36 ptr> +// -*- C++ -*- Time-stamp: <08/07/07 21:03:34 yeti> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -266,6 +266,19 @@ } private: + struct _not_empty + { + _not_empty( EvManager& m ) : + me( m ) + { } + + bool operator()() const + { return !me.in_ev_queue.empty() || me._dispatch_stop; } + + EvManager& me; + } not_empty; + + void Send( const Event& e ); __FIT_DECLSPEC void unsafe_Remove( void * ); @@ -308,7 +321,6 @@ unsigned _trflags; std::ostream *_trs; - std::tr2::spinlock _ev_queue_dispatch_guard; std::tr2::thread _ev_queue_thr; friend class Names; Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/lib/stem/ChangeLog 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,3 +1,10 @@ +2008-07-07 Petr Ovtchenkov <ye...@ya...> + + * EvManager.h, EvManager.cc: fix dispatch loop finish + condition; + + * libstem: library version 4.8.1. + 2008-06-27 Petr Ovtchenkov <pt...@is...> * Cron.h, EvManager.h, EventHandler.h, NetTransport.h: Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/lib/stem/EvManager.cc 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 18:18:21 yeti> +// -*- C++ -*- Time-stamp: <08/07/07 21:01:28 yeti> /* * @@ -44,6 +44,7 @@ std::string EvManager::inv_key_str( "invalid key" ); __FIT_DECLSPEC EvManager::EvManager() : + not_empty( *this ), _low( beglocaddr ), _high( endlocaddr ), _id( _low ), @@ -62,7 +63,7 @@ __FIT_DECLSPEC EvManager::~EvManager() { { - lock_guard<spinlock> lk( _ev_queue_dispatch_guard ); + lock_guard<mutex> lk( _lock_queue ); _dispatch_stop = true; _cnd_queue.notify_one(); } @@ -72,7 +73,7 @@ bool EvManager::not_finished() { - lock_guard<spinlock> lk( _ev_queue_dispatch_guard ); + lock_guard<mutex> lk( _lock_queue ); return !_dispatch_stop; } @@ -94,9 +95,7 @@ } { unique_lock<mutex> lk( lq ); - if ( in_ev_queue.empty() && me.not_finished() ) { - me._cnd_queue.wait( lk ); - } + me._cnd_queue.wait( lk, me.not_empty ); } } } Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2008-07-07 10:30:59 UTC (rev 1944) +++ trunk/complement/explore/lib/stem/Makefile.inc 2008-07-07 17:26:37 UTC (rev 1945) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <08/06/27 13:16:59 ptr> +# -*- Makefile -*- Time-stamp: <08/07/07 21:07:49 yeti> LIBNAME = stem MAJOR = 4 MINOR = 8 -PATCH = 0 +PATCH = 1 SRC_CC = _EventHandler.cc NetTransport.cc EvManager.cc EvPack.cc crc.cc \ Names.cc Cron.cc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |