[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] |