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 | |
7 | This library is distributed in the hope that it will be useful, but WITHOUT |
8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
10 | more details. |
11 | |
12 | You should have received a copy of the GNU Lesser General Public License |
13 | along with this library; if not, write to the Free Software Foundation, Inc., |
14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
15 | **********/ |
16 | // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved. |
17 | // Basic Usage Environment: for a simple, non-scripted, console application |
18 | // C++ header |
19 | |
20 | #ifndef _BASIC_USAGE_ENVIRONMENT_HH |
21 | #define _BASIC_USAGE_ENVIRONMENT_HH |
22 | |
23 | #ifndef _BASIC_USAGE_ENVIRONMENT0_HH |
24 | #include "BasicUsageEnvironment0.hh" |
25 | #endif |
26 | |
27 | class BasicUsageEnvironment: public BasicUsageEnvironment0 { |
28 | public: |
29 | static BasicUsageEnvironment* createNew(TaskScheduler& taskScheduler); |
30 | |
31 | // redefined virtual functions: |
32 | virtual int getErrno() const; |
33 | |
34 | virtual UsageEnvironment& operator<<(char const* str); |
35 | virtual UsageEnvironment& operator<<(int i); |
36 | virtual UsageEnvironment& operator<<(unsigned u); |
37 | virtual UsageEnvironment& operator<<(double d); |
38 | virtual UsageEnvironment& operator<<(void* p); |
39 | |
40 | protected: |
41 | BasicUsageEnvironment(TaskScheduler& taskScheduler); |
42 | // called only by "createNew()" (or subclass constructors) |
43 | virtual ~BasicUsageEnvironment(); |
44 | }; |
45 | |
46 | |
47 | class BasicTaskScheduler: public BasicTaskScheduler0 { |
48 | public: |
49 | static BasicTaskScheduler* createNew(unsigned maxSchedulerGranularity = 10000/*microseconds*/); |
50 | // "maxSchedulerGranularity" (default value: 10 ms) specifies the maximum time that we wait (in "select()") before |
51 | // returning to the event loop to handle non-socket or non-timer-based events, such as 'triggered events'. |
52 | // 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. |
53 | // (You should set it to 0 only if you know that you will not be using 'event triggers'.) |
54 | virtual ~BasicTaskScheduler(); |
55 | |
56 | protected: |
57 | BasicTaskScheduler(unsigned maxSchedulerGranularity); |
58 | // called only by "createNew()" |
59 | |
60 | static void schedulerTickTask(void* clientData); |
61 | void schedulerTickTask(); |
62 | |
63 | protected: |
64 | // Redefined virtual functions: |
65 | virtual void SingleStep(unsigned maxDelayTime); |
66 | |
67 | virtual void setBackgroundHandling(int socketNum, int conditionSet, BackgroundHandlerProc* handlerProc, void* clientData); |
68 | virtual void moveSocketHandling(int oldSocketNum, int newSocketNum); |
69 | |
70 | protected: |
71 | unsigned fMaxSchedulerGranularity; |
72 | |
73 | // To implement background operations: |
74 | int fMaxNumSockets; |
75 | fd_set fReadSet; |
76 | fd_set fWriteSet; |
77 | fd_set fExceptionSet; |
78 | |
79 | private: |
80 | #if defined(__WIN32__) || defined(_WIN32) |
81 | // Hack to work around a bug in Windows' "select()" implementation: |
82 | int fDummySocketNum; |
83 | #endif |
84 | }; |
85 | |
86 | #endif |
87 | |