AAO DRAMA C++ Interface (Old style)
DRAMA C++, Depreciated, don't use for new code
dcpp.h
Go to the documentation of this file.
1/*
2 * Name: filter.m4
3 *
4 * Description:
5 * DOXYGEN Input file filter for DRAMA source files.
6 *
7 * This file must be complatible with both Solaris and GNU m4. All
8 * unused macros are deleted and this comment must end up as a C/C++
9 * compatible comment which is not picked up by DOXYGEN.
10 *
11 * Synopsis:
12 * DCF(func) => Produces a link to a DRAMA C source file func.html
13 * in ../routines.
14 * DDL(link,text) => Produce a link to ../link.html, specified link text.
15 *
16 * Language: m4 macro.
17 *
18 * Author: Tony Farrell, AAO.
19 *
20 * "@(#) $Id$"
21 *
22 * History:
23 * 10-Nov-2004 - TJF - Original Version.
24 */
25
26
27
28#ifndef DCPPINC
29#define DCPPINC
30/*
31 *
32 * Copyright (c) Anglo-Australian Telescope Board, 1995.
33 * Not to be used for commercial purposes without AATB permission.
34 *
35 * @(#) $Id$
36 *
37 */
38
39/*
40 *
41 * This file now uses DOXYGEN comments to generate the C++ web pages.
42 * m4 macros of the form @htmlonly <a href="../routines/function.html">function()</a>@endhtmlonly are used in the comments
43 * to refer to DRAMA C function documentation (see DramaHtml/Makefile,
44 * DramaHtml/doxygen.config and DramaHtml/filter.m4 for detials)
45 */
46
50#include "DitsTypes.h"
51#include "DitsInteraction.h"
52#include "DitsBulk.h"
53#include "sds.h"
54#include "arg.h"
55#include "dcpp_err.h"
56
57const unsigned DcppNodeNameLen = 100;
58const unsigned DcppArgumentLen = 200;
59typedef void * DcppVoidPnt;
61/*
62 * There are a few places where we set up SDS structures with variable
63 * lists of arguments, with the name format Argument%d. We support
64 * only 9999 such arguments - which requires a lenght of 13 characters
65 * for the Argument%d string - 8 for Argument, 4 for the number, 1 for null.
66 */
67const unsigned DcppMaxArgs = 9999;
68const unsigned DcppArgNameLen = 13;
69
79
92 (DcppVoidPnt ClientData, StatusType *status);
93
105typedef void (*DcppBulkTransRoutine)
106 (unsigned long Transferred,
107 unsigned long Total,
108 DcppVoidPnt ClientData, StatusType *status);
109
121DPUBLIC DcppHandlerRet DcppDispatch(StatusType *const status);
122
123/* Call to DcppDispatch which ignores the return,
124 * since in modern C++ casting DcppDispatch to DitsActionRoutineType
125 * gets warnings
126 */
127DPUBLIC void Dcpp___UfaceDispatch(StatusType *const status);
128
137inline void DcppUfaceCtxEnable(StatusType * const status) {
138 DitsUfaceCtxEnable(DitsActionRoutineType(Dcpp___UfaceDispatch),0,status);
139}
140
141
142/*
143 * Routines which provide wrappers around DitsSpawnKickArg and
144 * DitsSpawnKickArgUpdate.
145 */
176DPUBLIC void DcppSpawnKickArg(
177 DitsTransIdType transid,
178 SdsId * id,
179 StatusType *status);
180
216 DitsTransIdType transid,
217 const SdsId * id,
218 StatusType *status);
219
220
221DPUBLICCLASS DcppTask; /*Forward declaration */
222
248DPUBLIC DVOID DcppForgetAll(
249 DVOIDP client_data,
250 int taskExit,
251 StatusType exitStatus,
252 StatusType * const status);
253
269DPUBLIC void DcppVarArgsToSds(
270 int count,
271 Arg& ArgId,
272 StatusType * status,
273 va_list args);
274
275/*
276 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
277 */
287DPUBLICCLASS DcppBuffers {
288 private:
289 DitsPathInfoType bufInfo;
290 public:
302 DcppBuffers( long int MessageBytes = 800,
303 long int MaxMessages = 2,
304 long int ReplyBytes = 800,
305 long int MaxReplies = 2) {
306 bufInfo.MessageBytes = MessageBytes;
307 bufInfo.MaxMessages = MaxMessages;
308 bufInfo.ReplyBytes = ReplyBytes;
309 bufInfo.MaxReplies = MaxReplies;
310 };
317 DcppBuffers ( const DitsPathInfoType & i) : bufInfo(i) {};
320 operator const DitsPathInfoType * () const {
321 return &bufInfo; }
324 long int MessageBytes() const { return bufInfo.MessageBytes; };
327 long int MaxMessages() const { return bufInfo.MaxMessages; };
330 long int ReplyBytes() const { return bufInfo.ReplyBytes; };
333 long int MaxReplies() const { return bufInfo.MaxReplies; };
334};
335
336
337/*
338 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
339 * DcppTransaction - keeps track of transactions. A transaction structure
340 * is normally stored using DitsPutTransData and retrieved using
341 * DitsGetTransData. A check value is put in the data structure and is
342 * used to ensure the item fetched by DitsGetTransData is valid.
343 *
344 */
345const long int DcppCheckData = 0x0e0e0e0e;
352DPUBLICCLASS DcppTransaction {
353 private:
354 long int checkvalue; /* Check value, must be first */
355 DcppHandlerRoutine successHandler;
356 /* Called on completion without error */
357 DcppHandlerRoutine errorHandler;
358 /* Called on completion with error */
359 DcppHandlerRoutine triggerHandler;/* Called on trigger message */
360 DcppHandlerRoutine ersHandler;/* Called on Ers message */
361 DcppHandlerRoutine msgHandler;/* Called on MsgOut message */
362 DcppBulkTransRoutine bulkTransHandler; /* Called for bulk transfer */
363 DcppHandlerRoutine bulkDoneHandler; /* Called for bulk done */
364 DcppVoidPnt clientData; /* Passed to callback routines */
365 DcppTask *task; /* The task involved */
366 bool forgotten; /* deliberately orphaned */
367
368/*
369 * Prevent Assignment and copying of this type by redefining the
370 * assignment and copy operators to be private.
371 * This ensures we can't get multiple threads controlling the one
372 * task unless done intentionally by the caller.
373 *
374 * Also disallow the default constructor.
375 */
376 DcppTransaction& operator=(const DcppTransaction&);
379
380
381 public:
387 const DcppHandlerRoutine Success= 0,
388 const DcppHandlerRoutine Error = 0,
389 const DcppHandlerRoutine Trigger = 0,
390 const DcppHandlerRoutine Ers = 0,
391 const DcppHandlerRoutine Msg = 0,
392 const DcppVoidPnt ClientData = 0):
393 checkvalue(DcppCheckData), successHandler(Success),
394 errorHandler(Error), triggerHandler(Trigger),
395 ersHandler(Ers), msgHandler(Msg), bulkTransHandler(0),
396 bulkDoneHandler(0), clientData(ClientData), task(Task),
397 forgotten(false)
398 {
399 };
405 const DcppHandlerRoutine Success= 0,
406 const DcppHandlerRoutine Error = 0,
407 const DcppHandlerRoutine Trigger = 0,
408 const DcppHandlerRoutine Ers = 0,
409 const DcppHandlerRoutine Msg = 0,
410 const DcppBulkTransRoutine BulkTrans = 0,
411 const DcppHandlerRoutine BulkDone = 0,
412 const DcppVoidPnt ClientData = 0):
413 checkvalue(DcppCheckData), successHandler(Success),
414 errorHandler(Error), triggerHandler(Trigger),
415 ersHandler(Ers), msgHandler(Msg),
416 bulkTransHandler(BulkTrans), bulkDoneHandler(BulkDone),
417 clientData(ClientData), task(Task), forgotten(false)
418 {
419 };
424 int check () const { return checkvalue == DcppCheckData;};
425
426 /* Functions to fetch the various items */
431 DcppHandlerRoutine SuccessHandler() const { return successHandler; };
436 DcppHandlerRoutine TriggerHandler() const { return triggerHandler; };
441 DcppHandlerRoutine ErrorHandler() const { return errorHandler; };
446 DcppHandlerRoutine ErsHandler() const { return ersHandler; };
451 DcppHandlerRoutine MsgHandler() const { return msgHandler; };
457 return bulkTransHandler;}
462 DcppHandlerRoutine BulkDoneHandler() const { return bulkDoneHandler;}
467 DcppVoidPnt ClientData() const { return clientData; };
472 DcppTask * Task() const { return task; };
476 DcppHandlerRet HandleEvent(StatusType * const status);
481 bool Forgotten () const { return forgotten; };
486 void Forget() { forgotten = true; };
487};
488
489
490/*
491 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
492 * DcppShared
493 */
499DPUBLICCLASS DcppShared {
500
501 public:
513 Create = DITS_SHARE_CREATE,
519 Gblsec = DITS_SHARE_GBLSEC,
524 Global = DITS_SHARE_GLOBAL,
534 ShMem = DITS_SHARE_SHMEM,
540 MMap = DITS_SHARE_MMAP
545 };
546
547 private:
548 DitsSharedMemInfoType info;
549 bool valid;
550 void *address;
551 SdsId Structure;
552 bool free;
553/*
554 * Prevent Assignment and copying of this type by redefining the
555 * assignment and copy operators to be private.
556 * This ensures we can't get multiple threads controlling the one
557 * task unless done intentionally by the caller.
558 *
559 * Also disallow the default constructor.
560 */
561 DcppShared& operator=(const DcppShared&);
562 DcppShared(const DcppShared&);
563 DcppShared();
564
565
566 public:
583 long Size,
584 StatusType *const status,
585 const SharedType Type = Create,
586 const int CreateIt = true,
587 const char * const Name = "",
588 const int Key = 0,
589 void * const Address = 0
590 ) : valid(false), address(0), Structure(0), free(true) {
591
592 if (*status != STATUS__OK) return;
593
594 // If an address was supplied, copy it (only used for some times)
595 if (Address)
596 address = Address;
597
598 DitsDefineShared(Type, (char *)Name, Key, Size, CreateIt, &address,
599 &info, status);
600 if (*status == STATUS__OK)
601 valid = true;
602 }
628 const SdsId & Template,
629 StatusType *const status,
630 const SharedType Type = Create,
631 const int CreateIt = true,
632 const char * const Name = "",
633 const int Key = 0,
634 void * const Address = 0
635 ) : valid(false), address(0), Structure(0), free(true) {
636
637 if (*status != STATUS__OK) return;
638
639 // If an address was supplied, copy it (only used for some times)
640 if (Address)
641 address = Address;
642
643 // Create the segement
644 SdsIdType ID;
645 DitsDefineSdsShared(Template, Type, (char *)Name, Key, CreateIt,
646 &address, &info, &ID, status);
647 if (*status == STATUS__OK)
648 {
649 // Valid return. Remember and copy the SDS id
650 valid = true;
651 Structure.ShallowCopy(ID, true, false, false);
652 }
653 }
674 DcppShared(DitsSharedMemInfoType *Info, void *Address = 0,
675 SdsIdType ID = 0, bool Free = false)
676 : valid(true), address(Address), Structure(0), free(Free) {
677 info = *Info;
678 if (ID)
679 Structure.ShallowCopy(ID, Free, false, false);
680 }
681
690 void GetInfo(const DitsSharedMemInfoType * * const Info,
691 StatusType * const status) const {
692 if (*status != STATUS__OK) return;
693 if (!valid)
694 *status = DCPP__SHARENOVALID;
695 else
696 *Info = &info;
697 }
698
707 void GetInfo(DitsSharedMemInfoType * * const Info,
708 StatusType * const status) {
709 if (*status != STATUS__OK) return;
710 if (!valid)
711 *status = DCPP__SHARENOVALID;
712 else
713 *Info = &info;
714 }
715
723 /*
724 We are safe to not have a status
725 argument since SdsId will have been initialised to a null
726 id. Doing it without status makes it easier to use. const
727 and non-const versions
728 */
730 return Structure;
731 }
739 const SdsId & GetSds () const {
740 return Structure;
741 }
742
748 void GetAddress(const void **Address, StatusType *status) const {
749 if (*status != STATUS__OK) return;
750 if (!valid)
751 *status = DCPP__SHARENOVALID;
752 else if (!address)
753 *status = DCPP__SHARENOADD; /* If created from Info
754 constructor and address not
755 supplied
756 */
757 else
758 *Address = address;
759 }
765 void GetAddress(void **Address, StatusType *status) {
766 if (*status != STATUS__OK) return;
767 if (!valid)
768 *status = DCPP__SHARENOVALID;
769 else
770 *Address = address;
771 }
772
776 virtual ~DcppShared() {
777 StatusType status = STATUS__OK;
778 if (free)
779 DitsReleaseShared(&info, 1, &status);
780 valid = false; // Should not be necessary;
781 }
782
783};
784#endif
785
A C++ Interface to the SDS Arg library.
Definition arg.h:263
long int MessageBytes() const
Return the message bytes specification.
Definition dcpp.h:324
DcppBuffers(const DitsPathInfoType &i)
Construct a DcppBuffers object from a DitsPathInfoType variable.
Definition dcpp.h:317
DcppBuffers(long int MessageBytes=800, long int MaxMessages=2, long int ReplyBytes=800, long int MaxReplies=2)
Construct a DcppBuffers object from indivual specifications.
Definition dcpp.h:302
long int ReplyBytes() const
Return the reply bytes specification.
Definition dcpp.h:330
long int MaxReplies() const
Return the Max Replies specification.
Definition dcpp.h:333
long int MaxMessages() const
Return the Max Messages specification.
Definition dcpp.h:327
A structure representing message buffer sizes.
Definition dcpp.h:287
void GetInfo(DitsSharedMemInfoType **const Info, StatusType *const status)
Get share memory details - non-const version.
Definition dcpp.h:707
virtual ~DcppShared()
Destructor - free shared memory and SDS ID.
Definition dcpp.h:776
const SdsId & GetSds() const
Return Sds structure id - const version.
Definition dcpp.h:739
void GetAddress(void **Address, StatusType *status)
Return the shared memory address - non-const version.
Definition dcpp.h:765
DcppShared(long Size, StatusType *const status, const SharedType Type=Create, const int CreateIt=true, const char *const Name="", const int Key=0, void *const Address=0)
Basic Shared memory segment constructor.
Definition dcpp.h:582
DcppShared(DitsSharedMemInfoType *Info, void *Address=0, SdsIdType ID=0, bool Free=false)
Shared memory segment constructor - using existing segment.
Definition dcpp.h:674
SdsId & GetSds()
Return Sds structure id.
Definition dcpp.h:729
void GetInfo(const DitsSharedMemInfoType **const Info, StatusType *const status) const
Get share memory details - const version.
Definition dcpp.h:690
void GetAddress(const void **Address, StatusType *status) const
Return the shared memory address - const version.
Definition dcpp.h:748
SharedType
This enum gives the various shared memory types.
Definition dcpp.h:512
DcppShared(const SdsId &Template, StatusType *const status, const SharedType Type=Create, const int CreateIt=true, const char *const Name="", const int Key=0, void *const Address=0)
Shared memory segment constructor - for an SDS structure.
Definition dcpp.h:627
This is used to create and represent a shared memory segment.
Definition dcpp.h:499
A Class which provides access to DRAMA's message sending facilities.
Definition dcpptask.h:132
DcppTransaction(DcppTask *Task, const DcppHandlerRoutine Success=0, const DcppHandlerRoutine Error=0, const DcppHandlerRoutine Trigger=0, const DcppHandlerRoutine Ers=0, const DcppHandlerRoutine Msg=0, const DcppBulkTransRoutine BulkTrans=0, const DcppHandlerRoutine BulkDone=0, const DcppVoidPnt ClientData=0)
Constructor for bulk data transactions.
Definition dcpp.h:404
DcppHandlerRoutine TriggerHandler() const
Returns the trigger handler routine.
Definition dcpp.h:436
DcppHandlerRoutine SuccessHandler() const
Returns the success handler routine.
Definition dcpp.h:431
int check() const
Check indicates if the check value is correct
Definition dcpp.h:424
void Forget()
Forget the transaction.
Definition dcpp.h:486
DcppHandlerRet HandleEvent(StatusType *const status)
Handle the event.
DcppBulkTransRoutine BulkTransHandler() const
Return the bulk transfer message handler routine.
Definition dcpp.h:456
DcppVoidPnt ClientData() const
Return the client data item.
Definition dcpp.h:467
DcppHandlerRoutine ErsHandler() const
Return the Ers handler routine.
Definition dcpp.h:446
bool Forgotten() const
Indicate if the transaction was forgotten.
Definition dcpp.h:481
DcppHandlerRoutine BulkDoneHandler() const
Return the bulkd transfer done message handler routine.
Definition dcpp.h:462
DcppTask * Task() const
Return the associated DcppTask object.
Definition dcpp.h:472
DcppTransaction(DcppTask *Task, const DcppHandlerRoutine Success=0, const DcppHandlerRoutine Error=0, const DcppHandlerRoutine Trigger=0, const DcppHandlerRoutine Ers=0, const DcppHandlerRoutine Msg=0, const DcppVoidPnt ClientData=0)
Constructor for normal transactions.
Definition dcpp.h:386
DcppHandlerRoutine MsgHandler() const
Return the MsgOut handler routine.
Definition dcpp.h:451
DcppHandlerRoutine ErrorHandler() const
Returns the Error handler routine.
Definition dcpp.h:441
A type used to connect DcppHandler and DcppTask.
Definition dcpp.h:352
void ShallowCopy(SdsId &source, const bool outlives=true)
Shallow copy from SdsId.
Definition sds.h:1932
A C++ Interface to the handling SDS structures.
Definition sds.h:761
void DcppUfaceCtxEnable(StatusType *const status)
Enable handling of messages started in UFACE context.
Definition dcpp.h:137
void DcppForgetAll(void *client_data, int taskExit, StatusType exitStatus, StatusType *const status)
Forget all transaction assocaited with the current action.
void DcppVarArgsToSds(int count, Arg &ArgId, StatusType *status, va_list args)
Convert a variable argument list into an SDS structure.
void DcppSpawnKickArgUpdate(DitsTransIdType transid, const SdsId *id, StatusType *status)
Update an argument structure used when kick actions which spawn.
void * DcppVoidPnt
A pointer to void
Definition dcpp.h:59
void(* DcppBulkTransRoutine)(unsigned long Transferred, unsigned long Total, DcppVoidPnt ClientData, StatusType *status)
Type for call backs for DITS_REA_TRANSFERRED messages.
Definition dcpp.h:106
DcppHandlerRet DcppDispatch(StatusType *const status)
Basic message handler function.
const long int DcppCheckData
Internal use only.
Definition dcpp.h:345
DcppHandlerRet(* DcppHandlerRoutine)(DcppVoidPnt ClientData, StatusType *status)
Type for call backs when messages arrive.
Definition dcpp.h:92
DcppHandlerRet
Type returns by various routines to indicate what is to happen next.
Definition dcpp.h:75
@ DcppNotHandled
Only from DccpDisptach, message not handled.
Definition dcpp.h:76
@ DcppFinished
Have finished, action can complete
Definition dcpp.h:77
@ DcppReschedule
More messages expected, should reschedule.
Definition dcpp.h:75
void DcppSpawnKickArg(DitsTransIdType transid, SdsId *id, StatusType *status)
Create an argument structure used when kick actions which spawn.
DcppVoidPnt * DcppVoidPntPnt
A pointer to a pointer to void.
Definition dcpp.h:60
const unsigned DcppNodeNameLen
Maximum Node name length
Definition dcpp.h:57
const unsigned DcppArgumentLen
Maximum Node name length
Definition dcpp.h:58