PleoraVideo::PleoraVideo(Params& p): size_bytes(0), lPvSystem(0), lDevice(0), lStream(0), lDeviceParams(0), lStart(0), lStop(0), lTemperatureCelcius(0), getTemp(false), lStreamParams(0), validGrabbedBuffers(0) { std::string sn; std::string mn; int index = 0; size_t buffer_count = PleoraVideo::DEFAULT_BUFFER_COUNT; Params device_params; for(Params::ParamMap::iterator it = p.params.begin(); it != p.params.end(); it++) { if(it->first == "model"){ mn = it->second; } else if(it->first == "sn"){ sn = it->second; } else if(it->first == "idx"){ index = p.Get<int>("idx", 0); } else if(it->first == "buffers"){ buffer_count = p.Get<size_t>("buffers", PleoraVideo::DEFAULT_BUFFER_COUNT); } else { device_params.Set(it->first, it->second); } } InitDevice(mn.empty() ? 0 : mn.c_str(), sn.empty() ? 0 : sn.c_str(), index); SetDeviceParams(device_params); InitStream(); InitPangoStreams(); InitBuffers(buffer_count); Start(); }
void CmtSdCard::InitSetup( OMAP_MMCHS_REGS *mmc ) { uint32 reg_val; cmtDebug1( 4, 1, "InitSetup SoftReset", 0 ); BoardInit( mmc ); mmc->MMCHS_SYSCONFIG |= MMC_SOFTRESET; while( (__raw_readl( &(mmc->MMCHS_SYSSTATUS) ) & RESETDONE) == 0 ); cmtDebug1( 4, 2, "...done. InitSetup AllReset", 0 ); mmc->MMCHS_SYSCTL |= SOFTRESETALL; while( (__raw_readl( &(mmc->MMCHS_SYSCTL) ) & SOFTRESETALL) != 0x0 ); cmtDebug1( 4, 3, "...done. InitSetup Clock Config", 0 ); mmc->MMCHS_HCTL = DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0; mmc->MMCHS_CAPA |= VS30_3V0SUP | VS18_1V8SUP; reg_val = mmc->MMCHS_CON & RESERVED_MASK; mmc->MMCHS_CON = CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH | MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK | HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN; ClockConfig( mmc, CLK_INITSEQ, 0 ); mmc->MMCHS_HCTL |= SDBP_PWRON; mmc->MMCHS_IE = 0x307f0033; cmtDebug1( 4, 4, "...done.", 0 ); InitStream( mmc ); }
/*---------------------------------------------------------------------*/ BOOL ReadState(H_ARCHIVE harchive) { UINT32 i; STREAM stream; NODE *node; if (!ValidateHandle(harchive)) { ArchiveLog(ARC_LOG_ERRORS, "ReadState: Invalid archive handle"); return (FALSE); } _archive[harchive].last_error = ARC_NO_ERROR; _archive_error = ARC_NO_ERROR; /* Go to top of file */ if (!FileRewind(_archive[harchive].file)) { _archive[harchive].last_error = ARC_FILE_IO_ERROR; ArchiveLog(ARC_LOG_ERRORS, "ReadState: Error rewinding state file (state): %s", _archive[harchive].filespec); return (FALSE); } /* Read state structure */ InitState(&_archive[harchive].state); if (SerializedRead(&_archive[harchive].state, _state_template, _archive[harchive].file) == VOID_UINT32) { ArchiveLog(ARC_LOG_ERRORS, "ReadState: Error reading state file (state): %s", _archive[harchive].filespec); return (FALSE); } /* If we don't have streams... */ if (_archive[harchive].state.n_streams == 0) return (TRUE); /* Read stream structures into stream list */ /* Destroy any existing list */ DestroyList(&_archive[harchive].streams); /* Set node to head */ node = &_archive[harchive].streams.head; for (i = 0; i < _archive[harchive].state.n_streams; i++) { /* Clean stream record */ InitStream(&stream); if (SerializedRead(&stream, _stream_template, _archive[harchive].file) == VOID_UINT32) { ArchiveLog(ARC_LOG_ERRORS, "ReadState: Error reading state file (stream): %s", _archive[harchive].filespec); return (FALSE); } /* Insert new node after the current one */ if ((node = InsertNodeAfter(node, &stream, sizeof(STREAM))) == NULL) { _archive_error = ARC_NO_MEMORY; ArchiveLog(ARC_LOG_ERRORS, "ReadState: Error allocating stream node (stream): %s", _archive[harchive].filespec); return (FALSE); } } return (TRUE); }
bool CFMODEx::SetupSound() { if(!initDone) return false; DeInitStream(); return InitStream(); }
wxSafeHTTPEngineInputStream(const wxString &url, const wxProxySettings &proxy, const wxHTTPAuthSettings &auth) : m_pStream(NULL) { m_http.SetProxySettings(proxy); m_http.SetAuthentication(auth); InitStream(url); }
GDLGStream* GetStream( bool open=true) { if( actStream == NULL) { if( !open) return NULL; InitStream(); } return actStream; }
void CPDF_Stream::InitStream(IFX_FileRead *pFile, CPDF_Dictionary* pDict) { InitStream(pDict); m_pFile = pFile; m_dwSize = (FX_DWORD)pFile->GetSize(); if (m_pDict) { m_pDict->SetAtInteger(FX_BSTRC("Length"), m_dwSize); } }
void CPDF_Stream::InitStream(FX_LPBYTE pData, FX_DWORD size, CPDF_Dictionary* pDict) { InitStream(pDict); m_GenNum = (FX_DWORD) - 1; m_pDataBuf = FX_Alloc(FX_BYTE, size); if (pData) { FXSYS_memcpy32(m_pDataBuf, pData, size); } m_dwSize = size; if (m_pDict) { m_pDict->SetAtInteger(FX_BSTRC("Length"), size); } }
MainObject::MainObject(QObject *parent,const char *name) { input_fd=-1; dest_hostname=RMLSEND_DEFAULT_ADDR; dest_port=RMLSEND_DEFAULT_PORT; rml_ptr=0; ReadSwitches(); ResolveName(); InitStream(); ProcessCommands(); CloseStream(); exit(0); }
bool FileReadBuffer::Open( const tstring &file_path ) { DWORD readlen = 0; size_t headerlen = 0; int z_return = Z_OK; obj_hdr header_obj; handle_ = CreateFile(file_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (INVALID_HANDLE_VALUE == handle_) { return false; } InitStream(&zs_, headerbuf_, sizeof(headerbuf_)); z_return = inflateInit(&zs_); // Inflate odb file header while (z_return == Z_OK && zs_.total_out != ODB_HEADER_MAX_LEN) { if (::ReadFile(handle_, rawbuf_, sizeof(rawbuf_), &readlen, NULL) && readlen > 0) { SetStreamInput(&zs_, rawbuf_, readlen); z_return = inflate(&zs_, 0); } else { z_return = Z_STREAM_END; } } if (z_return != Z_STREAM_END && z_return != Z_OK) {// Inflate error return false; } if ((headerlen = GetObjectHeader(&header_obj, headerbuf_)) == 0) { return false; } else { len_ = header_obj.size; type_ = header_obj.type; headerlen_ = headerlen; tail_ = zs_.total_out - headerlen_; } return true; }
PleoraVideo::PleoraVideo(const Params& p): size_bytes(0), lPvSystem(0), lDevice(0), lStream(0), lDeviceParams(0), lStart(0), lStop(0), lTemperatureCelcius(0), getTemp(false), lStreamParams(0), validGrabbedBuffers(0) { std::string sn; std::string mn; int index = 0; size_t buffer_count = PleoraVideo::DEFAULT_BUFFER_COUNT; Params device_params; for(Params::ParamMap::const_iterator it = p.params.begin(); it != p.params.end(); it++) { if(it->first == "model"){ mn = it->second; } else if(it->first == "sn"){ sn = it->second; } else if(it->first == "idx"){ index = p.Get<int>("idx", 0); } else if(it->first == "size") { const ImageDim dim = p.Get<ImageDim>("size", ImageDim(0,0) ); device_params.Set("Width" , dim.x); device_params.Set("Height" , dim.y); } else if(it->first == "pos") { const ImageDim pos = p.Get<ImageDim>("pos", ImageDim(0,0) ); device_params.Set("OffsetX" , pos.x); device_params.Set("OffsetY" , pos.y); } else if(it->first == "roi") { const ImageRoi roi = p.Get<ImageRoi>("roi", ImageRoi(0,0,0,0) ); device_params.Set("Width" , roi.w); device_params.Set("Height" , roi.h); device_params.Set("OffsetX", roi.x); device_params.Set("OffsetY", roi.y); } else { device_params.Set(it->first, it->second); } } InitDevice(mn.empty() ? 0 : mn.c_str(), sn.empty() ? 0 : sn.c_str(), index); SetDeviceParams(device_params); InitStream(); InitPangoStreams(); InitPangoDeviceProperties(); InitBuffers(buffer_count); }
/*---------------------------------------------------------------------*/ VOID InitRead(H_STREAM hstream) { if (hstream > MAX_OPEN_STREAMS) return; _reads[hstream].harchive = VOID_H_ARCHIVE; InitStream(&_reads[hstream].criteria); _reads[hstream].options = 0x00000000; InitEvent(&_reads[hstream].event); _reads[hstream].state = STA_STARTING; _reads[hstream].time.earliest = VOID_TIME; _reads[hstream].time.latest = VOID_TIME; _reads[hstream].out_evn = VOID_EVENT_NO; _reads[hstream].out_seq = VOID_SEQ_NO; _reads[hstream].channels = 0; _reads[hstream].in_seq = VOID_SEQ_NO; _reads[hstream].file = VOID_H_FILE; return; }
int __cdecl SocketPosixC__Accept(int server, EndPoint* ep) { SockAddrIn name; int client = { 0 }; while (1) { socklen_t len = sizeof(name); ZERO_MEMORY(name); client = accept(server, (struct sockaddr *)&name, &len); if (client >= 0) { InitStream(client); AddressToEndPoint(&name, ep); return client; } switch (GetSocketError()) { case EMFILE: case ENFILE: IOError(NoResources); return -1; case EWOULDBLOCK: #if EAGAIN != EWOULDBLOCK case EAGAIN: #endif /* nope, not yet */ break; default: IOError(Unexpected); return -1; } SchedulerPosix__IOAlertWait(server, TRUE); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { //init ui->setupUi(this); InitPlaylist(); search_model = new QStandardItemModel(); search_model->setHorizontalHeaderLabels( QStringList() << QApplication::translate("nestedlayouts", "Song") << QApplication::translate("nestedlayouts", "Url ")); qDebug() << "hello from GUI thread " << QThread::currentThread(); //connect button QObject::connect(ui->searchButton, SIGNAL(clicked()), this , SLOT(SearchSongHandler())); QObject::connect(ui->addButton, SIGNAL(clicked()), this , SLOT(AddSongHandler())); ui->searchView->setSelectionMode(QAbstractItemView::ExtendedSelection); qRegisterMetaType<PlayStructList>("PlayStructList"); connect(&playlist_thread, SIGNAL(UpdatePlaylist(PlayStructList)), this, SLOT(ShowPlaylist(PlayStructList))); stream = new Stream; InitStream(); //connect button stop stream QObject::connect(ui->pauseButton, SIGNAL(clicked()), this , SLOT(StartStopStream())); //ui->songNameLabel->setText("test"); ui->lcdTime->display("00:00"); connect(stream->mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); //connect(stream, SIGNAL(UpdateTimer(QTime displayTime)), this, SLOT(ShowTimer(QTime displayTime))); }
wxURLInputStream(const wxString &url) : m_url(url), m_pStream(NULL) { InitStream(); }
void __cdecl SocketPosixC__Connect(int fd, EndPoint* ep) { SockAddrIn name; int error; ZERO_MEMORY(name); EndPointToAddress(ep, &name); InitStream(fd); while (1) { if (connect(fd, (struct sockaddr *)&name, sizeof(name)) == 0) break; error = GetSocketError(); #if REFETCH_ERROR switch (error) { case EINVAL: /* hack to try to get real GetSocketError(), hidden due to NBIO bug in connect */ case EBADF: /* we'll try the same for EBADF, which we've seen on Alpha */ error = RefetchError(fd); } #endif if (CommonError(error)) return; switch (error) { #ifdef _WIN32 case WSAEISCONN: #else case EISCONN: #endif return; #ifdef _WIN32 case WSAEADDRNOTAVAIL: case WSAECONNREFUSED: case WSAEINVAL: case WSAECONNRESET: case WSAEBADF: #else case EADDRNOTAVAIL: case ECONNREFUSED: case EINVAL: case ECONNRESET: case EBADF: #endif IOError(Refused); return; #ifdef _WIN32 case WSAEWOULDBLOCK: case WSAEAGAIN: case WSAEINPROGRESS: case WSAEALREADY: #else case EWOULDBLOCK: #if EWOULDBLOCK != EAGAIN case EAGAIN: #endif case EINPROGRESS: case EALREADY: #endif /* nope, not yet */ break; default: IOError(Unexpected); return; } #ifndef _WIN32 SchedulerPosix__IOAlertWait(fd, FALSE); #endif } }
void Entresol::ConstructFromXML(const String& EngineDataPath, const Mezzanine::ArchiveType ArchType, const String& InitializerFile) { //Add default manager factories AddAllEngineDefaultManagerFactories(); //Set some sane Defaults for some values. this->ManualLoopBreak = false; // Create Ogre. SetupOgre(); // Load the necessary plugins. SubSystemParticleFXPlugin = new Ogre::ParticleFXPlugin(); Ogre::Root::getSingleton().installPlugin(SubSystemParticleFXPlugin); // Set up the data we'll be populating. XML::Attribute CurrAttrib; String GUIInit, ResourceInit, PluginsInit, LogFileName; String PluginExtension, PluginPath; // Create or set the resource manager. /// @todo This currently forces our default resource manager to be constructed, which isn't in line with our factory/initiailzation design. /// This should be addressed somehow. if(ResourceManager::SingletonValid()) { AddManager(ResourceManager::GetSingletonPtr()); } else { AddManager(new ResourceManager(EngineDataPath, ArchType)); } // Open and load the initializer doc. ResourceManager* ResourceMan = GetResourceManager(); /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready. Resource::FileStream InitStream(InitializerFile,EngineDataPath); XML::Document InitDoc; XML::ParseResult DocResult = InitDoc.Load(InitStream); if( DocResult.Status != XML::StatusOk ) { StringStream ExceptionStream; ExceptionStream << "Failed to parse XML file \"" << InitializerFile << "\"."; MEZZ_EXCEPTION(Exception::SYNTAX_ERROR_EXCEPTION_XML,ExceptionStream.str()); } XML::Node InitRoot = InitDoc.GetChild("InitializerRoot"); if( InitRoot.Empty() ) { StringStream ExceptionStream; ExceptionStream << "Failed to find expected Root node in \"" << InitializerFile << "\"."; MEZZ_EXCEPTION(Exception::SYNTAX_ERROR_EXCEPTION_XML,ExceptionStream.str()); } // Get the world settings and set them. XML::Node WorldSettings = InitRoot.GetChild("WorldSettings"); for( XML::NodeIterator SetIt = WorldSettings.begin() ; SetIt != WorldSettings.end() ; ++SetIt ) { String SecName = (*SetIt).Name(); if( "FrameSettings" == SecName ) { CurrAttrib = (*SetIt).GetAttribute("TargetFrameRate"); if(CurrAttrib.Empty()) { CurrAttrib = (*SetIt).GetAttribute("TargetFrameTime"); if(!CurrAttrib.Empty()) SetTargetFrameTimeMicroseconds(CurrAttrib.AsWhole()); }else{ this->SetTargetFrameRate(CurrAttrib.AsWhole()); } } else { MEZZ_EXCEPTION(Exception::SYNTAX_ERROR_EXCEPTION_XML,String("Unknown WorldSetting ")+SecName); } } SetupLogging(LogFileName); // Get the other initializer files we'll be using, since we'll need the plugins initializer. XML::Node InitFiles = InitRoot.GetChild("OtherInitializers"); for( XML::NodeIterator InitIt = InitFiles.begin() ; InitIt != InitFiles.end() ; ++InitIt ) { String InitFileName = (*InitIt).Name(); if( "PluginInit" == InitFileName ) { CurrAttrib = (*InitIt).GetAttribute("FileName"); if(!CurrAttrib.Empty()) PluginsInit = CurrAttrib.AsString(); } else if( "ResourceInit" == InitFileName ) { CurrAttrib = (*InitIt).GetAttribute("FileName"); if(!CurrAttrib.Empty()) ResourceInit = CurrAttrib.AsString(); } else if( "GUIInit" == InitFileName ) { CurrAttrib = (*InitIt).GetAttribute("FileName"); if(!CurrAttrib.Empty()) GUIInit = CurrAttrib.AsString(); } } // Load additional resource groups /*if(!ResourceInit.empty()) { /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready. Resource::FileStream ResourceStream(ResourceInit,EngineDataPath); XML::Document ResourceDoc; ResourceDoc.Load(ResourceStream); // Get an iterator to the first resource group node, and declare them all. XML::Node ResourceLocations = ResourceDoc.GetChild("ResourceLocations"); for( XML::NodeIterator GroupIt = ResourceLocations.begin() ; GroupIt != ResourceLocations.end() ; ++GroupIt ) { String GroupName, GroupType, GroupPath; bool GroupRecursive = false; // Get the group path CurrAttrib = (*GroupIt).GetAttribute("GroupPath"); if(!CurrAttrib.Empty()) GroupPath = CurrAttrib.AsString(); // Get the group type CurrAttrib = (*GroupIt).GetAttribute("GroupType"); if(!CurrAttrib.Empty()) GroupType = CurrAttrib.AsString(); // Get the group name CurrAttrib = (*GroupIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); // Get whether this is recursive CurrAttrib = (*GroupIt).GetAttribute("Recursive"); if(!CurrAttrib.Empty()) GroupRecursive = StringTool::ConvertToBool(CurrAttrib.AsString()); // Finally create the resource location. ResourceMan->AddAssetLocation(GroupPath,GroupType,GroupName,GroupRecursive); } // Get what resource groups should be initialized. XML::Node InitGroups = ResourceDoc.GetChild("InitGroups"); for( XML::NodeIterator InitIt = InitGroups.begin() ; InitIt != InitGroups.end() ; ++InitIt ) { String GroupName; CurrAttrib = (*InitIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); ResourceMan->InitAssetGroup(GroupName); } }//*/ // Create the requested managers and set their necessary values. XML::Node Managers = InitRoot.GetChild("Managers"); for( XML::NodeIterator ManIt = Managers.begin() ; ManIt != Managers.end() ; ++ManIt ) { CreateManager( (*ManIt).Name(), (*ManIt) ); } // Load additional resource groups if(!ResourceInit.empty()) { /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready. Resource::FileStream ResourceStream(ResourceInit,EngineDataPath); XML::Document ResourceDoc; ResourceDoc.Load(ResourceStream); // Get an iterator to the first resource group node, and declare them all. XML::Node ResourceLocations = ResourceDoc.GetChild("ResourceLocations"); for( XML::NodeIterator GroupIt = ResourceLocations.begin() ; GroupIt != ResourceLocations.end() ; ++GroupIt ) { String GroupName, GroupPath; ArchiveType GroupType; bool GroupRecursive = false; // Get the group path CurrAttrib = (*GroupIt).GetAttribute("GroupPath"); if(!CurrAttrib.Empty()) GroupPath = CurrAttrib.AsString(); // Get the group type CurrAttrib = (*GroupIt).GetAttribute("GroupType"); if(!CurrAttrib.Empty()) GroupType = ResourceManager::GetArchiveTypeFromString(CurrAttrib.AsString()); // Get the group name CurrAttrib = (*GroupIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); // Get whether this is recursive CurrAttrib = (*GroupIt).GetAttribute("Recursive"); if(!CurrAttrib.Empty()) GroupRecursive = StringTools::ConvertToBool(CurrAttrib.AsString()); // Finally create the resource location. ResourceMan->AddAssetLocation(GroupPath,GroupType,GroupName,GroupRecursive); } // Get what resource groups should be initialized. XML::Node InitGroups = ResourceDoc.GetChild("InitGroups"); for( XML::NodeIterator InitIt = InitGroups.begin() ; InitIt != InitGroups.end() ; ++InitIt ) { String GroupName; CurrAttrib = (*InitIt).GetAttribute("GroupName"); if(!CurrAttrib.Empty()) GroupName = CurrAttrib.AsString(); ResourceMan->InitAssetGroup(GroupName); } } // Configure the UI if(!GUIInit.empty()) { /// @todo This is currently not implemented. } SanityChecks(); }
/*====================================================================== Purpose: Perform the purge Returns: TRUE something purged FALSE nothing purged Notes: Revised: 15Dec04 (pld) move archive size adjustment into DeleteOldestEvent() ----------------------------------------------------------------------*/ static BOOL Purge(H_ARCHIVE harchive) { VOID *ptr; CHAR string[32]; REAL64 earliest; STREAM criteria; STREAM *stream; EVENT event; UINT64 bytes_removed; if (!ValidateHandle(harchive)) { ArchiveLog(ARC_LOG_ERRORS, "Purge: ValidateHandle failed"); return (FALSE); } _archive[harchive].last_error = ARC_NO_ERROR; _archive_error = ARC_NO_ERROR; /* Try and delete a file to make room for another packet */ /* Note: if no file found, bytes_removed will be 0 */ InitStream(&criteria); if (bytes_removed = DeleteOldestEvent(harchive, &event, &criteria, &stream), bytes_removed == 0) { ArchiveLog(ARC_LOG_ERRORS, "Purge: DeleteOldestEvent failed"); return (FALSE); } /* Find the *new* earliest event for this stream */ InitStream(&criteria); criteria.unit = event.unit; criteria.stream = event.stream; InitEvent(&event); if (!ArchiveFindFirstEvent(harchive, &criteria, &event)) { MUTEX_LOCK(&_archive[harchive].mutex); stream->time.earliest = VOID_TIME; stream->time.latest = VOID_TIME; } /* This is now the earliest time in the stream record */ else { MUTEX_LOCK(&_archive[harchive].mutex); stream->time.earliest = event.time.earliest; ArchiveLog(ARC_LOG_MAXIMUM, "Purge: stream earliest data: %s", FormatMSTime(string, stream->time.earliest, 10)); } /* Find new archive earliest time */ earliest = VOID_TIME; if ((stream = ArchiveFirstStream(harchive, &ptr)) != NULL) { do { if (UndefinedTime(earliest) || stream->time.earliest < earliest) earliest = stream->time.earliest; } while ((stream = ArchiveNextStream(&ptr)) != NULL); } if (UndefinedTime(earliest)) { _archive[harchive].state.time.earliest = VOID_TIME; _archive[harchive].state.time.latest = VOID_TIME; } else { _archive[harchive].state.time.earliest = earliest; ArchiveLog(ARC_LOG_MAXIMUM, "Purge: archive earliest data: %s", FormatMSTime(string, _archive[harchive].state.time.earliest, 10)); } MUTEX_UNLOCK(&_archive[harchive].mutex); return (TRUE); } /* end Purge() */
/*====================================================================== Purpose: Find and delete the oldest file. Returns: Size in bytes of deleted file. Notes: Notes: Try and find the oldest file and delete it. If not deleted try next oldest. Revised: 15Dec04 (pld) move archive size adjustment here from Purge() ----------------------------------------------------------------------*/ static UINT64 DeleteOldestEvent(H_ARCHIVE harchive, EVENT *event, STREAM *criteria, STREAM **stream) { EVENT info; STREAM day_criteria; YD_NODE *cur_dir; YD_NODE *dir_list; INT16 max_tries_n_no_file_removed = 7; UINT64 bytes_removed = 0; char filename[MAX_PATH_LEN + 1]; CHAR string[32]; ASSERT(event != NULL); if (!ValidateHandle(harchive)) { ArchiveLog(ARC_LOG_ERRORS, "DeleteOldestEvent: ValidateHandle failed"); return (FALSE); } /* Lets get an ordered list of YYYYDDD directories to search thru */ dir_list = GetYDList(harchive,criteria); cur_dir = dir_list; /* Now lets proceed thru the YYYYDDD directory list & try and find a file to delete */ while ((max_tries_n_no_file_removed > 0) && cur_dir) { max_tries_n_no_file_removed--; /* Set criteria time range to cover this day */ InitStream(&day_criteria); day_criteria.time.earliest = EncodeMSTimeDOY(cur_dir->year, cur_dir->day, 0, 0, 0.0); day_criteria.time.latest = day_criteria.time.earliest + DAY; ArchiveLog(ARC_LOG_MAXIMUM, "DeleteOldestEvent: Look in Directory %4d%3d",cur_dir->year,cur_dir->day); do { /* Find oldest event file in this day */ InitEvent(&info); InitEvent(event); filename[0] = '\0'; if (ArchiveFindFirstEvent(harchive, &day_criteria, &info)) { memcpy(filename,info.filespec,sizeof(filename)); do { if (event->unit == VOID_UNIT || info.time.earliest < event->time.earliest) memcpy(event, &info, sizeof(STREAM)); } while (ArchiveFindNextEvent(harchive, &day_criteria, &info) && strncmp(filename,info.filespec,MAX_PATH_LEN)); } if (event->unit == VOID_UNIT) { break; /* try next days directory */ } ArchiveLog(ARC_LOG_VERBOSE, "Archive: Purge event: %s", event->filespec); /* Find the stream record */ MUTEX_LOCK(&_archive[harchive].mutex); if ((*stream = LookupStream(harchive, event->unit, event->stream)) == NULL) { ArchiveLog(ARC_LOG_ERRORS, "DeleteOldestEvent: LookupStream failed"); MUTEX_UNLOCK(&_archive[harchive].mutex); day_criteria.time.earliest += DAY/24; ArchiveLog(ARC_LOG_VERBOSE, "DeleteOldestEvent: Look for next earliest"); continue; /* try & find next earliest in directory */ } MUTEX_UNLOCK(&_archive[harchive].mutex); /* Try to delete the file */ bytes_removed = 0; if (RemoveEventFile(event->filespec)) { bytes_removed = event->bytes; break; } else /* if we were unable to remove this old event,*/ /* try and delete the next oldest event */ { day_criteria.time.earliest = event->time.latest + (DAY/24); ArchiveLog(ARC_LOG_VERBOSE, "DeleteOldestEvent: Look for next earliest"); continue; } } while(event->unit != VOID_UNIT);/* end do while files in days directory */ if (bytes_removed) { /* Adjust size based on data actually removed*/ MUTEX_LOCK(&_archive[harchive].mutex); if ((*stream)->bytes > bytes_removed) (*stream)->bytes -= bytes_removed; else (*stream)->bytes = 0; if (_archive[harchive].state.bytes > bytes_removed) _archive[harchive].state.bytes -= bytes_removed; else _archive[harchive].state.bytes = 0; ArchiveLog(ARC_LOG_MAXIMUM, "DeleteOldestEvent: stream %04X:%u size: %s bytes", event->unit, event->stream, FormatAsSIBinaryUnit(string, (*stream)->bytes, TRUE)); ArchiveLog(ARC_LOG_MAXIMUM, "DeleteOldestEvent: Archive size: %s bytes", FormatAsSIBinaryUnit(string, _archive[harchive].state.bytes, TRUE)); MUTEX_UNLOCK(&_archive[harchive].mutex); break; /* if we deleted a file we are done */ } /* end if (bytes_removed) */ cur_dir = cur_dir->next; } /* end while no file removed */ DeleteYDList(dir_list); return(bytes_removed); } /* end DeleteOldestEvent() */
FileInputStream(LFA_FileRef file) : iFile(file), iPos(0), iEndPos(0) { InitStream(); };