live
BasicUsageEnvironment0.hh
Go to the documentation of this file.
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-2025 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_ENVIRONMENT0_HH
21#define _BASIC_USAGE_ENVIRONMENT0_HH
22
23#ifndef _BASICUSAGEENVIRONMENT_VERSION_HH
25#endif
26
27#ifndef _USAGE_ENVIRONMENT_HH
28#include "UsageEnvironment.hh"
29#endif
30
31#ifndef _DELAY_QUEUE_HH
32#include "DelayQueue.hh"
33#endif
34
35#define RESULT_MSG_BUFFER_MAX 1000
36
37// An abstract base class, useful for subclassing
38// (e.g., to redefine the implementation of "operator<<")
40public:
41 // redefined virtual functions:
42 virtual MsgString getResultMsg() const;
43
44 virtual void setResultMsg(MsgString msg);
45 virtual void setResultMsg(MsgString msg1,
46 MsgString msg2);
47 virtual void setResultMsg(MsgString msg1,
48 MsgString msg2,
49 MsgString msg3);
50 virtual void setResultErrMsg(MsgString msg, int err = 0);
51
52 virtual void appendToResultMsg(MsgString msg);
53
54 virtual void reportBackgroundError();
55
56protected:
59
60private:
61 void reset();
62
66};
67
68class HandlerSet; // forward
69
70// Note: You may redefine MAX_NUM_EVENT_TRIGGERS,
71// but it must be <= the number of bits in an "EventTriggerId"
72#ifndef MAX_NUM_EVENT_TRIGGERS
73#define MAX_NUM_EVENT_TRIGGERS 32
74#endif
75#define EVENT_TRIGGER_ID_HIGH_BIT (1 << (MAX_NUM_EVENT_TRIGGERS-1))
76
77// An abstract base class, useful for subclassing
78// (e.g., to redefine the implementation of socket event handling)
80public:
82
83 virtual void SingleStep(unsigned maxDelayTime = 0) = 0;
84 // "maxDelayTime" is in microseconds. It allows a subclass to impose a limit
85 // on how long "select()" can delay, in case it wants to also do polling.
86 // 0 (the default value) means: There's no maximum; just look at the delay queue
87
88public:
89 // Redefined virtual functions:
90 virtual TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc* proc,
91 void* clientData);
92 virtual void unscheduleDelayedTask(TaskToken& prevTask);
93
94 virtual void doEventLoop(EventLoopWatchVariable* watchVariable);
95
96 virtual EventTriggerId createEventTrigger(TaskFunc* eventHandlerProc);
97 virtual void deleteEventTrigger(EventTriggerId eventTriggerId);
98 virtual void triggerEvent(EventTriggerId eventTriggerId, void* clientData = NULL);
99
100protected:
102
103protected:
104 // To implement delayed operations:
107
108 // To implement background reads:
111
112 // To implement event triggers:
113#ifndef NO_STD_LIB
115#else
117#endif
118 u_int32_t fLastUsedTriggerMask; // implemented as a 32-bit bitmap
121 unsigned fLastUsedTriggerNum; // in the range [0,MAX_NUM_EVENT_TRIGGERS)
123};
124
125#endif
#define MAX_NUM_EVENT_TRIGGERS
#define RESULT_MSG_BUFFER_MAX
unsigned char Boolean
Definition: Boolean.hh:25
#define NULL
void TaskFunc(void *clientData)
u_int32_t EventTriggerId
std::atomic_char EventLoopWatchVariable
void * TaskToken
virtual EventTriggerId createEventTrigger(TaskFunc *eventHandlerProc)
void * fTriggeredEventClientDatas[MAX_NUM_EVENT_TRIGGERS]
virtual void unscheduleDelayedTask(TaskToken &prevTask)
virtual void SingleStep(unsigned maxDelayTime=0)=0
virtual void doEventLoop(EventLoopWatchVariable *watchVariable)
virtual void deleteEventTrigger(EventTriggerId eventTriggerId)
virtual void triggerEvent(EventTriggerId eventTriggerId, void *clientData=NULL)
virtual ~BasicTaskScheduler0()
TaskFunc * fTriggeredEventHandlers[MAX_NUM_EVENT_TRIGGERS]
std::atomic_flag fTriggersAwaitingHandling[MAX_NUM_EVENT_TRIGGERS]
virtual TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc *proc, void *clientData)
virtual void setResultMsg(MsgString msg)
virtual void setResultMsg(MsgString msg1, MsgString msg2, MsgString msg3)
char fResultMsgBuffer[RESULT_MSG_BUFFER_MAX]
BasicUsageEnvironment0(TaskScheduler &taskScheduler)
virtual MsgString getResultMsg() const
virtual void setResultErrMsg(MsgString msg, int err=0)
virtual ~BasicUsageEnvironment0()
virtual void appendToResultMsg(MsgString msg)
virtual void setResultMsg(MsgString msg1, MsgString msg2)
virtual void reportBackgroundError()
char const * MsgString
TaskScheduler & taskScheduler() const