BasicUsageEnvironment0.hh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  15. // Basic Usage Environment: for a simple, non-scripted, console application
  16. // C++ header
  17. #ifndef _BASIC_USAGE_ENVIRONMENT0_HH
  18. #define _BASIC_USAGE_ENVIRONMENT0_HH
  19. #ifndef _BASICUSAGEENVIRONMENT_VERSION_HH
  20. #include "BasicUsageEnvironment_version.hh"
  21. #endif
  22. #ifndef _USAGE_ENVIRONMENT_HH
  23. #include "UsageEnvironment.hh"
  24. #endif
  25. #ifndef _DELAY_QUEUE_HH
  26. #include "DelayQueue.hh"
  27. #endif
  28. #define RESULT_MSG_BUFFER_MAX 1000
  29. // An abstract base class, useful for subclassing
  30. // (e.g., to redefine the implementation of "operator<<")
  31. class BasicUsageEnvironment0: public UsageEnvironment {
  32. public:
  33. // redefined virtual functions:
  34. virtual MsgString getResultMsg() const;
  35. virtual void setResultMsg(MsgString msg);
  36. virtual void setResultMsg(MsgString msg1,
  37. MsgString msg2);
  38. virtual void setResultMsg(MsgString msg1,
  39. MsgString msg2,
  40. MsgString msg3);
  41. virtual void setResultErrMsg(MsgString msg, int err = 0);
  42. virtual void appendToResultMsg(MsgString msg);
  43. virtual void reportBackgroundError();
  44. protected:
  45. BasicUsageEnvironment0(TaskScheduler& taskScheduler);
  46. virtual ~BasicUsageEnvironment0();
  47. private:
  48. void reset();
  49. char fResultMsgBuffer[RESULT_MSG_BUFFER_MAX];
  50. unsigned fCurBufferSize;
  51. unsigned fBufferMaxSize;
  52. };
  53. class HandlerSet; // forward
  54. #define MAX_NUM_EVENT_TRIGGERS 32
  55. // An abstract base class, useful for subclassing
  56. // (e.g., to redefine the implementation of socket event handling)
  57. class BasicTaskScheduler0: public TaskScheduler {
  58. public:
  59. virtual ~BasicTaskScheduler0();
  60. virtual void SingleStep(unsigned maxDelayTime = 0) = 0;
  61. // "maxDelayTime" is in microseconds. It allows a subclass to impose a limit
  62. // on how long "select()" can delay, in case it wants to also do polling.
  63. // 0 (the default value) means: There's no maximum; just look at the delay queue
  64. public:
  65. // Redefined virtual functions:
  66. virtual TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc* proc,
  67. void* clientData);
  68. virtual void unscheduleDelayedTask(TaskToken& prevTask);
  69. virtual void doEventLoop(char volatile* watchVariable);
  70. virtual EventTriggerId createEventTrigger(TaskFunc* eventHandlerProc);
  71. virtual void deleteEventTrigger(EventTriggerId eventTriggerId);
  72. virtual void triggerEvent(EventTriggerId eventTriggerId, void* clientData = NULL);
  73. protected:
  74. BasicTaskScheduler0();
  75. protected:
  76. // To implement delayed operations:
  77. DelayQueue fDelayQueue;
  78. // To implement background reads:
  79. HandlerSet* fHandlers;
  80. int fLastHandledSocketNum;
  81. // To implement event triggers:
  82. EventTriggerId volatile fTriggersAwaitingHandling; // implemented as a 32-bit bitmap
  83. EventTriggerId fLastUsedTriggerMask; // implemented as a 32-bit bitmap
  84. TaskFunc* fTriggeredEventHandlers[MAX_NUM_EVENT_TRIGGERS];
  85. void* fTriggeredEventClientDatas[MAX_NUM_EVENT_TRIGGERS];
  86. unsigned fLastUsedTriggerNum; // in the range [0,MAX_NUM_EVENT_TRIGGERS)
  87. };
  88. #endif