Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.6 KiB

  1. /*
  2. * REVISIONS:
  3. * xxxddMMMyy
  4. * sja09Dec92 - Poll method made public for Windows 3.1
  5. * pcy14Dec92 - ZERO changed to APCZERO
  6. * ajr08Mar93: added C_UNIX to single SINGLETHREADED
  7. * pcy21Apr93: OS2 FE merge
  8. * pcy14May93: Added Set(PTransactionGroup)
  9. * tje01Jun93: Moved SINGLETHREADED to cdefine.h
  10. * cad09Jul93: using new semaphores
  11. * cad03Sep93: made more methods virtual
  12. * cad08Sep93: Protected the event list
  13. * cad14Sep93: Cleaning up theState
  14. * cad17Nov93: publicized haslostcomm method
  15. * mwh18Nov93: changed EventID to INT
  16. * cad11Jan94: moved const/dest to .cxx
  17. * ajr16Feb94: Added default id to SubmitList.
  18. * ajr16Feb94: Added writeUpsOffFile() protected member function.
  19. * mwh05May94: #include file madness , part 2
  20. * srt24Oct96: Added an abort semaphore
  21. * tjg26Jan98: Added Stop method
  22. * tjg02Mar98: Removed Stop method (dead code)
  23. */
  24. #ifndef _INC__CDEVICE_H
  25. #define _INC__CDEVICE_H
  26. _CLASSDEF(CommDevice)
  27. _CLASSDEF(PollLoop)
  28. #include "apc.h"
  29. #include "update.h"
  30. #include "thrdable.h"
  31. #include "apcsemnt.h"
  32. extern "C" {
  33. #include <time.h>
  34. }
  35. _CLASSDEF(Message)
  36. _CLASSDEF(ProtectedList)
  37. _CLASSDEF(ListIterator)
  38. _CLASSDEF(TransactionGroup)
  39. _CLASSDEF(Controller)
  40. _CLASSDEF(Protocol)
  41. _CLASSDEF(Stream)
  42. _CLASSDEF(MutexLock)
  43. _CLASSDEF(Thread)
  44. _CLASSDEF(List)
  45. _CLASSDEF(CommDevice)
  46. // Values for theState
  47. //
  48. #define NORMAL_STATE 0
  49. #define RETRYING 2
  50. #define COMM_STOPPED 3
  51. #define PAUSE_POLLING 4
  52. #define FOURSECONDS 4000
  53. class CommDevice : public UpdateObj
  54. {
  55. public:
  56. CommDevice(PController control);
  57. virtual ~CommDevice();
  58. PController GetController(VOID) {return theController;};
  59. PProtocol GetProtocol(VOID) {return theProtocol;};
  60. PStream GetPort(VOID) {return thePort;};
  61. INT HasLostComm(VOID) {return theLostCommFlag;};
  62. virtual INT Equal(RObj item) const;
  63. virtual INT RegisterEvent(INT event, PUpdateObj object);
  64. virtual INT UnregisterEvent(INT event, PUpdateObj object);
  65. virtual INT Initialize(VOID);
  66. virtual INT Set(INT pid, const PCHAR value);
  67. virtual INT Set(PTransactionGroup agroup);
  68. virtual INT Get(INT pid, PCHAR value);
  69. virtual INT Get(PTransactionGroup agroup);
  70. virtual INT Update(PEvent anEvent);
  71. virtual INT IsA() const {return COMMDEVICE;};
  72. virtual VOID OkToPoll(VOID);
  73. virtual INT Poll(VOID);
  74. protected:
  75. PApcSemaphore theAbortSem;
  76. PProtectedList thePollList;
  77. PListIterator thePollIterator;
  78. PTransactionGroup theCurrentTransaction;
  79. time_t pollStartTime;
  80. INT theSleepingFlag;
  81. INT thePollIsDone;
  82. PProtectedList theEventList;
  83. PListIterator theEventIterator;
  84. INT theState;
  85. PController theController;
  86. PProtocol theProtocol;
  87. PStream thePort;
  88. PMutexLock theAskLock;
  89. LONG thePollInterval;
  90. INT theLostCommFlag;
  91. PThread thePollThread;
  92. virtual INT CreatePort() = 0;
  93. virtual INT CreateProtocol() = 0;
  94. INT SubmitList(PList msglist,INT id=-1);
  95. INT HandleEvents();
  96. INT Retry();
  97. virtual INT AskUps(PMessage msg) = 0;
  98. virtual VOID StartPollThread();
  99. VOID Access();
  100. VOID Release();
  101. friend class PollLoop;
  102. };
  103. class PollLoop : public Threadable
  104. {
  105. public:
  106. PollLoop (PCommDevice aDevice);
  107. virtual ~PollLoop ();
  108. virtual VOID ThreadMain(VOID);
  109. protected:
  110. PCommDevice theDevice;
  111. };
  112. #endif