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-2008 Live Networks, Inc. All rights reserved. 00017 // Basic Usage Environment: for a simple, non-scripted, console application 00018 // Implementation 00019 00020 #include "BasicUsageEnvironment0.hh" 00021 #include <stdio.h> 00022 00024 00025 BasicUsageEnvironment0::BasicUsageEnvironment0(TaskScheduler& taskScheduler) 00026 : UsageEnvironment(taskScheduler), 00027 fBufferMaxSize(RESULT_MSG_BUFFER_MAX) { 00028 reset(); 00029 } 00030 00031 BasicUsageEnvironment0::~BasicUsageEnvironment0() { 00032 } 00033 00034 void BasicUsageEnvironment0::reset() { 00035 fCurBufferSize = 0; 00036 fResultMsgBuffer[fCurBufferSize] = '\0'; 00037 } 00038 00039 00040 // Implementation of virtual functions: 00041 00042 char const* BasicUsageEnvironment0::getResultMsg() const { 00043 return fResultMsgBuffer; 00044 } 00045 00046 void BasicUsageEnvironment0::setResultMsg(MsgString msg) { 00047 reset(); 00048 appendToResultMsg(msg); 00049 } 00050 00051 void BasicUsageEnvironment0::setResultMsg(MsgString msg1, MsgString msg2) { 00052 setResultMsg(msg1); 00053 appendToResultMsg(msg2); 00054 } 00055 00056 void BasicUsageEnvironment0::setResultMsg(MsgString msg1, MsgString msg2, 00057 MsgString msg3) { 00058 setResultMsg(msg1, msg2); 00059 appendToResultMsg(msg3); 00060 } 00061 00062 void BasicUsageEnvironment0::setResultErrMsg(MsgString msg) { 00063 setResultMsg(msg); 00064 00065 #ifndef _WIN32_WCE 00066 appendToResultMsg(strerror(getErrno())); 00067 #endif 00068 } 00069 00070 void BasicUsageEnvironment0::appendToResultMsg(MsgString msg) { 00071 char* curPtr = &fResultMsgBuffer[fCurBufferSize]; 00072 unsigned spaceAvailable = fBufferMaxSize - fCurBufferSize; 00073 unsigned msgLength = strlen(msg); 00074 00075 // Copy only enough of "msg" as will fit: 00076 if (msgLength > spaceAvailable-1) { 00077 msgLength = spaceAvailable-1; 00078 } 00079 00080 memmove(curPtr, (char*)msg, msgLength); 00081 fCurBufferSize += msgLength; 00082 fResultMsgBuffer[fCurBufferSize] = '\0'; 00083 } 00084 00085 void BasicUsageEnvironment0::reportBackgroundError() { 00086 fputs(fResultMsgBuffer, stderr); 00087 } 00088
1.5.2