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

dcpp.h

Go to the documentation of this file.
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 DCPPINC
00029 #define DCPPINC
00030 /*
00031  *
00032  *  Copyright (c) Anglo-Australian Telescope Board, 1995.
00033  *  Not to be used for commercial purposes without AATB permission.
00034  *
00035  *     @(#) $Id: ACMM:DramaDul/dcpp.h,v 3.43 17-Sep-2009 14:07:35+10 tjf $
00036  *
00037  */
00038 
00039 /*
00040  *
00041  * This file now uses DOXYGEN comments to generate the C++ web pages.
00042  * m4 macros of the form @htmlonly <a href="../routines/function.html">function()</a>@endhtmlonly are used in the comments
00043  * to refer to DRAMA C function documention (see DramaHtml/Makefile,
00044  * DramaHtml/doxygen.config and DramaHtml/filter.m4 for detials)
00045  */
00046 
00050 #include "DitsTypes.h"
00051 #include "DitsInteraction.h"
00052 #include "DitsBulk.h"
00053 #include "sds.h"
00054 #include "arg.h"
00055 #include "dcpp_err.h"
00056 
00057 const unsigned DcppNodeNameLen = 100;   
00058 const unsigned DcppArgumentLen = 200;   
00059 typedef  void * DcppVoidPnt;    
00060 typedef  DcppVoidPnt * DcppVoidPntPnt;
00061 /*
00062  * There are a few places where we set up SDS structures with variable
00063  * lists of arguments, with the name format Argument%d.  We support
00064  * only 9999 such arguments - which requires a lenght of 13 characters
00065  * for the Argument%d string - 8 for Argument, 4 for the number, 1 for null.
00066  */
00067 const unsigned DcppMaxArgs = 9999;
00068 const unsigned DcppArgNameLen = 13; 
00069 
00075 typedef enum { DcppReschedule,
00076                DcppNotHandled,
00077                DcppFinished   
00078                 } DcppHandlerRet;
00079 
00091 typedef DcppHandlerRet (*DcppHandlerRoutine)
00092                         (DcppVoidPnt ClientData, StatusType *status);
00093 
00105 typedef void (*DcppBulkTransRoutine)
00106                         (unsigned long Transferred,
00107                          unsigned long Total,
00108                          DcppVoidPnt ClientData, StatusType *status);
00109 
00121 DPUBLIC DcppHandlerRet DcppDispatch(StatusType *const status);
00122 
00131 inline void DcppUfaceCtxEnable(StatusType * const status) {
00132     DitsUfaceCtxEnable(DitsActionRoutineType(DcppDispatch),0,status);
00133 }
00134 
00135 
00136 /*
00137  *  Routines which provide wrappers around DitsSpawnKickArg and
00138  *  DitsSpawnKickArgUpdate.
00139  */
00170 DPUBLIC void DcppSpawnKickArg(
00171     DitsTransIdType transid,
00172     SdsId * id,
00173     StatusType *status);
00174 
00209 DPUBLIC void DcppSpawnKickArgUpdate(
00210     DitsTransIdType transid,
00211     const SdsId * id,
00212     StatusType *status);
00213 
00214 
00215 DPUBLICCLASS DcppTask;  /*Forward declaration */
00216 
00242 DPUBLIC DVOID DcppForgetAll(
00243     DVOIDP client_data,
00244     int taskExit,
00245     StatusType exitStatus,
00246     StatusType * const status);
00247 
00263 DPUBLIC void DcppVarArgsToSds(
00264     int count, 
00265     Arg& ArgId,
00266     StatusType * status, 
00267     va_list args);
00268 
00269 /*
00270  * * *  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00271  */
00281 DPUBLICCLASS DcppBuffers {
00282     private:
00283         DitsPathInfoType bufInfo;
00284     public:
00296         DcppBuffers( long int MessageBytes = 800,
00297                      long int MaxMessages = 2,
00298                      long int ReplyBytes = 800,
00299                      long int MaxReplies = 2) {
00300                 bufInfo.MessageBytes = MessageBytes;
00301                 bufInfo.MaxMessages  = MaxMessages;
00302                 bufInfo.ReplyBytes   = ReplyBytes;
00303                 bufInfo.MaxReplies   = MaxReplies; 
00304         };
00311         DcppBuffers ( const DitsPathInfoType & i) : bufInfo(i) {};
00314         operator const DitsPathInfoType * () const { 
00315                 return &bufInfo; }
00318         long int MessageBytes() const { return bufInfo.MessageBytes; };
00321         long int MaxMessages()  const { return bufInfo.MaxMessages;  };
00324         long int ReplyBytes()   const { return bufInfo.ReplyBytes;   };
00327         long int MaxReplies()   const { return bufInfo.MaxReplies;   }; 
00328 };
00329 
00330 
00331 /*
00332  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00333  *  DcppTransaction - keeps track of transactions.  A transaction structure
00334  *  is normally stored using DitsPutTransData and retrieved using 
00335  *  DitsGetTransData.  A check value is put in the data structure and is 
00336  *  used to ensure the item fetched by DitsGetTransData is valid.
00337  *      
00338  */
00339 const long int DcppCheckData = 0x0e0e0e0e; 
00346 DPUBLICCLASS DcppTransaction {
00347     private:
00348         long int checkvalue;               /* Check value, must be first */
00349         DcppHandlerRoutine successHandler;
00350                                 /* Called on completion without error */
00351         DcppHandlerRoutine errorHandler;  
00352                                 /* Called on completion with error */
00353         DcppHandlerRoutine triggerHandler;/* Called on trigger message */
00354         DcppHandlerRoutine ersHandler;/* Called on Ers message */
00355         DcppHandlerRoutine msgHandler;/* Called on MsgOut message */
00356         DcppBulkTransRoutine bulkTransHandler; /* Called for bulk transfer */
00357         DcppHandlerRoutine bulkDoneHandler; /* Called for bulk done */
00358         DcppVoidPnt clientData; /* Passed to callback routines  */
00359         DcppTask *task;         /* The task involved            */
00360         bool    forgotten;      /* deliberately orphaned        */
00361 
00362 /*
00363  *      Prevent Assignment and copying of this type by redefining the
00364  *      assignment and copy operators to be private.
00365  *      This ensures we can't get multiple threads controlling the one
00366  *      task unless done intentionally by the caller.
00367  *
00368  *      Also disallow the default constructor.
00369  */
00370         DcppTransaction& operator=(const DcppTransaction&);
00371         DcppTransaction(const DcppTransaction&);
00372         DcppTransaction();
00373 
00374 
00375     public:
00380         DcppTransaction(DcppTask *Task, 
00381                         const DcppHandlerRoutine Success= 0, 
00382                         const DcppHandlerRoutine Error = 0,
00383                         const DcppHandlerRoutine Trigger = 0,
00384                         const DcppHandlerRoutine Ers = 0,
00385                         const DcppHandlerRoutine Msg = 0,
00386                         const DcppVoidPnt ClientData = 0):
00387             checkvalue(DcppCheckData), successHandler(Success),
00388             errorHandler(Error), triggerHandler(Trigger),
00389             ersHandler(Ers), msgHandler(Msg), bulkTransHandler(0),
00390             bulkDoneHandler(0), clientData(ClientData), task(Task),
00391             forgotten(false)
00392         {
00393         };
00398         DcppTransaction(DcppTask *Task, 
00399                         const DcppHandlerRoutine Success= 0, 
00400                         const DcppHandlerRoutine Error = 0,
00401                         const DcppHandlerRoutine Trigger = 0,
00402                         const DcppHandlerRoutine Ers = 0,
00403                         const DcppHandlerRoutine Msg = 0,
00404                         const DcppBulkTransRoutine BulkTrans = 0,
00405                         const DcppHandlerRoutine BulkDone = 0,
00406                         const DcppVoidPnt ClientData = 0):
00407             checkvalue(DcppCheckData), successHandler(Success),
00408             errorHandler(Error), triggerHandler(Trigger),
00409             ersHandler(Ers), msgHandler(Msg),  
00410             bulkTransHandler(BulkTrans), bulkDoneHandler(BulkDone), 
00411             clientData(ClientData), task(Task), forgotten(false)
00412         {
00413         };
00418         int check () const { return checkvalue == DcppCheckData;};
00419 
00420         /* Functions to fetch the various items         */
00425         DcppHandlerRoutine SuccessHandler() const { return successHandler; };
00430         DcppHandlerRoutine TriggerHandler() const { return triggerHandler; };
00435         DcppHandlerRoutine ErrorHandler() const { return errorHandler; };
00440         DcppHandlerRoutine ErsHandler() const { return ersHandler; };
00445         DcppHandlerRoutine MsgHandler() const { return msgHandler; };
00450         DcppBulkTransRoutine BulkTransHandler() const { 
00451             return bulkTransHandler;}
00456         DcppHandlerRoutine BulkDoneHandler() const { return bulkDoneHandler;}
00461         DcppVoidPnt        ClientData() const { return clientData; };
00466         DcppTask *         Task() const { return task; };
00470         DcppHandlerRet     HandleEvent(StatusType * const status);
00475         bool Forgotten () const  { return forgotten; };
00480         void Forget() { forgotten = true; };
00481 };
00482 
00483 
00484 /*
00485  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00486  * DcppShared
00487  */
00493 DPUBLICCLASS DcppShared {
00494 
00495     public:
00506         enum SharedType { 
00507                Create  = DITS_SHARE_CREATE, 
00513                Gblsec  = DITS_SHARE_GBLSEC, 
00518                Global  = DITS_SHARE_GLOBAL, 
00528                ShMem   = DITS_SHARE_SHMEM, 
00534                MMap    = DITS_SHARE_MMAP   
00539                };
00540 
00541     private:
00542         DitsSharedMemInfoType info;
00543         bool valid;
00544         void *address;
00545         SdsId Structure;
00546         bool free;
00547 /*
00548  *      Prevent Assignment and copying of this type by redefining the
00549  *      assignment and copy operators to be private.
00550  *      This ensures we can't get multiple threads controlling the one
00551  *      task unless done intentionally by the caller.
00552  *
00553  *      Also disallow the default constructor.
00554  */
00555         DcppShared& operator=(const DcppShared&);
00556         DcppShared(const DcppShared&);
00557         DcppShared();
00558 
00559 
00560     public:
00576         DcppShared(
00577             long Size,
00578             StatusType *const status,
00579             const SharedType Type = Create,
00580             const int CreateIt = true,
00581             const char * const Name = "",
00582             const int Key = 0,
00583             void * const Address = 0
00584             ) : valid(false), address(0), Structure(0), free(true) {
00585 
00586             if (*status != STATUS__OK) return;
00587 
00588             // If an address was supplied, copy it (only used for some times)
00589             if (Address)
00590                 address = Address;
00591 
00592             DitsDefineShared(Type, (char *)Name, Key, Size, CreateIt, &address,
00593                              &info, status);
00594             if (*status == STATUS__OK)
00595                 valid = true;
00596         }
00621         DcppShared(
00622             const SdsId & Template,
00623             StatusType *const status,
00624             const SharedType Type = Create,
00625             const int CreateIt = true,
00626             const char * const Name = "",
00627             const int Key = 0,
00628             void * const Address = 0
00629             ) : valid(false), address(0), Structure(0), free(true) {
00630 
00631             if (*status != STATUS__OK) return;
00632 
00633             // If an address was supplied, copy it (only used for some times)
00634             if (Address)
00635                 address = Address;
00636 
00637             // Create the segement 
00638             SdsIdType ID;
00639             DitsDefineSdsShared(Template, Type, (char *)Name, Key, CreateIt, 
00640                                 &address, &info, &ID, status);
00641             if (*status == STATUS__OK)
00642             {
00643                 // Valid return.  Remember and copy the SDS id
00644                 valid = true;
00645                 Structure.ShallowCopy(ID, true, false, false);
00646             }
00647         }
00668         DcppShared(DitsSharedMemInfoType *Info, void *Address = 0, 
00669                    SdsIdType ID = 0, bool Free = false) 
00670              :  valid(true), address(Address), Structure(0), free(Free) {
00671             info = *Info;
00672             if (ID)
00673                 Structure.ShallowCopy(ID, Free, false, false);
00674         }
00675 
00684         void GetInfo(const DitsSharedMemInfoType * * const Info, 
00685                      StatusType * const status) const {
00686             if (*status != STATUS__OK) return;
00687             if (!valid)
00688                 *status = DCPP__SHARENOVALID;
00689             else
00690                 *Info = &info;
00691         }
00692 
00701         void GetInfo(DitsSharedMemInfoType * * const Info, 
00702                      StatusType * const status) {
00703             if (*status != STATUS__OK) return;
00704             if (!valid)
00705                 *status = DCPP__SHARENOVALID;
00706             else
00707                 *Info = &info;
00708         }
00709 
00717          /*
00718            We are safe to not have a status
00719            argument since SdsId will have been initialised to a null
00720            id.  Doing it without status makes it easier to use.  const
00721            and non-const versions
00722          */
00723         SdsId & GetSds () {
00724             return Structure;
00725         }
00733         const SdsId & GetSds () const {
00734             return Structure;
00735         }
00736 
00742         void GetAddress(const void **Address, StatusType *status) const {
00743             if (*status != STATUS__OK) return;
00744             if (!valid)
00745                 *status = DCPP__SHARENOVALID;
00746             else if (!address)
00747                 *status = DCPP__SHARENOADD; /* If created from Info 
00748                                                constructor and address not
00749                                                supplied
00750                                                */
00751             else
00752                 *Address = address;
00753         }
00759         void GetAddress(void **Address, StatusType *status) {
00760             if (*status != STATUS__OK) return;
00761             if (!valid)
00762                 *status = DCPP__SHARENOVALID;
00763             else
00764                 *Address = address;
00765         }
00766 
00770         virtual ~DcppShared() {
00771             StatusType status = STATUS__OK;
00772             if (free)
00773                 DitsReleaseShared(&info, 1, &status);
00774             valid = false; // Should not be necessary;
00775         }
00776         
00777 };                                      
00778 #endif
00779 
00780 

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