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 GITTASKINC 00029 #define GITTASKINC 00030 00031 /* g i t t a s k 00032 00033 * Module name: 00034 gittask.h 00035 00036 * Function: 00037 Include file for the gittask.C module 00038 00039 * Description: 00040 gittask.C/gittask.h implement a C++ class derived from 00041 DcppTask. See gittask.C for details. 00042 00043 This file now uses DOXYGEN comments to generate the C++ web pages. 00044 m4 macros of the form @htmlonly <a href="../routines/function.html">function()</a>@endhtmlonly are used in the comments 00045 to refer to DRAMA C function documention (see DramaHtml/Makefile, 00046 DramaHtml/doxygen.config and DramaHtml/filter.m4 for detials) 00047 00048 * Language: 00049 C 00050 00051 * Support: Tony Farrell, AAO 00052 00053 * History: 00054 16-Dec-2003 - TJF - Original Version. 00055 16-Jan-2004 - TJF - Remove GitTask::isActive variable and 00056 revamp list stuff. Remove status argument from 00057 SetSimulation(), Support user override of version 00058 stuff, Get remove net start stuff working, 00059 09-Nov-2004 - TJF - In cases where some arguments were not used, put 00060 the name back in (e.g. "StatusType *") such that 00061 doxygen does not complain, and then use the 00062 argument such that the compiler does not complain. 00063 30-May-2006 - TJF - The self path constructor now takes an enum as 00064 the argument to ensure a char * is not converted 00065 to a bool triggering this constructor. 00066 00067 * @(#) $Id: ACMM:DramaGit/gittask.h,v 3.49 17-Sep-2009 14:08:15+10 tjf $ 00068 00069 */ 00070 00071 #include "dcpptask.h" 00072 #include "Git.h" 00073 #include "DitsMsgOut.h" 00074 00075 #include <string> 00076 00095 class GitResetType : public GitEnum { 00096 private: 00097 /* Enum possibilities */ 00098 enum resetEnum { Soft=0, Full, Hard, Recover, Invalid }; 00099 /* value contains the actual value, lookupTable the list of strings.*/ 00100 resetEnum value; 00101 static const char * const lookupTable[]; 00102 00103 /* Return lookup table address. Used by GitEnum::Get */ 00104 const char * const * Lookup() { 00105 return lookupTable; 00106 }; 00107 /* Set the value, Use by GitEnum::Get */ 00108 void SetValue(const unsigned int i) { 00109 if (i >= Invalid) 00110 value = Invalid; 00111 else 00112 value = (resetEnum)i; 00113 } 00114 /* Conversion operator - given enum, return an int */ 00115 operator int() const { 00116 return ((int)(value)); 00117 }; 00118 00119 public: 00136 GitResetType(const SdsId &Id, 00137 const char * const Name, 00138 int Position, 00139 StatusType * status, 00140 const int Flags=Git::Upper|Git::Abbrev|Git::KeepErr) { 00141 // Just get the value using GitEnum. 00142 GitEnum::Get(Id, Name, Position, status, "SOFT", Flags); 00143 } 00144 00148 GitResetType() { 00149 value = Soft; 00150 }; 00151 00152 void Get(const SdsId &Id, 00153 const char * const Name, 00154 int Position, 00155 StatusType * status, 00156 const int Flags=Git::Upper|Git::Abbrev|Git::KeepErr) { 00157 // Just get the value using GitEnum. 00158 GitEnum::Get(Id, Name, Position, status, "SOFT", Flags); 00159 } 00160 00163 void SetRecover() { 00164 value = Recover; 00165 }; 00168 void SetSoft() { 00169 value = Soft; 00170 } 00173 void SetHard() { 00174 value = Hard; 00175 } 00178 void SetFull() { 00179 value = Full; 00180 } 00183 bool IsSoft() const { return (value == Soft); }; 00186 bool IsFull() const { return (value == Full); }; 00189 bool IsHard() const { return (value == Hard); }; 00192 bool IsRecover() const { return (value == Recover); }; 00195 bool IsInvalid() const { return (value == Invalid); }; 00196 00199 operator const char*() const { 00200 return lookupTable[value]; 00201 }; 00202 00203 }; 00204 /* 00205 * Forward declaration - since we need this in GitTaskRepsonseHandler. 00206 */ 00207 class GitTask; 00208 00215 class GitTaskResponseHandler { 00216 public: 00219 GitTaskResponseHandler() {} 00220 00235 virtual DcppHandlerRet CompleteOk(GitTask *task,StatusType *status) { 00236 if (*status != STATUS__OK) return DcppFinished; 00237 task = 0; /* Shut up compiler */ 00238 return DcppFinished; 00239 } 00257 virtual DcppHandlerRet CompleteWithError(GitTask *task, 00258 StatusType *status) { 00259 if (*status == STATUS__OK) 00260 *status = DitsGetEntStatus(); 00261 task= 0; /* Shut up compliler */ 00262 return DcppFinished; 00263 } 00278 virtual DcppHandlerRet Triggered(GitTask *task, StatusType *status) { 00279 if (*status != STATUS__OK) return DcppFinished; 00280 task = 0; 00281 return DcppFinished; 00282 } 00283 00286 virtual ~GitTaskResponseHandler() {}; 00287 00288 }; 00289 00290 /* 00291 * This class is a helper class used by GitTask to help manage 00292 * the GitTaskResponseHandler class objects. 00293 */ 00294 class GitTask___ResponseManager { 00295 private: 00296 bool deleteHandler; /* Should the handler be deleted */ 00297 GitTaskResponseHandler *handler; /* Handler address */ 00298 GitTask *task; /* Task this is part of */ 00299 public: 00300 GitTask___ResponseManager(GitTask *t) : 00301 deleteHandler(false), handler(0), task(t) {} 00302 00303 /* 00304 * Set up a new handler routine. If responseHandler is null, then a new 00305 * handler is allocated. If freeRepsonse is true, then the handler 00306 * will be deleted after we have finished with it. Note that if 00307 * responseHandler is null, then freeResponse will also be set true. 00308 */ 00309 void SetNew(GitTaskResponseHandler *responseHandler, 00310 bool freeResponse, 00311 StatusType *status); 00312 00313 /* 00314 * Invoke the response handler's CompleteOk() method, delete the handler 00315 * if needed and return the result. 00316 */ 00317 DcppHandlerRet InvokeCompleteOK(StatusType *status); 00318 /* 00319 * Invoke the response handler's CompleteWithError() method, delete the handler 00320 * if needed and return the result. 00321 */ 00322 00323 DcppHandlerRet InvokeCompleteError(StatusType *status); 00324 00325 00326 /* 00327 * Invoke the handler's Trigger() method. 00328 */ 00329 DcppHandlerRet InvokeTriggered(StatusType *status); 00330 /* 00331 * Tidy up the handler 00332 */ 00333 void Tidy(); 00334 }; 00335 00336 00398 class GitTask : public DcppTask { 00399 friend class GitTaskActiveList; 00400 friend class GitTaskActiveListIterator; 00401 friend class GitTaskKnownList; 00402 friend class GitTaskKnownListIterator; 00403 00404 private: 00405 GitTask *nextKnown; /* For putting tasks in the list of */ 00406 /* known tasks */ 00407 /* Note, can only be put in one list*/ 00408 GitTask *nextActive; /* For putting tasks in a list of */ 00409 /* active tasks */ 00410 /* Note, can only be put in one list*/ 00411 00412 00413 GitTask___ResponseManager initialiseResponse; 00414 GitTask___ResponseManager exitResponse; 00415 GitTask___ResponseManager pollResponse; 00416 /* 00417 * Internal routines. 00418 * 00419 * static routines are normally used as callbacks. 00420 * 00421 * This bunch all used by Initialise. 00422 */ 00423 static DcppHandlerRet HandlePathSuccess( 00424 DcppVoidPnt ClientData, 00425 StatusType *status); 00426 static DcppHandlerRet HandlePathError( 00427 DcppVoidPnt ClientData, 00428 StatusType *status); 00429 static DcppHandlerRet HandleVerGetSuccess( 00430 DcppVoidPnt ClientData, 00431 StatusType *status); 00432 static DcppHandlerRet HandleVerGetError( 00433 DcppVoidPnt ClientData, 00434 StatusType *status); 00435 00436 static DcppHandlerRet HandleInitParGetSuccess( 00437 DcppVoidPnt ClientData, 00438 StatusType *status); 00439 static DcppHandlerRet HandleInitParGetError( 00440 DcppVoidPnt ClientData, 00441 StatusType *status); 00442 static DcppHandlerRet HandleInitParGetErs( 00443 DcppVoidPnt ClientData, 00444 StatusType *status); 00445 00446 00447 00448 /* 00449 * Exit handlers 00450 */ 00451 static DcppHandlerRet HandleExitSuccess( 00452 DcppVoidPnt ClientData, 00453 StatusType *status); 00454 static DcppHandlerRet HandleExitError( 00455 DcppVoidPnt ClientData, 00456 StatusType *status); 00457 00458 /* 00459 * Poll handlers 00460 */ 00461 static DcppHandlerRet HandlePollSuccess( 00462 DcppVoidPnt ClientData, 00463 StatusType *status); 00464 static DcppHandlerRet HandlePollError( 00465 DcppVoidPnt ClientData, 00466 StatusType *status); 00467 static DcppHandlerRet HandlePollTrigger( 00468 DcppVoidPnt ClientData, 00469 StatusType *status); 00470 static DcppHandlerRet HandlePollKickSuccess( 00471 DcppVoidPnt ClientData, 00472 StatusType *status); 00473 static DcppHandlerRet HandlePollKickError( 00474 DcppVoidPnt ClientData, 00475 StatusType *status); 00476 00482 virtual void DeActivate() { 00483 nextActive = 0; 00484 }; 00485 /* 00486 * Prevent Assignment and copying of this type by redefining the 00487 * assignment and copy operators to be private. 00488 * This ensures we can't get multiple threads controlling the one 00489 * task unless done intentionally by the caller. 00490 */ 00491 GitTask& operator=(const GitTask&); 00492 GitTask(const GitTask&); 00493 00494 00495 /* 00496 * The internal routines below and data associated with them are 00497 * available to inheriting classes. 00498 */ 00499 protected: 00500 00501 00502 static const int PollRetry = 5; 00504 /* 00505 * In a way, we probably should not have variables here, just routines, 00506 * but these things are commonly used by inheriters to re-implement 00507 * basic functions. 00508 */ 00509 int pollDont; 00510 bool pollCancelling; 00511 GitResetType resetMode; 00512 std::string simulationLevel; 00513 std::string simulationArg; 00514 float timeBase; 00516 bool havePath; 00517 bool failed; 00519 bool amExiting; 00521 bool resetting; 00522 bool firstTime; 00524 std::string verDate; 00525 std::string verNum; 00526 std::string taskDescr; 00547 virtual DcppHandlerRet SendSimulate(StatusType *status); 00548 00569 virtual DcppHandlerRet GetVersionInfo(StatusType *status); 00570 00594 virtual DcppHandlerRet GetInitialisedPar(StatusType *status); 00595 00596 00607 virtual DcppHandlerRet HandleVerComp(StatusType *status); 00608 00620 virtual DcppHandlerRet HandleInitParGetComp(bool initialised, 00621 StatusType *status); 00622 00642 virtual DcppHandlerRet SendInitialise(StatusType * status); 00643 00660 virtual DcppHandlerRet NoNetOnRemote(StatusType *status) { 00661 if (*status != STATUS__OK) return DcppFinished; 00662 return DcppFinished; 00663 } 00664 00665 00677 virtual void SetInfo(const Arg &info, StatusType *status); 00678 00687 virtual void SetInitial(StatusType *status) { 00688 if (*status != STATUS__OK) return; 00689 havePath = false; 00690 } 00697 virtual void SetPathWait(StatusType *status) { 00698 if (*status != STATUS__OK) return; 00699 } 00706 virtual void SetInitialising(StatusType *status) { 00707 if (*status != STATUS__OK) return; 00708 } 00715 virtual void SetResetting(StatusType *status){ 00716 if (*status != STATUS__OK) return; 00717 resetting = true; 00718 } 00725 virtual void SetIdle(StatusType *status) { 00726 if (*status != STATUS__OK) return; 00727 } 00734 virtual void SetExiting(StatusType *status) { 00735 if (*status != STATUS__OK) return; 00736 amExiting = true; 00737 } 00740 virtual void SetFailed() { 00741 failed = true; 00742 } 00745 virtual void SetDied() { 00746 failed = true; 00747 } 00748 00749 /* * * 00750 * Here we have methods which are not intended for overriding, unless 00751 * the underlying routine is also invoked. 00752 * 00753 * 00754 * These are invoked when the SIMULATE_LEVEL command 00755 * completes. 00756 */ 00769 static DcppHandlerRet HandleSimSuccess( 00770 DcppVoidPnt ClientData, 00771 StatusType *status); 00772 00785 static DcppHandlerRet HandleSimError( 00786 DcppVoidPnt ClientData, 00787 StatusType *status); 00788 /* 00789 * Invoked when INITIALISE/RESET completes. 00790 */ 00804 static DcppHandlerRet HandleInitSuccess( 00805 DcppVoidPnt ClientData, 00806 StatusType *status); 00807 00821 static DcppHandlerRet HandleInitError( 00822 DcppVoidPnt ClientData, 00823 StatusType *status); 00824 00825 00835 virtual DcppHandlerRet RemoteNetStarted(StatusType *status); 00845 virtual DcppHandlerRet RemoteNetStartErr(StatusType *status); 00846 00862 virtual bool RecoveryNeeded(); 00863 00864 public: 00870 enum SelfPathType { SelfPath }; 00886 GitTask(const std::string & name, 00887 const std::string &node = "", 00888 const std::string &file = ""); 00889 00903 GitTask(SelfPathType self) : 00904 DcppTask(true), 00905 nextKnown(0), 00906 nextActive(0), 00907 initialiseResponse(this), 00908 exitResponse(this), 00909 pollResponse(this), 00910 pollDont(0), 00911 pollCancelling(false), 00912 simulationLevel("NONE"), 00913 timeBase(1), 00914 havePath(false), 00915 failed(false), 00916 amExiting(false), 00917 resetting(false), 00918 firstTime(true) 00919 { 00920 resetMode.SetRecover(); 00921 StatusType ignore = STATUS__OK; 00922 SetInitial(&ignore); 00923 self = SelfPath; // Just to shut up noisey compilers 00924 }; 00925 00945 virtual void SetSimulation(const std::string &value, 00946 const float TimeBase, 00947 const std::string &string, 00948 StatusType *status); 00949 00950 00958 virtual void SetResetMode(GitResetType & mode, 00959 StatusType *status) { 00960 if (*status == STATUS__OK) 00961 resetMode = mode; 00962 } 00963 01004 virtual DcppHandlerRet Initialise( 01005 StatusType *status, 01006 GitTaskResponseHandler *responseHandler = 0, 01007 bool freeResponse = false); 01008 01009 01045 virtual DcppHandlerRet Poll( 01046 StatusType *status, 01047 GitTaskResponseHandler *responseHandler = 0, 01048 bool freeResponse = false); 01049 01050 01082 virtual DcppHandlerRet Exit( 01083 StatusType *status, 01084 GitTaskResponseHandler *responseHandler = 0, 01085 bool freeResponse = false); 01086 01087 01094 virtual void Report(StatusType * status); 01095 01098 virtual int IsActive() const { 01099 return (nextActive != 0); 01100 }; 01101 01104 virtual ~GitTask() { } 01105 01106 01107 }; 01108 01109 01110 01132 class GitTaskActiveList { 01133 friend class GitTaskActiveListIterator; 01134 private : 01135 GitTask *head; 01136 01137 static GitTask * const ListEnd; /* Indicate the end of the list */ 01138 01139 /* 01140 * Prevent Assignment and copying of this type by redefining the 01141 * assignment and copy operators to be private. 01142 */ 01143 GitTaskActiveList& operator=(const GitTaskActiveList&); 01144 GitTaskActiveList(const GitTaskActiveList&); 01145 01146 /* 01147 * Since we ony have one of these, the constructor is made 01148 * private and the object declared statically in the theList() function. 01149 */ 01150 GitTaskActiveList() { head = ListEnd; }; 01157 static GitTaskActiveList * theList(); 01158 public: 01159 01160 01165 static void ReInit(); 01166 01174 static void Insert(GitTask * t); 01175 01176 }; 01177 01198 class GitTaskKnownList { 01199 friend class GitTaskKnownListIterator; 01200 private : 01201 GitTask *head; 01202 01203 static GitTask * const ListEnd; /* Indicate the end of the list */ 01204 /* 01205 * Prevent Assignment and copying of this type by redefining the 01206 * assignment and copy operators to be private. 01207 */ 01208 GitTaskKnownList& operator=(const GitTaskKnownList&); 01209 GitTaskKnownList(const GitTaskKnownList&); 01210 01211 /* 01212 * Since we ony have one of these, the constructor is made 01213 * private and the object declared statically in the theList() function. 01214 */ 01215 GitTaskKnownList() : head(ListEnd) { }; 01222 static GitTaskKnownList * theList(); 01223 01224 01225 public: 01226 01235 static void Insert(GitTask * t); 01236 01237 }; 01238 01247 class GitTaskActiveListIterator { 01248 private: 01249 GitTask * ptr; 01250 GitTask * head; 01251 01252 public: 01255 GitTaskActiveListIterator() { 01256 head = ptr = GitTaskActiveList::theList()->head; }; 01257 01262 GitTask *operator()() { 01263 GitTask * p; 01264 p = (ptr != GitTaskActiveList::ListEnd)? ptr : 0; 01265 ptr = (ptr != GitTaskActiveList::ListEnd) ? ptr->nextActive : GitTaskActiveList::ListEnd; 01266 return (p); 01267 }; 01270 void reset() { 01271 ptr = head; 01272 }; 01273 }; 01283 class GitTaskKnownListIterator { 01284 private: 01285 GitTask * ptr; 01286 GitTask * head; 01287 01288 public: 01291 GitTaskKnownListIterator() { 01292 head = ptr = GitTaskKnownList::theList()->head; }; 01293 01294 01299 GitTask *operator()() { 01300 GitTask * p; 01301 p = (ptr != GitTaskKnownList::ListEnd)? ptr : 0; 01302 ptr = (ptr != GitTaskKnownList::ListEnd) ? ptr->nextKnown : GitTaskKnownList::ListEnd; 01303 return (p); 01304 }; 01307 void reset() { /* Reset iterator */ 01308 ptr = head; 01309 }; 01310 }; 01311 01312 01313 #endif 01314
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
1.2.18