BasicUsageEnvironment.hh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_ENVIRONMENT_HH
  18. #define _BASIC_USAGE_ENVIRONMENT_HH
  19. #ifndef _BASIC_USAGE_ENVIRONMENT0_HH
  20. #include "BasicUsageEnvironment0.hh"
  21. #endif
  22. class BasicUsageEnvironment: public BasicUsageEnvironment0 {
  23. public:
  24. static BasicUsageEnvironment* createNew(TaskScheduler& taskScheduler);
  25. // redefined virtual functions:
  26. virtual int getErrno() const;
  27. virtual UsageEnvironment& operator<<(char const* str);
  28. virtual UsageEnvironment& operator<<(int i);
  29. virtual UsageEnvironment& operator<<(unsigned u);
  30. virtual UsageEnvironment& operator<<(double d);
  31. virtual UsageEnvironment& operator<<(void* p);
  32. protected:
  33. BasicUsageEnvironment(TaskScheduler& taskScheduler);
  34. // called only by "createNew()" (or subclass constructors)
  35. virtual ~BasicUsageEnvironment();
  36. };
  37. class BasicTaskScheduler: public BasicTaskScheduler0 {
  38. public:
  39. static BasicTaskScheduler* createNew(unsigned maxSchedulerGranularity = 10000/*microseconds*/);
  40. // "maxSchedulerGranularity" (default value: 10 ms) specifies the maximum time that we wait (in "select()") before
  41. // returning to the event loop to handle non-socket or non-timer-based events, such as 'triggered events'.
  42. // You can change this is you wish (but only if you know what you're doing!), or set it to 0, to specify no such maximum time.
  43. // (You should set it to 0 only if you know that you will not be using 'event triggers'.)
  44. virtual ~BasicTaskScheduler();
  45. protected:
  46. BasicTaskScheduler(unsigned maxSchedulerGranularity);
  47. // called only by "createNew()"
  48. static void schedulerTickTask(void* clientData);
  49. void schedulerTickTask();
  50. protected:
  51. // Redefined virtual functions:
  52. virtual void SingleStep(unsigned maxDelayTime);
  53. virtual void setBackgroundHandling(int socketNum, int conditionSet, BackgroundHandlerProc* handlerProc, void* clientData);
  54. virtual void moveSocketHandling(int oldSocketNum, int newSocketNum);
  55. protected:
  56. unsigned fMaxSchedulerGranularity;
  57. // To implement background operations:
  58. int fMaxNumSockets;
  59. fd_set fReadSet;
  60. fd_set fWriteSet;
  61. fd_set fExceptionSet;
  62. private:
  63. #if defined(__WIN32__) || defined(_WIN32)
  64. // Hack to work around a bug in Windows' "select()" implementation:
  65. int fDummySocketNum;
  66. #endif
  67. };
  68. #endif