BasicUsageEnvironment/include/BasicUsageEnvironment0.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // Copyright (c) 1996-2013 Live Networks, Inc.  All rights reserved.
00017 // Basic Usage Environment: for a simple, non-scripted, console application
00018 // C++ header
00019 
00020 #ifndef _BASIC_USAGE_ENVIRONMENT0_HH
00021 #define _BASIC_USAGE_ENVIRONMENT0_HH
00022 
00023 #ifndef _BASICUSAGEENVIRONMENT_VERSION_HH
00024 #include "BasicUsageEnvironment_version.hh"
00025 #endif
00026 
00027 #ifndef _USAGE_ENVIRONMENT_HH
00028 #include "UsageEnvironment.hh"
00029 #endif
00030 
00031 #ifndef _DELAY_QUEUE_HH
00032 #include "DelayQueue.hh"
00033 #endif
00034 
00035 #define RESULT_MSG_BUFFER_MAX 1000
00036 
00037 // An abstract base class, useful for subclassing
00038 // (e.g., to redefine the implementation of "operator<<")
00039 class BasicUsageEnvironment0: public UsageEnvironment {
00040 public:
00041   // redefined virtual functions:
00042   virtual MsgString getResultMsg() const;
00043 
00044   virtual void setResultMsg(MsgString msg);
00045   virtual void setResultMsg(MsgString msg1,
00046                     MsgString msg2);
00047   virtual void setResultMsg(MsgString msg1,
00048                     MsgString msg2,
00049                     MsgString msg3);
00050   virtual void setResultErrMsg(MsgString msg, int err = 0);
00051 
00052   virtual void appendToResultMsg(MsgString msg);
00053 
00054   virtual void reportBackgroundError();
00055 
00056 protected:
00057   BasicUsageEnvironment0(TaskScheduler& taskScheduler);
00058   virtual ~BasicUsageEnvironment0();
00059 
00060 private:
00061   void reset();
00062 
00063   char fResultMsgBuffer[RESULT_MSG_BUFFER_MAX];
00064   unsigned fCurBufferSize;
00065   unsigned fBufferMaxSize;
00066 };
00067 
00068 class HandlerSet; // forward
00069 
00070 #define MAX_NUM_EVENT_TRIGGERS 32
00071 
00072 // An abstract base class, useful for subclassing
00073 // (e.g., to redefine the implementation of socket event handling)
00074 class BasicTaskScheduler0: public TaskScheduler {
00075 public:
00076   virtual ~BasicTaskScheduler0();
00077 
00078   virtual void SingleStep(unsigned maxDelayTime = 0) = 0;
00079       // "maxDelayTime" is in microseconds.  It allows a subclass to impose a limit
00080       // on how long "select()" can delay, in case it wants to also do polling.
00081       // 0 (the default value) means: There's no maximum; just look at the delay queue
00082 
00083 public:
00084   // Redefined virtual functions:
00085   virtual TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc* proc,
00086                                 void* clientData);
00087   virtual void unscheduleDelayedTask(TaskToken& prevTask);
00088 
00089   virtual void doEventLoop(char* watchVariable);
00090 
00091   virtual EventTriggerId createEventTrigger(TaskFunc* eventHandlerProc);
00092   virtual void deleteEventTrigger(EventTriggerId eventTriggerId);
00093   virtual void triggerEvent(EventTriggerId eventTriggerId, void* clientData = NULL);
00094 
00095 protected:
00096   BasicTaskScheduler0();
00097 
00098 protected:
00099   // To implement delayed operations:
00100   DelayQueue fDelayQueue;
00101 
00102   // To implement background reads:
00103   HandlerSet* fHandlers;
00104   int fLastHandledSocketNum;
00105 
00106   // To implement event triggers:
00107   EventTriggerId fTriggersAwaitingHandling, fLastUsedTriggerMask; // implemented as 32-bit bitmaps
00108   TaskFunc* fTriggeredEventHandlers[MAX_NUM_EVENT_TRIGGERS];
00109   void* fTriggeredEventClientDatas[MAX_NUM_EVENT_TRIGGERS];
00110   unsigned fLastUsedTriggerNum; // in the range [0,MAX_NUM_EVENT_TRIGGERS)
00111 };
00112 
00113 #endif

Generated on Mon Apr 29 13:28:00 2013 for live by  doxygen 1.5.2