[complement-svn] SF.net SVN: complement: [1427] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-11-30 19:54:49
|
Revision: 1427 http://svn.sourceforge.net/complement/?rev=1427&view=rev Author: complement Date: 2006-11-30 11:54:45 -0800 (Thu, 30 Nov 2006) Log Message: ----------- * Event.h: code clean; change specialization of Event_base to avoid wrong code or bogus workarounds if whole class specialization happens; * EventSpec.h: removed, due to reasons above; * Event.h, EventHandler.h: add _flags member to event, in particular to detect errors during conversions and network conversions; * NetTransport.cc: pass _flags; taken unused field for this; * _SessionMgr.cc, _EvSession.cc: removed; * SessionMgr.h, EvSession.h: ditto. * EventHandler.h: add classname() function, allow find real name of class in the _Dispatch [well, the name of last class with DECLARE_RESPONSE_TABLE]; very useful for debug; * EvManager.h, EvManager.cc, NetTransport.cc: add possibility to trace events in EvManager; library version 4.3.0 Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/Event.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Removed Paths: ------------- trunk/complement/explore/include/stem/EvSession.h trunk/complement/explore/include/stem/EventSpec.h trunk/complement/explore/include/stem/SessionMgr.h trunk/complement/explore/lib/stem/_EvSession.cc trunk/complement/explore/lib/stem/_SessionMgr.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 02:52:45 ptr> +// -*- C++ -*- Time-stamp: <06/11/30 22:33:25 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -93,7 +93,8 @@ enum traceflags { notrace = 0, tracenet = 1, - tracedispatch = 2 + tracedispatch = 2, + tracefault = 4 }; typedef std::queue< Event > queue_type; @@ -162,8 +163,14 @@ __FIT_DECLSPEC void Remove( void * ); __FIT_DECLSPEC std::ostream& dump( std::ostream& ) const; - + static void settrf( unsigned f ); + static void unsettrf( unsigned f ); + static void resettrf( unsigned f ); + static void cleantrf(); + static unsigned trflags(); + static void settrs( std::ostream * ); + protected: bool unsafe_is_avail( addr_type id ) const { @@ -251,8 +258,12 @@ xmt::Condition _cnd_queue; static std::string inv_key_str; + static xmt::Mutex _lock_tr; + static unsigned _trflags; + static std::ostream *_trs; friend class Names; + friend class NetTransportMgr; }; } // namespace stem Deleted: trunk/complement/explore/include/stem/EvSession.h =================================================================== --- trunk/complement/explore/include/stem/EvSession.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EvSession.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,370 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/07/20 10:32:22 ptr> - -/* - * - * Copyright (c) 1997-1999, 2002, 2003, 2005 - * Petr Ovtchenkov - * - * Copyright (c) 1999-2001 - * ParallelGraphics Ltd. - * - * Licensed under the Academic Free License version 2.1 - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - */ - -#ifndef __stem_EvSession_h -#define __stem_EvSession_h - -#ifndef __config_feature_h -#include <config/feature.h> -#endif - -#include <string> -#include <ctime> - -#ifndef __SOCKSTREAM__ -#include <sockios/sockstream> -#endif - -#include <map> - -#ifndef __XMT_H -#include <mt/xmt.h> -#endif - -#ifndef __Event_h -#include <stem/Event.h> -#endif - -namespace stem { - -#if defined(__SUNPRO_CC) && defined(__STL_USE_NEW_C_HEADERS) -using std::time; -#endif - -struct SessionInfo -{ - SessionInfo() : -// _start( 0 ), -// _last( 0 ), -// _conn( 0 ), - _on_line( 0 ), - _sz_from( 0 ), - _sz_to( 0 ), - _un_from( 0 ), - _un_to( 0 ), - _lun_from( 0 ), - _lun_to( 0 ), - _reconnect_cnt( 0 ), - _control( badaddr ) -// _is_connected( true ) - { - _start = connect(); - // _start = time( &_last ); - // _conn = _last; - } - -#ifndef WIN32 - __FIT_DECLSPEC SessionInfo( const SessionInfo& ); -#else - SessionInfo( const SessionInfo& si ) - { - _host = si._host; - _port = si._port; - - _sz_from = si._sz_from; - _un_from = si._un_from; - _sz_to = si._sz_to; - _un_to = si._un_to; - _lun_from = si._lun_from; - _lun_to = si._lun_to; - _start = si._start; - _on_line = si._on_line; - _conn = si._conn; - _last = si._last; - _reconnect_cnt = si._reconnect_cnt; - _is_connected = si._is_connected; - - _control = si._control; - } -#endif - - -// ConnectSession( sockstream *s ) -// { connect( s ); } - - ~SessionInfo() - { } - - // key_type key; - - // key_type ? secret_key; - - // machine identification: - -// union { -// sockaddr_in inet; -// sockaddr any; -// } _address; - - std::string _host; // name + ip +? port? - int _port; // ? - - // sockstream *_sock; // ? - - // protocols stack: -// sock_base::stype _proto_low; // TCP, UDP, etc -// sock_base::protocol _proto_domain; // inet/local - // ????? proto_high; // row, over HTTP, etc. - - // billing info - size_t _sz_from; // bytes transfer from - size_t _un_from; // transfer units (say, events) from - size_t _sz_to; // bytes transfer to - size_t _un_to; // transfer units (say, events) to - unsigned _lun_from; // last unit number had received - unsigned _lun_to; // last unit number sended; - time_t _start; // session start time - time_t _on_line; // time on line. - time_t _conn; // last time of connect - time_t _last; // last access time - unsigned _reconnect_cnt; // reconnection counter - bool _is_connected; // true if on line now (for stream connection) - - key_type _control; // address of control object; - - // encoding / crypt info - // ... - - - bool is_connected() const - { return _is_connected; } - - void inc_from( size_t sz, size_t u = 1 ) - { - _sz_from += sz; - _un_from += u; - _last = time( 0 ); - } - - void inc_to( size_t sz, size_t u = 1 ) - { - _sz_to += sz; - _un_to += u; - } - - unsigned un_from( unsigned u ) - { - if ( ++_lun_from == u ) { - return 0; - } - unsigned tmp = _lun_from; - _lun_from = u; - return u - tmp; - } - - unsigned un_to( unsigned u ) - { - if ( ++_lun_to == u ) { - return 0; - } - unsigned tmp = _lun_to; - _lun_to = u; - return u - tmp; - } - - time_t connect() - { - _conn = time( &_last ); - _is_connected = true; - return _last; - } - - time_t disconnect() - { - if ( _is_connected ) { - _on_line += time( 0 ) - _conn; - ++_reconnect_cnt; - _is_connected = false; - } - return _on_line; - } - -#ifndef WIN32 - __FIT_DECLSPEC SessionInfo& operator =( const SessionInfo& ); -#else - SessionInfo& operator =( const SessionInfo& si ) - { - _host = si._host; - _port = si._port; - - _sz_from = si._sz_from; - _un_from = si._un_from; - _sz_to = si._sz_to; - _un_to = si._un_to; - _lun_from = si._lun_from; - _lun_to = si._lun_to; - _start = si._start; - _on_line = si._on_line; - _conn = si._conn; - _last = si._last; - _reconnect_cnt = si._reconnect_cnt; - _is_connected = si._is_connected; - - _control = si._control; - - return *this; - } -#endif -}; - -template <class T> -class SessionManager -{ - public: - typedef unsigned key_type; - // typedef __STD::map<key_type,T,__STD::less<key_type>, - // __STL_DEFAULT_ALLOCATOR(T) > heap_type; - typedef std::map<key_type,T> heap_type; - typedef typename heap_type::iterator iterator; - - SessionManager() - { } - - key_type create() - { - MT_REENTRANT( _lock, _x1 ); - return unsafe_create(); - } - - void lock() - { MT_LOCK( _lock ); } - - void unlock() - { MT_UNLOCK( _lock ); } - - bool is_avail( const key_type& k ) const - { - MT_REENTRANT( _lock, _x1 ); - return unsafe_is_avail( k ); - } - - void erase( const key_type& k ) - { - MT_REENTRANT( _lock, _x1 ); - unsafe_erase( k ); - } - - void assign( const key_type& k, const T& v ) - { - MT_REENTRANT( _lock, _x1 ); - heap[k] = v; - } - - protected: - heap_type heap; - - key_type unsafe_create() - { - key_type new_key = create_unique(); - heap[new_key]; - return new_key; - } - - T& operator[]( const key_type& k ) - { - // MT_REENTRANT( _lock, _x1 ); - return heap[k]; - } - - void erase( iterator& k ) - { - MT_REENTRANT( _lock, _x1 ); - unsafe_erase( k ); - } - - bool unsafe_is_avail( const key_type& k ) const - { return heap.find( k ) != heap.end(); } - - void unsafe_erase( const key_type& k ) - { heap.erase( k ); } - - void unsafe_erase( iterator& k ) - { heap.erase( k ); } - - friend class NetTransport_base; - - private: - key_type create_unique(); - static const key_type _low; - static const key_type _high; - static key_type _id; - mutable xmt::Mutex _lock; -}; - -#ifndef _MSC_VER -template <class T> -const typename SessionManager<T>::key_type SessionManager<T>::_low = 0; -#else -template <class T> -const SessionManager<T>::key_type SessionManager<T>::_low = 0; -#endif - -#ifndef _MSC_VER -template <class T> -const typename SessionManager<T>::key_type SessionManager<T>::_high( 65535 ); -#else -template <class T> -const SessionManager<T>::key_type SessionManager<T>::_high = 65535; -#endif - -#ifndef _MSC_VER -template <class T> -typename SessionManager<T>::key_type SessionManager<T>::_id = SessionManager<T>::_low; -// template <class T> -// typename SessionManager<T>::key_type SessionManager<T>::_id( SessionManager<T>::_low ); -#else -template <class T> -SessionManager<T>::key_type SessionManager<T>::_id = SessionManager<T>::_low; -#endif - -#ifndef _MSC_VER -template <class T> -typename SessionManager<T>::key_type SessionManager<T>::create_unique() -#else -template <class T> -SessionManager<T>::key_type SessionManager<T>::create_unique() -#endif -{ -#ifndef _MSC_VER - std::pair<typename heap_type::iterator, bool> ret; -#else - std::pair<heap_type::iterator,bool> ret; -#endif - - do { - if ( ++_id > _high ) { - _id = (_id - _low) % (_high - _low) + _low; - } - } while ( heap.find( _id ) != heap.end() ); - - return _id; -} - -typedef SessionManager<SessionInfo> EvSessionManager; - -} // namespace stem - -#ifdef _MSC_VER -typedef stem::SessionInfo SessionInfo; -#endif - -#endif // __EvSession_h Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/Event.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/26 14:32:35 ptr> +// -*- C++ -*- Time-stamp: <06/11/30 20:11:30 ptr> /* * @@ -70,8 +70,6 @@ # include <bits/type_traits.h> # endif // __GLIBCXX__ -#define _STLP_TEMPLATE_NULL template <> - #endif namespace stem { @@ -147,19 +145,22 @@ __Event_Base() : _code( badcode ), _dst( badaddr ), - _src( badaddr ) + _src( badaddr ), + _flags( 0 ) { } explicit __Event_Base( code_type c ) : _code( c ), _dst( badaddr ), - _src( badaddr ) + _src( badaddr ), + _flags( 0 ) { } /* explicit */ __Event_Base( const __Event_Base& e ) : _code( e._code ), _dst( e._dst ), - _src( e._src ) + _src( e._src ), + _flags( e._flags ) { } code_type code() const @@ -168,6 +169,8 @@ { return _dst; } addr_type src() const { return _src; } + uint32_t flags() const + { return _flags; } bool is_from_foreign() const { return ((_src & extbit) != 0) && (_src != badaddr); } bool is_to_foreign() const @@ -180,33 +183,38 @@ void src( addr_type c ) const { _src = c; } + void setf( uint32_t f ) const + { _flags |= f; } + void unsetf( uint32_t f ) const + { _flags &= (0xffffffff & ~f); } + void resetf( uint32_t f ) const + { _flags = f; } + void cleanf() const + { _flags = 0; } + + enum { + conv = 1, + expand = 2 + }; + protected: - mutable code_type _code; // event code + mutable code_type _code; // event code mutable addr_type _dst; // destination mutable addr_type _src; // source - - friend class NetTransport_base; - friend class NetTransportMgr; + mutable uint32_t _flags; }; -#if defined(_MSC_VER) && !defined(_DEBUG) // workaround for VC 5.0 / Release -} // namespace stem -typedef stem::__Event_Base __Event_Base; -namespace stem { -#endif - // Forward declarations +template <class D, class POD > class __Event_base_aux; +template <class D> class __Event_base_aux<D,__true_type>; +template <class D> class __Event_base_aux<D,__false_type>; + template <class D> class Event_base; -// VC 5.0 to be very huffy on typedefed std::string... -#ifndef _MSC_VER -_STLP_TEMPLATE_NULL class Event_base<std::string>; -#else -_STLP_TEMPLATE_NULL -class Event_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >; -#endif -_STLP_TEMPLATE_NULL class Event_base<void>; +template <> class Event_base<std::string>; +template <> class Event_base<void>; + // Typedefs: typedef Event_base<void> EventVoid; @@ -239,8 +247,14 @@ \* ******************************************** */ +template <class D, class POD > +class __Event_base_aux : + public __Event_Base +{ +}; + template <class D> -class Event_base : +class __Event_base_aux<D,__true_type> : public __Event_Base { public: @@ -250,27 +264,24 @@ typedef D * pointer; typedef const D * const_pointer; - Event_base() : + __Event_base_aux() : __Event_Base(), _data() { } - explicit Event_base( code_type c ) : + explicit __Event_base_aux( code_type c ) : __Event_Base( c ), _data() { } - Event_base( code_type c, const D& d ) : + __Event_base_aux( code_type c, const D& d ) : __Event_Base( c ), _data( d ) { } -// #ifndef __GNUG__ // otherwise gcc can't return structure -// explicit -// #endif - Event_base( const Event_base& e ) : + __Event_base_aux( const __Event_Base& e, const D& d ) : __Event_Base( e ), - _data( e._data ) + _data( d ) { } const_reference value() const @@ -280,66 +291,58 @@ size_type value_size() const { return sizeof(_data); } -//#ifndef __FIT_TEMPLATE_FORWARD_BUG -#if 0 - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::ostringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } + void pack( std::ostream& __s ) const + { __pack_base::__pack( __s, _data ); } + void unpack( std::istream& __s ) + { __pack_base::__unpack( __s, _data ); } + void net_pack( std::ostream& __s ) const + { __pack_base::__net_pack( __s, _data ); } + void net_unpack( std::istream& __s ) + { __pack_base::__net_unpack( __s, _data ); } - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - std::stringstream ss( s.value() ); - net_unpack( ss ); - } + protected: + value_type _data; +}; - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } +template <class D> +class __Event_base_aux<D,__false_type> : + public __Event_Base +{ + public: + typedef D value_type; + typedef D& reference; + typedef const D& const_reference; + typedef D * pointer; + typedef const D * const_pointer; - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - std::stringstream ss( s.value() ); - unpack( ss ); - } -#else // __FIT_TEMPLATE_FORWARD_BUG - void net_pack( Event& s ) const; - void net_unpack( const Event& s ); - void pack( Event& s ) const; - void unpack( const Event& s ); -#endif + __Event_base_aux() : + __Event_Base(), + _data() + { } -#ifndef _MSC_VER + explicit __Event_base_aux( code_type c ) : + __Event_Base( c ), + _data() + { } + + __Event_base_aux( code_type c, const D& d ) : + __Event_Base( c ), + _data( d ) + { } + + __Event_base_aux( const __Event_Base& e, const D& d ) : + __Event_Base( e ), + _data( d ) + { } + + const_reference value() const + { return _data; } + reference value() + { return _data; } + size_type value_size() const + { return sizeof(_data); } + void pack( std::ostream& __s ) const - { pack( __s, typename __type_traits<D>::is_POD_type() ); } - void unpack( std::istream& __s ) - { unpack( __s, typename __type_traits<D>::is_POD_type() ); } - void net_pack( std::ostream& __s ) const - { net_pack( __s, typename __type_traits<D>::is_POD_type() ); } - void net_unpack( std::istream& __s ) - { net_unpack( __s, typename __type_traits<D>::is_POD_type() ); } -#else -// VC instantiate only whole class, so I need stupid specializaton for it, -// and this template can be compiled for non-POD classes only -// (specialization for integral types in separate file, included below) - void pack( std::ostream& __s ) const { _data.pack( __s ); } void unpack( std::istream& __s ) { _data.unpack( __s ); } @@ -347,49 +350,13 @@ { _data.net_pack( __s ); } void net_unpack( std::istream& __s ) { _data.net_unpack( __s ); } -#endif protected: value_type _data; - -#ifndef _MSC_VER - void pack( std::ostream& __s, __true_type ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - - void pack( std::ostream& __s, __false_type ) const - { _data.pack( __s ); } - - void unpack( std::istream& __s, __true_type ) - { __s.read( (char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s, __false_type ) - { _data.unpack( __s ); } - - void net_pack( std::ostream& __s, __true_type ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_pack( std::ostream& __s, __false_type ) const - { _data.net_pack( __s ); } - void net_unpack( std::istream& __s, __true_type ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - void net_unpack( std::istream& __s, __false_type ) - { _data.net_unpack( __s ); } -#endif }; - -// VC 5.0 to be very huffy on typedefed std::string... -_STLP_TEMPLATE_NULL -#ifndef _MSC_VER -class Event_base<std::string> : -#else -class Event_base<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > : -#endif +template <> +class __Event_base_aux<std::string,__false_type> : public __Event_Base { public: @@ -399,27 +366,24 @@ typedef std::string * pointer; typedef const std::string * const_pointer; - Event_base() : + __Event_base_aux() : __Event_Base(), _data() { } - explicit Event_base( code_type c ) : + explicit __Event_base_aux( code_type c ) : __Event_Base( c ), _data() { } - Event_base( code_type c, const std::string& d ) : + __Event_base_aux( code_type c, const std::string& d ) : __Event_Base( c ), _data( d ) { } -#if !defined( __GNUG__ ) && !defined( _MSC_VER ) // otherwise gcc can't return structure -// explicit -#endif - Event_base( const Event_base& e ) : + __Event_base_aux( const __Event_Base& e, const std::string& d ) : __Event_Base( e ), - _data( e._data ) + _data( d ) { } const_reference value() const @@ -427,13 +391,117 @@ reference value() { return _data; } size_type value_size() const - { return _data.size(); } + { return sizeof(_data); } + void pack( std::ostream& __s ) const + { __pack_base::__pack( __s, _data ); } + void unpack( std::istream& __s ) + { __pack_base::__unpack( __s, _data ); } + void net_pack( std::ostream& __s ) const + { __pack_base::__net_pack( __s, _data ); } + void net_unpack( std::istream& __s ) + { __pack_base::__net_unpack( __s, _data ); } + + protected: + value_type _data; +}; + +template <> +class __Event_base_aux<void,__true_type> : + public __Event_Base +{ + public: + typedef void value_type; + typedef void * pointer; + typedef size_t size_type; + typedef const void * const_pointer; + + __Event_base_aux() : + __Event_Base() + { } + + explicit __Event_base_aux( code_type c ) : + __Event_Base( c ) + { } + + __Event_base_aux( const __Event_Base& e ) : + __Event_Base( e ) + { } + + size_type value_size() const + { return 0; } + + void pack( std::ostream& __s ) const + { } + void unpack( std::istream& __s ) + { } + void net_pack( std::ostream& __s ) const + { } + void net_unpack( std::istream& __s ) + { } +}; + +template <class D> +class Event_base : + public __Event_base_aux<D,typename __type_traits<D>::is_POD_type> +{ + private: + typedef __Event_base_aux<D,typename __type_traits<D>::is_POD_type> _Base; + + public: + Event_base() : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>() + { } + + explicit Event_base( code_type c ) : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>( c ) + { } + + Event_base( code_type c, const D& d ) : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>( c, d ) + { } + + Event_base( const Event_base& e ) : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>( e, e._data ) + { } + + void net_pack( Event& s ) const; + void net_unpack( const Event& s ); + void pack( Event& s ) const; + void unpack( const Event& s ); +}; + + +template <> +class Event_base<std::string> : + public __Event_base_aux<std::string,__false_type> +{ + private: + typedef __Event_base_aux<std::string,__false_type> _Base; + + public: + Event_base() : + __Event_base_aux<std::string,__false_type>() + { } + + explicit Event_base( code_type c ) : + __Event_base_aux<std::string,__false_type>( c ) + { } + + Event_base( code_type c, const std::string& d ) : + __Event_base_aux<std::string,__false_type>( c, d ) + { } + + Event_base( const Event_base& e ) : + __Event_base_aux<std::string,__false_type>( e, e._data ) + { } + void net_pack( Event& s ) const { s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _flags ); s.value() = _data; } @@ -442,6 +510,7 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags(); _data = s.value(); } @@ -450,6 +519,7 @@ s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _flags ); s.value() = _data; } @@ -458,96 +528,90 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags(); _data = s.value(); } - - void pack( std::ostream& __s ) const - { __pack_base::__pack( __s, _data ); } - void unpack( std::istream& __s ) - { __pack_base::__unpack( __s, _data ); } - void net_pack( std::ostream& __s ) const - { __pack_base::__net_pack( __s, _data ); } - void net_unpack( std::istream& __s ) - { __pack_base::__net_unpack( __s, _data ); } - - protected: - value_type _data; }; -//#ifdef __FIT_TEMPLATE_FORWARD_BUG template <class D> void Event_base<D>::net_pack( Event& s ) const { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); + // std::cerr << "**1\n"; + s.code( _Base::_code ); + s.dest( _Base::_dst ); + s.src( _Base::_src ); + s.resetf( _Base::_flags | (__Event_Base::conv | __Event_Base::expand) ); std::ostringstream ss; - net_pack( ss ); - s.value() = ss.str(); + _Base::net_pack( ss ); + s.value() = ss.str(); } template <class D> void Event_base<D>::net_unpack( const Event& s ) { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); + _Base::_code = s.code(); + _Base::_dst = s.dest(); + _Base::_src = s.src(); + _Base::_flags = s.flags() & ~(__Event_Base::conv | __Event_Base::expand); std::istringstream ss( s.value() ); - net_unpack( ss ); + _Base::net_unpack( ss ); + // std::cerr << "**2 " << std::hex << _Base::flags() << std::dec << std::endl; } template <class D> void Event_base<D>::pack( Event& s ) const { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); + s.code( _Base::_code ); + s.dest( _Base::_dst ); + s.src( _Base::_src ); + s.resetf( _Base::_flags | __Event_Base::expand & ~__Event_Base::conv ); + // s.unsetf( __Event_Base::conv ); std::ostringstream ss; - pack( ss ); + _Base::pack( ss ); s.value() = ss.str(); + // std::cerr << "**3 " << std::hex << s.flags() << std::dec << std::endl; } template <class D> void Event_base<D>::unpack( const Event& s ) { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); + _Base::_code = s.code(); + _Base::_dst = s.dest(); + _Base::_src = s.src(); + _Base::_flags = s.flags() & ~__Event_Base::expand; + // _Base::unsetf( __Event_Base::expand ); std::istringstream ss( s.value() ); - unpack( ss ); + _Base::unpack( ss ); + // std::cerr << "**4 " << std::hex << _Base::flags() << std::dec << std::endl; } -//#endif // __FIT_TEMPLATE_FORWARD_BUG -_STLP_TEMPLATE_NULL +template <> class Event_base<void> : - public __Event_Base + public __Event_base_aux<void,__true_type> { + private: + typedef __Event_base_aux<void,__true_type> _Base; + public: - typedef void value_type; - typedef void * pointer; - typedef size_t size_type; - typedef const void * const_pointer; Event_base() : - __Event_Base() + __Event_base_aux<void,__true_type>() { } explicit Event_base( code_type c ) : - __Event_Base( c ) + __Event_base_aux<void,__true_type>( c ) { } __FIT_EXPLICIT Event_base( const Event_base& e ) : - __Event_Base( e ) + __Event_base_aux<void,__true_type>( e ) { } - size_type value_size() const - { return 0; } - void net_pack( Event& s ) const { s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _Base::_flags | __Event_Base::conv | __Event_Base::expand ); s.value().erase(); } @@ -556,6 +620,7 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags() & ~(__Event_Base::conv | __Event_Base::expand); } void pack( Event& s ) const @@ -563,6 +628,7 @@ s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _Base::_flags & ~__Event_Base::conv | __Event_Base::expand ); s.value().erase(); } @@ -571,6 +637,7 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags() & ~__Event_Base::expand; } void pack( std::ostream& ) const @@ -583,11 +650,6 @@ { } }; -// VC instantiate only whole class, so I need stupid specializaton for it: -#ifdef _MSC_VER -#include <EDS/EventSpec.h> -#endif - } // namespace stem namespace EDS = stem; Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EventHandler.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 20:29:41 ptr> +// -*- C++ -*- Time-stamp: <06/11/30 20:50:13 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -31,6 +31,7 @@ #include <vector> #include <list> #include <ostream> +#include <typeinfo> #include <mt/xmt.h> @@ -109,8 +110,11 @@ { T operator ()( const stem::Event& x ) const { + if ( (x.flags() & __Event_Base::expand) == 0 ) { + throw std::invalid_argument( std::string("invalid conversion") ); + } T tmp; - if ( x.is_from_foreign() ) { + if ( /* x.is_from_foreign() */ x.flags() & __Event_Base::conv ) { tmp.net_unpack( x ); } else { tmp.unpack( x ); @@ -125,8 +129,11 @@ { T operator ()( const stem::Event& x ) const { + if ( (x.flags() & __Event_Base::expand) == 0 ) { + throw std::invalid_argument( std::string("invalid conversion") ); + } stem::Event_base<T> tmp; - if ( x.is_from_foreign() ) { + if ( /* x.is_from_foreign() */ x.flags() & __Event_Base::conv ) { tmp.net_unpack( x ); } else { tmp.unpack( x ); @@ -142,9 +149,9 @@ stem::Event operator ()( const stem::Event_base<T>& x ) const { stem::Event tmp; - // first is evident, the second introduced - // to support Forward autodetection - if ( x.is_to_foreign() || x.is_from_foreign() ) { + // first is evident, the second was introduced + // to support Forward autodetection (and commented with addressing changes) + if ( x.is_to_foreign() /* || x.is_from_foreign() */ ) { x.net_pack( tmp ); } else { x.pack( tmp ); @@ -208,25 +215,15 @@ template <class PMF, class Arg > struct __dispatcher_convert_Event { -#ifndef _MSC_VER static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) { (c->*pmf)( convert_Event<typename PMF::argument_type>()(arg) ); } -#else - static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) - { (c->*pmf)( convert_Event<PMF::argument_type>()(arg) ); } -#endif }; template <class PMF, class Arg > struct __dispatcher_convert_Event_extr { -#ifndef _MSC_VER static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) { (c->*pmf)( convert_Event_extr<typename PMF::argument_type>()(arg) ); } -#else - static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) - { (c->*pmf)( convert_Event_extr<PMF::argument_type>()(arg) ); } -#endif }; struct __AnyPMFentry @@ -243,11 +240,7 @@ typedef void (T::*PMF)(); PMF pmf; -#if !defined( _MSC_VER ) || defined( _DEBUG ) __FIT_TYPENAME stem::GENERIC::DPMF dpmf; -#else // _MSC_VER && !_DEBUG - GENERIC::DPMF dpmf; -#endif const char *pmf_name; }; @@ -255,18 +248,8 @@ struct __DeclareAnyPMF { state_type st; -#ifndef _MSC_VER /* __FIT_TYPENAME */ stem::code_type code; __FIT_TYPENAME stem::__PMFentry<T> func; -#else // _MSC_VER -# ifdef _DEBUG - stem::code_type code; - stem::__PMFentry<T> func; -# else // !_DEBUG - code_type code; // workaround for VC 5.0 - __PMFentry<T> func; -# endif // _DEBUG -#endif // _MSC_VER }; template <class Key1, class Key2, class Value> @@ -274,9 +257,9 @@ { public: typedef std::pair<Key2,Value> pair2_type; - typedef std::vector<pair2_type,std::allocator<pair2_type > > Container2; + typedef std::vector<pair2_type> Container2; typedef std::pair<Key1,Container2> pair1_type; - typedef std::vector<pair1_type,std::allocator<pair1_type> > Container1; + typedef std::vector<pair1_type> Container1; typedef typename Container1::iterator iterator1; typedef typename Container2::iterator iterator2; typedef typename Container1::const_iterator const_iterator1; @@ -418,11 +401,7 @@ class __EvHandler { public: -#ifndef _MSC_VER typedef typename T::table_type table_type; -#else // should sync at least with EventHandler::table_type below: - typedef __EvTable<stem::code_type,state_type,__AnyPMFentry *> table_type; -#endif // (that was workaround of M$ VC 5.0 bug) __EvHandler() { __EvTableLoader( &table, (T *)0 ); } @@ -558,6 +537,7 @@ typedef __EvTable<code_type,state_type,__AnyPMFentry *> table_type; typedef __DeclareAnyPMF<EventHandler> evtable_decl_type; typedef EventHandler ThisCls; + protected: // See comment near EventHandler::EventHandler() implementation // HistoryContainer& theHistory; @@ -655,6 +635,8 @@ { return false; } virtual void Trace( ostream& ) const { } + virtual const std::type_info& classtype() const + { return typeid(EventHandler); } __FIT_DECLSPEC void TraceStack( ostream& ) const; private: @@ -723,6 +705,8 @@ MT_REENTRANT_SDS( this->_theHistory_lock, _x1 ); \ return theEventsTable.DispatchTrace( theHistory.begin(), \ theHistory.end(), __e, __s ); } \ + virtual const std::type_info& classtype() const \ + { return typeid(ThisCls); } \ typedef stem::__EvHandler<cls,stem::h_iterator> evtable_type; \ typedef stem::__DeclareAnyPMF<cls> evtable_decl_type; \ typedef cls ThisCls; \ Deleted: trunk/complement/explore/include/stem/EventSpec.h =================================================================== --- trunk/complement/explore/include/stem/EventSpec.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EventSpec.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,878 +0,0 @@ -// -*- C++ -*- Time-stamp: <03/11/06 07:49:19 ptr> - -/* - * - * Copyright (c) 1997-1999, 2002, 2003 - * Petr Ovchenkov - * - * Copyright (c) 1999-2001 - * ParallelGraphics Ltd. - * - * Licensed under the Academic Free License version 2.0 - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - */ - -// Only for MS VC! -// NEVER direct include! - -#ifdef __unix -# ifdef __HP_aCC -#pragma VERSIONID "@(#)$Id$" -# else -#ident "@(#)$Id$" -# endif -#endif - -_STLP_TEMPLATE_NULL -class Event_base<short> : - public __Event_Base -{ - public: - typedef short value_type; - typedef short& reference; - typedef const short& const_reference; - typedef short * pointer; - typedef const short * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const short& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned short> : - public __Event_Base -{ - public: - typedef unsigned short value_type; - typedef unsigned short& reference; - typedef const unsigned short& const_reference; - typedef unsigned short * pointer; - typedef const unsigned short * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned short& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<int> : - public __Event_Base -{ - public: - typedef int value_type; - typedef int& reference; - typedef const int& const_reference; - typedef int * pointer; - typedef const int * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const int& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned> : - public __Event_Base -{ - public: - typedef unsigned value_type; - typedef unsigned& reference; - typedef const unsigned& const_reference; - typedef unsigned * pointer; - typedef const unsigned * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<long> : - public __Event_Base -{ - public: - typedef long value_type; - typedef long& reference; - typedef const long& const_reference; - typedef long * pointer; - typedef const long * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const long& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned long> : - public __Event_Base -{ - public: - typedef unsigned long value_type; - typedef unsigned long& reference; - typedef const unsigned long& const_reference; - typedef unsigned long * pointer; - typedef const unsigned long * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned long& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<char> : - public __Event_Base -{ - public: - typedef char value_type; - typedef char& reference; - typedef const char& const_reference; - typedef char * pointer; - typedef const char * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const char& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned char> : - public __Event_Base -{ - public: - typedef unsigned char value_type; - typedef unsigned char& reference; - typedef const unsigned char& const_reference; - typedef unsigned char * pointer; - typedef const unsigned char * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned char& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<signed char> : - public __Event_Base -{ - public: - typedef signed char value_type; - typedef signed char& reference; - typedef const signed char& const_reference; - typedef signed char * pointer; - typedef const signed char * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const signed char& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; Deleted: trunk/complement/explore/include/stem/SessionMgr.h =================================================================== --- trunk/complement/explore/include/stem/SessionMgr.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/SessionMgr.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,107 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/06/28 15:09:44 ptr> - -/* - * - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 - * Petr Ovtchenkov - * - * Copyright (c) 1999-2001 - * ParallelGraphics Ltd. - * - * Licensed under the Academic Free License version 2.1 - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - */ - -#ifndef __stem_SessionMgr_h -#define __stem_SessionMgr_h - -#ifndef __config_feature_h -#include <config/feature.h> -#endif - -#ifndef __stem_Event_h -#include <stem/Event.h> -#endif - -#ifndef __stem_EventHandler_h -#include <stem/EventHandler.h> -#endif - -#include <ctime> - -#ifndef __stem_EvPack_h -#include <stem/EvPack.h> -#endif - -namespace stem { - -class SessionMgr : - public EventHandler -{ - public: - __FIT_DECLSPEC SessionMgr(); - __FIT_DECLSPEC SessionMgr( const char *info ); - __FIT_DECLSPEC SessionMgr( addr_type addr, const char *info = 0 ); - __FIT_DECLSPEC ~SessionMgr(); - - void raw_establish_session( EventHandler *, addr_type ); - - protected: - - virtual __FIT_DECLSPEC EventHandler *session_leader( const std::string& account, - const std::string& passwd, - addr_type addr ) throw(); - virtual __FIT_DECLSPEC void destroy_session_leader( EventHandler * ) throw(); - - void establish_session( const Event& ); - void restore_session( const Event_base<key_type>& ); - void close_session( const Event_base<key_type>& ); - - struct __S - { - // Event::key_type leader; - EventHandler *leader; - time_t timeout; - }; - - typedef std::pair<key_type,__S> account_type; - typedef std::vector<account_type> Container; - - key_type key_generate(); - Container _M_c; -#ifdef STLPORT - std::select1st<account_type> _skey; - std::select2nd<account_type> _sess; -#else - __gnu_cxx::select1st<account_type> _skey; - __gnu_cxx::select2nd<account_type> _sess; -#endif - std::equal_to<key_type> _eq_key; - - DECLARE_RESPONSE_TABLE( SessionMgr, EventHandler ); -}; - - -struct SessionRsp : - public __pack_base -{ - key_type key; - addr_type addr; - - virtual __FIT_DECLSPEC void pack( std::ostream& s ) const; - virtual __FIT_DECLSPEC void net_pack( std::ostream& s ) const; - virtual __FIT_DECLSPEC void unpack( std::istream& s ); - virtual __FIT_DECLSPEC void net_unpack( std::istream& s ); -}; - -} // namespace stem - -#endif // __stem_SessionMgr_h Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/lib/stem/ChangeLog 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,3 +1,31 @@ +2006-11-30 Petr Ovtchenkov <pt...@is...> + + * Event.h: code clean; change specialization of Event_base + to avoid wrong code or bogus workarounds if whole cla... [truncated message content] |