Thread: [asycxx-devel] SF.net SVN: asycxx:[4] trunk
Status: Alpha
Brought to you by:
joe_steeve
From: <kar...@us...> - 2009-02-20 18:59:09
|
Revision: 4 http://asycxx.svn.sourceforge.net/asycxx/?rev=4&view=rev Author: karthikbk Date: 2009-02-20 18:58:54 +0000 (Fri, 20 Feb 2009) Log Message: ----------- Initial Version. Asycxx v. 0.1 Modified Paths: -------------- trunk/Makefile.am trunk/autogen.sh trunk/configure.ac trunk/src/DataBuffer.cxx trunk/src/Deferred.cxx trunk/src/Error.cxx trunk/src/Factory.cxx trunk/src/GimpleMsgBus.cxx trunk/src/Listener.cxx trunk/src/Logger.cxx trunk/src/Makefile.am trunk/src/MsgBus.cxx trunk/src/MsgHandler.cxx trunk/src/Protocol.cxx trunk/src/Reactor.cxx trunk/src/RefCounter.cxx trunk/src/SelectReactor.cxx trunk/src/TCPLLTransport.cxx trunk/src/TCPListener.cxx trunk/src/TCPTransport.cxx trunk/src/Timer.cxx trunk/src/Transport.cxx trunk/src/XMLParser.cxx trunk/src/core.cxx Added Paths: ----------- trunk/asycxx-0.1.pc.in trunk/asycxx-config.h.in trunk/include/ trunk/include/Makefile.am trunk/include/asycxx/ trunk/include/asycxx/DataBuffer.h trunk/include/asycxx/Deferred.h trunk/include/asycxx/Error.h trunk/include/asycxx/Factory.h trunk/include/asycxx/GimpleMsgBus.h trunk/include/asycxx/Listener.h trunk/include/asycxx/Logger.h trunk/include/asycxx/MsgBus.h trunk/include/asycxx/MsgHandler.h trunk/include/asycxx/Protocol.h trunk/include/asycxx/Reactor.h trunk/include/asycxx/RefCounter.h trunk/include/asycxx/SelectReactor.h trunk/include/asycxx/TCPLLTransport.h trunk/include/asycxx/TCPListener.h trunk/include/asycxx/TCPTransport.h trunk/include/asycxx/Timer.h trunk/include/asycxx/Transport.h trunk/include/asycxx/XMLParser.h trunk/include/asycxx/asycxx.h Removed Paths: ------------- trunk/hmi-ctrl-config.h trunk/hmi-ctrl-config.h.in trunk/hmi-ctrl-config.xml.sample trunk/src/App.cxx trunk/src/App.h trunk/src/Config.cxx trunk/src/Config.h trunk/src/DataBuffer.h trunk/src/Deferred.h trunk/src/Error.h trunk/src/Factory.h trunk/src/GimpleMsgBus.h trunk/src/Listener.h trunk/src/Logger.h trunk/src/MsgBus.h trunk/src/MsgHandler.h trunk/src/Protocol.h trunk/src/Reactor.h trunk/src/RefCounter.h trunk/src/SelectReactor.h trunk/src/TCPLLTransport.h trunk/src/TCPListener.h trunk/src/TCPTransport.h trunk/src/Timer.h trunk/src/Transport.h trunk/src/XMLParser.h trunk/src/hmi-ctrl.cxx trunk/src/hmi-ctrl.h Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/Makefile.am 2009-02-20 18:58:54 UTC (rev 4) @@ -1,5 +1,5 @@ # -*- mode: makefile; indent-tabs-mode: nil; tab-width: 4; -*- -configdir = $(sysconfdir)/hmi-ctrl -dist_config_DATA = hmi-ctrl-config.xml.sample +SUBDIRS = src include -SUBDIRS = src +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = asycxx-0.1.pc Added: trunk/asycxx-0.1.pc.in =================================================================== --- trunk/asycxx-0.1.pc.in (rev 0) +++ trunk/asycxx-0.1.pc.in 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: asycxx.0 +Description: ASYCxx +Version: @VERSION@ +Libs: -L${libdir} -lasycxx-0.1 +Cflags: -I${includedir} Added: trunk/asycxx-config.h.in =================================================================== --- trunk/asycxx-config.h.in (rev 0) +++ trunk/asycxx-config.h.in 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,72 @@ +/* asycxx-config.h.in. Generated from configure.ac by autoheader. */ + +/* Release tag associated with the build */ +#undef ASYCXX_RELEASE_TAG + +/* SCM revision number */ +#undef ASYCXX_REVISION + +/* Controls the amount of logs */ +#undef ASYCXX_VERBOSE_LEVEL + +/* Enable/Disable sanity checks */ +#undef ENABLE_SANITY_CHECKS + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif Modified: trunk/autogen.sh =================================================================== --- trunk/autogen.sh 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/autogen.sh 2009-02-20 18:58:54 UTC (rev 4) @@ -2,5 +2,6 @@ echo "Generating build necessaries..." aclocal +libtoolize --force automake --add-missing autoconf Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/configure.ac 2009-02-20 18:58:54 UTC (rev 4) @@ -1,6 +1,8 @@ -AC_INIT([hmi-ctrl], [0.1], jo...@hi...) +AC_INIT([asycxx], [0.1], jo...@hi...) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) +AC_PREFIX_DEFAULT(/opt/asycxx) + CFLAGS="-Wall -Werror" CXXFLAGS="-Wall -Werror" @@ -8,59 +10,49 @@ AC_ARG_WITH(verbose-level, AS_HELP_STRING([--with-verbose-level], [Use the given debug level (0 to 3) 0=disable]), - [hmi_ctrl_with_verbose_level=$withval],) + [asycxx_with_verbose_level=$withval],) -if test $hmi_ctrl_with_verbose_level; then - HMI_CTRL_verbose_level=$hmi_ctrl_with_verbose_level +if test $asycxx_with_verbose_level; then + ASYCXX_verbose_level=$asycxx_with_verbose_level else - HMI_CTRL_verbose_level=2 + ASYCXX_verbose_level=2 fi -AC_DEFINE_UNQUOTED(HMI_CTRL_VERBOSE_LEVEL, $HMI_CTRL_verbose_level, +AC_DEFINE_UNQUOTED(ASYCXX_VERBOSE_LEVEL, $ASYCXX_verbose_level, [Controls the amount of logs]) dnl SCM revision tag -HMI_CTRL_revision=`svn info | grep "^Revision" | cut -d' ' -f 2 -s` -if [[ "$HMI_CTRL_revision" = "" ]]; then - HMI_CTRL_revision="unknown" +ASYCXX_revision=`svn info | grep "^Revision" | cut -d' ' -f 2 -s` +if [[ "$ASYCXX_revision" = "" ]]; then + ASYCXX_revision="unknown" fi -AC_DEFINE_UNQUOTED(HMI_CTRL_REVISION, "$HMI_CTRL_revision", +AC_DEFINE_UNQUOTED(ASYCXX_REVISION, "$ASYCXX_revision", [SCM revision number]) dnl setup a release tag AC_ARG_WITH(release-tag, AS_HELP_STRING([--with-release-tag], [Release tag to associate with the build]), - [HMI_CTRL_release_tag=$withval],) + [ASYCXX_release_tag=$withval],) -if test -z $HMI_CTRL_release_tag; then - HMI_CTRL_release_tag="<DEBUG:Rev=$HMI_CTRL_revision>" +if test -z $ASYCXX_release_tag; then + ASYCXX_release_tag="<DEBUG:Rev=$ASYCXX_revision>" fi -AC_DEFINE_UNQUOTED(HMI_CTRL_RELEASE_TAG, "$HMI_CTRL_release_tag", +AC_DEFINE_UNQUOTED(ASYCXX_RELEASE_TAG, "$ASYCXX_release_tag", [Release tag associated with the build]) - -dnl setup the acw-common -ACW_COMMON_Folder=`pwd`/../acw-common -CFLAGS="$CFLAGS -I $ACW_COMMON_Folder" -CXXFLAGS="$CXXFLAGS -I $ACW_COMMON_Folder" -dnl setup the hmi-common -HMI_COMMON_Folder=`pwd`/../hmi-common -CFLAGS="$CFLAGS -I $HMI_COMMON_Folder" -CXXFLAGS="$CXXFLAGS -I $HMI_COMMON_Folder" - dnl enable/disable sanity checks AC_ARG_ENABLE(sanity-checks, AS_HELP_STRING([--enable-sanity-checks], [Enable all sanity checks]), [ if [[ "$enableval" = "yes" ]]; then - HMI_CTRL_sanity_checks=1 + ASYCXX_sanity_checks=1 else - HMI_CTRL_sanity_checks=0 + ASYCXX_sanity_checks=0 fi ], - [HMI_CTRL_sanity_checks=1]) -AC_DEFINE_UNQUOTED(ENABLE_SANITY_CHECKS, $HMI_CTRL_sanity_checks, + [ASYCXX_sanity_checks=1]) +AC_DEFINE_UNQUOTED(ENABLE_SANITY_CHECKS, $ASYCXX_sanity_checks, [Enable/Disable sanity checks]) dnl check for libhdb-tinyxml @@ -74,10 +66,33 @@ AC_PROG_CXX AC_GNU_SOURCE +AC_PROG_LIBTOOL -AC_CONFIG_HEADERS([hmi-ctrl-config.h]) +AC_CONFIG_HEADERS([asycxx-config.h]) AC_CONFIG_FILES([ Makefile src/Makefile +include/Makefile +asycxx-0.1.pc ]) +AC_CONFIG_LINKS(src/Logger.h:include/asycxx/Logger.h + src/Error.h:include/asycxx/Error.h + src/Deferred.h:include/asycxx/Deferred.h + src/RefCounter.h:include/asycxx/RefCounter.h + src/DataBuffer.h:include/asycxx/DataBuffer.h + src/Reactor.h:include/asycxx/Reactor.h + src/SelectReactor.h:include/asycxx/SelectReactor.h + src/Timer.h:include/asycxx/Timer.h + src/Transport.h:include/asycxx/Transport.h + src/Listener.h:include/asycxx/Listener.h + src/TCPTransport.h:include/asycxx/TCPTransport.h + src/TCPListener.h:include/asycxx/TCPListener.h + src/TCPLLTransport.h:include/asycxx/TCPLLTransport.h + src/Protocol.h:include/asycxx/Protocol.h + src/Factory.h:include/asycxx/Factory.h + src/MsgBus.h:include/asycxx/MsgBus.h + src/MsgHandler.h:include/asycxx/MsgHandler.h + src/GimpleMsgBus.h:include/asycxx/GimpleMsgBus.h + src/XMLParser.h:include/asycxx/XMLParser.h + src/asycxx.h:include/asycxx/asycxx.h) AC_OUTPUT Deleted: trunk/hmi-ctrl-config.h =================================================================== --- trunk/hmi-ctrl-config.h 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/hmi-ctrl-config.h 2009-02-20 18:58:54 UTC (rev 4) @@ -1,40 +0,0 @@ -/* hmi-ctrl-config.h. Generated from hmi-ctrl-config.h.in by configure. */ -/* hmi-ctrl-config.h.in. Generated from configure.ac by autoheader. */ - -/* Enable/Disable sanity checks */ -#define ENABLE_SANITY_CHECKS 1 - -/* Release tag associated with the build */ -#define HMI_CTRL_RELEASE_TAG "<DEBUG:Rev=unknown>" - -/* SCM revision number */ -#define HMI_CTRL_REVISION "unknown" - -/* Controls the amount of logs */ -#define HMI_CTRL_VERBOSE_LEVEL 2 - -/* Name of package */ -#define PACKAGE "hmi-ctrl" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "jo...@hi..." - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "hmi-ctrl" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "hmi-ctrl 0.1" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "hmi-ctrl" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "0.1" - -/* Version number of package */ -#define VERSION "0.1" - -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif Deleted: trunk/hmi-ctrl-config.h.in =================================================================== --- trunk/hmi-ctrl-config.h.in 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/hmi-ctrl-config.h.in 2009-02-20 18:58:54 UTC (rev 4) @@ -1,39 +0,0 @@ -/* hmi-ctrl-config.h.in. Generated from configure.ac by autoheader. */ - -/* Enable/Disable sanity checks */ -#undef ENABLE_SANITY_CHECKS - -/* Release tag associated with the build */ -#undef HMI_CTRL_RELEASE_TAG - -/* SCM revision number */ -#undef HMI_CTRL_REVISION - -/* Controls the amount of logs */ -#undef HMI_CTRL_VERBOSE_LEVEL - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* Version number of package */ -#undef VERSION - -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif Deleted: trunk/hmi-ctrl-config.xml.sample =================================================================== --- trunk/hmi-ctrl-config.xml.sample 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/hmi-ctrl-config.xml.sample 2009-02-20 18:58:54 UTC (rev 4) @@ -1,28 +0,0 @@ -<hmi-ctrl-config> - <spindle-count>64</spindle-count> - - <spindle-ctrl> - <ip>0.0.0.0</ip> - <port>10000</port> - </spindle-ctrl> - - <doffer-ctrl> - <ip>0.0.0.0</ip> - <port>10001</port> - </doffer-ctrl> - - <hstock-ctrl> - <ip>0.0.0.0</ip> - <port>10002</port> - </hstock-ctrl> - - <rpc-local> - <ip>127.0.0.1</ip> - <port>10010</port> - </rpc-local> - - <rpc-public> - <ip>0.0.0.0</ip> - <port>10011</port> - </rpc-public> -</hmi-ctrl-config> Added: trunk/include/Makefile.am =================================================================== --- trunk/include/Makefile.am (rev 0) +++ trunk/include/Makefile.am 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,22 @@ +# -*- mode: makefile; indent-tabs-mode: nil; tab-width: 4; -*- + +pkginclude_HEADERS = \ + asycxx/Logger.h \ + asycxx/Error.h \ + asycxx/Deferred.h \ + asycxx/RefCounter.h \ + asycxx/DataBuffer.h \ + asycxx/Reactor.h \ + asycxx/SelectReactor.h \ + asycxx/Timer.h \ + asycxx/Transport.h \ + asycxx/Listener.h \ + asycxx/TCPTransport.h \ + asycxx/TCPListener.h \ + asycxx/TCPLLTransport.h \ + asycxx/Protocol.h \ + asycxx/Factory.h \ + asycxx/MsgBus.h \ + asycxx/MsgHandler.h \ + asycxx/GimpleMsgBus.h \ + asycxx/XMLParser.h Added: trunk/include/asycxx/DataBuffer.h =================================================================== --- trunk/include/asycxx/DataBuffer.h (rev 0) +++ trunk/include/asycxx/DataBuffer.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,58 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__DATA_BUFFER_H__ +#define __HIPRO_ASYCXX__DATA_BUFFER_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "RefCounter.h" + +class DataBuffer : public RefCounter +{ +public: + /* ctors */ + DataBuffer (size_t len); + DataBuffer (void *buffer, size_t len); + + /* Accessors */ + void * Data (void) { return m_Data; } + size_t Len (void) { return m_DataLen; } + void Len (size_t len); + size_t BufferLen (void) { return m_BufferLen; } + void Processed (size_t len); + size_t Processed (void) { return m_ProcessedLen; } + void * UnProcessed (void); + +protected: + /* dtors */ + ~DataBuffer (); + +private: + /* initializer */ + void _init (void); + + /* The buffer */ + void *m_Data; + + /* meta-data about the buffer and its contents */ + size_t m_BufferLen; /* Maximum length of the buffer */ + size_t m_DataLen; /* Length of data held in the buffer */ + size_t m_ProcessedLen; /* Length of data processed */ +}; + +#endif /* __HIPRO_ASYCXX__DATA_BUFFER_H__ */ Added: trunk/include/asycxx/Deferred.h =================================================================== --- trunk/include/asycxx/Deferred.h (rev 0) +++ trunk/include/asycxx/Deferred.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,52 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__DEFERRED_H__ +#define __HIPRO_ASYCXX__DEFERRED_H__ + +#include "asycxx.h" +#include "Error.h" + +typedef void (*cbDeferredOnEvent_t) (void *obj); +typedef void (*cbDeferredOnError_t) (void *obj); +typedef void (*cbDeferredOnTimeout_t) (void *obj, h_msecs_t excess_time); + +class Deferred +{ + +public: + Deferred (); + ~Deferred (); + + Deferred * OnEvent (cbDeferredOnEvent_t cb_fn, void *cb_obj) throw (); + Deferred * OnError (cbDeferredOnError_t cb_fn, void *cb_obj) throw (); + Deferred * OnTimeout (cbDeferredOnTimeout_t cb_fn, void *cb_obj) throw (); + + void NotifyEvent (void); + void NotifyError (void); + void NotifyTimeout (h_msecs_t excess_time); + +private: + cbDeferredOnEvent_t m_cbOnEvent; + void * m_cbOnEvent_obj; + + cbDeferredOnError_t m_cbOnError; + void * m_cbOnError_obj; + + cbDeferredOnTimeout_t m_cbOnTimeout; + void * m_cbOnTimeout_obj; + +}; + +#endif // __HIPRO_ASYCXX__DEFERRED_H__ Added: trunk/include/asycxx/Error.h =================================================================== --- trunk/include/asycxx/Error.h (rev 0) +++ trunk/include/asycxx/Error.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,70 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO__ERROR_H__ +#define __HIPRO__ERROR_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" + +#define THROW(x, fmt, ...) throw x("[%s:%d] " fmt "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) + +#define ExpMSG_LEN 1024 + +class Error +{ +public: + Error () {} + Error (const char *fmt, ...) + { + va_list args; + va_start (args, fmt); + doError (fmt, args); + va_end (args); + } + virtual ~Error () {} + +protected: + void doError (const char *fmt, va_list vargs); + virtual const char *GetErrorName (void) { return "Unknown error"; } +}; + +#define CREATE_ERROR(err, berr, name) \ + class err : public berr \ + { \ +public: \ + err () {} \ + err (const char *fmt, ...) \ + { \ + va_list args; \ + va_start (args, fmt); \ + doError (fmt, args); \ + va_end (args); \ + } \ +protected: \ + virtual const char *GetErrorName (void) { return name; } \ + } + +CREATE_ERROR (FatalError, Error, "unknown FatalError"); +CREATE_ERROR (OutOfMemoryError, FatalError, "OutOfMemoryError"); +CREATE_ERROR (DevError, FatalError, "DevError"); +CREATE_ERROR (RunTimeError, FatalError, "RunTimeError"); + +CREATE_ERROR (RecoverableError, Error, "unknown RecoverableError"); +CREATE_ERROR (BadFDError, RecoverableError, "BadFDError"); +#endif /* __HIPRO_ASYCXX__ERROR_H__ */ Added: trunk/include/asycxx/Factory.h =================================================================== --- trunk/include/asycxx/Factory.h (rev 0) +++ trunk/include/asycxx/Factory.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,38 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__FACTORY_H__ +#define __HIPRO_ASYCXX__FACTORY_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "Error.h" +#include "Reactor.h" +#include "Transport.h" + +class Factory +{ +public: + Factory (Reactor *reactor); + virtual ~Factory (); + virtual Protocol *GetProtocol (Transport *trans) = 0; + +protected: + Reactor *m_Reactor; +}; + +#endif /* __HIPRO_ASYCXX__FACTORY_H__ */ Added: trunk/include/asycxx/GimpleMsgBus.h =================================================================== --- trunk/include/asycxx/GimpleMsgBus.h (rev 0) +++ trunk/include/asycxx/GimpleMsgBus.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,97 @@ +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__GIMPLE_MSG_BUS_H__ +#define __HIPRO_ASYCXX__GIMPLE_MSG_BUS_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <stdint.h> + +#include <deque> + +#include "asycxx.h" +#include "Error.h" +#include "Reactor.h" +#include "Protocol.h" +#include "MsgBus.h" + +/** + * \author Joe Steeve, jo...@hi... + * \class GimpleMsgBus + * + * \brief A down-to-earth simple message-bus + * + * \details This class implements a simple message-bus without any + * bells or whistles. It simply breaks down incoming data into + * messages and passes them on to the MsgHandler. Data submitted to + * this class by the MsgHandler is wrapped with a header and sent to + * the Transport. + */ + +class GimpleMsgBus : public Protocol, public MsgBus +{ + +public: + GimpleMsgBus (Reactor *reactor, Factory *factory, Transport *transport, + MsgHandler *handler); + ~GimpleMsgBus (); + + void DataAvailable (DataBuffer *data); + void ReadError (void); + void WriteError (void); + void ReadTimeout (h_msecs_t excess_time); + void WriteTimeout (h_msecs_t excess_time); + void SendMsg (DataBuffer *msg); + +protected: + Result InitProtocol (void); + +private: + struct GMBPacketHdr_s + { + char signature [4]; /* should contain "GMB\0" */ + uint32_t len; /* length of the xml-packet in + network-byte-order. */ + } __attribute__ ((packed)); + + enum GMBState + { + GMB_WaitingForNewMsg = 0, + GMB_MsgHarvestInProgress + }; + GMBState m_State; + + GMBPacketHdr_s m_Hdr; + size_t m_Hdr_filled; + size_t m_Hdr_left; + + DataBuffer *m_Payload; + size_t m_Payload_filled; + size_t m_Payload_left; + + Result ReadHeader (void *data_ptr, size_t len, size_t& processed); + Result ReadPayload (void *data_ptr, size_t len, size_t& processed); +}; + +#endif /* __HIPRO_ASYCXX__GIMPLE_MSG_BUS_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/include/asycxx/Listener.h =================================================================== --- trunk/include/asycxx/Listener.h (rev 0) +++ trunk/include/asycxx/Listener.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,35 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__LISTENER_H__ +#define __HIPRO_ASYCXX__LISTENER_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "Error.h" +#include "Reactor.h" + +class Listener +{ + +public: + Listener (); + virtual ~Listener (); + +}; + +#endif /* __HIPRO_ASYCXX__LISTENER_H__ */ Added: trunk/include/asycxx/Logger.h =================================================================== --- trunk/include/asycxx/Logger.h (rev 0) +++ trunk/include/asycxx/Logger.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,38 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO__LOGGER_H__ +#define __HIPRO__LOGGER_H__ + +#include <stdarg.h> + +class Logger +{ +public: + Logger (); + ~Logger (); + + void LogThis (const char *fmt, ...); + + void EnableConsole (void); + void DisableConsole (void); + +private: + bool m_logToConsole; + + void LogToConsole (const char *fmt, va_list args); +// void LogToFile (const char *fmt, va_list args); +}; + +#endif // __HIPRO__LOGGER_H__ Added: trunk/include/asycxx/MsgBus.h =================================================================== --- trunk/include/asycxx/MsgBus.h (rev 0) +++ trunk/include/asycxx/MsgBus.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,57 @@ +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__MSG_BUS_H__ +#define __HIPRO_ASYCXX__MSG_BUS_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "DataBuffer.h" + +/** + * \author Joe Steeve, jo...@hi... + * \class MsgBus + * + * \brief The interface of a MsgBus + * + * \details This class requires a MsgHandler to be provided at the + * time of construction. This class assumes ownership of the + * MsgHandler and destroys it when this is destroyed. + */ +class MsgHandler; + +class MsgBus +{ +public: + MsgBus (MsgHandler *handler); + virtual ~MsgBus (); + + virtual void SendMsg (DataBuffer *msg) = 0; + +protected: + MsgHandler *m_Handler; + +}; + +#endif /* __HIPRO_ASYCXX__MSG_BUS_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/include/asycxx/MsgHandler.h =================================================================== --- trunk/include/asycxx/MsgHandler.h (rev 0) +++ trunk/include/asycxx/MsgHandler.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,54 @@ +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__MSG_HANDLER_H__ +#define __HIPRO_ASYCXX__MSG_HANDLER_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "DataBuffer.h" +#include "MsgBus.h" + + +/** + * \author Joe Steeve, jo...@hi... + * \class MsgHandler + * + * \brief The interface of a MsgHandler + */ + +class MsgHandler +{ +public: + MsgHandler (); + virtual ~MsgHandler (); + + void SetMsgBus (MsgBus *bus); + virtual Result GotMsg (DataBuffer *data) = 0; + +protected: + MsgBus *m_Bus; +}; + +#endif /* __HIPRO_ASYCXX__MSG_HANDLER_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/include/asycxx/Protocol.h =================================================================== --- trunk/include/asycxx/Protocol.h (rev 0) +++ trunk/include/asycxx/Protocol.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,57 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__PROTOCOL_H__ +#define __HIPRO_ASYCXX__PROTOCOL_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "Error.h" +#include "Reactor.h" +#include "DataBuffer.h" +#include "Transport.h" +#include "Factory.h" + +#define ASYCXX_DEFAULT_PROTOCOL_BUFSIZE 1024 + +class Protocol +{ +public: + Protocol (Reactor *reactor, Factory *factory, Transport *transport); + virtual ~Protocol (); + + void BuildProtocol (void); + /* Methods exposed for the 'transport' to send msgs to the + Protocol */ + virtual void DataAvailable (DataBuffer *data); + virtual void ConnectionLost (void); + virtual void ReadTimeout (h_msecs_t excess_time); + virtual void ReadError (void); + virtual void WriteTimeout (h_msecs_t excess_time); + virtual void WriteError (void); + +protected: + Reactor *m_Reactor; + Factory *m_Factory; + Transport *m_Transport; + + /* Interface that should be implemented by all protocol + sub-classes */ + virtual Result InitProtocol (void); +}; + +#endif /* __HIPRO_ASYCXX__PROTOCOL_H__ */ Added: trunk/include/asycxx/Reactor.h =================================================================== --- trunk/include/asycxx/Reactor.h (rev 0) +++ trunk/include/asycxx/Reactor.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,89 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__REACTOR_H__ +#define __HIPRO_ASYCXX__REACTOR_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <deque> + +#include "asycxx.h" +#include "Deferred.h" + +#define TIME_SENSITIVITY 200LL + +class Reactor +{ +public: + Reactor (); + virtual ~Reactor (); + + Deferred * OnReadable (int Fd) throw (); + Deferred * OnReadable (int Fd, h_msecs_t timeoutTime) throw (); + Deferred * OnWritable (int Fd) throw (); + Deferred * OnWritable (int Fd, h_msecs_t timeoutTime) throw (); + Deferred * OnTimeElapsed (h_msecs_t timeoutTime) throw (); + void UnRegister (Deferred *deferred) throw (); + + h_timestamp_t CurrentTS (void) { return m_LastAwokenTS; } + void Run (void); + +protected: + class Event + { + public: + Event (); + ~Event (); + + bool m_bDie; + + int m_Fd; + h_msecs_t m_TimeoutTime; + h_timestamp_t m_LastTriggerTS; + h_timestamp_t m_NextTriggerTS; + Deferred m_Deferred; + }; + std::deque<Event *> m_readEvents; + std::deque<Event *> m_writeEvents; + std::deque<Event *> m_timeEvents; + + int m_PendingFDEvents; + virtual void WaitForEvents (void) = 0; + virtual void ProcessFDEvents (void) = 0; + + /** + * \brief The TimeStamp when latest activity happened + * + * \detail This holds the last time-stamp when the reactor was doing + * something. This should be updated by Reactor implementations + * (Select, Epoll, etc.) everytime they wake up to do something + * (attend to file-descriptor activity or handle timeout actions + */ + h_timestamp_t m_LastAwokenTS; + void DoFDEventNotification (Reactor::Event *ev); + void DoFDTimeoutNotification (Reactor::Event *ev); + +private: + void ProcessTimeEvents (void); + void ProcessFDTimeouts (void); + void CleanupEventLists (void); + Deferred * AddToReadEvents (int Fd, h_msecs_t timeoutTime); + Deferred * AddToWriteEvents (int Fd, h_msecs_t timeoutTime); + +}; + +#endif /* __HIPRO_ASYCXX__REACTOR_H__ */ Added: trunk/include/asycxx/RefCounter.h =================================================================== --- trunk/include/asycxx/RefCounter.h (rev 0) +++ trunk/include/asycxx/RefCounter.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,38 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__REF_COUNTER_H__ +#define __HIPRO_ASYCXX__REF_COUNTER_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "Error.h" + +class RefCounter +{ +public: + RefCounter (); + + void Own (void); + void DisOwn (void); + +protected: + virtual ~RefCounter (); + int m__OwnerCount; +}; + +#endif /* __HIPRO_ASYCXX__REF_COUNTER_H__ */ Added: trunk/include/asycxx/SelectReactor.h =================================================================== --- trunk/include/asycxx/SelectReactor.h (rev 0) +++ trunk/include/asycxx/SelectReactor.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,51 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__SELECT_REACTOR_H__ +#define __HIPRO_ASYCXX__SELECT_REACTOR_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <vector> + +#include <sys/select.h> + +#include "asycxx.h" +#include "Reactor.h" + +class SelectReactor :public Reactor +{ + +public: + SelectReactor (void); + ~SelectReactor (void); + +protected: + void WaitForEvents (void); + void ProcessFDEvents (void); + +private: + int m_maxFd; + int m_FdCount; + fd_set m_FdsForReading; + bool m_bReadingFdSetIsEmpty; + fd_set m_FdsForWriting; + bool m_bWritingFdSetIsEmpty; + + void BuildFdSets (void); +}; + +#endif /* __HIPRO_ASYCXX__SELECT_REACTOR_H__ */ Added: trunk/include/asycxx/TCPLLTransport.h =================================================================== --- trunk/include/asycxx/TCPLLTransport.h (rev 0) +++ trunk/include/asycxx/TCPLLTransport.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,37 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__TCP_LL_TRANSPORT_H__ +#define __HIPRO_ASYCXX__TCP_LL_TRANSPORT_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "Reactor.h" +#include "TCPTransport.h" + +class TCPLLTransport : public TCPTransport +{ +public: + TCPLLTransport (Reactor *reactor, int fd); + virtual ~TCPLLTransport (); + + void configureTCPLLNoDelay (void); + void configureTCPLLKeepAlive (int idle_time, int probe_count, + int probe_interval); +}; + +#endif /* __HIPRO_ASYCXX__TCP_LL_TRANSPORT_H__ */ Added: trunk/include/asycxx/TCPListener.h =================================================================== --- trunk/include/asycxx/TCPListener.h (rev 0) +++ trunk/include/asycxx/TCPListener.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,59 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__TCP_LISTENER_H__ +#define __HIPRO_ASYCXX__TCP_LISTENER_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <sys/types.h> +#include <arpa/inet.h> + +#include "asycxx.h" +#include "Error.h" +#include "Listener.h" +#include "Factory.h" +#include "Deferred.h" +#include "Reactor.h" + +class TCPListener : public Listener +{ +public: + + TCPListener (Reactor *reactor, Factory *factory, unsigned short port); + TCPListener (Reactor *reactor, Factory *factory, char *ip, + unsigned short port); + virtual ~TCPListener (); + + void SetupTCPNoDelay (void); + +protected: + Reactor *m_Reactor; + Factory *m_Factory; + Deferred *m_ReactorDeferred; + + int m_Socket; + unsigned short m_BindPort; + in_addr m_BindIPAddr; + char m_BindAddr_str[64]; + bool m_bSetupNoDelay; + + void Init (Reactor *reactor, Factory *factory, + struct in_addr ip_addr, unsigned short port); + static void handleNewConnection (void *obj); +}; + +#endif /* __HIPRO_ASYCXX__TCP_LISTENER_H__ */ Added: trunk/include/asycxx/TCPTransport.h =================================================================== --- trunk/include/asycxx/TCPTransport.h (rev 0) +++ trunk/include/asycxx/TCPTransport.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,41 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C), 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__TCP_TRANSPORT_H__ +#define __HIPRO_ASYCXX__TCP_TRANSPORT_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx.h" +#include "Error.h" +#include "Reactor.h" +#include "DataBuffer.h" +#include "Transport.h" + +class TCPTransport : public Transport +{ +public: + TCPTransport (Reactor *reactor, int fd); + virtual ~TCPTransport (); + +protected: + Result doWrite (void); + Result doRead (DataBuffer *data); + void doDisconnect (void); + +}; + +#endif /* __HIPRO_ASYCXX__TCP_TRANSPORT_H__ */ Added: trunk/include/asycxx/Timer.h =================================================================== --- trunk/include/asycxx/Timer.h (rev 0) +++ trunk/include/asycxx/Timer.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,87 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__TIMER_H__ +#define __HIPRO_ASYCXX__TIMER_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <vector> + +#include "asycxx.h" +#include "Reactor.h" + + +/** + * \brief Timer's callback function type + * + * \param[in] obj The context-object to use for the callback + * \param[in] excess_time The number of milli-seconds elapsed after the + * configured timeout period. Consult the documentation of Timer for + * more information on this. + */ +typedef void (*cbTimerCallback_t)(void *obj, h_msecs_t excess_time); + +#define ASYCXX_TIMER_RESOLUTION 200 + +class Timer +{ +public: + + /** + * \brief Timer type + * + * \detail The timer-type changes the behaviour of the + * timer. Consult the documentation of Timer class for more + * information. + */ + enum TimerType + { + Timer_OneShot, /**< A one-shot timer. Fires only once */ + Timer_Periodic, /**< A periodic timer. Fires periodically */ + }; + + static void Init (Reactor *reactor); + static void UpdateTimers (h_timestamp_t currentTS); + + Timer (h_msecs_t timeoutTime, TimerType type, + cbTimerCallback_t cb_fn, void * cb_obj); + ~Timer (); + void StartTimer (void); + void StopTimer (void); + +private: + static Reactor *m_Reactor; + static std::vector<Timer *> m_Timers; + static h_timestamp_t m_LastUpdatedTS; + static Deferred *m_ReactorDeferred; + static void RegisterTimer (Timer *timer); + static void UnRegisterTimer (Timer *timer); + static void CheckAndFireTimers (void *obj, h_msecs_t excess_time); + + enum TimerType m_Type; + bool m_bTimerActive; + + h_msecs_t m_TimeoutTime; + h_timestamp_t m_LastTriggerTS; + h_timestamp_t m_NextTriggerTS; + + cbTimerCallback_t m_cbFunction; + void * m_cbObject; +}; + + +#endif /* __HIPRO_ASYCXX__TIMER_H__ */ Added: trunk/include/asycxx/Transport.h =================================================================== --- trunk/include/asycxx/Transport.h (rev 0) +++ trunk/include/asycxx/Transport.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,82 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__TRANSPORT_H__ +#define __HIPRO_ASYCXX__TRANSPORT_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <deque> + +#include "asycxx.h" +#include "Error.h" +#include "Reactor.h" +#include "DataBuffer.h" + +class Protocol; + +#define ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE 1024 +class Transport +{ + +public: + Transport (Reactor *reactor, int fd); + virtual ~Transport (); + + /* method to write to the transport */ + void Write (DataBuffer *data); + /* method to disconnect the transport and mark for destruction */ + void LoseConnection (void); + + /* methods to configure the transport */ + void configureReadTimeout (h_msecs_t timeout); + void configureWriteTimeout (h_msecs_t timeout); + void configureReadBufferSize (size_t len); + + /* accessors */ + int FD (void) { return m_Fd; } + Protocol * GetProtocol (void); + void SetProtocol (Protocol *protocol); + +protected: + Reactor *m_Reactor; + Protocol *m_Protocol; + int m_Fd; + + size_t m_readBufSize; + h_msecs_t m_writeTimeout; /* the timeout used for reading */ + Deferred *m_readDefer; /* deferred to handle reading */ + Deferred *m_writeDefer; /* deferred to handle writing */ + std::deque<DataBuffer *> m_writeBuffers; + bool m_bDisconnectAndDie; + + /* methods to be implemented by the derived sub-classes */ + virtual Result doWrite (void) = 0; + virtual Result doRead (DataBuffer *data) = 0; + virtual void doDisconnect (void) = 0; + + /* handler methods */ + static void handleReadable (void *obj); + static void handleReadTimeout (void *obj, h_msecs_t excess_time); + static void handleWritable (void *obj); + static void handleWriteTimeout (void *obj, h_msecs_t excess_time); + +private: + void KillMeIfYouMust (void); + +}; + +#endif /* __HIPRO_ASYCXX__TRANSPORT_H__ */ Added: trunk/include/asycxx/XMLParser.h =================================================================== --- trunk/include/asycxx/XMLParser.h (rev 0) +++ trunk/include/asycxx/XMLParser.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,46 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi... + * + *******************************************************************/ + +#ifndef __HIPRO_ACW__XML_PARSER_H__ +#define __HIPRO_ACW__XML_PARSER_H__ + +#include <vector> +#include <hdb-tinyxml/tinyxml.h> + +#include "asycxx.h" + +class XMLParser +{ +public: + XMLParser (const char *file_name); + ~XMLParser (); + + Result GetValue (const char *xpath, const char **value); + Result GetValue (const char *xpath, int *value); + +protected: + char m_FileName[HMI_CTRL_MAX_URL_LEN]; + TiXmlDocument *m_txDoc; + +private: + + Result ParseXPath (const char *xpath); + + /* used by the xpath parser */ + char m_XPath[HMI_CTRL_MAX_XPATH_LEN]; + std::vector<char *> m_XPathComponents; + +}; + +#endif /* __ACW__XML_PARSER_H__ */ Added: trunk/include/asycxx/asycxx.h =================================================================== --- trunk/include/asycxx/asycxx.h (rev 0) +++ trunk/include/asycxx/asycxx.h 2009-02-20 18:58:54 UTC (rev 4) @@ -0,0 +1,71 @@ +/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ + +#ifndef __ACW__HMI_CTRL_H__ +#define __ACW__HMI_CTRL_H__ + +#include <stdio.h> +#include <stdlib.h> + +#include "Logger.h" + +extern Logger *Log; + +#define cERR(fmt, ...) fprintf (stderr, "[E:%18s:%04d] " fmt "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) +#define ERR(fmt, ...) Log->LogThis ("[%20s:%04d] ERROR: " fmt "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) +#define LOG(fmt, ...) Log->LogThis ("[%20s:%04d] " fmt "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) + +/* log messages to track ctor and dtor */ +#define ctorLOG(cls) Log->LogThis ("CTOR: %s <%p>\n", cls, this) +#define dtorLOG(cls) Log->LogThis ("DTOR: %s <%p>\n", cls, this) + +#define dummyLog(fmt, ...) + +#if HMI_CTRL_VERBOSE_LEVEL >= 1 +#define LOG1 LOG +#else +#define LOG1 dummyLog +#endif + +#if HMI_CTRL_VERBOSE_LEVEL >= 2 +#define LOG2 LOG +#else +#define LOG2 dummyLog +#endif + +#if HMI_CTRL_VERBOSE_LEVEL >= 3 +#define LOG3 LOG +#else +#define LOG3 dummyLog +#endif + +#define ASSERT(x, fmt, ...) \ + { \ + if (!(x)) \ + { \ + THROW (DevError, "assertion failed: %s, " fmt "\n", \ + #x, ##__VA_ARGS__); \ + } \ + } + +enum Result + { + Result_Success = 0, + Result_Error, + Result_Pending, + Result_NotFound, + }; + +typedef unsigned char u8_t; +typedef long long h_msecs_t; +typedef long long h_timestamp_t; + +h_msecs_t GetCurrentTimeStamp (void); +void SetFDAsNonBlocking (int fd); + +#define HMI_CTRL_MAX_URL_LEN 512 +#define HMI_CTRL_MAX_XPATH_LEN 1024 + +#endif /* __ACW__HMI_CTRL_H__ */ Deleted: trunk/src/App.cxx =================================================================== --- trunk/src/App.cxx 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/src/App.cxx 2009-02-20 18:58:54 UTC (rev 4) @@ -1,113 +0,0 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <hmi-ctrl-config.h> -#endif - -#include <string.h> -#include <errno.h> - -#include "hmi-ctrl.h" -#include "App.h" -#include "Config.h" -#include "SpindleManager.h" - - -App* App::m_App = NULL; - -/** - * \brief Method to get the App object - * - * \details This is a static method which should be used to get the - * App object. More information on the App class is provided in the - * class documentation. - */ -App* -App::GetApp (void) -{ - if (m_App == NULL) - { - m_App = new App(); - } - return m_App; -} - - -/** - * \brief constructor - */ -App::App () -{ - m_Config = NULL; -} - - -/** - * \brief destructor - */ -App::~App () -{ - if (m_Config != NULL) - { - delete m_Config; - } - - if (m_SpindleManager != NULL) - { - delete m_SpindleManager; - } -} - - -/** - * \brief Initialize the App - * - * \param[in] config_file The configuration file to use - * - * \details This method initializes the App object. This should be - * called only once. When called the second time, this method will - * return a Result_Error. - */ -Result -App::Init (const char *config_file) -{ - /* Load and initialize the configuration file */ - m_Config = new Config(config_file); - - /* Load the Spindle-manager */ - m_SpindleManager = new SpindleManager (); - - /* TBD: Load the Doffer-manager */ - - /* TBD: Load the HStock-manager */ - - return Result_Success; -} - - -Config* -App::GetConfig (void) -{ - ASSERT ((m_Config != NULL), "cannot get Config before ::Init"); - return m_Config; -} - -SpindleManager* -App::GetSpindleManager (void) -{ - ASSERT ((m_SpindleManager != NULL), - "cannot get SpindleManager before ::Init"); - return m_SpindleManager; -} Deleted: trunk/src/App.h =================================================================== --- trunk/src/App.h 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/src/App.h 2009-02-20 18:58:54 UTC (rev 4) @@ -1,47 +0,0 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifndef __HIPRO_ACW__APP_H__ -#define __HIPRO_ACW__APP_H__ - -#ifdef HAVE_CONFIG_H -#include <hmi-ctrl-config.h> -#endif - -#include "hmi-ctrl.h" -#include "Config.h" - -class SpindleManager; - -class App -{ -public: - ~App (); - - static App* GetApp (void); - Result Init (const char *config_file); - - Config* GetConfig (void); - SpindleManager* GetSpindleManager (void); - -private: - App (); - - static App *m_App; - Config *m_Config; - SpindleManager *m_SpindleManager; - -}; - -#endif Deleted: trunk/src/Config.cxx =================================================================== --- trunk/src/Config.cxx 2009-02-05 20:57:10 UTC (rev 3) +++ trunk/src/Config.cxx 2009-02-20 18:58:54 UTC (rev 4) @@ -1,217 +0,0 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi... - * - *******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <hmi-ctrl-config.h> -#endif - -#include "hmi-ctrl.h" -#include "Config.h" -#include "Error.h" - - -/** - * \brief constructor - */ -Config::Config (const char *file_name) : - XMLParser (file_name) -{ - memset ((void *)&m_SpindleIp, 0, CONFIG_IP_LEN); - memset ((void *)&m_DofferIp, 0, CONFIG_IP_LEN); - memset ((void *)&m_HStockIp, 0, CONFIG_IP_LEN); - m_SpindlePort = 10000; - m_DofferPort = 10001; - m_HStockPort = 10002; - - memset ((void *)&m_LocalRPCIp, 0, CONFIG_IP_LEN); - memset ((void *)&m_PublicRPCIp, 0, CONFIG_IP_LEN); - m_LocalRPCPort = 10010; - m_PublicRPCPort = 10011; -} - - -/** - * \brief destructor - */ -Config::~Config () -{ - -} - - -const int -Config::GetSpindleCount (void) -{ - int value; - Result ret; - - ret = GetValue ("/hmi-ctrl-config/spindle-count", &value); - if (ret != Result_Success) - { - ERR ("failed to get /hmi-ctrl-config/spindle-count. Bad config-file?"); - return 0; - } - if (value <= 0) - { - THROW (RunTimeError, - "/hmi-ctrl-config/spindle-count should be greater than 0"); - } - - return value; -} - - -void -Config::GetSpindleNetCfg (char **Ip, int *Port) -{ - Result ret; - - const char *ip; - int port; - - ret = GetValue ("/hmi-ctrl-config/spindle-ctrl/ip", &ip); - if (ret != Result_Success) - { - ERR ("failed to get /hmi-ctrl-config/spindle-ctrl/ip. " - "Assuming default"); - strcpy (m_SpindleIp, "0.0.0.0"); - } - - ret = GetValue ("/hmi-ctrl-config/spindle-ctrl/port", &port); - if (ret != Result_Success) - { - ERR ("failed to get /hmi-ctrl-config/spindle-ctrl/port. " - "Assuming default"); - m_SpindlePort = 10000; - } - - *Port = m_SpindlePort; - *Ip = m_SpindleIp; -} - - -void -Config::GetDofferNetCfg (char **Ip, int *Port) -{ - Result ret; - - const char *ip; - int port; - - ret = GetValue ("/hmi-ctrl-config/doffer-ctrl/ip", &ip); - if (ret != Result_Success) - { - ERR ("failed to get /hmi-ctrl-config/doffer-ctrl/ip. " - "Assuming default"); - strcpy (m_DofferIp, "0.0.0.0"); - } - - ret = GetValue ("/hmi-ctrl-config/doffer-ctrl/port", &port); - if (ret != Result_Success) - { - ERR ("failed to get /hmi-ctrl-config/doffer-ctrl/port. " - "Assuming default"); - m_DofferPort = 10001; - } - - *Port = m_DofferPort; - *Ip = m_DofferIp; -} - - -void -Config::GetHStockNetCfg (char **Ip, int *Port) -{ - Result ret; - - const char *ip; - int port; - - ret = GetValue ("/hmi-ctrl-config/hstock-ctrl/ip", &ip); - if (ret != Result_Success) - { - ERR ("failed to get /hmi-ctrl-config/hstock-ctrl/ip. " - "Assuming default"); - strcpy (m_HStockIp, "0.0.0.0"); - } - - ret = GetValue ("/hmi-ctrl-config/hstock-ctrl/port", &port); - if (ret != Result_Success) - { - ERR ("fa... [truncated message content] |
From: <joe...@us...> - 2009-03-12 09:35:29
|
Revision: 6 http://asycxx.svn.sourceforge.net/asycxx/?rev=6&view=rev Author: joe_steeve Date: 2009-03-12 09:35:26 +0000 (Thu, 12 Mar 2009) Log Message: ----------- split asycxx internal stuff into the private asycxx-common.h The installed ascyxx.h should not contain things that are internal to asycxx. Hence moved asycxx specific content into a private asycxx-common.h. the include/asycxx.h should be used as a one time header to include all parts of asycxx. From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/configure.ac trunk/include/asycxx/DataBuffer.h trunk/include/asycxx/Deferred.h trunk/include/asycxx/Error.h trunk/include/asycxx/Factory.h trunk/include/asycxx/GimpleMsgBus.h trunk/include/asycxx/Listener.h trunk/include/asycxx/MsgBus.h trunk/include/asycxx/MsgHandler.h trunk/include/asycxx/Protocol.h trunk/include/asycxx/Reactor.h trunk/include/asycxx/RefCounter.h trunk/include/asycxx/SelectReactor.h trunk/include/asycxx/TCPLLTransport.h trunk/include/asycxx/TCPListener.h trunk/include/asycxx/TCPTransport.h trunk/include/asycxx/Timer.h trunk/include/asycxx/Transport.h trunk/include/asycxx/XMLParser.h trunk/include/asycxx/asycxx.h trunk/src/DataBuffer.cxx trunk/src/Error.cxx trunk/src/Factory.cxx trunk/src/GimpleMsgBus.cxx trunk/src/Listener.cxx trunk/src/MsgBus.cxx trunk/src/MsgHandler.cxx trunk/src/Protocol.cxx trunk/src/Reactor.cxx trunk/src/RefCounter.cxx trunk/src/SelectReactor.cxx trunk/src/TCPLLTransport.cxx trunk/src/TCPListener.cxx trunk/src/TCPTransport.cxx trunk/src/Timer.cxx trunk/src/Transport.cxx trunk/src/XMLParser.cxx trunk/src/core.cxx Added Paths: ----------- trunk/include/asycxx/_asycxx.h trunk/src/asycxx-common.h Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/configure.ac 2009-03-12 09:35:26 UTC (rev 6) @@ -94,5 +94,5 @@ src/MsgHandler.h:include/asycxx/MsgHandler.h src/GimpleMsgBus.h:include/asycxx/GimpleMsgBus.h src/XMLParser.h:include/asycxx/XMLParser.h - src/asycxx.h:include/asycxx/asycxx.h) + src/_asycxx.h:include/asycxx/_asycxx.h) AC_OUTPUT Modified: trunk/include/asycxx/DataBuffer.h =================================================================== --- trunk/include/asycxx/DataBuffer.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/DataBuffer.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,9 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" +#include <sys/types.h> + +#include "_asycxx.h" #include "RefCounter.h" class DataBuffer : public RefCounter Modified: trunk/include/asycxx/Deferred.h =================================================================== --- trunk/include/asycxx/Deferred.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Deferred.h 2009-03-12 09:35:26 UTC (rev 6) @@ -15,7 +15,6 @@ #ifndef __HIPRO_ASYCXX__DEFERRED_H__ #define __HIPRO_ASYCXX__DEFERRED_H__ -#include "asycxx.h" #include "Error.h" typedef void (*cbDeferredOnEvent_t) (void *obj); Modified: trunk/include/asycxx/Error.h =================================================================== --- trunk/include/asycxx/Error.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Error.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,7 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" +#include <stdarg.h> #define THROW(x, fmt, ...) throw x("[%s:%d] " fmt "\n", \ __FILE__, __LINE__, ##__VA_ARGS__) Modified: trunk/include/asycxx/Factory.h =================================================================== --- trunk/include/asycxx/Factory.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Factory.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "Error.h" #include "Reactor.h" #include "Transport.h" Modified: trunk/include/asycxx/GimpleMsgBus.h =================================================================== --- trunk/include/asycxx/GimpleMsgBus.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/GimpleMsgBus.h 2009-03-12 09:35:26 UTC (rev 6) @@ -21,7 +21,6 @@ #include <deque> -#include "asycxx.h" #include "Error.h" #include "Reactor.h" #include "Protocol.h" Modified: trunk/include/asycxx/Listener.h =================================================================== --- trunk/include/asycxx/Listener.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Listener.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "Error.h" #include "Reactor.h" Modified: trunk/include/asycxx/MsgBus.h =================================================================== --- trunk/include/asycxx/MsgBus.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/MsgBus.h 2009-03-12 09:35:26 UTC (rev 6) @@ -17,7 +17,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "DataBuffer.h" /** Modified: trunk/include/asycxx/MsgHandler.h =================================================================== --- trunk/include/asycxx/MsgHandler.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/MsgHandler.h 2009-03-12 09:35:26 UTC (rev 6) @@ -17,7 +17,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "DataBuffer.h" #include "MsgBus.h" Modified: trunk/include/asycxx/Protocol.h =================================================================== --- trunk/include/asycxx/Protocol.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Protocol.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "Error.h" #include "Reactor.h" #include "DataBuffer.h" Modified: trunk/include/asycxx/Reactor.h =================================================================== --- trunk/include/asycxx/Reactor.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Reactor.h 2009-03-12 09:35:26 UTC (rev 6) @@ -21,7 +21,7 @@ #include <deque> -#include "asycxx.h" +#include "_asycxx.h" #include "Deferred.h" #define TIME_SENSITIVITY 200LL Modified: trunk/include/asycxx/RefCounter.h =================================================================== --- trunk/include/asycxx/RefCounter.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/RefCounter.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "Error.h" class RefCounter Modified: trunk/include/asycxx/SelectReactor.h =================================================================== --- trunk/include/asycxx/SelectReactor.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/SelectReactor.h 2009-03-12 09:35:26 UTC (rev 6) @@ -23,7 +23,6 @@ #include <sys/select.h> -#include "asycxx.h" #include "Reactor.h" class SelectReactor :public Reactor Modified: trunk/include/asycxx/TCPLLTransport.h =================================================================== --- trunk/include/asycxx/TCPLLTransport.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/TCPLLTransport.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "Reactor.h" #include "TCPTransport.h" Modified: trunk/include/asycxx/TCPListener.h =================================================================== --- trunk/include/asycxx/TCPListener.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/TCPListener.h 2009-03-12 09:35:26 UTC (rev 6) @@ -22,7 +22,6 @@ #include <sys/types.h> #include <arpa/inet.h> -#include "asycxx.h" #include "Error.h" #include "Listener.h" #include "Factory.h" Modified: trunk/include/asycxx/TCPTransport.h =================================================================== --- trunk/include/asycxx/TCPTransport.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/TCPTransport.h 2009-03-12 09:35:26 UTC (rev 6) @@ -19,7 +19,6 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" #include "Error.h" #include "Reactor.h" #include "DataBuffer.h" Modified: trunk/include/asycxx/Timer.h =================================================================== --- trunk/include/asycxx/Timer.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Timer.h 2009-03-12 09:35:26 UTC (rev 6) @@ -21,7 +21,6 @@ #include <vector> -#include "asycxx.h" #include "Reactor.h" Modified: trunk/include/asycxx/Transport.h =================================================================== --- trunk/include/asycxx/Transport.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/Transport.h 2009-03-12 09:35:26 UTC (rev 6) @@ -21,7 +21,6 @@ #include <deque> -#include "asycxx.h" #include "Error.h" #include "Reactor.h" #include "DataBuffer.h" Modified: trunk/include/asycxx/XMLParser.h =================================================================== --- trunk/include/asycxx/XMLParser.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/XMLParser.h 2009-03-12 09:35:26 UTC (rev 6) @@ -18,7 +18,7 @@ #include <vector> #include <hdb-tinyxml/tinyxml.h> -#include "asycxx.h" +#include "_asycxx.h" class XMLParser { Copied: trunk/include/asycxx/_asycxx.h (from rev 5, trunk/src/MsgHandler.cxx) =================================================================== --- trunk/include/asycxx/_asycxx.h (rev 0) +++ trunk/include/asycxx/_asycxx.h 2009-03-12 09:35:26 UTC (rev 6) @@ -0,0 +1,38 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi... + * + *******************************************************************/ + +#ifndef __HIPRO_ACW___ASYCXX_H__ +#define __HIPRO_ACW___ASYCXX_H__ + +enum Result + { + Result_Success = 0, + Result_Error, + Result_Pending, + Result_NotFound, + }; + +typedef unsigned char u8_t; +typedef long long h_msecs_t; +typedef long long h_timestamp_t; + +#endif /* __HIPRO_ACW___ASYCXX_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/asycxx.h =================================================================== --- trunk/include/asycxx/asycxx.h 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/include/asycxx/asycxx.h 2009-03-12 09:35:26 UTC (rev 6) @@ -1,71 +1,28 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ -#ifndef __ACW__HMI_CTRL_H__ -#define __ACW__HMI_CTRL_H__ +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi... + * + *******************************************************************/ -#include <stdio.h> -#include <stdlib.h> +#ifndef __HIPRO_ACW__ASYCXX_H__ +#define __HIPRO_ACW__ASYCXX_H__ -#include "Logger.h" +#include "_asycxx.h" -extern Logger *Log; +#endif /* __HIPRO_ACW__XML_PARSER_H__ */ -#define cERR(fmt, ...) fprintf (stderr, "[E:%18s:%04d] " fmt "\n", \ - __FILE__, __LINE__, ##__VA_ARGS__) -#define ERR(fmt, ...) Log->LogThis ("[%20s:%04d] ERROR: " fmt "\n", \ - __FILE__, __LINE__, ##__VA_ARGS__) -#define LOG(fmt, ...) Log->LogThis ("[%20s:%04d] " fmt "\n", \ - __FILE__, __LINE__, ##__VA_ARGS__) - -/* log messages to track ctor and dtor */ -#define ctorLOG(cls) Log->LogThis ("CTOR: %s <%p>\n", cls, this) -#define dtorLOG(cls) Log->LogThis ("DTOR: %s <%p>\n", cls, this) - -#define dummyLog(fmt, ...) - -#if HMI_CTRL_VERBOSE_LEVEL >= 1 -#define LOG1 LOG -#else -#define LOG1 dummyLog -#endif - -#if HMI_CTRL_VERBOSE_LEVEL >= 2 -#define LOG2 LOG -#else -#define LOG2 dummyLog -#endif - -#if HMI_CTRL_VERBOSE_LEVEL >= 3 -#define LOG3 LOG -#else -#define LOG3 dummyLog -#endif - -#define ASSERT(x, fmt, ...) \ - { \ - if (!(x)) \ - { \ - THROW (DevError, "assertion failed: %s, " fmt "\n", \ - #x, ##__VA_ARGS__); \ - } \ - } - -enum Result - { - Result_Success = 0, - Result_Error, - Result_Pending, - Result_NotFound, - }; - -typedef unsigned char u8_t; -typedef long long h_msecs_t; -typedef long long h_timestamp_t; - -h_msecs_t GetCurrentTimeStamp (void); -void SetFDAsNonBlocking (int fd); - -#define HMI_CTRL_MAX_URL_LEN 512 -#define HMI_CTRL_MAX_XPATH_LEN 1024 - -#endif /* __ACW__HMI_CTRL_H__ */ +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/DataBuffer.cxx =================================================================== --- trunk/src/DataBuffer.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/DataBuffer.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -16,6 +16,9 @@ #include <asycxx-config.h> #endif +#include <cstdlib> + +#include "asycxx-common.h" #include "DataBuffer.h" Modified: trunk/src/Error.cxx =================================================================== --- trunk/src/Error.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/Error.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -20,7 +20,7 @@ #include <stdlib.h> #include <execinfo.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" void Modified: trunk/src/Factory.cxx =================================================================== --- trunk/src/Factory.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/Factory.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -17,7 +17,7 @@ #endif -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Reactor.h" #include "Factory.h" Modified: trunk/src/GimpleMsgBus.cxx =================================================================== --- trunk/src/GimpleMsgBus.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/GimpleMsgBus.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -17,7 +17,7 @@ #include <string.h> #include <arpa/inet.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Transport.h" Modified: trunk/src/Listener.cxx =================================================================== --- trunk/src/Listener.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/Listener.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -17,7 +17,7 @@ #endif -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Listener.h" Modified: trunk/src/MsgBus.cxx =================================================================== --- trunk/src/MsgBus.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/MsgBus.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -14,7 +14,7 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "MsgBus.h" #include "MsgHandler.h" Modified: trunk/src/MsgHandler.cxx =================================================================== --- trunk/src/MsgHandler.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/MsgHandler.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -14,7 +14,7 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "MsgHandler.h" Modified: trunk/src/Protocol.cxx =================================================================== --- trunk/src/Protocol.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/Protocol.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -17,7 +17,7 @@ #endif -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Protocol.h" Modified: trunk/src/Reactor.cxx =================================================================== --- trunk/src/Reactor.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/Reactor.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -27,7 +27,7 @@ #include <unistd.h> #include <exception> -#include "asycxx.h" +#include "asycxx-common.h" #include "Reactor.h" #include "Deferred.h" Modified: trunk/src/RefCounter.cxx =================================================================== --- trunk/src/RefCounter.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/RefCounter.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -16,7 +16,7 @@ #include <asycxx-config.h> #endif -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "RefCounter.h" Modified: trunk/src/SelectReactor.cxx =================================================================== --- trunk/src/SelectReactor.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/SelectReactor.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -20,7 +20,7 @@ #include <errno.h> #include <string.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "SelectReactor.h" Modified: trunk/src/TCPLLTransport.cxx =================================================================== --- trunk/src/TCPLLTransport.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/TCPLLTransport.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -23,7 +23,7 @@ #include <netinet/in.h> #include <netinet/tcp.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Protocol.h" #include "TCPLLTransport.h" Modified: trunk/src/TCPListener.cxx =================================================================== --- trunk/src/TCPListener.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/TCPListener.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -26,7 +26,7 @@ #include <errno.h> #include <unistd.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Factory.h" #include "Protocol.h" Modified: trunk/src/TCPTransport.cxx =================================================================== --- trunk/src/TCPTransport.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/TCPTransport.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -24,7 +24,7 @@ #include <sys/socket.h> #include <errno.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Protocol.h" #include "TCPTransport.h" Modified: trunk/src/Timer.cxx =================================================================== --- trunk/src/Timer.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/Timer.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -44,7 +44,7 @@ #include <vector> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Timer.h" Modified: trunk/src/Transport.cxx =================================================================== --- trunk/src/Transport.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/Transport.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -18,7 +18,7 @@ #include <unistd.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Transport.h" #include "Protocol.h" Modified: trunk/src/XMLParser.cxx =================================================================== --- trunk/src/XMLParser.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/XMLParser.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -20,8 +20,8 @@ #include <stdlib.h> #include <errno.h> +#include "asycxx-common.h" #include "XMLParser.h" -#include "asycxx.h" #include "Error.h" #include <hdb-tinyxml/tinyxml.h> Copied: trunk/src/asycxx-common.h (from rev 5, trunk/include/asycxx/asycxx.h) =================================================================== --- trunk/src/asycxx-common.h (rev 0) +++ trunk/src/asycxx-common.h 2009-03-12 09:35:26 UTC (rev 6) @@ -0,0 +1,80 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __ACW_ASYCXX__ASYCXX_COMMON_H__ +#define __ACW_ASYCXX__ASYCXX_COMMON_H__ + +#include <stdio.h> +#include <stdlib.h> + +#include "_asycxx.h" +#include "Logger.h" + +extern Logger *Log; + +#define cERR(fmt, ...) fprintf (stderr, "[E:%18s:%04d] " fmt "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) +#define ERR(fmt, ...) Log->LogThis ("[%20s:%04d] ERROR: " fmt "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) +#define LOG(fmt, ...) Log->LogThis ("[%20s:%04d] " fmt "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) + +/* log messages to track ctor and dtor */ +#define ctorLOG(cls) Log->LogThis ("CTOR: %s <%p>\n", cls, this) +#define dtorLOG(cls) Log->LogThis ("DTOR: %s <%p>\n", cls, this) + +#define dummyLog(fmt, ...) + +#if HMI_CTRL_VERBOSE_LEVEL >= 1 +#define LOG1 LOG +#else +#define LOG1 dummyLog +#endif + +#if HMI_CTRL_VERBOSE_LEVEL >= 2 +#define LOG2 LOG +#else +#define LOG2 dummyLog +#endif + +#if HMI_CTRL_VERBOSE_LEVEL >= 3 +#define LOG3 LOG +#else +#define LOG3 dummyLog +#endif + +#define ASSERT(x, fmt, ...) \ + { \ + if (!(x)) \ + { \ + THROW (DevError, "assertion failed: %s, " fmt "\n", \ + #x, ##__VA_ARGS__); \ + } \ + } + +h_msecs_t GetCurrentTimeStamp (void); +void SetFDAsNonBlocking (int fd); + +#define HMI_CTRL_MAX_URL_LEN 512 +#define HMI_CTRL_MAX_XPATH_LEN 1024 + +#endif /* __ACW_ASYCXX__ASYCXX_COMMON_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/core.cxx =================================================================== --- trunk/src/core.cxx 2009-02-20 19:18:20 UTC (rev 5) +++ trunk/src/core.cxx 2009-03-12 09:35:26 UTC (rev 6) @@ -22,7 +22,7 @@ #include <unistd.h> #include <fcntl.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" h_msecs_t This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-03-12 09:40:49
|
Revision: 7 http://asycxx.svn.sourceforge.net/asycxx/?rev=7&view=rev Author: joe_steeve Date: 2009-03-12 09:40:41 +0000 (Thu, 12 Mar 2009) Log Message: ----------- converted Emacs modeline variables to Emacs file local variables From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/DataBuffer.h trunk/include/asycxx/Deferred.h trunk/include/asycxx/Error.h trunk/include/asycxx/Factory.h trunk/include/asycxx/GimpleMsgBus.h trunk/include/asycxx/Listener.h trunk/include/asycxx/Logger.h trunk/include/asycxx/MsgBus.h trunk/include/asycxx/MsgHandler.h trunk/include/asycxx/Protocol.h trunk/include/asycxx/Reactor.h trunk/include/asycxx/RefCounter.h trunk/include/asycxx/SelectReactor.h trunk/include/asycxx/TCPLLTransport.h trunk/include/asycxx/TCPListener.h trunk/include/asycxx/TCPTransport.h trunk/include/asycxx/Timer.h trunk/include/asycxx/Transport.h trunk/include/asycxx/XMLParser.h trunk/src/DataBuffer.cxx trunk/src/Deferred.cxx trunk/src/Error.cxx trunk/src/Factory.cxx trunk/src/GimpleMsgBus.cxx trunk/src/Listener.cxx trunk/src/Logger.cxx trunk/src/MsgHandler.cxx trunk/src/Protocol.cxx trunk/src/Reactor.cxx trunk/src/RefCounter.cxx trunk/src/SelectReactor.cxx trunk/src/TCPLLTransport.cxx trunk/src/TCPListener.cxx trunk/src/TCPTransport.cxx trunk/src/Timer.cxx trunk/src/Transport.cxx trunk/src/XMLParser.cxx trunk/src/core.cxx Modified: trunk/include/asycxx/DataBuffer.h =================================================================== --- trunk/include/asycxx/DataBuffer.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/DataBuffer.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -58,3 +57,12 @@ }; #endif /* __HIPRO_ASYCXX__DATA_BUFFER_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/Deferred.h =================================================================== --- trunk/include/asycxx/Deferred.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Deferred.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -49,3 +48,12 @@ }; #endif // __HIPRO_ASYCXX__DEFERRED_H__ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/Error.h =================================================================== --- trunk/include/asycxx/Error.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Error.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -67,4 +66,14 @@ CREATE_ERROR (RecoverableError, Error, "unknown RecoverableError"); CREATE_ERROR (BadFDError, RecoverableError, "BadFDError"); + #endif /* __HIPRO_ASYCXX__ERROR_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/Factory.h =================================================================== --- trunk/include/asycxx/Factory.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Factory.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -35,3 +34,12 @@ }; #endif /* __HIPRO_ASYCXX__FACTORY_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/GimpleMsgBus.h =================================================================== --- trunk/include/asycxx/GimpleMsgBus.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/GimpleMsgBus.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,3 +1,4 @@ + /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All * rights reserved. Modified: trunk/include/asycxx/Listener.h =================================================================== --- trunk/include/asycxx/Listener.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Listener.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -32,3 +31,12 @@ }; #endif /* __HIPRO_ASYCXX__LISTENER_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/Logger.h =================================================================== --- trunk/include/asycxx/Logger.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Logger.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -36,3 +35,12 @@ }; #endif // __HIPRO__LOGGER_H__ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/MsgBus.h =================================================================== --- trunk/include/asycxx/MsgBus.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/MsgBus.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,3 +1,4 @@ + /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All * rights reserved. Modified: trunk/include/asycxx/MsgHandler.h =================================================================== --- trunk/include/asycxx/MsgHandler.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/MsgHandler.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,3 +1,4 @@ + /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All * rights reserved. Modified: trunk/include/asycxx/Protocol.h =================================================================== --- trunk/include/asycxx/Protocol.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Protocol.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -54,3 +53,12 @@ }; #endif /* __HIPRO_ASYCXX__PROTOCOL_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/Reactor.h =================================================================== --- trunk/include/asycxx/Reactor.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Reactor.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -87,3 +86,12 @@ }; #endif /* __HIPRO_ASYCXX__REACTOR_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/RefCounter.h =================================================================== --- trunk/include/asycxx/RefCounter.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/RefCounter.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -35,3 +34,12 @@ }; #endif /* __HIPRO_ASYCXX__REF_COUNTER_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/SelectReactor.h =================================================================== --- trunk/include/asycxx/SelectReactor.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/SelectReactor.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -48,3 +47,12 @@ }; #endif /* __HIPRO_ASYCXX__SELECT_REACTOR_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/TCPLLTransport.h =================================================================== --- trunk/include/asycxx/TCPLLTransport.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/TCPLLTransport.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -34,3 +33,12 @@ }; #endif /* __HIPRO_ASYCXX__TCP_LL_TRANSPORT_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/TCPListener.h =================================================================== --- trunk/include/asycxx/TCPListener.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/TCPListener.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -56,3 +55,12 @@ }; #endif /* __HIPRO_ASYCXX__TCP_LISTENER_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/TCPTransport.h =================================================================== --- trunk/include/asycxx/TCPTransport.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/TCPTransport.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C), 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -38,3 +37,12 @@ }; #endif /* __HIPRO_ASYCXX__TCP_TRANSPORT_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/Timer.h =================================================================== --- trunk/include/asycxx/Timer.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Timer.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -84,3 +83,12 @@ #endif /* __HIPRO_ASYCXX__TIMER_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/Transport.h =================================================================== --- trunk/include/asycxx/Transport.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/Transport.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -79,3 +78,12 @@ }; #endif /* __HIPRO_ASYCXX__TRANSPORT_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/include/asycxx/XMLParser.h =================================================================== --- trunk/include/asycxx/XMLParser.h 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/include/asycxx/XMLParser.h 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -44,3 +43,12 @@ }; #endif /* __ACW__XML_PARSER_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/DataBuffer.cxx =================================================================== --- trunk/src/DataBuffer.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/DataBuffer.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -144,3 +143,12 @@ ptr = (void *)((unsigned int)m_Data + m_ProcessedLen); return ptr; } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Deferred.cxx =================================================================== --- trunk/src/Deferred.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Deferred.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -145,3 +144,12 @@ m_cbOnTimeout (m_cbOnTimeout_obj, excess_time); } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Error.cxx =================================================================== --- trunk/src/Error.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Error.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -55,3 +54,12 @@ ("\n ----------------------------------------------------------------\n"); free (stsyms); } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Factory.cxx =================================================================== --- trunk/src/Factory.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Factory.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -42,3 +41,12 @@ Factory::~Factory () { } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/GimpleMsgBus.cxx =================================================================== --- trunk/src/GimpleMsgBus.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/GimpleMsgBus.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,3 +1,4 @@ + /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All * rights reserved. Modified: trunk/src/Listener.cxx =================================================================== --- trunk/src/Listener.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Listener.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -31,3 +30,12 @@ { } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Logger.cxx =================================================================== --- trunk/src/Logger.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Logger.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -84,3 +83,12 @@ vfprintf (stderr, fmt, args); } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/MsgHandler.cxx =================================================================== --- trunk/src/MsgHandler.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/MsgHandler.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,3 +1,4 @@ + /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All * rights reserved. Modified: trunk/src/Protocol.cxx =================================================================== --- trunk/src/Protocol.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Protocol.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -100,3 +99,12 @@ { LOG3 ("write caused error out but not handled. lame protocol"); } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Reactor.cxx =================================================================== --- trunk/src/Reactor.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Reactor.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -553,3 +552,12 @@ } } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/RefCounter.cxx =================================================================== --- trunk/src/RefCounter.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/RefCounter.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -60,3 +59,12 @@ delete this; } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/SelectReactor.cxx =================================================================== --- trunk/src/SelectReactor.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/SelectReactor.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -176,3 +175,12 @@ } } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/TCPLLTransport.cxx =================================================================== --- trunk/src/TCPLLTransport.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/TCPLLTransport.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -147,3 +146,12 @@ } } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/TCPListener.cxx =================================================================== --- trunk/src/TCPListener.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/TCPListener.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -243,3 +242,12 @@ { m_bSetupNoDelay = true; } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/TCPTransport.cxx =================================================================== --- trunk/src/TCPTransport.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/TCPTransport.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -162,3 +161,12 @@ // /** \todo using setsockopt should configure TCP_KEEPINTVL */ // } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Timer.cxx =================================================================== --- trunk/src/Timer.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Timer.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -265,3 +264,12 @@ UnRegisterTimer (this); } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Transport.cxx =================================================================== --- trunk/src/Transport.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/Transport.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -349,3 +348,12 @@ /* notify write-timeout to the protocol */ trans->m_Protocol->WriteTimeout (excess_time); } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/XMLParser.cxx =================================================================== --- trunk/src/XMLParser.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/XMLParser.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -286,3 +285,12 @@ return Result_Success; } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/core.cxx =================================================================== --- trunk/src/core.cxx 2009-03-12 09:35:26 UTC (rev 6) +++ trunk/src/core.cxx 2009-03-12 09:40:41 UTC (rev 7) @@ -1,4 +1,3 @@ -/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4; -*- */ /******************************************************************** * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All @@ -68,3 +67,12 @@ } } } + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-03-12 09:45:27
|
Revision: 9 http://asycxx.svn.sourceforge.net/asycxx/?rev=9&view=rev Author: joe_steeve Date: 2009-03-12 09:45:10 +0000 (Thu, 12 Mar 2009) Log Message: ----------- removed XMLParser.* this is not relevant to asycxx * removed references of XMLParser.* from the build system * removed the dependance on hdb-tinyxml * added a .gitignore to ignore un-necessary stuff From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/configure.ac trunk/src/Makefile.am Added Paths: ----------- trunk/.gitignore Removed Paths: ------------- trunk/include/asycxx/XMLParser.h trunk/src/XMLParser.cxx Added: trunk/.gitignore =================================================================== --- trunk/.gitignore (rev 0) +++ trunk/.gitignore 2009-03-12 09:45:10 UTC (rev 9) @@ -0,0 +1,39 @@ +*~ +*.o +Makefile +Makefile.in +*.lo +stamp-h1 +aclocal.m4 +config.* +.deps +.libs +missing +ltmain.sh +install-sh +libtool +autom4te.cache +*.pc +asycxx-config.h +configure +depcomp +*.la +src/DataBuffer.h +src/Deferred.h +src/Error.h +src/Factory.h +src/GimpleMsgBus.h +src/Listener.h +src/Logger.h +src/MsgBus.h +src/MsgHandler.h +src/Protocol.h +src/Reactor.h +src/RefCounter.h +src/SelectReactor.h +src/TCPLLTransport.h +src/TCPListener.h +src/TCPTransport.h +src/Timer.h +src/Transport.h +src/_asycxx.h Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-03-12 09:42:31 UTC (rev 8) +++ trunk/configure.ac 2009-03-12 09:45:10 UTC (rev 9) @@ -6,10 +6,10 @@ CFLAGS="-Wall -Werror" CXXFLAGS="-Wall -Werror" -dnl setup the debug level +dnl setup the verbosity level AC_ARG_WITH(verbose-level, AS_HELP_STRING([--with-verbose-level], - [Use the given debug level (0 to 3) 0=disable]), + [Use the given verbosity level (0 to 3) 0=disable]), [asycxx_with_verbose_level=$withval],) if test $asycxx_with_verbose_level; then @@ -55,11 +55,6 @@ AC_DEFINE_UNQUOTED(ENABLE_SANITY_CHECKS, $ASYCXX_sanity_checks, [Enable/Disable sanity checks]) -dnl check for libhdb-tinyxml -PKG_CHECK_MODULES(HDB_TINYXML, hdb-tinyxml-1.0) -AC_SUBST(HDB_TINYXML_CFLAGS) -AC_SUBST(HDB_TINYXML_LIBS) - AC_SUBST(CFLAGS) AC_SUBST(CXXFLAGS) @@ -93,6 +88,5 @@ src/MsgBus.h:include/asycxx/MsgBus.h src/MsgHandler.h:include/asycxx/MsgHandler.h src/GimpleMsgBus.h:include/asycxx/GimpleMsgBus.h - src/XMLParser.h:include/asycxx/XMLParser.h src/_asycxx.h:include/asycxx/_asycxx.h) AC_OUTPUT Deleted: trunk/include/asycxx/XMLParser.h =================================================================== --- trunk/include/asycxx/XMLParser.h 2009-03-12 09:42:31 UTC (rev 8) +++ trunk/include/asycxx/XMLParser.h 2009-03-12 09:45:10 UTC (rev 9) @@ -1,54 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi... - * - *******************************************************************/ - -#ifndef __HIPRO_ACW__XML_PARSER_H__ -#define __HIPRO_ACW__XML_PARSER_H__ - -#include <vector> -#include <hdb-tinyxml/tinyxml.h> - -#include "_asycxx.h" - -class XMLParser -{ -public: - XMLParser (const char *file_name); - ~XMLParser (); - - Result GetValue (const char *xpath, const char **value); - Result GetValue (const char *xpath, int *value); - -protected: - char m_FileName[HMI_CTRL_MAX_URL_LEN]; - TiXmlDocument *m_txDoc; - -private: - - Result ParseXPath (const char *xpath); - - /* used by the xpath parser */ - char m_XPath[HMI_CTRL_MAX_XPATH_LEN]; - std::vector<char *> m_XPathComponents; - -}; - -#endif /* __HIPRO_ACW__XML_PARSER_H__ */ - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2009-03-12 09:42:31 UTC (rev 8) +++ trunk/src/Makefile.am 2009-03-12 09:45:10 UTC (rev 9) @@ -21,8 +21,7 @@ MsgBus.cxx \ MsgHandler.cxx \ GimpleMsgBus.cxx \ - XMLParser.cxx \ core.cxx -libasycxx_0_1_la_CXXFLAGS = -O2 $(HDB_TINYXML_CFLAGS) +libasycxx_0_1_la_CXXFLAGS = -O2 libasycxx_0_1_la_LDFLAGS = -version-info 0:1:0 Deleted: trunk/src/XMLParser.cxx =================================================================== --- trunk/src/XMLParser.cxx 2009-03-12 09:42:31 UTC (rev 8) +++ trunk/src/XMLParser.cxx 2009-03-12 09:45:10 UTC (rev 9) @@ -1,296 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi... - * - *******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <asycxx-config.h> -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> - -#include "asycxx-common.h" -#include "XMLParser.h" -#include "Error.h" - -#include <hdb-tinyxml/tinyxml.h> - -/** - * \class XMLParser - * - * \details The xpath used here is not the standard xpath defined by - * the W3C but a smaller subset of it. It does not have all query - * features contained in the standard XPath. - * - * The XPath is the denotation of a node in an XML file in the form of - * a file-system path. In the following, XML file: - * - * <pre> - * - * \<config\> - * \<name\>Joe\</name\> - * \</config\> - * - * </pre> - * - * The node named 'name' can be referred to using the string - * "/config/name". The W3C standard XPath notation has more complex - */ - -XMLParser::XMLParser (const char *file_name) -{ - ASSERT ((file_name != NULL), "bad parameters"); - ASSERT ((strnlen (file_name, HMI_CTRL_MAX_URL_LEN) < HMI_CTRL_MAX_URL_LEN), - "bad parameters"); - - m_txDoc = NULL; - memset (m_FileName, 0, sizeof(m_FileName)); - memset (m_XPath, 0, sizeof(m_XPath)); - - strncpy (m_FileName, file_name, HMI_CTRL_MAX_URL_LEN); - m_txDoc = new TiXmlDocument (m_FileName); - if (m_txDoc->LoadFile() == false) - { - THROW (RunTimeError, "failed to load (parse) XML file=%s", m_FileName); - } -} - - -XMLParser::~XMLParser () -{ - if (m_txDoc != NULL) - { - delete m_txDoc; - } -} - - -/** - * \brief Get the string value pointed by the x-path - * - * \param[in] XPath A string containing the path to the node - * \param[out] value A pointer to a string pointer to take a pointer - * to the string value in the node. - * - * \details This method gets the value contained in the node pointed to - * by the 'xpath' string. On success, value should point to a const - * string which contains the value. - */ -Result -XMLParser::GetValue (const char *xpath, const char **value) -{ - Result ret; - - ASSERT ((xpath != NULL), "bad parameters"); - ASSERT ((value != NULL), "bad parameters"); - - *value = NULL; - if (strnlen (xpath, HMI_CTRL_MAX_XPATH_LEN) == HMI_CTRL_MAX_XPATH_LEN) - { - ERR ("XPath string is too long (max=%d bytes)", HMI_CTRL_MAX_XPATH_LEN); - return Result_Error; - } - - ret = ParseXPath (xpath); - if (ret != Result_Success) - { - ERR ("bad xpath. cannot fetch value"); - return Result_Error; - } - - /* loop through the children and obtain the node pointed to by the - xpath */ - TiXmlNode *pChild, *pParent; - pParent = m_txDoc; - bool bFound; - unsigned int i; - const char *strValue; - - for (i=0; i<m_XPathComponents.size(); i++) - { - pChild = pParent->FirstChild(m_XPathComponents[i]); - if (pChild == NULL) - { - ERR ("node=%s does not have a child=%s. bad xpath=%s", - pParent->Value(), m_XPathComponents[i], m_XPath); - return Result_Error; - } - pParent = pChild; - } - - /* If everything went well, then the child of this node should have - the requested value */ - bFound = false; - for (pChild = pParent->FirstChild(); pChild != NULL; - pChild = pChild->NextSibling()) - { - if (pChild->Type() == TiXmlNode::TEXT) - { - strValue = pChild->Value(); - if (strValue != NULL) - { - bFound = true; - break; - } - else - { - LOG3 ("TiXMLNode->Value() returned NULL"); - } - } - } - if (bFound == false) - { - ERR ("xpath=%s does not contain any 'text' value", m_XPath); - return Result_Error; - } - - /* Found the value */ - *value = strValue; - return Result_Success; -} - - -/** - * \brief Get the int value pointed by the x-path - * - * \param[in] XPath A string containing the path to the node - * \param[out] value A pointer to an integer to take the integer value - * in the node. - * - * \details This method gets the value contained in the node pointed to - * by the 'xpath' string and stores it into 'value'. - */ -Result -XMLParser::GetValue (const char *xpath, int *value) -{ - Result ret; - const char *strValue; - int intValue; - - ASSERT ((xpath != NULL), "bad parameters"); - ASSERT ((value != NULL), "bad parameters"); - - *value = 0; - - ret = GetValue (xpath, &strValue); - if (ret != Result_Success) - { - ERR ("failed to retrieve value from given xpath"); - return Result_Error; - } -#ifdef ENABLE_SANITY_CHECKS - if (strValue == NULL) - { - ERR ("a successfull GetValue gave NULL value"); - return Result_Error; - } -#endif - - intValue = atoi (strValue); - *value = intValue; - - return Result_Success; -} - - -/** - * \brief Break a xpath string into individual components - * - * \param[in] xpath A string containing the x-path to be broken down. - * - * \details This method breaks an xpath of the form '/doc/node1/node' - * into a vector of node-names arranged in the same order. - */ -Result -XMLParser::ParseXPath (const char *xpath) -{ - ASSERT ((xpath != NULL), "bad parameters"); - ASSERT ((strnlen (xpath, HMI_CTRL_MAX_XPATH_LEN) < HMI_CTRL_MAX_XPATH_LEN), - "xpath string is too long (max=%d bytes)", HMI_CTRL_MAX_XPATH_LEN); - - /* a clean start */ - memset (m_XPath, 0, sizeof(m_XPath)); - m_XPathComponents.clear(); - - if (xpath[0] != '/') - { - ERR ("xpath=%s is not absolute. should start with /", xpath); - return Result_Error; - } - - /* Break the 'xpath' string into seperate components. */ - char *tmpStr; bool foundStr; - unsigned int i; - - strncpy (m_XPath, xpath, HMI_CTRL_MAX_XPATH_LEN); - foundStr = false; - tmpStr = NULL; - for (i=0; i<HMI_CTRL_MAX_XPATH_LEN; i++) - { - if (m_XPath[i] == '\0') - { - /* We reached end of string. If we have a valid component in - the tmpStr, then we should save it before breaking out of - here */ - if (foundStr == true) - { - m_XPathComponents.push_back (tmpStr); - } - break; - } - - if (m_XPath[i] == '/') - { - /* We found a delimiter. */ - if (foundStr == true) - { - /* Looks like we already found a component. Then this is - the end of that component. We should save the - component and mark this location with a \0. */ - m_XPath[i] = '\0'; - m_XPathComponents.push_back (tmpStr); - foundStr = false; - } - /* If we did not find a valid component string before - finding this delimiter, then it is just consequtive - delimiters. We'll ignore them. */ - } - else - { - /* we found a normal character */ - if (foundStr == false) - { - /* Start of a valid component string */ - tmpStr = &m_XPath[i]; - foundStr = true; - } - } - } - - if (m_XPathComponents.empty() == true) - { - ERR ("no valid path components in xpath=%s", xpath); - return Result_Error; - } - - return Result_Success; -} - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-03-12 12:55:51
|
Revision: 12 http://asycxx.svn.sourceforge.net/asycxx/?rev=12&view=rev Author: joe_steeve Date: 2009-03-12 12:55:38 +0000 (Thu, 12 Mar 2009) Log Message: ----------- [ticket:4] Deferred.* is referred wrongly in the build (fixed) From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/Deferred.h trunk/src/Deferred.cxx trunk/src/Makefile.am Modified: trunk/include/asycxx/Deferred.h =================================================================== --- trunk/include/asycxx/Deferred.h 2009-03-12 12:54:15 UTC (rev 11) +++ trunk/include/asycxx/Deferred.h 2009-03-12 12:55:38 UTC (rev 12) @@ -15,6 +15,7 @@ #define __HIPRO_ASYCXX__DEFERRED_H__ #include "Error.h" +#include "_asycxx.h" typedef void (*cbDeferredOnEvent_t) (void *obj); typedef void (*cbDeferredOnError_t) (void *obj); Modified: trunk/src/Deferred.cxx =================================================================== --- trunk/src/Deferred.cxx 2009-03-12 12:54:15 UTC (rev 11) +++ trunk/src/Deferred.cxx 2009-03-12 12:55:38 UTC (rev 12) @@ -19,7 +19,7 @@ #include <errno.h> #include <string.h> -#include "asycxx.h" +#include "asycxx-common.h" #include "Error.h" #include "Deferred.h" Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2009-03-12 12:54:15 UTC (rev 11) +++ trunk/src/Makefile.am 2009-03-12 12:55:38 UTC (rev 12) @@ -5,7 +5,7 @@ libasycxx_0_1_la_SOURCES = \ Logger.cxx \ Error.cxx \ - Deferred.cxx.h \ + Deferred.cxx \ RefCounter.cxx \ DataBuffer.cxx \ Reactor.cxx \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-03-12 12:58:06
|
Revision: 14 http://asycxx.svn.sourceforge.net/asycxx/?rev=14&view=rev Author: joe_steeve Date: 2009-03-12 12:57:59 +0000 (Thu, 12 Mar 2009) Log Message: ----------- [ticket:2] A simple EchoServer example The echo-server simply echos back whatever we give. Demonstrates on using asycxx. From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/Makefile.am trunk/configure.ac Added Paths: ----------- trunk/examples/ trunk/examples/Makefile.am trunk/examples/echoserver/ trunk/examples/echoserver/EchoServer.cxx trunk/examples/echoserver/Makefile.am Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2009-03-12 12:56:40 UTC (rev 13) +++ trunk/Makefile.am 2009-03-12 12:57:59 UTC (rev 14) @@ -1,5 +1,5 @@ # -*- mode: makefile; indent-tabs-mode: nil; tab-width: 4; -*- -SUBDIRS = src include +SUBDIRS = src include examples pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = asycxx-0.1.pc Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-03-12 12:56:40 UTC (rev 13) +++ trunk/configure.ac 2009-03-12 12:57:59 UTC (rev 14) @@ -68,6 +68,8 @@ Makefile src/Makefile include/Makefile +examples/Makefile +examples/echoserver/Makefile asycxx-0.1.pc ]) AC_CONFIG_LINKS(src/Logger.h:include/asycxx/Logger.h Added: trunk/examples/Makefile.am =================================================================== --- trunk/examples/Makefile.am (rev 0) +++ trunk/examples/Makefile.am 2009-03-12 12:57:59 UTC (rev 14) @@ -0,0 +1,2 @@ + +SUBDIRS = echoserver Added: trunk/examples/echoserver/EchoServer.cxx =================================================================== --- trunk/examples/echoserver/EchoServer.cxx (rev 0) +++ trunk/examples/echoserver/EchoServer.cxx 2009-03-12 12:57:59 UTC (rev 14) @@ -0,0 +1,79 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#include <memory> + +#include <asycxx/Logger.h> +#include <asycxx/Error.h> +#include <asycxx/Timer.h> +#include <asycxx/SelectReactor.h> +#include <asycxx/Protocol.h> +#include <asycxx/Factory.h> +#include <asycxx/TCPListener.h> + +Logger *Log; + +class EchoServerProtocol : public Protocol +{ +public: + EchoServerProtocol (Reactor *reactor, Factory *factory, Transport *transport) + : Protocol (reactor, factory, transport) + {} + ~EchoServerProtocol () {} + + void DataAvailable (DataBuffer *data) + { + m_Transport->Write (data); + } +}; + + +class EchoServerProtocolFactory : public Factory +{ +public: + EchoServerProtocolFactory (Reactor *reactor) : Factory (reactor) + {} + ~EchoServerProtocolFactory () {} + + EchoServerProtocol * GetProtocol (Transport *trans) + { + return new EchoServerProtocol (m_Reactor, this, trans); + } +}; + + +int +main () +{ + Reactor *reactor; + + Log = new Logger(); + Log->EnableConsole(); + + reactor = new SelectReactor (); + Timer::Init (reactor); + + EchoServerProtocolFactory echofactory (reactor); + TCPListener echolistener (reactor, &echofactory, (char *)"0.0.0.0", + 10000); + reactor->Run (); +} + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/examples/echoserver/Makefile.am =================================================================== --- trunk/examples/echoserver/Makefile.am (rev 0) +++ trunk/examples/echoserver/Makefile.am 2009-03-12 12:57:59 UTC (rev 14) @@ -0,0 +1,14 @@ + +noinst_PROGRAMS = EchoServer + +EchoServer_SOURCES = EchoServer.cxx +EchoServer_LDADD = $(top_srcdir)/src/libasycxx-0.1.la +EchoServer_CPPFLAGS = -I$(top_srcdir)/include +EchoServer_LDFLAGS = -L$(top_srcdir)/src + + +# Local Variables: +# mode: makefile +# indent-tabs-mode: nil +# tab-width: 4 +# End: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-03-12 15:12:38
|
Revision: 15 http://asycxx.svn.sourceforge.net/asycxx/?rev=15&view=rev Author: joe_steeve Date: 2009-03-12 15:12:33 +0000 (Thu, 12 Mar 2009) Log Message: ----------- [ticket:3] headers should not be linked into src/ (fixed) The configure script was creating to all the asycxx headers in the src/ folder. This means, we need to remember to modify the configure.ac everytime we add a new header. This commit removes that dependancy. From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/configure.ac trunk/src/DataBuffer.cxx trunk/src/Deferred.cxx trunk/src/Error.cxx trunk/src/Factory.cxx trunk/src/GimpleMsgBus.cxx trunk/src/Listener.cxx trunk/src/Logger.cxx trunk/src/Makefile.am trunk/src/MsgBus.cxx trunk/src/MsgHandler.cxx trunk/src/Protocol.cxx trunk/src/Reactor.cxx trunk/src/RefCounter.cxx trunk/src/SelectReactor.cxx trunk/src/TCPLLTransport.cxx trunk/src/TCPListener.cxx trunk/src/TCPTransport.cxx trunk/src/Timer.cxx trunk/src/Transport.cxx trunk/src/asycxx-common.h trunk/src/core.cxx Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/configure.ac 2009-03-12 15:12:33 UTC (rev 15) @@ -72,23 +72,4 @@ examples/echoserver/Makefile asycxx-0.1.pc ]) -AC_CONFIG_LINKS(src/Logger.h:include/asycxx/Logger.h - src/Error.h:include/asycxx/Error.h - src/Deferred.h:include/asycxx/Deferred.h - src/RefCounter.h:include/asycxx/RefCounter.h - src/DataBuffer.h:include/asycxx/DataBuffer.h - src/Reactor.h:include/asycxx/Reactor.h - src/SelectReactor.h:include/asycxx/SelectReactor.h - src/Timer.h:include/asycxx/Timer.h - src/Transport.h:include/asycxx/Transport.h - src/Listener.h:include/asycxx/Listener.h - src/TCPTransport.h:include/asycxx/TCPTransport.h - src/TCPListener.h:include/asycxx/TCPListener.h - src/TCPLLTransport.h:include/asycxx/TCPLLTransport.h - src/Protocol.h:include/asycxx/Protocol.h - src/Factory.h:include/asycxx/Factory.h - src/MsgBus.h:include/asycxx/MsgBus.h - src/MsgHandler.h:include/asycxx/MsgHandler.h - src/GimpleMsgBus.h:include/asycxx/GimpleMsgBus.h - src/_asycxx.h:include/asycxx/_asycxx.h) AC_OUTPUT Modified: trunk/src/DataBuffer.cxx =================================================================== --- trunk/src/DataBuffer.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/DataBuffer.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -18,7 +18,7 @@ #include <cstdlib> #include "asycxx-common.h" -#include "DataBuffer.h" +#include <asycxx/DataBuffer.h> void Modified: trunk/src/Deferred.cxx =================================================================== --- trunk/src/Deferred.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Deferred.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -20,8 +20,8 @@ #include <string.h> #include "asycxx-common.h" -#include "Error.h" -#include "Deferred.h" +#include <asycxx/Error.h> +#include <asycxx/Deferred.h> /** Modified: trunk/src/Error.cxx =================================================================== --- trunk/src/Error.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Error.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -20,7 +20,7 @@ #include <execinfo.h> #include "asycxx-common.h" -#include "Error.h" +#include <asycxx/Error.h> void Error::doError (const char *fmt, va_list vargs) Modified: trunk/src/Factory.cxx =================================================================== --- trunk/src/Factory.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Factory.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -17,9 +17,9 @@ #include "asycxx-common.h" -#include "Error.h" -#include "Reactor.h" -#include "Factory.h" +#include <asycxx/Error.h> +#include <asycxx/Reactor.h> +#include <asycxx/Factory.h> /** Modified: trunk/src/GimpleMsgBus.cxx =================================================================== --- trunk/src/GimpleMsgBus.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/GimpleMsgBus.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -19,14 +19,13 @@ #include <arpa/inet.h> #include "asycxx-common.h" -#include "Error.h" +#include <asycxx/Error.h> +#include <asycxx/Transport.h> +#include <asycxx/Factory.h> +#include <asycxx/MsgHandler.h> +#include <asycxx/GimpleMsgBus.h> -#include "Transport.h" -#include "Factory.h" -#include "MsgHandler.h" -#include "GimpleMsgBus.h" - GimpleMsgBus::GimpleMsgBus (Reactor *reactor, Factory *factory, Transport *transport, MsgHandler *handler) : Protocol (reactor, factory, transport), Modified: trunk/src/Listener.cxx =================================================================== --- trunk/src/Listener.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Listener.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -17,8 +17,8 @@ #include "asycxx-common.h" -#include "Error.h" -#include "Listener.h" +#include <asycxx/Error.h> +#include <asycxx/Listener.h> Listener::Listener () Modified: trunk/src/Logger.cxx =================================================================== --- trunk/src/Logger.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Logger.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -18,7 +18,7 @@ #include <stdio.h> #include <stdarg.h> -#include "Logger.h" +#include <asycxx/Logger.h> Logger::Logger () Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Makefile.am 2009-03-12 15:12:33 UTC (rev 15) @@ -23,5 +23,6 @@ GimpleMsgBus.cxx \ core.cxx +libasycxx_0_1_la_CPPFLAGS = -I$(top_srcdir)/include libasycxx_0_1_la_CXXFLAGS = -O2 libasycxx_0_1_la_LDFLAGS = -version-info 0:1:0 Modified: trunk/src/MsgBus.cxx =================================================================== --- trunk/src/MsgBus.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/MsgBus.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -15,9 +15,9 @@ #endif #include "asycxx-common.h" -#include "Error.h" -#include "MsgBus.h" -#include "MsgHandler.h" +#include <asycxx/Error.h> +#include <asycxx/MsgBus.h> +#include <asycxx/MsgHandler.h> MsgBus::MsgBus (MsgHandler *handler) { Modified: trunk/src/MsgHandler.cxx =================================================================== --- trunk/src/MsgHandler.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/MsgHandler.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -16,8 +16,8 @@ #endif #include "asycxx-common.h" -#include "Error.h" -#include "MsgHandler.h" +#include <asycxx/Error.h> +#include <asycxx/MsgHandler.h> MsgHandler::MsgHandler () { Modified: trunk/src/Protocol.cxx =================================================================== --- trunk/src/Protocol.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Protocol.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -17,8 +17,8 @@ #include "asycxx-common.h" -#include "Error.h" -#include "Protocol.h" +#include <asycxx/Error.h> +#include <asycxx/Protocol.h> Protocol::Protocol (Reactor *reactor, Factory *factory, Transport *transport) Modified: trunk/src/Reactor.cxx =================================================================== --- trunk/src/Reactor.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Reactor.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -27,8 +27,8 @@ #include <exception> #include "asycxx-common.h" -#include "Reactor.h" -#include "Deferred.h" +#include <asycxx/Reactor.h> +#include <asycxx/Deferred.h> ////////////////////////////////////////////////////////////////////////////// Modified: trunk/src/RefCounter.cxx =================================================================== --- trunk/src/RefCounter.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/RefCounter.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -16,8 +16,8 @@ #endif #include "asycxx-common.h" -#include "Error.h" -#include "RefCounter.h" +#include <asycxx/Error.h> +#include <asycxx/RefCounter.h> /** Modified: trunk/src/SelectReactor.cxx =================================================================== --- trunk/src/SelectReactor.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/SelectReactor.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -20,8 +20,8 @@ #include <string.h> #include "asycxx-common.h" -#include "Error.h" -#include "SelectReactor.h" +#include <asycxx/Error.h> +#include <asycxx/SelectReactor.h> /** Modified: trunk/src/TCPLLTransport.cxx =================================================================== --- trunk/src/TCPLLTransport.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/TCPLLTransport.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -23,9 +23,9 @@ #include <netinet/tcp.h> #include "asycxx-common.h" -#include "Error.h" -#include "Protocol.h" -#include "TCPLLTransport.h" +#include <asycxx/Error.h> +#include <asycxx/Protocol.h> +#include <asycxx/TCPLLTransport.h> TCPLLTransport::TCPLLTransport (Reactor *reactor, int fd) Modified: trunk/src/TCPListener.cxx =================================================================== --- trunk/src/TCPListener.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/TCPListener.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -26,11 +26,11 @@ #include <unistd.h> #include "asycxx-common.h" -#include "Error.h" -#include "Factory.h" -#include "Protocol.h" -#include "TCPTransport.h" -#include "TCPListener.h" +#include <asycxx/Error.h> +#include <asycxx/Factory.h> +#include <asycxx/Protocol.h> +#include <asycxx/TCPTransport.h> +#include <asycxx/TCPListener.h> /** Modified: trunk/src/TCPTransport.cxx =================================================================== --- trunk/src/TCPTransport.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/TCPTransport.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -24,9 +24,9 @@ #include <errno.h> #include "asycxx-common.h" -#include "Error.h" -#include "Protocol.h" -#include "TCPTransport.h" +#include <asycxx/Error.h> +#include <asycxx/Protocol.h> +#include <asycxx/TCPTransport.h> TCPTransport::TCPTransport (Reactor *reactor, int fd) Modified: trunk/src/Timer.cxx =================================================================== --- trunk/src/Timer.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Timer.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -44,8 +44,8 @@ #include <vector> #include "asycxx-common.h" -#include "Error.h" -#include "Timer.h" +#include <asycxx/Error.h> +#include <asycxx/Timer.h> /*****************************************************************************/ Reactor * Timer::m_Reactor = NULL; Modified: trunk/src/Transport.cxx =================================================================== --- trunk/src/Transport.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/Transport.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -18,9 +18,9 @@ #include <unistd.h> #include "asycxx-common.h" -#include "Error.h" -#include "Transport.h" -#include "Protocol.h" +#include <asycxx/Error.h> +#include <asycxx/Transport.h> +#include <asycxx/Protocol.h> /** * \brief ctor Modified: trunk/src/asycxx-common.h =================================================================== --- trunk/src/asycxx-common.h 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/asycxx-common.h 2009-03-12 15:12:33 UTC (rev 15) @@ -17,8 +17,8 @@ #include <stdio.h> #include <stdlib.h> -#include "_asycxx.h" -#include "Logger.h" +#include <asycxx/_asycxx.h> +#include <asycxx/Logger.h> extern Logger *Log; Modified: trunk/src/core.cxx =================================================================== --- trunk/src/core.cxx 2009-03-12 12:57:59 UTC (rev 14) +++ trunk/src/core.cxx 2009-03-12 15:12:33 UTC (rev 15) @@ -22,7 +22,7 @@ #include <fcntl.h> #include "asycxx-common.h" -#include "Error.h" +#include <asycxx/Error.h> h_msecs_t GetCurrentTimeStamp (void) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <viv...@us...> - 2009-03-23 08:45:21
|
Revision: 18 http://asycxx.svn.sourceforge.net/asycxx/?rev=18&view=rev Author: vivekanand83 Date: 2009-03-23 08:45:18 +0000 (Mon, 23 Mar 2009) Log Message: ----------- Raw CAN support added. Modified Paths: -------------- trunk/configure.ac trunk/examples/Makefile.am trunk/src/Makefile.am trunk/src/asycxx-common.h Added Paths: ----------- trunk/examples/canserver/ trunk/examples/canserver/Canserver.cxx trunk/examples/canserver/Makefile.am trunk/include/asycxx/RAWCANListener.h trunk/include/asycxx/RAWCANTransport.h trunk/src/RAWCANListener.cxx trunk/src/RAWCANTransport.cxx Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-03-17 09:24:06 UTC (rev 17) +++ trunk/configure.ac 2009-03-23 08:45:18 UTC (rev 18) @@ -70,6 +70,7 @@ include/Makefile examples/Makefile examples/echoserver/Makefile +examples/canserver/Makefile asycxx-0.1.pc ]) AC_OUTPUT Modified: trunk/examples/Makefile.am =================================================================== --- trunk/examples/Makefile.am 2009-03-17 09:24:06 UTC (rev 17) +++ trunk/examples/Makefile.am 2009-03-23 08:45:18 UTC (rev 18) @@ -1,2 +1,2 @@ -SUBDIRS = echoserver +SUBDIRS = echoserver canserver Added: trunk/examples/canserver/Canserver.cxx =================================================================== --- trunk/examples/canserver/Canserver.cxx (rev 0) +++ trunk/examples/canserver/Canserver.cxx 2009-03-23 08:45:18 UTC (rev 18) @@ -0,0 +1,79 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#include <memory> + +#include <asycxx/Logger.h> +#include <asycxx/Error.h> +#include <asycxx/Timer.h> +#include <asycxx/SelectReactor.h> +#include <asycxx/Protocol.h> +#include <asycxx/Factory.h> +#include <asycxx/RAWCANListener.h> + +Logger *Log; + +class RAWCANServerProtocol : public Protocol +{ + public: + RAWCANServerProtocol (Reactor *reactor, Factory *factory, Transport +*transport) + : Protocol (reactor, factory, transport) + {} + ~RAWCANServerProtocol () {} + + void DataAvailable (DataBuffer *data) + { + printf ("CANSERVER: Got data of size %d\n", data->Len()); + } +}; + + +class RAWCANServerProtocolFactory : public Factory +{ + public: + RAWCANServerProtocolFactory (Reactor *reactor) : Factory (reactor) + {} + ~RAWCANServerProtocolFactory () {} + + RAWCANServerProtocol * GetProtocol (Transport *trans) + { + return new RAWCANServerProtocol (m_Reactor, this, trans); + } +}; + + +int +main () +{ + Reactor *reactor; + + Log = new Logger(); + Log->EnableConsole(); + + reactor = new SelectReactor (); + Timer::Init (reactor); + + RAWCANServerProtocolFactory CANfactory (reactor); + RAWCANListener RAWCANlistener (reactor, &CANfactory, "vcan0"); + reactor->Run (); +} + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/examples/canserver/Makefile.am =================================================================== --- trunk/examples/canserver/Makefile.am (rev 0) +++ trunk/examples/canserver/Makefile.am 2009-03-23 08:45:18 UTC (rev 18) @@ -0,0 +1,14 @@ + +noinst_PROGRAMS = CanServer + +CanServer_SOURCES = Canserver.cxx +CanServer_LDADD = $(top_srcdir)/src/libasycxx-0.1.la +CanServer_CPPFLAGS = -I$(top_srcdir)/include +CanServer_LDFLAGS = -L$(top_srcdir)/src + + +# Local Variables: +# mode: makefile +# indent-tabs-mode: nil +# tab-width: 4 +# End: Added: trunk/include/asycxx/RAWCANListener.h =================================================================== --- trunk/include/asycxx/RAWCANListener.h (rev 0) +++ trunk/include/asycxx/RAWCANListener.h 2009-03-23 08:45:18 UTC (rev 18) @@ -0,0 +1,60 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__RAW_CAN_LISTENER_H__ +#define __HIPRO_ASYCXX__RAW_CAN_LISTENER_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <sys/types.h> +#include <arpa/inet.h> +#include <linux/can.h> +#include <linux/can/raw.h> + +#include "Error.h" +#include "Listener.h" +#include "Factory.h" +#include "Deferred.h" +#include "Reactor.h" + +class RAWCANListener : public Listener +{ + public: + + RAWCANListener (Reactor *reactor, Factory *factory, const char *interface); + virtual ~RAWCANListener (); + + protected: + Reactor *m_Reactor; + Factory *m_Factory; + Deferred *m_ReactorDeferred; + + int m_Socket; + char m_Interface[8]; + bool m_bSetupNoDelay; + protected: + void Init (Reactor *reactor, Factory *factory, const char *interface); +}; + +#endif /* __HIPRO_ASYCXX__RAW_CAN_LISTENER_H__*/ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/include/asycxx/RAWCANTransport.h =================================================================== --- trunk/include/asycxx/RAWCANTransport.h (rev 0) +++ trunk/include/asycxx/RAWCANTransport.h 2009-03-23 08:45:18 UTC (rev 18) @@ -0,0 +1,48 @@ + +/******************************************************************** + * Copyright (C), 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__CAN_TRANSPORT_H__ +#define __HIPRO_ASYCXX__CAN_TRANSPORT_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "Error.h" +#include "Reactor.h" +#include "DataBuffer.h" +#include "Transport.h" + +class RAWCANTransport : public Transport +{ + public: + RAWCANTransport (Reactor *reactor, int fd); + virtual ~RAWCANTransport (); + + protected: + Result doWrite (void); + Result doRead (DataBuffer *data); + void doDisconnect (void); + +}; + +#endif /* __HIPRO_ASYCXX__CAN_TRANSPORT_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2009-03-17 09:24:06 UTC (rev 17) +++ trunk/src/Makefile.am 2009-03-23 08:45:18 UTC (rev 18) @@ -21,8 +21,11 @@ MsgBus.cxx \ MsgHandler.cxx \ GimpleMsgBus.cxx \ - core.cxx + core.cxx \ + RAWCANTransport.cxx \ + RAWCANListener.cxx + libasycxx_0_1_la_CPPFLAGS = -I$(top_srcdir)/include libasycxx_0_1_la_CXXFLAGS = -O2 libasycxx_0_1_la_LDFLAGS = -version-info 0:1:0 Added: trunk/src/RAWCANListener.cxx =================================================================== --- trunk/src/RAWCANListener.cxx (rev 0) +++ trunk/src/RAWCANListener.cxx 2009-03-23 08:45:18 UTC (rev 18) @@ -0,0 +1,156 @@ +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netinet/tcp.h> +#include <net/if.h> +#include <linux/can.h> +#include <linux/can/raw.h> + +#include <string.h> +#include <errno.h> +#include <unistd.h> + +#include "asycxx-common.h" +#include <asycxx/Error.h> +#include <asycxx/Factory.h> +#include <asycxx/Protocol.h> +#include <asycxx/RAWCANTransport.h> +#include <asycxx/RAWCANListener.h> + + +#include <sys/ioctl.h> + +/* At time of writing, these constants are not defined in the headers */ +#ifndef PF_CAN +#define PF_CAN 29 +#endif + +#ifndef AF_CAN +#define AF_CAN PF_CAN +#endif + +/** + * \brief ctor to put RAWCANListener on interface + * + * \param[in] reactor The reactor to hook to + * \param[in] factory The factory to use to produce protocols to + * handle new connections + * \param[in] interface The CAN interface to listen to + * + * \details This constructor puts the RAWCANListener object to listen on + * the specified interface. + */ +RAWCANListener::RAWCANListener (Reactor *reactor, Factory *factory, + const char *interface) +{ + Init (reactor, factory, interface); +} + + +/* + * \brief dtor + */ +RAWCANListener::~RAWCANListener () +{ + if (m_Socket != -1) + { + close (m_Socket); + } +} + + +/** + * \brief Initialize the RAWCANListener + * + * \param[in] reactor The reactor to hook to + * \param[in] factory The factory to use to produce protocols + * \param[in] interface The CAN interface to listen to + + * \details This method is the backend method for all the + * constructors. This creates a socketbinds it to the given interface and + * hooks it up to the reactor. + */ +void +RAWCANListener::Init (Reactor *reactor, Factory *factory, const char *interface) +{ + int iret; + + ASSERT ((factory != NULL), "checking parameters"); + ASSERT ((reactor != NULL), "checking parameters"); + ASSERT ((interface != NULL), "checking parameters"); + + m_Factory = factory; + m_Reactor = reactor; + strncpy(m_Interface, interface, strlen(interface) + 1); + + /* Create the socket */ + m_Socket = socket( PF_CAN, SOCK_RAW, CAN_RAW ); + if (m_Socket == -1) + { + THROW (RunTimeError, + "RAWCANListener: %s : creating socket to listen on %s", + strerror (errno), m_Interface); + } + + /* Locate the interface we wish to use */ + struct ifreq ifr; + strcpy(ifr.ifr_name, m_Interface); + iret = ioctl(m_Socket, SIOCGIFINDEX, &ifr); /* ifr.ifr_ifindex gets filled + * with that device's index */ + if (iret < 0) + { + close(m_Socket); + THROW (RunTimeError, + "RAWCANListener: %s : locating interface (ioctl) %s", + strerror (errno), m_Interface); + } + + /* Select that CAN interface, and bind the socket to it. */ + struct sockaddr_can addr; + addr.can_family = AF_CAN; + addr.can_ifindex = ifr.ifr_ifindex; + + iret = bind(m_Socket, (struct sockaddr*)&addr, sizeof(addr)); + if (iret < 0) + { + close(m_Socket); + THROW (RunTimeError, + "RAWCANListener: %s : binding CAN to %s", + strerror (errno), m_Interface); + } + + /* register the non-blocking FD with the reactor */ + SetFDAsNonBlocking (m_Socket); + Protocol *proto; + /* create a protocol using the factory */ + RAWCANTransport *trans; + trans = new RAWCANTransport (m_Reactor, m_Socket); + proto = m_Factory->GetProtocol (trans); + proto->BuildProtocol (); +} + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/src/RAWCANTransport.cxx =================================================================== --- trunk/src/RAWCANTransport.cxx (rev 0) +++ trunk/src/RAWCANTransport.cxx 2009-03-23 08:45:18 UTC (rev 18) @@ -0,0 +1,138 @@ +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <deque> + +#include <sys/socket.h> +#include <errno.h> + +#include "asycxx-common.h" +#include <asycxx/Error.h> +#include <asycxx/Protocol.h> +#include <asycxx/RAWCANTransport.h> + +#define RAW_CAN_FRAME_SIZE 16 + +RAWCANTransport::RAWCANTransport (Reactor *reactor, int fd) + : Transport (reactor, fd) +{ + ctorLOG (__FUNCTION__); + configureReadBufferSize (RAW_CAN_FRAME_SIZE); +} + + +RAWCANTransport::~RAWCANTransport () +{ + dtorLOG(__FUNCTION__); +} + + +Result +RAWCANTransport::doRead (DataBuffer *data) +{ + ASSERT ((data != NULL), "checking parameters"); + ssize_t rlen; + + __doRead__again: + rlen = read (m_Fd, data->Data(), data->BufferLen()); + if (rlen == -1) + { + if (errno == EINTR) + { + goto __doRead__again; + } + else if (errno == EAGAIN) + { + data->Len(0); + return Result_Success; + } + else + { + ERR ("%s: reading from fd=%d", strerror(errno), m_Fd); + return Result_Error; + } + } + + /* check for end-of-file */ + if (rlen == 0) + { + ERR ("EoF on fd=%d", m_Fd); + return Result_Error; + } + data->Len(rlen); + + return Result_Success; +} + +Result +RAWCANTransport::doWrite (void) +{ + ssize_t wrote; + ssize_t wlen, to_wlen; + DataBuffer *data; + void *bfr; + + wrote = 0; + while (m_writeBuffers.size() > 0) + { + data = m_writeBuffers[0]; + to_wlen = data->Len() - data->Processed(); + bfr = data->UnProcessed (); + + wlen = write (m_Fd, bfr, to_wlen); + if (wlen == -1) + { + if (errno == EINTR) { continue; } + else if (errno == EAGAIN) { return Result_Pending; } + else + { + ERR ("%s: writing DataBuffer<%p>::data<%p>,len=%d to fd=%d", + strerror (errno), data, bfr, to_wlen, m_Fd); + return Result_Error; + } + } + + /* update pointers */ + data->Processed((data->Processed() + wlen)); + wrote += wlen; + + if (data->Processed() == data->Len()) + { + m_writeBuffers.pop_front(); + data->DisOwn(); + } + } + + return Result_Success; +} + +void +RAWCANTransport::doDisconnect (void) +{ + +} + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Modified: trunk/src/asycxx-common.h =================================================================== --- trunk/src/asycxx-common.h 2009-03-17 09:24:06 UTC (rev 17) +++ trunk/src/asycxx-common.h 2009-03-23 08:45:18 UTC (rev 18) @@ -35,19 +35,19 @@ #define dummyLog(fmt, ...) -#if HMI_CTRL_VERBOSE_LEVEL >= 1 +#if ASYCXX_VERBOSE_LEVEL >= 1 #define LOG1 LOG #else #define LOG1 dummyLog #endif -#if HMI_CTRL_VERBOSE_LEVEL >= 2 +#if ASYCXX_VERBOSE_LEVEL >= 2 #define LOG2 LOG #else #define LOG2 dummyLog #endif -#if HMI_CTRL_VERBOSE_LEVEL >= 3 +#if ASYCXX_VERBOSE_LEVEL >= 3 #define LOG3 LOG #else #define LOG3 dummyLog This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:28:22
|
Revision: 23 http://asycxx.svn.sourceforge.net/asycxx/?rev=23&view=rev Author: joe_steeve Date: 2009-04-08 07:28:20 +0000 (Wed, 08 Apr 2009) Log Message: ----------- Generalized Deferred dont make sense here. Removed them. From: Joe Steeve <js...@hi...> Removed Paths: ------------- trunk/include/asycxx/Deferred.h trunk/src/Deferred.cxx Deleted: trunk/include/asycxx/Deferred.h =================================================================== --- trunk/include/asycxx/Deferred.h 2009-04-08 04:42:11 UTC (rev 22) +++ trunk/include/asycxx/Deferred.h 2009-04-08 07:28:20 UTC (rev 23) @@ -1,60 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifndef __HIPRO_ASYCXX__DEFERRED_H__ -#define __HIPRO_ASYCXX__DEFERRED_H__ - -#include "Error.h" -#include "_asycxx.h" - -typedef void (*cbDeferredOnEvent_t) (void *obj); -typedef void (*cbDeferredOnError_t) (void *obj); -typedef void (*cbDeferredOnTimeout_t) (void *obj, h_msecs_t excess_time); - -class Deferred -{ - -public: - Deferred (); - ~Deferred (); - - Deferred * OnEvent (cbDeferredOnEvent_t cb_fn, void *cb_obj) throw (); - Deferred * OnError (cbDeferredOnError_t cb_fn, void *cb_obj) throw (); - Deferred * OnTimeout (cbDeferredOnTimeout_t cb_fn, void *cb_obj) throw (); - - void NotifyEvent (void); - void NotifyError (void); - void NotifyTimeout (h_msecs_t excess_time); - -private: - cbDeferredOnEvent_t m_cbOnEvent; - void * m_cbOnEvent_obj; - - cbDeferredOnError_t m_cbOnError; - void * m_cbOnError_obj; - - cbDeferredOnTimeout_t m_cbOnTimeout; - void * m_cbOnTimeout_obj; - -}; - -#endif // __HIPRO_ASYCXX__DEFERRED_H__ - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ Deleted: trunk/src/Deferred.cxx =================================================================== --- trunk/src/Deferred.cxx 2009-04-08 04:42:11 UTC (rev 22) +++ trunk/src/Deferred.cxx 2009-04-08 07:28:20 UTC (rev 23) @@ -1,155 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <asycxx-config.h> -#endif - -#include <stdlib.h> -#include <errno.h> -#include <string.h> - -#include "asycxx-common.h" -#include <asycxx/Error.h> -#include <asycxx/Deferred.h> - - -/** - * \brief ctor - */ -Deferred::Deferred () -{ - -} - - -/** - * \brief dtor - */ -Deferred::~Deferred () -{ - m_cbOnEvent = NULL; - m_cbOnEvent_obj = NULL; - m_cbOnError = NULL; - m_cbOnError_obj = NULL; - m_cbOnTimeout = NULL; - m_cbOnTimeout_obj = NULL; -} - - -/** - * - * - */ -Deferred * -Deferred::OnEvent (cbDeferredOnEvent_t cb_fn, void *cb_obj) throw () -{ - if (cb_fn == NULL) - { - THROW (DevError, "cannot register cbDeferredOnEvent = 'NULL'"); - } - - m_cbOnEvent = cb_fn; - m_cbOnEvent_obj = cb_obj; - return this; -} - - -/** - * - * - */ -Deferred * -Deferred::OnError (cbDeferredOnError_t cb_fn, void *cb_obj) throw () -{ - if (cb_fn == NULL) - { - THROW (DevError, "cannot register cbDeferredOnError = 'NULL'"); - } - - m_cbOnError = cb_fn; - m_cbOnError_obj = cb_obj; - return this; -} - - -/** - * - * - */ -Deferred * -Deferred::OnTimeout (cbDeferredOnTimeout_t cb_fn, void *cb_obj) throw () -{ - if (cb_fn == NULL) - { - THROW (DevError, "cannot register cbDeferredOnTimeout = 'NULL'"); - } - - m_cbOnTimeout = cb_fn; - m_cbOnTimeout_obj = cb_obj; - return this; -} - - -/** - * - * - * - */ -void -Deferred::NotifyEvent (void) -{ - if (m_cbOnEvent != NULL) - { - m_cbOnEvent (m_cbOnEvent_obj); - } -} - - -/** - * - * - * - */ -void -Deferred::NotifyError (void) -{ - if (m_cbOnError != NULL) - { - m_cbOnError (m_cbOnError_obj); - } -} - - -/** - * - * - * - */ -void -Deferred::NotifyTimeout (h_msecs_t excess_time) -{ - if (m_cbOnTimeout != NULL) - { - m_cbOnTimeout (m_cbOnTimeout_obj, excess_time); - } -} - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:29:18
|
Revision: 24 http://asycxx.svn.sourceforge.net/asycxx/?rev=24&view=rev Author: joe_steeve Date: 2009-04-08 07:29:15 +0000 (Wed, 08 Apr 2009) Log Message: ----------- refactored Factory to ProtocolFactory * The 'Factory' class creates 'Protocol' objects. Refactored 'Factory' to 'ProtocolFactory' to be more specific. * Moved ProtocolFactory to 'asycxx' namespace From: Joe Steeve <js...@hi...> Added Paths: ----------- trunk/include/asycxx/ProtocolFactory.h trunk/src/ProtocolFactory.cxx Removed Paths: ------------- trunk/include/asycxx/Factory.h trunk/src/Factory.cxx Deleted: trunk/include/asycxx/Factory.h =================================================================== --- trunk/include/asycxx/Factory.h 2009-04-08 07:28:20 UTC (rev 23) +++ trunk/include/asycxx/Factory.h 2009-04-08 07:29:15 UTC (rev 24) @@ -1,41 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifndef __HIPRO_ASYCXX__FACTORY_H__ -#define __HIPRO_ASYCXX__FACTORY_H__ - -#include "Error.h" -#include "Reactor.h" -#include "Transport.h" - -class Factory -{ -public: - Factory (Reactor *reactor); - virtual ~Factory (); - virtual Protocol *GetProtocol (Transport *trans) = 0; - -protected: - Reactor *m_Reactor; -}; - -#endif /* __HIPRO_ASYCXX__FACTORY_H__ */ - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ Copied: trunk/include/asycxx/ProtocolFactory.h (from rev 23, trunk/include/asycxx/Factory.h) =================================================================== --- trunk/include/asycxx/ProtocolFactory.h (rev 0) +++ trunk/include/asycxx/ProtocolFactory.h 2009-04-08 07:29:15 UTC (rev 24) @@ -0,0 +1,42 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__PROTOCOL_FACTORY_H__ +#define __HIPRO_ASYCXX__PROTOCOL_FACTORY_H__ + +#include "Error.h" +#include "Reactor.h" +#include "Transport.h" + +namespace asycxx +{ + class ProtocolFactory + { + public: + ProtocolFactory (Reactor *reactor); + virtual ~ProtocolFactory () {} + + protected: + Reactor *m_Reactor; + }; +} +#endif /* __HIPRO_ASYCXX__PROTOCOL_FACTORY_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Deleted: trunk/src/Factory.cxx =================================================================== --- trunk/src/Factory.cxx 2009-04-08 07:28:20 UTC (rev 23) +++ trunk/src/Factory.cxx 2009-04-08 07:29:15 UTC (rev 24) @@ -1,52 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <asycxx-config.h> -#endif - - -#include "asycxx-common.h" -#include <asycxx/Error.h> -#include <asycxx/Reactor.h> -#include <asycxx/Factory.h> - - -/** - * \author Joe Steeve, jo...@hi... - * \class Factory - * \brief Defines a protocol-factory - * - * \details This class is a factory class that produces - * protocols. This will be used by a 'Listener'/'Connector' to produce - * protocols to handle a new connection. - */ - -Factory::Factory (Reactor *reactor) -{ - ASSERT ((reactor != NULL), "checking parameters"); - m_Reactor = reactor; -} - -Factory::~Factory () -{ -} - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ Copied: trunk/src/ProtocolFactory.cxx (from rev 23, trunk/src/Factory.cxx) =================================================================== --- trunk/src/ProtocolFactory.cxx (rev 0) +++ trunk/src/ProtocolFactory.cxx 2009-04-08 07:29:15 UTC (rev 24) @@ -0,0 +1,36 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "asycxx-common.h" +#include <asycxx/ProtocolFactory.h> + +using namespace asycxx; + +ProtocolFactory::ProtocolFactory (Reactor *reactor) +{ + ASSERT ((reactor != NULL), "checking parameters"); + m_Reactor = reactor; +} + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:30:41
|
Revision: 26 http://asycxx.svn.sourceforge.net/asycxx/?rev=26&view=rev Author: joe_steeve Date: 2009-04-08 07:30:35 +0000 (Wed, 08 Apr 2009) Log Message: ----------- all Transports are now 'Selectable's This makes sure we can add the Transport directly to the Reactor instead of having callbacks between them. From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/Transport.h trunk/src/Transport.cxx Modified: trunk/include/asycxx/Transport.h =================================================================== --- trunk/include/asycxx/Transport.h 2009-04-08 07:29:52 UTC (rev 25) +++ trunk/include/asycxx/Transport.h 2009-04-08 07:30:35 UTC (rev 26) @@ -14,66 +14,109 @@ #ifndef __HIPRO_ASYCXX__TRANSPORT_H__ #define __HIPRO_ASYCXX__TRANSPORT_H__ +#include <list> -#include <deque> - #include "Error.h" #include "Reactor.h" #include "DataBuffer.h" +#include "Selectable.h" -class Protocol; - -#define ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE 1024 -class Transport +namespace asycxx { + class Protocol; -public: - Transport (Reactor *reactor, int fd); - virtual ~Transport (); + class Transport : public Selectable + { + public: + /** + * \brief CTOR + * + * \param[in] reactor Pointer to a Reactor + * \param[in] fd A valid file-descriptor to build the transport on + */ + Transport (Reactor *reactor, int fd); + virtual ~Transport (); - /* method to write to the transport */ - void Write (DataBuffer *data); - /* method to disconnect the transport and mark for destruction */ - void LoseConnection (void); + /** + * \brief Sets the transport ready for reading + */ + void startReading (void); - /* methods to configure the transport */ - void configureReadTimeout (h_msecs_t timeout); - void configureWriteTimeout (h_msecs_t timeout); - void configureReadBufferSize (size_t len); + /** + * \brief Sets the transport to stop reading + */ + void stopReading (void); - /* accessors */ - int FD (void) { return m_Fd; } - Protocol * GetProtocol (void); - void SetProtocol (Protocol *protocol); - -protected: - Reactor *m_Reactor; - Protocol *m_Protocol; - int m_Fd; + /** + * \brief Sets the transport ready for writing + */ + void startWriting (void); - size_t m_readBufSize; - h_msecs_t m_writeTimeout; /* the timeout used for reading */ - Deferred *m_readDefer; /* deferred to handle reading */ - Deferred *m_writeDefer; /* deferred to handle writing */ - std::deque<DataBuffer *> m_writeBuffers; - bool m_bDisconnectAndDie; + /** + * \brief Sets the transport to stop writing + */ + void stopWriting (void); - /* methods to be implemented by the derived sub-classes */ - virtual Result doWrite (void) = 0; - virtual Result doRead (DataBuffer *data) = 0; - virtual void doDisconnect (void) = 0; + /** + * \brief Attach the given protocol to the Transport + */ + Protocol * getProtocol (void) { return m_Protocol; } - /* handler methods */ - static void handleReadable (void *obj); - static void handleReadTimeout (void *obj, h_msecs_t excess_time); - static void handleWritable (void *obj); - static void handleWriteTimeout (void *obj, h_msecs_t excess_time); + /** + * \brief Get the currently attached protocol + */ + void setProtocol (Protocol *protocol); -private: - void KillMeIfYouMust (void); + /** + * \brief Get the reactor to which the Transport is hooked to + */ + Reactor * getReactor (void) { return m_Reactor; } -}; + /** + * \brief Query whether the 'read end' is open + */ + bool isReaderOpen (void) { return m_bReaderOpen; } + /** + * \brief Query whether the 'write end' is open + */ + bool isWriterOpen (void) { return m_bWriterOpen; } + + /** + * \brief Close the transport completely + */ + virtual void Close (void) = 0; + + /** + * \brief close the read-end of the transport + */ + virtual void closeReader (void) = 0; + + /** + * \brief close the write-end of the transport + */ + virtual void closeWriter (void) = 0; + + protected: + /** + * \brief Mark that the reader has been closed + */ + void markReaderAsClosed (void) { m_bReaderOpen = false; } + + /** + * \brief Mark that the writer has been closed + */ + void markWriterAsClosed (void) { m_bWriterOpen = false; } + + private: + Reactor *m_Reactor; + Protocol *m_Protocol; + bool m_bAddedToReaders; + bool m_bAddedToWriters; + bool m_bReaderOpen; + bool m_bWriterOpen; + }; +} #endif /* __HIPRO_ASYCXX__TRANSPORT_H__ */ /* Modified: trunk/src/Transport.cxx =================================================================== --- trunk/src/Transport.cxx 2009-04-08 07:29:52 UTC (rev 25) +++ trunk/src/Transport.cxx 2009-04-08 07:30:35 UTC (rev 26) @@ -22,333 +22,91 @@ #include <asycxx/Transport.h> #include <asycxx/Protocol.h> -/** - * \brief ctor - * - * \param[in] reactor Pointer to a Reactor - * \param[in] fd A valid file-descriptor to build the transport on + +using namespace asycxx; + + +/* + * CTOR */ Transport::Transport (Reactor *reactor, int fd) { ASSERT ((reactor != NULL), "cannot marry a <NULL> Reactor"); ASSERT ((fd != -1), "bad file-descriptor. checking parameters"); - m_Reactor = reactor; - m_Fd = fd; - m_bDisconnectAndDie = false; - /* set file-descriptor as non-blocking */ - SetFDAsNonBlocking (m_Fd); + /* initialize */ + m_bAddedToReaders = false; + m_bAddedToWriters = false; - /* default configuration */ - m_readDefer = NULL; - m_writeDefer = NULL; - configureReadTimeout (0L); - configureWriteTimeout (0L); - configureReadBufferSize (ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE); + m_bReaderOpen = true; + m_bWriterOpen = true; + + m_Reactor = reactor; + m_Protocol = NULL; + + /* set file-descriptor as non-blocking */ + SetFDAsNonBlocking (fd); + Fd (fd); } -/** - * \brief dtor - */ +/* DTOR */ Transport::~Transport () { - DataBuffer *data; - - /* discard the DataBuffers in the pending queue */ - while (m_writeBuffers.size() > 0) - { - data = m_writeBuffers[0]; - ERR ("Transport<%p> dumping write-buffer <%p>, len=%d", - this, data->Data(), data->Len()); - m_writeBuffers.pop_front(); - data->DisOwn(); - } - /* un-register from the reactor */ - if (m_readDefer != NULL) - { - m_Reactor->UnRegister (m_readDefer); - } - if (m_writeDefer != NULL) - { - m_Reactor->UnRegister (m_writeDefer); - } + stopReading(); + stopWriting(); - /* destroy the protocol */ - if (m_Protocol != NULL) - { - delete m_Protocol; - } - - /* we own the fd that was given to us */ - close (m_Fd); + /* destroy the protocol. we own it. */ + if (m_Protocol != NULL) { delete m_Protocol; } } -/* accessors for protocol */ -void -Transport::SetProtocol (Protocol *protocol) -{ - ASSERT ((protocol != NULL), "checking parameters"); - m_Protocol = protocol; -} - - -Protocol * -Transport::GetProtocol (void) -{ - ASSERT ((m_Protocol != NULL), "protocol not set."); - return m_Protocol; -} - - -/** - * \brief Configures the reading timeout - * - * \param[in] timeout timeout in milli-seconds - * - * \details This method sets a timeout for the reading. - */ -void -Transport::configureReadTimeout (h_msecs_t timeout) -{ - if (m_readDefer != NULL) +/* Methods to add/remove the transport from the readers/writers list + * of the reactor */ +void Transport::startReading (void) +{ + if (m_bAddedToReaders == false) { - m_Reactor->UnRegister (m_readDefer); + m_Reactor->addReader(this); + m_bAddedToReaders = true; } - if (timeout > 0L) - { - m_readDefer = m_Reactor->OnReadable (m_Fd, timeout); - m_readDefer->OnTimeout (Transport::handleReadTimeout, this); - } - else - { - m_readDefer = m_Reactor->OnReadable (m_Fd); - } - m_readDefer->OnEvent (Transport::handleReadable, this); } - -/** - * \brief Configures the writing timeout - * - * \param[in] timeout timeout in milli-seconds - * - * \details This method sets a timeout for the writing. This timeout - * becomes effective from the next write operation - */ -void -Transport::configureWriteTimeout (h_msecs_t timeout) -{ - m_writeTimeout = timeout; -} - - -/** - * \brief Configures the size of the read-buffer - * - * \param[in] len Number of bytes to set the read-buffer to - * - * \details This method sets the read-buffer to the given length. The - * read-buffer-len is the maximum amount of data that can be read from - * the transport at any time. The transport does not wait till the - * buffer of read-buffer-len is full. When data is available, utmost - * read-buffer-len bytes can be read from it. If more data is still - * available, they'll be read only in the next read operation. - */ -void -Transport::configureReadBufferSize (size_t len) -{ - ASSERT ((len != 0), "zero length read-buffer??"); - m_readBufSize = len; -} - - -/** - * \brief Queues the provided data-buffer for writing - * - * \param[in] data The DataBuffer object that should be written - * - * \details This method queues the given DataBuffer to the - * m_writeBuffers queue. This queue is flushed out when the - * file-descriptor becomes writable next. This class assumes ownership - * of the provided DataBuffer. - */ -void -Transport::Write (DataBuffer *data) -{ - ASSERT ((m_Protocol != NULL), "no protocol attached"); - ASSERT ((data != NULL), "given data-buffer is NULL"); - - /* If we are not listening for write-events already, then hook up - with the reactor for writable events */ - if (m_writeDefer == NULL) +void Transport::stopReading (void) +{ + if (m_bAddedToReaders == true) { - if (m_writeTimeout == 0L) - { - m_writeDefer = m_Reactor->OnWritable (m_Fd); - } - else - { - m_writeDefer = m_Reactor->OnWritable (m_Fd, m_writeTimeout); - m_writeDefer->OnTimeout (Transport::handleWriteTimeout, this); - } - m_writeDefer->OnEvent (Transport::handleWritable, this); + m_Reactor->removeReader(this); + m_bAddedToReaders = false; } - /* add the DataBuffer to the queue */ - m_writeBuffers.push_back (data); - - /* assume ownership of the given data-buffer. we do this last so - that any exception in the middle does not cause a leak */ - data->Own (); } - -/** - * \brief Mark the connection to be destroyed. - * - * \details This method marks the transport for destruction. This - * should be used by the protocol to notify the transport to destory - * itself. The Transport will do the destruction once it regains - * control from the event handlers that it has called. - */ -void -Transport::LoseConnection (void) -{ - ASSERT ((m_Protocol != NULL), "no protocol attached"); - m_bDisconnectAndDie = true; -} - - -/* handlers for reactor generated events */ - -/** \todo: should use ioctl(m_Fd, SIOCINQ) to find the amount of - unread data in the socket and then construct the DataBuffer. This - should be done in the 'doRead' coz, Transport does not know what - kind of file-descriptor we have with us. */ -void -Transport::handleReadable (void *obj) -{ - ASSERT ((obj != NULL), "checking parameters"); - - DataBuffer *data; - Result ret; - Transport *trans = (Transport *) obj; - ASSERT ((trans->m_Protocol != NULL), "no protocol attached"); - - /* Read till there is no more */ - while (1) +void Transport::startWriting (void) +{ + if (m_bAddedToWriters == false) { - data = new DataBuffer (trans->m_readBufSize); - - /* call the sub-classes read-method to fill up the - data-buffer */ - ret = trans->doRead (data); - if (ret != Result_Success) - { - /* reading from transport failed */ - data->DisOwn (); - trans->m_Protocol->ReadError (); - goto __handlelReadable__ScreamAndDie__; - } - - if (data->Len() == 0) - { - /* If there is no more to read, then get out */ - data->DisOwn (); - break; - } - - /* give data-buffer to the protocol. after this point, the - Protocol takes responsibility for the data-buffer object */ - trans->m_Protocol->DataAvailable (data); - data->DisOwn (); - - /* check whether we should die */ - if (trans->m_bDisconnectAndDie == true) - { - goto __handlelReadable__ScreamAndDie__; - } + m_Reactor->addWriter(this); + m_bAddedToWriters = true; } - return; - - __handlelReadable__ScreamAndDie__ : - trans->doDisconnect (); - trans->m_Protocol->ConnectionLost (); - delete trans; - return; } - -void -Transport::handleReadTimeout (void *obj, h_msecs_t excess_time) -{ - ASSERT ((obj != NULL), "checking parameters"); - Transport *trans = (Transport *) obj; - ASSERT ((trans->m_Protocol != NULL), "no protocol attached"); - - /* notify read-timeout to the protocol */ - trans->m_Protocol->ReadTimeout (excess_time); - - if (trans->m_bDisconnectAndDie == true) +void Transport::stopWriting (void) +{ + if (m_bAddedToWriters == true) { - goto __handlelReadTimeout__ScreamAndDie__; + m_Reactor->removeWriter(this); + m_bAddedToWriters = false; } - - __handlelReadTimeout__ScreamAndDie__: - trans->doDisconnect (); - trans->m_Protocol->ConnectionLost (); - delete trans; - return; } - -void -Transport::handleWritable (void *obj) +void Transport::setProtocol (Protocol *protocol) { - ASSERT ((obj != NULL), "checking parameters"); - - Transport *trans = (Transport *) obj; - ASSERT ((trans->m_Protocol != NULL), "no protocol attached"); - - /* call the base-class method to write the pending buffers */ - Result ret; - ret = trans->doWrite (); - if (ret == Result_Error) - { - /* writing to transport failed */ - trans->m_Protocol->WriteError (); - goto __handlelWritable__ScreamAndDie__; - } - if (ret == Result_Success) - { - /* nothing more to write */ - trans->m_Reactor->UnRegister (trans->m_writeDefer); - trans->m_writeDefer = NULL; - } - return; - - __handlelWritable__ScreamAndDie__ : - trans->doDisconnect (); - trans->m_Protocol->ConnectionLost (); - delete trans; - return; + ASSERT ((protocol != NULL), "checking parameters"); + m_Protocol = protocol; } -void -Transport::handleWriteTimeout (void *obj, h_msecs_t excess_time) -{ - ASSERT ((obj != NULL), "checking parameters"); - - Transport *trans = (Transport *) obj; - ASSERT ((trans->m_Protocol != NULL), "no protocol attached"); - - /* notify write-timeout to the protocol */ - trans->m_Protocol->WriteTimeout (excess_time); -} - /* Local Variables: mode: c++ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:31:26
|
Revision: 27 http://asycxx.svn.sourceforge.net/asycxx/?rev=27&view=rev Author: joe_steeve Date: 2009-04-08 07:31:24 +0000 (Wed, 08 Apr 2009) Log Message: ----------- added class:StreamTransport to hold all connection oriented Transports From: Joe Steeve <js...@hi...> Added Paths: ----------- trunk/include/asycxx/StreamTransport.h trunk/src/StreamTransport.cxx Added: trunk/include/asycxx/StreamTransport.h =================================================================== --- trunk/include/asycxx/StreamTransport.h (rev 0) +++ trunk/include/asycxx/StreamTransport.h 2009-04-08 07:31:24 UTC (rev 27) @@ -0,0 +1,127 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__STREAM_TRANSPORT_H__ +#define __HIPRO_ASYCXX__STREAM_TRANSPORT_H__ + +#include "Error.h" +#include "Transport.h" +#include "DataBuffer.h" +#include "StreamProtocol.h" + +#define ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE 1024 +namespace asycxx +{ + class StreamTransport : public Transport + { + public: + /** + * \brief CTOR + * + * \param[in] reactor Pointer to a Reactor + * \param[in] fd A valid file-descriptor to build the transport on + */ + StreamTransport (Reactor *reactor, int fd); + virtual ~StreamTransport (); + + /** + * \brief Queues the provided data-buffer for writing + * + * \param[in] data The DataBuffer object that should be written + * + * \details This method queues the given DataBuffer to the + * m_writeBuffers queue. This queue is flushed out when the + * file-descriptor becomes writable next. This class assumes + * ownership of the provided DataBuffer. + */ + void Write (DataBuffer *data); + + /** + * \brief Mark the transport for destruction + * + * \details This method marks the transport for destruction. This + * should be used by the protocol to notify the transport to + * destory itself. The Transport will do the destruction once it + * regains control from the event handlers that it has called. + */ + void loseConnection (void); + + /** + * \brief set the size of the read-buffer + * + * \details This method configures the size of the read-buffer to + * the given size. This is an upper limit on the amount of data + * read at any given time. If available data is more than this + * length, then it is read in multiple parts (chunks). + */ + void configureReadBufferSize (size_t len); + + /** + * \brief configure a timeout for the 'wait for readable' + * operation + */ + void configureReadTimeout (asycxx_msecs_t timeout); + + /** + * \brief configure a timeout for the 'wait for writable' + * operation + */ + void configureWriteTimeout (asycxx_msecs_t timeout); + + /** + * \brief Attach the given protocol to the Transport + */ + StreamProtocol * getProtocol (void) + { + return (StreamProtocol *) Transport::getProtocol(); + } + + /** + * \brief Get the currently attached protocol + */ + void setProtocol (StreamProtocol *protocol) + { + Transport::setProtocol ((Protocol *)protocol); + } + + /* Methods to provide 'Selectable' interface. Lookup 'Selectable' + * for documentation */ + virtual void Readable (void); + virtual void Writable (void); + virtual void Close (void); + virtual void closeReader (void); + virtual void closeWriter (void); + + protected: + asycxx_msecs_t m_writeTimeout; /* the timeout used for writing */ + asycxx_msecs_t m_readTimeout; /* the timeout used for reading */ + size_t m_readBufSize; // max buffer size to read + + std::list<DataBuffer *> m_writeBuffers; + bool m_bDisconnectAndDie; + + /* methods to be implemented by the derived sub-classes */ + virtual RetCode doWrite (void); + virtual RetCode doRead (DataBuffer *data); + }; +} +#endif /* __HIPRO_ASYCXX__STREAM_TRANSPORT_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/src/StreamTransport.cxx =================================================================== --- trunk/src/StreamTransport.cxx (rev 0) +++ trunk/src/StreamTransport.cxx 2009-04-08 07:31:24 UTC (rev 27) @@ -0,0 +1,311 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include <unistd.h> +#include <errno.h> +#include <string.h> + +#include "asycxx-common.h" +#include <asycxx/Error.h> +#include <asycxx/StreamTransport.h> +#include <asycxx/StreamProtocol.h> + +using namespace asycxx; + + +/* + * CTOR + */ +StreamTransport::StreamTransport (Reactor *reactor, int fd) + : Transport (reactor, fd) +{ + m_bDisconnectAndDie = false; + + /* default configuration */ + configureReadTimeout (0L); + configureWriteTimeout (0L); + configureReadBufferSize (ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE); +} + + +/* + * DTOR + */ +StreamTransport::~StreamTransport () +{ + DataBuffer *data; + + /* discard the DataBuffers in the pending queue */ + std::list<DataBuffer *>::iterator it; + for (it = m_writeBuffers.begin(); it != m_writeBuffers.end(); it++) + { + data = *it; + ERR ("Transport<%p> dumping write-buffer <%p>, len=%d", + this, data->Data(), data->Len()); + data->DisOwn (); + } +} + + +void +StreamTransport::configureReadBufferSize (size_t len) +{ + ASSERT ((len != 0), "zero length read-buffer??"); + m_readBufSize = len; +} + + +/* TODO: setup a timer to handle timeout and inform the protocol about + * the timeout */ +void +StreamTransport::configureReadTimeout (asycxx_msecs_t timeout) +{ + m_readTimeout = timeout; +} + +void +StreamTransport::configureWriteTimeout (asycxx_msecs_t timeout) +{ + m_writeTimeout = timeout; +} + + +/* Method to Write a buffer. This method should queue the buffer for + * writing. The actual writing should happen later when the + * file-handle becomes writable. */ +void +StreamTransport::Write (DataBuffer *data) +{ + ASSERT ((data != NULL), "given data-buffer is NULL"); + /* If we are not on the reactor's writers list, then add ourselves + to the reactor's writers list */ + startWriting(); + /* add the DataBuffer to the queue */ + m_writeBuffers.push_back (data); + /* assume ownership of the given data-buffer. we do this last so + that any exception in the middle does not cause a leak */ + data->Own (); +} + + +/* Mark the transport for destruction */ +void +StreamTransport::loseConnection (void) +{ + m_bDisconnectAndDie = true; +} + + +/* This method is called by the reactor when the transport becomes + readable */ +void +StreamTransport::Readable (void) +{ + DataBuffer *data; + RetCode ret; + StreamProtocol *proto; + proto = getProtocol (); + + /** \todo: should use ioctl(m_Fd, SIOCINQ) to find the amount of + * unread data in the socket and then construct the DataBuffer. This + * should be done in the 'doRead' coz, Transport does not know what + * kind of file-descriptor we have with us. */ + + /* Read till there is no more */ + while (1) + { + data = new DataBuffer (m_readBufSize); + + /* call the sub-classes read-method to fill up the + data-buffer */ + ret = doRead (data); + if (ret != RetCode_Success) + { + /* reading from transport failed */ + data->DisOwn (); + proto->ReadError (); + goto __handlelReadable__ScreamAndDie__; + } + + if (data->Len() == 0) + { + /* If there is no more to read, then get out */ + data->DisOwn (); + break; + } + + /* give data-buffer to the protocol. after this point, the + Protocol takes responsibility for the data-buffer object */ + proto->DataAvailable (data); + data->DisOwn (); + + /* check whether we should die */ + if (m_bDisconnectAndDie == true) + { + goto __handlelReadable__ScreamAndDie__; + } + } + return; + + __handlelReadable__ScreamAndDie__ : + Close (); + proto->ConnectionLost (); + delete this; +} + + +/* This method is called by the reactor when a 'Selectable' becomes + * writable. */ +void +StreamTransport::Writable (void) +{ + StreamProtocol *proto; + proto = getProtocol (); + RetCode ret; + + /* call the base-class method to write the pending buffers */ + ret = doWrite (); + if (ret == RetCode_Error) + { + /* writing to transport failed */ + proto->WriteError (); + goto __handlelWritable__ScreamAndDie__; + } + if (ret == RetCode_Success) + { + /* nothing more to write */ + stopWriting(); + } + return; + + __handlelWritable__ScreamAndDie__ : + Close (); + proto->ConnectionLost (); + delete this; +} + + +RetCode +StreamTransport::doRead (DataBuffer *data) +{ + ASSERT ((data != NULL), "checking parameters"); + ssize_t rlen; + + __doRead__again: + rlen = read (Fd(), data->Data(), data->BufferLen()); + if (rlen == -1) + { + if (errno == EINTR) + { + goto __doRead__again; + } + else if (errno == EAGAIN) + { + data->Len(0); + return RetCode_Success; + } + else + { + ERR ("%s: reading from fd=%d", strerror(errno), Fd()); + return RetCode_Error; + } + } + + /* check for end-of-file */ + if (rlen == 0) + { + ERR ("EoF on fd=%d", Fd()); + return RetCode_Error; + } + data->Len(rlen); + + return RetCode_Success; +} + + +RetCode +StreamTransport::doWrite (void) +{ + ssize_t wrote; + ssize_t wlen, to_wlen; + DataBuffer *data; + void *bfr; + std::list<DataBuffer *>::iterator it; + + wrote = 0; + it = m_writeBuffers.begin(); + while (it != m_writeBuffers.end()) + { + data = *it; + to_wlen = data->Len() - data->Processed(); + bfr = data->UnProcessed (); + + wlen = write (Fd(), bfr, to_wlen); + if (wlen == -1) + { + if (errno == EINTR) { continue; } + else if (errno == EAGAIN) { return RetCode_Pending; } + else + { + ERR ("%s: writing DataBuffer<%p>::data<%p>,len=%d to fd=%d", + strerror (errno), data, bfr, to_wlen, Fd()); + return RetCode_Error; + } + } + + /* update pointers */ + data->Processed((data->Processed() + wlen)); + wrote += wlen; + + if (data->Processed() == data->Len()) + { + it = m_writeBuffers.erase(it); + data->DisOwn(); + } + } + + return RetCode_Success; +} + + +void +StreamTransport::Close (void) +{ + ERR ("I got nothing special to close"); +} + +void +StreamTransport::closeReader (void) +{ + ERR ("I dont know how to close the reader-end"); +} + + +void +StreamTransport::closeWriter (void) +{ + ERR ("I dont know how to close the writer-end"); +} + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:32:12
|
Revision: 28 http://asycxx.svn.sourceforge.net/asycxx/?rev=28&view=rev Author: joe_steeve Date: 2009-04-08 07:32:11 +0000 (Wed, 08 Apr 2009) Log Message: ----------- moved one-liners in Listener.cxx to Listener.h * moved class:Listeners to 'asycxx' namespace From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/Listener.h Removed Paths: ------------- trunk/src/Listener.cxx Modified: trunk/include/asycxx/Listener.h =================================================================== --- trunk/include/asycxx/Listener.h 2009-04-08 07:31:24 UTC (rev 27) +++ trunk/include/asycxx/Listener.h 2009-04-08 07:32:11 UTC (rev 28) @@ -16,16 +16,18 @@ #include "Error.h" #include "Reactor.h" +#include "Selectable.h" -class Listener +namespace asycxx { - -public: - Listener (); - virtual ~Listener (); + class Listener : public Selectable + { + public: + Listener () {} + virtual ~Listener () {} + }; +} -}; - #endif /* __HIPRO_ASYCXX__LISTENER_H__ */ /* Deleted: trunk/src/Listener.cxx =================================================================== --- trunk/src/Listener.cxx 2009-04-08 07:31:24 UTC (rev 27) +++ trunk/src/Listener.cxx 2009-04-08 07:32:11 UTC (rev 28) @@ -1,41 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <asycxx-config.h> -#endif - - -#include "asycxx-common.h" -#include <asycxx/Error.h> -#include <asycxx/Listener.h> - - -Listener::Listener () -{ - -} - -Listener::~Listener () -{ - -} - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:33:03
|
Revision: 29 http://asycxx.svn.sourceforge.net/asycxx/?rev=29&view=rev Author: joe_steeve Date: 2009-04-08 07:32:54 +0000 (Wed, 08 Apr 2009) Log Message: ----------- converted class:Protocol to a simple base class Since 'stream' protocols and 'datagram' protocols behave completely differently, the class:Protocol now contains only the bare minimum. From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/Protocol.h trunk/src/Protocol.cxx Modified: trunk/include/asycxx/Protocol.h =================================================================== --- trunk/include/asycxx/Protocol.h 2009-04-08 07:32:11 UTC (rev 28) +++ trunk/include/asycxx/Protocol.h 2009-04-08 07:32:54 UTC (rev 29) @@ -17,37 +17,54 @@ #include "Error.h" #include "Reactor.h" #include "DataBuffer.h" -#include "Transport.h" -#include "Factory.h" #define ASYCXX_DEFAULT_PROTOCOL_BUFSIZE 1024 -class Protocol +namespace asycxx { -public: - Protocol (Reactor *reactor, Factory *factory, Transport *transport); - virtual ~Protocol (); + class ProtocolFactory; - void BuildProtocol (void); - /* Methods exposed for the 'transport' to send msgs to the - Protocol */ - virtual void DataAvailable (DataBuffer *data); - virtual void ConnectionLost (void); - virtual void ReadTimeout (h_msecs_t excess_time); - virtual void ReadError (void); - virtual void WriteTimeout (h_msecs_t excess_time); - virtual void WriteError (void); - -protected: - Reactor *m_Reactor; - Factory *m_Factory; - Transport *m_Transport; + class Protocol + { + public: + Protocol (Reactor *reactor, ProtocolFactory *factory); + virtual ~Protocol () {} - /* Interface that should be implemented by all protocol - sub-classes */ - virtual Result InitProtocol (void); -}; + /** + * \brief Get the 'Reactor' that is being used + */ + Reactor * getReactor (void) { return m_Reactor; } + /** + * \brief Get the 'Factory' that created this 'Protocol' + */ + ProtocolFactory * getFactory (void) { return m_Factory; } + + /** + * \brief Method used by the 'Transport' to notify read-timeout + */ + virtual void ReadTimeout (asycxx_msecs_t excess_time); + + /** + * \brief Method used by the 'Transport' to notify read-error + */ + virtual void ReadError (void); + + /** + * \brief Method used by the 'Transport' to notify write-timeout + */ + virtual void WriteTimeout (asycxx_msecs_t excess_time); + + /** + * \brief Method used by the 'Transport' to notify write-error + */ + virtual void WriteError (void); + + private: + Reactor *m_Reactor; + ProtocolFactory *m_Factory; + }; +} #endif /* __HIPRO_ASYCXX__PROTOCOL_H__ */ /* Modified: trunk/src/Protocol.cxx =================================================================== --- trunk/src/Protocol.cxx 2009-04-08 07:32:11 UTC (rev 28) +++ trunk/src/Protocol.cxx 2009-04-08 07:32:54 UTC (rev 29) @@ -20,63 +20,23 @@ #include <asycxx/Error.h> #include <asycxx/Protocol.h> +using namespace asycxx; -Protocol::Protocol (Reactor *reactor, Factory *factory, Transport *transport) +Protocol::Protocol (Reactor *reactor, ProtocolFactory *factory) { ASSERT ((reactor != NULL), "checking parameters"); ASSERT ((factory != NULL), "checking parameters"); - ASSERT ((transport != NULL), "checking parameters"); - + m_Reactor = reactor; m_Factory = factory; - m_Transport = transport; - m_Transport->SetProtocol (this); } -Protocol::~Protocol () -{ -} -void -Protocol::BuildProtocol (void) -{ - Result ret; - ret = InitProtocol (); - if (ret == Result_Success) - { - return; - } - - /* looks like init-protocol was not overloaded. should configure - sane defaults */ -} - -Result -Protocol::InitProtocol (void) -{ - return Result_Error; -} - - /* default protocol methods. should be overridden by the derived classes */ void -Protocol::DataAvailable (DataBuffer *data) +Protocol::ReadTimeout (asycxx_msecs_t excess_time) { - ERR ("data-available but not handled. lame protocol"); -} - - -void -Protocol::ConnectionLost (void) -{ - ERR ("connection-lost not handled. lame protocol"); -} - - -void -Protocol::ReadTimeout (h_msecs_t excess_time) -{ ERR ("read timed out (excess=%lld) but not handled. lame protocol", excess_time); } @@ -88,7 +48,7 @@ } void -Protocol::WriteTimeout (h_msecs_t excess_time) +Protocol::WriteTimeout (asycxx_msecs_t excess_time) { ERR ("write timed out (excess=%lld) but not handled. lame protocol", excess_time); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:33:47
|
Revision: 30 http://asycxx.svn.sourceforge.net/asycxx/?rev=30&view=rev Author: joe_steeve Date: 2009-04-08 07:33:40 +0000 (Wed, 08 Apr 2009) Log Message: ----------- added class:StreamProtocol to provide a base for 'stream' protocols This contains code that was previously in class:Protocol. This class should serve as a base for all 'stream'/'connection' based protocols. From: Joe Steeve <js...@hi...> Added Paths: ----------- trunk/include/asycxx/StreamProtocol.h trunk/src/StreamProtocol.cxx Added: trunk/include/asycxx/StreamProtocol.h =================================================================== --- trunk/include/asycxx/StreamProtocol.h (rev 0) +++ trunk/include/asycxx/StreamProtocol.h 2009-04-08 07:33:40 UTC (rev 30) @@ -0,0 +1,77 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifndef __HIPRO_ASYCXX__STREAM_PROTOCOL_H__ +#define __HIPRO_ASYCXX__STREAM_PROTOCOL_H__ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + +#include "Error.h" +#include "Reactor.h" +#include "DataBuffer.h" +#include "Protocol.h" + + +namespace asycxx +{ + class StreamProtocolFactory; + class StreamTransport; + + class StreamProtocol : public Protocol + { + public: + StreamProtocol (Reactor *reactor, StreamProtocolFactory *factory, + StreamTransport *transport); + virtual ~StreamProtocol () {} + + /** + * \brief Called when there is data available + * + * \details This method is called by the attached + * 'StreamTransport' when there is data available. The given + * 'DataBuffer' is owned by the 'StreamTransport'. The 'Protocol' + * should claim it if it needs it for further processing. + */ + virtual void DataAvailable (DataBuffer *data); + + /** + * \brief Called when the connection is lost + * + * \details This method is called by the attached + * 'StreamTransport' when it loses connection. The 'Protocol' will + * be deleted after this. + */ + virtual void ConnectionLost (void); + + /** + * \brief get the current Transport + */ + StreamTransport * getTransport (void) { return m_Transport; } + + private: + StreamTransport * m_Transport; + }; +} + +#endif /* __HIPRO_ASYCXX__STREAM_PROTOCOL_H__ */ + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ Added: trunk/src/StreamProtocol.cxx =================================================================== --- trunk/src/StreamProtocol.cxx (rev 0) +++ trunk/src/StreamProtocol.cxx 2009-04-08 07:33:40 UTC (rev 30) @@ -0,0 +1,58 @@ + +/******************************************************************** + * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All + * rights reserved. + * + * This program and the accompanying materials are made available + * under the terms described in the LICENSE file which accompanies + * this distribution. If the LICENSE file was not attached to this + * distribution or for further clarifications, please contact + * le...@hi.... + * + *******************************************************************/ + +#ifdef HAVE_CONFIG_H +#include <asycxx-config.h> +#endif + + +#include "asycxx-common.h" +#include <asycxx/Error.h> +#include <asycxx/StreamProtocol.h> +#include <asycxx/StreamTransport.h> + +using namespace asycxx; + +StreamProtocol::StreamProtocol (Reactor *reactor, + StreamProtocolFactory *factory, + StreamTransport *transport) + : Protocol (reactor, (ProtocolFactory *)factory) +{ + ASSERT ((transport != NULL), "NULL transport?"); + m_Transport = transport; + m_Transport->startReading(); +} + +/* default protocol methods. should be overridden by the derived + classes */ +void +StreamProtocol::DataAvailable (DataBuffer *data) +{ + ERR ("data-available but not handled. lame protocol"); +} + + +void +StreamProtocol::ConnectionLost (void) +{ + ERR ("connection-lost not handled. lame protocol"); +} + +/* + Local Variables: + mode: c++ + indent-tabs-mode: nil + tab-width: 4 + c-file-style: "gnu" + End: +*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:35:08
|
Revision: 32 http://asycxx.svn.sourceforge.net/asycxx/?rev=32&view=rev Author: joe_steeve Date: 2009-04-08 07:35:06 +0000 (Wed, 08 Apr 2009) Log Message: ----------- refactored class:TCPTransport to derive from StreamTransport Since most of the I/O code is the same as the one in StreamTransport, this class only provides ways to close the transport properly From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/TCPTransport.h trunk/src/TCPTransport.cxx Modified: trunk/include/asycxx/TCPTransport.h =================================================================== --- trunk/include/asycxx/TCPTransport.h 2009-04-08 07:34:17 UTC (rev 31) +++ trunk/include/asycxx/TCPTransport.h 2009-04-08 07:35:06 UTC (rev 32) @@ -18,21 +18,23 @@ #include "Error.h" #include "Reactor.h" #include "DataBuffer.h" -#include "Transport.h" +#include "StreamTransport.h" -class TCPTransport : public Transport +namespace asycxx { -public: - TCPTransport (Reactor *reactor, int fd); - virtual ~TCPTransport (); - -protected: - Result doWrite (void); - Result doRead (DataBuffer *data); - void doDisconnect (void); - -}; + class TCPTransport : public StreamTransport + { + public: + TCPTransport (Reactor *reactor, int fd) : StreamTransport (reactor, fd) {} + virtual ~TCPTransport (); + /* methods to satisfy the 'Transport' interface */ + void Close (void); + void closeReader (void); + void closeWriter (void); + }; +} + #endif /* __HIPRO_ASYCXX__TCP_TRANSPORT_H__ */ /* Modified: trunk/src/TCPTransport.cxx =================================================================== --- trunk/src/TCPTransport.cxx 2009-04-08 07:34:17 UTC (rev 31) +++ trunk/src/TCPTransport.cxx 2009-04-08 07:35:06 UTC (rev 32) @@ -28,140 +28,59 @@ #include <asycxx/Protocol.h> #include <asycxx/TCPTransport.h> +using namespace asycxx; -TCPTransport::TCPTransport (Reactor *reactor, int fd) - : Transport (reactor, fd) + +TCPTransport::~TCPTransport () { + Close (); } -TCPTransport::~TCPTransport () +void +TCPTransport::Close (void) { + closeReader (); + closeWriter (); } -Result -TCPTransport::doRead (DataBuffer *data) +void +TCPTransport::closeReader (void) { - ASSERT ((data != NULL), "checking parameters"); - ssize_t rlen; - - __doRead__again: - rlen = read (m_Fd, data->Data(), data->BufferLen()); - if (rlen == -1) + stopReading(); // first unhook from the reactor + if (isReaderOpen()) { - if (errno == EINTR) - { - goto __doRead__again; - } - else if (errno == EAGAIN) + int ret; + ret = shutdown (Fd(), SHUT_RD); + if (ret == -1) { - data->Len(0); - return Result_Success; + ERR ("%s: shutting-down read end of TCP connection, %d", + strerror(errno), Fd()); } - else - { - ERR ("%s: reading from fd=%d", strerror(errno), m_Fd); - return Result_Error; - } + markReaderAsClosed(); } - - /* check for end-of-file */ - if (rlen == 0) - { - ERR ("EoF on fd=%d", m_Fd); - return Result_Error; - } - data->Len(rlen); - - return Result_Success; } -Result -TCPTransport::doWrite (void) +void +TCPTransport::closeWriter (void) { - ssize_t wrote; - ssize_t wlen, to_wlen; - DataBuffer *data; - void *bfr; - - wrote = 0; - while (m_writeBuffers.size() > 0) + stopWriting (); // first unhook from the reactor + if (isWriterOpen()) { - data = m_writeBuffers[0]; - to_wlen = data->Len() - data->Processed(); - bfr = data->UnProcessed (); - - wlen = write (m_Fd, bfr, to_wlen); - if (wlen == -1) + int ret; + ret = shutdown (Fd(), SHUT_WR); + if (ret == -1) { - if (errno == EINTR) { continue; } - else if (errno == EAGAIN) { return Result_Pending; } - else - { - ERR ("%s: writing DataBuffer<%p>::data<%p>,len=%d to fd=%d", - strerror (errno), data, bfr, to_wlen, m_Fd); - return Result_Error; - } + ERR ("%s: shutting-down write end of TCP connection, %d", + strerror(errno), Fd()); } - - /* update pointers */ - data->Processed((data->Processed() + wlen)); - wrote += wlen; - - if (data->Processed() == data->Len()) - { - m_writeBuffers.pop_front(); - data->DisOwn(); - } + markWriterAsClosed(); } - - return Result_Success; } -void -TCPTransport::doDisconnect (void) -{ - int ret; - ret = shutdown (m_Fd, SHUT_RDWR); - if (ret == -1) - { - ERR ("%s: shutting down connection", strerror(errno)); - } - -} - -// Result -// TCPTransport::configureTCPNoDelay (void) -// { -// /** \todo using setsockopt should configure TCP_NODELAY. This disables -// nagle's algorithm and increase small packets on the network. */ -// ASSERT ((m_Fd != -1), "sanity checks"); - -// int iret; -// int optval = 1; -// iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_NODELAY, (void *)&optval, -// sizeof (optval)); -// if (iret != 0) -// { - -// } -// } - - -// Result -// TCPTransport::configureTCPKeelAlive (int idle_time, int probe_count, -// int probe_interval) -// { -// /** \todo using setsockopt should configure TCP_KEEPCNT */ - -// /** \todo using setsockopt should configure TCP_KEEPIDLE */ - -// /** \todo using setsockopt should configure TCP_KEEPINTVL */ -// } - /* Local Variables: mode: c++ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:35:52
|
Revision: 33 http://asycxx.svn.sourceforge.net/asycxx/?rev=33&view=rev Author: joe_steeve Date: 2009-04-08 07:35:50 +0000 (Wed, 08 Apr 2009) Log Message: ----------- moved class:MsgBus into 'asycxx' namespace From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/MsgBus.h trunk/src/MsgBus.cxx Modified: trunk/include/asycxx/MsgBus.h =================================================================== --- trunk/include/asycxx/MsgBus.h 2009-04-08 07:35:06 UTC (rev 32) +++ trunk/include/asycxx/MsgBus.h 2009-04-08 07:35:50 UTC (rev 33) @@ -27,21 +27,25 @@ * time of construction. This class assumes ownership of the * MsgHandler and destroys it when this is destroyed. */ -class MsgHandler; -class MsgBus +namespace asycxx { -public: - MsgBus (MsgHandler *handler); - virtual ~MsgBus (); + class MsgHandler; - virtual void SendMsg (DataBuffer *msg) = 0; + class MsgBus + { + public: + MsgBus (MsgHandler *handler); + virtual ~MsgBus (); -protected: - MsgHandler *m_Handler; + virtual void SendMsg (DataBuffer *msg) = 0; -}; + protected: + MsgHandler *m_Handler; + }; +} + #endif /* __HIPRO_ASYCXX__MSG_BUS_H__ */ /* Modified: trunk/src/MsgBus.cxx =================================================================== --- trunk/src/MsgBus.cxx 2009-04-08 07:35:06 UTC (rev 32) +++ trunk/src/MsgBus.cxx 2009-04-08 07:35:50 UTC (rev 33) @@ -19,6 +19,8 @@ #include <asycxx/MsgBus.h> #include <asycxx/MsgHandler.h> +using namespace asycxx; + MsgBus::MsgBus (MsgHandler *handler) { ASSERT ((handler != NULL), "cannot use a NULL MsgHandler"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:36:35
|
Revision: 34 http://asycxx.svn.sourceforge.net/asycxx/?rev=34&view=rev Author: joe_steeve Date: 2009-04-08 07:36:33 +0000 (Wed, 08 Apr 2009) Log Message: ----------- moved oneliners in MsgHandler.cxx to MsgHandler.h From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/MsgHandler.h Removed Paths: ------------- trunk/src/MsgHandler.cxx Modified: trunk/include/asycxx/MsgHandler.h =================================================================== --- trunk/include/asycxx/MsgHandler.h 2009-04-08 07:35:50 UTC (rev 33) +++ trunk/include/asycxx/MsgHandler.h 2009-04-08 07:36:33 UTC (rev 34) @@ -26,19 +26,26 @@ * \brief The interface of a MsgHandler */ -class MsgHandler +namespace asycxx { -public: - MsgHandler (); - virtual ~MsgHandler (); + class MsgHandler + { + public: + MsgHandler () { m_Bus = NULL; } + virtual ~MsgHandler () {} - void SetMsgBus (MsgBus *bus); - virtual Result GotMsg (DataBuffer *data) = 0; + void SetMsgBus (MsgBus *bus) + { + ASSERT ((bus != NULL), "cannot use a NULL MsgBus"); + m_Bus = bus; + } -protected: - MsgBus *m_Bus; -}; + virtual RetCode GotMsg (DataBuffer *data) = 0; + protected: + MsgBus *m_Bus; + }; +} #endif /* __HIPRO_ASYCXX__MSG_HANDLER_H__ */ /* Deleted: trunk/src/MsgHandler.cxx =================================================================== --- trunk/src/MsgHandler.cxx 2009-04-08 07:35:50 UTC (rev 33) +++ trunk/src/MsgHandler.cxx 2009-04-08 07:36:33 UTC (rev 34) @@ -1,47 +0,0 @@ - -/******************************************************************** - * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All - * rights reserved. - * - * This program and the accompanying materials are made available - * under the terms described in the LICENSE file which accompanies - * this distribution. If the LICENSE file was not attached to this - * distribution or for further clarifications, please contact - * le...@hi.... - * - *******************************************************************/ - -#ifdef HAVE_CONFIG_H -#include <asycxx-config.h> -#endif - -#include "asycxx-common.h" -#include <asycxx/Error.h> -#include <asycxx/MsgHandler.h> - -MsgHandler::MsgHandler () -{ - m_Bus = NULL; -} - - -MsgHandler::~MsgHandler () -{ -} - - -void -MsgHandler::SetMsgBus (MsgBus *bus) -{ - ASSERT ((bus != NULL), "cannot use a NULL MsgBus"); - m_Bus = bus; -} - -/* - Local Variables: - mode: c++ - indent-tabs-mode: nil - tab-width: 4 - c-file-style: "gnu" - End: -*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:37:19
|
Revision: 35 http://asycxx.svn.sourceforge.net/asycxx/?rev=35&view=rev Author: joe_steeve Date: 2009-04-08 07:37:17 +0000 (Wed, 08 Apr 2009) Log Message: ----------- class:TCPListener now uses StreamProtocol/ProtocolFactory/Transport From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/TCPListener.h trunk/src/TCPListener.cxx Modified: trunk/include/asycxx/TCPListener.h =================================================================== --- trunk/include/asycxx/TCPListener.h 2009-04-08 07:36:33 UTC (rev 34) +++ trunk/include/asycxx/TCPListener.h 2009-04-08 07:37:17 UTC (rev 35) @@ -19,37 +19,75 @@ #include "Error.h" #include "Listener.h" -#include "Factory.h" -#include "Deferred.h" +#include "StreamProtocolFactory.h" #include "Reactor.h" -class TCPListener : public Listener +namespace asycxx { -public: + class TCPListener : public Listener + { + public: - TCPListener (Reactor *reactor, Factory *factory, unsigned short port); - TCPListener (Reactor *reactor, Factory *factory, char *ip, - unsigned short port); - virtual ~TCPListener (); + /** + * \brief ctor to put TCPListener on localhost:port + * + * \param[in] reactor The reactor to hook to + * \param[in] factory The factory to use to produce protocols to + * handle new connections + * \param[in] port The port number to bind to + * + * \details This constructor puts the TCPListener object to listen + * on the 127.0.0.1:port interface. + */ + TCPListener (Reactor *reactor, StreamProtocolFactory *factory, + unsigned short port); - void SetupTCPNoDelay (void); + /** + * \brief ctor to put TCPListener on given ip:port + * + * \param[in] reactor The reactor to hook to + * \param[in] factory The factory to use to produce protocols to + * handle new connections + * \param[in] ip A string containing the IP address to bind to + * \param[in] port The port number to bind to + * + * \details This constructor puts the TCPListener object to listen + * on the given ip:port interface. This method expects a valid + * IPv4 ip-address in the 'ip' parameter. + */ + TCPListener (Reactor *reactor, StreamProtocolFactory *factory, + char *ip, unsigned short port); -protected: - Reactor *m_Reactor; - Factory *m_Factory; - Deferred *m_ReactorDeferred; + virtual ~TCPListener () {}; - int m_Socket; - unsigned short m_BindPort; - in_addr m_BindIPAddr; - char m_BindAddr_str[64]; - bool m_bSetupNoDelay; + /** + * \brief set the socket as TCP_NODELAY + * + * \details This method disables the Nagle algorithm on the + * connection by setting TCP_NODELAY. + */ + void SetupTCPNoDelay (void) { m_bSetupNoDelay = true; } - void Init (Reactor *reactor, Factory *factory, - struct in_addr ip_addr, unsigned short port); - static void handleNewConnection (void *obj); -}; + /* methods to be implemented for 'Selectable' */ + virtual void Readable (void); + + virtual void Writable (void) {} + virtual void closeReader (void) {} + virtual void closeWriter (void) {} + protected: + Reactor *m_Reactor; + StreamProtocolFactory *m_Factory; + + unsigned short m_BindPort; + in_addr m_BindIPAddr; + char m_BindAddr_str[64]; + bool m_bSetupNoDelay; + + void Init (Reactor *reactor, StreamProtocolFactory *factory, + struct in_addr ip_addr, unsigned short port); + }; +} #endif /* __HIPRO_ASYCXX__TCP_LISTENER_H__ */ /* Modified: trunk/src/TCPListener.cxx =================================================================== --- trunk/src/TCPListener.cxx 2009-04-08 07:36:33 UTC (rev 34) +++ trunk/src/TCPListener.cxx 2009-04-08 07:37:17 UTC (rev 35) @@ -27,141 +27,87 @@ #include "asycxx-common.h" #include <asycxx/Error.h> -#include <asycxx/Factory.h> -#include <asycxx/Protocol.h> +#include <asycxx/StreamProtocolFactory.h> +#include <asycxx/StreamProtocol.h> #include <asycxx/TCPTransport.h> #include <asycxx/TCPListener.h> +using namespace asycxx; -/** - * \brief ctor to put TCPListener on localhost:port - * - * \param[in] reactor The reactor to hook to - * \param[in] factory The factory to use to produce protocols to - * handle new connections - * \param[in] port The port number to bind to - * - * \details This constructor puts the TCPListener object to listen on - * the 127.0.0.1:port interface. - */ -TCPListener::TCPListener (Reactor *reactor, Factory *factory, +/* a simple constructor where we listen on loopback */ +TCPListener::TCPListener (Reactor *reactor, StreamProtocolFactory *factory, unsigned short port) { struct in_addr ip_addr; - ip_addr.s_addr = htonl (INADDR_LOOPBACK); + Init (reactor, factory, ip_addr, port); } -/** - * \brief ctor to put TCPListener on given ip:port - * - * \param[in] reactor The reactor to hook to - * \param[in] factory The factory to use to produce protocols to - * handle new connections - * \param[in] ip A string containing the IP address to bind to - * \param[in] port The port number to bind to - * - * \details This constructor puts the TCPListener object to listen on - * the given ip:port interface. This method expects a valid IPv4 - * ip-address in the 'ip' parameter. - */ -TCPListener::TCPListener (Reactor *reactor, Factory *factory, +/* a ctor to listen on a specific interface */ +TCPListener::TCPListener (Reactor *reactor, StreamProtocolFactory *factory, char *ip, unsigned short port) { int ret; struct in_addr ip_addr; ret = inet_aton (ip, &ip_addr); - if (ret == 0) - { - THROW (RunTimeError, "'%s' is not a valid ip-address", ip); - } + ASSERT ((ret != 0), "'%s' is not a valid ip-address", ip); Init (reactor, factory, ip_addr, port); } -/* - * \brief dtor - */ -TCPListener::~TCPListener () -{ - if (m_Socket != -1) - { - close (m_Socket); - } -} - -/** - * \brief Initialize the TCPListener - * - * \param[in] reactor The reactor to hook to - * \param[in] factory The factory to use to produce protocols - * \param[in] ip_addr A 'struct in_addr' containing the IP address to - * listen on - * \param[in] port The port to listen on - * - * \details This method is the backend method for all the - * constructors. This creates a socket, puts it on listening mode, - * binds it to the given interface and hooks it up to the reactor. - */ +/* This method is the backend method for all the constructors. This + * creates a socket, puts it on listening mode, binds it to the given + * interface and hooks it up to the reactor. */ void -TCPListener::Init (Reactor *reactor, Factory *factory, +TCPListener::Init (Reactor *reactor, StreamProtocolFactory *factory, struct in_addr ip_addr, unsigned short port) { int iret; - ASSERT ((factory != NULL), "checking parameters"); - ASSERT ((reactor != NULL), "checking parameters"); + ASSERT ((factory != NULL), "NULL factory :("); + ASSERT ((reactor != NULL), "NULL reactor :("); m_Factory = factory; m_Reactor = reactor; m_bSetupNoDelay = false; + int sock; sprintf (m_BindAddr_str, "%s:%d", inet_ntoa (ip_addr), port); /* creating a socket */ - m_Socket = socket (PF_INET, SOCK_STREAM, 0); - if (m_Socket == -1) - { - THROW (RunTimeError, - "TCPListener: %s : creating socket to listen on %s", - strerror (errno), m_BindAddr_str); - } + sock = socket (PF_INET, SOCK_STREAM, 0); + ASSERT ((sock != -1), "TCPListener: %s : creating socket to listen on %s", + strerror (errno), m_BindAddr_str); + /* set so_reuseaddr to avoid 'address in use' */ int on = 1; - iret = setsockopt (m_Socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + iret = setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); ASSERT ((iret == 0), "%s: setting SO_REUSEADDR on socket=%d", - strerror (errno), m_Socket); + strerror (errno), sock); + /* bind the socket to an interface */ struct sockaddr_in saddr; saddr.sin_family = AF_INET; saddr.sin_port = htons (port); saddr.sin_addr.s_addr = ip_addr.s_addr; - iret = bind (m_Socket, (struct sockaddr *)&saddr, sizeof (saddr)); - if (iret == -1) - { - close (m_Socket); - THROW (RunTimeError, - "TCPListener: %s : binding socket=%u to %s", - strerror (errno), m_Socket, m_BindAddr_str); - } + iret = bind (sock, (struct sockaddr *)&saddr, sizeof (saddr)); + ASSERT ((iret == 0), "TCPListener: %s : binding socket=%u to %s", + strerror (errno), sock, m_BindAddr_str); + /* put the socket on listen mode */ - iret = listen (m_Socket, 5); - if (iret == -1) - { - close (m_Socket); - THROW (RunTimeError, - "TCPListener: %s : putting socket=%u to listen on %s", - strerror (errno), m_Socket, m_BindAddr_str); - } + iret = listen (sock, 5); + ASSERT ((iret == 0), "TCPListener: %s : putting socket=%u to listen on %s", + strerror (errno), sock, m_BindAddr_str); + /* put the socket on non-blocking mode so that we can pass it on to the reactor */ - SetFDAsNonBlocking (m_Socket); - - /* register the non-blocking FD with the reactor */ - m_ReactorDeferred = m_Reactor->OnReadable (m_Socket); - m_ReactorDeferred->OnEvent (TCPListener::handleNewConnection, (void *)this); + SetFDAsNonBlocking (sock); + Fd (sock); + + /* hook ourselves to the reactor */ + m_Reactor->addReader (this); } @@ -171,20 +117,16 @@ * \details */ void -TCPListener::handleNewConnection (void *obj) +TCPListener::Readable (void) { - ASSERT ((obj != NULL), "checking parameters"); - int conn, ret; struct sockaddr_in addr; socklen_t addrlen; - Protocol *proto; - TCPListener *pthis = (TCPListener *) obj; while (1) { addrlen = sizeof (struct sockaddr_in); - conn = accept (pthis->m_Socket, (struct sockaddr *)&addr, &addrlen); + conn = accept (Fd(), (struct sockaddr *)&addr, &addrlen); if (conn == -1) { if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) @@ -192,59 +134,46 @@ if ((errno == EINTR) || (errno == ECONNABORTED)) { ERR ("non-fatal: %s: accepting connections on %s", - strerror(errno), pthis->m_BindAddr_str); + strerror(errno), m_BindAddr_str); return; } ERR ("%s: accepting connections on %s", - strerror(errno), pthis->m_BindAddr_str); + strerror(errno), m_BindAddr_str); ERR ("**FATAL** I am silently unregistering **FATAL**"); ERR ("**FATAL** I very definitely am lost :( **FATAL**"); - pthis->m_Reactor->UnRegister (pthis->m_ReactorDeferred); + m_Reactor->removeReader (this); return; } char client[64]; sprintf (client, "%s:%d", inet_ntoa (addr.sin_addr), addr.sin_port); - LOG3 ("incoming connection from %s on %s", client, pthis->m_BindAddr_str); + LOG3 ("incoming connection from %s on %s", client, m_BindAddr_str); /* See if we need TCP_NODELAY, and configure it */ - if (pthis->m_bSetupNoDelay == true) + if (m_bSetupNoDelay == true) { int optval = 1; ret = setsockopt (conn, IPPROTO_TCP, TCP_NODELAY, (void *)&optval, sizeof (optval)); - if (ret == -1) - { - THROW (RunTimeError, - "setting up TCP_NODELAY on fd=%d failed with %s", - conn, strerror (errno)); - } + ASSERT ((ret == 0), "setting up TCP_NODELAY on fd=%d failed with %s", + conn, strerror (errno)); } /* create a transport */ TCPTransport *trans; - trans = new TCPTransport (pthis->m_Reactor, conn); + trans = new TCPTransport (m_Reactor, conn); /* create a protocol using the factory */ - proto = pthis->m_Factory->GetProtocol (trans); - proto->BuildProtocol (); + StreamProtocol *proto; + proto = m_Factory->GetProtocol (trans); + + /* attach the protocol to the transport */ + trans->setProtocol (proto); } } -/** - * \brief set the socket as TCP_NODELAY - * - * \details This method disables the Nagle algorithm on the connection - * by setting TCP_NODELAY. - */ -void -TCPListener::SetupTCPNoDelay (void) -{ - m_bSetupNoDelay = true; -} - /* Local Variables: mode: c++ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:38:17
|
Revision: 36 http://asycxx.svn.sourceforge.net/asycxx/?rev=36&view=rev Author: joe_steeve Date: 2009-04-08 07:38:15 +0000 (Wed, 08 Apr 2009) Log Message: ----------- moved class:DataBuffer into 'asycxx' namespace From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/DataBuffer.h trunk/src/DataBuffer.cxx Modified: trunk/include/asycxx/DataBuffer.h =================================================================== --- trunk/include/asycxx/DataBuffer.h 2009-04-08 07:37:17 UTC (rev 35) +++ trunk/include/asycxx/DataBuffer.h 2009-04-08 07:38:15 UTC (rev 36) @@ -20,39 +20,41 @@ #include "_asycxx.h" #include "RefCounter.h" -class DataBuffer : public RefCounter +namespace asycxx { -public: - /* ctors */ - DataBuffer (size_t len); - DataBuffer (void *buffer, size_t len); + class DataBuffer : public RefCounter + { + public: + /* ctors */ + DataBuffer (size_t len); + DataBuffer (void *buffer, size_t len); - /* Accessors */ - void * Data (void) { return m_Data; } - size_t Len (void) { return m_DataLen; } - void Len (size_t len); - size_t BufferLen (void) { return m_BufferLen; } - void Processed (size_t len); - size_t Processed (void) { return m_ProcessedLen; } - void * UnProcessed (void); + /* Accessors */ + void * Data (void) { return m_Data; } + size_t Len (void) { return m_DataLen; } + void Len (size_t len); + size_t BufferLen (void) { return m_BufferLen; } + void Processed (size_t len); + size_t Processed (void) { return m_ProcessedLen; } + void * UnProcessed (void); -protected: - /* dtors */ - ~DataBuffer (); + protected: + /* dtors */ + ~DataBuffer (); -private: - /* initializer */ - void _init (void); + private: + /* initializer */ + void _init (void); - /* The buffer */ - void *m_Data; + /* The buffer */ + void *m_Data; - /* meta-data about the buffer and its contents */ - size_t m_BufferLen; /* Maximum length of the buffer */ - size_t m_DataLen; /* Length of data held in the buffer */ - size_t m_ProcessedLen; /* Length of data processed */ -}; - + /* meta-data about the buffer and its contents */ + size_t m_BufferLen; /* Maximum length of the buffer */ + size_t m_DataLen; /* Length of data held in the buffer */ + size_t m_ProcessedLen; /* Length of data processed */ + }; +} #endif /* __HIPRO_ASYCXX__DATA_BUFFER_H__ */ /* Modified: trunk/src/DataBuffer.cxx =================================================================== --- trunk/src/DataBuffer.cxx 2009-04-08 07:37:17 UTC (rev 35) +++ trunk/src/DataBuffer.cxx 2009-04-08 07:38:15 UTC (rev 36) @@ -20,6 +20,7 @@ #include "asycxx-common.h" #include <asycxx/DataBuffer.h> +using namespace asycxx; void DataBuffer::_init (void) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:39:06
|
Revision: 37 http://asycxx.svn.sourceforge.net/asycxx/?rev=37&view=rev Author: joe_steeve Date: 2009-04-08 07:39:05 +0000 (Wed, 08 Apr 2009) Log Message: ----------- moved Error* to 'asycxx' namespace From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/Error.h trunk/src/Error.cxx Modified: trunk/include/asycxx/Error.h =================================================================== --- trunk/include/asycxx/Error.h 2009-04-08 07:38:15 UTC (rev 36) +++ trunk/include/asycxx/Error.h 2009-04-08 07:39:05 UTC (rev 37) @@ -21,48 +21,58 @@ #define ExpMSG_LEN 1024 -class Error +namespace asycxx { -public: - Error () {} - Error (const char *fmt, ...) - { - va_list args; - va_start (args, fmt); - doError (fmt, args); - va_end (args); - } - virtual ~Error () {} + enum ErrorCode + { + Err_Unknown = 1, + Err_Timeout, + Err_BadFD, + }; -protected: - void doError (const char *fmt, va_list vargs); - virtual const char *GetErrorName (void) { return "Unknown error"; } -}; + class Error + { + public: + Error () {} + Error (const char *fmt, ...) + { + va_list args; + va_start (args, fmt); + doError (fmt, args); + va_end (args); + } + virtual ~Error () {} -#define CREATE_ERROR(err, berr, name) \ - class err : public berr \ - { \ -public: \ - err () {} \ - err (const char *fmt, ...) \ - { \ - va_list args; \ - va_start (args, fmt); \ - doError (fmt, args); \ - va_end (args); \ - } \ -protected: \ - virtual const char *GetErrorName (void) { return name; } \ + protected: + void doError (const char *fmt, va_list vargs); + virtual const char *GetErrorName (void) { return "Unknown error"; } + }; + +#define CREATE_ERROR(err, berr, name) \ + class err : public berr \ + { \ + public: \ + err () {} \ + err (const char *fmt, ...) \ + { \ + va_list args; \ + va_start (args, fmt); \ + doError (fmt, args); \ + va_end (args); \ + } \ + protected: \ + virtual const char *GetErrorName (void) { return name; } \ } -CREATE_ERROR (FatalError, Error, "unknown FatalError"); -CREATE_ERROR (OutOfMemoryError, FatalError, "OutOfMemoryError"); -CREATE_ERROR (DevError, FatalError, "DevError"); -CREATE_ERROR (RunTimeError, FatalError, "RunTimeError"); + CREATE_ERROR (FatalError, Error, "unknown FatalError"); + CREATE_ERROR (OutOfMemoryError, FatalError, "OutOfMemoryError"); + CREATE_ERROR (DevError, FatalError, "DevError"); + CREATE_ERROR (RunTimeError, FatalError, "RunTimeError"); -CREATE_ERROR (RecoverableError, Error, "unknown RecoverableError"); -CREATE_ERROR (BadFDError, RecoverableError, "BadFDError"); + CREATE_ERROR (RecoverableError, Error, "unknown RecoverableError"); + CREATE_ERROR (BadFDError, RecoverableError, "BadFDError"); +} #endif /* __HIPRO_ASYCXX__ERROR_H__ */ /* Modified: trunk/src/Error.cxx =================================================================== --- trunk/src/Error.cxx 2009-04-08 07:38:15 UTC (rev 36) +++ trunk/src/Error.cxx 2009-04-08 07:39:05 UTC (rev 37) @@ -22,6 +22,8 @@ #include "asycxx-common.h" #include <asycxx/Error.h> +using namespace asycxx; + void Error::doError (const char *fmt, va_list vargs) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:39:51
|
Revision: 38 http://asycxx.svn.sourceforge.net/asycxx/?rev=38&view=rev Author: joe_steeve Date: 2009-04-08 07:39:49 +0000 (Wed, 08 Apr 2009) Log Message: ----------- removed 'Deferred' code from class:Reactor Reactor now directly manages 'Selectables'. Since both Transports and Listeners are Selectables, we can directly use them instead of callbacks. From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/Reactor.h trunk/src/Reactor.cxx Modified: trunk/include/asycxx/Reactor.h =================================================================== --- trunk/include/asycxx/Reactor.h 2009-04-08 07:39:05 UTC (rev 37) +++ trunk/include/asycxx/Reactor.h 2009-04-08 07:39:49 UTC (rev 38) @@ -14,74 +14,152 @@ #ifndef __HIPRO_ASYCXX__REACTOR_H__ #define __HIPRO_ASYCXX__REACTOR_H__ +#include <list> -#include <deque> - #include "_asycxx.h" -#include "Deferred.h" +#include "Selectable.h" + #define TIME_SENSITIVITY 200LL -class Reactor +namespace asycxx { -public: - Reactor (); - virtual ~Reactor (); + /** + * \class Reactor + * + * \brief The main event dispatching mechanism + * + * \details The reactor provides a mechanism to register + * 'Selectable's waiting for readability or writability. The reactor + * sits in a tight loop waiting for any of the 'Selectable's to + * become readable/writable. The exact mechanism of this depends on + * the Reactor implementation. Eg: SelectReactor uses select(), + * while EPollReactor uses epoll(). + */ + class Reactor + { + public: + Reactor(); + virtual ~Reactor(); - Deferred * OnReadable (int Fd) throw (); - Deferred * OnReadable (int Fd, h_msecs_t timeoutTime) throw (); - Deferred * OnWritable (int Fd) throw (); - Deferred * OnWritable (int Fd, h_msecs_t timeoutTime) throw (); - Deferred * OnTimeElapsed (h_msecs_t timeoutTime) throw (); - void UnRegister (Deferred *deferred) throw (); + /** + * \brief Gets the current time-stamp (millisecond accuracy) + * + * \details This method returns the current time-stamp. This + * time-stamp gets updated every time the Reactor wakes up. + */ + asycxx_timestamp_t CurrentTS (void) { return m_LastAwokenTS; } - h_timestamp_t CurrentTS (void) { return m_LastAwokenTS; } - void Run (void); + /** + * \brief Add a 'Selectable' to be notified when Readable + * + * \param[in] reader A 'Selectable' object + * + * \details This method adds the given 'Selectable' to the list of + * 'readers'. + */ + virtual void addReader (Selectable *reader); + + /** + * \brief Add a 'Selectable' to be notified when Writable + * + * \param[in] writer A 'Selectable' object + * + * \details This method adds the given 'Selectable' to the list of + * 'writers'. + */ + virtual void addWriter (Selectable *writer); + + /** + * \brief Remove a 'Selectable' from 'readers list' + * + * \param[in] reader A 'Selectable' object + * + * \details This method removes the given 'Selectable' from the + * list of 'readers'. The given 'Selectable' wont get 'Readable' + * notification anymore. + */ + virtual void removeReader (Selectable *reader); + + /** + * \brief Remove a 'Selectable' from 'writers list' + * + * \param[in] reader A 'Selectable' object + * + * \details This method removes the given 'Selectable' from the + * list of 'writers'. The given 'Selectable' wont get 'Writable' + * notification anymore. + */ + virtual void removeWriter (Selectable *writer); + + /** + * \brief Clear all the 'readers' and 'writers' + * + * \details This method clears the readers and writers list. All + * objects associated with the selectables in the respective lists + * would also be destroyed. + * + * Note: Unless the application has registered a 'Timer', the + * application would hang after calling this method. + */ + //virtual void resetAll (void); + + /** + * \brief Runs the reactor + * + * \details This method does not return. It blocks waiting for + * events on the registered 'Selectables' and notifies them. + */ + void Run (void); -protected: - class Event - { - public: - Event (); - ~Event (); + protected: + class Event + { + public: + Event (Selectable *selectable) + { + pSelectable = selectable; + Fd = pSelectable->Fd(); + bDie = false; + } + ~Event () {} - bool m_bDie; + int Fd; + bool bDie; + Selectable *pSelectable; + }; - int m_Fd; - h_msecs_t m_TimeoutTime; - h_timestamp_t m_LastTriggerTS; - h_timestamp_t m_NextTriggerTS; - Deferred m_Deferred; - }; - std::deque<Event *> m_readEvents; - std::deque<Event *> m_writeEvents; - std::deque<Event *> m_timeEvents; + std::list<Event *> m_readEvents; + std::list<Event *> m_writeEvents; - int m_PendingFDEvents; - virtual void WaitForEvents (void) = 0; - virtual void ProcessFDEvents (void) = 0; + /** + * \brief Wait until some event occurs + * + * \details This method should be implemented by the specific + * reactor implementations. This method should block till some event + * occurs and is available for processing. This method should return + * the number of pending file-descriptor events. + */ + virtual int WaitForEvents (void) = 0; - /** - * \brief The TimeStamp when latest activity happened - * - * \detail This holds the last time-stamp when the reactor was doing - * something. This should be updated by Reactor implementations - * (Select, Epoll, etc.) everytime they wake up to do something - * (attend to file-descriptor activity or handle timeout actions - */ - h_timestamp_t m_LastAwokenTS; - void DoFDEventNotification (Reactor::Event *ev); - void DoFDTimeoutNotification (Reactor::Event *ev); + /** + * \brief Process the timeouts of FD events + * + * \details This method looks up the list of events for timeouts and + * fires them. + */ + virtual void ProcessEvents (void) = 0; -private: - void ProcessTimeEvents (void); - void ProcessFDTimeouts (void); - void CleanupEventLists (void); - Deferred * AddToReadEvents (int Fd, h_msecs_t timeoutTime); - Deferred * AddToWriteEvents (int Fd, h_msecs_t timeoutTime); + private: + asycxx_timestamp_t m_LastAwokenTS; -}; + void CleanupEventLists (void); + void _CleanupEventList (std::list<Event *>& ev_list); + void addFdEvent (Selectable *s, const char *type, + std::list<Reactor::Event *>& ev_list); + }; +} #endif /* __HIPRO_ASYCXX__REACTOR_H__ */ /* Modified: trunk/src/Reactor.cxx =================================================================== --- trunk/src/Reactor.cxx 2009-04-08 07:39:05 UTC (rev 37) +++ trunk/src/Reactor.cxx 2009-04-08 07:39:49 UTC (rev 38) @@ -11,545 +11,191 @@ * *******************************************************************/ -/** - * \author Joe Steeve, jo...@hi... - * \class Reactor - * \brief Core 'reactor' functionality - * - * \details The reactor is the core. - */ #ifdef HAVE_CONFIG_H #include <asycxx-config.h> #endif #include <unistd.h> -#include <exception> #include "asycxx-common.h" #include <asycxx/Reactor.h> -#include <asycxx/Deferred.h> +#include <asycxx/Selectable.h> +#include <asycxx/Error.h> -////////////////////////////////////////////////////////////////////////////// +using namespace asycxx; -/** - * \author Joe Steeve, jo...@hi... - * \class Reactor::Event - * \brief Defines an event - * - * \details This class defines an 'Event' - */ - -/** - * \brief ctor. - */ -Reactor::Event::Event () -{ - m_Fd = -1; - m_TimeoutTime = 0L; - m_LastTriggerTS = 0L; - m_NextTriggerTS = 0L; - m_bDie = false; -} - -/** - * \brief dtor. - */ -Reactor::Event::~Event () -{ -} - - ////////////////////////////////////////////////////////////////////////////// -/** - * \brief Constructor - * +/* + * CTOR: */ Reactor::Reactor () { - m_PendingFDEvents = 0; - m_LastAwokenTS = GetCurrentTimeStamp (); + m_LastAwokenTS = GetCurrentTimeStamp(); } -/** - * \brief Destructor - * +/* + * DTOR: we clear up all the event lists here */ Reactor::~Reactor () { - size_t i; - Event *ev; + std::list<Event *>::iterator it; /* Destroy all event-infos */ - for (i=0; i<m_readEvents.size(); i++) + for (it = m_readEvents.begin(); it != m_readEvents.end(); it++) { - ev = m_readEvents[0]; - m_readEvents.pop_front(); - delete ev; + delete *it; } - for (i=0; i<m_writeEvents.size(); i++) + for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++) { - ev = m_writeEvents[0]; - m_writeEvents.pop_front(); - delete ev; + delete *it; } - for (i=0; i<m_timeEvents.size(); i++) - { - ev = m_timeEvents[0]; - m_timeEvents.pop_front(); - delete ev; - } } -/** - * \brief Get a deferred that fires when given 'Fd' becomes readable - * - * \details The deferred returned by this method does not keep track - * of time. It fires only when Fd becomes readable. +/* + * Methods to register the given 'Selectable's */ -Deferred * -Reactor::OnReadable (int Fd) throw () +void +Reactor::addReader (Selectable *reader) { - if (Fd == -1) - { THROW (DevError, "bad fd = -1"); } - - return AddToReadEvents (Fd, 0L); + ASSERT ((reader != NULL), "bad reader"); + ASSERT ((reader->Fd() != -1), "bad fd = -1"); + addFdEvent (reader, "reader", m_readEvents); } -/** - * \brief Get a deferred that fires when given 'Fd' becomes readable - * - * \details The deferred returned by this method fires when given 'Fd' - * becomes readable or when given 'timeoutTime' elapses. - */ -Deferred * -Reactor::OnReadable (int Fd, h_msecs_t timeoutTime) throw () -{ - if (Fd == -1) - { THROW (DevError, "bad fd = -1"); } - if (timeoutTime == 0L) - { THROW (DevError, "timeoutTime = 0 will wait for ever"); } - return AddToReadEvents(Fd, timeoutTime); -} -/** - * \brief Get a deferred that fires when given 'Fd' becomes readable - * - * \details The deferred returned by this method does not keep track - * of time. It fires only when Fd becomes writable. - */ -Deferred * -Reactor::OnWritable (int Fd) throw () +void +Reactor::addWriter (Selectable *writer) { - if (Fd == -1) - { THROW (DevError, "bad fd = -1"); } - - return AddToWriteEvents (Fd, 0L); + ASSERT ((writer != NULL), "bad reader"); + ASSERT ((writer->Fd() != -1), "bad fd = -1"); + addFdEvent (writer, "writer", m_writeEvents); } -/** - * \brief Get a deferred that fires when given 'Fd' becomes readable - * - * \details The deferred returned by this method fires when given 'Fd' - * becomes writable or when given 'timeoutTime' elapses. - */ -Deferred * -Reactor::OnWritable (int Fd, h_msecs_t timeoutTime) throw () -{ - if (Fd == -1) - { THROW (DevError, "bad fd = -1"); } - if (timeoutTime == 0L) - { THROW (DevError, "timeoutTime = 0 will wait for ever"); } - return AddToWriteEvents (Fd, timeoutTime); -} - -/** - * \brief Add the given Fd to the on-readable-event monitoring list - * - * \param[in] Fd A valid file descriptor - * \param[in] timeoutTime Timeout in milliseconds - * - * \details This method adds the given file-descriptor to the list of - * file-descriptors being monitored for 'readability'. +/* + * Method to add a given fd to the given list. Used as a common + * convenience function for the addReader, addWriter methods. */ -Deferred * -Reactor::AddToReadEvents (int Fd, h_msecs_t timeoutTime) +void +Reactor::addFdEvent (Selectable *s, const char *type, + std::list<Reactor::Event *>& ev_list) { - size_t i; + Reactor::Event *ev; + std::list<Event *>::iterator it; /* lets make sure we dont have this file-descriptor in our lists already */ - for (i=0; i < m_readEvents.size(); i++) + for (it = ev_list.begin(); it != ev_list.end(); it++) { - if ((m_readEvents[i]->m_Fd == Fd) && (m_readEvents[i]->m_bDie == false)) + ev = *it; + if ((ev->Fd == s->Fd()) && (ev->bDie == false)) { - THROW (DevError, "fd=%u alreaded registered for On-Readable event", - Fd); + THROW (DevError, "fd=%u '%s' exists", ev->Fd, type); } } - Reactor::Event *ev; - try - { - ev = new Reactor::Event(); - } - catch (std::bad_alloc &e) - { - THROW (OutOfMemoryError, "allocating a read-'Event' object"); - } + /* create a new event and configure it */ + ev = new Reactor::Event (s); - ev->m_Fd = Fd; - ev->m_TimeoutTime = timeoutTime; - ev->m_LastTriggerTS = m_LastAwokenTS; - ev->m_NextTriggerTS = m_LastAwokenTS + timeoutTime; - - try - { - m_readEvents.push_back (ev); - LOG3 ("added Reactor::Event<%p> OnReadable: timeout=%lld msecs, fd=%d", - ev, timeoutTime, Fd); - } - catch (...) - { - delete ev; - THROW (OutOfMemoryError, "adding 'Event' to m_readEvents"); - } - - return &ev->m_Deferred; + /* add the event to our lists */ + ev_list.push_back (ev); + LOG3 ("added Reactor::Event<%p> '%s': fd=%d", ev, type, ev->Fd); } -/** - * \brief Add the given Fd to the on-writable-event monitoring list - * - * \param[in] Fd A valid file descriptor - * \param[in] timeoutTime Timeout in milliseconds - * - * \details This method adds the given file-descriptor to the list of - * file-descriptors being monitored for 'writability'. +/* + * Methods to remove events from readers, writers, and time-waiters + * lists. */ -Deferred * -Reactor::AddToWriteEvents (int Fd, h_msecs_t timeoutTime) +void +Reactor::removeReader (Selectable *reader) { - size_t i; - - /* lets make sure we dont have a similar event already registered */ - for (i=0; i < m_writeEvents.size(); i++) - { - if ((m_writeEvents[i]->m_Fd == Fd) && (m_writeEvents[i]->m_bDie == false)) - { - THROW (DevError, "fd=%u alreaded registered for On-Writable event", - Fd); - } - } - Reactor::Event *ev; - try + std::list<Event *>::iterator it; + for (it = m_readEvents.begin(); it != m_readEvents.end(); it++) { - ev = new Reactor::Event(); + ev = *it; + if (ev->Fd == reader->Fd()) { ev->bDie = true; return; } } - catch (std::bad_alloc &e) - { - THROW (OutOfMemoryError, "allocating a write-'Event' object"); - } - - ev->m_Fd = Fd; - ev->m_TimeoutTime = timeoutTime; - ev->m_LastTriggerTS = m_LastAwokenTS; - ev->m_NextTriggerTS = m_LastAwokenTS + timeoutTime; - - try - { - m_writeEvents.push_back (ev); -// LOG3 ("added Reactor::Event<%p> OnWritable: timeout=%lld msecs, fd=%d", -// ev, timeoutTime, Fd); - } - catch (...) - { - delete ev; - THROW (OutOfMemoryError, "adding 'Event' to m_writeEvents"); - } - - return &ev->m_Deferred; } - -/** - * \brief Creates a time-elapsed event - * - * \param[in] timeoutTime time-out time in milliseconds - * - * \details This method registers a time-elapsed event for the given - * 'timeoutTime'. - */ -Deferred * -Reactor::OnTimeElapsed (h_msecs_t timeoutTime) throw () -{ - Reactor::Event *ev; - - try - { - ev = new Reactor::Event(); - } - catch (std::bad_alloc &e) - { - THROW (OutOfMemoryError, "allocating an 'Event' object"); - } - - ev->m_TimeoutTime = timeoutTime; - ev->m_LastTriggerTS = m_LastAwokenTS; - ev->m_NextTriggerTS = m_LastAwokenTS + timeoutTime; - - try - { - m_timeEvents.push_back (ev); - LOG3 ("added Reactor::Event<%p> for OnTimeElapsed (%lld msecs)", - ev, timeoutTime); - } - catch (...) - { - delete ev; - THROW (OutOfMemoryError, "adding 'Event' to m_timeEvents"); - } - - return &ev->m_Deferred; -} - - -/** - * \brief Unregisters the event associated with the given deferred - * - * \param[in] deferred The Deferred that was provided at the time of - * registering for an event. - * - * \details This method looks up the event-lists for the event that is - * associated with the given deferred object, and marks it for - * removal. - */ -void -Reactor::UnRegister (Deferred *deferred) throw () -{ - size_t i; - for (i=0; i< m_readEvents.size(); i++) - { - if (&m_readEvents[i]->m_Deferred == deferred) - { - m_readEvents[i]->m_bDie = true; - return; - } - } - for (i=0; i< m_writeEvents.size(); i++) - { - if (&m_writeEvents[i]->m_Deferred == deferred) - { - m_writeEvents[i]->m_bDie = true; - return; - } - } - for (i=0; i< m_timeEvents.size(); i++) - { - if (&m_timeEvents[i]->m_Deferred == deferred) - { - m_timeEvents[i]->m_bDie = true; - return; - } - } -} - - -/** - * \brief Cleans up the inactive events - * - * \details This method looks through the event-lists for events that - * can be removed, and removes them permanently. - */ void -Reactor::CleanupEventLists (void) +Reactor::removeWriter (Selectable *writer) { - size_t i; Reactor::Event *ev; - - for (i=0; i< m_readEvents.size(); i++) + std::list<Event *>::iterator it; + for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++) { - if (m_readEvents[i]->m_bDie == true) - { - ev = m_readEvents[i]; - m_readEvents.erase(m_readEvents.begin()+i); - delete ev; - i--; - } + ev = *it; + if (ev->Fd == writer->Fd()) { ev->bDie = true; return; } } - for (i=0; i< m_writeEvents.size(); i++) - { - if (m_writeEvents[i]->m_bDie == true) - { - ev = m_writeEvents[i]; - m_writeEvents.erase(m_writeEvents.begin()+i); - delete ev; - i--; - } - } - for (i=0; i< m_timeEvents.size(); i++) - { - if (m_timeEvents[i]->m_bDie == true) - { - ev = m_timeEvents[i]; - m_timeEvents.erase(m_timeEvents.begin()+i); - delete ev; - i--; - } - } } -/** - * \brief Process time-events - * - * \details This method looks up the list of time-events for events - * that are ready to be triggered, and triggers them. +/* + * The main run-loop. Simply sits in a tight loop waiting for events. */ void -Reactor::ProcessTimeEvents (void) +Reactor::Run (void) { - size_t i; - Reactor::Event * ev; - h_msecs_t excessTime; - - for (i=0; i < m_timeEvents.size(); i++) + while (1) { - ev = m_timeEvents[i]; - if (m_LastAwokenTS >= ev->m_NextTriggerTS) - { - excessTime = m_LastAwokenTS - ev->m_NextTriggerTS; - ev->m_Deferred.NotifyTimeout (excessTime); - ev->m_LastTriggerTS = m_LastAwokenTS; - ev->m_NextTriggerTS = m_LastAwokenTS + ev->m_TimeoutTime; - } - } -} + /* wait for events */ + WaitForEvents (); + /* update the current timestamp */ + m_LastAwokenTS = GetCurrentTimeStamp(); -/** - * \brief Process the timeouts of FD events - * - * \details This method looks up the list of events for timeouts and - * fires them. - */ -void -Reactor::ProcessFDTimeouts (void) -{ - size_t i; - Reactor::Event * e; + /* process file-descriptor events if we have any */ + ProcessEvents (); - /* check for readable descriptors */ - for (i=0; i<m_readEvents.size(); i++) - { - e = m_readEvents[i]; - DoFDTimeoutNotification (e); - } - /* check for writable descriptors */ - for (i=0; i<m_writeEvents.size(); i++) - { - e = m_writeEvents[i]; - DoFDTimeoutNotification (e); - } -} + /* update the timer so that it can fire timeouts */ + /* TODO: update the timer here */ - -/** - * \brief The main run-loop - * - * \details This is the main run-loop of the reactor. This is a - * continuous while loop which waits for events and dispatches them. - */ -void -Reactor::Run (void) -{ - while (1) - { - WaitForEvents (); - m_LastAwokenTS = GetCurrentTimeStamp (); - if (m_PendingFDEvents > 0) - { - ProcessFDEvents (); - } - else - { - ProcessFDTimeouts (); - } - if (m_PendingFDEvents > 0) - { - LOG3 ("not all pending fd-events were processed. %d remaining", - m_PendingFDEvents); - } - ProcessTimeEvents (); + /* cleanup the event lists of dead 'Selectable's */ CleanupEventLists (); }; - ERR ("FATAL: broken out of Reactor::Run(). should not happen"); + ERR ("FATAL: broken out of Reactor::Run(). should not have happened"); } -/** - * \brief Helper to notify read/write events on a file-descriptor - * - * \param[in] e Pointer to the Reactor::Event whose deferred should be - * fired. - * - * \details This method fires the deferred for the given event. If the - * event-notification failes with a BadFDError exception, then this - * calls the OnError call-back, and unregisters the event from the - * reactor. +/* + * This method looks through the event-lists for events that can be + * removed, and removes them permanently. */ void -Reactor::DoFDEventNotification (Reactor::Event *ev) +Reactor::CleanupEventLists (void) { - try - { - ev->m_Deferred.NotifyEvent (); - } - catch (BadFDError& e) - { - /* We got a bad-file descriptor here */ - ev->m_Deferred.NotifyError (); - UnRegister (&ev->m_Deferred); - } - ev->m_LastTriggerTS = m_LastAwokenTS; - ev->m_NextTriggerTS = m_LastAwokenTS + ev->m_TimeoutTime; -// LOG3 ("EvNo:: updating timeout, fd=%u, ts=%llu, to_ts=%llu", -// ev->m_Fd, ev->m_LastTriggerTS, ev->m_NextTriggerTS); - m_PendingFDEvents --; + _CleanupEventList (m_readEvents); + _CleanupEventList (m_writeEvents); } - -/** - * \brief Helper to notify timeout events on a file-descriptor - * - * \param[in] e Pointer to the Reactor::Event whose deferred should be - * fired in case we hit a timeout. - * - * \details This method fires the 'timeout' method in the deferred for - * the given event. First checks to see if the timeout has elapsed. +/* + * Convenience function to clean up entries in the given event list */ void -Reactor::DoFDTimeoutNotification (Reactor::Event *ev) +Reactor::_CleanupEventList (std::list<Event *>& ev_list) { - h_msecs_t excessTime; + Reactor::Event *ev; + std::list<Event *>::iterator it; - if (ev->m_TimeoutTime != 0) - { - if (m_LastAwokenTS >= ev->m_NextTriggerTS) + it = ev_list.begin(); + while (it != ev_list.end()) + { + ev = *it; + if (ev->bDie == true) { - excessTime = m_LastAwokenTS - ev->m_NextTriggerTS; - ev->m_Deferred.NotifyTimeout (excessTime); - ev->m_LastTriggerTS = m_LastAwokenTS; - ev->m_NextTriggerTS = m_LastAwokenTS + ev->m_TimeoutTime; -// LOG3 ("ToNo:: updating timeout, fd=%u, ts=%llu, to_ts=%llu", -// ev->m_Fd, ev->m_LastTriggerTS, ev->m_NextTriggerTS); + it = ev_list.erase (it); + delete ev; } + else + { + it++; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:40:46
|
Revision: 39 http://asycxx.svn.sourceforge.net/asycxx/?rev=39&view=rev Author: joe_steeve Date: 2009-04-08 07:40:45 +0000 (Wed, 08 Apr 2009) Log Message: ----------- moved class:SelectReactor to 'asycxx' namespace * also added minor refactor to support changes in class:Reactor From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/SelectReactor.h trunk/src/SelectReactor.cxx Modified: trunk/include/asycxx/SelectReactor.h =================================================================== --- trunk/include/asycxx/SelectReactor.h 2009-04-08 07:39:49 UTC (rev 38) +++ trunk/include/asycxx/SelectReactor.h 2009-04-08 07:40:45 UTC (rev 39) @@ -19,30 +19,43 @@ #include <sys/select.h> +#include "Selectable.h" #include "Reactor.h" -class SelectReactor :public Reactor +namespace asycxx { + /** + * + */ + class SelectReactor :public Reactor + { + public: + SelectReactor (void); + virtual ~SelectReactor (void); -public: - SelectReactor (void); - ~SelectReactor (void); + protected: + /* Overridden methods */ + int WaitForEvents (void); + void ProcessEvents (void); -protected: - void WaitForEvents (void); - void ProcessFDEvents (void); + private: + /* counts maintained for 'select()' */ + int m_maxFd; + int m_FdCount; -private: - int m_maxFd; - int m_FdCount; - fd_set m_FdsForReading; - bool m_bReadingFdSetIsEmpty; - fd_set m_FdsForWriting; - bool m_bWritingFdSetIsEmpty; - - void BuildFdSets (void); -}; + /* fd-sets for 'select()' */ + fd_set m_FdsForReading; + fd_set m_FdsForWriting; + /* helper bools to track if a given fd-set is empty */ + bool m_bReadingFdSetIsEmpty; + bool m_bWritingFdSetIsEmpty; + + /* helper function to build the fd-sets */ + void BuildFdSets (void); + }; +} + #endif /* __HIPRO_ASYCXX__SELECT_REACTOR_H__ */ /* Modified: trunk/src/SelectReactor.cxx =================================================================== --- trunk/src/SelectReactor.cxx 2009-04-08 07:39:49 UTC (rev 38) +++ trunk/src/SelectReactor.cxx 2009-04-08 07:40:45 UTC (rev 39) @@ -23,10 +23,10 @@ #include <asycxx/Error.h> #include <asycxx/SelectReactor.h> +using namespace asycxx; -/** - * \brief ctor - * +/* + * CTOR */ SelectReactor::SelectReactor (void) { @@ -38,9 +38,8 @@ } -/** - * \brief dtor - * +/* + * DTOR */ SelectReactor::~SelectReactor (void) { @@ -48,16 +47,14 @@ } -/** - * \brief Wait for file-descriptor events till some time-out - * - * \details This method uses the select() system call to wait till - * some of the file-descriptors become readable/writable. This method - * blocks waiting for events for a maximum of TIME_SENSITIVITY +/* + * This method uses the select() system call to wait till some of the + * file-descriptors become readable/writable. This method blocks + * waiting for events for a maximum of TIME_SENSITIVITY * milli-seconds. This method updates the m_PendingEvents to show how * many file-descriptors need action on. */ -void +int SelectReactor::WaitForEvents (void) { int iret; @@ -71,11 +68,13 @@ else { rfds = &m_FdsForReading; } if (m_bWritingFdSetIsEmpty == true) { wfds = NULL; } else { wfds = &m_FdsForWriting; } + /* make sure we are waiting for something */ if ((m_bReadingFdSetIsEmpty == true) && (m_bWritingFdSetIsEmpty == true)) { LOG3 ("<%p>: Who are we waiting for??", this); } + /* wake-up time. we are not sleeping forever */ tv.tv_sec = 0L; tv.tv_usec = (TIME_SENSITIVITY * 1000); @@ -89,19 +88,20 @@ this, strerror (errno), m_FdCount); } } - /* update the pending file-descriptor events */ - m_PendingFDEvents = iret; + + /* return the pending file-descriptor events */ + return iret; } -/** - * \brief Builds file-descriptor sets for select () +/* + * Builds file-descriptor sets for select () */ void SelectReactor::BuildFdSets (void) { - size_t i; - Reactor::Event * e; + Reactor::Event * ev; + std::list<Event *>::iterator it; m_bReadingFdSetIsEmpty = true; m_bWritingFdSetIsEmpty = true; @@ -111,18 +111,18 @@ FD_ZERO (&m_FdsForReading); FD_ZERO (&m_FdsForWriting); - for (i=0; i<m_readEvents.size(); i++) + for (it = m_readEvents.begin(); it != m_readEvents.end(); it++) { - e = m_readEvents[i]; - FD_SET (e->m_Fd, &m_FdsForReading); - if (m_maxFd < e->m_Fd) { m_maxFd = e->m_Fd; } + ev = *it; + FD_SET (ev->Fd, &m_FdsForReading); + if (m_maxFd < ev->Fd) { m_maxFd = ev->Fd; } m_FdCount ++; } - for (i=0; i<m_writeEvents.size(); i++) + for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++) { - e = m_writeEvents[i]; - FD_SET (e->m_Fd, &m_FdsForWriting); - if (m_maxFd < e->m_Fd) { m_maxFd = e->m_Fd; } + ev = *it; + FD_SET (ev->Fd, &m_FdsForWriting); + if (m_maxFd < ev->Fd) { m_maxFd = ev->Fd; } m_FdCount ++; } m_maxFd++; @@ -132,47 +132,40 @@ } -/** - * \brief Process the pending file-descriptor events - * - * \details This method looks up the FDSETs setup by the select() - * system call and triggers the appropriate event. +/* + * This method looks up the FDSETs setup by the select() system call + * and triggers the appropriate events. */ void -SelectReactor::ProcessFDEvents (void) +SelectReactor::ProcessEvents (void) { - size_t i; - Reactor::Event * e; + Reactor::Event * ev; fd_set *read_fds, *write_fds; + std::list<Event *>::iterator it; read_fds = &m_FdsForReading; write_fds = &m_FdsForWriting; - /* check for readable descriptors */ - for (i=0; i<m_readEvents.size(); i++) + /* check the readers list for 'Readable's */ + for (it = m_readEvents.begin(); it != m_readEvents.end(); it++) { - e = m_readEvents[i]; - if (FD_ISSET (e->m_Fd, read_fds)) - { - DoFDEventNotification (e); + ev = *it; + if (FD_ISSET (ev->Fd, read_fds)) + { + /* Notify that the 'Selectable' is now readable */ + ev->pSelectable->Readable(); } - else - { - DoFDTimeoutNotification (e); - } } + /* check for writable descriptors */ - for (i=0; i<m_writeEvents.size(); i++) + for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++) { - e = m_writeEvents[i]; - if (FD_ISSET (e->m_Fd, write_fds)) + ev = *it; + if (FD_ISSET (ev->Fd, write_fds)) { - DoFDEventNotification (e); + /* Notify that the 'Selectable' is now writable */ + ev->pSelectable->Writable(); } - else - { - DoFDTimeoutNotification (e); - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:41:33
|
Revision: 40 http://asycxx.svn.sourceforge.net/asycxx/?rev=40&view=rev Author: joe_steeve Date: 2009-04-08 07:41:32 +0000 (Wed, 08 Apr 2009) Log Message: ----------- refactored RefCounter.* * moved class:RefCounter into 'asycxx' namespace * moved most of the one-liner code from RefCounter.cxx to RefCounter.h From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/RefCounter.h trunk/src/RefCounter.cxx Modified: trunk/include/asycxx/RefCounter.h =================================================================== --- trunk/include/asycxx/RefCounter.h 2009-04-08 07:40:45 UTC (rev 39) +++ trunk/include/asycxx/RefCounter.h 2009-04-08 07:41:32 UTC (rev 40) @@ -17,19 +17,36 @@ #include "Error.h" -class RefCounter +namespace asycxx { -public: - RefCounter (); + class RefCounter + { + public: + /* + * CTOR: + */ + RefCounter () { m_OwnerCount = 1; } - void Own (void); - void DisOwn (void); + void Own (void) { m_OwnerCount ++; } + void DisOwn (void) + { + m_OwnerCount --; + if (m_OwnerCount == 0) + { + delete this; + } + } -protected: - virtual ~RefCounter (); - int m__OwnerCount; -}; + protected: + /* DTOR: A reference counted object may not be deleted + * directly. Hence we have the 'dtor' as protected. + */ + virtual ~RefCounter (); + private: + int m_OwnerCount; + }; +} #endif /* __HIPRO_ASYCXX__REF_COUNTER_H__ */ /* Modified: trunk/src/RefCounter.cxx =================================================================== --- trunk/src/RefCounter.cxx 2009-04-08 07:40:45 UTC (rev 39) +++ trunk/src/RefCounter.cxx 2009-04-08 07:41:32 UTC (rev 40) @@ -16,50 +16,15 @@ #endif #include "asycxx-common.h" -#include <asycxx/Error.h> #include <asycxx/RefCounter.h> +using namespace asycxx; -/** - * \author Joe Steeve, jo...@hi... - * \class RefCounter - * \brief A simple reference counting mechanism - * - * \details This class provides functionality necessary for a simple - * reference-counting system. The creator of the object already owns - * the object. Hence the creator should explicitly calls - * RefCounter::DisOwn() to disown the object - */ - -RefCounter::RefCounter () -{ - m__OwnerCount = 1; -} - RefCounter::~RefCounter () { - if (m__OwnerCount != 0) - { - ERR ("FATAL: some-one still owns me"); - } + ASSERT ((m_OwnerCount == 0), "FATAL: some-one still owns me"); } -void -RefCounter::Own (void) -{ - m__OwnerCount ++; -} - -void -RefCounter::DisOwn (void) -{ - m__OwnerCount --; - if (m__OwnerCount == 0) - { - delete this; - } -} - /* Local Variables: mode: c++ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <joe...@us...> - 2009-04-08 07:42:24
|
Revision: 41 http://asycxx.svn.sourceforge.net/asycxx/?rev=41&view=rev Author: joe_steeve Date: 2009-04-08 07:42:19 +0000 (Wed, 08 Apr 2009) Log Message: ----------- refactored class:TCPLLTransport * changes to support changes in TCPTransport * moved class:TCPLLTransport to 'asycxx' namespace From: Joe Steeve <js...@hi...> Modified Paths: -------------- trunk/include/asycxx/TCPLLTransport.h trunk/src/TCPLLTransport.cxx Modified: trunk/include/asycxx/TCPLLTransport.h =================================================================== --- trunk/include/asycxx/TCPLLTransport.h 2009-04-08 07:41:32 UTC (rev 40) +++ trunk/include/asycxx/TCPLLTransport.h 2009-04-08 07:42:19 UTC (rev 41) @@ -18,17 +18,47 @@ #include "Reactor.h" #include "TCPTransport.h" -class TCPLLTransport : public TCPTransport +namespace asycxx { -public: - TCPLLTransport (Reactor *reactor, int fd); - virtual ~TCPLLTransport (); + class TCPLLTransport : public TCPTransport + { + public: + TCPLLTransport (Reactor *reactor, int fd); + virtual ~TCPLLTransport () {} + + /** + * \brief set the socket as TCP_NODELAY + * + * \details This method disables the Nagle algorithm on the connection + * by setting TCP_NODELAY. + */ + void configureTCPLLNoDelay (void); - void configureTCPLLNoDelay (void); - void configureTCPLLKeepAlive (int idle_time, int probe_count, - int probe_interval); -}; + /** + * \brief Configure the TCP keepalive mechanism + * + * \param[in] idle_time Idle time (time in which no data came + * across the wire) in seconds to wait for the keep-alive + * mechanism to kick in. + * \param[in] probe_count Number of keep-alive probes to send to + * the other end before deciding that the other-end is dead. + * \param[in] probe_interval The time in seconds between each + * keep-alive probe. + * + * \details This method configure's the TCP keepalive + * mechanism. This method is provided so that the user of this + * transport can tweak the keep-alive mechanism to see network + * errors faster. The maximum time taken before an error is + * noticed is + * + * idle_time + (probe_count * (probe_interval - 1)) + */ + void configureTCPLLKeepAlive (int idle_time, int probe_count, + int probe_interval); + }; +} + #endif /* __HIPRO_ASYCXX__TCP_LL_TRANSPORT_H__ */ /* Modified: trunk/src/TCPLLTransport.cxx =================================================================== --- trunk/src/TCPLLTransport.cxx 2009-04-08 07:41:32 UTC (rev 40) +++ trunk/src/TCPLLTransport.cxx 2009-04-08 07:42:19 UTC (rev 41) @@ -27,6 +27,7 @@ #include <asycxx/Protocol.h> #include <asycxx/TCPLLTransport.h> +using namespace asycxx; TCPLLTransport::TCPLLTransport (Reactor *reactor, int fd) : TCPTransport (reactor, fd) @@ -36,51 +37,19 @@ } -TCPLLTransport::~TCPLLTransport () -{ -} - -/** - * \brief set the socket as TCP_NODELAY - * - * \details This method disables the Nagle algorithm on the connection - * by setting TCP_NODELAY. - */ +/* setup tcp-no-delay */ void TCPLLTransport::configureTCPLLNoDelay (void) { - ASSERT ((m_Fd != -1), "sanity checks"); - int iret; int optval = 1; - iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_NODELAY, (void *)&optval, + iret = setsockopt (Fd(), IPPROTO_TCP, TCP_NODELAY, (void *)&optval, sizeof (optval)); - if (iret == -1) - { - THROW (RunTimeError, "setting up TCP_NODELAY on fd=%d failed with %s", - m_Fd, strerror (errno)); - } + ASSERT ((iret == 0), "setting up TCP_NODELAY on fd=%d failed with %s", + Fd(), strerror (errno)); } - -/** - * \brief Configure the TCP keepalive mechanism - * - * \param[in] idle_time Idle time (time in which no data came across - * the wire) in seconds to wait for the keep-alive mechanism to kick - * in. - * \param[in] probe_count Number of keep-alive probes to send to the - * other end before deciding that the other-end is dead. - * \param[in] probe_interval The time in seconds between each - * keep-alive probe. - * - * \details This method configure's the TCP keepalive mechanism. This - * method is provided so that the user of this transport can tweak the - * keep-alive mechanism to see network errors faster. The maximum time - * taken before an error is noticed is - * - * idle_time + (probe_count * (probe_interval - 1)) - */ +/* enable tcp-keep-alive */ void TCPLLTransport::configureTCPLLKeepAlive (int idle_time, int probe_count, int probe_interval) @@ -96,54 +65,30 @@ if (idle_time > 0) { optval = idle_time; - iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_KEEPIDLE, + iret = setsockopt (Fd(), IPPROTO_TCP, TCP_KEEPIDLE, (void *)&optval, sizeof (optval)); - if (iret == -1) - { - if (errno == EBADF) - { THROW (BadFDError, - "setting up TCP_KEEPIDLE(%d) on fd=%d threw '%s'", - idle_time, m_Fd, strerror (errno)); } - THROW (RunTimeError, - "setting up TCP_KEEPIDLE(%d) on fd=%d threw '%s'", - idle_time, m_Fd, strerror (errno)); - } + ASSERT ((iret == 0), "setting up TCP_KEEPIDLE(%d) on fd=%d threw '%s'", + idle_time, Fd(), strerror (errno)); } /* setup TCP_KEEPCNT */ if (probe_count > 0) { optval = probe_count; - iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_KEEPCNT, + iret = setsockopt (Fd(), IPPROTO_TCP, TCP_KEEPCNT, (void *)&optval, sizeof (optval)); - if (iret == -1) - { - if (errno == EBADF) - { THROW (BadFDError, - "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'", - probe_count, m_Fd, strerror (errno)); } - THROW (RunTimeError, - "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'", - probe_count, m_Fd, strerror (errno)); - } + ASSERT ((iret == 0), "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'", + probe_count, Fd(), strerror (errno)); } /* setup TCP_KEEPINTVL */ if (probe_interval > 0) { optval = probe_interval; - iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_KEEPCNT, + iret = setsockopt (Fd(), IPPROTO_TCP, TCP_KEEPCNT, (void *)&optval, sizeof (optval)); - if (iret == -1) - { - if (errno == EBADF) - { THROW (BadFDError, - "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'", - probe_interval, m_Fd, strerror (errno)); } - THROW (RunTimeError, - "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'", - probe_interval, m_Fd, strerror (errno)); - } + ASSERT ((iret == 0), "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'", + probe_interval, Fd(), strerror (errno)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |