UsageEnvironment/include/UsageEnvironment.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 // Usage Environment
00018 // C++ header
00019 
00020 #ifndef _USAGE_ENVIRONMENT_HH
00021 #define _USAGE_ENVIRONMENT_HH
00022 
00023 #ifndef _USAGEENVIRONMENT_VERSION_HH
00024 #include "UsageEnvironment_version.hh"
00025 #endif
00026 
00027 #ifndef _NETCOMMON_H
00028 #include "NetCommon.h"
00029 #endif
00030 
00031 #ifndef _BOOLEAN_HH
00032 #include "Boolean.hh"
00033 #endif
00034 
00035 #ifndef _STRDUP_HH
00036 // "strDup()" is used often, so include this here, so everyone gets it:
00037 #include "strDup.hh"
00038 #endif
00039 
00040 #ifndef NULL
00041 #define NULL 0
00042 #endif
00043 
00044 #ifdef __BORLANDC__
00045 #define _setmode setmode
00046 #define _O_BINARY O_BINARY
00047 #endif
00048 
00049 class TaskScheduler; // forward
00050 
00051 // An abstract base class, subclassed for each use of the library
00052 
00053 class UsageEnvironment {
00054 public:
00055   void reclaim();
00056 
00057   // task scheduler:
00058   TaskScheduler& taskScheduler() const {return fScheduler;}
00059 
00060   // result message handling:
00061   typedef char const* MsgString;
00062   virtual MsgString getResultMsg() const = 0;
00063 
00064   virtual void setResultMsg(MsgString msg) = 0;
00065   virtual void setResultMsg(MsgString msg1, MsgString msg2) = 0;
00066   virtual void setResultMsg(MsgString msg1, MsgString msg2, MsgString msg3) = 0;
00067   virtual void setResultErrMsg(MsgString msg, int err = 0) = 0;
00068         // like setResultMsg(), except that an 'errno' message is appended.  (If "err == 0", the "getErrno()" code is used instead.)
00069 
00070   virtual void appendToResultMsg(MsgString msg) = 0;
00071 
00072   virtual void reportBackgroundError() = 0;
00073         // used to report a (previously set) error message within
00074         // a background event
00075 
00076   virtual void internalError(); // used to 'handle' a 'should not occur'-type error condition within the library.
00077 
00078   // 'errno'
00079   virtual int getErrno() const = 0;
00080 
00081   // 'console' output:
00082   virtual UsageEnvironment& operator<<(char const* str) = 0;
00083   virtual UsageEnvironment& operator<<(int i) = 0;
00084   virtual UsageEnvironment& operator<<(unsigned u) = 0;
00085   virtual UsageEnvironment& operator<<(double d) = 0;
00086   virtual UsageEnvironment& operator<<(void* p) = 0;
00087 
00088   // a pointer to additional, optional, client-specific state
00089   void* liveMediaPriv;
00090   void* groupsockPriv;
00091 
00092 protected:
00093   UsageEnvironment(TaskScheduler& scheduler); // abstract base class
00094   virtual ~UsageEnvironment(); // we are deleted only by reclaim()
00095 
00096 private:
00097   TaskScheduler& fScheduler;
00098 };
00099 
00100 
00101 typedef void TaskFunc(void* clientData);
00102 typedef void* TaskToken;
00103 typedef u_int32_t EventTriggerId;
00104 
00105 class TaskScheduler {
00106 public:
00107   virtual ~TaskScheduler();
00108 
00109   virtual TaskToken scheduleDelayedTask(int64_t microseconds, TaskFunc* proc,
00110                                         void* clientData) = 0;
00111         // Schedules a task to occur (after a delay) when we next
00112         // reach a scheduling point.
00113         // (Does not delay if "microseconds" <= 0)
00114         // Returns a token that can be used in a subsequent call to
00115         // unscheduleDelayedTask()
00116 
00117   virtual void unscheduleDelayedTask(TaskToken& prevTask) = 0;
00118         // (Has no effect if "prevTask" == NULL)
00119         // Sets "prevTask" to NULL afterwards.
00120 
00121   virtual void rescheduleDelayedTask(TaskToken& task,
00122                                      int64_t microseconds, TaskFunc* proc,
00123                                      void* clientData);
00124   // Combines "unscheduleDelayedTask()" with "scheduleDelayedTask()"
00125   // (setting "task" to the new task token).
00126 
00127   // For handling socket operations in the background (from the event loop):
00128   typedef void BackgroundHandlerProc(void* clientData, int mask);
00129     // Possible bits to set in "mask".  (These are deliberately defined
00130     // the same as those in Tcl, to make a Tcl-based subclass easy.)
00131     #define SOCKET_READABLE    (1<<1)
00132     #define SOCKET_WRITABLE    (1<<2)
00133     #define SOCKET_EXCEPTION   (1<<3)
00134   virtual void setBackgroundHandling(int socketNum, int conditionSet, BackgroundHandlerProc* handlerProc, void* clientData) = 0;
00135   void disableBackgroundHandling(int socketNum) { setBackgroundHandling(socketNum, 0, NULL, NULL); }
00136   virtual void moveSocketHandling(int oldSocketNum, int newSocketNum) = 0;
00137         // Changes any socket handling for "oldSocketNum" so that occurs with "newSocketNum" instead.
00138 
00139   virtual void doEventLoop(char* watchVariable = NULL) = 0;
00140       // Causes further execution to take place within the event loop.
00141       // Delayed tasks, background I/O handling, and other events are handled, sequentially (as a single thread of control).
00142       // (If "watchVariable" is not NULL, then we return from this routine when *watchVariable != 0)
00143 
00144   virtual EventTriggerId createEventTrigger(TaskFunc* eventHandlerProc) = 0;
00145       // Creates a 'trigger' for an event, which - if it occurs - will be handled (from the event loop) using "eventHandlerProc".
00146       // (Returns 0 iff no such trigger can be created (e.g., because of implementation limits on the number of triggers).)
00147   virtual void deleteEventTrigger(EventTriggerId eventTriggerId) = 0;
00148 
00149   virtual void triggerEvent(EventTriggerId eventTriggerId, void* clientData = NULL) = 0;
00150       // Causes the (previously-registered) handler function for the specified event to be handled (from the event loop).
00151       // The handler function is called with "clientData" as parameter.
00152       // Note: This function (unlike other library functions) may be called from an external thread - to signal an external event.
00153 
00154   // The following two functions are deprecated, and are provided for backwards-compatibility only:
00155   void turnOnBackgroundReadHandling(int socketNum, BackgroundHandlerProc* handlerProc, void* clientData) {
00156     setBackgroundHandling(socketNum, SOCKET_READABLE, handlerProc, clientData);
00157   }
00158   void turnOffBackgroundReadHandling(int socketNum) { disableBackgroundHandling(socketNum); }
00159 
00160   virtual void internalError(); // used to 'handle' a 'should not occur'-type error condition within the library.
00161 
00162 protected:
00163   TaskScheduler(); // abstract base class
00164 };
00165 
00166 #endif

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