1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 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
27class BasicUsageEnvironment: public BasicUsageEnvironment0 {
28public:
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
40protected:
41 BasicUsageEnvironment(TaskScheduler& taskScheduler);
42 // called only by "createNew()" (or subclass constructors)
43 virtual ~BasicUsageEnvironment();
44};
45
46
47class BasicTaskScheduler: public BasicTaskScheduler0 {
48public:
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
56protected:
57 BasicTaskScheduler(unsigned maxSchedulerGranularity);
58 // called only by "createNew()"
59
60 static void schedulerTickTask(void* clientData);
61 void schedulerTickTask();
62
63protected:
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
70protected:
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
79private:
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