Ejemplo n.º 1
0
bool USBDownloader::download(const String &file)
{
  String fil = file;
  
  if(!_locateFile(fil))
  {
    logger(LOG_ERROR) << "USBDownloader: Could not locate '" << file << "'." << std::endl;
    _outStream << "USBDownloader: Could not locate '" << file << "'." << std::endl;
    return false;
  }
  
  std::ifstream f(fil, std::ios::binary | std::ios::ate);
  
  if(!f.good())
  {
    logger(LOG_ERROR) << "USBDownloader: Could not open '" << fil << "'." << std::endl;
    _outStream << "USBDownloader: Could not open '" << fil << "'." << std::endl;
    return false;
  }
  
  std::streamoff size = f.tellg();
  
  f.seekg(std::ios::beg);
  
  return _configureForDownload() && _download(f, size);
}
Ejemplo n.º 2
0
/**************************************************************************
 * private functions
 **************************************************************************/
static void *_preloadThread(void *arg) {
    int status;
    preloadThreadData_t *threadData = (preloadThreadData_t *)arg;
    preloadThreadInfo_t *threadInfo = NULL;

    if(threadData == NULL) {
        rodsLog (LOG_DEBUG, "_preloadThread: given thread argument is null");
        pthread_exit(NULL);
    }

    threadInfo = threadData->threadInfo;

    rodsLog (LOG_DEBUG, "_preloadThread: preload - %s", threadData->path);
    
    status = _download(threadData->path, &threadData->stbuf);
    if(status != 0) {
        rodsLog (LOG_DEBUG, "_preloadThread: download error - %d", status);
    }

    // downloading is done
    LOCK(PreloadLock);

    // change thread status
    LOCK_STRUCT(*threadInfo);
    threadInfo->running = PRELOAD_THREAD_IDLE;
    UNLOCK_STRUCT(*threadInfo);

    // release threadData
    rodsLog (LOG_DEBUG, "_preloadThread: thread finished - %s", threadData->path);
    if(threadData->path != NULL) {
        free(threadData->path);
        threadData->path = NULL;
    }

    free(threadData);

    // remove from hash table
    removeFromConcurrentList2(PreloadThreadList, threadInfo);
    deleteFromHashTable(PreloadThreadTable, threadInfo->path);

    if(threadInfo != NULL) {
        if(threadInfo->path != NULL) {
            free(threadInfo->path);
            threadInfo->path = NULL;
        }
        free(threadInfo);
    }

    UNLOCK(PreloadLock);
    pthread_exit(NULL);
}