DRAMA C++ Intro   Class Hierarchy   Alphabetical List of types   List of Classes   File List   Class Member Index   File Members Index   Related Pages  

dcpphandler.h

00001 /*
00002  * Name: filter.m4
00003  *
00004  * Description:
00005  *     DOXYGEN Input file filter for DRAMA source files.
00006  *
00007  *     This file must be complatible with both Solaris and GNU m4.  All
00008  *     unused macros are deleted and this comment must end up as a C/C++
00009  *     compatible comment which is not picked up by DOXYGEN.
00010  * 
00011  * Synopsis:
00012  *    DCF(func)  => Produces a link to a DRAMA C source file func.html 
00013  *                   in ../routines.
00014  *     DDL(link,text) => Produce a link to ../link.html, specified link text.
00015  *
00016  * Language: m4 macro. 
00017  *
00018  * Author: Tony Farrell, AAO.
00019  *
00020  * "@(#) $Id: ACMM:DramaHtml/filter.m4,v 3.24 03-Nov-2009 09:07:29+11 tjf $"
00021  *
00022  * History:
00023  *     10-Nov-2004 - TJF - Original Version.
00024  */
00025 
00026 
00027 
00028 #ifndef dcpphandler_h
00029 #define dcpphandler_h
00030 /*                            d c p p h a n d l e r
00031   
00032  * Module name:
00033       dcpphandler.h
00034   
00035  * Function:
00036         A class that completly hides the details of action reschedule.
00037   
00038  * Description:
00039         When a DcppHandler object is installed for the current action,
00040         it calls DitsPutObeyHandler supplying its own routine to handle
00041         future reschedules of the action.  The idea is that the various
00042         handlers will be invoked when events occur.  By returning
00043         DcppReschedule, they indicate that reschedule should occur,
00044         Otherwise they should return DcppFinished.        
00045   
00046         This file now uses DOXYGEN comments to generate the C++ web pages.
00047         m4 macros of the form @htmlonly <a href="../routines/function.html">function()</a>@endhtmlonly are used in the comments
00048         to refer to DRAMA C function documention (see DramaHtml/Makefile,
00049         DramaHtml/doxygen.config and DramaHtml/filter.m4 for detials)
00050 
00051  * Language:
00052       C++
00053   
00054  * Support: Tony Farrell, AAO
00055   
00056  * Copyright (c) Anglo-Australian Telescope Board, 1995.
00057    Not to be used for commercial purposes without AATB permission.
00058   
00059  *    @(#) $Id: ACMM:DramaDul/dcpphandler.h,v 3.43 17-Sep-2009 14:07:36+10 tjf $
00060   
00061  * History:
00062       12-Oct-1995 - TJF - Original version.  Taken from dcpp.h
00063       25-Sep-1996 - TJF - Extensively modified to support multiple
00064                                 threads.
00065       09-Dec-1997 - TJF - Declare class with DPUBLICCLASS to allow
00066                           export from WIN32 DLL.
00067       02-Feb-1998 - TJF - Declare ReschedHandler static function using
00068                           DSTATICMEM macro to support WIN32 DLL correctly.
00069       23-Nov-1998 - TJF - SetTimeout now does DitsPutDelay() to ensure
00070                           we can install and then to SetTimeout().  But
00071                           unsetting timeout does not work.
00072       17-Nov-1999 - TJF - Add NewThread method.  The increment operators
00073                           are now obsolete and will be removed.
00074       19-Nov-1999 - TJF - Add ability to set a timeout handler.
00075       12-Sep-2003 - TJF - Add new ThreadCount() function to help in debugging.
00076       17-Sep-2003 - TJF - Use Dits___Log for logging and log handler being
00077                           installed.
00078       26-Sep-2003 - TJF - GCC 3.x complains if printf style arguments for
00079                           the %p formater are not cast to void *.  Fixed.
00080       19-Jan-2004 - TJF - The external interface is now virtual and
00081                           all significant virtual functions are now moved
00082                           to dcpphandler.C.
00083       19-Aug-2004 - MVV - Added a member data that is a pointer to 
00084                           DcppCallbackBase type.
00085       18-Oct-2004 - TJF - Include DitsFix.h - it is needed by IsUface() to get
00086                             DitsGetContext().
00087       01-Dec-2004 - TJF - Improve Wait and WaitAll headers.
00088   
00089  */
00090 #include "dcpp.h"
00091 #include "DitsFix.h"
00092 #include "dcppcallbackbase.h"
00148 DPUBLICCLASS DcppHandler {
00149     private:
00150         DcppHandlerRoutine finishedHandler;     /* User supplied routine to invoke when messages complete*/
00151         DcppHandlerRoutine errorHandler;        /* User supplied routine to inovked on errors   */
00152         DcppHandlerRoutine timeoutHandler;      /* User supplied routine to inovked on timeout  */
00153         DcppVoidPnt oldActData;                 /* actData is saved here                        */
00154         DcppVoidPnt clientData;                 /* Client data item for handlers                */
00155         DitsDeltaTimeType delay;                /* Timeout between reschedules                  */
00156         bool timeoutEnabled;                    /* Is the timeout enabled                       */
00157         StatusType errorStat;                   /* Status of first error in current sequence    */
00158         int threadCount;                        /* Number of outstanding threads                */
00159         int initThreads;                        /* When reinitialising threads, use this value  */
00160         int errorCount;                         /* Number of threads which completed in error   */
00161         bool errorMode;                 /* If true errorHandler is invoked for each     */
00162                                                 /* thread on which an error occurs instead of   */
00163                                                 /* when all threads have completed              */
00164         bool *destroyedPtr;   /* IF non-null, then contains a pointer to
00165                                  a bool which should be set true by the
00166                                  destructor - allowing HandleReschedule()
00167                                  to work out if the handler was destroyed
00168                                  whilst it was run
00169                               */
00170 
00171         DcppCallbackBase* callbackObj;
00172 
00173         void ErrorHandler(StatusType * status); 
00174         void TimeoutHandler(StatusType * status); 
00175         void FinishedHandler(StatusType * status);
00176 
00182         bool IsUface() const
00183         { 
00184             return ((DitsGetContext() == DITS_CTX_UFACE) ? true : false);
00185         }
00186 
00187 /*
00188  *      Prevent Assignment and copying of this type by redefining the
00189  *      assignment and copy operators to be private.
00190  *      This ensures we can't get multiple threads controlling the one
00191  *      task unless done intentionally by the caller.
00192  *
00193  *      Disallow the default constructor.
00194  */
00195         DcppHandler& operator=(const DcppHandler&);
00196         DcppHandler(const DcppHandler&);
00197 
00198 
00199      public:
00227         DcppHandler(const DcppHandlerRoutine FinishedHandler = 0,
00228                     const DcppHandlerRoutine ErrorHandler = 0,
00229                     const DcppVoidPnt ClientData = 0, 
00230                     const float Timeout = -1);
00231 
00256         DcppHandler(DcppCallbackBase* CallbackObj,
00257                     const float Timeout = -1);
00258 
00259 
00273         virtual void Install(StatusType * const status, int threads = 1);
00274 
00283         virtual void DeInstall(StatusType * const status);
00284 
00294         virtual void SetFinished(const DcppHandlerRoutine FinishedHandler) {
00295                 finishedHandler = FinishedHandler;
00296         };
00297      
00350         void Wait(DitsTransIdType transId, StatusType* status, double timeout = 0);
00351 
00374         void WaitAll(StatusType* status, double timeout = 0);
00375 
00382         virtual void SetError   (const DcppHandlerRoutine ErrorHandler) {
00383                 errorHandler = ErrorHandler;
00384         };
00389         virtual void SetData    (const DcppVoidPnt ClientData) {
00390                 clientData = ClientData;
00391         };
00400         virtual void SetTimeout(const float Timeout);
00401 
00408         virtual void SetTimeout   (const DcppHandlerRoutine TimeoutHandler,
00409                            const float Timeout) {
00410                 SetTimeout(Timeout);
00411                 timeoutHandler = TimeoutHandler;
00412         };
00418         virtual void SetMultiCallErrorMode(int enable = true) {
00419             errorMode = enable;
00420         }
00423         virtual StatusType ErrorStatus() const { return errorStat; }
00424 
00428         virtual DcppVoidPnt GetData() const { return clientData; }
00429         
00432         virtual int ThreadCount() const { return threadCount; }
00437         void operator++() {     /* Preincrement operator */
00438             if (TheTask(debug) & DITS_LOG_LIBS)
00439                 Dits___Log("DcppHd::++[pre]",
00440                            "Thread count incremented for %p from %d to %d",
00441                            (void *)this, threadCount, threadCount+1);
00442             ++threadCount;
00443         }
00448         void operator++(int) { /* Post increment operator */
00449             if (TheTask(debug) & DITS_LOG_LIBS)
00450                 Dits___Log("DcppHd::++[post]",
00451                            "Thread count incremented for %p from %d to %d",
00452                            (void *)this, threadCount, threadCount+1);
00453             ++threadCount;
00454         }
00462         virtual void NewThread() {
00463             if (TheTask(debug) & DITS_LOG_LIBS)
00464                 Dits___Log("DcppHd::NewThread",
00465                            "Thread count incremented for %p from %d to %d",
00466                            (void *)this, threadCount, threadCount+1);
00467             
00468             ++threadCount;
00469         }
00470 
00473         virtual ~DcppHandler();
00474 
00478         void HandleReschedule(StatusType * status);
00479 
00483         void SetupTimeout(const float Timeout);
00484 
00485 };
00486 
00487  
00488 #endif
00489 

Click here for the DRAMA home page and here for the AAO home page.

For more information, contact tjf@aaoepp.aao.gov.au 

Generated on Tue Nov 3 09:09:56 2009 for AAO DRAMA C++ Interfaces by doxygen 1.2.18